'); //////////////////////////////////////// // table_id: 's id tag - WARNING : do not use '-' in table ids as it's used for generating javascript code // headers: an associative array "label"=>"type" // column_sort: the column to sort on at load-time // options : an associative array to override options // - search_area : boolean (default true) // - pagesize_area : boolean (default true) // - notes_area : boolean (default true) // - search_width : size in chars of the search text dialog // - notes : an array of additional notes // - pagesize: the initial pagination size // - pagesize_def: the page size when one clicks the pagesize reset button // - max_pages: the max number of pages to display in the paginator class PlekitTable { // mandatory var $table_id; var $headers; var $column_sort; // options var $caption; var $search_area; // boolean (default true) var $pagesize_area; // boolean (default true) var $notes_area; // boolean (default true) var $search_width; // size in chars of the search text dialog var $pagesize; // the initial pagination size var $pagesize_def; // the page size when one clicks the pagesize reset button var $max_pages; // the max number of pages to display in the paginator var $notes; // an array of additional notes var $has_tfoot; function PlekitTable ($table_id,$headers,$column_sort,$options=NULL) { $this->table_id = $table_id; $this->headers = $headers; $this->column_sort = $column_sort; $this->has_tfoot=false; $this->search_area = true; $this->pagesize_area = true; $this->notes_area = true; $this->search_width = 40; $this->pagesize = 25; $this->pagesize_def = 999; $this->max_pages = 10; $this->notes = array(); $this->set_options ($options); } function set_options ($options) { if ( ! $options) return; if (array_key_exists('caption',$options)) $this->caption=$options['caption']; if (array_key_exists('search_area',$options)) $this->search_area=$options['search_area']; if (array_key_exists('pagesize_area',$options)) $this->pagesize_area=$options['pagesize_area']; if (array_key_exists('notes_area',$options)) $this->notes_area=$options['notes_area']; if (array_key_exists('search_width',$options)) $this->search_width=$options['search_width']; if (array_key_exists('pagesize',$options)) $this->pagesize=$options['pagesize']; if (array_key_exists('pagesize_def',$options)) $this->pagesize_def=$options['pagesize_def']; if (array_key_exists('max_pages',$options)) $this->max_pages=$options['max_pages']; if (array_key_exists('notes',$options)) $this->notes=array_merge($this->notes,$options['notes']); } public function columns () { return count ($this->headers); } //////////////////// public function start () { $paginator=$this->table_id."_paginator"; $classname="paginationcallback-".$paginator; $classname.=" max-pages-" . $this->max_pages; $classname.=" paginate-" . $this->pagesize; // instantiate paginator callback print <<< EOF
EOF; if ($this->pagesize_area) print $this->pagesize_area_html (); if ($this->search_area) print $this->search_area_html (); if ($this->caption) print ""; print ""; foreach ($this->headers as $label => $type) { switch ($type) { case "none" : $class=""; break; case "string": case "int": case "float": $class="sortable"; break; case ( strpos($type,"date-") == 0): $class="sortable-" . $type; break; default: $class="sortable-sort" . $type; break; } printf ('',$class,$label); } print <<< EOF EOF; } //////////////////// // for convenience, the options that apply to the bottom area can be passed here // typically notes will add up to the ones provided so far, and to the default ones // xxx default should be used only if applicable function end ($options=NULL) { $this->set_options($options); print $this->bottom_html(); if ($this->notes_area) print $this->notes_area_html(); } //////////////////// function pagesize_area_html () { $width=count($this->headers); $pagesize_text_id = $this->table_id . "_pagesize"; $result= <<< EOF EOF; return $result; } //////////////////// function search_area_html () { $width=count($this->headers); $search_text_id = $this->table_id . "_search"; $search_reset_id = $this->table_id . "_search_reset"; $search_and_id = $this->table_id . "_search_and"; $result = <<< EOF EOF; return $result; } //////////////////// start a section function tfoot_start () { print $this->tfoot_start_html(); } function tfoot_start_html () { $this->has_tfoot=true; return ""; } //////////////////////////////////////// function bottom_html () { $result=""; if ($this->has_tfoot) $result .= ""; else $result .= ""; $result .= "
$this->caption
%s
reset visible size
\n"; return $result; } //////////////////////////////////////// function notes_area_html () { $default_notes = array( "Enter & or | in the search area to switch between AND and OR search modes", "Hold down the shift key to select multiple columns to sort"); if ($this->notes) $notes=$this->notes; else $notes=array(); $notes=array_merge($notes,$default_notes); if (! $notes) return ""; $result = ""; $result .= "

Notes\n"; foreach ($notes as $note) $result .= "
$note\n"; $result .= "

"; return $result; } //////////////////////////////////////// function row_start ($id=NULL,$class=NULL) { print "\n"; } function row_end () { print "\n"; } //////////////////// // supported options: // (*) only-if : if set and false, then print 'n/a' instead of (presumably void) $text // (*) class // (*) columns // (*) hfill // (*) align public function cell ($text,$options=NULL) { print $this->cell_html ($text,$options); } public function cell_html ($text,$options=NULL) { if (isset ($options['only-if']) && ! $options['only-if'] ) $text="n/a"; $html=""; $html .= "columns() . "'"; $option=$options['align']; if ($option) $html .= " style='text-align:$option'"; $html .= ">$text"; return $html; } } ?>