constructors are named __construct for php8
[plewww.git] / plekit / php / table.php
index bb63155..2e75dac 100644 (file)
@@ -7,6 +7,7 @@ require_once 'prototype.php';
 drupal_set_html_head('
 <script type="text/javascript" src="/plekit/tablesort/tablesort.js"></script>
 <script type="text/javascript" src="/plekit/tablesort/customsort.js"></script>
+<script type="text/javascript" src="/plekit/tablesort/plc_customsort.js"></script>
 <script type="text/javascript" src="/plekit/tablesort/paginate.js"></script>
 <script type="text/javascript" src="/plekit/table/table.js"></script>
 <link href="/plekit/table/table.css" rel="stylesheet" type="text/css" />
@@ -14,7 +15,14 @@ drupal_set_html_head('
 
 ////////////////////////////////////////
 // table_id: <table>'s id tag - WARNING : do not use '-' in table ids as it's used for generating javascript code
-// headers: an associative array "label"=>"type" 
+// headers: an associative array; the values can take several forms
+//      simple/legacy form is "label"=>"type" 
+//      more advanced form is "label"=>options, it self a dict with the following known keys
+//         (*) 'type': the type for sorting; this is passed to the javascript layer for custom sorting
+//             default is to use 'text', custom sort functions can be specified with e.g. 'type'=>'sortAlphaNumericBottom'
+//             a special case is for type to be 'date-format' like e.g. 'type'=>'date-dmy'
+//             setting type to 'none' gives an non-sortable column
+//        (*) 'title': if set, this is used in the "Sort on ``<title>''" bubble
 // sort_column: the column to sort on at load-time - set to negative number for no onload- sorting
 // options : an associative array to override options 
 //  - bullets1 : set to true if you want decorative bullets in column 1 (need white background)
@@ -52,7 +60,7 @@ class PlekitTable {
   // internal
   var $has_tfoot;
 
-  function PlekitTable ($table_id,$headers,$sort_column,$options=NULL) {
+  function __construct ($table_id,$headers,$sort_column,$options=NULL) {
     $this->table_id = $table_id;
     $this->headers = $headers;
     $this->sort_column = $sort_column;
@@ -65,7 +73,7 @@ class PlekitTable {
     $this->notes_area = true;
     $this->search_width = 40;
     $this->pagesize = 25;
-    $this->pagesize_def = 999;
+    $this->pagesize_def = 9999;
     $this->max_pages = 10;
     $this->notes = array();
     $this->debug = false;
@@ -130,7 +138,16 @@ class PlekitTable {
     if ($this->caption) 
       print "<caption> $this->caption </caption>";
     print "<tr>";
-    foreach ($this->headers as $label => $type) {
+    foreach ($this->headers as $label => $colspec) {
+      // which form is being used
+      if (is_array($colspec)) {
+       $type=$colspec['type'];
+       $title=ucfirst($colspec['title']);
+      } else {
+       // simple/legacy form
+       $type=$colspec;
+       $title=NULL;
+      }
       switch ($type) {
       case "none" : 
        $class=""; break;
@@ -141,7 +158,8 @@ class PlekitTable {
       default:
        $class="sortable-sort" . $type; break;
       }
-      printf ('<th class="%s plekit_table">%s</th>',$class,$label);
+      $title_part=$title ? "title=\"$title\"" : "";
+      print ("<th class=\"$class plekit_table\" $title_part>$label</th>\n");
     }
 
     print "</tr></thead><tbody>";
@@ -167,7 +185,7 @@ class PlekitTable {
 <form class='pagesize' action='satisfy_xhtml_validator'><fieldset>
    <input class='pagesize_input' type='text' id="$pagesize_text_id" value='$this->pagesize'
       onkeyup='plekit_pagesize_set("$this->table_id","$pagesize_text_id", $this->pagesize);' 
-      size='3' maxlength='3' /> 
+      size='3' maxlength='4' /> 
   <label class='pagesize_label'> items/page </label>   
   <img class='reset' src="/planetlab/icons/clear.png" alt="reset visible size"
       onmousedown='plekit_pagesize_reset("$this->table_id","$pagesize_text_id",$this->pagesize_def);' />
@@ -220,15 +238,18 @@ EOF;
 
   ////////////////////////////////////////
   function notes_area_html () {
-    $default_notes =  array(
-       "Enter &amp; or | in the search area to switch between <span class='bold'>AND</span> and <span class='bold'>OR</span> search modes",
-       "Hold down the shift key to select multiple columns to sort");
+    $search_notes =  
+      array("Enter &amp; or | in the search area to switch between <span class='bold'>AND</span> and <span class='bold'>OR</span> search modes");
+    $sort_notes = 
+      array ("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);
+    $notes=array_merge($notes,$sort_notes);
+    if ($this->search_area)
+      $notes=array_merge($notes,$search_notes);
     if (! $notes)
       return "";
     $result = "";