Show dates in the past.
[readifood.git] / lib / functions.php
index 3727a65..801ed78 100644 (file)
     return get_area_city($area);
   }
 
+  /* Parcel strings are the same so this can work. */
+  function get_contact_parcel_string($contact) {
+    return get_order_parcel_string($contact);
+  }
+
   /* Hub and Contact are similar enough that this can work. */
   function get_hub_address($hub) {
     return get_contact_address($hub);
   }
 
   function show_date_form($name, $date = null) {
+    $past = 60;
+    $future = 60;
     echo "<select name=\"$name\">\n";
-    $now = time();
+    $now = date('Y-m-d', time());
+    list($y, $m, $d) = explode('-', $now);
+    $today = mktime(0, 0, 0, $m, $d, $y);
     if (isset($date)) {
       list($y, $m, $d) = explode('-', $date);
       $then = mktime(0, 0, 0, $m, $d, $y);
-      option($name, $date, date('l j F Y', $then), $date);
+      if ($then < $today - 86400 * $past || $then > $today + 86400 * $future) {
+        option($name, $date, date('l j F Y', $then), $date);
+      }
     }
-    for ($i = 0; $i < 60; $i++) {
-      $then = $now + 86400 * $i;
+    else $date = $now;
+    for ($i = -$past; $i < $future; $i++) {
+      $then = $today + 86400 * $i;
       option($name, date('Y-m-d', $then), date('l j F Y', $then), $date);
     }
     echo "</select>\n";