3 require_once 'plc_functions.php';
4 require_once 'form.php';
7 <link href="/plekit/details/details.css" rel="stylesheet" type="text/css" />
11 // the basic idea is to define an area for displaying details like
13 // and we add in-line editing capabilities
15 // $editable : if not set, no edition will be allowed in the table
16 // this is typically set to false when user does not have write access
17 // then each individual th_td provides its form_varname if and only iff edition is desired
19 // start & end :create and close a 2-columns table
20 // th_td -> display label & value, with optional inline editing capability
21 // th_tds -> not editable, display a (vertical) list of values in the <td> area
22 // th_th : special cases, display 2 <th>
23 // xxx todo : accept optional arguments as an options hash, rather than using the set_ methods which are ugly
29 // various options for the editing area
35 function __construct ($editable) {
36 $this->editable=$editable;
40 $this->input_type="text";
43 function form() { return $this->form; }
45 // start the details area, with an optional caption
46 function start ($caption="") { print $this->start_html("$caption");}
47 function start_html ($caption="") {
48 $html="<table class='plc_details'>";
49 if ($caption) $html .= "<thead><caption>$caption</caption></thead>";
54 function end() { print $this->end_html(); }
55 function end_html () {
56 return "</tbody></table>\n";
59 // starts an inner form if the details are editable
60 // accpets same args as PlekitForm
61 function form_start ($url,$values,$options=NULL) { print $this->form_start_html($url,$values,$options); return $this->form; }
62 function form_start_html ($url,$values,$options=NULL) {
63 $this->form = new PlekitForm ($url,$values,$options);
64 return $this->form->start_html();
67 function form_end () { print $this->form_end_html(); }
68 function form_end_html () {
69 if ( ! $this->form) return "";
70 $html = $this->form->end_html();
75 //////////////////// several forms for submit button
76 // xxx need a way to ask for confirmation
78 // must be embedded in a th_td or a tr
79 function submit_html ($name,$display) {
80 if ( ! $this->form) return "";
81 if ( ! $this->editable) return "";
82 return $this->form->submit_html($name,$display);
84 function tr_submit_html ($name,$display) {
85 if ( ! $this->form) return "";
86 if ( ! $this->editable) return "";
87 return $this->tr_html($this->form->submit_html($name,$display),"right");
89 function tr_submit ($name,$display) { print $this->tr_submit_html ($name,$display); }
92 ////////////////////////////////////////
93 function set_width ($width) {
98 function set_height ($height) {
100 $this->height=$height;
104 // give a form_varname if the field can be edited
105 function th_td ($title,$value,$form_varname="",$options=NULL) {
106 print $this->th_td_html ($title,$value,$form_varname,$options);
108 function th_td_html ($title,$value,$form_varname="",$options=NULL) {
109 if (!$options) $options = array();
110 if ( ! ($this->editable && $form_varname) ) {
111 // xxx hack: if input_type is select, look for the 'value' option to display current value
112 if ($options['input_type'] == "select")
113 $value=$options['value'];
114 return "<tr><th>$title</th><td>$value</td></tr>";
116 // use options if provided, otherwise the latest set_ function
117 if (array_key_exists('input_type',$options)) $input_type=$options['input_type'];
118 else $input_type=$this->input_type;
119 if (array_key_exists('width',$options)) $width=$options['width'];
120 else $width=$this->width;
121 if (array_key_exists('height',$options)) $height=$options['height'];
122 else $height=$this->height;
125 $html .= "<tr><th><label for='$form_varname'>$title</label></th>";
127 // xxx hack: if input_type is select : user provides the input field verbatim
128 if ( $input_type == "select" ) {
130 } else if ($input_type == "textarea") {
131 $html .= "<textarea name='$form_varname'";
132 if ($width) $html .= " cols=$width";
133 if ($height) $html .= " rows=$height";
134 $html .= ">$value</textarea>";
137 $html .= "<input type='$input_type' name='$form_varname' id='$form_varname' value='$value'";
138 if ($width) $html .= " size='$width'";
139 // handle event callbacks
140 $html .= PlekitForm::attributes($options);
143 $html .= "</td></tr>";
148 // same but the values are multiple and displayed in an embedded vertical table (not editable)
149 function th_tds($title,$list) { print $this->th_tds_html($title,$list); }
150 function th_tds_html($title,$list) {
151 return $this->th_td_html($title,plc_vertical_table($list,"foo"));
154 // only for special cases, not editable
155 function th_th ($th1,$th2) { print $this->th_th_html ($th1, $th2);}
156 function th_th_html ($th1, $th2) {
157 return "<tr><th>$th1</th><th>$th2</th></tr>";
161 function tr($title,$align=NULL) { print $this->tr_html($title,$align);}
162 function tr_html($title,$align=NULL) {
163 $result="<tr><td colspan='2'";
164 if ($align) $result .= " style='text-align:$align'";
165 $result .=">$title</td></tr>";
169 // a dummy line for getting some air
170 function space () { print $this->space_html(); }
171 function space_html () { return "<tr><td colspan='2'> </td></tr>\n"; }