X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;f=lib%2Farea.php;h=77272f76e9ba375d5d076471f17c9c87da834e59;hb=f02dbb704b8c6f04529bf9cae3b99d379f998567;hp=9670a86c6bb8c3672a0985b8f625f01772da9c50;hpb=87843f0ab772989647ce3116f2508b781f56f0b6;p=readifood.git diff --git a/lib/area.php b/lib/area.php index 9670a86..77272f7 100644 --- a/lib/area.php +++ b/lib/area.php @@ -1,6 +1,7 @@ Added area.

\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/%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']) { @@ -27,10 +30,12 @@ if (count($areas)) { foreach ($areas as $area) { - echo "
\nArea: " . $area->getStrongLink(); - printf(" Contacts", urlencode($area->getName()), $area->getId()); - printf(" Donations", urlencode($area->getName()), $area->getId()); - printf(" Orders", urlencode($area->getName()), $area->getId()); + echo "
\nArea: " . $area->getStrongLink() . "\n"; + $n = urlencode($area->getName()); + $i = $area->getId(); + echo " " . get_small_link("Contacts", "/contact/in/area/%s/%d", $n, $i); + echo " " . get_small_link("Donations", "/donation/in/area/%s/%d", $n, $i); + echo " " . get_small_link("Orders", "/order/in/area/%s/%d", $n, $i); if (check_admin(1)) { echo " " . $area->getDeleteLink(); } @@ -51,15 +56,22 @@ return; } - echo "
\n"; + $candidates = array(); + foreach ($cities as $city) { + if (! count(get_city_areas($city->getId()))) continue; + $candidates[] = $city; + } + if (! count($candidates)) return; + + form("noprint standout"); echo "

Show areas in\n"; echo "\n"; echo "\n"; - echo "

\n"; + end_form(); } function show_new_area_form($city_id = null) { @@ -72,7 +84,7 @@ return; } - echo "
\n"; + form("noprint standout"); echo "

Add a new area \n"; echo "in \n"; echo "\n"; - echo "

\n"; + end_form(); } function add_area($name, $city_id) { @@ -117,32 +129,14 @@ 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 "

Error deleting $name!

\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 " $week[$i]\n"; + echo ">\n"; } } else { @@ -182,8 +176,19 @@ 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 "

Confirm deletion

\n"; + echo "

You must confirm deletion of area " . $area->getName() . ": " . $area->getDeleteLink(true) . "

\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); @@ -209,11 +214,13 @@ $area = get_area_by_name($name); if (! $area) return; - echo "
\n"; + form(); echo "

Area: " . $area->getName() . ""; - printf(" Contacts", urlencode($area->getName()), $area->getId()); - printf(" Donations", urlencode($area->getName()), $area->getId()); - printf(" Orders", urlencode($area->getName()), $area->getId()); + $n = $area->getName(); + $i = $area->getId(); + echo " " . get_small_link("Contacts", "/contact/in/area/%s/%d", $n, $i); + echo " " . get_small_link("Donations", "/donation/in/area/%s/%d", $n, $i); + echo " " . get_small_link("Orders", "/order/in/area/%s/%d", $n, $i); if (check_admin(1)) { echo " " . $area->getDeleteLink(); } @@ -230,7 +237,7 @@ echo "\n"; } echo "

\n"; - echo "
\n"; + end_form(); } /* /area/in/Cambridge/1 */ @@ -248,6 +255,10 @@ 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; }