3 /* XXX: Show links to other objects. Don't show cities by default. */
5 if ($_POST['city_name']) {
6 $id = add_city($_POST['city_name'], $_POST['city_postcode_area']);
8 echo "<p>Added city.</p>\n";
9 $parameters = array($_POST['city_name'], $id);
13 function show_cities($offset, $per_page, $name = null) {
16 if (isset($name)) $q->filterByName($name);
17 $p = $q->paginate($offset, $per_page);
19 foreach ($p as $city) {
20 echo "<br>\nCity: " . $city->getStrongLink(get_city_displayname($city));
21 $n = $city->getName();
23 echo " " . get_small_link("Areas", "/area/in/city/%s/%d", $n, $i);
24 echo " " . get_small_link("Contacts", "/contact/in/city/%s/%d", $n, $i);
25 echo " " . get_small_link("Donations", "/donation/in/city/%s/%d", $n, $i);
26 echo " " . get_small_link("Orders", "/order/in/city/%s/%d", $n, $i);
28 echo " " . $city->getDeleteLink();
36 function show_new_city_form() {
37 if (! check_admin(1)) return;
39 form("noprint standout");
40 echo "<p>Add a new city <input name=\"city_name\">\n";
41 echo "with postcode prefix <input name=\"city_postcode_area\" size=4 maxlength=4>\n";
42 echo "<input type=\"submit\" value=\"Add\"></p>\n";
45 function add_city($name, $postcode) {
46 if (! check_admin(1, "add a city")) return;
48 if (preg_match('/^([A-Za-z]+)/', $postcode, $m)) {
49 $prefix = strtoupper($m[1]);
52 echo "<p>Invalid postcode prefix!</p>\n";
56 $city = get_city_by_name($name, $prefix, false);
58 echo "<p>$name already exists!</p>\n";
59 show_city($name, $city->getId());
64 $city->setName($name);
65 $city->setPostcodeArea($prefix);
70 catch (Exception $e) {
71 echo "<p>Error adding $name!</p>\n";
76 return $city->getId();
79 function delete_city($name, $id = null) {
80 if (! check_admin(1, "delete a city")) return;
82 if (isset($id)) $city = get_city_by_id($id);
83 else $city = get_city_by_name($name);
84 if (! $city) return false;
88 echo "<p>Deleted city.</p>\n";
90 catch (Exception $e) {
91 echo "<p>Error deleting $name!</p>\n";
92 /* XXX: Why? Check for addresses in use... */
99 function show_city($name, $id = null) {
100 if (isset($id)) $city = get_city_by_id($id);
101 else $city = get_city_by_name($name);
104 echo "<p>City: <span class=\"strong\">" . get_city_displayname($city) . "</span>";
105 $n = $city->getName();
107 echo " " . get_small_link("Areas", "/area/in/city/%s/%d", $n, $i);
108 echo " " . get_small_link("Contacts", "/contact/in/city/%s/%d", $n, $i);
109 echo " " . get_small_link("Donations", "/donation/in/city/%s/%d", $n, $i);
110 echo " " . get_small_link("Orders", "/order/in/city/%s/%d", $n, $i);
111 if (check_admin(1)) {
112 echo " " . $city->getDeleteLink();
116 $areas = $q->filterByCityId($city->getId())->find();
118 foreach ($areas as $area) {
119 echo "<br>\nArea: " . $area->getLink();
126 list($name, $id, $args) = parse_parameters($parameters);
127 //echo "<p>$name($id) " . print_r($args, true) . "</p>\n";
131 delete_city($name, $id);
135 show_cities(0, 10, $name);
136 show_new_city_form();
140 else if (isset($name)) show_city($name, $id);
141 else show_cities(0, 10);
143 if (count($parameters)) echo "<p class=\"noprint standout\">Show all <a href=\"/city\">cities</a></p>\n";
144 show_new_city_form();