Allow reordering the delivery list.
[readifood.git] / lib / area.php
index 51f57d3..9b0d5e1 100644 (file)
       return;
     }
 
+    $candidates = array();
+    foreach ($cities as $city) {
+      if (! count(get_city_areas($city->getId()))) continue;
+      $candidates[] = $city;
+    }
+    if (! count($candidates)) return;
+
     form("noprint standout");
     echo "<p>Show areas in\n";
     echo "<select name=\"city_id\">\n";
-    foreach ($cities as $city) {
+    foreach ($candidates as $city) {
       option("city_id", sprintf("%s/%s", $city->getName(), $city->getId()), get_city_displayname($city));
     }
     echo "</select>\n";
     return $area->getId();
   }
 
-  function delete_city($name) {
-    if (! check_admin(1, "delete a city")) return;
-
-    $city = get_city_by_name($name);
-    if (! $city) return false;
-
-    try {
-      $city->delete();
-    }
-    catch (Exception $e) {
-      echo "<p>Error deleting $name!</p>\n";
-      /* XXX: Why? Check for addresses in use... */
-      return false;
-    }
-
-    return true;
-  }
-
   function show_area_delivery_days_form($days) {
     global $week;
     echo "Delivery days:";
     if (check_admin(1)) {
       for ($i = 0; $i < count($week); $i++) {
-        echo " <input type=\"checkbox\" name=\"day_$i\"";
+        echo " <input type=\"checkbox\" id=\"day_$i\" name=\"day_$i\"";
         if ($days & (1 << $i)) echo " checked";
-        echo ">$week[$i]\n";
+        echo "><label for=\"day_$i\">$week[$i]</label>\n";
       }
     }
     else {
     return true;
   }
 
+  function confirm_delete_area($name, $id = null, &$city_id = null) {
+    if (! check_admin(1, "delete an area")) return;
+
+    if (isset($id)) $area = get_area_by_id($id);
+    else $area = get_area_by_name($name);
+    if (! $area) return false;
+
+    echo "<h3>Confirm deletion</h3>\n";
+    echo "<p>You must confirm deletion of area " . $area->getName() . ": " . $area->getDeleteLink(true) . "</p>\n";
+  }
+
   function delete_area($name, $id = null, &$city_id = null) {
-    if (! check_admin(1, "delete a area")) return;
+    if (! check_admin(1, "delete an area")) return;
 
     if (isset($id)) $area = get_area_by_id($id);
     else $area = get_area_by_name($name);
   if (count($args)) {
     switch ($args[0]) {
       case "delete":
+        confirm_delete_area($name, $id, $city_id);
+      break;
+
+      case "confirmdelete":
         delete_area($name, $id, $city_id);
       break;
     }