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($name = null) {
14 list($first_page, $per_page) = pagination();
17 if (isset($name)) $q->filterByName($name);
18 $cities = $q->paginate($first_page, $per_page);
20 foreach ($cities as $city) {
21 echo "<br>\nCity: " . $city->getStrongLink(get_city_displayname($city));
22 $n = $city->getName();
24 echo " " . get_small_link("Areas", "/area/in/city/%s/%d", $n, $i);
25 echo " " . get_small_link("Contacts", "/contact/in/city/%s/%d", $n, $i);
26 echo " " . get_small_link("Donations", "/donation/in/city/%s/%d", $n, $i);
27 echo " " . get_small_link("Orders", "/order/in/city/%s/%d", $n, $i);
29 echo " " . $city->getDeleteLink();
32 show_pagination($cities);
38 function show_new_city_form() {
39 if (! check_admin(1)) return;
41 form("noprint standout");
42 echo "<p>Add a new city <input name=\"city_name\">\n";
43 echo "with postcode prefix <input name=\"city_postcode_area\" size=4 maxlength=4>\n";
44 echo "<input type=\"submit\" value=\"Add\"></p>\n";
47 function add_city($name, $postcode) {
48 if (! check_admin(1, "add a city")) return;
50 if (preg_match('/^([A-Za-z]+)/', $postcode, $m)) {
51 $prefix = strtoupper($m[1]);
54 echo "<p>Invalid postcode prefix!</p>\n";
58 $city = get_city_by_name($name, $prefix, false);
60 echo "<p>$name already exists!</p>\n";
61 show_city($name, $city->getId());
66 $city->setName($name);
67 $city->setPostcodeArea($prefix);
72 catch (Exception $e) {
73 echo "<p>Error adding $name!</p>\n";
78 return $city->getId();
81 function confirm_delete_city($name, $id = null) {
82 if (! check_admin(1, "delete a city")) return;
84 if (isset($id)) $city = get_city_by_id($id);
85 else $city = get_city_by_name($name);
86 if (! $city) return false;
88 echo "<h3>Confirm deletion</h3>\n";
89 echo "<p>You must confirm deletion of city " . $city->getName() . ": " . $city->getDeleteLink(true) . "</p>\n";
92 function delete_city($name, $id = null) {
93 if (! check_admin(1, "delete a city")) return;
95 if (isset($id)) $city = get_city_by_id($id);
96 else $city = get_city_by_name($name);
97 if (! $city) return false;
101 echo "<p>Deleted city.</p>\n";
103 catch (Exception $e) {
104 echo "<p>Error deleting $name!</p>\n";
105 /* XXX: Why? Check for addresses in use... */
112 function show_city($name, $id = null) {
113 if (isset($id)) $city = get_city_by_id($id);
114 else $city = get_city_by_name($name);
117 echo "<p>City: <span class=\"strong\">" . get_city_displayname($city) . "</span>";
118 $n = $city->getName();
120 echo " " . get_small_link("Areas", "/area/in/city/%s/%d", $n, $i);
121 echo " " . get_small_link("Contacts", "/contact/in/city/%s/%d", $n, $i);
122 echo " " . get_small_link("Donations", "/donation/in/city/%s/%d", $n, $i);
123 echo " " . get_small_link("Orders", "/order/in/city/%s/%d", $n, $i);
124 if (check_admin(1)) {
125 echo " " . $city->getDeleteLink();
129 $areas = $q->filterByCityId($city->getId())->find();
131 foreach ($areas as $area) {
132 echo "<br>\nArea: " . $area->getLink();
139 list($name, $id, $args) = parse_parameters($parameters);
140 //echo "<p>$name($id) " . print_r($args, true) . "</p>\n";
144 confirm_delete_city($name, $id);
147 case "confirmdelete":
148 delete_city($name, $id);
153 show_new_city_form();
157 else if (isset($name)) show_city($name, $id);
160 if (count($parameters)) echo "<p class=\"noprint standout\">Show all <a href=\"/city\">cities</a></p>\n";
161 show_new_city_form();