5 require_once 'plc_functions.php';
7 // the rationale behind having function names with _html is that
8 // the first functions that we had were actually printing the stuff instead of returning it
9 // so basically the foo (...) function should just do ``print (foo_html(...))''
14 var $values; // a hash var=>value - default is empty array
15 var $method; // default is POST
17 function PlcForm ($full_url, $values, $method="POST") {
18 // so we can use the various l_* functions:
19 // we parse the url to extract var-values pairs,
20 // and add them to the 'values' argument if any
22 // extract var=value settings from url if any
23 $split=split_url($full_url);
24 $this->url=$split['url'];
26 $url_values=$split['values'];
27 if ( ! $values ) $values = array();
28 if ( $url_values ) $values=array_merge($values,$url_values);
29 $this->values=$values;
31 $this->method=$method;
34 function start () { print $this->start_html(); }
35 function start_html () {
36 $html="<form method=$this->method action='$this->url' enctype='multipart/form-data'>";
38 foreach ($this->values as $key=>$value)
39 $html .= $this->hidden_html($key,$value);
43 function end() { print $this->end_html(); }
44 function end_html() { return "</form>"; }
46 static function hidden_html ($key,$value) {
47 return "<input type=hidden name='$key' value='$value'/>";
49 static function checkbox_html ($name,$value,$selected=false) {
50 if ($selected) $xtra=" selected=selected";
51 return "<input type=checkbox name='$name' value='$value'$xtra/>";
53 static function submit_html ($name,$display) {
54 return "<input type=submit name='$name' value='$display'/>";
56 static function file_html ($name,$size) {
57 return "<input type=file name='$name' size=$size/>";
59 static function label_html ($name,$display) {
60 return "<label for=$name>$display </label>";
62 static function text_html ($name,$value,$size) {
63 return "<input type=text name='$name' size=$size value='$value'>";
65 static function textarea_html ($name,$value,$cols,$rows) {
66 return "<textarea name='$name' cols=$cols rows=$rows>$value</textarea>";
69 // selectors is an array of hashes with the following keys
71 // (*) value : the value that the 'name' variable will be assigned
72 // (*) optional 'selected': the entry selected initially
73 // (*) optional 'disabled': the entry is displayed but not selectable
74 // optional label is inserted as the first option, with no value attached
75 // autosubmit: onchange=submit()
76 static function select_html ($name,$selectors,$label=NULL,$autosubmit=false) {
78 $html.="<select name='$name'";
79 if ($autosubmit) $html .= " onChange='submit();'";
82 $encoded=htmlentities($label,ENT_QUOTES);
83 $html.="<option selected=selected value=''>$encoded</option>";
85 foreach ($selectors as $selector) {
86 $display=htmlentities($selector['display'],ENT_QUOTES);
87 $value=$selector['value'];
88 $html .= "<option value='$value'";
89 if ($selector['selected']) $html .= " selected=selected";
90 if ($selector['disabled']) $html .= " disabled=disabled";
91 $html .= ">$display</option>\n";
98 // a form with a single button
99 class PlcFormButton extends PlcForm {
104 function PlcFormButton ($full_url, $button_id, $button_text, $method="POST") {
105 $this->PlcForm($full_url,array(),$method);
106 $this->button_id=$button_id;
107 $this->button_text=$button_text;
112 $this->start_html() .
113 $this->submit_html($this->button_id,$this->button_text).