/[cvs]/nfo/php/libs/com.newsblob.phphtmllib/widgets/data_list/DefaultGUIDataList.inc
ViewVC logotype

Annotation of /nfo/php/libs/com.newsblob.phphtmllib/widgets/data_list/DefaultGUIDataList.inc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.11 - (hide annotations)
Thu May 6 16:27:48 2004 UTC (20 years, 4 months ago) by jonen
Branch: MAIN
CVS Tags: HEAD
Changes since 1.10: +246 -63 lines
 updated all to v2.4.1 - Apr 01, 2004

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

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed