get_array
[plewww.git] / plekit / php / details.php
index ccf1c4a..b6e03c4 100644 (file)
@@ -1,7 +1,5 @@
 <?php
 
-// $Id$
-
 require_once 'plc_functions.php';
 require_once 'form.php';
 
@@ -14,7 +12,7 @@ drupal_set_html_head('
 // fieldname=>value
 // and we add in-line editing capabilities
 
-// $editable : if not set, no edition will be allowed in the table 
+// $editable : if not set, no edition will be allowed in the table
 //   this is typically set to false when user does not have write access
 // then each individual th_td provides its form_varname if and only iff edition is desired
 
@@ -24,17 +22,17 @@ drupal_set_html_head('
 // th_th : special cases, display 2 <th>
 // xxx todo : accept optional arguments as an options hash, rather than using the set_ methods which are ugly
 
-class PlcDetails {
-  
+class PlekitDetails {
+
   var $editable;
   var $form;
   // various options for the editing area
-  // set manually 
+  // set manually
   var $width;
   var $height;
   var $input_type;
 
-  function PlcDetails ($editable) {
+  function __construct ($editable) {
     $this->editable=$editable;
     $this->form=NULL;
     $this->width="";
@@ -47,9 +45,9 @@ class PlcDetails {
   // start the details area, with an optional caption
   function start ($caption="") { print $this->start_html("$caption");}
   function start_html ($caption="") {
-    $html="<table class=plc_details><thead>";
-    if ($caption) $html .= "<caption>$caption</caption>";
-    $html .= "</thead><tbody>";
+    $html="<table class='plc_details'>";
+    if ($caption) $html .= "<thead><caption>$caption</caption></thead>";
+    $html .= "<tbody>";
     return $html;
   }
 
@@ -59,10 +57,10 @@ class PlcDetails {
   }
 
   // starts an inner form if the details are editable
-  // accpets same args as PlcForm
-  function form_start ($url,$values,$method="POST") { print $this->form_start_html($url,$values,$method); return $this->form; }
-  function form_start_html ($url,$values,$method="POST") {
-    $this->form = new PlcForm ($url,$values,$method);
+  // accpets same args as PlekitForm
+  function form_start ($url,$values,$options=NULL) { print $this->form_start_html($url,$values,$options); return $this->form; }
+  function form_start_html ($url,$values,$options=NULL) {
+    $this->form = new PlekitForm ($url,$values,$options);
     return $this->form->start_html();
   }
 
@@ -103,7 +101,7 @@ class PlcDetails {
     return $old;
   }
 
-  // give a form_varname if the field can be edited 
+  // give a form_varname if the field can be edited
   function th_td ($title,$value,$form_varname="",$options=NULL) {
     print $this->th_td_html ($title,$value,$form_varname,$options);
   }
@@ -111,11 +109,11 @@ class PlcDetails {
     if (!$options) $options = array();
     if ( ! ($this->editable && $form_varname) ) {
       // xxx hack: if input_type is select, look for the 'value' option to display current value
-      if ($options['input_type'] == "select") 
-       $value=$options['value'];
+      if (get_array($options, 'input_type') == "select")
+             $value=$options['value'];
       return "<tr><th>$title</th><td>$value</td></tr>";
     } else {
-      // use options if provided, otherwise the latest set_ function 
+      // use options if provided, otherwise the latest set_ function
       if (array_key_exists('input_type',$options)) $input_type=$options['input_type'];
       else $input_type=$this->input_type;
       if (array_key_exists('width',$options)) $width=$options['width'];
@@ -124,7 +122,7 @@ class PlcDetails {
       else $height=$this->height;
 
       $html="";
-      $html .= "<tr><th><label for=$form_varname>$title</label></th>";
+      $html .= "<tr><th><label for='$form_varname'>$title</label></th>";
       $html .= "<td>";
       // xxx hack: if input_type is select : user provides the input field verbatim
       if ( $input_type == "select" ) {
@@ -135,11 +133,11 @@ class PlcDetails {
        if ($height) $html .= " rows=$height";
        $html .= ">$value</textarea>";
       } else {
-       // set id too 
+       // set id too
        $html .= "<input type='$input_type' name='$form_varname' id='$form_varname' value='$value'";
-       if ($width) $html .= " size=$width";
+       if ($width) $html .= " size='$width'";
        // handle event callbacks
-       $html .= PlcForm::attributes($options);
+       $html .= PlekitForm::attributes($options);
        $html .= "/>";
       }
       $html .= "</td></tr>";
@@ -153,7 +151,7 @@ class PlcDetails {
     return $this->th_td_html($title,plc_vertical_table($list,"foo"));
   }
 
-  // only for special cases, not editable 
+  // only for special cases, not editable
   function th_th ($th1,$th2) { print $this->th_th_html ($th1, $th2);}
   function th_th_html ($th1, $th2) {
     return "<tr><th>$th1</th><th>$th2</th></tr>";
@@ -162,15 +160,15 @@ class PlcDetails {
   // 1 item, colspan=2
   function tr($title,$align=NULL) { print $this->tr_html($title,$align);}
   function tr_html($title,$align=NULL) {
-    $result="<tr><td colspan=2";
+    $result="<tr><td colspan='2'";
     if ($align) $result .= " style='text-align:$align'";
     $result .=">$title</td></tr>";
     return $result;
   }
-  
+
   // a dummy line for getting some air
   function space () { print $this->space_html(); }
-  function space_html () { return "<tr><td colspan=2>&nbsp;</td></tr>\n"; }
+  function space_html () { return "<tr><td colspan='2'>&nbsp;</td></tr>\n"; }
 
 }