X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;f=lib%2Farea.php;h=fbf739d0aae041bdb9c478dff41044b3167c476e;hb=ea0e53db8b5a264b6e231038815d2c350076d02a;hp=51f57d39ad9d38ad4abdec426be6196a4d13ed0f;hpb=6bd4ad3daf2cc870d96a3fed9ea9caf6798d2b78;p=readifood.git diff --git a/lib/area.php b/lib/area.php index 51f57d3..fbf739d 100644 --- a/lib/area.php +++ b/lib/area.php @@ -1,6 +1,7 @@ Added area.

\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 "

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 "

\n"; @@ -53,11 +58,18 @@ return; } + $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"; @@ -119,32 +131,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 { @@ -184,8 +178,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); @@ -242,7 +247,7 @@ 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); } } @@ -252,6 +257,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; }