+ function datepicker($name, $value = null, $past = true, $past_picker = null, $future = true, $future_picker = null) {
+ $id = "datepicker_$name";
+ echo "<script>\n $(function() {\n";
+ echo " $(\"#$id\").datepicker({\n";
+ /*
+ If this is the "to" picker in a date range, restrict the end date of the
+ "from" picker to be the date selected by this picker.
+ */
+ if (isset($past_picker)) {
+ echo " onClose: function(selectedDate) {\n";
+ echo " $(\"#datepicker_$past_picker\").datepicker(\"option\", \"maxDate\", selectedDate);\n";
+ echo " },\n";
+ }
+ /*
+ If this is the "from" picker in a date range, restrict the start date of
+ the "to" picker to be the date selected by this picker.
+ */
+ if (isset($future_picker)) {
+ echo " onClose: function(selectedDate) {\n";
+ echo " $(\"#datepicker_$future_picker\").datepicker(\"option\", \"minDate\", selectedDate);\n";
+ echo " },\n";
+ }
+ echo " changeMonth: true,\n";
+ echo " changeYear: true,\n";
+ echo " dateFormat: 'yy-mm-dd',\n";
+ /* Are we allowed to show dates earlier than today? */
+ if (! $past) echo " minDate: 0,\n";
+ /* Are we allowed to show dates later than today? */
+ if (! $future) echo " maxDate: 0,\n";
+ echo " showButtonPanel: true\n";
+ echo " });\n });</script>";
+ echo "<input name=\"$name\" id=\"$id\"";
+ echo " maxlength=10 size=10";
+ if (isset($value)) echo " value=\"$value\"";
+ else echo " value=\"" . $_POST[$name] . "\"";
+ echo "><em class=\"small\">(Y-m-d)</em>";
+ }
+