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

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

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

revision 1.4 by joko, Thu Feb 13 00:40:51 2003 UTC revision 1.5 by jonen, Sat Feb 22 21:08:35 2003 UTC
# Line 1  Line 1 
1  <?php  <?php
   
2  /**  /**
3   * This is the base class for managing a list   * This is the base class for managing a list
4   * of data points.   * of data points.
# Line 8  Line 7 
7   * @package phpHtmlLib   * @package phpHtmlLib
8   */   */
9    
10    /**
11     * Some global defines used
12     */
13  define("SORTABLE", TRUE);  define("SORTABLE", TRUE);
14  define("NOT_SORTABLE", FALSE);  define("NOT_SORTABLE", FALSE);
15  define("SEARCHABLE", TRUE);  define("SEARCHABLE", TRUE);
# Line 142  class DataList extends BaseWidget { Line 144  class DataList extends BaseWidget {
144       */       */
145      var $_global_prefix = '';      var $_global_prefix = '';
146    
     /**  
      * The offset variable name  
      */  
     var $_offsetVar = "offset";  
147    
148      /**      /**
149       * The order by variable name       * Holds an array of all the
150       */       * form vars we need for this
151      var $_orderbyVar = "orderby";       * class to work.
152         */
153        var $_vars = array("offsetVar" => "offset",
154                           "orderbyVar" => "orderby",
155                           "reverseorderVar" => "reverseorder",
156                           "numrowsVar" => "numrows",
157                           "showallVar" => "showall",
158                           "search_fieldVar" => "search_field",
159                           "search_valueVar" => "search_value",
160                           "search_typeVar" => "search_type",
161                           "simple_search_modifierVar" => "simple_search_modifier");
162    
163      /**      /**
164       * Holds the db column name that       * Holds the db column name that
# Line 159  class DataList extends BaseWidget { Line 167  class DataList extends BaseWidget {
167      var $_default_orderby = '';      var $_default_orderby = '';
168    
169      /**      /**
      * The reverseorder variable name  
      */  
     var $_reverseorderVar = "reverseorder";  
   
     /**  
170       * Holds a flag to let us know to       * Holds a flag to let us know to
171       * reverse order the column by default       * reverse order the column by default
172       */       */
173      var $_default_reverseorder = "false";      var $_default_reverseorder = "false";
174    
175      /**      /**
      * The number of rows variable name  
      */  
     var $_numrowsVar = "numrows";  
   
         /**  
      * This var to tell us to show all  
      * data or not.  
      */  
     var $_showallVar = "showall";  
   
     /**  
      * The search field variable  
      */  
     var $_search_fieldVar  = "search_field";  
   
     /**  
      * The search value  
      */  
     var $_search_valueVar  = "search_value";  
   
     /**  
      * The type of search  
      * advanced/simple  
      */  
     var $_search_typeVar = "search_type";  
   
     /**  
      * The simple search modifier  
      * var name.  
      *  
      */  
     var $_simple_search_modifierVar = "simple_search_modifier";  
     
   
     /**  
176       * Flag to let us know that search       * Flag to let us know that search
177       * is enabled.       * is enabled.
178       *       *
# Line 227  class DataList extends BaseWidget { Line 195  class DataList extends BaseWidget {
195      var $_simple_search_modifier = FALSE;      var $_simple_search_modifier = FALSE;
196    
197    
198          /**      /**
199           * Holds the object block that is the       * Holds the object block that is the
200           * search UI       * search UI
201           */       */
202          var $_search_table = NULL;      var $_search_table = NULL;
203    
204      /**      /**
205       * This holds a list of       * This holds a list of
# Line 243  class DataList extends BaseWidget { Line 211  class DataList extends BaseWidget {
211      var $_save_vars = array();      var $_save_vars = array();
212    
213    
214          /**      /**
215           * The column descriptions       * The column descriptions
216           * for the data we are working on       * for the data we are working on
217           *       *
218           * @var array       * @var array
219           */       */
220          var $_columns = array();      var $_columns = array();
221    
222          /**      /**
223       * Keeps track of the # of columns we have       * Keeps track of the # of columns we have
224       */       */
225      var $_num_columns = 0;      var $_num_columns = 0;
226    
227    
228          /**      /**
229           * This holds the form attributes       * This holds the form attributes
230           *       *
231           */       */
232          var $_form_attributes = array("method" => "GET",      var $_form_attributes = array("method" => "GET",
233                                                                    "target" => "",                                    "target" => "",
234                                                                    "action" => "",                                    "action" => "",
235                                                                    "name" => "");                                    "name" => "");
236    
237          /**      /**
238           * Build everything inside a form?       * Build everything inside a form?
239           *       *
240           */       */
241          var $_form_render_flag = FALSE;      var $_form_render_flag = FALSE;
242    
243    
244          /**      /**
245           * flag to let us know if we want to show       * flag to let us know if we want to show
246           * the results or not.       * the results or not.
247           */       */
248          var $_show_results_flag = TRUE;      var $_show_results_flag = TRUE;
249    
250    
251          /**      /**
252           * Holds our reference/copy of the       * Holds our reference/copy of the
253           * DataListSource object which is used to       * DataListSource object which is used to
254           * access the data that this object uses       * access the data that this object uses
255           *       *
256           * @var DataListSource object       * @var DataListSource object
257           */       */
258          var $_datasource = NULL;      var $_datasource = NULL;
259    
260          /**      /**
261           * This stores the base path to where the       * This stores the base path to where the
262           * tool link images live.  This lets you       * tool link images live.  This lets you
263           * specify a new path to where your images       * specify a new path to where your images
264           * live.       * live.
265           */       */
266          var $_image_path = "img/widgets";      var $_image_path = "/phphtmllib/images/widgets";
267            
268            
269        /**
270          /**       * The constructor
271           * The constructor       *
272           *       * @param string - the title of the data list
273           * @param string - the title of the data list       * @param string - the overall width
274           * @param string - the overall width       * @param string - the column to use as the default sorting order
275           * @param string - the column to use as the default sorting order       * @param boolean - sort the default column in reverse order?
276           * @param boolean - sort the default column in reverse order?       */
277           */      function DataList($title, $width = "100%", $default_orderby='',
278          function DataList($title, $width = "100%", $default_orderby='',                        $default_reverseorder=FALSE) {
279                                            $default_reverseorder=FALSE ) {          $this->set_title( $title );
280                  $this->set_title( $title );          $this->set_form_name( str_replace(' ', '_', strtolower($title)) );
281                  $this->set_form_name( str_replace(' ', '_', strtolower($title)) );          $this->set_width( $width );
282                  $this->set_width( $width );  
283    
284          $this->_default_orderby = $default_orderby;          $this->_default_orderby = $default_orderby;
285                  if ($default_reverseorder === TRUE) {          if ( $default_reverseorder === TRUE ) {
286                          $default_reverseorder = "true";              $default_reverseorder = "true";
287                  } if ($default_reverse_order === FALSE) {          }if ( $default_reverse_order === FALSE ) {
288                          $default_reverseorder = "false";              $default_reverseorder = "false";
289                  }          }
290          $this->_default_reverseorder = $default_reverseorder;          $this->_default_reverseorder = $default_reverseorder;
291    
292    
293          //Set the global prefix for our variables.          //Set the global prefix for our variables.
294          //want to make sure we can have multiple          //want to make sure we can have multiple
295          //item lists per html page.          //item lists per html page.
296          $this->set_global_prefix('');          $this->set_global_prefix('');
297    
298                  //child class MUST override this          //child class MUST override this
299                  //method to automatically set          //method to automatically set
300                  //the DataListSource object.          //the DataListSource object.
301                  //This class doesn't work without it.          //This class doesn't work without it.
302                  $this->get_data_source();          $this->get_data_source();
303    
304          //Call the subclass setup function.          //Call the subclass setup function.
305          //This is a way to get around having          //This is a way to get around having
306          //to override the constructor and          //to override the constructor and
307          //pass in the same params.          //pass in the same params.
308          $this->user_setup();          $this->user_setup();
309          }      }
310    
311        /**
312         * This function renders the final
313         * widget
314         *
315         */
316        function render($indent_level, $output_debug) {
317    
318          /**          //setup the columns in their sorts
319           * This function renders the final          $this->setup_columns();
320           * widget  
321           *          //do any data prefetch work
322           */          //which may be child specific
323          function render($indent_level, $output_debug) {          if ( $this->_show_results() ) {
324                $this->data_prefetch();
325                  //setup the columns in their sorts          }
326                  $this->setup_columns();  
327            //This function gives the child class
328                  //do any data prefetch work          //a chance to build the tables/divs/containers
329                  //which may be child specific          //that will be responsible for the look/feel
330                  if ($this->_show_results()) {          //of the DataList
331                          $this->data_prefetch();          $this->gui_init();
332                  }  
333            //see if we need to build the search area.
334                  //This function gives the child class          if ( $this->is_search_enabled() || $this->is_advanced_search_enabled() ) {
335                  //a chance to build the tables/divs/containers              $this->_search_table = $this->child_build_search_table();
336                  //that will be responsible for the look/feel              if ( $this->_search_table ) {
337                  //of the DataList                  $this->set_form_render(TRUE);
338                  $this->gui_init();              }
   
                 //see if we need to build the search area.  
                 if ($this->is_search_enabled() || $this->is_advanced_search_enabled()) {  
                         $this->_search_table = $this->child_build_search_table();  
                         if ($this->_search_table) {  
                                 $this->set_form_render(TRUE);  
                         }  
339          }          }
                   
340    
341          if ($this->get_form_render()) {  
342            if ( $this->get_form_render() ) {
343              $form =  new FORMtag( array("method" => $this->get_form_method(),              $form =  new FORMtag( array("method" => $this->get_form_method(),
344                                          "action" => $this->build_base_url(),                                          "action" => $this->build_base_url(),
345                                          "name" => $this->get_form_name(),                                          "name" => $this->get_form_name(),
346                                          "style" => "margin-top: 0px;margin-bottom:0px;") );                                          "style" => "margin-top: 0px;margin-bottom:0px;") );
347    
348                          $target = $this->get_form_target();              $target = $this->get_form_target();
349              if ($target != NULL)              if ( $target != NULL )
350                  $form->set_tag_attribute("target",$target);                  $form->set_tag_attribute("target",$target);
351    
352                          $action = $this->get_form_action();              $action = $this->get_form_action();
353              if ($action != NULL)              if ( $action != NULL )
354                  $form->set_tag_attribute("action",$action);                  $form->set_tag_attribute("action",$action);
355    
356                          //now build the UI and return it              //now build the UI and return it
357                          $form->add( $this->build_gui() );              $form->add( $this->build_gui() );
358                
                         //add the save vars the user wants.  
                         $form->add( $this->_build_save_vars() );  
359          } else {          } else {
360                          $form = container();              $form = container();
361    
362                //now build the UI and return it
363                $form->add( $this->build_gui() );
364            }
365            
366            //add the hidden vars if we are a POST
367            if ($this->get_form_method() == "POST") {
368                $form->add( $this->_build_default_vars() );
369            }
370    
371                          //now build the UI and return it          //add the save vars the user wants.
372                          $form->add( $this->build_gui() );          $form->add( $this->_build_save_vars() );
                 }  
373    
374                  //add any javascript required          //add any javascript required
375          $container = container( $this->_javascript(), $form );          $container = container( $this->_javascript(), $form );
376          return $container->render( $indent_level, $output_debug );          return $container->render( $indent_level, $output_debug );
377          }      }
378    
379        /**
380         * This function is responsible for calling the child
381         * class's methods for building the GUI container.
382         * This function builds the search area, the
383         * title, page controls, the column headers,
384         * and walks the rows of data and adds them
385         *
386         * A child class can override this method to
387         * move the placement of the search box
388         * relative to the data list.  By default
389         * the search area comes above the table
390         * for the data list and page controls
391         *
392         * @return Container
393         */
394        function build_gui() {
395            $container = container();
396    
397            //if we have a search area to show
398            //add it to the ui.
399            if ( $this->_search_table ) {
400                $container->add( $this->_search_table );
401            }
402    
403            if ( $this->_show_results() ) {
404                //walk the list of columns and call the child
405                //method to add it
406                $column_count = count($this->_columns);
407                foreach( $this->_columns as $name => $col ) {
408                    $this->child_build_column_header( $name, $col, $column_count);
409                }
410    
411          /**              //now walk the list of rows and build and add the
412           * This function is responsible for calling the child              //cells of data
413           * class's methods for building the GUI container.              $col_count = count($this->_columns);
414           * This function builds the search area, the              while ( $row = $this->_datasource->get_next_data_row() ) {
415           * title, page controls, the column headers,                  $cnt = 1;
416           * and walks the rows of data and adds them                  foreach( $this->_columns as $col_name => $data ) {
417           *                      $obj = $this->build_column_item($row, $col_name);
418           * A child class can override this method to                      if ( !is_object($obj) ) {
419           * move the placement of the search box                          $obj = $this->_clean_string($obj, $col_name);
          * relative to the data list.  By default  
          * the search area comes above the table  
          * for the data list and page controls  
          *  
          * @return Container  
          */  
         function build_gui() {  
                 $container = container();  
                   
                 //if we have a search area to show  
                 //add it to the ui.  
                 if ($this->_search_table) {  
                         $container->add( $this->_search_table );  
                 }  
   
                 if ($this->_show_results()) {  
                         //walk the list of columns and call the child  
                         //method to add it  
                         $column_count = count($this->_columns);  
                         foreach( $this->_columns as $name => $col ) {  
                                 $this->child_build_column_header( $name, $col, $column_count);  
                         }  
                           
                         //now walk the list of rows and build and add the  
                         //cells of data  
                         $col_count = count($this->_columns);  
                         while ($row = $this->_datasource->get_next_data_row()) {  
                                 $cnt = 1;  
                                 foreach( $this->_columns as $col_name => $data ) {  
                                         $obj = $this->build_column_item($row, $col_name);  
                                         if (!is_object($obj)) {  
                                                 $obj = $this->_clean_string($obj, $col_name);  
420                      }                      }
421                                          //                      //
422                                          $this->child_add_row_cell($obj, $col_name, ($cnt == $col_count) ? TRUE : FALSE );                      $this->child_add_row_cell($obj, $col_name,
423                                          $cnt++;                                                (($cnt == $col_count) ? TRUE : FALSE),
424                                  }                                                $row);
425                          }                      $cnt++;
426                          $container->add( $this->child_get_gui() );                  }
427                  }              }
428                                $container->add( $this->child_get_gui() );
429            }
430                  return $container;  
431          }  
432            return $container;
433          /**      }
434           * This function is called automatically by  
435           * the DataList constructor.  It must be      /**
436           * extended by the child class to actually       * This function is called automatically by
437           * set the DataListSource object.       * the DataList constructor.  It must be
438           *       * extended by the child class to actually
439           *       * set the DataListSource object.
440           */       *
441          function get_data_source() {       *
442                  user_error("DataList::get_data_source() - ".       */
443                                     "child class must override this to ".      function get_data_source() {
444                                     "set the the DataListSource object.");          user_error("DataList::get_data_source() - ".
445          }                     "child class must override this to ".
446                       "set the the DataListSource object.");
447        }
448    
449      /**      /**
450       * A subclass can override this function       * A subclass can override this function
451       * to setup the class variables after       * to setup the class variables after
452       * the constructor.  The constructor       * the constructor.  The constructor
453       * automatically calls this function.       * automatically calls this function.
454           *       *
455       */       */
456      function user_setup() {      function user_setup() {
457          user_error("DataList::user_setup() - ".          user_error("DataList::user_setup() - ".
458                                     "child class must override this method ".                     "child class must override this method ".
459                                     "to set the columns, and any options for ".                     "to set the columns, and any options for ".
460                                     "the DataListSource.");                     "the DataListSource.");
461      }      }
462    
463      /**      /**
# Line 488  class DataList extends BaseWidget { Line 465  class DataList extends BaseWidget {
465       * to setup the class variables after       * to setup the class variables after
466       * the constructor.  The constructor       * the constructor.  The constructor
467       * automatically calls this function.       * automatically calls this function.
468           *       *
469       */       */
470      function gui_init() {      function gui_init() {
471          user_error("DataList::gui_init() - ".          user_error("DataList::gui_init() - ".
472                                     "child class must override this method ".                     "child class must override this method ".
473                                     "to set up the containers/objects that will ".                     "to set up the containers/objects that will ".
474                                     "hold the search area, page controls, ".                     "hold the search area, page controls, ".
475                                     "column headers and the data cells");                     "column headers and the data cells");
476      }      }
477    
478          /**      /**
479           * This method is supposed to be written by       * This method is supposed to be written by
480           * the child class to build and add the column       * the child class to build and add the column
481           * title to the UI       * title to the UI
482           *       *
483           * @param string - the title of the column       * @param string - the title of the column
484           * @param array - the column data ( from $this->_columns )       * @param array - the column data ( from $this->_columns )
485           * @param int - the column #       * @param int - the column #
486           *       *
487           */       */
488          function child_build_column_header($title, $col_data, $col_count) {      function child_build_column_header($title, $col_data, $col_count) {
489                  user_error("DataList::child_build_column_header() - ".          user_error("DataList::child_build_column_header() - ".
490                                     "child class must override this method ".                     "child class must override this method ".
491                                     "to build the object that will be the ".                     "to build the object that will be the ".
492                                     "individual column header/itle");                     "individual column header/itle");
493          }      }
494    
495          /**      /**
496           * This method is supposed to be written by       * This method is supposed to be written by
497           * the child class to add the cell data to the       * the child class to add the cell data to the
498           * current row in the UI       * current row in the UI
499           *       *
500           * @param mixed - the object/string/entity that       * @param mixed - the object/string/entity that
501           *                should get put into the column row cell.       *                should get put into the column row cell.
502           * @param string - the name/title of the column that the       * @param string - the name/title of the column that the
503           *                 object will live in       *                 object will live in
504           * @param boolean - flag that tells the function if this is       * @param boolean - flag that tells the function if this is
505           *                  is the last cell for the current row.       *                  is the last cell for the current row.
506           *       *
507           */       */
508          function child_add_row_cell($obj, $col_name, $last_in_row_flag) {      function child_add_row_cell($obj, $col_name, $last_in_row_flag) {
509                  user_error("DataList::child_build_column_header() - ".          user_error("DataList::child_add_row_cell() - ".
510                                     "child class must override this method ".                     "child class must override this method ".
511                                     "to build the object that will be the ".                     "to build the object that will be the ".
512                                     "individual column header/itle");                     "individual column data cell");
513          }      }
   
         /**  
          * This function is called after all of the data has  
          * been added to the UI object.  It just returns the  
          * container that is the entire UI for the DataList  
          *  
          * @return Container  
          */  
         function child_get_gui() {  
                 user_error("DataList::child_get_gui() - ".  
                                    "child class must override this method ".  
                                    "to return the wrapper that contains ".  
                                    "the entire UI.");  
         }  
   
         /**  
          * This function builds the search  
          * block that lives above the results  
          *  
          * @return Container  
          */  
         function child_build_search_table() {  
                 user_error("DataList::child_build_search_table() - ".  
                                    "child class must override this");  
                 return NULL;  
         }  
514    
515          /**      /**
516         * This function is called after all of the data has
517         * been added to the UI object.  It just returns the
518         * container that is the entire UI for the DataList
519         *
520         * @return Container
521         */
522        function child_get_gui() {
523            user_error("DataList::child_get_gui() - ".
524                       "child class must override this method ".
525                       "to return the wrapper that contains ".
526                       "the entire UI.");
527        }
528    
529        /**
530         * This function builds the search
531         * block that lives above the results
532         *
533         * @return Container
534         */
535        function child_build_search_table() {
536            user_error("DataList::child_build_search_table() - ".
537                       "child class must override this");
538            return NULL;
539        }
540    
541        /**
542       * This function provides a way to automatically       * This function provides a way to automatically
543       * add javascript to this object.       * add javascript to this object.
544       * This function is meant to be extended by the       * This function is meant to be extended by the
# Line 595  class DataList extends BaseWidget { Line 572  class DataList extends BaseWidget {
572                                $max_text_length=NULL) {                                $max_text_length=NULL) {
573    
574          $this->_columns[$label] = array("size" => $size,          $this->_columns[$label] = array("size" => $size,
575                                                                             "data_name" => $data_name,                                          "data_name" => $data_name,
576                                                                             "sortable" => $sortable,                                          "sortable" => $sortable,
577                                                                             "searchable" => $searchable,                                          "searchable" => $searchable,
578                                                                             "align" => $align,                                          "align" => $align,
579                                                                             "sortorder" => $sortorder,                                          "sortorder" => $sortorder,
580                                                                             "maxtextlength" => $max_text_length);                                          "maxtextlength" => $max_text_length);
581          $this->_num_headers++;          $this->_num_headers++;
582                    
583                  $this->_check_datasource("add_header_item");          $this->_check_datasource("add_header_item");
584                  $this->_datasource->add_column($label, $data_name, $sortable,          $this->_datasource->add_column($label, $data_name, $sortable,
585                                                                                  $searchable, $sortorder);                                         $searchable, $sortorder);
586      }      }
587    
588    
# Line 618  class DataList extends BaseWidget { Line 595  class DataList extends BaseWidget {
595       * @param string $prefix - the prefix for all vars.       * @param string $prefix - the prefix for all vars.
596       */       */
597      function set_global_prefix($prefix) {      function set_global_prefix($prefix) {
598          $this->_global_prefix           = $prefix;          $this->_global_prefix = $prefix;
599          $this->_offsetVar                       = $prefix . "offset";          //update all the vars used
600          $this->_orderbyVar                      = $prefix . "orderby";          foreach ($this->_vars as $name => $value ) {
601          $this->_reverseorderVar         = $prefix . "reverseorder";              $this->_vars[$name] = $prefix.$value;
602          $this->_numrowsVar                      = $prefix . "numrows";          }
         $this->_showallVar                      = $prefix . "showall";  
         $this->_search_fieldVar         = $prefix . "search_field";  
         $this->_search_valueVar         = $prefix . "search_value";  
                 $this->_search_typeVar          = $prefix . $this->_search_typeVar;  
         $this->_simple_search_modifierVar = $prefix . $this->_simple_search_modifierVar;  
603      }      }
604    
605      /**      /**
# Line 640  class DataList extends BaseWidget { Line 612  class DataList extends BaseWidget {
612          return $this->_global_prefix;          return $this->_global_prefix;
613      }      }
614    
615          /**      /**
616           * This function is used to set the       * This function is used to set the
617           * DataListSource object for this instance       * DataListSource object for this instance
618           *       *
619           * @param DataListSource object       * @param DataListSource object
620           */       */
621          function set_data_source( $datasource ) {      function set_data_source( $datasource ) {
622                  $this->_datasource = &$datasource;          $this->_datasource = &$datasource;
623          }      }
624    
625      /**      /**
626       * Enable the search ability.       * Enable the search ability.
# Line 657  class DataList extends BaseWidget { Line 629  class DataList extends BaseWidget {
629       */       */
630      function search_enable( ) {      function search_enable( ) {
631          $this->_search_flag = TRUE;          $this->_search_flag = TRUE;
632          if (!$this->is_advanced_search_enabled()) {          if ( !$this->is_advanced_search_enabled() ) {
633              $this->set_search_type("simple");              $this->set_search_type("simple");
634          }          }
635      }      }
# Line 691  class DataList extends BaseWidget { Line 663  class DataList extends BaseWidget {
663       */       */
664      function advanced_search_enable() {      function advanced_search_enable() {
665          $this->_advanced_search_flag = TRUE;          $this->_advanced_search_flag = TRUE;
666          if (!$this->is_search_enabled()) {          if ( !$this->is_search_enabled() ) {
667              $this->set_search_type("advanced");              $this->set_search_type("advanced");
668          }          }
669      }      }
# Line 737  class DataList extends BaseWidget { Line 709  class DataList extends BaseWidget {
709       * @param string       * @param string
710       */       */
711      function set_simple_search_modifier( $modifier = SEARCH_ALL ) {      function set_simple_search_modifier( $modifier = SEARCH_ALL ) {
712          if ($modifier == 0) {          if ( $modifier == 0 ) {
713              $this->_simple_search_modifier = SEARCH_BEGINS_WITH |              $this->_simple_search_modifier = SEARCH_BEGINS_WITH |
714                                               SEARCH_CONTAINS |                                               SEARCH_CONTAINS |
715                                               SEARCH_EXACT |                                               SEARCH_EXACT |
# Line 776  class DataList extends BaseWidget { Line 748  class DataList extends BaseWidget {
748          return $this->_default_rows_per_page;          return $this->_default_rows_per_page;
749      }      }
750    
751        /**
752         * This returns the Maximum # of rows to
753         * display when in expand mode
754         *
755         * @return int
756         */
757        function get_max_rows() {
758            return $this->_max_rows;
759        }
760    
761      /**      /**
762       * This function sets the save variables       * This sets the maximum # of rows to
763       * that the user/child wants to automatically       * display when in expand mode
764       * propogate       *
765         * @param int - new # of maximum rows
766         *              to display when in 'expand' mode
767       *       *
      * @param array - name=>value pairs of the data  
      *                that they want to propogate  
768       */       */
769      function set_save_vars( $vars ) {      function set_max_rows( $max ) {
770          $this->_save_vars = $vars;          $this->_max_rows = $max;
771      }      }
772    
         /**  
          * This returns the Maximum # of rows to  
          * display when in expand mode  
          *  
          * @return int  
          */  
         function get_max_rows() {  
                 return $this->_max_rows;  
         }  
   
         /**  
          * This sets the maximum # of rows to  
          * display when in expand mode  
          *  
          * @param int - new # of maximum rows  
          *              to display when in 'expand' mode  
          *  
          */  
         function set_max_rows( $max ) {  
                 $this->_max_rows = $max;  
         }  
773    
774    
775        /**
776         * This function is used to set up any
777         * data that needs to be munged before the
778         * data is fetched from the DataListSource
779         *
780         */
781        function data_prefetch() {
782            $this->_check_datasource("data_prefetch");
783    
784            if ( $this->showall() ) {
785                $this->set_default_num_rows( $this->get_max_rows() );
786                $this->set_numrows( $this->get_max_rows() );
787            }
788    
789          /**          $limit = $this->numrows();
790           * This function is used to set up any          $this->_datasource->query($this->offset(), $limit,
791           * data that needs to be munged before the                                    $this->orderby(), $this->reverseorder(),
792           * data is fetched from the DataListSource                                    $this->search_field(), $this->search_value(),
793           *                                    $this->simple_search_modifier_value(),
794           */                                    $this->search_type() );
795          function data_prefetch() {      }
                 $this->_check_datasource("data_prefetch");  
   
                 if ($this->showall()) {  
                         $this->set_default_num_rows( $this->get_max_rows() );  
                         $this->set_numrows( $this->get_max_rows() );  
                 }  
   
                 $limit = $this->numrows();  
                 $this->_datasource->query($this->offset(), $limit,  
                                                                    $this->orderby(), $this->reverseorder(),  
                                                                    $this->search_field(), $this->search_value(),  
                                                                    $this->simple_search_modifier_value(),  
                                                                    $this->search_type() );  
         }  
796    
797    
798    
# Line 845  class DataList extends BaseWidget { Line 804  class DataList extends BaseWidget {
804          $temp_headers = array();          $temp_headers = array();
805    
806          foreach( $this->_columns as $col_name => $data ) {          foreach( $this->_columns as $col_name => $data ) {
807              if ($data["sortorder"] == "reverse") {              if ( $data["sortorder"] == "reverse" ) {
808                  $data["reverseorder"] = "true";                  $data["reverseorder"] = "true";
809              }              } else {
             else {  
810                  $data["reverseorder"] = "false";                  $data["reverseorder"] = "false";
811              }              }
812              $temp_headers[$col_name] = $data;              $temp_headers[$col_name] = $data;
# Line 858  class DataList extends BaseWidget { Line 816  class DataList extends BaseWidget {
816    
817    
818    
819          /**      /**
820           * general DataListSource object checker.       * general DataListSource object checker.
821           *       *
822           */       */
823          function _check_datasource($function_name) {      function _check_datasource($function_name) {
824                  if (!is_object($this->_datasource)) {          if ( !is_object($this->_datasource) ) {
825                          user_error("DataList::".$function_name."() - DataListSource object is not set");              user_error("DataList::".$function_name."() - DataListSource object is not set");
826                          exit;              exit;
827                  }          }
828          }      }
829    
830    
831          /*********************************************/      /*********************************************/
832          /*     REQUEST VARIABLE SECTION              */      /*     REQUEST VARIABLE SECTION              */
833          /*********************************************/      /*********************************************/
834    
835    
836    
837        /**
838         * Function used to get the current
839         * value of one of the control vars
840         * for this class
841         *
842         * @param string - the name we want to get
843         * @param mixed - the default value if not set
844         * @return the current value or default if not set
845         */
846        function _get($name, $default_value=NULL) {
847            if ( !$_REQUEST[$this->_vars[$name]] ) {
848                $this->_set($name, $default_value);
849            }
850            //ddd( $name . " : ". $_REQUEST[$this->_vars[$name]] );
851            return $_REQUEST[$this->_vars[$name]];
852        }
853    
854        /**
855         * This function is used to set the
856         * value of the control var
857         *
858         * @param string - the name we want to get
859         * @param mixed - the new value for it.
860         */
861        function _set($name, $value) {
862            $_REQUEST[$this->_vars[$name]] = $value;
863        }
864    
865          /**      /**
866       * This function returns the current value       * This function returns the current value
867       * of the offset variable. This is an offset       * of the offset variable. This is an offset
868       * into the query return data set.       * into the query return data set.
# Line 882  class DataList extends BaseWidget { Line 870  class DataList extends BaseWidget {
870       * @return int - the current value.       * @return int - the current value.
871       */       */
872      function offset() {      function offset() {
873                  if (!$_REQUEST[$this->_offsetVar]) {          return(int)$this->_get("offsetVar", 0);
                         $this->set_offset(0);  
                 }  
                 return (int)$_REQUEST[$this->_offsetVar];  
874      }      }
875    
876          /**      /**
877       * This function is used to set/change       * This function is used to set/change
878       * the offset for this list.       * the offset for this list.
879       *       *
880       * @param int - the new offset.       * @param int - the new offset.
881       */       */
882      function set_offset($new_offset) {      function set_offset($new_offset) {
883                  $_REQUEST[$this->_offsetVar] = $new_offset;          $this->_set("offsetVar", $new_offset);
884      }      }
885    
886          /**      /**
887       * This function returns the value of the       * This function returns the value of the
888       * current orderby variable.       * current orderby variable.
889       *       *
890       * @return string.       * @return string.
891       */       */
892      function orderby() {      function orderby() {
893                  if (!$_REQUEST[$this->_orderbyVar]) {          return $this->_get("orderbyVar", $this->_default_orderby);
                         $_REQUEST[$this->_orderbyVar] = $this->_default_orderby;  
                 }  
   
                 return $_REQUEST[$this->_orderbyVar];  
894      }      }
895    
896          /**      /**
897       * This builds a query string var for the       * This builds a query string var for the
898       * orderby value.       * orderby value.
899       *       *
900       * @return string - "orderby=(thevalue)"       * @return string - "orderby=(thevalue)"
901       */       */
902      function build_orderby_querystring() {      function build_orderby_querystring() {
903          $str = $this->_orderbyVar."=".$this->orderby();          $str = $this->_vars["orderbyVar"]."=".urlencode($this->orderby());
904          return $str;          return $str;
905      }      }
906    
# Line 930  class DataList extends BaseWidget { Line 911  class DataList extends BaseWidget {
911       * @return string.       * @return string.
912       */       */
913      function reverseorder() {      function reverseorder() {
914                  if (!$_REQUEST[$this->_reverseorderVar]) {          return $this->_get("reverseorderVar", $this->_default_reverseorder);
                         $this->set_reverseorder($this->_default_reverseorder);  
                 }  
                 return $_REQUEST[$this->_reverseorderVar];  
915      }      }
916    
917      /**      /**
# Line 943  class DataList extends BaseWidget { Line 921  class DataList extends BaseWidget {
921       * @param string - the new value.       * @param string - the new value.
922       */       */
923      function set_reverseorder($new_value) {      function set_reverseorder($new_value) {
924                  $_REQUEST[$this->_reverseorderVar] = $new_value;          $this->_set("reverseorderVar", $new_value);
925      }      }
926    
927          /**      /**
928       * This builds a query string var for the       * This builds a query string var for the
929       * reverseorder value.       * reverseorder value.
930       *       *
931       * @return string - "orderby=(thevalue)"       * @return string - "orderby=(thevalue)"
932       */       */
933      function build_reverseorder_querystring() {      function build_reverseorder_querystring() {
934          $str = $this->_reverseorderVar."=".$this->reverseorder();          $str = $this->_vars["reverseorderVar"]."=".urlencode($this->reverseorder());
935          return $str;          return $str;
936      }      }
937    
# Line 964  class DataList extends BaseWidget { Line 942  class DataList extends BaseWidget {
942       * @return int - the number of rows       * @return int - the number of rows
943       */       */
944      function numrows() {      function numrows() {
945                  if (!$_REQUEST[$this->_numrowsVar]) {          return(int)$this->_get("numrowsVar", $this->_default_rows_per_page);
                         $this->set_numrows($this->_default_rows_per_page);  
                 }  
                 return (int) $_REQUEST[$this->_numrowsVar];  
946      }      }
947    
948      /**      /**
# Line 977  class DataList extends BaseWidget { Line 952  class DataList extends BaseWidget {
952       * @param int - the # of rows       * @param int - the # of rows
953       */       */
954      function set_numrows($new_numrows) {      function set_numrows($new_numrows) {
955                  $_REQUEST[$this->_numrowsVar] = $new_numrows;          $this->_set("numrowsVar", $new_numrows);
956      }      }
957    
958      /**      /**
# Line 987  class DataList extends BaseWidget { Line 962  class DataList extends BaseWidget {
962       * @return string       * @return string
963       */       */
964      function search_field() {      function search_field() {
965                  if (!$_REQUEST[$this->_search_fieldVar]) {          return $this->_get("search_fieldVar", '');
                         $_REQUEST[$this->_search_fieldVar] = '';  
                 }  
                 return $_REQUEST[$this->_search_fieldVar];  
966      }      }
967    
968          /**      /**
969       * This builds a query string var for the       * This builds a query string var for the
970       * searchfield value.       * searchfield value.
971       *       *
972       * @return string - "orderby=(thevalue)"       * @return string - "orderby=(thevalue)"
973       */       */
974      function build_searchfield_querystring() {      function build_searchfield_querystring() {
975          $str = $this->_search_fieldVar."=".$this->searchfield();          $str = $this->_vars["search_fieldVar"]."=".urlencode($this->searchfield());
976          return $str;          return $str;
977      }      }
978    
# Line 1011  class DataList extends BaseWidget { Line 983  class DataList extends BaseWidget {
983       * @return string       * @return string
984       */       */
985      function search_value() {      function search_value() {
986                  if (!$_REQUEST[$this->_search_valueVar]) {          return $this->_get("search_valueVar", '');
                         $_REQUEST[$this->_search_valueVar] = '';  
                 }  
                 return $_REQUEST[$this->_search_valueVar];  
987      }      }
988    
989          /**      /**
990       * This builds a query string var for the       * This builds a query string var for the
991       * searchfield value.       * searchfield value.
992       *       *
993       * @return string - "orderby=(thevalue)"       * @return string - "orderby=(thevalue)"
994       */       */
995      function build_searchvalue_querystring() {      function build_searchvalue_querystring() {
996          $str = $this->_search_valueVar."=".$this->search_value();          $str = $this->_vars["search_valueVar"]."=".urlencode($this->search_value());
997          return $str;          return $str;
998      }      }
999    
# Line 1035  class DataList extends BaseWidget { Line 1004  class DataList extends BaseWidget {
1004       * @return string       * @return string
1005       */       */
1006      function simple_search_modifier_value() {      function simple_search_modifier_value() {
1007                  if (!$_REQUEST[$this->_simple_search_modifierVar]) {          return $this->_get("simple_search_modifierVar", '');
                         $_REQUEST[$this->_simple_search_modifierVar] = '';  
                 }  
                 return $_REQUEST[$this->_simple_search_modifierVar];  
1008      }      }
1009    
1010    
# Line 1048  class DataList extends BaseWidget { Line 1014  class DataList extends BaseWidget {
1014       * @return string       * @return string
1015       */       */
1016      function search_type() {      function search_type() {
1017                  if (!$_REQUEST[$this->_search_typeVar]) {          return $this->_get("search_typeVar", "simple");
                         $_REQUEST[$this->_search_typeVar] = "simple";  
                 }  
                 return $_REQUEST[$this->_search_typeVar];  
1018      }      }
1019    
1020      /**      /**
# Line 1061  class DataList extends BaseWidget { Line 1024  class DataList extends BaseWidget {
1024       *                 "simple" or "advanced"       *                 "simple" or "advanced"
1025       */       */
1026      function set_search_type($type) {      function set_search_type($type) {
1027                  $_REQUEST[$this->_search_typeVar] = $type;          $this->_set("search_typeVar", $type);
1028      }      }
1029    
1030    
# Line 1073  class DataList extends BaseWidget { Line 1036  class DataList extends BaseWidget {
1036       * @return string - the current value       * @return string - the current value
1037       */       */
1038      function showall() {      function showall() {
1039                  if (!$_REQUEST[$this->_showallVar]) {          return(int)$this->_get("showallVar", 0);
1040                          $_REQUEST[$this->_showallVar] = 0;      }
1041                  }  
1042                  return (int) $_REQUEST[$this->_showallVar];      /**
1043         * This is the basic function for letting us
1044         * do a mapping between the column name in
1045         * the header, to the value found in the DB.
1046         *
1047         * NOTE: this function is meant to be overridden
1048         *       so that you can push whatever you want.
1049         *
1050         * @param array - $row_data - the entire data for the row
1051         * @param string - $col_name - the name of the column header
1052         *                             for this row to render.
1053         * @return  mixed - either a HTMLTag object, or raw text.
1054         */
1055        function build_column_item($row_data, $col_name) {
1056            $key = $this->_columns[$col_name]["data_name"];
1057    
1058            if ( $row_data[$key] == '' ) {
1059                return "&nbsp;";
1060            } else {
1061                return $this->_filter_column_string($row_data[$key]);
1062            }
1063      }      }
1064    
1065    
1066        /**
1067         * This does some magic filtering on the data
1068         * that we display in a column.  This helps
1069         * to prevent nast data that may have html
1070         * tags in it.
1071         *
1072         * @param string - the column data u want to filter
1073         * @return string the cleaned/filtered data
1074         */
1075        function _filter_column_string($data) {
1076            return htmlspecialchars(trim($data));
1077        }
1078    
         /*******************************************/  
         /*         FORM VARIABLES SECTION          */  
         /*******************************************/  
1079    
1080          /**      /*******************************************/
1081        /*         FORM VARIABLES SECTION          */
1082        /*******************************************/
1083    
1084        /**
1085       * This function is used to set the       * This function is used to set the
1086       * form name       * form name
1087       *       *
# Line 1124  class DataList extends BaseWidget { Line 1120  class DataList extends BaseWidget {
1120      function get_form_target() {      function get_form_target() {
1121          return $this->_form_attributes["target"];          return $this->_form_attributes["target"];
1122      }      }
1123        
1124      /**      /**
1125       * This function is used to set the       * This function is used to set the
1126       * form method       * form method
# Line 1132  class DataList extends BaseWidget { Line 1128  class DataList extends BaseWidget {
1128       * @param string (POST or GET)       * @param string (POST or GET)
1129       */       */
1130      function set_form_method($method) {      function set_form_method($method) {
1131                  if ($method != "GET" && $method != "POST") {          if ( $method != "GET" && $method != "POST" ) {
1132                          user_error("DataList::set_form_method() - INVALID Form method ".$method);              user_error("DataList::set_form_method() - INVALID Form method ".$method);
1133                  } else {          } else {
1134                          $this->_form_attributes["method"] = $method;              $this->_form_attributes["method"] = $method;
1135                  }          }
1136      }      }
1137    
1138      /**      /**
# Line 1149  class DataList extends BaseWidget { Line 1145  class DataList extends BaseWidget {
1145          return $this->_form_attributes["method"];          return $this->_form_attributes["method"];
1146      }      }
1147    
1148     /**      /**
1149      * Sets the form action       * Sets the form action
1150      *       *
1151      * @param string       * @param string
1152      */       */
1153      function set_form_action($action) {      function set_form_action($action) {
1154          $this->_form_attributes["action"] = $action;          $this->_form_attributes["action"] = $action;
1155      }      }
1156    
1157          /**      /**
1158       * This function is used to get       * This function is used to get
1159       * the form action       * the form action
1160       *       *
# Line 1187  class DataList extends BaseWidget { Line 1183  class DataList extends BaseWidget {
1183      }      }
1184    
1185      /**      /**
1186           * This function is used to set the       * This function is used to set the
1187           * message displayed when no data is found       * message displayed when no data is found
1188           *       *
1189           * @param string       * @param string
1190           */       */
1191      function set_not_found_message($mesg) {      function set_not_found_message($mesg) {
1192                  $this->_check_datasource("set_not_found_message");          $this->_check_datasource("set_not_found_message");
1193          $this->_datasource->set_not_found_message($mesg);          $this->_datasource->set_not_found_message($mesg);
1194      }      }
1195    
1196    
1197          /**      /**
1198           * This function is used to set the value       * This function is used to set the value
1199           * of the _show_results_flag       * of the _show_results_flag
1200           *       *
1201           * @param boolean - TRUE to show the results       * @param boolean - TRUE to show the results
1202           */       */
1203          function set_show_results( $flag=TRUE ) {      function set_show_results( $flag=TRUE ) {
1204                  $this->_show_results_flag = $flag;          $this->_show_results_flag = $flag;
1205          }      }
1206            
   
         /**  
          * This function is used to let render() know  
          * that we should show the results or not.  
          *  
          * @return boolean  
          */  
         function _show_results() {  
                 return $this->_show_results_flag;  
         }  
1207    
1208          /**      /**
1209         * This function is used to let render() know
1210         * that we should show the results or not.
1211         *
1212         * @return boolean
1213         */
1214        function _show_results() {
1215            return $this->_show_results_flag;
1216        }
1217    
1218        /**
1219       * this method builds some hidden       * this method builds some hidden
1220       * form fields to automatically       * form fields to automatically
1221       * be placed inside the form.       * be placed inside the form.
1222         *
1223         * This method returns a list of
1224         * hidden form fields if we are a POST.
1225         * It returns a portion of a query string
1226         * If we are a GET.
1227       *       *
1228       * @return ContainerWidget object.       * @return mixed depending on form method
1229       */       */
1230      function _build_save_vars() {      function _build_save_vars() {
1231          $container = container();          $container = container();
# Line 1234  class DataList extends BaseWidget { Line 1235  class DataList extends BaseWidget {
1235          return $container;          return $container;
1236      }      }
1237    
1238          /**      /**
1239       * This function sets the save variables       * This function sets the save variables
1240       * that the user/child wants to automatically       * that the user/child wants to automatically
1241       * propogate       * propogate
# Line 1247  class DataList extends BaseWidget { Line 1248  class DataList extends BaseWidget {
1248      }      }
1249    
1250      /**      /**
1251         * This function builds the list of
1252         * default hidden form vars for when
1253         * the datalist is being rendered
1254         * as a POST
1255         *
1256         * @return Container
1257         */
1258        function _build_default_vars() {
1259            // the navigation links will set the offset anyway
1260            $container = container(form_hidden($this->_vars["offsetVar"], $this->offset()),
1261                                   form_hidden($this->_vars["orderbyVar"], $this->orderby()),
1262                                   form_hidden($this->_vars["reverseorderVar"], $this->reverseorder()),
1263                                   form_hidden($this->_vars["showallVar"], $this->showall()));
1264            return $container;
1265        }
1266    
1267        
1268    
1269        /**
1270       * This builds the base url used       * This builds the base url used
1271       * by the column headers as well       * by the column headers as well
1272       * as the page tool links.       * as the page tool links.
# Line 1260  class DataList extends BaseWidget { Line 1280  class DataList extends BaseWidget {
1280    
1281          $url = $_SERVER["PHP_SELF"]."?";          $url = $_SERVER["PHP_SELF"]."?";
1282    
1283          if ($this->get_form_method() == "POST") {          if ( $this->get_form_method() == "POST" ) {
1284              return $url;              return $url;
1285          }          }
1286    
1287                  $vars = array_merge($_POST, $_GET);          $vars = array_merge($_POST, $_GET);
1288          //request method independant access to          //request method independant access to
1289          //browser variables          //browser variables
1290          if (count($vars)) {          if ( count($vars) ) {
1291              //walk through all of the get vars              //walk through all of the get vars
1292              //and add them to the url to save them.              //and add them to the url to save them.
1293              foreach($vars as $name => $value) {              foreach($vars as $name => $value) {
1294    
1295                  if ($name != $this->_offsetVar &&                  if ( $name != $this->_vars["offsetVar"] &&
1296                      $name != $this->_orderbyVar &&                       $name != $this->_vars["orderbyVar"] &&
1297                      $name != $this->_reverseorderVar &&                       $name != $this->_vars["reverseorderVar"] &&
1298                      $name != $this->_search_valueVar                       $name != $this->_vars["search_valueVar"]
1299                     ) {                     ) {
1300                      if (is_array($value)) {                      if ( is_array($value) ) {
1301                          $url .= $name."[]=".implode("&".$name."[]=",$value)."&";                          $url .= $name."[]=".implode("&".$name."[]=",$value)."&";
1302                      } else {                      } else {
1303                                                  $url .= $name."=".urlencode(stripslashes($value))."&";                          $url .= $name."=".urlencode(stripslashes($value))."&";
1304                                          }                      }
1305                  }                  }
1306              }              }
1307          }          }
1308    
1309          return $url;          return htmlentities($url);
1310      }      }
1311    
1312          /**      /**
1313           * This function builds the 'tool' images that       * This function builds the 'tool' images that
1314           * allow  you to walk through the data list itself.       * allow  you to walk through the data list itself.
1315           * It provides image links for       * It provides image links for
1316           * first - go to the first page in the data list       * first - go to the first page in the data list
1317           * prev - go to the previous page in the data list       * prev - go to the previous page in the data list
1318           * next - go to the next page in the data list       * next - go to the next page in the data list
1319           * last - go to the last page in the data list       * last - go to the last page in the data list
1320           * all - show the rest of the list from the current offset       * all - show the rest of the list from the current offset
1321           *       *
1322           * @param string - which tool image to build       * @param string - which tool image to build
1323           * @return Object       * @return Object
1324           */       */
1325          function build_tool_link( $which ) {      function build_tool_link( $which ) {
1326                  $num_pages = $this->get_num_pages();          $num_pages = $this->get_num_pages();
1327          $cur_page = $this->get_current_page();          $cur_page = $this->get_current_page();
1328          $last_page = $this->get_last_page();          $last_page = $this->get_last_page();
1329    
1330                  $image_path = $this->get_image_path();          $image_path = $this->get_image_path();
1331                  switch ($which) {          switch ( $which ) {
1332                            
1333                  case "first":          case "first":
1334                          $rows_string = "First ".$this->get_default_num_rows()." Rows";              $rows_string = "First ".$this->get_default_num_rows()." Rows";
1335                          if ($this->offset() <= 0) {              if ( $this->offset() <= 0 ) {
1336                                  $obj = html_img($image_path."/first_group_button_inactive.gif",                  $obj = html_img($image_path."/first_group_button_inactive.gif",
1337                                                                  '','',0,$rows_string, NULL, $rows_string);                                  '','',0,$rows_string, NULL, $rows_string);
1338                          } else {              } else {
1339                  $url = $this->_build_tool_url(0);                  $url = $this->_build_tool_url(0);
1340                                  $obj = html_img_href($url, $image_path."/first_group_button.gif",                  $obj = html_img_href($url, $image_path."/first_group_button.gif",
1341                                                                           '','',0, $rows_string, NULL, NULL, $rows_string);                                       '','',0, $rows_string, NULL, NULL, $rows_string);
1342                }
1343                break;
1344    
1345            case "prev":
1346                $rows_string = "Previous ".$this->get_default_num_rows()." Rows";
1347                if ( $this->offset() <= 0 ) {
1348                    $obj = html_img($image_path."/prev_group_button_inactive.gif",
1349                                    '','',0,$rows_string, NULL, $rows_string);
1350                } else {
1351                    $offset = $this->offset() - $this->numrows();
1352                    if ( $offset < 0 ) {
1353                        $offset = 0;
1354                    }
1355                    $url = $this->_build_tool_url($offset);
1356                    $obj = html_img_href($url, $image_path."/prev_group_button.gif",
1357                                         '','',0, $rows_string, NULL, NULL, $rows_string);
1358              }              }
1359                          break;              break;
1360    
1361                  case "prev":          case "next":
1362                          $rows_string = "Previous ".$this->get_default_num_rows()." Rows";              $rows_string = "Next ".$this->get_default_num_rows()." Rows";
1363                          if ($this->offset() <= 0) {              if ( ($num_pages == 1) || ($cur_page == $last_page) ) {
1364                                  $obj = html_img($image_path."/prev_group_button_inactive.gif",                  $obj = html_img($image_path."/next_group_button_inactive.gif",
1365                                                                  '','',0,$rows_string, NULL, $rows_string);                                  '','',0, $rows_string, NULL, $rows_string);
1366                          } else {              } else {
1367                                  $offset = $this->offset() - $this->numrows();                  $offset = $this->offset() + $this->numrows();
1368                                  if ($offset < 0) {                  $url = $this->_build_tool_url($offset);
1369                                          $offset = 0;                  $obj = html_img_href($url, $image_path."/next_group_button.gif",
1370                                  }                                       '','',0, $rows_string, NULL, NULL, $rows_string);
1371                                  $url = $this->_build_tool_url($offset);              }
1372                                  $obj = html_img_href($url, $image_path."/prev_group_button.gif",              break;
1373                                                                           '','',0, $rows_string, NULL, NULL, $rows_string);  
1374                          }          case "last":
1375                          break;              $rows_string = "Last ".$this->get_default_num_rows()." Rows";
1376                if ( ($num_pages == 1) || ($cur_page == $last_page) ) {
1377                  case "next":                  $obj = html_img($image_path."/last_group_button_inactive.gif",
1378                          $rows_string = "Next ".$this->get_default_num_rows()." Rows";                                  '','',0, $rows_string, NULL, $rows_string);
1379                          if (($num_pages == 1) || ($cur_page == $last_page)) {              } else {
1380                                  $obj = html_img($image_path."/next_group_button_inactive.gif",                  $offset = (int)(($num_pages - 1) * $this->numrows());
1381                                                                  '','',0, $rows_string, NULL, $rows_string);                  $url = $this->_build_tool_url($offset);
1382                          } else {                  $obj = html_img_href($url, $image_path."/last_group_button.gif",
1383                                  $offset = $this->offset() + $this->numrows();                                       '','',0, $rows_string, NULL, NULL, $rows_string);
1384                                  $url = $this->_build_tool_url($offset);              }
1385                                  $obj = html_img_href($url, $image_path."/next_group_button.gif",              break;
1386                                                                           '','',0, $rows_string, NULL, NULL, $rows_string);  
1387                          }          case "all":
1388                          break;              $offset = $this->offset();
1389                if ( $this->showall() ) {
1390                  case "last":                  $url = $this->_build_tool_url($offset, TRUE, 0);
1391                          $rows_string = "Last ".$this->get_default_num_rows()." Rows";                  $obj = html_img_href($url, $image_path."/close_group_button.gif",
1392                          if (($num_pages == 1) || ($cur_page == $last_page)) {                                       '','',0,"Collapse Rows", NULL, NULL, "Collapse Rows");
1393                                  $obj = html_img($image_path."/last_group_button_inactive.gif",              } else {
1394                                                                  '','',0, $rows_string, NULL, $rows_string);                  if ( ($num_pages == 1) ) {
1395                          } else {                      $obj = html_img($image_path."/expand_group_button_inactive.gif",
1396                                  $offset = (int)(($num_pages - 1) * $this->numrows());                                      '','',0, "Expand Rows", NULL, "Expand Rows");
1397                                  $url = $this->_build_tool_url($offset);                  } else {
1398                                  $obj = html_img_href($url, $image_path."/last_group_button.gif",                      $url = $this->_build_tool_url($offset, TRUE, 1);
1399                                                                           '','',0, $rows_string, NULL, NULL, $rows_string);                      $obj = html_img_href($url, $image_path."/expand_group_button.gif",
1400                          }                                           '','',0,"Expand Rows", NULL, NULL, "Expand Rows");
1401                          break;                  }
1402                }
1403                  case "all":              //so we don't save it into the mozilla navigation bar links
1404                          $offset = $this->offset();              unset($url);
1405                          if ($this->showall()) {              break;
1406                                  $url = $this->_build_tool_url($offset, TRUE, 0);          }
1407                                  $obj = html_img_href($url, $image_path."/close_group_button.gif",  
1408                                                                           '','',0,"Collapse Rows", NULL, NULL, "Collapse Rows");          if ( $url ) {
1409                          } else {              $this->_save_mozilla_nav_link($which, $url);
1410                                  if (($num_pages == 1)) {          }
1411                                          $obj = html_img($image_path."/expand_group_button_inactive.gif",  
1412                                                                          '','',0, "Expand Rows", NULL, "Expand Rows");          return $obj;
1413                                  } else {      }
1414                                          $url = $this->_build_tool_url($offset, TRUE, 1);  
1415                                          $obj = html_img_href($url, $image_path."/expand_group_button.gif",      /**
1416                                                                                   '','',0,"Expand Rows", NULL, NULL, "Expand Rows");       * This function is used to build the url
1417                                  }       * for a tool link.  
1418                          }       * (first, prev, next, last, all)
1419                          //so we don't save it into the mozilla navigation bar links       *
1420                          unset($url);       * @param int - the offset for the link
1421                          break;       * @param boolean - add the showall value to the url
1422                  }       * @param int - the showall value to use if the flag is on
1423         *
1424                  if ($url) {       * @return string
1425                          $this->_save_mozilla_nav_link($which, $url);       */
1426                  }      function _build_tool_url($offset, $showall_flag=FALSE, $showall_value=0) {
1427                            if ( $this->get_form_method() == "POST" ) {
1428                  return $obj;              $form_name = $this->get_form_name();
1429          }              $url = "javascript: document.".$form_name;
1430                $url .= ".".$this->_vars["offsetVar"].".value='".$offset."';";
1431          /**  
1432           * This function is used to build the url              //add the showall variable to the post
1433           * for a tool link.                if ( $showall_flag ) {
1434           * (first, prev, next, last, all)                  $form_field = $this->_vars["showallVar"];
          *  
          * @param int - the offset for the link  
          * @param boolean - add the showall value to the url  
          * @param int - the showall value to use if the flag is on  
          *  
          * @return string  
          */  
         function _build_tool_url($offset, $showall_flag=FALSE, $showall_value=0) {  
                 if ($this->get_form_method() == "POST") {  
                         $form_name = $this->get_form_name();  
                         $url = "javascript: document.".$form_name;  
                         $url .= ".".$this->_offsetVar.".value='".$offset."';";  
   
                         //add the showall variable to the post  
                         if ($showall_flag) {  
                                 $form_field = $this->_showallVar;  
1435                  $url .= "document.".$form_name.".";                  $url .= "document.".$form_name.".";
1436                                  $url .= $form_field.".value='".$showall_value."';";                  $url .= $form_field.".value='".$showall_value."';";
1437                          }              }
1438    
1439                          $url .= "document.".$form_name.".submit();";              $url .= "document.".$form_name.".submit();";
1440                  } else {          } else {
1441                          $url = $this->build_base_url();              $url = $this->build_base_url();
1442                          $url .= $this->build_state_vars_query_string($offset, $showall_flag,              $url .= $this->build_state_vars_query_string($offset, $showall_flag,
1443                                                                                                                   $showall_value);                                                           $showall_value);
1444                  }          }
1445                  return $url;          return $url;
1446          }      }
1447    
1448      /**      /**
1449       * this function is used to build a sub query string       * this function is used to build a sub query string
# Line 1434  class DataList extends BaseWidget { Line 1454  class DataList extends BaseWidget {
1454       * @return string - name=value& pairs       * @return string - name=value& pairs
1455       */       */
1456      function build_state_vars_query_string($offset, $showall_flag=FALSE,      function build_state_vars_query_string($offset, $showall_flag=FALSE,
1457                                                                                     $showall_value=0) {                                             $showall_value=0) {
1458          $str = "";          $str = "";
1459    
1460          $str .= $this->_offsetVar."=".urlencode($offset);          $str .= $this->_vars["offsetVar"]."=".urlencode($offset);
1461          $str .= "&".$this->_orderbyVar."=".urlencode($this->orderby());          $str .= "&".$this->_vars["orderbyVar"]."=".urlencode($this->orderby());
1462          $str .= "&".$this->_reverseorderVar."=".urlencode($this->reverseorder());          $str .= "&".$this->_vars["reverseorderVar"]."=".urlencode($this->reverseorder());
1463          $str .= "&".$this->_search_fieldVar."=".urlencode($this->search_field());          $str .= "&".$this->_vars["search_fieldVar"]."=".urlencode($this->search_field());
1464          $str .= "&".$this->_search_valueVar."=".urlencode($this->search_value());          $str .= "&".$this->_vars["search_valueVar"]."=".urlencode($this->search_value());
1465          $str .= "&".$this->_simple_search_modifierVar."=".urlencode($this->simple_search_modifier_value());          $str .= "&".$this->_vars["simple_search_modifierVar"]."=".urlencode($this->simple_search_modifier_value());
1466          $str .= "&".$this->_search_typeVar."=".urlencode($this->search_type());          $str .= "&".$this->_vars["search_typeVar"]."=".urlencode($this->search_type());
1467                  if ($showall_flag) {          if ( $showall_flag ) {
1468                          $str .= "&".$this->_showallVar."=".urlencode($showall_value);              $str .= "&".$this->_vars["showallVar"]."=".urlencode($showall_value);
1469                  }          }
1470    
1471          return $str;          return htmlentities($str);
1472        }
1473    
1474        /**
1475         * This function stores the url for each of the tool
1476         * urls, so we can push these out for mozilla.
1477         * Mozilla has a nice navigation bar feature that
1478         * lets you program first, prev, next, last links
1479         *
1480         * @param string - which tool link
1481         * @param string - the url for that link
1482         */
1483        function _save_mozilla_nav_link($which, $url) {
1484            $this->_mozilla_nav_links[$which] = $url;
1485        }
1486    
1487    
1488        /**
1489         * This function returns the path to the
1490         * images used in this class
1491         *
1492         * @return string
1493         */
1494        function get_image_path() {
1495            return $this->_image_path;
1496      }      }
1497    
1498          /**      /**
1499           * This function stores the url for each of the tool       * This function returns the path to the
1500           * urls, so we can push these out for mozilla.       * images used in this class
1501           * Mozilla has a nice navigation bar feature that       *
1502           * lets you program first, prev, next, last links       * @return string
1503           *       */
1504           * @param string - which tool link      function set_image_path($path) {
1505           * @param string - the url for that link          return $this->_image_path = $path;
1506           */      }
         function _save_mozilla_nav_link($which, $url) {  
                 $this->_mozilla_nav_links[$which] = $url;  
         }  
   
   
         /**  
          * This function returns the path to the  
          * images used in this class  
          *  
          * @return string  
          */  
         function get_image_path() {  
                 return $this->_image_path;  
         }  
   
         /**  
          * This function returns the path to the  
          * images used in this class  
          *  
          * @return string  
          */  
         function set_image_path($path) {  
                 return $this->_image_path = $path;  
         }  
1507    
1508      /**      /**
1509       * This function returns the current       * This function returns the current
# Line 1503  class DataList extends BaseWidget { Line 1523  class DataList extends BaseWidget {
1523       * @return int       * @return int
1524       */       */
1525      function get_num_pages() {      function get_num_pages() {
1526                  $this->_check_datasource("get_num_pages");          $this->_check_datasource("get_num_pages");
1527                  $total_rows = $this->_datasource->get_total_rows();          $total_rows = $this->_datasource->get_total_rows();
1528    
1529          $cnt = (int)($total_rows / $this->numrows());          $cnt = (int)($total_rows / $this->numrows());
1530          if ((($total_rows % $this->numrows()) != 0) || ($total_rows == 0)) {          if ( (($total_rows % $this->numrows()) != 0) || ($total_rows == 0) ) {
1531              $cnt++;              $cnt++;
1532          }          }
1533          return $cnt;          return $cnt;
# Line 1536  class DataList extends BaseWidget { Line 1556  class DataList extends BaseWidget {
1556          $num_pages = $this->get_num_pages();          $num_pages = $this->get_num_pages();
1557          $num_rows_per_page = $this->numrows();          $num_rows_per_page = $this->numrows();
1558    
1559                  $this->_check_datasource("get_page_info");          $this->_check_datasource("get_page_info");
1560                  $total_rows = $this->_datasource->get_total_rows();          $total_rows = $this->_datasource->get_total_rows();
1561    
1562          $high_range = $low_range + ($num_rows_per_page - 1);          $high_range = $low_range + ($num_rows_per_page - 1);
1563          if ($high_range > $total_rows) {          if ( $high_range > $total_rows ) {
1564              $high_range = $total_rows;              $high_range = $total_rows;
1565          }          }
1566    
1567          if ($total_rows == 0) {          if ( $total_rows == 0 ) {
1568              $str = "0 of 0";              $str = "0 of 0";
1569          } else {          } else {
1570              $str  = $low_range . " to ". $high_range;              $str  = $low_range . " to ". $high_range;
# Line 1570  class DataList extends BaseWidget { Line 1590  class DataList extends BaseWidget {
1590    
1591          $order_value = $this->_columns[$col_name]["data_name"];          $order_value = $this->_columns[$col_name]["data_name"];
1592          $reverse_value = "false";          $reverse_value = "false";
1593          if (!$reverseorder) {          if ( !$reverseorder ) {
1594              $reverseorder = 'false';              $reverseorder = 'false';
1595          }          }
1596    
1597          if ($orderby == $order_value && $reverseorder === 'false') {          if ( $orderby == $order_value && $reverseorder === 'false' ) {
1598              $reverse_value = "true";              $reverse_value = "true";
1599          }          }
1600    
1601          if ($this->form_method == "POST") {          if ( $this->get_form_method() == "POST" ) {
1602              //we have to construct this url              //we have to construct this url
1603              //specially.              //specially.
1604              $form_name = $this->get_form_name();              $form_name = $this->get_form_name();
1605    
1606              $url = "javascript: ";              $url = "javascript: ";
1607              //set the offset correctly              //set the offset correctly
1608              $url .= "document.".$form_name.".".$this->_offsetVar.".value='".$this->offset()."';";              $url .= "document.".$form_name.".".$this->_vars["offsetVar"].".value='".$this->offset()."';";
1609              //set the orderby correctly.              //set the orderby correctly.
1610              $url .= "document.".$form_name.".".$this->_orderbyVar.".value='".$order_value."';";              $url .= "document.".$form_name.".".$this->_vars["orderbyVar"].".value='".$order_value."';";
1611              //set the reverseorder              //set the reverseorder
1612              $url .= "document.".$form_name.".".$this->_reverseorderVar.".value='".$reverse_value."';";              $url .= "document.".$form_name.".".$this->_vars["reverseorderVar"].".value='".$reverse_value."';";
1613    
1614              $url .= "document.".$form_name.".submit();";              $url .= "document.".$form_name.".submit();";
1615          } else {          } else {
1616              //handle the normal get.              //handle the normal get.
1617              $url = $this->build_base_url();              $url = $this->build_base_url();
1618              //Now add the orderby, reverseorder and offset vars              //Now add the orderby, reverseorder and offset vars
1619              $url .= $this->_offsetVar ."=0&";              $url .= $this->_vars["offsetVar"] ."=0&";
1620              //set the orderbyvar              //set the orderbyvar
1621              $url .= $this->_orderbyVar ."=".$order_value."&";              $url .= $this->_vars["orderbyVar"] ."=".$order_value."&";
1622              //set the reverseorder              //set the reverseorder
1623              $url .= $this->_reverseorderVar ."=".$reverse_value."&";              $url .= $this->_vars["reverseorderVar"] ."=".$reverse_value."&";
1624              //set the search value              //set the search value
1625              $url .= $this->_search_valueVar ."=".$search_value;              $url .= $this->_vars["search_valueVar"] ."=".$search_value;
1626          }          }
1627    
1628          return $url;          return $url;
1629      }      }
1630    
1631      /**      /**
      * This is the basic function for letting us  
      * do a mapping between the column name in  
      * the header, to the value found in the DB.  
      *  
      * NOTE: this function is meant to be overridden  
      *       so that you can push whatever you want.  
      *  
      * @param array - $row_data - the entire data for the row  
      * @param string - $col_name - the name of the column header  
      *                             for this row to render.  
      * @return  mixed - either a HTMLTag object, or raw text.  
      */  
     function build_column_item($row_data, $col_name) {  
         $key = $this->_columns[$col_name]["data_name"];  
   
         if ($row_data[$key] == '') {  
             return "&nbsp;";  
         } else {  
             return $this->filter_column_string($row_data[$key]);  
         }  
     }  
   
   
     /**  
1632       * This does some magic filtering on the data       * This does some magic filtering on the data
1633       * that we display in a column.  This helps       * that we display in a column.  This helps
1634       * to prevent nast data that may have html       * to prevent nast data that may have html
# Line 1642  class DataList extends BaseWidget { Line 1638  class DataList extends BaseWidget {
1638       * @return string the cleaned/filtered data       * @return string the cleaned/filtered data
1639       */       */
1640      function filter_column_string($data) {      function filter_column_string($data) {
1641          // WAS: return htmlspecialchars(trim($data));          return htmlspecialchars(trim($data));
1642                }
1643          // NEW: require 'flib/Application/i18n/TextEncode.php'  
1644          //  this will do a 'htmlentities' RECURSIVE on each item  
1645          $encoder = new Data_Encode($data);  
1646          $encoder->toHTML();      /**
1647          return $data;       * This function is used to make sure that the string we are
1648      }       * placing in a cell has been "cleaned"
1649                 *
1650         * @param mixed - the cell object.  It can be a string.
1651         * @param string - the name of the column this object/string
1652          /**       *                 will live
1653           * This function is used to make sure that the string we are       *
1654           * placing in a cell has been "cleaned"       * @return mixed - the cleaned string or object
1655           *       */
1656           * @param mixed - the cell object.  It can be a string.      function _clean_string($obj, $col_name) {
1657           * @param string - the name of the column this object/string          if ( is_string($obj) ) {
1658           *                 will live              if ( $this->_columns[$col_name]["maxtextlength"] ) {
1659           *                  //looks like we need to make sure we
1660           * @return mixed - the cleaned string or object                  //truncate the string to a max length
1661           */                  if ( strlen($obj) > $this->_columns[$col_name]["maxtextlength"] ) {
1662          function _clean_string($obj, $col_name){                      //we need to truncate it.
1663                  if (is_string($obj)) {                      $obj = substr($obj, 0, $this->_columns[$col_name]["maxtextlength"]);
1664                          if ($this->_columns[$col_name]["maxtextlength"]) {                      $obj .= "...";
1665                                  //looks like we need to make sure we                  }
1666                                  //truncate the string to a max length              }
1667                                  if (strlen($obj) > $this->_columns[$col_name]["maxtextlength"]) {          }
1668                                          //we need to truncate it.          return $obj;
1669                                          $obj = substr($obj, 0, $this->_columns[$col_name]["maxtextlength"]);      }
1670                                          $obj .= "...";  
1671                                  }      /********************************/
1672                          }      /*      SEARCH RELATED          */
1673                  }      /********************************/
                 return $obj;  
         }  
   
         /********************************/  
         /*      SEARCH RELATED          */  
         /********************************/  
1674    
1675      /**      /**
1676       * This method gets the array of       * This method gets the array of
# Line 1691  class DataList extends BaseWidget { Line 1681  class DataList extends BaseWidget {
1681      function _get_searchable_fields() {      function _get_searchable_fields() {
1682          $fields = array();          $fields = array();
1683          foreach($this->_columns as $name => $header) {          foreach($this->_columns as $name => $header) {
1684              if ($header["searchable"] == TRUE) {              if ( $header["searchable"] == TRUE ) {
1685                  $fields[$name] = $header["data_name"];                  $fields[$name] = $header["data_name"];
1686              }              }
1687          }          }
# Line 1710  class DataList extends BaseWidget { Line 1700  class DataList extends BaseWidget {
1700    
1701          $modifier = $this->get_simple_search_modifier();          $modifier = $this->get_simple_search_modifier();
1702    
1703          if ($modifier & SEARCH_BEGINS_WITH) {          if ( $modifier & SEARCH_BEGINS_WITH ) {
1704              $options["beginning with"] = "BEGINS";              $options["beginning with"] = "BEGINS";
1705          }          }
1706          if ($modifier & SEARCH_CONTAINS) {          if ( $modifier & SEARCH_CONTAINS ) {
1707              $options["containing"] = "CONTAINS";              $options["containing"] = "CONTAINS";
1708          }          }
1709          if ($modifier & SEARCH_EXACT) {          if ( $modifier & SEARCH_EXACT ) {
1710              $options["matching"] = "EXACT";              $options["matching"] = "EXACT";
1711          }          }
1712          if ($modifier & SEARCH_ENDS_WITH) {          if ( $modifier & SEARCH_ENDS_WITH ) {
1713              $options["ending with"] = "ENDS";              $options["ending with"] = "ENDS";
1714          }          }
1715    
1716          $selected = $this->simple_search_modifier_value();          $selected = $this->simple_search_modifier_value();
1717          //make the default Begins with          //make the default Begins with
1718          if (!$selected) {          if ( !$selected ) {
1719              $selected = "BEGINS";              $selected = "BEGINS";
1720          }          }
1721    
1722          return form_select($this->_simple_search_modifierVar, $options, $selected);          return form_select($this->_vars["simple_search_modifierVar"], $options, $selected);
1723      }      }
1724    
1725          /**      /**
1726       * This function is used to make safe       * This function is used to make safe
1727       * any query string value that is used       * any query string value that is used
1728       *       *

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

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