3 function form($classes = null, $action = null) {
4 if (is_null($classes)) $classes = array();
5 else if (! is_array($classes)) $classes = explode('/\s+/', $classes);
6 if (! isset($action)) $action = $_SERVER['REQUEST_URI'];
8 if (count($classes)) printf("class=\"%s\" ", implode(" ", $classes));
9 echo "method=\"POST\" action=\"$action\">\n";
16 function input($name, $value = null, $type = null) {
17 echo "<input name=\"$name\"";
18 if (isset($type)) echo " type=\"$type\"";
19 if (isset($value)) echo " value=\"$value\"";
20 else echo " value=\"" . $_POST[$name] . "\"";
24 function hidden($name, $value = null) {
25 return input($name, $value, "hidden");
28 function submit($name, $value = null) {
29 return input($name, $value, "submit");
32 function textarea($name, $value = null) {
33 echo "<textarea name=\"$name\">";
34 if (isset($value)) echo $value;
35 else echo $_POST[$name];
39 function option($select, $value, $text, $selected = null) {
40 echo " <option value=\"$value\"";
41 if (! isset($selected)) $selected = $_POST[$select];
42 if ($value == $selected) echo " selected";
46 function datepicker($name, $value = null, $past = true, $past_picker = null, $future = true, $future_picker = null) {
47 $id = "datepicker_$name";
48 echo "<script>\n $(function() {\n";
49 echo " $(\"#$id\").datepicker({\n";
51 If this is the "to" picker in a date range, restrict the end date of the
52 "from" picker to be the date selected by this picker.
54 if (isset($past_picker)) {
55 echo " onClose: function(selectedDate) {\n";
56 echo " $(\"#datepicker_$past_picker\").datepicker(\"option\", \"maxDate\", selectedDate);\n";
60 If this is the "from" picker in a date range, restrict the start date of
61 the "to" picker to be the date selected by this picker.
63 if (isset($future_picker)) {
64 echo " onClose: function(selectedDate) {\n";
65 echo " $(\"#datepicker_$future_picker\").datepicker(\"option\", \"minDate\", selectedDate);\n";
68 echo " changeMonth: true,\n";
69 echo " changeYear: true,\n";
70 echo " dateFormat: 'yy-mm-dd',\n";
71 /* Are we allowed to show dates earlier than today? */
72 if (! $past) echo " minDate: 0,\n";
73 /* Are we allowed to show dates later than today? */
74 if (! $future) echo " maxDate: 0,\n";
75 echo " showButtonPanel: true\n";
76 echo " });\n });</script>";
77 echo "<input name=\"$name\" id=\"$id\"";
78 echo " maxlength=10 size=10";
79 if (isset($value)) echo " value=\"$value\"";
80 else echo " value=\"" . $_POST[$name] . "\"";
81 echo "><em class=\"small\">(Y-m-d)</em>";