Added city.
\n"; $parameters = array($_POST['city_name'], $id); } } function show_cities($name = null) { list($first_page, $per_page) = pagination(); echo "Cities:";
$q = new CityQuery;
if (isset($name)) $q->filterByName($name);
$cities = $q->paginate($first_page, $per_page);
if (count($cities)) {
foreach ($cities as $city) {
echo "
\nCity: " . $city->getStrongLink(get_city_displayname($city));
$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 "
Add a new city \n"; echo "with postcode prefix \n"; echo "
\n"; } function add_city($name, $postcode) { if (! check_admin(1, "add a city")) return; if (preg_match('/^([A-Za-z]+)/', $postcode, $m)) { $prefix = strtoupper($m[1]); } else { echo "Invalid postcode prefix!
\n"; return false; } $city = get_city_by_name($name, $prefix, false); if ($city) { echo "$name already exists!
\n"; show_city($name, $city->getId()); return false; } $city = new City; $city->setName($name); $city->setPostcodeArea($prefix); try { $city->save(); } catch (Exception $e) { echo "Error adding $name!
\n"; /* XXX: Why? */ return false; } 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 "You must confirm deletion of city " . $city->getName() . ": " . $city->getDeleteLink(true) . "
\n"; } function 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; try { $city->delete(); echo "Deleted city.
\n"; } catch (Exception $e) { echo "Error deleting $name!
\n"; /* XXX: Why? Check for addresses in use... */ return false; } return true; } function show_city($name, $id = null) { if (isset($id)) $city = get_city_by_id($id); else $city = get_city_by_name($name); if (! $city) return; echo "City: " . get_city_displayname($city) . "";
$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();
}
$q = new AreaQuery;
$areas = $q->filterByCityId($city->getId())->find();
if (count($areas)) {
foreach ($areas as $area) {
echo "
\nArea: " . $area->getLink();
}
}
echo "
$name($id) " . print_r($args, true) . "
\n"; if (count($args)) { switch ($args[0]) { case "delete": confirm_delete_city($name, $id); break; case "confirmdelete": delete_city($name, $id); break; default: show_cities($name); show_new_city_form(); break; } } else if (isset($name)) show_city($name, $id); else show_cities(); if (count($parameters)) echo " \n"; show_new_city_form(); ?>