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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (hide annotations)
Sat Feb 22 21:08:35 2003 UTC (21 years, 6 months ago) by jonen
Branch: MAIN
Changes since 1.4: +769 -779 lines
+ updated whole lib to version 2.2.1 (new FormProcessing since 2.2.0!)

1 jonen 1.1 <?php
2     /**
3     * This is the base class for managing a list
4     * of data points.
5     *
6     * @author Walter A. Boring IV <waboring@buildabetterweb.com>
7     * @package phpHtmlLib
8     */
9    
10 jonen 1.5 /**
11     * Some global defines used
12     */
13 jonen 1.1 define("SORTABLE", TRUE);
14     define("NOT_SORTABLE", FALSE);
15     define("SEARCHABLE", TRUE);
16     define("NOT_SEARCHABLE", FALSE);
17    
18     //Some defines for setting up the search
19     //modifier fields.
20     define("SEARCH_BEGINS_WITH", 1);
21     define("SEARCH_CONTAINS", 2);
22     define("SEARCH_EXACT", 4);
23     define("SEARCH_ENDS_WITH", 8);
24     define("SEARCH_ALL", 15);
25    
26    
27     /**
28     * This object is the base class that can be
29     * used to build a widget that shows lists of
30     * data from any source via the DataListSource
31     * object. It fetches/builds/gets its data
32     * from the DataListSource object, which can
33     * be written to support any data source
34     * (MySQL, Oracle, comma delimited file, xml, etc.)
35     *
36     * This base class MUST be extended by a child to
37     * actually render the list. The job of the DataList
38     * class is to provide the basic API and abstraction
39     * mechanism to handling searching, showing, sorting
40     * lists of data.
41     *
42     * Each column of data is associated with a title and a
43     * name. The title is what is shown to the user for that
44     * column. The name is the mapping between the column and
45     * the DataListSource. Each column can be marked
46     * as sortable and searchable. If a column is sortable,
47     * the title is a link that can be clicked on to sort.
48     * The sorting is done in the DataListSource object (
49     * via the sql query, or sort() functions depending on the
50     * data source itself)
51     *
52     * The DataList object will build the title, the search block
53     * (if any), the datalist controls (the links/imges for
54     * first, prev, next, last, all). Then the data columns/labels.
55     * Then it will fetch each of the rows of data to display
56     * from the DataListSource.
57     *
58     * The logic of the output calls follows in the order:
59     *
60     * title
61     * search table/block
62     * datalist controls (first, prev, next, last, all)
63     * data columns/labels
64     * data rows x through y
65     *
66     *
67     * REQUIREMENTS:
68     * You must use/define a DataListSource object.
69     * You MUST override/extend the following methods:
70     *
71     * * get_data_source() - used to set the DataListSource
72     * by this class.
73     * * user_setup() - used to set the columns to show and any
74     * options used by the DataList class and
75     * DataListSource object.
76     *
77     *
78     * UI ABSTRACTION METHODS
79     * These methods allow for some level of abstraction for
80     * the layout/look/feel of the actual list of data.
81     *
82     *
83     * * gui_init() - the function gives the child class a chance
84     * to do any building of the objects that will
85     * hold the search area, column headers and the
86     * rows of data.
87     *
88     * * child_build_column_header() - This method is responsible
89     * for building and inserting
90     * the column header title into
91     * the UI object.
92     *
93     * * child_add_row_cell() - This function is responsible for adding
94     * the cell in the current row. The method
95     * is responsible for keeping track of the
96     * location in its UI object for the current
97     * row.
98     *
99     * * child_get_gui() - This method returns the entire UI in 1 object
100     * or container. At this point the entire UI
101     * has been constructed, the entire list of data
102     * has been walked and inserted.
103     *
104     *
105     * @author Walter A. Boring IV <waboring@buildabetterweb.com>
106     * @package phpHtmlLib
107     */
108     class DataList extends BaseWidget {
109    
110     /**
111     * This value holds the number
112     * of pages of data we have
113     * to display.
114     *
115     */
116     var $_num_pages=1;
117    
118     /**
119     * The number of rows of data
120     * to show per "page".
121     * The default is 20.
122     *
123     */
124     var $_default_rows_per_page = 10;
125    
126     /**
127     * The max number of rows to
128     * show when the user does the
129     * "EXPAND" command.
130     */
131     var $_max_rows = 200;
132    
133    
134     /**
135     * Do we want to alternate the row colors?
136     * This helps to see each row easier.
137     */
138     var $alternating_row_colors = TRUE;
139    
140     /**
141     * prefix for all list variable
142     * names, so we can potentially
143     * have more then 1 list per page.
144     */
145     var $_global_prefix = '';
146    
147    
148     /**
149 jonen 1.5 * Holds an array of all the
150     * form vars we need for this
151     * 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 jonen 1.1
163     /**
164     * Holds the db column name that
165     * we want to order by default.
166     */
167     var $_default_orderby = '';
168    
169     /**
170     * Holds a flag to let us know to
171     * reverse order the column by default
172     */
173     var $_default_reverseorder = "false";
174    
175     /**
176     * Flag to let us know that search
177     * is enabled.
178     *
179     */
180     var $_search_flag = FALSE;
181    
182     /**
183     * Flag to let us know that
184     * advanced search is enabled
185     *
186     */
187     var $_advanced_search_flag = FALSE;
188    
189     /**
190     * Flag to enable simple search modifyer.
191     * IF enabled it will add a select that adds
192     * the "beings with", "contains" options for
193     * a simple search.
194     */
195     var $_simple_search_modifier = FALSE;
196    
197    
198 jonen 1.5 /**
199     * Holds the object block that is the
200     * search UI
201     */
202     var $_search_table = NULL;
203 jonen 1.1
204     /**
205     * This holds a list of
206     * name=>value vars that the
207     * caller/child wants to propogate
208     * automatically.
209     *
210     */
211     var $_save_vars = array();
212    
213    
214 jonen 1.5 /**
215     * The column descriptions
216     * for the data we are working on
217     *
218     * @var array
219     */
220     var $_columns = array();
221 jonen 1.1
222 jonen 1.5 /**
223 jonen 1.1 * Keeps track of the # of columns we have
224     */
225     var $_num_columns = 0;
226    
227    
228 jonen 1.5 /**
229     * This holds the form attributes
230     *
231     */
232     var $_form_attributes = array("method" => "GET",
233     "target" => "",
234     "action" => "",
235     "name" => "");
236    
237     /**
238     * Build everything inside a form?
239     *
240     */
241     var $_form_render_flag = FALSE;
242    
243    
244     /**
245     * flag to let us know if we want to show
246     * the results or not.
247     */
248     var $_show_results_flag = TRUE;
249    
250    
251     /**
252     * Holds our reference/copy of the
253     * DataListSource object which is used to
254     * access the data that this object uses
255     *
256     * @var DataListSource object
257     */
258     var $_datasource = NULL;
259    
260     /**
261     * This stores the base path to where the
262     * tool link images live. This lets you
263     * specify a new path to where your images
264     * live.
265     */
266     var $_image_path = "/phphtmllib/images/widgets";
267    
268    
269     /**
270     * The constructor
271     *
272     * @param string - the title of the data list
273     * @param string - the overall width
274     * @param string - the column to use as the default sorting order
275     * @param boolean - sort the default column in reverse order?
276     */
277     function DataList($title, $width = "100%", $default_orderby='',
278     $default_reverseorder=FALSE) {
279     $this->set_title( $title );
280     $this->set_form_name( str_replace(' ', '_', strtolower($title)) );
281     $this->set_width( $width );
282    
283 jonen 1.1
284     $this->_default_orderby = $default_orderby;
285 jonen 1.5 if ( $default_reverseorder === TRUE ) {
286     $default_reverseorder = "true";
287     }if ( $default_reverse_order === FALSE ) {
288     $default_reverseorder = "false";
289     }
290 jonen 1.1 $this->_default_reverseorder = $default_reverseorder;
291    
292 jonen 1.5
293 jonen 1.1 //Set the global prefix for our variables.
294     //want to make sure we can have multiple
295     //item lists per html page.
296     $this->set_global_prefix('');
297    
298 jonen 1.5 //child class MUST override this
299     //method to automatically set
300     //the DataListSource object.
301     //This class doesn't work without it.
302     $this->get_data_source();
303 jonen 1.1
304     //Call the subclass setup function.
305     //This is a way to get around having
306     //to override the constructor and
307     //pass in the same params.
308     $this->user_setup();
309 jonen 1.5 }
310    
311     /**
312     * This function renders the final
313     * widget
314     *
315     */
316     function render($indent_level, $output_debug) {
317 jonen 1.1
318 jonen 1.5 //setup the columns in their sorts
319     $this->setup_columns();
320    
321     //do any data prefetch work
322     //which may be child specific
323     if ( $this->_show_results() ) {
324     $this->data_prefetch();
325     }
326    
327     //This function gives the child class
328     //a chance to build the tables/divs/containers
329     //that will be responsible for the look/feel
330     //of the DataList
331     $this->gui_init();
332    
333     //see if we need to build the search area.
334     if ( $this->is_search_enabled() || $this->is_advanced_search_enabled() ) {
335     $this->_search_table = $this->child_build_search_table();
336     if ( $this->_search_table ) {
337     $this->set_form_render(TRUE);
338     }
339 jonen 1.1 }
340    
341 jonen 1.5
342     if ( $this->get_form_render() ) {
343 jonen 1.1 $form = new FORMtag( array("method" => $this->get_form_method(),
344     "action" => $this->build_base_url(),
345     "name" => $this->get_form_name(),
346     "style" => "margin-top: 0px;margin-bottom:0px;") );
347    
348 jonen 1.5 $target = $this->get_form_target();
349     if ( $target != NULL )
350 jonen 1.1 $form->set_tag_attribute("target",$target);
351    
352 jonen 1.5 $action = $this->get_form_action();
353     if ( $action != NULL )
354 jonen 1.1 $form->set_tag_attribute("action",$action);
355    
356 jonen 1.5 //now build the UI and return it
357     $form->add( $this->build_gui() );
358    
359     } else {
360     $form = container();
361 jonen 1.1
362 jonen 1.5 //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 jonen 1.1
371 jonen 1.5 //add the save vars the user wants.
372     $form->add( $this->_build_save_vars() );
373 jonen 1.1
374 jonen 1.5 //add any javascript required
375 jonen 1.1 $container = container( $this->_javascript(), $form );
376     return $container->render( $indent_level, $output_debug );
377 jonen 1.5 }
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 jonen 1.1
411 jonen 1.5 //now walk the list of rows and build and add the
412     //cells of data
413     $col_count = count($this->_columns);
414     while ( $row = $this->_datasource->get_next_data_row() ) {
415     $cnt = 1;
416     foreach( $this->_columns as $col_name => $data ) {
417     $obj = $this->build_column_item($row, $col_name);
418     if ( !is_object($obj) ) {
419     $obj = $this->_clean_string($obj, $col_name);
420 jonen 1.1 }
421 jonen 1.5 //
422     $this->child_add_row_cell($obj, $col_name,
423     (($cnt == $col_count) ? TRUE : FALSE),
424     $row);
425     $cnt++;
426     }
427     }
428     $container->add( $this->child_get_gui() );
429     }
430    
431    
432     return $container;
433     }
434    
435     /**
436     * This function is called automatically by
437     * the DataList constructor. It must be
438     * extended by the child class to actually
439     * set the DataListSource object.
440     *
441     *
442     */
443     function get_data_source() {
444     user_error("DataList::get_data_source() - ".
445     "child class must override this to ".
446     "set the the DataListSource object.");
447     }
448 jonen 1.1
449     /**
450     * A subclass can override this function
451     * to setup the class variables after
452     * the constructor. The constructor
453     * automatically calls this function.
454 jonen 1.5 *
455 jonen 1.1 */
456     function user_setup() {
457     user_error("DataList::user_setup() - ".
458 jonen 1.5 "child class must override this method ".
459     "to set the columns, and any options for ".
460     "the DataListSource.");
461 jonen 1.1 }
462    
463     /**
464     * A subclass can override this function
465     * to setup the class variables after
466     * the constructor. The constructor
467     * automatically calls this function.
468 jonen 1.5 *
469 jonen 1.1 */
470     function gui_init() {
471     user_error("DataList::gui_init() - ".
472 jonen 1.5 "child class must override this method ".
473     "to set up the containers/objects that will ".
474     "hold the search area, page controls, ".
475     "column headers and the data cells");
476     }
477    
478     /**
479     * This method is supposed to be written by
480     * the child class to build and add the column
481     * title to the UI
482     *
483     * @param string - the title of the column
484     * @param array - the column data ( from $this->_columns )
485     * @param int - the column #
486     *
487     */
488     function child_build_column_header($title, $col_data, $col_count) {
489     user_error("DataList::child_build_column_header() - ".
490     "child class must override this method ".
491     "to build the object that will be the ".
492     "individual column header/itle");
493     }
494    
495     /**
496     * This method is supposed to be written by
497     * the child class to add the cell data to the
498     * current row in the UI
499     *
500     * @param mixed - the object/string/entity that
501     * should get put into the column row cell.
502     * @param string - the name/title of the column that the
503     * object will live in
504     * @param boolean - flag that tells the function if this is
505     * is the last cell for the current row.
506     *
507     */
508     function child_add_row_cell($obj, $col_name, $last_in_row_flag) {
509     user_error("DataList::child_add_row_cell() - ".
510     "child class must override this method ".
511     "to build the object that will be the ".
512     "individual column data cell");
513     }
514 jonen 1.1
515 jonen 1.5 /**
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 jonen 1.1 * This function provides a way to automatically
543     * add javascript to this object.
544     * This function is meant to be extended by the
545     * child class.
546     *
547     * @return SCRIPTtag object
548     */
549     function _javascript() {
550     return NULL;
551     }
552    
553     /**
554     * This function adds a header item to the column headers
555     * from a list of parameters.
556     *
557     * @param string - $label - the label to use for
558     * the column header.
559     * @param int - $size - the size for the table column.
560     * @param string - $dbfield - the db field associated
561     * with this label from the query.
562     * @param boolean - $sortable - flag to make this column sortable.
563     * @param boolean - $searchable - flag to make this column searchable.
564     * @param string - header align value.
565     * @param string - the maximum # of characters to allow in the cell.
566     *
567     * @return array a single header array
568     */
569     function add_header_item( $label, $size=100, $data_name=NULL,
570     $sortable=FALSE, $searchable=FALSE,
571     $align="left", $sortorder="",
572     $max_text_length=NULL) {
573    
574     $this->_columns[$label] = array("size" => $size,
575 jonen 1.5 "data_name" => $data_name,
576     "sortable" => $sortable,
577     "searchable" => $searchable,
578     "align" => $align,
579     "sortorder" => $sortorder,
580     "maxtextlength" => $max_text_length);
581 jonen 1.1 $this->_num_headers++;
582 jonen 1.5
583     $this->_check_datasource("add_header_item");
584     $this->_datasource->add_column($label, $data_name, $sortable,
585     $searchable, $sortorder);
586 jonen 1.1 }
587    
588    
589     /**
590     * This function sets a prefix for all
591     * variables that are used in the item list
592     * table on a page. This allows you to have
593     * multiple itemlists on a single html page.
594     *
595     * @param string $prefix - the prefix for all vars.
596     */
597     function set_global_prefix($prefix) {
598 jonen 1.5 $this->_global_prefix = $prefix;
599     //update all the vars used
600     foreach ($this->_vars as $name => $value ) {
601     $this->_vars[$name] = $prefix.$value;
602     }
603 jonen 1.1 }
604    
605     /**
606     * returns the current variable prefix
607     * string being used.
608     *
609     * @return string - current global prefix
610     */
611     function get_global_prefix() {
612     return $this->_global_prefix;
613     }
614    
615 jonen 1.5 /**
616     * This function is used to set the
617     * DataListSource object for this instance
618     *
619     * @param DataListSource object
620     */
621     function set_data_source( $datasource ) {
622     $this->_datasource = &$datasource;
623     }
624 jonen 1.1
625     /**
626     * Enable the search ability.
627     *
628     * @param boolean
629     */
630     function search_enable( ) {
631     $this->_search_flag = TRUE;
632 jonen 1.5 if ( !$this->is_advanced_search_enabled() ) {
633 jonen 1.1 $this->set_search_type("simple");
634     }
635     }
636    
637     /**
638     * Disable the search ability.
639     *
640     * @param boolean
641     */
642     function search_disable( ) {
643     $this->_search_flag = FALSE;
644     }
645    
646     /**
647     * get the status of the search
648     * ability.
649     *
650     * @return boolean
651     */
652     function is_search_enabled() {
653     return $this->_search_flag;
654     }
655    
656    
657     /**
658     * Enable the advanced search
659     * capability
660     * NOTE: Child class MUST
661     * extend the
662     * _build_advanced_search_table
663     */
664     function advanced_search_enable() {
665     $this->_advanced_search_flag = TRUE;
666 jonen 1.5 if ( !$this->is_search_enabled() ) {
667 jonen 1.1 $this->set_search_type("advanced");
668     }
669     }
670    
671     /**
672     * Disable the advanced search
673     * capability
674     *
675     */
676     function advanced_search_disable() {
677     $this->_advanced_search_flag = FALSE;
678     }
679    
680     /**
681     * This returns the status of the
682     * advanced search flag.
683     *
684     * @return boolean
685     */
686     function is_advanced_search_enabled() {
687     return $this->_advanced_search_flag;
688     }
689    
690     /**
691     * Set the simple search modifyer
692     * flag.
693     * NOTE: by default all the modifiers
694     * are enabled. You can limit the
695     * modifiers by passing in the
696     * string of defines of which ones
697     * you want enabled.
698     *
699     * MODIFIERS:
700     * SEARCH_BEGINS_WITH
701     * SEARCH_CONTAINS
702     * SEARCH_EXACT
703     * SEARCH_ENDS_WITH
704     *
705     * ie. SEARCH_BEGINS_WITH.SEARCH_EXACT
706     * will enable ONLY the
707     * "begins with" and "exact" modifiers.
708     *
709     * @param string
710     */
711     function set_simple_search_modifier( $modifier = SEARCH_ALL ) {
712 jonen 1.5 if ( $modifier == 0 ) {
713 jonen 1.1 $this->_simple_search_modifier = SEARCH_BEGINS_WITH |
714     SEARCH_CONTAINS |
715     SEARCH_EXACT |
716     SEARCH_ENDS_WITH;
717     } else {
718     $this->_simple_search_modifier = $modifier;
719     }
720     }
721    
722     /**
723     * gets the value of the search modifier
724     * flag.
725     */
726     function get_simple_search_modifier() {
727     return $this->_simple_search_modifier;
728     }
729    
730     /**
731     * This function sets the default # of rows
732     * per page to display. By default its 10.
733     * This lets the user override this value.
734     *
735     * @param int - the # of rows to use.
736     */
737     function set_default_num_rows( $num_rows ) {
738     $this->default_rows_per_page = $num_rows;
739     }
740    
741     /**
742     * This function gets the current default
743     * number of rows to display setting.
744     *
745     * @return int
746     */
747     function get_default_num_rows( ) {
748     return $this->_default_rows_per_page;
749     }
750    
751 jonen 1.5 /**
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 jonen 1.1
761     /**
762 jonen 1.5 * This sets the maximum # of rows to
763     * display when in expand mode
764     *
765     * @param int - new # of maximum rows
766     * to display when in 'expand' mode
767 jonen 1.1 *
768     */
769 jonen 1.5 function set_max_rows( $max ) {
770     $this->_max_rows = $max;
771 jonen 1.1 }
772    
773    
774    
775 jonen 1.5 /**
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 jonen 1.1
789 jonen 1.5 $limit = $this->numrows();
790     $this->_datasource->query($this->offset(), $limit,
791     $this->orderby(), $this->reverseorder(),
792     $this->search_field(), $this->search_value(),
793     $this->simple_search_modifier_value(),
794     $this->search_type() );
795     }
796 jonen 1.1
797    
798    
799     /*
800     * Takes an array of (name, sortable, db_field, alignment,
801     * size), with one element corresponding to each column.
802     */
803     function setup_columns() {
804     $temp_headers = array();
805    
806     foreach( $this->_columns as $col_name => $data ) {
807 jonen 1.5 if ( $data["sortorder"] == "reverse" ) {
808 jonen 1.1 $data["reverseorder"] = "true";
809 jonen 1.5 } else {
810 jonen 1.1 $data["reverseorder"] = "false";
811     }
812     $temp_headers[$col_name] = $data;
813     }
814     $this->_columns = $temp_headers;
815     }
816    
817    
818    
819 jonen 1.5 /**
820     * general DataListSource object checker.
821     *
822     */
823     function _check_datasource($function_name) {
824     if ( !is_object($this->_datasource) ) {
825     user_error("DataList::".$function_name."() - DataListSource object is not set");
826     exit;
827     }
828     }
829    
830    
831     /*********************************************/
832     /* 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 jonen 1.1
865 jonen 1.5 /**
866 jonen 1.1 * This function returns the current value
867     * of the offset variable. This is an offset
868     * into the query return data set.
869     *
870     * @return int - the current value.
871     */
872     function offset() {
873 jonen 1.5 return(int)$this->_get("offsetVar", 0);
874 jonen 1.1 }
875    
876 jonen 1.5 /**
877 jonen 1.1 * This function is used to set/change
878     * the offset for this list.
879     *
880     * @param int - the new offset.
881     */
882     function set_offset($new_offset) {
883 jonen 1.5 $this->_set("offsetVar", $new_offset);
884 jonen 1.1 }
885    
886 jonen 1.5 /**
887 jonen 1.1 * This function returns the value of the
888     * current orderby variable.
889     *
890     * @return string.
891     */
892     function orderby() {
893 jonen 1.5 return $this->_get("orderbyVar", $this->_default_orderby);
894 jonen 1.1 }
895    
896 jonen 1.5 /**
897 jonen 1.1 * This builds a query string var for the
898     * orderby value.
899     *
900     * @return string - "orderby=(thevalue)"
901     */
902     function build_orderby_querystring() {
903 jonen 1.5 $str = $this->_vars["orderbyVar"]."=".urlencode($this->orderby());
904 jonen 1.1 return $str;
905     }
906    
907     /**
908     * This function returns the current value of
909     * the reverse order member variable.
910     *
911     * @return string.
912     */
913     function reverseorder() {
914 jonen 1.5 return $this->_get("reverseorderVar", $this->_default_reverseorder);
915 jonen 1.1 }
916    
917     /**
918     * This function sets the reverse order flag
919     * to a new value.
920     *
921     * @param string - the new value.
922     */
923     function set_reverseorder($new_value) {
924 jonen 1.5 $this->_set("reverseorderVar", $new_value);
925 jonen 1.1 }
926    
927 jonen 1.5 /**
928 jonen 1.1 * This builds a query string var for the
929     * reverseorder value.
930     *
931     * @return string - "orderby=(thevalue)"
932     */
933     function build_reverseorder_querystring() {
934 jonen 1.5 $str = $this->_vars["reverseorderVar"]."=".urlencode($this->reverseorder());
935 jonen 1.1 return $str;
936     }
937    
938     /**
939     * This function returns the number of rows
940     * that the query found.
941     *
942     * @return int - the number of rows
943     */
944     function numrows() {
945 jonen 1.5 return(int)$this->_get("numrowsVar", $this->_default_rows_per_page);
946 jonen 1.1 }
947    
948     /**
949     * This function sets the # of rows to display
950     * per page.
951     *
952     * @param int - the # of rows
953     */
954     function set_numrows($new_numrows) {
955 jonen 1.5 $this->_set("numrowsVar", $new_numrows);
956 jonen 1.1 }
957    
958     /**
959     * returns the current value of
960     * the search field name
961     *
962     * @return string
963     */
964     function search_field() {
965 jonen 1.5 return $this->_get("search_fieldVar", '');
966 jonen 1.1 }
967    
968 jonen 1.5 /**
969 jonen 1.1 * This builds a query string var for the
970     * searchfield value.
971     *
972     * @return string - "orderby=(thevalue)"
973     */
974     function build_searchfield_querystring() {
975 jonen 1.5 $str = $this->_vars["search_fieldVar"]."=".urlencode($this->searchfield());
976 jonen 1.1 return $str;
977     }
978    
979     /**
980     * returns the current value of
981     * te search field value.
982     *
983     * @return string
984     */
985     function search_value() {
986 jonen 1.5 return $this->_get("search_valueVar", '');
987 jonen 1.1 }
988    
989 jonen 1.5 /**
990 jonen 1.1 * This builds a query string var for the
991     * searchfield value.
992     *
993     * @return string - "orderby=(thevalue)"
994     */
995     function build_searchvalue_querystring() {
996 jonen 1.5 $str = $this->_vars["search_valueVar"]."=".urlencode($this->search_value());
997 jonen 1.1 return $str;
998     }
999    
1000     /**
1001     * returns the current value of the
1002     * simple search modifier
1003     *
1004     * @return string
1005     */
1006     function simple_search_modifier_value() {
1007 jonen 1.5 return $this->_get("simple_search_modifierVar", '');
1008 jonen 1.1 }
1009    
1010    
1011     /**
1012     * returns the type of search being used
1013     *
1014     * @return string
1015     */
1016     function search_type() {
1017 jonen 1.5 return $this->_get("search_typeVar", "simple");
1018 jonen 1.1 }
1019    
1020     /**
1021     * This function sets the search type
1022     *
1023     * @param string - the search type
1024     * "simple" or "advanced"
1025     */
1026     function set_search_type($type) {
1027 jonen 1.5 $this->_set("search_typeVar", $type);
1028 jonen 1.1 }
1029    
1030    
1031     /**
1032     * returns the current value of the showall
1033     * flag. This tells us if they want the entire
1034     * list of data back from the DB.
1035     *
1036     * @return string - the current value
1037     */
1038     function showall() {
1039 jonen 1.5 return(int)$this->_get("showallVar", 0);
1040     }
1041    
1042     /**
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 jonen 1.1 }
1064    
1065    
1066 jonen 1.5 /**
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 jonen 1.1
1079    
1080 jonen 1.5 /*******************************************/
1081     /* FORM VARIABLES SECTION */
1082     /*******************************************/
1083    
1084     /**
1085 jonen 1.1 * This function is used to set the
1086     * form name
1087     *
1088     * @param string
1089     */
1090     function set_form_name($name) {
1091     $this->_form_attributes["name"] = $name;
1092     }
1093    
1094     /**
1095     * This function is used to get
1096     * the form name
1097     *
1098     * @return string
1099     */
1100     function get_form_name() {
1101     return $this->_form_attributes["name"];
1102     }
1103    
1104     /**
1105     * This function is used to set the
1106     * form target
1107     *
1108     * @param string
1109     */
1110     function set_form_target($target) {
1111     $this->_form_attributes["target"] = $target;
1112     }
1113    
1114     /**
1115     * This function is used to get
1116     * the form target
1117     *
1118     * @return string
1119     */
1120     function get_form_target() {
1121     return $this->_form_attributes["target"];
1122     }
1123 jonen 1.5
1124 jonen 1.1 /**
1125     * This function is used to set the
1126     * form method
1127     *
1128     * @param string (POST or GET)
1129     */
1130     function set_form_method($method) {
1131 jonen 1.5 if ( $method != "GET" && $method != "POST" ) {
1132     user_error("DataList::set_form_method() - INVALID Form method ".$method);
1133     } else {
1134     $this->_form_attributes["method"] = $method;
1135     }
1136 jonen 1.1 }
1137    
1138     /**
1139     * This function is used to get
1140     * the form method
1141     *
1142     * @return string (POST or GET)
1143     */
1144     function get_form_method() {
1145     return $this->_form_attributes["method"];
1146     }
1147    
1148 jonen 1.5 /**
1149     * Sets the form action
1150     *
1151     * @param string
1152     */
1153 jonen 1.1 function set_form_action($action) {
1154     $this->_form_attributes["action"] = $action;
1155     }
1156    
1157 jonen 1.5 /**
1158 jonen 1.1 * This function is used to get
1159     * the form action
1160     *
1161     * @return string (POST or GET)
1162     */
1163     function get_form_action() {
1164     return $this->_form_attributes["action"];
1165     }
1166    
1167     /**
1168     * Sets whether to the output into a form
1169     *
1170     * @param bool
1171     */
1172     function set_form_render($flag) {
1173     $this->_form_render_flag = $flag;
1174     }
1175    
1176     /**
1177     * Return the state of the form render
1178     *
1179     * @return bool
1180     */
1181     function get_form_render() {
1182     return $this->_form_render_flag;
1183     }
1184    
1185     /**
1186 jonen 1.5 * This function is used to set the
1187     * message displayed when no data is found
1188     *
1189     * @param string
1190     */
1191 jonen 1.1 function set_not_found_message($mesg) {
1192 jonen 1.5 $this->_check_datasource("set_not_found_message");
1193 jonen 1.1 $this->_datasource->set_not_found_message($mesg);
1194     }
1195    
1196    
1197 jonen 1.5 /**
1198     * This function is used to set the value
1199     * of the _show_results_flag
1200     *
1201     * @param boolean - TRUE to show the results
1202     */
1203     function set_show_results( $flag=TRUE ) {
1204     $this->_show_results_flag = $flag;
1205     }
1206    
1207 jonen 1.1
1208 jonen 1.5 /**
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 jonen 1.1 * this method builds some hidden
1220     * form fields to automatically
1221     * be placed inside the form.
1222 jonen 1.5 *
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 jonen 1.1 *
1228 jonen 1.5 * @return mixed depending on form method
1229 jonen 1.1 */
1230     function _build_save_vars() {
1231     $container = container();
1232     foreach($this->_save_vars as $name => $value) {
1233     $container->add(form_hidden($name, $value));
1234     }
1235     return $container;
1236     }
1237    
1238 jonen 1.5 /**
1239 jonen 1.1 * This function sets the save variables
1240     * that the user/child wants to automatically
1241     * propogate
1242     *
1243     * @param array - name=>value pairs of the data
1244     * that they want to propogate
1245     */
1246     function set_save_vars($vars) {
1247     $this->_save_vars = $vars;
1248     }
1249    
1250     /**
1251 jonen 1.5 * 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 jonen 1.1 * This builds the base url used
1271     * by the column headers as well
1272     * as the page tool links.
1273     *
1274     * it basically builds:
1275     * $_SELF?$_GET
1276     *
1277     * @return string
1278     */
1279     function build_base_url() {
1280    
1281     $url = $_SERVER["PHP_SELF"]."?";
1282    
1283 jonen 1.5 if ( $this->get_form_method() == "POST" ) {
1284 jonen 1.1 return $url;
1285     }
1286    
1287 jonen 1.5 $vars = array_merge($_POST, $_GET);
1288 jonen 1.1 //request method independant access to
1289     //browser variables
1290 jonen 1.5 if ( count($vars) ) {
1291 jonen 1.1 //walk through all of the get vars
1292     //and add them to the url to save them.
1293     foreach($vars as $name => $value) {
1294    
1295 jonen 1.5 if ( $name != $this->_vars["offsetVar"] &&
1296     $name != $this->_vars["orderbyVar"] &&
1297     $name != $this->_vars["reverseorderVar"] &&
1298     $name != $this->_vars["search_valueVar"]
1299 jonen 1.1 ) {
1300 jonen 1.5 if ( is_array($value) ) {
1301 jonen 1.1 $url .= $name."[]=".implode("&".$name."[]=",$value)."&";
1302     } else {
1303 jonen 1.5 $url .= $name."=".urlencode(stripslashes($value))."&";
1304     }
1305 jonen 1.1 }
1306     }
1307     }
1308    
1309 jonen 1.5 return htmlentities($url);
1310 jonen 1.1 }
1311    
1312 jonen 1.5 /**
1313     * This function builds the 'tool' images that
1314     * allow you to walk through the data list itself.
1315     * It provides image links for
1316     * first - go to the first page in the data list
1317     * prev - go to the previous page in the data list
1318     * next - go to the next page in the data list
1319     * last - go to the last page in the data list
1320     * all - show the rest of the list from the current offset
1321     *
1322     * @param string - which tool image to build
1323     * @return Object
1324     */
1325     function build_tool_link( $which ) {
1326     $num_pages = $this->get_num_pages();
1327 jonen 1.1 $cur_page = $this->get_current_page();
1328     $last_page = $this->get_last_page();
1329    
1330 jonen 1.5 $image_path = $this->get_image_path();
1331     switch ( $which ) {
1332    
1333     case "first":
1334     $rows_string = "First ".$this->get_default_num_rows()." Rows";
1335     if ( $this->offset() <= 0 ) {
1336     $obj = html_img($image_path."/first_group_button_inactive.gif",
1337     '','',0,$rows_string, NULL, $rows_string);
1338     } else {
1339 jonen 1.1 $url = $this->_build_tool_url(0);
1340 jonen 1.5 $obj = html_img_href($url, $image_path."/first_group_button.gif",
1341     '','',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 jonen 1.1 }
1359 jonen 1.5 break;
1360 jonen 1.1
1361 jonen 1.5 case "next":
1362     $rows_string = "Next ".$this->get_default_num_rows()." Rows";
1363     if ( ($num_pages == 1) || ($cur_page == $last_page) ) {
1364     $obj = html_img($image_path."/next_group_button_inactive.gif",
1365     '','',0, $rows_string, NULL, $rows_string);
1366     } else {
1367     $offset = $this->offset() + $this->numrows();
1368     $url = $this->_build_tool_url($offset);
1369     $obj = html_img_href($url, $image_path."/next_group_button.gif",
1370     '','',0, $rows_string, NULL, NULL, $rows_string);
1371     }
1372     break;
1373    
1374     case "last":
1375     $rows_string = "Last ".$this->get_default_num_rows()." Rows";
1376     if ( ($num_pages == 1) || ($cur_page == $last_page) ) {
1377     $obj = html_img($image_path."/last_group_button_inactive.gif",
1378     '','',0, $rows_string, NULL, $rows_string);
1379     } else {
1380     $offset = (int)(($num_pages - 1) * $this->numrows());
1381     $url = $this->_build_tool_url($offset);
1382     $obj = html_img_href($url, $image_path."/last_group_button.gif",
1383     '','',0, $rows_string, NULL, NULL, $rows_string);
1384     }
1385     break;
1386    
1387     case "all":
1388     $offset = $this->offset();
1389     if ( $this->showall() ) {
1390     $url = $this->_build_tool_url($offset, TRUE, 0);
1391     $obj = html_img_href($url, $image_path."/close_group_button.gif",
1392     '','',0,"Collapse Rows", NULL, NULL, "Collapse Rows");
1393     } else {
1394     if ( ($num_pages == 1) ) {
1395     $obj = html_img($image_path."/expand_group_button_inactive.gif",
1396     '','',0, "Expand Rows", NULL, "Expand Rows");
1397     } else {
1398     $url = $this->_build_tool_url($offset, TRUE, 1);
1399     $obj = html_img_href($url, $image_path."/expand_group_button.gif",
1400     '','',0,"Expand Rows", NULL, NULL, "Expand Rows");
1401     }
1402     }
1403     //so we don't save it into the mozilla navigation bar links
1404     unset($url);
1405     break;
1406     }
1407    
1408     if ( $url ) {
1409     $this->_save_mozilla_nav_link($which, $url);
1410     }
1411    
1412     return $obj;
1413     }
1414    
1415     /**
1416     * This function is used to build the url
1417     * for a tool link.
1418     * (first, prev, next, last, all)
1419     *
1420     * @param int - the offset for the link
1421     * @param boolean - add the showall value to the url
1422     * @param int - the showall value to use if the flag is on
1423     *
1424     * @return string
1425     */
1426     function _build_tool_url($offset, $showall_flag=FALSE, $showall_value=0) {
1427     if ( $this->get_form_method() == "POST" ) {
1428     $form_name = $this->get_form_name();
1429     $url = "javascript: document.".$form_name;
1430     $url .= ".".$this->_vars["offsetVar"].".value='".$offset."';";
1431    
1432     //add the showall variable to the post
1433     if ( $showall_flag ) {
1434     $form_field = $this->_vars["showallVar"];
1435 jonen 1.1 $url .= "document.".$form_name.".";
1436 jonen 1.5 $url .= $form_field.".value='".$showall_value."';";
1437     }
1438 jonen 1.1
1439 jonen 1.5 $url .= "document.".$form_name.".submit();";
1440     } else {
1441     $url = $this->build_base_url();
1442     $url .= $this->build_state_vars_query_string($offset, $showall_flag,
1443     $showall_value);
1444     }
1445     return $url;
1446     }
1447 jonen 1.1
1448     /**
1449     * this function is used to build a sub query string
1450     * of all of the query string vars to save the
1451     * state of the DBItemList. This is used for pages
1452     * that want to come back to the list at the same state
1453     *
1454     * @return string - name=value& pairs
1455     */
1456     function build_state_vars_query_string($offset, $showall_flag=FALSE,
1457 jonen 1.5 $showall_value=0) {
1458 jonen 1.1 $str = "";
1459    
1460 jonen 1.5 $str .= $this->_vars["offsetVar"]."=".urlencode($offset);
1461     $str .= "&".$this->_vars["orderbyVar"]."=".urlencode($this->orderby());
1462     $str .= "&".$this->_vars["reverseorderVar"]."=".urlencode($this->reverseorder());
1463     $str .= "&".$this->_vars["search_fieldVar"]."=".urlencode($this->search_field());
1464     $str .= "&".$this->_vars["search_valueVar"]."=".urlencode($this->search_value());
1465     $str .= "&".$this->_vars["simple_search_modifierVar"]."=".urlencode($this->simple_search_modifier_value());
1466     $str .= "&".$this->_vars["search_typeVar"]."=".urlencode($this->search_type());
1467     if ( $showall_flag ) {
1468     $str .= "&".$this->_vars["showallVar"]."=".urlencode($showall_value);
1469     }
1470    
1471     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 jonen 1.1
1488 jonen 1.5 /**
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 jonen 1.1 }
1497    
1498 jonen 1.5 /**
1499     * This function returns the path to the
1500     * images used in this class
1501     *
1502     * @return string
1503     */
1504     function set_image_path($path) {
1505     return $this->_image_path = $path;
1506     }
1507 jonen 1.1
1508     /**
1509     * This function returns the current
1510     * page that the item list is on.
1511     *
1512     * @return int
1513     */
1514     function get_current_page() {
1515     return((int) ($this->offset() / $this->numrows())) + 1;
1516     }
1517    
1518     /**
1519     * This function returns the #
1520     * of pages that are available
1521     * for this list of items.
1522     *
1523     * @return int
1524     */
1525     function get_num_pages() {
1526 jonen 1.5 $this->_check_datasource("get_num_pages");
1527     $total_rows = $this->_datasource->get_total_rows();
1528 jonen 1.1
1529     $cnt = (int)($total_rows / $this->numrows());
1530 jonen 1.5 if ( (($total_rows % $this->numrows()) != 0) || ($total_rows == 0) ) {
1531 jonen 1.1 $cnt++;
1532     }
1533     return $cnt;
1534     }
1535    
1536     /**
1537     * This calculates the last page #
1538     * for this list of items
1539     *
1540     * @return int
1541     */
1542     function get_last_page() {
1543     return $this->get_num_pages();
1544     }
1545    
1546     /**
1547     * This function builds the string
1548     * that describes the current page
1549     * out of n pages the list is showing
1550     *
1551     * @return string (ie. 1 to 10 of 25)
1552     */
1553     function get_page_info() {
1554     $cur_page = $this->get_current_page();
1555     $low_range = $this->offset() + 1;
1556     $num_pages = $this->get_num_pages();
1557     $num_rows_per_page = $this->numrows();
1558    
1559 jonen 1.5 $this->_check_datasource("get_page_info");
1560     $total_rows = $this->_datasource->get_total_rows();
1561 jonen 1.1
1562     $high_range = $low_range + ($num_rows_per_page - 1);
1563 jonen 1.5 if ( $high_range > $total_rows ) {
1564 jonen 1.1 $high_range = $total_rows;
1565     }
1566    
1567 jonen 1.5 if ( $total_rows == 0 ) {
1568 jonen 1.1 $str = "0 of 0";
1569     } else {
1570     $str = $low_range . " to ". $high_range;
1571     $str .= " of ".$total_rows;
1572     }
1573    
1574     return $str;
1575     }
1576    
1577    
1578    
1579     /**
1580     * This builds a url for a particular
1581     * column header.
1582     *
1583     * @param string - $col_name
1584     * @return Atag object;
1585     */
1586     function build_column_url($col_name) {
1587     $orderby = $this->orderby();
1588     $reverseorder = $this->reverseorder();
1589     $search_value = $this->search_value();
1590    
1591     $order_value = $this->_columns[$col_name]["data_name"];
1592     $reverse_value = "false";
1593 jonen 1.5 if ( !$reverseorder ) {
1594 jonen 1.1 $reverseorder = 'false';
1595     }
1596    
1597 jonen 1.5 if ( $orderby == $order_value && $reverseorder === 'false' ) {
1598 jonen 1.1 $reverse_value = "true";
1599     }
1600    
1601 jonen 1.5 if ( $this->get_form_method() == "POST" ) {
1602 jonen 1.1 //we have to construct this url
1603     //specially.
1604     $form_name = $this->get_form_name();
1605    
1606     $url = "javascript: ";
1607     //set the offset correctly
1608 jonen 1.5 $url .= "document.".$form_name.".".$this->_vars["offsetVar"].".value='".$this->offset()."';";
1609 jonen 1.1 //set the orderby correctly.
1610 jonen 1.5 $url .= "document.".$form_name.".".$this->_vars["orderbyVar"].".value='".$order_value."';";
1611 jonen 1.1 //set the reverseorder
1612 jonen 1.5 $url .= "document.".$form_name.".".$this->_vars["reverseorderVar"].".value='".$reverse_value."';";
1613 jonen 1.1
1614     $url .= "document.".$form_name.".submit();";
1615     } else {
1616     //handle the normal get.
1617     $url = $this->build_base_url();
1618     //Now add the orderby, reverseorder and offset vars
1619 jonen 1.5 $url .= $this->_vars["offsetVar"] ."=0&";
1620 jonen 1.1 //set the orderbyvar
1621 jonen 1.5 $url .= $this->_vars["orderbyVar"] ."=".$order_value."&";
1622 jonen 1.1 //set the reverseorder
1623 jonen 1.5 $url .= $this->_vars["reverseorderVar"] ."=".$reverse_value."&";
1624 jonen 1.1 //set the search value
1625 jonen 1.5 $url .= $this->_vars["search_valueVar"] ."=".$search_value;
1626 jonen 1.1 }
1627    
1628     return $url;
1629     }
1630    
1631     /**
1632     * This does some magic filtering on the data
1633     * that we display in a column. This helps
1634     * to prevent nast data that may have html
1635     * tags in it.
1636     *
1637     * @param string - the column data u want to filter
1638     * @return string the cleaned/filtered data
1639     */
1640     function filter_column_string($data) {
1641 jonen 1.5 return htmlspecialchars(trim($data));
1642     }
1643    
1644    
1645    
1646     /**
1647     * 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     *
1654     * @return mixed - the cleaned string or object
1655     */
1656     function _clean_string($obj, $col_name) {
1657     if ( is_string($obj) ) {
1658     if ( $this->_columns[$col_name]["maxtextlength"] ) {
1659     //looks like we need to make sure we
1660     //truncate the string to a max length
1661     if ( strlen($obj) > $this->_columns[$col_name]["maxtextlength"] ) {
1662     //we need to truncate it.
1663     $obj = substr($obj, 0, $this->_columns[$col_name]["maxtextlength"]);
1664     $obj .= "...";
1665     }
1666     }
1667     }
1668     return $obj;
1669     }
1670    
1671     /********************************/
1672     /* SEARCH RELATED */
1673     /********************************/
1674 jonen 1.1
1675     /**
1676     * This method gets the array of
1677     * searchable header fields (columns)
1678     *
1679     * @return array
1680     */
1681     function _get_searchable_fields() {
1682     $fields = array();
1683     foreach($this->_columns as $name => $header) {
1684 jonen 1.5 if ( $header["searchable"] == TRUE ) {
1685 jonen 1.1 $fields[$name] = $header["data_name"];
1686     }
1687     }
1688     return $fields;
1689     }
1690    
1691     /**
1692     * This builds the simple search modifier
1693     * select box.
1694     *
1695     * @return INPUTtag object.
1696     */
1697     function _build_simple_search_modifier() {
1698    
1699     $options = array();
1700    
1701     $modifier = $this->get_simple_search_modifier();
1702    
1703 jonen 1.5 if ( $modifier & SEARCH_BEGINS_WITH ) {
1704 jonen 1.1 $options["beginning with"] = "BEGINS";
1705     }
1706 jonen 1.5 if ( $modifier & SEARCH_CONTAINS ) {
1707 jonen 1.1 $options["containing"] = "CONTAINS";
1708     }
1709 jonen 1.5 if ( $modifier & SEARCH_EXACT ) {
1710 jonen 1.1 $options["matching"] = "EXACT";
1711     }
1712 jonen 1.5 if ( $modifier & SEARCH_ENDS_WITH ) {
1713 jonen 1.1 $options["ending with"] = "ENDS";
1714     }
1715    
1716     $selected = $this->simple_search_modifier_value();
1717     //make the default Begins with
1718 jonen 1.5 if ( !$selected ) {
1719 jonen 1.1 $selected = "BEGINS";
1720     }
1721    
1722 jonen 1.5 return form_select($this->_vars["simple_search_modifierVar"], $options, $selected);
1723 jonen 1.1 }
1724    
1725 jonen 1.5 /**
1726 jonen 1.1 * This function is used to make safe
1727     * any query string value that is used
1728     *
1729     * @param string
1730     * @return string
1731     */
1732     function search_value_filter( $value ) {
1733     return stripslashes( trim($value) );
1734     }
1735     }
1736     ?>

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