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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by jonen, Fri Feb 21 03:23:43 2003 UTC revision 1.11 by jonen, Thu May 6 16:27:48 2004 UTC
# Line 1  Line 1 
1  <?php  <?php
   
2  /**  /**
3   *   *
4   * This file contains the Default DataList child   * This file contains the Default DataList child
# Line 10  Line 9 
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   * This class is the Default phpHtmlLib GUI interface
# Line 24  Line 27 
27   */   */
28  class DefaultGUIDatalist extends DataList {  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         * 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    
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    
82    
83        /**
84         * Do we show action bar row?
85         */
86        var $_show_actionbar = TRUE;
87    
88        /**
89         * This variable tells us whether to display
90         * select all checkbox
91         */
92        var $_allow_select_all = TRUE;
93    
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        /**
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        /**
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          function gui_init() {          function gui_init() {
159                  $container = container();                  $container = container();
160                  $container->add( $this->build_tool_link("first"),          if (!$this->get_showall()) {
161                $container->add( $this->build_tool_link("first"),
162                                                   $this->build_tool_link("prev"),                                                   $this->build_tool_link("prev"),
163                                                   $this->build_tool_link("next"),                                                   $this->build_tool_link("next"),
164                                                   $this->build_tool_link("last"),                                                   $this->build_tool_link("last"),
165                                                   $this->build_tool_link("all"),                                                   $this->build_tool_link("expand") );
166                                                   $this->get_page_info() );          }
167                    
168            $container->add_reference( $this->__page_info );
169    
170                  $this->_data_table = html_table($this->get_width(),0,0,0,"center");                  $this->_data_table = html_table($this->get_width());
171                  $this->_data_table->set_class("datalist_border");                  $this->_data_table->set_class("datalist_border");
172    
173                  $this->_tool_td = html_td("datalist_title", "right", $container);                  $this->_tool_td = html_td("datalist_title", "right", $container);
174          $this->_tool_td->set_style("padding-top: 5px; padding-right: 5px;");          $this->_tool_td->set_style("padding-top: 5px; padding-right: 5px;");
175                  $this->_tool_td->set_tag_attribute("colspan", count($this->_columns)-1);  
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    
186                  $title = new TDtag(array("align" => "left",                  $title = new TDtag(array("align" => "left",
187                                                                   "class" => "datalist_title",                                                                   "class" => "datalist_title",
188                                                                   "style" => "padding-left: 5px;"),                                                                   "style" => "padding-left: 5px;"),
189                                                     $this->get_title() );                                                     $this->get_title() );
190    
191            $title_table->add( new TRtag( array(), $title,
192                                          $this->_tool_td) );
193    
194    
195                  //add the header tr reference                  //add the header tr reference
196                  //it will get populated later                  //it will get populated later
197                  $this->_header_tr = new TRtag;                  $this->_header_tr = new TRtag;
198                  $this->_data_table->add( new TRtag(array(), $title, $this->_tool_td) );                  //$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                  $this->_data_table->add_reference($this->_header_tr);                  $this->_data_table->add_reference($this->_header_tr);
202    
203                  //initialize the first date row                  //initialize the first date row
# Line 60  class DefaultGUIDatalist extends DataLis Line 209  class DefaultGUIDatalist extends DataLis
209    
210          }          }
211    
212        /**
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          function child_build_column_header($name, $col, $cnt) {          function child_build_column_header($name, $col, $cnt) {
223                  $td = $this->build_column_header($name, $col, $cnt);          if (!$this->_cur_col_cntr) {
224                  $this->_header_tr->add( $td );              $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                $this->_cur_col_cntr = 0;
250            } else {
251                $this->_cur_col_cntr++;
252            }        
253          }          }
254    
255          function child_add_row_cell($obj, $col_name, $last_in_row_flag) {          function child_add_row_cell($obj, $col_name, $last_in_row_flag, $row_data) {
256                  $td = $this->wrap_column_item($obj, $col_name);          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    
273                  $this->_data_row->add( $td );                  
274                  if ($last_in_row_flag) {                  if ($last_in_row_flag) {
275                //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                          $this->_data_table->add_row( $this->_data_row );                          $this->_data_table->add_row( $this->_data_row );
286                          $this->_data_row = new TRtag;                          $this->_data_row = new TRtag;
287                  }              $this->_cur_col_cntr = 0;
288                    } else {
289                $this->_cur_col_cntr++;
290            }
291          }          }
292    
293        /**
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          function child_get_gui() {          function child_get_gui() {
307                  return $this->_data_table;          $this->__page_info = $this->get_page_info();
308            return container( $this->_data_table,
309                              $this->_build_actionbar() );
310            }
311            
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    
326      /**      /**
# Line 104  class DefaultGUIDatalist extends DataLis Line 348  class DefaultGUIDatalist extends DataLis
348    
349              $td->set_tag_attribute("title","Sort By ".$col_name);              $td->set_tag_attribute("title","Sort By ".$col_name);
350    
351              $td->push(html_a($col_url, $col_name,"form_link"));              $td->add(html_a($col_url, $col_name,"form_link"));
352    
353              if ($this->_columns[$col_name]["data_name"] == $this->orderby()) {              if ($this->_columns[$col_name]["data_name"] == $this->orderby()) {
354    
# Line 112  class DefaultGUIDatalist extends DataLis Line 356  class DefaultGUIDatalist extends DataLis
356                                          $alt_title = "Sorted in Ascending Order";                                          $alt_title = "Sorted in Ascending Order";
357                      $img = html_img($this->get_image_path()."/picto_down.gif",11,11,'',$alt_title);                      $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;");                      $img->set_tag_attribute("style", "padding-left: 5px;margin-left:5px;vertical-align:middle;");
359                      $td->push($img);                      $td->add($img);
360                  } else {                  } else {
361                                          $alt_title = "Sorted in Descending Order";                                          $alt_title = "Sorted in Descending Order";
362                      $img = html_img($this->get_image_path()."/picto_up.gif",11,11,'',$alt_title);                      $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;");                      $img->set_tag_attribute("style", "padding-left: 5px;margin-left:5px;vertical-align:middle;");
364                      $td->push($img);                      $td->add($img);
365                  }                  }
366              }              }
367    
# Line 131  class DefaultGUIDatalist extends DataLis Line 375  class DefaultGUIDatalist extends DataLis
375    
376    
377              if ($this->get_form_method() == "POST") {              if ($this->get_form_method() == "POST") {
378                  $td->set_tag_attribute("onClick", $col_url);                  $td->set_tag_attribute("onclick", $col_url);
379              }              }
380              else {              else {
381                  $td->set_tag_attribute("onClick", "javascript:document.location='".$col_url."';");                  $td->set_tag_attribute("onclick", "javascript:document.location='".$col_url."';");
382              }              }
383          } else {          } else {
384              $td->push($col_name);              $td->add($col_name);
385              $td->set_tag_attribute("style", $style."padding-left:5px;padding-right:5px;white-space:nowrap;");              $td->set_tag_attribute("style", "padding-left:5px;padding-right:5px;white-space:nowrap;");
386          }          }
387    
388          return $td;          return $td;
# Line 163  class DefaultGUIDatalist extends DataLis Line 407  class DefaultGUIDatalist extends DataLis
407          if ($obj == '') {          if ($obj == '') {
408              $obj = "&nbsp;";              $obj = "&nbsp;";
409          }          }
         // if item is an Array we will replace it with an link or contained form object  
         elseif( is_array($obj) ) {  
           $cur_row_index = $this->_datasource->get_cur_data_index();  
           $parent_guid = $this->_datasource->_data[$cur_row_index]['guid'];  
           foreach($obj as $key => $value) {  
             if(is_numeric($key)) {  
                 $guid = $value['guid'];  
                 $list[$key] = $guid;  
             }  
                 }  
                 if(is_array($list) ) {  
               $container = container(  
                   form_open($obj[guid], $_SERVER["PHP_SELF"] ),  
                   form_select("guid", $list),  
                   form_hidden("ap", "oedit"),  
                   form_hidden("guid", $obj['guid']),  
                   form_hidden("class", $col_name),  
                   form_submit("submit","view" ),  
                   form_close()  
                   );  
               $obj = $container;  
             } else {  
                   $obj = html_a($_SERVER["PHP_SELF"] . "?ap=oedit&guid=" . $obj['guid'] . "&class=" . $col_name, "view");  
                 }  
         }  
           
410    
411          //make sure we don't put a right border on the last          //make sure we don't put a right border on the last
412          //column we are working on.          //column we are working on.
413          $style = "padding-left: 3px;padding-right:3px;border-top: 1px solid #dddddd;";          //$style = "padding-left: 3px;padding-right:3px;border-top: 1px solid #dddddd;";
414            
415    
416                  if ($this->_columns[$col_name]["data_name"] == $this->orderby()) {                  if ($this->_columns[$col_name]["data_name"] == $this->orderby()) {
417              $style .= "background-color: #f4f4f4;";              $style = "background-color: #f4f4f4;";
418          } else {          } else {
419                          $style .= "background-color: #ffffff;";                          $style = "background-color: #ffffff;";
420                  }                  }
421    
422          $align = $this->_columns[$col_name]["align"];          $align = $this->_columns[$col_name]["align"];
423          $td = new TDtag(array("align" => $align,          $td = new TDtag(array("align" => $align,
424                                "style" => $style,                                "style" => $style,
425                                                            "class" => "font10"));                                                            "class" => "datalist_data_cell"));
426    
427          if (is_object($obj) && $obj->_tag == "td") {          if (is_object($obj) && $obj->_tag == "td") {
428                          return $obj;                          return $obj;
# Line 228  class DefaultGUIDatalist extends DataLis Line 447  class DefaultGUIDatalist extends DataLis
447                                 "align" => "left",                                 "align" => "left",
448                                 "class" => "font10");                                 "class" => "font10");
449    
450          $table = html_table($this->get_width(),0,0,0,"center");          $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    
457          //test to see if they want to render the outer borders          //test to see if they want to render the outer borders
458          $table->set_tag_attribute("style", "border-left: 1px solid #a1a1a1;".          $table->set_tag_attribute("style", "border-left: 1px solid #a1a1a1;".
# Line 237  class DefaultGUIDatalist extends DataLis Line 461  class DefaultGUIDatalist extends DataLis
461          $td = new TDtag($td_attributes);          $td = new TDtag($td_attributes);
462    
463          if ($this->search_type() == "advanced") {          if ($this->search_type() == "advanced") {
464              $td->push($this->_build_advanced_search_form());              $td->add($this->_build_advanced_search_form());
465          } else {          } else {
466              $td->push($this->_build_simple_search_form());              $td->add($this->_build_simple_search_form());
467          }          }
468          $table->push_row($td);          $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    
477          return container($this->_build_search_title(), $table);              $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      }      }
486    
487      /**      /**
# Line 253  class DefaultGUIDatalist extends DataLis Line 491  class DefaultGUIDatalist extends DataLis
491       */       */
492      function _build_search_title() {      function _build_search_title() {
493          //build the title stacked table          //build the title stacked table
494          $title = html_table($this->get_width(), 0, 0, 0, "center");          $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    
516          //test to see if they want to render the outer borders          //test to see if they want to render the outer borders
517          $title->set_tag_attribute("style","border: 1px solid #a1a1a1;");          $title->set_tag_attribute("style","border: 1px solid #a1a1a1;");
518          $title->push_row(new TDtag(array("class" => "datalist_title",          $title->add_row(new TDtag(array("class" => "datalist_title",
519                                                                                   "style" => "color: ".$this->_title_fcolor.";".                                           "align" => "left"), $c));
                                                                                             "background-color: ".$this->_title_color.";"), "&nbsp;Search"));  
520    
521          return $title;          return $title;
522      }      }
# Line 285  class DefaultGUIDatalist extends DataLis Line 542  class DefaultGUIDatalist extends DataLis
542          if ($cnt == 1) {          if ($cnt == 1) {
543              //user only has 1 field to show.              //user only has 1 field to show.
544              list($name, $field) = each($fields);              list($name, $field) = each($fields);
545              $container->push("Find ".$name."&nbsp;&nbsp;");              $container->add($this->_search_text["find"]." ".$name."&nbsp;&nbsp;");
546          } else {          } else {
547              //user has many fields to show.              //user has many fields to show.
548              $container->push("Find ",              $container->add($this->_search_text["find"]." ",
549                               form_select($this->_search_fieldVar, $fields, $this->search_field()));                               form_select($this->_vars["search_fieldVar"], $fields, $this->search_field()));
550          }          }
551    
552          if ($this->get_simple_search_modifier()) {          if ($this->get_simple_search_modifier()) {
553              //the user wants the search modifier turned on.              //the user wants the search modifier turned on.
554              $container->push($this->_build_simple_search_modifier());              $container->add($this->_build_simple_search_modifier());
555          }          }
556    
557          $container->push(form_text($this->_search_valueVar, $this->search_value_filter($this->search_value()), "20", "100", array("style"=>"vertical-align:middle;")),          $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(), "Search", array("style"=>"vertical-align:middle;")));                           form_submit($this->get_form_name(),
559                                         $this->_search_text["button"], array("style"=>"vertical-align:middle;")));
560    
561          if ($this->is_advanced_search_enabled()) {          if ($this->is_advanced_search_enabled()) {
562              $span = html_span(html_a("ass","Advanced Search", "title"));              $span = html_span(html_a("#","Advanced Search", "title"));
563              $container->push("&nbsp;", $span);              $container->add("&nbsp;", $span);
564          }          }
565    
566          if ($cnt == 1) {          if ($cnt == 1) {
567              $container->push(form_hidden($this->_search_fieldVar, $field));              $container->add(form_hidden($this->_vars["search_fieldVar"], $field));
568          }          }
           
         $hidden_fields = $this->get_hidden_fields();  
         if(is_array($hidden_fields)) {  
           foreach($hidden_fields as $key => $value) {  
             $container->push(form_hidden($key, $value));  
           }  
         }  
           
         $container->push(form_close() );  
569    
570          return $container;          return $container;
571      }      }
572    
573    
574      function get_hidden_fields() {      /**
575          user_error("DefaulGUIDataList::get_hidden_fields() - ".       * This function adds an action column.  This
576                                     "child class must override this method ".       * adds a column of either checkboxes or radio
577                                     "this function should return a hash for hidden fields, if not needed just return" );       * 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         * 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        }
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                        $obj->set_tag_attribute("onclick", "javascript:mass(this.form)");
766                    } 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                $this->_visible_checkbox_items[$form_value] = TRUE;
786                break;
787            }
788            $td->add($obj);
789            $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            } else {
819                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                $table = html_table($this->get_width());
860                $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                    $td->add(html_img($this->get_image_path()."/arrow_right.gif"));
903                }
904                else {
905                    $td->add("&nbsp;");
906                }
907            }
908            else {
909                $td->set_tag_attribute("align", "right");
910                if ($this->_has_action_column("LAST") &&
911                    $this->_datasource->get_total_rows()) {
912                    $td->add(html_img($this->get_image_path()."/arrow_left.gif"));
913                }
914                else {
915                    $td->add("&nbsp;");
916                }
917            }
918            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                $td->add($this->actionbar_cell());
944            }
945            else {
946                $td->add("&nbsp;");
947            }
948    
949            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            $js = '';
997    
998            if ($this->_collapsable_search) {
999                $js .= $this->_search_javascript();
1000            }
1001    
1002    
1003            if ($this->_has_action_column("FIRST") || $this->_has_action_column("LAST")) {
1004                $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                if ($last == "checkbox" || $first == "checkbox") {
1007                    $js .= $this->_checkbox_javascript();
1008                }            
1009            }
1010    
1011            if (strlen($js) > 0) {
1012                $script = new SCRIPTtag(array("language" => "Javascript"));
1013                $script->add($js);
1014                return $script;
1015            } else {
1016                return NULL;
1017            }
1018        }
1019    
1020        /**
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            $js .= "  if (form.".$var_name.".checked) {\n";
1033            $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            $js .= "    if (form.elements[i].name.substring(0, ".strlen($var_name).") == '".$var_name."' && !form.elements[i].disabled) {\n";
1039            $js .= "      form.elements[i].checked = value;\n";
1040            $js .= "    }\n";
1041            $js .= "  }\n";
1042            $js .= "}\n";
1043    
1044            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        }
1084    
1085    
1086  }  }
1087    
1088  /**  /**
# Line 359  class DefaultGUIDataListCSS extends CSSB Line 1114  class DefaultGUIDataListCSS extends CSSB
1114    
1115                  $this->add_entry(".datalist_col_head", "a.form_link:active,a.form_link:visited,a.form_link:link",                  $this->add_entry(".datalist_col_head", "a.form_link:active,a.form_link:visited,a.form_link:link",
1116                                                   array("color" => "#000000",                                                   array("color" => "#000000",
1117                                   "font-family" => "arial, helvetica, sans-serif",
1118                                   "font-size" => "10pt",
1119                                   "font-weight" => "bold",
1120                                                             "text-decoration" => "none"));                                                             "text-decoration" => "none"));
1121    
1122                  $this->add_entry(".datalist_col_head_hover", "",                  $this->add_entry(".datalist_col_head_hover", "",
# Line 405  class DefaultGUIDataListCSS extends CSSB Line 1163  class DefaultGUIDataListCSS extends CSSB
1163                                                                  "color" => "#FFFFFF",                                                                  "color" => "#FFFFFF",
1164                                                                  "background-color" => "#999999",                                                                  "background-color" => "#999999",
1165                                                                  "white-space" =>"nowrap"));                                                                  "white-space" =>"nowrap"));
1166    
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          }                }      
1203  }  }
1204  ?>  ?>

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.11

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