Track last selected area or city.
[readifood.git] / lib / area.php
index 9b0d5e1..77272f7 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,8 +9,10 @@
     }
   }
   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']) {
@@ -64,7 +67,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";