');
+//// hash to retrieve the headers and options as passed at table-creation time
+// this means that table_id's need to be different across the page,
+// which is required anyway for the search and pagesize areas to work properly
+$plc_table_hash=array();
+
////////////////////////////////////////
function plc_table_cell($cell) {
printf ('<td class="plc_table"> %s </td>',$cell);
// table_id: <table>'s id tag
// headers: an associative array "label"=>"type"
// column_sort: the column to sort on at load-time
-// search_area : boolean
-// 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
-function plc_table_start ($table_id, $headers, $column_sort,
- $search_area=true,$max_pages="10",$pagesize="25",$pagesize_def="999") {
- if ($search_area) {
+// options : an associative array to override options (should be passed to both _stsart and _end)
+// - search_area : boolean (default true)
+// - notes_area : boolean (default true)
+// - 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
+// - footers: a list of table rows (<tr> will be added) for building the table's tfoot area
+function plc_table_start ($table_id, $headers, $column_sort, $options=NULL) {
+ if ( ! $options ) $options = array();
+ global $plc_table_hash;
+ $plc_table_hash[$table_id]=array($headers,$options);
+ $search_area = array_key_exists('search_area',$options) ? $options['search_area'] : true;
+ $max_pages = array_key_exists('max_pages',$options) ? $options['max_pages'] : 10;
+ $pagesize = array_key_exists('pagesize',$options) ? $options['pagesize'] : 25;
+ $pagesize_def = array_key_exists('pagesize_def',$options) ? $options['pagesize_def'] : 999;
+
+ if ($search_area)
plc_table_search_area($table_id,$pagesize,$pagesize_def);
- }
plc_table_head($table_id,$headers,$column_sort,$max_pages,$pagesize);
}
-function plc_table_end () {
- plc_table_foot();
+// for convenience, the options that apply to the footer only can be passed in plc_table_end()
+// they add up to the ones provided to the begin clause
+// makes code more readable, as preparing the footer before the table is displayed is confusing
+function plc_table_end ($table_id,$options_end=NULL) {
+ global $plc_table_hash;
+ list($headers,$options) = $plc_table_hash[$table_id];
+ if ($options_end)
+ $options=array_merge($options,$options_end);
+
+ plc_table_foot($options);
+ $notes_area = array_key_exists('notes_area',$options) ? $options['notes_area'] : true;
+ if ($notes_area)
+ plc_table_notes($options);
}
////////////////////
$classname.=" paginate-" . $pagesize;
print <<< EOF
<!-- instantiate paginator callback -->
-<script type"text/javascript">
+<script type="text/javascript">
function $paginator (opts) { plc_table_paginator (opts,"$table_id"); }
</script>
<br/>
EOF;
foreach ($headers as $label => $type) {
- if ($type == "string") $type="";
- if ($type == "int") $type="";
- if ($type == "float") $type="";
- $class="sortable";
- if ( ! empty($type)) $class .= "-" . $type;
- print '<th class="' . $class . ' plc_table">' . $label . "</th>\n";
+ if ($type == "none" ) {
+ $class="";
+ } else {
+ if ($type == "string") $type="";
+ if ($type == "int") $type="";
+ if ($type == "float") $type="";
+ $class="sortable";
+ if ( ! empty($type)) $class .= "-sort" . $type;
+ }
+ printf ('<th class="%s plc_table">%s</th>',$class,$label);
}
print <<< EOF
}
////////////////////////////////////////
-function plc_table_foot () {
- print <<< EOF
-</tbody>
-<tfoot>
-</tfoot>
-</table>
-EOF;
+function plc_table_foot ($options) {
+ print "</tbody><tfoot>";
+ if ($options['footers'])
+ foreach ($options['footers'] as $footer)
+ print "<tr> $footer </tr>";
+ print "</tfoot></table>\n";
}
////////////////////////////////////////
-function plc_table_notes () {
+function plc_table_notes ($options) {
print <<< EOF
<p class='plc_filter_note'>
Notes: Enter & or | in the search area to alternate between <bold>AND</bold> and <bold>OR</bold> search modes
<br/>
Hold down the shift key to select multiple columns to sort
-</p>
EOF;
+ if (array_key_exists('notes',$options)) {
+ foreach ($options['notes'] as $line) {
+ print "<br/>" . $line . "\n";
+ }
+ }
+ print "</p>";
}
+////////////////////////////////////////
+function plc_table_title ($text) {
+ print "<h2> $text </h2>\n";
+}
+
+function plc_table_row_start ($id="") {
+ if ( $id) {
+ printf ('<tr id="%s">',$id);
+ } else {
+ print '<tr>';
+ }
+}
+function plc_table_row_end () {
+ print "</tr>\n";
+}
?>