Added contact offers.
[readifood.git] / lib / city.php
index d4a4a6f..94c556e 100644 (file)
     }
   }
 
-  function show_cities($offset, $per_page, $name = null) {
+  function show_cities($name = null) {
+    list($first_page, $per_page) = pagination();
     echo "<p>Cities:";
     $q = new CityQuery;
     if (isset($name)) $q->filterByName($name);
-    $p = $q->paginate($offset, $per_page);
-    if (count($p)) {
-      foreach ($p as $city) {
+    $cities = $q->paginate($first_page, $per_page);
+    if (count($cities)) {
+      foreach ($cities as $city) {
         echo "<br>\nCity: " . $city->getStrongLink(get_city_displayname($city));
-        printf(" <a class=\"small\" href=\"/area/in/%s/%d\">Areas</a>", urlencode($city->getName()), $city->getID());
-        printf(" <a class=\"small\" href=\"/contact/in/city/%s/%d\">Contacts</a>", urlencode($city->getName()), $city->getId());
-        printf(" <a class=\"small\" href=\"/donation/in/city/%s/%d\">Donations</a>", urlencode($city->getName()), $city->getId());
-        printf(" <a class=\"small\" href=\"/order/in/city/%s/%d\">Orders</a>", urlencode($city->getName()), $city->getId());
+        $n = $city->getName();
+        $i = $city->getId();
+        echo " " . get_small_link("Areas", "/area/in/city/%s/%d", $n, $i);
+        echo " " . get_small_link("Contacts", "/contact/in/city/%s/%d", $n, $i);
+        echo " " . get_small_link("Donations", "/donation/in/city/%s/%d", $n, $i);
+        echo " " . get_small_link("Orders", "/order/in/city/%s/%d", $n, $i);
         if (check_admin(1)) {
           echo " " . $city->getDeleteLink();
         }
       }
+      show_pagination($cities);
     }
     else echo " none";
     echo "</p>\n";
@@ -34,7 +38,7 @@
   function show_new_city_form() {
     if (! check_admin(1)) return;
 
-    echo "<form method=\"POST\" action=\"" . $_SERVER['REQUEST_URI'] . "\">\n";
+    form("noprint standout");
     echo "<p>Add a new city <input name=\"city_name\">\n";
     echo "with postcode prefix <input name=\"city_postcode_area\" size=4 maxlength=4>\n";
     echo "<input type=\"submit\" value=\"Add\"></p>\n";
     return $city->getId();
   }
 
+  function confirm_delete_city($name, $id = null) {
+    if (! check_admin(1, "delete a city")) return;
+
+    if (isset($id)) $city = get_city_by_id($id);
+    else $city = get_city_by_name($name);
+    if (! $city) return false;
+
+    echo "<h3>Confirm deletion</h3>\n";
+    echo "<p>You must confirm deletion of city " . $city->getName() . ": " . $city->getDeleteLink(true) . "</p>\n";
+  }
+
   function delete_city($name, $id = null) {
     if (! check_admin(1, "delete a city")) return;
 
     if (! $city) return;
 
     echo "<p>City: <span class=\"strong\">" . get_city_displayname($city) . "</span>";
-    printf(" <a class=\"small\" href=\"/area/in/city/%s/%d\">Areas</a>", urlencode($city->getName()), $city->getID());
-    printf(" <a class=\"small\" href=\"/contact/in/city/%s/%d\">Contacts</a>", urlencode($city->getName()), $city->getId());
-    printf(" <a class=\"small\" href=\"/donation/in/city/%s/%d\">Donations</a>", urlencode($city->getName()), $city->getId());
-    printf(" <a class=\"small\" href=\"/order/in/city/%s/%d\">Orders</a>", urlencode($city->getName()), $city->getId());
+    $n = $city->getName();
+    $i = $city->getId();
+    echo " " . get_small_link("Areas", "/area/in/city/%s/%d", $n, $i);
+    echo " " . get_small_link("Contacts", "/contact/in/city/%s/%d", $n, $i);
+    echo " " . get_small_link("Donations", "/donation/in/city/%s/%d", $n, $i);
+    echo " " . get_small_link("Orders", "/order/in/city/%s/%d", $n, $i);
     if (check_admin(1)) {
       echo " " . $city->getDeleteLink();
     }
   if (count($args)) {
     switch ($args[0]) {
       case "delete":
+        confirm_delete_city($name, $id);
+      break;
+
+      case "confirmdelete":
         delete_city($name, $id);
       break;
 
       default:
-        show_cities(0, 10, $name);
+        show_cities($name);
         show_new_city_form();
       break;
     }
   }
   else if (isset($name)) show_city($name, $id);
-  else {
-    show_cities(0, 10);
-    show_new_city_form();
-  }
+  else show_cities();
+
+  if (count($parameters)) echo "<p class=\"noprint standout\">Show all <a href=\"/city\">cities</a></p>\n";
+  show_new_city_form();
 
-  # XXX: Format URL in branch case...
-  if (count($parameters))
-  echo "<p>Show all <a href=\"/city\">cities</a></p>\n";
 ?>