Support Auth0.
[readifood.git] / lib / area.php
index 9b0d5e1..fbf739d 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 
   if ($_POST['area_name']) {
+    set_last_selected("city_id", $_POST['city_id']);
     $id = add_area($_POST['area_name'], $_POST['city_id']);
     if ($id !== false) {
       echo "<p>Added area.</p>\n";
@@ -8,22 +9,25 @@
     }
   }
   else if ($_POST['city_id']) {
-    /* XXX: city_id is actually a string $city_name/$city_id */
-    header(sprintf("Location: http%s://%s/%s/in/city/%s", ($_SERVER['HTTPS']) ? "s" : "", $_SERVER['HTTP_HOST'], $module, $_POST['city_id']));
+    set_last_selected("city_id", $_POST['city_id']);
+    $city_id = $_POST['city_id'];
+    $city = get_city_by_id($city_id);
+    header(sprintf("Location: http%s://%s/%s/in/city/%s/%d", ($_SERVER['HTTPS']) ? "s" : "", $_SERVER['HTTP_HOST'], $module, $city->getName(), $city_id));
     exit;
   }
   else if ($_POST['update_area']) {
     update_area_delivery_days($parameters[0]);
   }
 
-  function show_areas($offset, $per_page, $city_name = null, $city_id = null) {
+  function show_areas($city_name = null, $city_id = null) {
+    list($first_page, $per_page) = pagination();
     if (isset($city_name) || isset($city_id)) {
       if (isset($city_id)) $city = get_city_by_id($city_id);
       else if ($city_name) $city = get_city_by_name($city_name);
       if ($city) {
         echo "<p>Areas in " . $city->getLink(get_city_displayname($city)) . ":";
         $q = new AreaQuery;
-        $areas = $q->filterByCityId($city_id)->find();
+        $areas = $q->filterByCityId($city_id)->orderByName()->orderById()->paginate($first_page, $per_page);
 
         if (count($areas)) {
           foreach ($areas as $area) {
@@ -37,6 +41,7 @@
               echo " " . $area->getDeleteLink();
             }
           }
+          show_pagination($areas);
         }
         else echo " none";
         echo "</p>\n";
@@ -64,7 +69,7 @@
     echo "<p>Show areas in\n";
     echo "<select name=\"city_id\">\n";
     foreach ($candidates as $city) {
-      option("city_id", sprintf("%s/%s", $city->getName(), $city->getId()), get_city_displayname($city));
+      option("city_id", $city->getId(), get_city_displayname($city));
     }
     echo "</select>\n";
     echo "<input type=\"submit\" value=\"Show\">\n";
     if ($parameters[0] == "in") {
       if ($parameters[1] == "city") {
         $city_id = $parameters[3];
-        show_areas(0, 10, $parameters[2], $city_id);
+        show_areas($parameters[2], $city_id);
         show_new_area_form($city_id);
       }
     }