details can be updated inline - old forms still to be cleaned up
[plewww.git] / planetlab / includes / plc_tables.php
index d565ee8..3a15e0f 100644 (file)
@@ -21,7 +21,6 @@ drupal_set_html_head('
 //  - 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: an array of table rows (<tr> will be added) for building the table's tfoot area
 
 class PlcTable {
   // mandatory
@@ -37,12 +36,14 @@ class PlcTable {
   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 $footers;       // an array of table rows (<tr> will be added) for building the table's tfoot area
+  var $has_tfoot;
 
   function PlcTable ($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;
@@ -52,7 +53,6 @@ class PlcTable {
     $this->pagesize_def = 999;
     $this->max_pages = 10;
     $this->notes = array();
-    $this->footers = array();
 
     $this->set_options ($options);
   }
@@ -69,7 +69,10 @@ class PlcTable {
     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']);
-    if (array_key_exists('footers',$options)) $this->footers=array_merge($this->footers,$options['footers']);
+  }
+
+  public function columns () {
+    return count ($this->headers);
   }
 
   ////////////////////
@@ -90,9 +93,9 @@ class="plc_table sortable-onload-$this->column_sort rowstyle-alt colstyle-alt no
 EOF;
 
   if ($this->pagesize_area)
-    print $this->pagesize_area_text ();
+    print $this->pagesize_area_html ();
   if ($this->search_area) 
-    print $this->search_area_text ();
+    print $this->search_area_html ();
 
   print "<tr>";
   foreach ($this->headers as $label => $type) {
@@ -116,18 +119,18 @@ EOF;
 }
 
   ////////////////////
-  // for convenience, the options that apply to the footer can be passed here
-  // typically footers or notes will add up to the ones provided so far
-  // makes code more readable, as preparing the footer before the table is displayed is confusing
+  // 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->foot_text();
+    print $this->bottom_html();
     if ($this->notes_area) 
-      print $this->notes_area_text();
+      print $this->notes_area_html();
   }
                    
   ////////////////////
-  function pagesize_area_text () {
+  function pagesize_area_html () {
     $width=count($this->headers);
     $pagesize_text_id = $this->table_id . "_pagesize";
     $result= <<< EOF
@@ -144,7 +147,7 @@ EOF;
 }
 
   ////////////////////
-  function search_area_text () {
+  function search_area_html () {
     $width=count($this->headers);
     $search_text_id = $this->table_id . "_search";
     $search_reset_id = $this->table_id . "_search_reset";
@@ -166,19 +169,26 @@ EOF;
     return $result;
   }
 
+  //////////////////// start a <tfoot> section
+  function tfoot_start () { print $this->tfoot_start_html(); }
+  function tfoot_start_html () {
+    $this->has_tfoot=true;
+    return "</tbody><tfoot>";
+  }
+
   ////////////////////////////////////////
-  function foot_text () {
+  function bottom_html () {
     $result="";
-    $result .= "</tbody><tfoot>\n";
-    if ($this->footers) 
-      foreach ($this->footers as $footer) 
-       $result .="<tr>$footer</tr>\n";
-    $result .= "</tfoot></table>\n";
+    if ($this->has_tfoot)
+      $result .= "</tfoot>";
+    else
+      $result .= "</tbody>";
+    $result .= "</table>\n";
     return $result;
   }
 
   ////////////////////////////////////////
-  function notes_area_text () {
+  function notes_area_html () {
     $default_notes =  array(
        "Enter & or | in the search area to alternate between <bold>AND</bold> and <bold>OR</bold> search modes",
        "Hold down the shift key to select multiple columns to sort");
@@ -211,14 +221,8 @@ EOF;
   }
 
   ////////////////////
-  public function cell_text ($cell) {
-    return "<td>$cell</td>";
-  }
-  public function cell ($cell) {
-    print $this->cell_text($cell);
-  }
-  
-  public static function td_text ($text,$colspan=0,$align=NULL) {
+  public function cell ($text,$colspan=0,$align=NULL) { print $this->cell_html ($text,$colspan,$align); }
+  public function cell_html ($text,$colspan=0,$align=NULL) {
     $result="";
     $result .= "<td";
     if ($colspan) $result .= " colspan=$colspan";