Merge branch 'master' into uat
[readifood.git] / lib / order.php
index 2eae9e0..7c68455 100644 (file)
       return;
     }
 
+    $candidates = array();
+    foreach ($areas as $area) {
+      if (! count(get_area_contacts($area->getId()))) continue;
+      $candidates[] = $area;
+    }
+    if (! count($candidates)) return;
+
     echo "<p>Show orders in area\n";
     echo "<select name=\"area_id\">\n";
-    foreach ($areas as $area) {
+    foreach ($candidates as $area) {
       option("area_id", $area->getId(), get_area_displayname($area));
     }
     echo "</select>\n";
       return;
     }
 
+    $candidates = array();
+    foreach ($cities as $city) {
+      if (! count(get_city_contacts($city->getId()))) continue;
+      $candidates[] = $city;
+    }
+    if (! count($candidates)) return;
+
     echo "<p>Show orders in city\n";
     echo "<select name=\"city_id\">\n";
-    foreach ($cities as $city) {
+    foreach ($candidates as $city) {
       option("city_id", $city->getId(), get_city_displayname($city), $city_id);
     }
     echo "</select>\n";
       echo "  <td>State</td>\n";
       echo "  <td><select name=\"state\">\n";
       for ($i = 0; $i < count($states); $i++) {
-        option("state", $i << 1, ucfirst($states[$i]), $state);
+        option("state", 1 << $i, ucfirst($states[$i]), $state);
       }
       echo "</select></td>\n";
       echo "</tr>\n";
     return $order->getId();
   }
 
+  function confirm_delete_order($id = null) {
+    if (! check_admin(1, "delete an order")) return;
+
+    if (isset($id)) $order = get_order_by_id($id);
+    if (! $order) return false;
+
+    echo "<h3>Confirm deletion</h3>\n";
+    echo "<p>You must confirm deletion of order $id: " . $order->getDeleteLink(true) . "</p>\n";
+  }
+
   function delete_order($id = null) {
     if (! check_admin(1, "delete an order")) return;
 
   if (count($args)) {
     switch ($args[0]) {
       case "delete":
+        confirm_delete_order($id);
+      break;
+
+      case "confirmdelete":
         delete_order($id);
       break;
     }