|
1
|
|
|
<?php |
|
2
|
|
|
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ |
|
3
|
|
|
/** |
|
4
|
|
|
* PEAR::HTML_Table makes the design of HTML tables easy, flexible, reusable and |
|
5
|
|
|
* efficient. |
|
6
|
|
|
* |
|
7
|
|
|
* The PEAR::HTML_Table package provides methods for easy and efficient design |
|
8
|
|
|
* of HTML tables. |
|
9
|
|
|
* - Lots of customization options. |
|
10
|
|
|
* - Tables can be modified at any time. |
|
11
|
|
|
* - The logic is the same as standard HTML editors. |
|
12
|
|
|
* - Handles col and rowspans. |
|
13
|
|
|
* - PHP code is shorter, easier to read and to maintain. |
|
14
|
|
|
* - Tables options can be reused. |
|
15
|
|
|
* |
|
16
|
|
|
* For auto filling of data and such then check out |
|
17
|
|
|
* http://pear.php.net/package/HTML_Table_Matrix |
|
18
|
|
|
* |
|
19
|
|
|
* PHP versions 4 and 5 |
|
20
|
|
|
* |
|
21
|
|
|
* LICENSE: |
|
22
|
|
|
* |
|
23
|
|
|
* Copyright (c) 2005-2007, Adam Daniel <[email protected]>, |
|
24
|
|
|
* Bertrand Mansion <[email protected]>, |
|
25
|
|
|
* Mark Wiesemann <[email protected]> |
|
26
|
|
|
* All rights reserved. |
|
27
|
|
|
* |
|
28
|
|
|
* Redistribution and use in source and binary forms, with or without |
|
29
|
|
|
* modification, are permitted provided that the following conditions |
|
30
|
|
|
* are met: |
|
31
|
|
|
* |
|
32
|
|
|
* * Redistributions of source code must retain the above copyright |
|
33
|
|
|
* notice, this list of conditions and the following disclaimer. |
|
34
|
|
|
* * Redistributions in binary form must reproduce the above copyright |
|
35
|
|
|
* notice, this list of conditions and the following disclaimer in the |
|
36
|
|
|
* documentation and/or other materials provided with the distribution. |
|
37
|
|
|
* * The names of the authors may not be used to endorse or promote products |
|
38
|
|
|
* derived from this software without specific prior written permission. |
|
39
|
|
|
* |
|
40
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
|
41
|
|
|
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
|
42
|
|
|
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
43
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
|
44
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
|
45
|
|
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
46
|
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
|
47
|
|
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
|
48
|
|
|
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
49
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
|
50
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
51
|
|
|
|
|
52
|
|
|
* |
|
53
|
|
|
* @category HTML |
|
54
|
|
|
* @package HTML_Table |
|
55
|
|
|
* @author Adam Daniel <[email protected]> |
|
56
|
|
|
* @author Bertrand Mansion <[email protected]> |
|
57
|
|
|
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License |
|
58
|
|
|
* @version CVS: $Id: Table.php,v 1.39 2007/06/25 16:44:43 wiesemann Exp $ |
|
59
|
|
|
* @link http://pear.php.net/package/HTML_Table |
|
60
|
|
|
*/ |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* PEAR::HTML_Table makes the design of HTML tables easy, flexible, reusable and efficient. |
|
64
|
|
|
* |
|
65
|
|
|
* The PEAR::HTML_Table package provides methods for easy and efficient design |
|
66
|
|
|
* of HTML tables. |
|
67
|
|
|
* - Lots of customization options. |
|
68
|
|
|
* - Tables can be modified at any time. |
|
69
|
|
|
* - The logic is the same as standard HTML editors. |
|
70
|
|
|
* - Handles col and rowspans. |
|
71
|
|
|
* - PHP code is shorter, easier to read and to maintain. |
|
72
|
|
|
* - Tables options can be reused. |
|
73
|
|
|
* |
|
74
|
|
|
* For auto filling of data and such then check out |
|
75
|
|
|
* http://pear.php.net/package/HTML_Table_Matrix |
|
76
|
|
|
* |
|
77
|
|
|
* @category HTML |
|
78
|
|
|
* @package HTML_Table |
|
79
|
|
|
* @author Adam Daniel <[email protected]> |
|
80
|
|
|
* @author Bertrand Mansion <[email protected]> |
|
81
|
|
|
* @copyright 2005-2006 The PHP Group |
|
82
|
|
|
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License |
|
83
|
|
|
* @version Release: @package_version@ |
|
84
|
|
|
* @link http://pear.php.net/package/HTML_Table |
|
85
|
|
|
*/ |
|
86
|
|
|
class HTML_Table extends HTML_Common |
|
87
|
|
|
{ |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Value to insert into empty cells. This is used as a default for |
|
91
|
|
|
* newly-created tbodies. |
|
92
|
|
|
* @var string |
|
93
|
|
|
* @access private |
|
94
|
|
|
*/ |
|
95
|
|
|
var $_autoFill = ' '; |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Automatically adds a new row, column, or body if a given row, column, or |
|
99
|
|
|
* body index does not exist. |
|
100
|
|
|
* This is used as a default for newly-created tbodies. |
|
101
|
|
|
* @var bool |
|
102
|
|
|
* @access private |
|
103
|
|
|
*/ |
|
104
|
|
|
var $_autoGrow = true; |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Array containing the table caption |
|
108
|
|
|
* @var array |
|
109
|
|
|
* @access private |
|
110
|
|
|
*/ |
|
111
|
|
|
var $_caption = array(); |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Array containing the table column group specifications |
|
115
|
|
|
* |
|
116
|
|
|
* @var array |
|
117
|
|
|
* @author Laurent Laville (pear at laurent-laville dot org) |
|
118
|
|
|
* @access private |
|
119
|
|
|
*/ |
|
120
|
|
|
var $_colgroup = array(); |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* HTML_Table_Storage object for the (t)head of the table |
|
124
|
|
|
* @var object |
|
125
|
|
|
* @access private |
|
126
|
|
|
*/ |
|
127
|
|
|
var $_thead = null; |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* HTML_Table_Storage object for the (t)foot of the table |
|
131
|
|
|
* @var object |
|
132
|
|
|
* @access private |
|
133
|
|
|
*/ |
|
134
|
|
|
var $_tfoot = null; |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* HTML_Table_Storage object for the (t)body of the table |
|
138
|
|
|
* @var object |
|
139
|
|
|
* @access private |
|
140
|
|
|
*/ |
|
141
|
|
|
var $_tbodies = array(); |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* Number of bodies in the table |
|
145
|
|
|
* @var int |
|
146
|
|
|
* @access private |
|
147
|
|
|
*/ |
|
148
|
|
|
var $_tbodyCount = 0; |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* Whether to use <thead>, <tfoot> and <tbody> or not |
|
152
|
|
|
* @var bool |
|
153
|
|
|
* @access private |
|
154
|
|
|
*/ |
|
155
|
|
|
var $_useTGroups = false; |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* Class constructor |
|
159
|
|
|
* @param array $attributes Associative array of table tag |
|
160
|
|
|
* attributes |
|
161
|
|
|
* @param int $tabOffset Tab offset of the table |
|
162
|
|
|
* @param bool $useTGroups Whether to use <thead>, <tfoot> and |
|
163
|
|
|
* <tbody> or not |
|
164
|
|
|
* @access public |
|
165
|
|
|
*/ |
|
166
|
|
|
public function __construct($attributes = null, $tabOffset = 0, $useTGroups = false) |
|
167
|
|
|
{ |
|
168
|
|
|
parent::__construct($attributes, (int)$tabOffset); |
|
169
|
|
|
$this->_useTGroups = (boolean)$useTGroups; |
|
170
|
|
|
$this->addBody(); |
|
171
|
|
|
if ($this->_useTGroups) { |
|
172
|
|
|
$this->_thead = new HTML_Table_Storage($tabOffset, $this->_useTGroups); |
|
173
|
|
|
$this->_tfoot = new HTML_Table_Storage($tabOffset, $this->_useTGroups); |
|
174
|
|
|
} |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
/** |
|
178
|
|
|
* Returns the API version |
|
179
|
|
|
* @access public |
|
180
|
|
|
* @return double |
|
181
|
|
|
* @deprecated |
|
182
|
|
|
*/ |
|
183
|
|
|
function apiVersion() |
|
184
|
|
|
{ |
|
185
|
|
|
return 1.7; |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
/** |
|
189
|
|
|
* Returns the HTML_Table_Storage object for <thead> |
|
190
|
|
|
* @access public |
|
191
|
|
|
* @return object |
|
192
|
|
|
*/ |
|
193
|
|
View Code Duplication |
function &getHeader() |
|
194
|
|
|
{ |
|
195
|
|
|
if (is_null($this->_thead)) { |
|
196
|
|
|
$this->_useTGroups = true; |
|
197
|
|
|
$this->_thead = new HTML_Table_Storage($this->_tabOffset, |
|
198
|
|
|
$this->_useTGroups); |
|
199
|
|
|
for ($i = 0; $i < $this->_tbodyCount; $i++) { |
|
200
|
|
|
$this->_tbodies[$i]->setUseTGroups(true); |
|
201
|
|
|
} |
|
202
|
|
|
} |
|
203
|
|
|
return $this->_thead; |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
/** |
|
207
|
|
|
* Returns the HTML_Table_Storage object for <tfoot> |
|
208
|
|
|
* @access public |
|
209
|
|
|
* @return object |
|
210
|
|
|
*/ |
|
211
|
|
View Code Duplication |
function &getFooter() |
|
212
|
|
|
{ |
|
213
|
|
|
if (is_null($this->_tfoot)) { |
|
214
|
|
|
$this->_useTGroups = true; |
|
215
|
|
|
$this->_tfoot = new HTML_Table_Storage($this->_tabOffset, |
|
216
|
|
|
$this->_useTGroups); |
|
217
|
|
|
for ($i = 0; $i < $this->_tbodyCount; $i++) { |
|
218
|
|
|
$this->_tbodies[$i]->setUseTGroups(true); |
|
219
|
|
|
} |
|
220
|
|
|
} |
|
221
|
|
|
return $this->_tfoot; |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
/** |
|
225
|
|
|
* Returns the HTML_Table_Storage object for the specified <tbody> |
|
226
|
|
|
* (or the whole table if <t{head|foot|body}> is not used) |
|
227
|
|
|
* @param int $body (optional) The index of the body to |
|
228
|
|
|
* return. |
|
229
|
|
|
* @access public |
|
230
|
|
|
* @return object |
|
231
|
|
|
* @throws PEAR_Error |
|
232
|
|
|
*/ |
|
233
|
|
|
function &getBody($body = 0) |
|
234
|
|
|
{ |
|
235
|
|
|
$ret = $this->_adjustTbodyCount($body, 'getBody'); |
|
236
|
|
|
if (PEAR::isError($ret)) { |
|
237
|
|
|
return $ret; |
|
238
|
|
|
} |
|
239
|
|
|
return $this->_tbodies[$body]; |
|
240
|
|
|
} |
|
241
|
|
|
|
|
242
|
|
|
/** |
|
243
|
|
|
* Adds a table body and returns the body identifier |
|
244
|
|
|
* @param mixed $attributes (optional) Associative array or |
|
245
|
|
|
* string of table body attributes |
|
246
|
|
|
* @access public |
|
247
|
|
|
* @return int |
|
248
|
|
|
*/ |
|
249
|
|
|
function addBody($attributes = null) |
|
250
|
|
|
{ |
|
251
|
|
|
if (!$this->_useTGroups && $this->_tbodyCount > 0) { |
|
252
|
|
|
for ($i = 0; $i < $this->_tbodyCount; $i++) { |
|
253
|
|
|
$this->_tbodies[$i]->setUseTGroups(true); |
|
254
|
|
|
} |
|
255
|
|
|
$this->_useTGroups = true; |
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
$body = $this->_tbodyCount++; |
|
259
|
|
|
$this->_tbodies[$body] = new HTML_Table_Storage($this->_tabOffset, |
|
260
|
|
|
$this->_useTGroups); |
|
261
|
|
|
$this->_tbodies[$body]->setAutoFill($this->_autoFill); |
|
262
|
|
|
$this->_tbodies[$body]->setAttributes($attributes); |
|
263
|
|
|
return $body; |
|
264
|
|
|
} |
|
265
|
|
|
|
|
266
|
|
|
/** |
|
267
|
|
|
* Adjusts the number of bodies |
|
268
|
|
|
* @param int $body Body index |
|
269
|
|
|
* @param string $method Name of calling method |
|
270
|
|
|
* @access private |
|
271
|
|
|
* @throws PEAR_Error |
|
272
|
|
|
*/ |
|
273
|
|
|
function _adjustTbodyCount($body, $method) |
|
274
|
|
|
{ |
|
275
|
|
|
if ($this->_autoGrow) { |
|
276
|
|
|
while ($this->_tbodyCount <= (int)$body) { |
|
277
|
|
|
$this->addBody(); |
|
278
|
|
|
} |
|
279
|
|
|
} else { |
|
280
|
|
|
return PEAR::raiseError('Invalid body reference[' . |
|
281
|
|
|
$body . '] in HTML_Table::' . $method); |
|
282
|
|
|
} |
|
283
|
|
|
} |
|
284
|
|
|
|
|
285
|
|
|
/** |
|
286
|
|
|
* Sets the table caption |
|
287
|
|
|
* @param string $caption |
|
288
|
|
|
* @param mixed $attributes Associative array or string of |
|
289
|
|
|
* table row attributes |
|
290
|
|
|
* @access public |
|
291
|
|
|
*/ |
|
292
|
|
|
function setCaption($caption, $attributes = null) |
|
293
|
|
|
{ |
|
294
|
|
|
$attributes = $this->_parseAttributes($attributes); |
|
295
|
|
|
$this->_caption = array('attr' => $attributes, 'contents' => $caption); |
|
296
|
|
|
} |
|
297
|
|
|
|
|
298
|
|
|
/** |
|
299
|
|
|
* Sets the table columns group specifications, or removes existing ones. |
|
300
|
|
|
* |
|
301
|
|
|
* @param mixed $colgroup (optional) Columns attributes |
|
302
|
|
|
* @param mixed $attributes (optional) Associative array or string |
|
303
|
|
|
* of table row attributes |
|
304
|
|
|
* @author Laurent Laville (pear at laurent-laville dot org) |
|
305
|
|
|
* @access public |
|
306
|
|
|
*/ |
|
307
|
|
|
function setColGroup($colgroup = null, $attributes = null) |
|
308
|
|
|
{ |
|
309
|
|
|
if (isset($colgroup)) { |
|
310
|
|
|
$attributes = $this->_parseAttributes($attributes); |
|
311
|
|
|
$this->_colgroup[] = array('attr' => $attributes, |
|
312
|
|
|
'contents' => $colgroup); |
|
313
|
|
|
} else { |
|
314
|
|
|
$this->_colgroup = array(); |
|
315
|
|
|
} |
|
316
|
|
|
} |
|
317
|
|
|
|
|
318
|
|
|
/** |
|
319
|
|
|
* Sets the autoFill value |
|
320
|
|
|
* @param mixed $fill Whether autoFill should be enabled or not |
|
321
|
|
|
* @param int $body (optional) The index of the body to set. |
|
322
|
|
|
* Pass null to set for all bodies. |
|
323
|
|
|
* @access public |
|
324
|
|
|
* @throws PEAR_Error |
|
325
|
|
|
*/ |
|
326
|
|
View Code Duplication |
function setAutoFill($fill, $body = null) |
|
327
|
|
|
{ |
|
328
|
|
|
if (!is_null($body)) { |
|
329
|
|
|
$ret = $this->_adjustTbodyCount($body, 'setAutoFill'); |
|
330
|
|
|
if (PEAR::isError($ret)) { |
|
331
|
|
|
return $ret; |
|
332
|
|
|
} |
|
333
|
|
|
$this->_tbodies[$body]->setAutoFill($fill); |
|
334
|
|
|
} else { |
|
335
|
|
|
$this->_autoFill = $fill; |
|
336
|
|
|
for ($i = 0; $i < $this->_tbodyCount; $i++) { |
|
337
|
|
|
$this->_tbodies[$i]->setAutoFill($fill); |
|
338
|
|
|
} |
|
339
|
|
|
} |
|
340
|
|
|
} |
|
341
|
|
|
|
|
342
|
|
|
/** |
|
343
|
|
|
* Returns the autoFill value |
|
344
|
|
|
* @param int $body (optional) The index of the body to get. |
|
345
|
|
|
* Pass null to get the default for new bodies. |
|
346
|
|
|
* @access public |
|
347
|
|
|
* @return mixed |
|
348
|
|
|
* @throws PEAR_Error |
|
349
|
|
|
*/ |
|
350
|
|
|
function getAutoFill($body = null) |
|
351
|
|
|
{ |
|
352
|
|
|
if (!is_null($body)) { |
|
353
|
|
|
$ret = $this->_adjustTbodyCount($body, 'getAutoFill'); |
|
354
|
|
|
if (PEAR::isError($ret)) { |
|
355
|
|
|
return $ret; |
|
356
|
|
|
} |
|
357
|
|
|
return $this->_tbodies[$body]->getAutoFill(); |
|
358
|
|
|
} else { |
|
359
|
|
|
return $this->_autoFill; |
|
360
|
|
|
} |
|
361
|
|
|
} |
|
362
|
|
|
|
|
363
|
|
|
/** |
|
364
|
|
|
* Sets the autoGrow value |
|
365
|
|
|
* @param bool $grow Whether autoGrow should be enabled or not |
|
366
|
|
|
* @param int $body (optional) The index of the body to set. |
|
367
|
|
|
* Pass null to set for all bodies. |
|
368
|
|
|
* @access public |
|
369
|
|
|
* @throws PEAR_Error |
|
370
|
|
|
*/ |
|
371
|
|
View Code Duplication |
function setAutoGrow($grow, $body = null) |
|
372
|
|
|
{ |
|
373
|
|
|
if (!is_null($body)) { |
|
374
|
|
|
$ret = $this->_adjustTbodyCount($body, 'setAutoGrow'); |
|
375
|
|
|
if (PEAR::isError($ret)) { |
|
376
|
|
|
return $ret; |
|
377
|
|
|
} |
|
378
|
|
|
$this->_tbodies[$body]->setAutoGrow($grow); |
|
379
|
|
|
} else { |
|
380
|
|
|
$this->_autoGrow = $grow; |
|
381
|
|
|
for ($i = 0; $i < $this->_tbodyCount; $i++) { |
|
382
|
|
|
$this->_tbodies[$i]->setAutoGrow($grow); |
|
383
|
|
|
} |
|
384
|
|
|
} |
|
385
|
|
|
} |
|
386
|
|
|
|
|
387
|
|
|
/** |
|
388
|
|
|
* Returns the autoGrow value |
|
389
|
|
|
* @param int $body (optional) The index of the body to get. |
|
390
|
|
|
* Pass null to get the default for new bodies. |
|
391
|
|
|
* @access public |
|
392
|
|
|
* @return mixed |
|
393
|
|
|
* @throws PEAR_Error |
|
394
|
|
|
*/ |
|
395
|
|
|
function getAutoGrow($body = null) |
|
396
|
|
|
{ |
|
397
|
|
|
if (!is_null($body)) { |
|
398
|
|
|
$ret = $this->_adjustTbodyCount($body, 'getAutoGrow'); |
|
399
|
|
|
if (PEAR::isError($ret)) { |
|
400
|
|
|
return $ret; |
|
401
|
|
|
} |
|
402
|
|
|
return $this->_tbodies[$body]->getAutoGrow(); |
|
403
|
|
|
} else { |
|
404
|
|
|
return $this->_autoGrow; |
|
405
|
|
|
} |
|
406
|
|
|
} |
|
407
|
|
|
|
|
408
|
|
|
/** |
|
409
|
|
|
* Sets the number of rows in the table body |
|
410
|
|
|
* @param int $rows The number of rows |
|
411
|
|
|
* @param int $body (optional) The index of the body to set. |
|
412
|
|
|
* @access public |
|
413
|
|
|
* @throws PEAR_Error |
|
414
|
|
|
*/ |
|
415
|
|
|
function setRowCount($rows, $body = 0) |
|
416
|
|
|
{ |
|
417
|
|
|
$ret = $this->_adjustTbodyCount($body, 'setRowCount'); |
|
418
|
|
|
if (PEAR::isError($ret)) { |
|
419
|
|
|
return $ret; |
|
420
|
|
|
} |
|
421
|
|
|
$this->_tbodies[$body]->setRowCount($rows); |
|
422
|
|
|
} |
|
423
|
|
|
|
|
424
|
|
|
/** |
|
425
|
|
|
* Sets the number of columns in the table |
|
426
|
|
|
* @param int $cols The number of columns |
|
427
|
|
|
* @param int $body (optional) The index of the body to set. |
|
428
|
|
|
* @access public |
|
429
|
|
|
* @throws PEAR_Error |
|
430
|
|
|
*/ |
|
431
|
|
|
function setColCount($cols, $body = 0) |
|
432
|
|
|
{ |
|
433
|
|
|
$ret = $this->_adjustTbodyCount($body, 'setColCount'); |
|
434
|
|
|
if (PEAR::isError($ret)) { |
|
435
|
|
|
return $ret; |
|
436
|
|
|
} |
|
437
|
|
|
$this->_tbodies[$body]->setColCount($cols); |
|
438
|
|
|
} |
|
439
|
|
|
|
|
440
|
|
|
/** |
|
441
|
|
|
* Returns the number of rows in the table |
|
442
|
|
|
* @param int $body (optional) The index of the body to get. |
|
443
|
|
|
* Pass null to get the total number of |
|
444
|
|
|
* rows in all bodies. |
|
445
|
|
|
* @access public |
|
446
|
|
|
* @return int |
|
447
|
|
|
* @throws PEAR_Error |
|
448
|
|
|
*/ |
|
449
|
|
View Code Duplication |
function getRowCount($body = null) |
|
450
|
|
|
{ |
|
451
|
|
|
if (!is_null($body)) { |
|
452
|
|
|
$ret = $this->_adjustTbodyCount($body, 'getRowCount'); |
|
|
|
|
|
|
453
|
|
|
if (PEAR::isError($ret)) { |
|
454
|
|
|
return $ret; |
|
455
|
|
|
} |
|
456
|
|
|
return $this->_tbodies[$body]->getRowCount(); |
|
457
|
|
|
} else { |
|
458
|
|
|
$rowCount = 0; |
|
459
|
|
|
for ($i = 0; $i < $this->_tbodyCount; $i++) { |
|
460
|
|
|
$rowCount += $this->_tbodies[$i]->getRowCount(); |
|
461
|
|
|
} |
|
462
|
|
|
return $rowCount; |
|
463
|
|
|
} |
|
464
|
|
|
} |
|
465
|
|
|
|
|
466
|
|
|
/** |
|
467
|
|
|
* Gets the number of columns in the table |
|
468
|
|
|
* |
|
469
|
|
|
* If a row index is specified, the count will not take |
|
470
|
|
|
* the spanned cells into account in the return value. |
|
471
|
|
|
* |
|
472
|
|
|
* @param int $row Row index to serve for cols count |
|
473
|
|
|
* @param int $body (optional) The index of the body to get. |
|
474
|
|
|
* @access public |
|
475
|
|
|
* @return int |
|
476
|
|
|
* @throws PEAR_Error |
|
477
|
|
|
*/ |
|
478
|
|
View Code Duplication |
function getColCount($row = null, $body = 0) |
|
479
|
|
|
{ |
|
480
|
|
|
$ret = $this->_adjustTbodyCount($body, 'getColCount'); |
|
|
|
|
|
|
481
|
|
|
if (PEAR::isError($ret)) { |
|
482
|
|
|
return $ret; |
|
483
|
|
|
} |
|
484
|
|
|
return $this->_tbodies[$body]->getColCount($row); |
|
485
|
|
|
} |
|
486
|
|
|
|
|
487
|
|
|
/** |
|
488
|
|
|
* Sets a rows type 'TH' or 'TD' |
|
489
|
|
|
* @param int $row Row index |
|
490
|
|
|
* @param string $type 'TH' or 'TD' |
|
491
|
|
|
* @param int $body (optional) The index of the body to set. |
|
492
|
|
|
* @access public |
|
493
|
|
|
* @throws PEAR_Error |
|
494
|
|
|
*/ |
|
495
|
|
|
function setRowType($row, $type, $body = 0) |
|
496
|
|
|
{ |
|
497
|
|
|
$ret = $this->_adjustTbodyCount($body, 'setRowType'); |
|
498
|
|
|
if (PEAR::isError($ret)) { |
|
499
|
|
|
return $ret; |
|
500
|
|
|
} |
|
501
|
|
|
$this->_tbodies[$body]->setRowType($row, $type); |
|
502
|
|
|
} |
|
503
|
|
|
|
|
504
|
|
|
/** |
|
505
|
|
|
* Sets a columns type 'TH' or 'TD' |
|
506
|
|
|
* @param int $col Column index |
|
507
|
|
|
* @param string $type 'TH' or 'TD' |
|
508
|
|
|
* @param int $body (optional) The index of the body to set. |
|
509
|
|
|
* Pass null to set for all bodies. |
|
510
|
|
|
* @access public |
|
511
|
|
|
* @throws PEAR_Error |
|
512
|
|
|
*/ |
|
513
|
|
View Code Duplication |
function setColType($col, $type, $body = null) |
|
514
|
|
|
{ |
|
515
|
|
|
if (!is_null($body)) { |
|
516
|
|
|
$ret = $this->_adjustTbodyCount($body, 'setColType'); |
|
517
|
|
|
if (PEAR::isError($ret)) { |
|
518
|
|
|
return $ret; |
|
519
|
|
|
} |
|
520
|
|
|
$this->_tbodies[$body]->setColType($col, $type); |
|
521
|
|
|
} else { |
|
522
|
|
|
for ($i = 0; $i < $this->_tbodyCount; $i++) { |
|
523
|
|
|
$this->_tbodies[$i]->setColType($col, $type); |
|
524
|
|
|
} |
|
525
|
|
|
} |
|
526
|
|
|
} |
|
527
|
|
|
|
|
528
|
|
|
/** |
|
529
|
|
|
* Sets the cell attributes for an existing cell. |
|
530
|
|
|
* |
|
531
|
|
|
* If the given indices do not exist and autoGrow is true then the given |
|
532
|
|
|
* row and/or col is automatically added. If autoGrow is false then an |
|
533
|
|
|
* error is returned. |
|
534
|
|
|
* @param int $row Row index |
|
535
|
|
|
* @param int $col Column index |
|
536
|
|
|
* @param mixed $attributes Associative array or string of |
|
537
|
|
|
* table row attributes |
|
538
|
|
|
* @param int $body (optional) The index of the body to set. |
|
539
|
|
|
* @access public |
|
540
|
|
|
* @throws PEAR_Error |
|
541
|
|
|
*/ |
|
542
|
|
|
function setCellAttributes($row, $col, $attributes, $body = 0) |
|
543
|
|
|
{ |
|
544
|
|
|
$ret = $this->_adjustTbodyCount($body, 'setCellAttributes'); |
|
545
|
|
|
if (PEAR::isError($ret)) { |
|
546
|
|
|
return $ret; |
|
547
|
|
|
} |
|
548
|
|
|
$ret = $this->_tbodies[$body]->setCellAttributes($row, $col, $attributes); |
|
549
|
|
|
if (PEAR::isError($ret)) { |
|
550
|
|
|
return $ret; |
|
551
|
|
|
} |
|
552
|
|
|
} |
|
553
|
|
|
|
|
554
|
|
|
/** |
|
555
|
|
|
* Updates the cell attributes passed but leaves other existing attributes |
|
556
|
|
|
* intact |
|
557
|
|
|
* @param int $row Row index |
|
558
|
|
|
* @param int $col Column index |
|
559
|
|
|
* @param mixed $attributes Associative array or string of table row |
|
560
|
|
|
* attributes |
|
561
|
|
|
* @param int $body (optional) The index of the body to set. |
|
562
|
|
|
* @access public |
|
563
|
|
|
* @throws PEAR_Error |
|
564
|
|
|
*/ |
|
565
|
|
|
function updateCellAttributes($row, $col, $attributes, $body = 0) |
|
566
|
|
|
{ |
|
567
|
|
|
$ret = $this->_adjustTbodyCount($body, 'updateCellAttributes'); |
|
568
|
|
|
if (PEAR::isError($ret)) { |
|
569
|
|
|
return $ret; |
|
570
|
|
|
} |
|
571
|
|
|
$ret = $this->_tbodies[$body]->updateCellAttributes($row, $col, $attributes); |
|
572
|
|
|
if (PEAR::isError($ret)) { |
|
573
|
|
|
return $ret; |
|
574
|
|
|
} |
|
575
|
|
|
} |
|
576
|
|
|
|
|
577
|
|
|
/** |
|
578
|
|
|
* Returns the attributes for a given cell |
|
579
|
|
|
* @param int $row Row index |
|
580
|
|
|
* @param int $col Column index |
|
581
|
|
|
* @param int $body (optional) The index of the body to get. |
|
582
|
|
|
* @return array |
|
583
|
|
|
* @access public |
|
584
|
|
|
* @throws PEAR_Error |
|
585
|
|
|
*/ |
|
586
|
|
|
function getCellAttributes($row, $col, $body = 0) |
|
587
|
|
|
{ |
|
588
|
|
|
$ret = $this->_adjustTbodyCount($body, 'getCellAttributes'); |
|
|
|
|
|
|
589
|
|
|
if (PEAR::isError($ret)) { |
|
590
|
|
|
return $ret; |
|
591
|
|
|
} |
|
592
|
|
|
return $this->_tbodies[$body]->getCellAttributes($row, $col); |
|
593
|
|
|
} |
|
594
|
|
|
|
|
595
|
|
|
/** |
|
596
|
|
|
* Sets the cell contents for an existing cell |
|
597
|
|
|
* |
|
598
|
|
|
* If the given indices do not exist and autoGrow is true then the given |
|
599
|
|
|
* row and/or col is automatically added. If autoGrow is false then an |
|
600
|
|
|
* error is returned. |
|
601
|
|
|
* @param int $row Row index |
|
602
|
|
|
* @param int $col Column index |
|
603
|
|
|
* @param mixed $contents May contain html or any object with a |
|
604
|
|
|
* toHTML() method; it is an array (with |
|
605
|
|
|
* strings and/or objects), $col will be |
|
606
|
|
|
* used as start offset and the array |
|
607
|
|
|
* elements will be set to this and the |
|
608
|
|
|
* following columns in $row |
|
609
|
|
|
* @param string $type (optional) Cell type either 'TH' or 'TD' |
|
610
|
|
|
* @param int $body (optional) The index of the body to set. |
|
611
|
|
|
* @access public |
|
612
|
|
|
* @throws PEAR_Error |
|
613
|
|
|
*/ |
|
614
|
|
|
function setCellContents($row, $col, $contents, $type = 'TD', $body = 0) |
|
615
|
|
|
{ |
|
616
|
|
|
$ret = $this->_adjustTbodyCount($body, 'setCellContents'); |
|
617
|
|
|
if (PEAR::isError($ret)) { |
|
618
|
|
|
return $ret; |
|
619
|
|
|
} |
|
620
|
|
|
$ret = $this->_tbodies[$body]->setCellContents($row, $col, $contents, $type); |
|
621
|
|
|
if (PEAR::isError($ret)) { |
|
622
|
|
|
return $ret; |
|
623
|
|
|
} |
|
624
|
|
|
} |
|
625
|
|
|
|
|
626
|
|
|
/** |
|
627
|
|
|
* Returns the cell contents for an existing cell |
|
628
|
|
|
* @param int $row Row index |
|
629
|
|
|
* @param int $col Column index |
|
630
|
|
|
* @param int $body (optional) The index of the body to get. |
|
631
|
|
|
* @access public |
|
632
|
|
|
* @return mixed |
|
633
|
|
|
* @throws PEAR_Error |
|
634
|
|
|
*/ |
|
635
|
|
|
function getCellContents($row, $col, $body = 0) |
|
636
|
|
|
{ |
|
637
|
|
|
$ret = $this->_adjustTbodyCount($body, 'getCellContents'); |
|
638
|
|
|
if (PEAR::isError($ret)) { |
|
639
|
|
|
return $ret; |
|
640
|
|
|
} |
|
641
|
|
|
return $this->_tbodies[$body]->getCellContents($row, $col); |
|
642
|
|
|
} |
|
643
|
|
|
|
|
644
|
|
|
/** |
|
645
|
|
|
* Sets the contents of a header cell |
|
646
|
|
|
* @param int $row |
|
647
|
|
|
* @param int $col |
|
648
|
|
|
* @param mixed $contents |
|
649
|
|
|
* @param mixed $attributes Associative array or string of |
|
650
|
|
|
* table row attributes |
|
651
|
|
|
* @param int $body (optional) The index of the body to set. |
|
652
|
|
|
* @access public |
|
653
|
|
|
* @throws PEAR_Error |
|
654
|
|
|
*/ |
|
655
|
|
|
function setHeaderContents($row, $col, $contents, $attributes = null, |
|
656
|
|
|
$body = 0) |
|
657
|
|
|
{ |
|
658
|
|
|
$ret = $this->_adjustTbodyCount($body, 'setHeaderContents'); |
|
659
|
|
|
if (PEAR::isError($ret)) { |
|
660
|
|
|
return $ret; |
|
661
|
|
|
} |
|
662
|
|
|
$this->_tbodies[$body]->setHeaderContents($row, $col, $contents, $attributes); |
|
663
|
|
|
} |
|
664
|
|
|
|
|
665
|
|
|
/** |
|
666
|
|
|
* Adds a table row and returns the row identifier |
|
667
|
|
|
* @param array $contents (optional) Must be a indexed array of |
|
668
|
|
|
* valid cell contents |
|
669
|
|
|
* @param mixed $attributes (optional) Associative array or string |
|
670
|
|
|
* of table row attributes. This can also |
|
671
|
|
|
* be an array of attributes, in which |
|
672
|
|
|
* case the attributes will be repeated |
|
673
|
|
|
* in a loop. |
|
674
|
|
|
* @param string $type (optional) Cell type either 'th' or 'td' |
|
675
|
|
|
* @param bool $inTR false if attributes are to be applied |
|
676
|
|
|
* in TD tags; true if attributes are to |
|
677
|
|
|
* �be applied in TR tag |
|
678
|
|
|
* @param int $body (optional) The index of the body to use. |
|
679
|
|
|
* @return int |
|
680
|
|
|
* @access public |
|
681
|
|
|
* @throws PEAR_Error |
|
682
|
|
|
*/ |
|
683
|
|
View Code Duplication |
function addRow($contents = null, $attributes = null, $type = 'td', |
|
684
|
|
|
$inTR = false, $body = 0) |
|
685
|
|
|
{ |
|
686
|
|
|
$ret = $this->_adjustTbodyCount($body, 'addRow'); |
|
|
|
|
|
|
687
|
|
|
if (PEAR::isError($ret)) { |
|
688
|
|
|
return $ret; |
|
689
|
|
|
} |
|
690
|
|
|
$ret = $this->_tbodies[$body]->addRow($contents, $attributes, $type, $inTR); |
|
691
|
|
|
return $ret; |
|
692
|
|
|
} |
|
693
|
|
|
|
|
694
|
|
|
/** |
|
695
|
|
|
* Sets the row attributes for an existing row |
|
696
|
|
|
* @param int $row Row index |
|
697
|
|
|
* @param mixed $attributes Associative array or string of table row |
|
698
|
|
|
* attributes. This can also be an array of |
|
699
|
|
|
* attributes, in which case the attributes |
|
700
|
|
|
* will be repeated in a loop. |
|
701
|
|
|
* @param bool $inTR false if attributes are to be applied in |
|
702
|
|
|
* TD tags; true if attributes are to be |
|
703
|
|
|
* applied in TR tag |
|
704
|
|
|
* @param int $body (optional) The index of the body to set. |
|
705
|
|
|
* @access public |
|
706
|
|
|
* @throws PEAR_Error |
|
707
|
|
|
*/ |
|
708
|
|
View Code Duplication |
function setRowAttributes($row, $attributes, $inTR = false, $body = 0) |
|
709
|
|
|
{ |
|
710
|
|
|
$ret = $this->_adjustTbodyCount($body, 'setRowAttributes'); |
|
711
|
|
|
if (PEAR::isError($ret)) { |
|
712
|
|
|
return $ret; |
|
713
|
|
|
} |
|
714
|
|
|
$ret = $this->_tbodies[$body]->setRowAttributes($row, $attributes, $inTR); |
|
715
|
|
|
if (PEAR::isError($ret)) { |
|
716
|
|
|
return $ret; |
|
717
|
|
|
} |
|
718
|
|
|
} |
|
719
|
|
|
|
|
720
|
|
|
/** |
|
721
|
|
|
* Updates the row attributes for an existing row |
|
722
|
|
|
* @param int $row Row index |
|
723
|
|
|
* @param mixed $attributes Associative array or string of table row |
|
724
|
|
|
* attributes |
|
725
|
|
|
* @param bool $inTR false if attributes are to be applied in |
|
726
|
|
|
* TD tags; true if attributes are to be |
|
727
|
|
|
* applied in TR tag |
|
728
|
|
|
* @param int $body (optional) The index of the body to set. |
|
729
|
|
|
* @access public |
|
730
|
|
|
* @throws PEAR_Error |
|
731
|
|
|
*/ |
|
732
|
|
View Code Duplication |
function updateRowAttributes($row, $attributes = null, $inTR = false, |
|
733
|
|
|
$body = 0) |
|
734
|
|
|
{ |
|
735
|
|
|
$ret = $this->_adjustTbodyCount($body, 'updateRowAttributes'); |
|
736
|
|
|
if (PEAR::isError($ret)) { |
|
737
|
|
|
return $ret; |
|
738
|
|
|
} |
|
739
|
|
|
$ret = $this->_tbodies[$body]->updateRowAttributes($row, $attributes, $inTR); |
|
740
|
|
|
if (PEAR::isError($ret)) { |
|
741
|
|
|
return $ret; |
|
742
|
|
|
} |
|
743
|
|
|
} |
|
744
|
|
|
|
|
745
|
|
|
/** |
|
746
|
|
|
* Returns the attributes for a given row as contained in the TR tag |
|
747
|
|
|
* @param int $row Row index |
|
748
|
|
|
* @param int $body (optional) The index of the body to get. |
|
749
|
|
|
* @return array |
|
750
|
|
|
* @access public |
|
751
|
|
|
* @throws PEAR_Error |
|
752
|
|
|
*/ |
|
753
|
|
|
function getRowAttributes($row, $body = 0) |
|
754
|
|
|
{ |
|
755
|
|
|
$ret = $this->_adjustTbodyCount($body, 'getRowAttributes'); |
|
|
|
|
|
|
756
|
|
|
if (PEAR::isError($ret)) { |
|
757
|
|
|
return $ret; |
|
758
|
|
|
} |
|
759
|
|
|
return $this->_tbodies[$body]->getRowAttributes($row); |
|
760
|
|
|
} |
|
761
|
|
|
|
|
762
|
|
|
/** |
|
763
|
|
|
* Alternates the row attributes starting at $start |
|
764
|
|
|
* @param int $start Row index of row in which alternating |
|
765
|
|
|
* begins |
|
766
|
|
|
* @param mixed $attributes1 Associative array or string of table |
|
767
|
|
|
* row attributes |
|
768
|
|
|
* @param mixed $attributes2 Associative array or string of table |
|
769
|
|
|
* row attributes |
|
770
|
|
|
* @param bool $inTR false if attributes are to be applied |
|
771
|
|
|
* in TD tags; true if attributes are to |
|
772
|
|
|
* be applied in TR tag |
|
773
|
|
|
* @param int $firstAttributes (optional) Which attributes should be |
|
774
|
|
|
* applied to the first row, 1 or 2. |
|
775
|
|
|
* @param int $body (optional) The index of the body to set. |
|
776
|
|
|
* Pass null to set for all bodies. |
|
777
|
|
|
* @access public |
|
778
|
|
|
* @throws PEAR_Error |
|
779
|
|
|
*/ |
|
780
|
|
|
function altRowAttributes($start, $attributes1, $attributes2, $inTR = false, |
|
781
|
|
|
$firstAttributes = 1, $body = null) |
|
782
|
|
|
{ |
|
783
|
|
|
if (!is_null($body)) { |
|
784
|
|
|
$ret = $this->_adjustTbodyCount($body, 'altRowAttributes'); |
|
785
|
|
|
if (PEAR::isError($ret)) { |
|
786
|
|
|
return $ret; |
|
787
|
|
|
} |
|
788
|
|
|
$this->_tbodies[$body]->altRowAttributes($start, $attributes1, |
|
789
|
|
|
$attributes2, $inTR, $firstAttributes); |
|
790
|
|
|
} else { |
|
791
|
|
|
for ($i = 0; $i < $this->_tbodyCount; $i++) { |
|
792
|
|
|
$this->_tbodies[$i]->altRowAttributes($start, $attributes1, |
|
793
|
|
|
$attributes2, $inTR, $firstAttributes); |
|
794
|
|
|
// if the tbody's row count is odd, toggle $firstAttributes to |
|
795
|
|
|
// prevent the next tbody's first row from having the same |
|
796
|
|
|
// attributes as this tbody's last row. |
|
797
|
|
|
if ($this->_tbodies[$i]->getRowCount() % 2) { |
|
798
|
|
|
$firstAttributes ^= 3; |
|
799
|
|
|
} |
|
800
|
|
|
} |
|
801
|
|
|
} |
|
802
|
|
|
} |
|
803
|
|
|
|
|
804
|
|
|
/** |
|
805
|
|
|
* Adds a table column and returns the column identifier |
|
806
|
|
|
* @param array $contents (optional) Must be a indexed array of |
|
807
|
|
|
* valid cell contents |
|
808
|
|
|
* @param mixed $attributes (optional) Associative array or string |
|
809
|
|
|
* of table row attributes |
|
810
|
|
|
* @param string $type (optional) Cell type either 'th' or 'td' |
|
811
|
|
|
* @param int $body (optional) The index of the body to use. |
|
812
|
|
|
* @return int |
|
813
|
|
|
* @access public |
|
814
|
|
|
* @throws PEAR_Error |
|
815
|
|
|
*/ |
|
816
|
|
View Code Duplication |
function addCol($contents = null, $attributes = null, $type = 'td', $body = 0) |
|
817
|
|
|
{ |
|
818
|
|
|
$ret = $this->_adjustTbodyCount($body, 'addCol'); |
|
|
|
|
|
|
819
|
|
|
if (PEAR::isError($ret)) { |
|
820
|
|
|
return $ret; |
|
821
|
|
|
} |
|
822
|
|
|
return $this->_tbodies[$body]->addCol($contents, $attributes, $type); |
|
823
|
|
|
} |
|
824
|
|
|
|
|
825
|
|
|
/** |
|
826
|
|
|
* Sets the column attributes for an existing column |
|
827
|
|
|
* @param int $col Column index |
|
828
|
|
|
* @param mixed $attributes (optional) Associative array or string |
|
829
|
|
|
* of table row attributes |
|
830
|
|
|
* @param int $body (optional) The index of the body to set. |
|
831
|
|
|
* Pass null to set for all bodies. |
|
832
|
|
|
* @access public |
|
833
|
|
|
* @throws PEAR_Error |
|
834
|
|
|
*/ |
|
835
|
|
View Code Duplication |
function setColAttributes($col, $attributes = null, $body = null) |
|
836
|
|
|
{ |
|
837
|
|
|
if (!is_null($body)) { |
|
838
|
|
|
$ret = $this->_adjustTbodyCount($body, 'setColAttributes'); |
|
839
|
|
|
if (PEAR::isError($ret)) { |
|
840
|
|
|
return $ret; |
|
841
|
|
|
} |
|
842
|
|
|
$this->_tbodies[$body]->setColAttributes($col, $attributes); |
|
843
|
|
|
} else { |
|
844
|
|
|
for ($i = 0; $i < $this->_tbodyCount; $i++) { |
|
845
|
|
|
$this->_tbodies[$i]->setColAttributes($col, $attributes); |
|
846
|
|
|
} |
|
847
|
|
|
} |
|
848
|
|
|
} |
|
849
|
|
|
|
|
850
|
|
|
/** |
|
851
|
|
|
* Updates the column attributes for an existing column |
|
852
|
|
|
* @param int $col Column index |
|
853
|
|
|
* @param mixed $attributes (optional) Associative array or |
|
854
|
|
|
* string of table row attributes |
|
855
|
|
|
* @param int $body (optional) The index of the body to set. |
|
856
|
|
|
* Pass null to set for all bodies. |
|
857
|
|
|
* @access public |
|
858
|
|
|
* @throws PEAR_Error |
|
859
|
|
|
*/ |
|
860
|
|
View Code Duplication |
function updateColAttributes($col, $attributes = null, $body = null) |
|
861
|
|
|
{ |
|
862
|
|
|
if (!is_null($body)) { |
|
863
|
|
|
$ret = $this->_adjustTbodyCount($body, 'updateColAttributes'); |
|
864
|
|
|
if (PEAR::isError($ret)) { |
|
865
|
|
|
return $ret; |
|
866
|
|
|
} |
|
867
|
|
|
$this->_tbodies[$body]->updateColAttributes($col, $attributes); |
|
868
|
|
|
} else { |
|
869
|
|
|
for ($i = 0; $i < $this->_tbodyCount; $i++) { |
|
870
|
|
|
$this->_tbodies[$i]->updateColAttributes($col, $attributes); |
|
871
|
|
|
} |
|
872
|
|
|
} |
|
873
|
|
|
} |
|
874
|
|
|
|
|
875
|
|
|
/** |
|
876
|
|
|
* Sets the attributes for all cells |
|
877
|
|
|
* @param mixed $attributes (optional) Associative array or |
|
878
|
|
|
* string of table row attributes |
|
879
|
|
|
* @param int $body (optional) The index of the body to set. |
|
880
|
|
|
* Pass null to set for all bodies. |
|
881
|
|
|
* @access public |
|
882
|
|
|
* @throws PEAR_Error |
|
883
|
|
|
*/ |
|
884
|
|
View Code Duplication |
function setAllAttributes($attributes = null, $body = null) |
|
885
|
|
|
{ |
|
886
|
|
|
if (!is_null($body)) { |
|
887
|
|
|
$ret = $this->_adjustTbodyCount($body, 'setAllAttributes'); |
|
888
|
|
|
if (PEAR::isError($ret)) { |
|
889
|
|
|
return $ret; |
|
890
|
|
|
} |
|
891
|
|
|
$this->_tbodies[$body]->setAllAttributes($attributes); |
|
892
|
|
|
} else { |
|
893
|
|
|
for ($i = 0; $i < $this->_tbodyCount; $i++) { |
|
894
|
|
|
$this->_tbodies[$i]->setAllAttributes($attributes); |
|
895
|
|
|
} |
|
896
|
|
|
} |
|
897
|
|
|
} |
|
898
|
|
|
|
|
899
|
|
|
/** |
|
900
|
|
|
* Updates the attributes for all cells |
|
901
|
|
|
* @param mixed $attributes (optional) Associative array or string |
|
902
|
|
|
* of table row attributes |
|
903
|
|
|
* @param int $body (optional) The index of the body to set. |
|
904
|
|
|
* Pass null to set for all bodies. |
|
905
|
|
|
* @access public |
|
906
|
|
|
* @throws PEAR_Error |
|
907
|
|
|
*/ |
|
908
|
|
View Code Duplication |
function updateAllAttributes($attributes = null, $body = null) |
|
909
|
|
|
{ |
|
910
|
|
|
if (!is_null($body)) { |
|
911
|
|
|
$ret = $this->_adjustTbodyCount($body, 'updateAllAttributes'); |
|
912
|
|
|
if (PEAR::isError($ret)) { |
|
913
|
|
|
return $ret; |
|
914
|
|
|
} |
|
915
|
|
|
$this->_tbodies[$body]->updateAllAttributes($attributes); |
|
916
|
|
|
} else { |
|
917
|
|
|
for ($i = 0; $i < $this->_tbodyCount; $i++) { |
|
918
|
|
|
$this->_tbodies[$i]->updateAllAttributes($attributes); |
|
919
|
|
|
} |
|
920
|
|
|
} |
|
921
|
|
|
} |
|
922
|
|
|
|
|
923
|
|
|
/** |
|
924
|
|
|
* Returns the table structure as HTML |
|
925
|
|
|
* @access public |
|
926
|
|
|
* @return string |
|
927
|
|
|
*/ |
|
928
|
|
|
function toHtml() |
|
929
|
|
|
{ |
|
930
|
|
|
$strHtml = ''; |
|
931
|
|
|
$tabs = $this->_getTabs(); |
|
932
|
|
|
$tab = $this->_getTab(); |
|
933
|
|
|
$lnEnd = $this->_getLineEnd(); |
|
934
|
|
|
$tBodyColCounts = array(); |
|
935
|
|
|
for ($i = 0; $i < $this->_tbodyCount; $i++) { |
|
936
|
|
|
$tBodyColCounts[] = $this->_tbodies[$i]->getColCount(); |
|
937
|
|
|
} |
|
938
|
|
|
$tBodyMaxColCount = 0; |
|
939
|
|
|
if (count($tBodyColCounts) > 0) { |
|
940
|
|
|
$tBodyMaxColCount = max($tBodyColCounts); |
|
941
|
|
|
} |
|
942
|
|
|
if ($this->_comment) { |
|
943
|
|
|
$strHtml .= $tabs . "<!-- $this->_comment -->" . $lnEnd; |
|
944
|
|
|
} |
|
945
|
|
|
if ($this->getRowCount() > 0 && $tBodyMaxColCount > 0) { |
|
946
|
|
|
$strHtml .= |
|
947
|
|
|
$tabs . '<table' . $this->_getAttrString($this->_attributes) . '>' . $lnEnd; |
|
948
|
|
|
if (!empty($this->_caption)) { |
|
949
|
|
|
$attr = $this->_caption['attr']; |
|
950
|
|
|
$contents = $this->_caption['contents']; |
|
951
|
|
|
$strHtml .= $tabs . $tab . '<caption' . $this->_getAttrString($attr) . '>'; |
|
952
|
|
|
if (is_array($contents)) { |
|
953
|
|
|
$contents = implode(', ', $contents); |
|
954
|
|
|
} |
|
955
|
|
|
$strHtml .= $contents; |
|
956
|
|
|
$strHtml .= '</caption>' . $lnEnd; |
|
957
|
|
|
} |
|
958
|
|
|
if (!empty($this->_colgroup)) { |
|
959
|
|
|
foreach ($this->_colgroup as $g => $col) { |
|
960
|
|
|
$attr = $this->_colgroup[$g]['attr']; |
|
961
|
|
|
$contents = $this->_colgroup[$g]['contents']; |
|
962
|
|
|
$strHtml .= $tabs . $tab . '<colgroup' . $this->_getAttrString($attr) . '>'; |
|
963
|
|
|
if (!empty($contents)) { |
|
964
|
|
|
$strHtml .= $lnEnd; |
|
965
|
|
|
if (!is_array($contents)) { |
|
966
|
|
|
$contents = array($contents); |
|
967
|
|
|
} |
|
968
|
|
|
foreach ($contents as $a => $colAttr) { |
|
969
|
|
|
$attr = $this->_parseAttributes($colAttr); |
|
970
|
|
|
$strHtml .= $tabs . $tab . $tab . '<col' . $this->_getAttrString($attr) . ' />' . $lnEnd; |
|
|
|
|
|
|
971
|
|
|
} |
|
972
|
|
|
$strHtml .= $tabs . $tab; |
|
973
|
|
|
} |
|
974
|
|
|
$strHtml .= '</colgroup>' . $lnEnd; |
|
975
|
|
|
} |
|
976
|
|
|
} |
|
977
|
|
|
if ($this->_useTGroups) { |
|
978
|
|
|
$tHeadColCount = 0; |
|
979
|
|
|
if ($this->_thead !== null) { |
|
980
|
|
|
$tHeadColCount = $this->_thead->getColCount(); |
|
981
|
|
|
} |
|
982
|
|
|
$tFootColCount = 0; |
|
983
|
|
|
if ($this->_tfoot !== null) { |
|
984
|
|
|
$tFootColCount = $this->_tfoot->getColCount(); |
|
985
|
|
|
} |
|
986
|
|
|
$maxColCount = max($tHeadColCount, $tFootColCount, $tBodyMaxColCount); |
|
987
|
|
View Code Duplication |
if ($this->_thead !== null) { |
|
988
|
|
|
$this->_thead->setColCount($maxColCount); |
|
989
|
|
|
if ($this->_thead->getRowCount() > 0) { |
|
990
|
|
|
$strHtml .= $tabs . $tab . '<thead' . |
|
991
|
|
|
$this->_getAttrString($this->_thead->_attributes) . |
|
992
|
|
|
'>' . $lnEnd; |
|
993
|
|
|
$strHtml .= $this->_thead->toHtml($tabs, $tab); |
|
994
|
|
|
$strHtml .= $tabs . $tab . '</thead>' . $lnEnd; |
|
995
|
|
|
} |
|
996
|
|
|
} |
|
997
|
|
View Code Duplication |
if ($this->_tfoot !== null) { |
|
998
|
|
|
$this->_tfoot->setColCount($maxColCount); |
|
999
|
|
|
if ($this->_tfoot->getRowCount() > 0) { |
|
1000
|
|
|
$strHtml .= $tabs . $tab . '<tfoot' . |
|
1001
|
|
|
$this->_getAttrString($this->_tfoot->_attributes) . |
|
1002
|
|
|
'>' . $lnEnd; |
|
1003
|
|
|
$strHtml .= $this->_tfoot->toHtml($tabs, $tab); |
|
1004
|
|
|
$strHtml .= $tabs . $tab . '</tfoot>' . $lnEnd; |
|
1005
|
|
|
} |
|
1006
|
|
|
} |
|
1007
|
|
|
for ($i = 0; $i < $this->_tbodyCount; $i++) { |
|
1008
|
|
|
$this->_tbodies[$i]->setColCount($maxColCount); |
|
1009
|
|
|
if ($this->_tbodies[$i]->getRowCount() > 0) { |
|
1010
|
|
|
$strHtml .= $tabs . $tab . '<tbody' . |
|
1011
|
|
|
$this->_getAttrString($this->_tbodies[$i]->_attributes) . |
|
1012
|
|
|
'>' . $lnEnd; |
|
1013
|
|
|
$strHtml .= $this->_tbodies[$i]->toHtml($tabs, $tab); |
|
1014
|
|
|
$strHtml .= $tabs . $tab . '</tbody>' . $lnEnd; |
|
1015
|
|
|
} |
|
1016
|
|
|
} |
|
1017
|
|
|
} else { |
|
1018
|
|
|
for ($i = 0; $i < $this->_tbodyCount; $i++) { |
|
1019
|
|
|
$this->_tbodies[$i]->setAutoFill($this->_autoFill); |
|
1020
|
|
|
$strHtml .= $this->_tbodies[$i]->toHtml($tabs, $tab); |
|
1021
|
|
|
} |
|
1022
|
|
|
} |
|
1023
|
|
|
$strHtml .= $tabs . '</table>' . $lnEnd; |
|
1024
|
|
|
} |
|
1025
|
|
|
return $strHtml; |
|
1026
|
|
|
} |
|
1027
|
|
|
|
|
1028
|
|
|
} |
|
1029
|
|
|
|
|
1030
|
|
|
?> |
|
|
|
|
|
|
1031
|
|
|
|