1 |
jonen |
1.1 |
<?php |
2 |
|
|
/** |
3 |
|
|
* |
4 |
jonen |
1.3 |
* $Id: InfoTable.inc,v 1.16 2003/03/14 01:12:30 hemna Exp $ |
5 |
jonen |
1.1 |
* |
6 |
|
|
* This renders a table with a title |
7 |
|
|
* optional column headers |
8 |
|
|
* and rows |
9 |
|
|
* |
10 |
|
|
* @author Walter A. Boring IV |
11 |
|
|
* @package phpHtmlLib |
12 |
|
|
*/ |
13 |
|
|
|
14 |
|
|
|
15 |
|
|
/** |
16 |
|
|
* This is a widget class that can build |
17 |
|
|
* and render data in a nicely formated table |
18 |
|
|
* with a title, column headers and data |
19 |
|
|
* |
20 |
|
|
* @author Walter A. Boring IV |
21 |
jonen |
1.2 |
* @package phpHtmlLib |
22 |
jonen |
1.1 |
*/ |
23 |
|
|
class InfoTable extends BaseWidget { |
24 |
|
|
|
25 |
jonen |
1.3 |
/** |
26 |
|
|
* this holds the column header |
27 |
|
|
* titles. |
28 |
|
|
*/ |
29 |
|
|
var $_headers = array(); |
30 |
|
|
|
31 |
|
|
/** |
32 |
|
|
* this holds the default cellpadding |
33 |
|
|
*/ |
34 |
|
|
var $_cellpadding=2; |
35 |
|
|
|
36 |
|
|
/** |
37 |
|
|
* This holds the default cellspacing |
38 |
|
|
*/ |
39 |
|
|
var $_cellspacing=0; |
40 |
|
|
|
41 |
|
|
/** |
42 |
|
|
* The default class used for the |
43 |
|
|
* title |
44 |
|
|
*/ |
45 |
|
|
var $_title_css_class = "title"; |
46 |
|
|
|
47 |
|
|
/** |
48 |
|
|
* The default alignment for the |
49 |
|
|
* title text in the caption. |
50 |
|
|
*/ |
51 |
|
|
var $_title_text_align = "left"; |
52 |
|
|
|
53 |
|
|
/** |
54 |
|
|
* Flag to tell the class to render |
55 |
|
|
* the vertical cell border |
56 |
|
|
*/ |
57 |
|
|
var $_show_vertical_cellborder = TRUE; |
58 |
|
|
|
59 |
|
|
|
60 |
|
|
|
61 |
|
|
/** |
62 |
|
|
* The constructor |
63 |
|
|
* |
64 |
|
|
* @param string - the title |
65 |
|
|
* @param string - the width of the table |
66 |
|
|
* @param string - the alignment |
67 |
|
|
*/ |
68 |
|
|
function InfoTable( $title, $width="100%", $align=NULL ) { |
69 |
|
|
$this->set_title($title); |
70 |
|
|
$this->set_width($width); |
71 |
|
|
$this->set_align($align); |
72 |
|
|
} |
73 |
|
|
|
74 |
|
|
/** |
75 |
|
|
* This function renders the object. |
76 |
|
|
* |
77 |
|
|
* @param int - the indentation level for |
78 |
|
|
* the container. |
79 |
|
|
* @param int - the output debug flag to |
80 |
|
|
* maintain compatibility w/ the API. |
81 |
|
|
* |
82 |
|
|
* @return string the raw html output. |
83 |
|
|
*/ |
84 |
|
|
function render($indent_level=1, $output_debug=0) { |
85 |
|
|
$table = html_table( $this->get_width(), 0, |
86 |
|
|
$this->get_cellspacing(), |
87 |
|
|
$this->get_cellpadding(), |
88 |
|
|
$this->get_align()); |
89 |
|
|
$table->set_class( "infotable" ); |
90 |
|
|
$table->add( $this->_build_title() ); |
91 |
|
|
|
92 |
|
|
$row = $this->_build_header(); |
93 |
|
|
if ( $row != NULL ) { |
94 |
|
|
$table->add_row( $row ); |
95 |
|
|
} |
96 |
|
|
|
97 |
|
|
//now go thru the rows of data |
98 |
|
|
//and add them |
99 |
|
|
foreach( $this->data as $row ) { |
100 |
|
|
if ( (count($row) == 1) && is_object($row[0]) && (is_a($row[0], "TRtag") || |
101 |
|
|
is_a($row[0], "TDtag")) ) { |
102 |
jonen |
1.2 |
$table->add_row( $row[0] ); |
103 |
|
|
} else { |
104 |
|
|
$tr = new TRtag; |
105 |
|
|
$cnt = count( $row ); |
106 |
jonen |
1.3 |
foreach( $row as $index => $data ) { |
107 |
jonen |
1.2 |
$td = $this->_build_td("", "", $index+1, $cnt ); |
108 |
|
|
$td->add( $data ); |
109 |
|
|
$tr->add( $td ); |
110 |
|
|
} |
111 |
|
|
$table->add_row( $tr ); |
112 |
|
|
} |
113 |
jonen |
1.3 |
} |
114 |
|
|
return $table->render($indent_level, $output_debug); |
115 |
|
|
} |
116 |
|
|
|
117 |
|
|
|
118 |
|
|
|
119 |
|
|
|
120 |
|
|
/*****************/ |
121 |
|
|
/* Public APIs */ |
122 |
|
|
/*****************/ |
123 |
|
|
|
124 |
|
|
/** |
125 |
|
|
* This function is used to set the column |
126 |
|
|
* header text for each column |
127 |
|
|
* |
128 |
|
|
* @param string - the title for the column |
129 |
|
|
* @param string - the alignment of the title |
130 |
|
|
*/ |
131 |
|
|
function add_column_header( $title, $width, $align="center") { |
132 |
|
|
$this->_headers[] = array("title" => $title, |
133 |
|
|
"width" => $width, |
134 |
|
|
"align" => $align); |
135 |
|
|
} |
136 |
|
|
|
137 |
|
|
/** |
138 |
|
|
* This function is used to add a row to the table |
139 |
|
|
* |
140 |
|
|
* @param mixed - n number of items to push |
141 |
|
|
*/ |
142 |
|
|
function add_row() { |
143 |
|
|
$num_args = func_num_args(); |
144 |
|
|
$arr = array(); |
145 |
|
|
for ( $i=0;$i<$num_args;$i++ ) { |
146 |
|
|
$arr[] = func_get_arg($i); |
147 |
|
|
} |
148 |
|
|
$this->data[] = $arr; |
149 |
|
|
} |
150 |
|
|
|
151 |
|
|
|
152 |
|
|
/** |
153 |
|
|
* This sets the cellpadding attribute |
154 |
|
|
* for this object. |
155 |
|
|
* |
156 |
|
|
* @param int - the cellpadding value |
157 |
|
|
*/ |
158 |
|
|
function set_cellpadding( $pad=0 ) { |
159 |
|
|
$this->_cellpadding = $pad; |
160 |
|
|
} |
161 |
|
|
|
162 |
|
|
/** |
163 |
|
|
* This gets the current value of the |
164 |
|
|
* cellpadding |
165 |
|
|
* |
166 |
|
|
* @return int - the current cellpadding |
167 |
|
|
*/ |
168 |
|
|
function get_cellpadding() { |
169 |
|
|
return $this->_cellpadding; |
170 |
|
|
} |
171 |
|
|
|
172 |
|
|
/** |
173 |
|
|
* This sets the cellspacing attribute |
174 |
|
|
* for this object. |
175 |
|
|
* |
176 |
|
|
* @param int - the cellspacing value |
177 |
|
|
*/ |
178 |
|
|
function set_cellspacing( $spacing=0 ) { |
179 |
|
|
$this->_cellspacing = $spacing; |
180 |
|
|
} |
181 |
|
|
|
182 |
|
|
/** |
183 |
|
|
* This gets the current value of the |
184 |
|
|
* cellspacing |
185 |
|
|
* |
186 |
|
|
* @return int - the current cellspacing |
187 |
|
|
*/ |
188 |
|
|
function get_cellspacing() { |
189 |
|
|
return $this->_cellspacing; |
190 |
|
|
} |
191 |
|
|
|
192 |
|
|
/** |
193 |
|
|
* this function lets you change the |
194 |
|
|
* text alignment of the text in the title |
195 |
|
|
* |
196 |
|
|
* @param string - the alignment. |
197 |
|
|
*/ |
198 |
|
|
function set_title_text_align( $align="left" ) { |
199 |
|
|
$this->_title_text_align = $align; |
200 |
|
|
} |
201 |
|
|
|
202 |
|
|
/** |
203 |
|
|
* this function lets gets the |
204 |
|
|
* default css class for the title |
205 |
|
|
* |
206 |
|
|
* @return string - the css class to use |
207 |
|
|
*/ |
208 |
|
|
function get_title_text_align( ) { |
209 |
|
|
return $this->_title_text_align; |
210 |
|
|
} |
211 |
|
|
|
212 |
|
|
/** |
213 |
|
|
* this function sets the flag to tell |
214 |
|
|
* the object to render (or not) the |
215 |
|
|
* vertical cell borders |
216 |
|
|
* |
217 |
|
|
* @param boolean |
218 |
|
|
*/ |
219 |
|
|
function set_vertical_cellborder( $flag=TRUE ) { |
220 |
|
|
$this->_show_vertical_cellborder = $flag; |
221 |
|
|
} |
222 |
|
|
|
223 |
|
|
/** |
224 |
|
|
* this function lets gets the |
225 |
|
|
* default css class for the title |
226 |
|
|
* |
227 |
|
|
* @return string - the css class to use |
228 |
|
|
*/ |
229 |
|
|
function get_vertical_cellborder( ) { |
230 |
|
|
return $this->_show_vertical_cellborder; |
231 |
|
|
} |
232 |
|
|
|
233 |
|
|
|
234 |
|
|
|
235 |
|
|
/******************/ |
236 |
|
|
/* Private APIs */ |
237 |
|
|
/******************/ |
238 |
|
|
|
239 |
|
|
|
240 |
|
|
/** |
241 |
|
|
* This function builds the title |
242 |
|
|
* container |
243 |
|
|
* |
244 |
|
|
* @return CAPTIONtag object |
245 |
|
|
*/ |
246 |
|
|
function _build_title() { |
247 |
|
|
$caption = new CAPTIONtag( array("style" => "text-align:".$this->get_title_text_align().";", |
248 |
|
|
"class" => "title"), |
249 |
|
|
$this->title ); |
250 |
|
|
return $caption; |
251 |
|
|
} |
252 |
|
|
|
253 |
|
|
/** |
254 |
|
|
* This function builds the table header |
255 |
|
|
* |
256 |
|
|
* @return TRtag object |
257 |
|
|
*/ |
258 |
|
|
function _build_header() { |
259 |
|
|
$tr = new TRtag; |
260 |
|
|
|
261 |
|
|
$cnt = count( $this->_headers ); |
262 |
|
|
if ( $cnt > 0 ) { |
263 |
|
|
$cur_col = 1; |
264 |
|
|
foreach( $this->_headers as $header ) { |
265 |
|
|
$td = $this->_build_td( $header["width"], $header["align"], $cur_col, $cnt); |
266 |
|
|
if ( $cur_col == $cnt ) { |
267 |
|
|
$class = "headerlast"; |
268 |
|
|
} else { |
269 |
|
|
$class = "header"; |
270 |
|
|
} |
271 |
|
|
$td->set_class( $class ); |
272 |
|
|
$td->push( $header["title"] ); |
273 |
|
|
$tr->push( $td ); |
274 |
|
|
$cur_col++; |
275 |
|
|
} |
276 |
|
|
return $tr; |
277 |
|
|
} else { |
278 |
|
|
return NULL; |
279 |
|
|
} |
280 |
|
|
} |
281 |
|
|
|
282 |
|
|
/** |
283 |
|
|
* this function builds a TD tag with the border styles |
284 |
|
|
* set appropriatly |
285 |
|
|
* |
286 |
|
|
* @param int - the width |
287 |
|
|
* @param string - the alignment |
288 |
|
|
* @param int - the current col # |
289 |
|
|
* @param int - the max cols |
290 |
|
|
* @return TDtag object. |
291 |
|
|
*/ |
292 |
|
|
function _build_td( $width="", $align="", $col_num, $total_cols ) { |
293 |
|
|
//first we have to build the style string |
294 |
|
|
$style = ""; |
295 |
|
|
|
296 |
|
|
if ( $width != "" ) { |
297 |
|
|
$style = "width:"; |
298 |
|
|
if ( substr($width, -1) != "%" ) { |
299 |
|
|
$style .= $width."px;"; |
300 |
|
|
} else { |
301 |
|
|
$style .= $width.";"; |
302 |
|
|
} |
303 |
|
|
} |
304 |
|
|
|
305 |
|
|
if ( $align != "" ) { |
306 |
|
|
//add the alignment |
307 |
|
|
$style .= "text-align:".$align.";"; |
308 |
|
|
} |
309 |
|
|
|
310 |
|
|
//add some padding |
311 |
|
|
$style .= "padding-left:5px;padding-right:5px;"; |
312 |
|
|
|
313 |
|
|
//now determine the bordering |
314 |
|
|
if ( $col_num != $total_cols && |
315 |
|
|
$this->get_vertical_cellborder() ) { |
316 |
|
|
$class = "contentvertical"; |
317 |
|
|
} else { |
318 |
|
|
$class = "contentnovertical"; |
319 |
|
|
} |
320 |
|
|
|
321 |
|
|
$attributes = array("class" => $class); |
322 |
|
|
return new TDtag( $attributes ); |
323 |
|
|
} |
324 |
jonen |
1.1 |
} |
325 |
|
|
|
326 |
|
|
/** |
327 |
|
|
* This class defines the css used by the |
328 |
|
|
* FooterNav Object. |
329 |
|
|
* |
330 |
|
|
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
331 |
|
|
* @package phpHtmlLib |
332 |
|
|
*/ |
333 |
|
|
class InfoTableCSS extends CSSBuilder { |
334 |
|
|
|
335 |
jonen |
1.3 |
function user_setup() { |
336 |
|
|
$this->add_entry(".infotable", NULL, |
337 |
|
|
array("margin" => "0px 0px 0px 0px", |
338 |
|
|
"font-family" => "arial, helvetica, sans-serif", |
339 |
|
|
"font-size" => "10pt", |
340 |
|
|
"border-left" => "1px solid #999999", |
341 |
|
|
"border-right" => "1px solid #999999", |
342 |
|
|
"border-bottom" => "1px solid #999999") ); |
343 |
|
|
|
344 |
|
|
$this->add_entry(".infotable", "caption.title", |
345 |
|
|
array("font-size" => "10pt", |
346 |
|
|
"font-weight" => "bold", |
347 |
|
|
"padding" => "2px 5px 2px 5px", |
348 |
|
|
"color" => "#FFFFFF", |
349 |
|
|
"background-color" => "#999999", |
350 |
|
|
"border-top" => "1px solid #999999", |
351 |
|
|
"border-left" => "1px solid #999999", |
352 |
|
|
"border-right" => "1px solid #999999")); |
353 |
jonen |
1.1 |
|
354 |
jonen |
1.3 |
$this->add_entry(".infotable", "td.header", |
355 |
|
|
array("font-weight" => "bold", |
356 |
jonen |
1.1 |
"border-top" => "1px solid #999999", |
357 |
jonen |
1.3 |
"border-right" => "1px solid #999999")); |
358 |
jonen |
1.1 |
|
359 |
jonen |
1.3 |
$this->add_entry(".infotable", "td.headerlast", |
360 |
|
|
array("font-weight" => "bold", |
361 |
jonen |
1.1 |
"border-top" => "1px solid #999999")); |
362 |
|
|
|
363 |
jonen |
1.3 |
$this->add_entry(".infotable", "td.contentnovertical", |
364 |
|
|
array("border-top" => "1px solid #999999")); |
365 |
jonen |
1.1 |
|
366 |
jonen |
1.3 |
$this->add_entry(".infotable", "td.contentvertical", |
367 |
|
|
array("border-top" => "1px solid #999999", |
368 |
|
|
"border-right" => "1px solid #999999")); |
369 |
|
|
} |
370 |
jonen |
1.1 |
} |
371 |
|
|
?> |