Added contact offers.
[readifood.git] / lib / forms.php
1 <?php
2
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'];
7     echo "<form ";
8     if (count($classes)) printf("class=\"%s\" ", implode(" ", $classes));
9     echo "method=\"POST\" action=\"$action\">\n";
10   }
11
12   function end_form() {
13     echo "</form>\n";
14   }
15
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] . "\"";
21     echo ">";
22   }
23
24   function hidden($name, $value = null) {
25     return input($name, $value, "hidden");
26   }
27
28   function submit($name, $value = null) {
29     return input($name, $value, "submit");
30   }
31
32   function textarea($name, $value = null) {
33     $id = "textarea_$name";
34     echo "<textarea id=\"$id\" name=\"$name\" cols=30>";
35     if (isset($value)) echo $value;
36     else echo $_POST[$name];
37     echo "</textarea>";
38     echo "<script>\n  $(function() {\n";
39     echo "    autosize($(\"#$id\"));\n";
40     echo "  });</script>";
41   }
42
43   function option($select, $value, $text, $selected = null) {
44     echo "  <option value=\"$value\"";
45     if (! isset($selected)) $selected = $_POST[$select];
46     if (! isset($selected)) $selected = get_last_selected($select);
47     if ($value == $selected) echo " selected";
48     echo ">$text\n";
49   }
50
51   function datepicker($name, $value = null, $past = true, $past_picker = null, $future = true, $future_picker = null) {
52     $id = "datepicker_$name";
53     echo "<script>\n  $(function() {\n";
54     echo "    $(\"#$id\").datepicker({\n";
55     /*
56       If this is the "to" picker in a date range, restrict the end date of the
57       "from" picker to be the date selected by this picker.
58     */
59     if (isset($past_picker)) {
60       echo "      onClose: function(selectedDate) {\n";
61       echo "        $(\"#datepicker_$past_picker\").datepicker(\"option\", \"maxDate\", selectedDate);\n";
62       echo "      },\n";
63     }
64     /*
65       If this is the "from" picker in a date range, restrict the start date of
66       the "to" picker to be the date selected by this picker.
67     */
68     if (isset($future_picker)) {
69       echo "      onClose: function(selectedDate) {\n";
70       echo "        $(\"#datepicker_$future_picker\").datepicker(\"option\", \"minDate\", selectedDate);\n";
71       echo "      },\n";
72     }
73     echo "      changeMonth: true,\n";
74     echo "      changeYear: true,\n";
75     echo "      dateFormat: 'yy-mm-dd',\n";
76     /* Are we allowed to show dates earlier than today? */
77     if (! $past) echo "      minDate: 0,\n";
78     /* Are we allowed to show dates later than today? */
79     if (! $future) echo "      maxDate: 0,\n";
80     echo "      showButtonPanel: true\n";
81     echo "    });\n  });</script>";
82     echo "<input name=\"$name\" id=\"$id\"";
83     echo " maxlength=10 size=10";
84     if (isset($value)) echo " value=\"$value\"";
85     else echo " value=\"" . $_POST[$name] . "\"";
86     echo "><em class=\"small\">(Y-m-d)</em>";
87   }
88
89 ?>