5 require_once 'plc_functions.php';
6 require_once 'form.php';
9 <link href="/plekit/details/details.css" rel="stylesheet" type="text/css" />
13 // the basic idea is to define an area for displaying details like
15 // and we add in-line editing capabilities
17 // $editable : if not set, no edition will be allowed in the table
18 // this is typically set to false when user does not have write access
19 // then each individual th_td provides its form_varname if and only iff edition is desired
21 // start & end :create and close a 2-columns table
22 // th_td -> display label & value, with optional inline editing capability
23 // th_tds -> not editable, display a (vertical) list of values in the <td> area
24 // th_th : special cases, display 2 <th>
25 // xxx todo : accept optional arguments as an options hash, rather than using the set_ methods which are ugly
31 // various options for the editing area
37 function PlekitDetails ($editable) {
38 $this->editable=$editable;
42 $this->input_type="text";
45 function form() { return $this->form; }
47 // start the details area, with an optional caption
48 function start ($caption="") { print $this->start_html("$caption");}
49 function start_html ($caption="") {
50 $html="<table class='plc_details'>";
51 if ($caption) $html .= "<thead><caption>$caption</caption></thead>";
56 function end() { print $this->end_html(); }
57 function end_html () {
58 return "</tbody></table>\n";
61 // starts an inner form if the details are editable
62 // accpets same args as PlekitForm
63 function form_start ($url,$values,$options=NULL) { print $this->form_start_html($url,$values,$options); return $this->form; }
64 function form_start_html ($url,$values,$options=NULL) {
65 $this->form = new PlekitForm ($url,$values,$options);
66 return $this->form->start_html();
69 function form_end () { print $this->form_end_html(); }
70 function form_end_html () {
71 if ( ! $this->form) return "";
72 $html = $this->form->end_html();
77 //////////////////// several forms for submit button
78 // xxx need a way to ask for confirmation
80 // must be embedded in a th_td or a tr
81 function submit_html ($name,$display) {
82 if ( ! $this->form) return "";
83 if ( ! $this->editable) return "";
84 return $this->form->submit_html($name,$display);
86 function tr_submit_html ($name,$display) {
87 if ( ! $this->form) return "";
88 if ( ! $this->editable) return "";
89 return $this->tr_html($this->form->submit_html($name,$display),"right");
91 function tr_submit ($name,$display) { print $this->tr_submit_html ($name,$display); }
94 ////////////////////////////////////////
95 function set_width ($width) {
100 function set_height ($height) {
102 $this->height=$height;
106 // give a form_varname if the field can be edited
107 function th_td ($title,$value,$form_varname="",$options=NULL) {
108 print $this->th_td_html ($title,$value,$form_varname,$options);
110 function th_td_html ($title,$value,$form_varname="",$options=NULL) {
111 if (!$options) $options = array();
112 if ( ! ($this->editable && $form_varname) ) {
113 // xxx hack: if input_type is select, look for the 'value' option to display current value
114 if ($options['input_type'] == "select")
115 $value=$options['value'];
116 return "<tr><th>$title</th><td>$value</td></tr>";
118 // use options if provided, otherwise the latest set_ function
119 if (array_key_exists('input_type',$options)) $input_type=$options['input_type'];
120 else $input_type=$this->input_type;
121 if (array_key_exists('width',$options)) $width=$options['width'];
122 else $width=$this->width;
123 if (array_key_exists('height',$options)) $height=$options['height'];
124 else $height=$this->height;
127 $html .= "<tr><th><label for='$form_varname'>$title</label></th>";
129 // xxx hack: if input_type is select : user provides the input field verbatim
130 if ( $input_type == "select" ) {
132 } else if ($input_type == "textarea") {
133 $html .= "<textarea name='$form_varname'";
134 if ($width) $html .= " cols=$width";
135 if ($height) $html .= " rows=$height";
136 $html .= ">$value</textarea>";
139 $html .= "<input type='$input_type' name='$form_varname' id='$form_varname' value='$value'";
140 if ($width) $html .= " size='$width'";
141 // handle event callbacks
142 $html .= PlekitForm::attributes($options);
145 $html .= "</td></tr>";
150 // same but the values are multiple and displayed in an embedded vertical table (not editable)
151 function th_tds($title,$list) { print $this->th_tds_html($title,$list); }
152 function th_tds_html($title,$list) {
153 return $this->th_td_html($title,plc_vertical_table($list,"foo"));
156 // only for special cases, not editable
157 function th_th ($th1,$th2) { print $this->th_th_html ($th1, $th2);}
158 function th_th_html ($th1, $th2) {
159 return "<tr><th>$th1</th><th>$th2</th></tr>";
163 function tr($title,$align=NULL) { print $this->tr_html($title,$align);}
164 function tr_html($title,$align=NULL) {
165 $result="<tr><td colspan='2'";
166 if ($align) $result .= " style='text-align:$align'";
167 $result .=">$title</td></tr>";
171 // a dummy line for getting some air
172 function space () { print $this->space_html(); }
173 function space_html () { return "<tr><td colspan='2'> </td></tr>\n"; }