1 |
<?php |
2 |
/** |
3 |
* |
4 |
* This file contains the Default DataList child |
5 |
* that has its specific GUI layout/look/feel |
6 |
* |
7 |
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
8 |
* @package phpHtmlLib |
9 |
* |
10 |
*/ |
11 |
|
12 |
/** |
13 |
* Need to make sure we have the DataList object |
14 |
*/ |
15 |
require_once($phphtmllib."/widgets/data_list/DataList.inc"); |
16 |
|
17 |
/** |
18 |
* This class is the Default phpHtmlLib GUI interface |
19 |
* child of the DataList class. This child simply does |
20 |
* the job of rendering the html/layout for a DataList. |
21 |
* You can use this as an example of how to build your |
22 |
* own look/feel for your DataList. |
23 |
* |
24 |
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
25 |
* @package phpHtmlLib |
26 |
* |
27 |
*/ |
28 |
class DefaultGUIDatalist extends DataList { |
29 |
|
30 |
|
31 |
/** |
32 |
* The overall alignment |
33 |
* |
34 |
* DEFAULT: "center" |
35 |
*/ |
36 |
var $_align = "center"; |
37 |
|
38 |
/** |
39 |
* This holds the action column |
40 |
* settings if any. |
41 |
*/ |
42 |
var $_action_column = array(); |
43 |
|
44 |
/** |
45 |
* holds the cntr for the action |
46 |
* checkbox name |
47 |
*/ |
48 |
var $_action_count = 0; |
49 |
|
50 |
/** |
51 |
* This array holds the list of |
52 |
* hidden checkbox[] items. |
53 |
* |
54 |
*/ |
55 |
var $_hidden_checkbox_items = array(); |
56 |
|
57 |
/** |
58 |
* this array keeps track of the list |
59 |
* of rendered visible checkbox[] |
60 |
* items. So we can not render the |
61 |
* hidden version of it. |
62 |
*/ |
63 |
var $_visible_checkbox_items = array(); |
64 |
|
65 |
|
66 |
/** |
67 |
* This variable holds the array of default |
68 |
* selected items. This is populated |
69 |
* inside the user_setup() function |
70 |
* to pre-populate the list of selected |
71 |
* items for a the checkbox action column. |
72 |
* |
73 |
*/ |
74 |
var $_default_checked_items = array(); |
75 |
|
76 |
|
77 |
/** |
78 |
* Do we show action bar row? |
79 |
*/ |
80 |
var $_show_actionbar = TRUE; |
81 |
|
82 |
/** |
83 |
* This variable tells us whether to display select all checkbox |
84 |
*/ |
85 |
var $_allow_select_all = TRUE; |
86 |
|
87 |
|
88 |
/** |
89 |
* This function sets a prefix for all |
90 |
* variables that are used in the item list |
91 |
* table on a page. This allows you to have |
92 |
* multiple itemlists on a single html page. |
93 |
* |
94 |
* @param string $prefix - the prefix for all vars. |
95 |
*/ |
96 |
function set_global_prefix($prefix) { |
97 |
$this->_vars["radioVar"] = "radio"; |
98 |
$this->_vars["checkboxVar"] = "checkbox"; |
99 |
DataList::set_global_prefix($prefix); |
100 |
} |
101 |
|
102 |
|
103 |
function gui_init() { |
104 |
$container = container(); |
105 |
$container->add( $this->build_tool_link("first"), |
106 |
$this->build_tool_link("prev"), |
107 |
$this->build_tool_link("next"), |
108 |
$this->build_tool_link("last"), |
109 |
$this->build_tool_link("all"), |
110 |
$this->get_page_info() ); |
111 |
|
112 |
$this->_data_table = html_table($this->get_width(),0,0,0, $this->_align); |
113 |
$this->_data_table->set_class("datalist_border"); |
114 |
|
115 |
$this->_tool_td = html_td("datalist_title", "right", $container); |
116 |
$this->_tool_td->set_style("padding-top: 5px; padding-right: 5px;"); |
117 |
|
118 |
//calculate the # of columns depending on if they |
119 |
//have added action columns. |
120 |
$cols = count($this->_columns); |
121 |
if ($this->_has_action_column("FIRST")) $cols++; |
122 |
if ($this->_has_action_column("LAST")) $cols++; |
123 |
|
124 |
//$this->_tool_td->set_tag_attribute("colspan", $cols-1); |
125 |
|
126 |
$title_table = html_table("100%"); |
127 |
|
128 |
$title = new TDtag(array("align" => "left", |
129 |
"class" => "datalist_title", |
130 |
"style" => "padding-left: 5px;"), |
131 |
$this->get_title() ); |
132 |
|
133 |
$title_table->add( new TRtag( array(), $title, |
134 |
$this->_tool_td) ); |
135 |
|
136 |
|
137 |
//add the header tr reference |
138 |
//it will get populated later |
139 |
$this->_header_tr = new TRtag; |
140 |
//$this->_data_table->add( new TRtag(array(), $title, $this->_tool_td) ); |
141 |
$this->_data_table->add_row( new TDtag(array("colspan" => $cols), |
142 |
$title_table) ); |
143 |
$this->_data_table->add_reference($this->_header_tr); |
144 |
|
145 |
//initialize the first date row |
146 |
$this->_data_row = new TRtag; |
147 |
|
148 |
//enable search |
149 |
$this->search_enable(); |
150 |
$this->set_simple_search_modifier(); |
151 |
|
152 |
} |
153 |
|
154 |
/** |
155 |
* this function is used to set the overall alignment |
156 |
* of the widget |
157 |
* |
158 |
* @param string - the align value |
159 |
*/ |
160 |
function set_align($align) { |
161 |
$this->_align = $align; |
162 |
} |
163 |
|
164 |
function child_build_column_header($name, $col, $cnt) { |
165 |
if (!$this->_cur_col_cntr) { |
166 |
$this->_cur_col_cntr = 1; |
167 |
//lets see if we need to add an action column |
168 |
//as the first column. |
169 |
if ($this->_has_action_column("FIRST")) { |
170 |
//looks like we have a FIRST column actionbar |
171 |
//lets add it |
172 |
$td = $this->_build_action_column("FIRST", TRUE); |
173 |
$this->_header_tr->add( $td ); |
174 |
} |
175 |
$td = $this->build_column_header($name, $col, $cnt); |
176 |
$this->_header_tr->add( $td ); |
177 |
} else { |
178 |
$td = $this->build_column_header($name, $col, $cnt); |
179 |
$this->_header_tr->add( $td ); |
180 |
} |
181 |
|
182 |
if ($this->_cur_col_cntr == $cnt) { |
183 |
//lets see if we need to add an action column |
184 |
//as the first column. |
185 |
if ($this->_has_action_column("LAST")) { |
186 |
//looks like we have a FIRST column actionbar |
187 |
//lets add it |
188 |
$td = $this->_build_action_column("LAST", TRUE); |
189 |
$this->_header_tr->add( $td ); |
190 |
} |
191 |
unset( $this->_cur_col_cntr ); |
192 |
} else { |
193 |
$this->_cur_col_cntr++; |
194 |
} |
195 |
} |
196 |
|
197 |
function child_add_row_cell($obj, $col_name, $last_in_row_flag, $row_data) { |
198 |
if (!$this->_cur_col_cntr) { |
199 |
$this->_cur_col_cntr = 1; |
200 |
//lets see if we need to add an action column |
201 |
//as the first column. |
202 |
if ($this->_has_action_column("FIRST")) { |
203 |
//looks like we have a FIRST column actionbar |
204 |
//lets add it |
205 |
$this->_data_row->add($this->_build_action_column("FIRST", FALSE, $row_data)); |
206 |
} |
207 |
$td = $this->wrap_column_item($obj, $col_name); |
208 |
$this->_data_row->add( $td ); |
209 |
} else { |
210 |
//show the normal data |
211 |
$td = $this->wrap_column_item($obj, $col_name); |
212 |
$this->_data_row->add( $td ); |
213 |
} |
214 |
|
215 |
|
216 |
if ($last_in_row_flag) { |
217 |
//lets see if we need to add an action column |
218 |
//as the first column. |
219 |
if ($this->_has_action_column("LAST")) { |
220 |
//looks like we have a LAST column actionbar |
221 |
//lets add it |
222 |
$this->_data_row->add($this->_build_action_column("LAST", FALSE, $row_data)); |
223 |
} |
224 |
|
225 |
|
226 |
|
227 |
$this->_data_table->add_row( $this->_data_row ); |
228 |
$this->_data_row = new TRtag; |
229 |
unset( $this->_cur_col_cntr ); |
230 |
} else { |
231 |
$this->_cur_col_cntr++; |
232 |
} |
233 |
} |
234 |
|
235 |
function child_get_gui() { |
236 |
return container( $this->_data_table, |
237 |
$this->_build_actionbar() ); |
238 |
} |
239 |
|
240 |
/** |
241 |
* This function builds the object/text |
242 |
* to be used for a column header. It can |
243 |
* either be an href because its sortable, |
244 |
* or it can just be text, because its not |
245 |
* sortable. |
246 |
* |
247 |
* @param string $col_name - the column name |
248 |
* to build from |
249 |
* the headers. |
250 |
* @param array $col_data - the column's data. |
251 |
* @param int the column # we are working on. |
252 |
* @return mixed - either an Atag object or |
253 |
* raw text. |
254 |
*/ |
255 |
function build_column_header($col_name, $col_data, $col_num) { |
256 |
|
257 |
$td = new TDtag(array("class"=>"datalist_col_head", |
258 |
"width" => $col_data["size"])); |
259 |
|
260 |
if ($this->_columns[$col_name]["sortable"]) { |
261 |
$col_url = $this->build_column_url($col_name); |
262 |
|
263 |
$td->set_tag_attribute("title","Sort By ".$col_name); |
264 |
|
265 |
$td->push(html_a($col_url, $col_name,"form_link")); |
266 |
|
267 |
if ($this->_columns[$col_name]["data_name"] == $this->orderby()) { |
268 |
|
269 |
if ($this->reverseorder() == "false") { |
270 |
$alt_title = "Sorted in Ascending Order"; |
271 |
$img = html_img($this->get_image_path()."/picto_down.gif",11,11,'',$alt_title); |
272 |
$img->set_tag_attribute("style", "padding-left: 5px;margin-left:5px;vertical-align:middle;"); |
273 |
$td->push($img); |
274 |
} else { |
275 |
$alt_title = "Sorted in Descending Order"; |
276 |
$img = html_img($this->get_image_path()."/picto_up.gif",11,11,'',$alt_title); |
277 |
$img->set_tag_attribute("style", "padding-left: 5px;margin-left:5px;vertical-align:middle;"); |
278 |
$td->push($img); |
279 |
} |
280 |
} |
281 |
|
282 |
// we want to highlight the td on mouse over |
283 |
$td->set_tag_attribute("onMouseOver", |
284 |
"javascript:style.cursor='hand';this.className='datalist_col_head_hover';"); |
285 |
$td->set_tag_attribute("onMouseOut", |
286 |
"javascript:this.className='datalist_col_head'"); |
287 |
$td->set_tag_attribute("onMouseDown", |
288 |
"javascript:this.className='datalist_col_head_clicked'"); |
289 |
|
290 |
|
291 |
if ($this->get_form_method() == "POST") { |
292 |
$td->set_tag_attribute("onClick", $col_url); |
293 |
} |
294 |
else { |
295 |
$td->set_tag_attribute("onClick", "javascript:document.location='".$col_url."';"); |
296 |
} |
297 |
} else { |
298 |
$td->push($col_name); |
299 |
$td->set_tag_attribute("style", $style."padding-left:5px;padding-right:5px;white-space:nowrap;"); |
300 |
} |
301 |
|
302 |
return $td; |
303 |
} |
304 |
|
305 |
/** |
306 |
* This function ensures that the data we place |
307 |
* in a column is aligned according to what the |
308 |
* user wants. |
309 |
* |
310 |
* @param mixed - $obj - the data for the td. |
311 |
* @param string - $col_name - the name of the column header |
312 |
* for this row to render. |
313 |
* @param int - $odd_row - tells us if this cell lives in |
314 |
* an odd # row (for alternating row colors) |
315 |
* @param int - the column # we are working on. |
316 |
* @return TDtag object |
317 |
*/ |
318 |
function wrap_column_item($obj, $col_name) { |
319 |
|
320 |
//make sure its set to something. |
321 |
if ($obj == '') { |
322 |
$obj = " "; |
323 |
} |
324 |
// if item is match by expression we will replace it with an link object |
325 |
elseif($this->_decode_column_item_expr($obj)) { |
326 |
$obj = $this->_decode_column_item_expr($obj); |
327 |
} |
328 |
// if item is an Array we will replace it with an selection form object |
329 |
elseif($this->_decode_column_item_array($obj)) { |
330 |
$obj = $this->_decode_column_item_array($obj); |
331 |
} |
332 |
|
333 |
//make sure we don't put a right border on the last |
334 |
//column we are working on. |
335 |
//$style = "padding-left: 3px;padding-right:3px;border-top: 1px solid #dddddd;"; |
336 |
|
337 |
|
338 |
if ($this->_columns[$col_name]["data_name"] == $this->orderby()) { |
339 |
$style = "background-color: #f4f4f4;"; |
340 |
} else { |
341 |
$style = "background-color: #ffffff;"; |
342 |
} |
343 |
|
344 |
$align = $this->_columns[$col_name]["align"]; |
345 |
$td = new TDtag(array("align" => $align, |
346 |
"style" => $style, |
347 |
"class" => "datalist_data_cell")); |
348 |
|
349 |
if (is_object($obj) && $obj->_tag == "td") { |
350 |
return $obj; |
351 |
} else { |
352 |
$td->add( $obj ); |
353 |
} |
354 |
return $td; |
355 |
} |
356 |
|
357 |
/** |
358 |
* This builds the table that holds the search |
359 |
* capability. |
360 |
* |
361 |
* @return TABLEtag object. |
362 |
*/ |
363 |
function child_build_search_table() { |
364 |
//the search capability is enabled. |
365 |
//lets try and build the table. |
366 |
$td_attributes = array("style" => "padding-left: 5px;padding-bottom:4px;". |
367 |
"padding-right:40px;padding-top:4px;". |
368 |
"background-color: #eeeeee;", |
369 |
"align" => "left", |
370 |
"class" => "font10"); |
371 |
|
372 |
$table = html_table($this->get_width(),0,0,0,$this->_align); |
373 |
|
374 |
//test to see if they want to render the outer borders |
375 |
$table->set_tag_attribute("style", "border-left: 1px solid #a1a1a1;". |
376 |
"border-right: 1px solid #a1a1a1;"); |
377 |
|
378 |
$td = new TDtag($td_attributes); |
379 |
|
380 |
if ($this->search_type() == "advanced") { |
381 |
$td->push($this->_build_advanced_search_form()); |
382 |
} else { |
383 |
$td->push($this->_build_simple_search_form()); |
384 |
} |
385 |
$table->push_row($td); |
386 |
|
387 |
return container($this->_build_search_title(), $table); |
388 |
} |
389 |
|
390 |
/** |
391 |
* This function builds the search title table |
392 |
* |
393 |
* @return TABLEtag object |
394 |
*/ |
395 |
function _build_search_title() { |
396 |
//build the title stacked table |
397 |
$title = html_table($this->get_width(), 0, 0, 0, $this->_align); |
398 |
|
399 |
//test to see if they want to render the outer borders |
400 |
$title->set_tag_attribute("style","border: 1px solid #a1a1a1;"); |
401 |
$title->push_row(new TDtag(array("class" => "datalist_title", |
402 |
"style" => "color: ".$this->_title_fcolor.";". |
403 |
"background-color: ".$this->_title_color.";"), " Search")); |
404 |
|
405 |
return $title; |
406 |
} |
407 |
|
408 |
|
409 |
/** |
410 |
* This function builds the simple search TD |
411 |
* |
412 |
* @return ContainerWidget |
413 |
*/ |
414 |
function _build_simple_search_form() { |
415 |
|
416 |
//if there is only 1 item enabled for search |
417 |
//then the search looks simple. |
418 |
$fields = $this->_get_searchable_fields(); |
419 |
$cnt = count($fields); |
420 |
if ($cnt == 0) { |
421 |
return NULL; |
422 |
} |
423 |
|
424 |
$container = new ContainerWidget; |
425 |
|
426 |
if ($cnt == 1) { |
427 |
//user only has 1 field to show. |
428 |
list($name, $field) = each($fields); |
429 |
$container->push("Find ".$name." "); |
430 |
} else { |
431 |
//user has many fields to show. |
432 |
$container->push("Find ", |
433 |
form_select($this->_vars["search_fieldVar"], $fields, $this->search_field())); |
434 |
} |
435 |
|
436 |
if ($this->get_simple_search_modifier()) { |
437 |
//the user wants the search modifier turned on. |
438 |
$container->push($this->_build_simple_search_modifier()); |
439 |
} |
440 |
|
441 |
$container->push(form_text($this->_vars["search_valueVar"], $this->search_value_filter($this->search_value()), "20", "100", array("style"=>"vertical-align:middle;")), |
442 |
form_submit($this->get_form_name(), "Search", array("style"=>"vertical-align:middle;"))); |
443 |
|
444 |
if ($this->is_advanced_search_enabled()) { |
445 |
$span = html_span(html_a("ass","Advanced Search", "title")); |
446 |
$container->push(" ", $span); |
447 |
} |
448 |
|
449 |
if ($cnt == 1) { |
450 |
$container->push(form_hidden($this->_vars["search_fieldVar"], $field)); |
451 |
} |
452 |
|
453 |
$hidden_fields = $this->get_hidden_fields(); |
454 |
if(is_array($hidden_fields)) { |
455 |
foreach($hidden_fields as $key => $value) { |
456 |
$container->push(form_hidden($key, $value)); |
457 |
} |
458 |
} |
459 |
$container->push(form_close() ); |
460 |
return $container; |
461 |
} |
462 |
|
463 |
|
464 |
/** |
465 |
* This function adds an action column. This |
466 |
* adds a column of either checkboxes or radio |
467 |
* buttons. |
468 |
* |
469 |
* @param string - type of column |
470 |
* 'checkbox' or 'radio' |
471 |
* @param string - which column it lives in |
472 |
* 'FIRST' or 'LAST' |
473 |
* @param string - which db field is associated |
474 |
* with this. |
475 |
* @param string - the title to use for the column. |
476 |
* NOTE: if this is set, then there |
477 |
* will NOT be a global checkbox |
478 |
* that can be used to select/deslect |
479 |
* all at once. |
480 |
* |
481 |
*/ |
482 |
function add_action_column($type, $col, $db_field, $title=NULL) { |
483 |
$action = array("type" => $type, |
484 |
"dbfield" => $db_field, |
485 |
"title" => $title); |
486 |
$this->_action_column[$col] = $action; |
487 |
} |
488 |
|
489 |
/** |
490 |
* This function is used to set the default list |
491 |
* of selected checkbox items. This is used so |
492 |
* the user can pre-populate the list of |
493 |
* checked items in the checkbox action column |
494 |
* |
495 |
* @param array - the array of checked items |
496 |
*/ |
497 |
function set_default_checked_items($items) { |
498 |
$this->_default_checked_items = $items; |
499 |
} |
500 |
|
501 |
/** |
502 |
* This function returns the array of default |
503 |
* checked items to be marked as checked in |
504 |
* the checkbox action column |
505 |
* |
506 |
* @return array |
507 |
*/ |
508 |
function get_default_checked_items() { |
509 |
return $this->_default_checked_items; |
510 |
} |
511 |
|
512 |
/** |
513 |
* set the flag to tell the object to |
514 |
* save the checked items |
515 |
* |
516 |
*/ |
517 |
function save_checked_items() { |
518 |
$this->_save_checked_items_flag = TRUE; |
519 |
} |
520 |
|
521 |
/** |
522 |
* This tests the object flag to |
523 |
* see if the child class wants to |
524 |
* automatically save the checked |
525 |
* items |
526 |
* |
527 |
* @return boolean |
528 |
*/ |
529 |
function _save_checked_items_enabled() { |
530 |
return $this->_save_checked_items_flag; |
531 |
} |
532 |
|
533 |
/** |
534 |
* This function tests to see if the child |
535 |
* wants to render an action column |
536 |
* |
537 |
* @param string - the column to test for |
538 |
* FIRST or LAST |
539 |
* @return boolean |
540 |
*/ |
541 |
function _has_action_column($col) { |
542 |
if (isset($this->_action_column[$col])) { |
543 |
return TRUE; |
544 |
} |
545 |
else { |
546 |
return FALSE; |
547 |
} |
548 |
} |
549 |
|
550 |
/** |
551 |
* This allows the caller to |
552 |
* turn on/off the rendering of |
553 |
* the bottom action bar row |
554 |
* |
555 |
* @param boolean - TRUE = on FALSE = off |
556 |
*/ |
557 |
function set_actionbar($flag = TRUE) { |
558 |
$this->_show_actionbar = $flag; |
559 |
} |
560 |
|
561 |
/** |
562 |
* This function gets the current value |
563 |
* of the show actionbar flag setting. |
564 |
* |
565 |
* @return boolean |
566 |
*/ |
567 |
function show_actionbar() { |
568 |
return $this->_show_actionbar; |
569 |
} |
570 |
|
571 |
/** |
572 |
* Sets the flag for rendering the select all checkbox |
573 |
* |
574 |
* @param bool flag |
575 |
*/ |
576 |
function allow_select_all($flag) { |
577 |
$this->_allow_select_all = $flag; |
578 |
} |
579 |
|
580 |
|
581 |
/** |
582 |
* This builds an action column cell |
583 |
* |
584 |
* @param string - the column to test for |
585 |
* FIRST or LAST |
586 |
* @param boolean - lets us know this is for |
587 |
* the header or a cell. |
588 |
* @param array - the row's data. |
589 |
* @return HTMLTag object |
590 |
*/ |
591 |
function _build_action_column($col, $header_flag=FALSE, $row_data=NULL) { |
592 |
|
593 |
$attributes = array("width" => "1%", |
594 |
"align" => "center"); |
595 |
|
596 |
if ($header_flag) $attributes["class"] = "datalist_col_head"; |
597 |
else $attributes["class"] = "datalist_actionbar_data_cell"; |
598 |
|
599 |
$td = new TDtag($attributes); |
600 |
$form_value = ''; |
601 |
if ($header_flag) { |
602 |
//this is for a header item. |
603 |
$form_value = ""; |
604 |
} else { |
605 |
$form_value = $row_data[$this->_action_column[$col]["dbfield"]]; |
606 |
} |
607 |
|
608 |
switch ($this->_action_column[$col]["type"]) { |
609 |
case "radio": |
610 |
if ($header_flag) { |
611 |
//we don't put a header button for radio |
612 |
if ($this->_action_column[$col]["title"]) |
613 |
$obj = $this->_action_column[$col]["title"]; |
614 |
else $obj = _HTML_SPACE; |
615 |
} else { |
616 |
$name = $this->_vars["radioVar"]."[".$this->_action_count."]"; |
617 |
$obj = form_radio($name, $form_value); |
618 |
|
619 |
//see if the checkbox should be disabled |
620 |
if (!$this->is_action_enabled($form_value, $row_data)) { |
621 |
$obj->set_tag_attribute("DISABLED"); |
622 |
$obj->set_tag_attribute("value",""); |
623 |
} |
624 |
} |
625 |
|
626 |
break; |
627 |
case "checkbox": |
628 |
if ($header_flag) { |
629 |
//see if the child wants a title instead |
630 |
//of the global check/uncheck checkbox |
631 |
if ($this->_action_column[$col]["title"]) { |
632 |
$obj = $this->_action_column[$col]["title"]; |
633 |
break; |
634 |
} else { |
635 |
$name = $this->_vars["checkboxVar"]; |
636 |
} |
637 |
} else { |
638 |
$name = $this->_vars["checkboxVar"]."[".$this->_action_count."]"; |
639 |
} |
640 |
|
641 |
$this->_action_count++; |
642 |
$obj = form_checkbox($name, $form_value); |
643 |
if ($header_flag) { |
644 |
if ($this->_allow_select_all) { |
645 |
$obj->set_tag_attribute("onClick", "javascript:mass(this.form)"); |
646 |
} else { |
647 |
$obj = _HTML_SPACE; |
648 |
} |
649 |
} |
650 |
|
651 |
//see if the checkbox should be checked |
652 |
if ($this->_is_col_checked($form_value, $row_data)) { |
653 |
$obj->set_tag_attribute("CHECKED"); |
654 |
} |
655 |
|
656 |
//see if the checkbox should be disabled |
657 |
if (!$header_flag && !$this->is_action_enabled($form_value, $row_data)) { |
658 |
$obj->set_tag_attribute("DISABLED"); |
659 |
$obj->set_tag_attribute("value",""); |
660 |
} |
661 |
|
662 |
//save which items we have rendered visibly. |
663 |
//so we can filter those out in the hidden |
664 |
//items |
665 |
$this->_visible_checkbox_items[$form_value] = TRUE;; |
666 |
break; |
667 |
} |
668 |
$td->push($obj); |
669 |
$td->set_collapse(); |
670 |
return $td; |
671 |
} |
672 |
|
673 |
/** |
674 |
* This method checks to see if a |
675 |
* particular row has been checked |
676 |
* in the action column |
677 |
* |
678 |
* @param string - the item to look for |
679 |
* @param array - the row's data. |
680 |
* @return boolean. |
681 |
*/ |
682 |
function _is_col_checked($value, $row_data) { |
683 |
if (count($this->_hidden_checkbox_items) == 0) { |
684 |
if (isset($_REQUEST[$this->_vars["checkboxVar"]]) && is_array($_REQUEST[$this->_vars["checkboxVar"]])) { |
685 |
$this->_hidden_checkbox_items = array_flip($_REQUEST[$this->_vars["checkboxVar"]]); |
686 |
} |
687 |
} |
688 |
|
689 |
//call the child function to see if item should |
690 |
//be checked |
691 |
$user_flag = $this->is_action_checked($value, $row_data); |
692 |
$hidden_flag = isset($this->_hidden_checkbox_items[$value]); |
693 |
|
694 |
return($user_flag || $hidden_flag); |
695 |
|
696 |
if (isset($this->_hidden_checkbox_items[$value])) { |
697 |
return TRUE; |
698 |
} |
699 |
else { |
700 |
return FALSE; |
701 |
} |
702 |
} |
703 |
|
704 |
/** |
705 |
* This function is provided to give the child class |
706 |
* the ability to precheck/select a particular |
707 |
* column. |
708 |
* |
709 |
* @param string - the item to look for. |
710 |
* @param array - the row's data. |
711 |
* @return boolean |
712 |
*/ |
713 |
function is_action_checked($value, $row_data) { |
714 |
return FALSE; |
715 |
} |
716 |
|
717 |
/** |
718 |
* This function is provided to give the child |
719 |
* class the ability to enable/disable a particular |
720 |
* checkbox. |
721 |
* |
722 |
* @param string - the item to look for. |
723 |
* @param array - the row's data. |
724 |
* @return boolean |
725 |
*/ |
726 |
function is_action_enabled($value, $row_data) { |
727 |
return TRUE; |
728 |
} |
729 |
|
730 |
/** |
731 |
* This function renders the action bar at the bottom |
732 |
* of the data list. |
733 |
* |
734 |
* @return TABLEtag object |
735 |
*/ |
736 |
function _build_actionbar() { |
737 |
|
738 |
if ($this->show_actionbar()) { |
739 |
|
740 |
$table = html_table($this->get_width(),0,0,0,$this->_align); |
741 |
$table->set_class("datalist_actionbar"); |
742 |
/*if ($this->show_outer_border()) { |
743 |
$table->set_tag_attribute("style", _CSS_BORDER_LEFT. |
744 |
_CSS_BORDER_RIGHT. |
745 |
_CSS_BORDER_BOTTOM); |
746 |
} |
747 |
else { |
748 |
$table->set_tag_attribute("style", _CSS_BORDER_TOP); |
749 |
}*/ |
750 |
|
751 |
$td = new TDtag(array("class"=>"datalist_bottom_seperator", |
752 |
"colspan" => 3), |
753 |
_HTML_SPACE); |
754 |
$table->add_row( $td ); |
755 |
|
756 |
$table->add_row($this->_build_actionbar_arrow_cell("FIRST"), |
757 |
$this->_build_actionbar_data_cell(), |
758 |
$this->_build_actionbar_arrow_cell("LAST") ); |
759 |
|
760 |
return $table; |
761 |
} |
762 |
else return NULL; |
763 |
} |
764 |
|
765 |
/** |
766 |
* This function builds a TD with the |
767 |
* appropriate action arrow. |
768 |
* |
769 |
* @param string - FIRST or LAST |
770 |
* @return TDtag |
771 |
*/ |
772 |
function _build_actionbar_arrow_cell($col) { |
773 |
$td = new TDtag(array("class" => "datalist_title", |
774 |
"style" => "padding-left:14px;padding-right:14px;". |
775 |
"padding-top:5px;", |
776 |
"width" => "5%") |
777 |
); |
778 |
|
779 |
if ($col == "FIRST") { |
780 |
$td->set_tag_attribute("align", "left"); |
781 |
if ($this->_has_action_column("FIRST") && |
782 |
$this->_datasource->get_total_rows()) { |
783 |
$td->push(html_img("/phphtmllib/images/widgets/arrow_right.gif")); |
784 |
} |
785 |
else { |
786 |
$td->push(" "); |
787 |
} |
788 |
} |
789 |
else { |
790 |
$td->set_tag_attribute("align", "right"); |
791 |
if ($this->_has_action_column("LAST") && |
792 |
$this->_datasource->get_total_rows()) { |
793 |
$td->push(html_img("/phphtmllib/images/widgets/arrow_left.gif")); |
794 |
} |
795 |
else { |
796 |
$td->push(" "); |
797 |
} |
798 |
} |
799 |
return $td; |
800 |
} |
801 |
|
802 |
/** |
803 |
* This function builds the user's data cell |
804 |
* |
805 |
* @return TDtag; |
806 |
*/ |
807 |
function _build_actionbar_data_cell() { |
808 |
$td = new TDtag(array("class" => "datalist_title", |
809 |
"style" => "padding-left:5px;padding-right:5px;". |
810 |
"padding-top:5px;padding-bottom:5px") |
811 |
); |
812 |
|
813 |
$flag = FALSE; |
814 |
if ($this->_has_action_column("FIRST")) { |
815 |
$flag = TRUE; |
816 |
$td->set_tag_attribute("align", "left"); |
817 |
} |
818 |
else if ($this->_has_action_column("LAST")) { |
819 |
$flag = TRUE; |
820 |
$td->set_tag_attribute("align", "right"); |
821 |
} |
822 |
|
823 |
if ($flag && $this->_datasource->get_total_rows()) { |
824 |
$td->push($this->actionbar_cell()); |
825 |
} |
826 |
else { |
827 |
$td->push(" "); |
828 |
} |
829 |
|
830 |
return $td; |
831 |
} |
832 |
|
833 |
/** |
834 |
* this is the method that builds |
835 |
* the contents for the middle actionbar |
836 |
* td cell. |
837 |
* NOTE this function is meant to be overriden |
838 |
* by the child class. |
839 |
* |
840 |
* @return ContainerWidget object |
841 |
*/ |
842 |
function actionbar_cell() { |
843 |
return _HTML_SPACE; |
844 |
} |
845 |
|
846 |
/** |
847 |
* This function builds an action button that will |
848 |
* modify the form action, to post to a different |
849 |
* script to handle the data |
850 |
* |
851 |
* @param string - the button name |
852 |
* @param string - the script that gets called. |
853 |
* @return INPUTtag object |
854 |
*/ |
855 |
function action_button($name, $action) { |
856 |
|
857 |
$submit = form_button("_action", $name); |
858 |
|
859 |
// here we make sure that all standard buttons look the same |
860 |
if (strlen($name)<10) $submit->set_tag_attribute("style","width: 80px;"); |
861 |
|
862 |
$form_name = $this->get_form_name(); |
863 |
|
864 |
$onclick = "javascript: document.".$form_name.".action='".$action."';"; |
865 |
$onclick .= "document.".$form_name.".submit();"; |
866 |
$submit->set_tag_attribute("onclick", $onclick); |
867 |
return $submit; |
868 |
} |
869 |
|
870 |
/** |
871 |
* This function returns any Javascript required |
872 |
* for this widget |
873 |
* |
874 |
* @return mixed |
875 |
*/ |
876 |
function _javascript() { |
877 |
if ($this->_has_action_column("FIRST") || $this->_has_action_column("LAST")) { |
878 |
$last = $this->_action_column["LAST"]["type"]; |
879 |
$first = $this->_action_column["FIRST"]["type"]; |
880 |
if ($last == "checkbox" || $first == "checkbox") { |
881 |
return $this->_checkbox_javascript(); |
882 |
} |
883 |
} |
884 |
else { |
885 |
return NULL; |
886 |
} |
887 |
} |
888 |
|
889 |
/** |
890 |
* This function builds the JS needed for the checkbox |
891 |
* action column |
892 |
* |
893 |
* @return SCRIPTtag |
894 |
*/ |
895 |
function _checkbox_javascript() { |
896 |
$script = new SCRIPTtag(array("language" => "Javascript")); |
897 |
|
898 |
$var_name = $this->_vars["checkboxVar"]; |
899 |
|
900 |
$js = "function mass(form) {\n"; |
901 |
$js .= " var i=0;\n"; |
902 |
$js .= " var value=0;\n\n"; |
903 |
$js .= " if (form.$var_name.checked) {\n"; |
904 |
$js .= " value=1;\n"; |
905 |
$js .= " } else {\n"; |
906 |
$js .= " value=0;\n"; |
907 |
$js .= " }\n\n"; |
908 |
$js .= " for (i = 0; i < form.length; i++) {\n"; |
909 |
$js .= " if (form.elements[i].name.substring(0, 8) == '$var_name' && !form.elements[i].disabled) {\n"; |
910 |
$js .= " form.elements[i].checked = value;\n"; |
911 |
$js .= " }\n"; |
912 |
$js .= " }\n"; |
913 |
$js .= "}\n"; |
914 |
|
915 |
$script->push($js); |
916 |
return $script; |
917 |
} |
918 |
|
919 |
function get_hidden_fields() { |
920 |
user_error("DefaulGUIDataList::get_hidden_fields() - ". |
921 |
"child class must override this method ". |
922 |
"this function should return a hash for hidden fields, if not needed just return" ); |
923 |
} |
924 |
|
925 |
function _decode_column_item_array($obj) { |
926 |
user_error("DefaulGUIDataList::_decode_column_item_array() - ". |
927 |
"child class must override this method ". |
928 |
"this function should decode the column_item if it is a (sub-) array,". |
929 |
"array should e.g. replaced by a select form." ); |
930 |
} |
931 |
|
932 |
function _decode_column_item_expr($obj) { |
933 |
user_error("DefaulGUIDataList::_decode_column_item_expr() - ". |
934 |
"child class must override this method ". |
935 |
"this function should decode the column_item, if it is encoded for e.g. objects" ); |
936 |
} |
937 |
} |
938 |
|
939 |
/** |
940 |
* This class defines the css used by the |
941 |
* FooterNav Object. |
942 |
* |
943 |
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
944 |
* @package phpHtmlLib |
945 |
*/ |
946 |
class DefaultGUIDataListCSS extends CSSBuilder { |
947 |
|
948 |
function user_setup() { |
949 |
$this->add_entry(".datalist_col_head", "", |
950 |
array("font-family" => "arial, helvetica, sans-serif", |
951 |
"font-size" => "10pt", |
952 |
"font-weight" => "bold", |
953 |
"color" => "#000000", |
954 |
"background-color" => "#CCCCCC", |
955 |
"text-align" => "left", |
956 |
"white-space" => "nowrap", |
957 |
"height" => "20px", |
958 |
"vertical-align" => "middle", |
959 |
"border-left" => "1px solid white", |
960 |
"border-top" => "1px solid white", |
961 |
"border-right" => "1px solid gray", |
962 |
"border-bottom" => "1px solid gray", |
963 |
"padding-left" => "3px", |
964 |
"padding-right" => "3px") ); |
965 |
|
966 |
$this->add_entry(".datalist_col_head", "a.form_link:active,a.form_link:visited,a.form_link:link", |
967 |
array("color" => "#000000", |
968 |
"font-family" => "arial, helvetica, sans-serif", |
969 |
"font-size" => "10pt", |
970 |
"font-weight" => "bold", |
971 |
"text-decoration" => "none")); |
972 |
|
973 |
$this->add_entry(".datalist_col_head_hover", "", |
974 |
array("font-family" => "arial, helvetica, sans-serif", |
975 |
"font-size" => "10pt", |
976 |
"font-weight" => "bold", |
977 |
"color" => "#000000", |
978 |
"background-color" => "#dcdcdc", |
979 |
"text-align" => "left", |
980 |
"white-space" => "nowrap", |
981 |
"height" => "20px", |
982 |
"vertical-align" => "middle", |
983 |
"border-left" => "1px solid white", |
984 |
"border-top" => "1px solid white", |
985 |
"border-right" => "1px solid gray", |
986 |
"border-bottom" => "1px solid gray", |
987 |
"padding-left" => "3px", |
988 |
"padding-right" => "3px") ); |
989 |
|
990 |
$this->add_entry(".datalist_col_head_clicked", "", |
991 |
array("font-family" => "arial, helvetica, sans-serif", |
992 |
"font-size" => "10pt", |
993 |
"font-weight" => "bold", |
994 |
"color" => "#000000", |
995 |
"background-color" => "#dddddd", |
996 |
"text-align" => "left", |
997 |
"white-space" => "nowrap", |
998 |
"height" => "20px", |
999 |
"vertical-align" => "middle", |
1000 |
"border-left" => "1px solid white", |
1001 |
"border-top" => "1px solid white", |
1002 |
"border-right" => "1px solid gray", |
1003 |
"border-bottom" => "1px solid gray", |
1004 |
"padding-left" => "3px", |
1005 |
"padding-right" => "3px") ); |
1006 |
|
1007 |
$this->add_entry( ".datalist_border", "", |
1008 |
array("border" => "1px solid #999999")); |
1009 |
|
1010 |
$this->add_entry( ".datalist_title", "", |
1011 |
array("font-family" => "arial", |
1012 |
"font-size" => "10pt", |
1013 |
"font-weight" => "bold", |
1014 |
"color" => "#FFFFFF", |
1015 |
"background-color" => "#999999", |
1016 |
"white-space" =>"nowrap")); |
1017 |
|
1018 |
$this->add_entry( ".datalist_data_cell", "", |
1019 |
array( |
1020 |
"font-family" => "arial", |
1021 |
"font-size" => "10pt", |
1022 |
"padding-left" => "3px", |
1023 |
"padding-right" => "3px", |
1024 |
"border-top" => "1px solid #dddddd")); |
1025 |
|
1026 |
$this->add_entry( ".datalist_actionbar", "", |
1027 |
array( |
1028 |
"border" => "1px solid #999999") ); |
1029 |
|
1030 |
$this->add_entry( ".datalist_actionbar_data_cell", "", |
1031 |
array( |
1032 |
"font-family" => "arial", |
1033 |
"font-size" => "10pt", |
1034 |
"background" => "#CCCCCC", |
1035 |
"padding-left" => "3px", |
1036 |
"padding-right" => "3px", |
1037 |
"border-top" => "1px solid #dddddd")); |
1038 |
|
1039 |
$this->add_entry( ".datalist_bottom_seperator", "", |
1040 |
array( |
1041 |
"font-size" => "5px", |
1042 |
"line-height" => "5px", |
1043 |
"background" => "#CCCCCC", |
1044 |
"text-align" => "left", |
1045 |
"white-space" => "nowrap", |
1046 |
"height" => "5px", |
1047 |
"border-left" => "1px solid #FFFFFF", |
1048 |
"border-top" => "1px solid #FFFFFF", |
1049 |
"border-right" => "1px solid #dddddd", |
1050 |
"border-bottom" => "1px solid #dddddd", |
1051 |
"padding-left" => "3px", |
1052 |
"padding-right" => "3px")); |
1053 |
} |
1054 |
} |
1055 |
?> |