From: Iain Patterson Date: Mon, 13 May 2013 10:52:21 +0000 (-0400) Subject: Confirm deletion. X-Git-Tag: 2013-05-13~1 X-Git-Url: http://git.iain.cx/?a=commitdiff_plain;ds=sidebyside;h=37d4290c9eae09546c22b257c589c7e66ad3a1f3;p=readifood.git Confirm deletion. Show a second link to confirm the deletion of an object rather than simply deleting immediately. --- diff --git a/lib/area.php b/lib/area.php index 2aa5e2d..8872a43 100644 --- a/lib/area.php +++ b/lib/area.php @@ -126,24 +126,6 @@ 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:"; @@ -191,8 +173,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); @@ -259,6 +252,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; } diff --git a/lib/city.php b/lib/city.php index b901163..dd60e36 100644 --- a/lib/city.php +++ b/lib/city.php @@ -76,6 +76,17 @@ 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 "

Confirm deletion

\n"; + 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; @@ -128,6 +139,10 @@ if (count($args)) { switch ($args[0]) { case "delete": + confirm_delete_city($name, $id); + break; + + case "confirmdelete": delete_city($name, $id); break; diff --git a/lib/contact.php b/lib/contact.php index a4610a7..de4dc82 100644 --- a/lib/contact.php +++ b/lib/contact.php @@ -479,6 +479,17 @@ return $contact->getId(); } + function confirm_delete_contact($name, $id = null, &$city_id = null) { + if (! check_admin(1, "delete a contact")) return; + + if (isset($id)) $contact = get_contact_by_id($id); + else $contact = get_contact_by_name($name); + if (! $contact) return false; + + echo "

Confirm deletion

\n"; + echo "

You must confirm deletion of contact " . $contact->getDisplayname() . ": " . $contact->getDeleteLink(true) . "

\n"; + } + function delete_contact($name, $id = null, &$city_id = null) { if (! check_admin(1, "delete a contact")) return; @@ -558,6 +569,10 @@ if (count($args)) { switch ($args[0]) { case "delete": + confirm_delete_contact($name, $id); + break; + + case "confirmdelete": delete_contact($name, $id); break; } diff --git a/lib/donation.php b/lib/donation.php index be3710c..4d928fb 100644 --- a/lib/donation.php +++ b/lib/donation.php @@ -309,6 +309,16 @@ return $donation->getId(); } + function confirm_delete_donation($id = null) { + if (! check_admin(1, "delete a donation")) return; + + if (isset($id)) $donation = get_donation_by_id($id); + if (! $donation) return false; + + echo "

Confirm deletion

\n"; + echo "

You must confirm deletion of donation $id: " . $donation->getDeleteLink(true) . "

\n"; + } + function delete_donation($id = null) { if (! check_admin(1, "delete a donation")) return; @@ -405,6 +415,10 @@ if (count($args)) { switch ($args[0]) { case "delete": + confirm_delete_donation($id); + break; + + case "confirmdelete": delete_donation($id); break; } diff --git a/lib/hub.php b/lib/hub.php index 51aec9a..7a18d47 100644 --- a/lib/hub.php +++ b/lib/hub.php @@ -342,6 +342,17 @@ return $hub->getId(); } + function confirm_delete_hub($name, $id = null) { + if (! check_admin(1, "delete a hub")) return; + + if (isset($id)) $hub = get_hub_by_id($id); + else $hub = get_hub_by_name($name); + if (! $hub) return false; + + echo "

Confirm deletion

\n"; + echo "

You must confirm deletion of hub " . $hub->getDisplayname() . ": " . $hub->getDeleteLink(true) . "

\n"; + } + function delete_hub($name, $id = null, &$city_id = null) { if (! check_admin(1, "delete a hub")) return; @@ -418,6 +429,10 @@ if (count($args)) { switch ($args[0]) { case "delete": + confirm_delete_hub($name, $id); + break; + + case "confirmdelete": delete_hub($name, $id); break; } diff --git a/lib/order.php b/lib/order.php index d48f214..114dfaf 100644 --- a/lib/order.php +++ b/lib/order.php @@ -522,6 +522,16 @@ return $order->getId(); } + function confirm_delete_order($id = null) { + if (! check_admin(1, "delete an order")) return; + + if (isset($id)) $order = get_order_by_id($id); + if (! $order) return false; + + echo "

Confirm deletion

\n"; + echo "

You must confirm deletion of order $id: " . $order->getDeleteLink(true) . "

\n"; + } + function delete_order($id = null) { if (! check_admin(1, "delete an order")) return; @@ -669,6 +679,10 @@ if (count($args)) { switch ($args[0]) { case "delete": + confirm_delete_order($id); + break; + + case "confirmdelete": delete_order($id); break; } diff --git a/propel/build/classes/ReadifoodObject.php b/propel/build/classes/ReadifoodObject.php index 9993239..6ea785b 100644 --- a/propel/build/classes/ReadifoodObject.php +++ b/propel/build/classes/ReadifoodObject.php @@ -22,8 +22,9 @@ return $this->getLink($blurb, sprintf("%s/%s", $this->getURL(), urlencode($action)), array_unique(array_merge($classes, array("small")))); } - function getDeleteLink() { - return $this->getActionLink("delete", "Delete", array("delete", "noprint")); + function getDeleteLink($confirm = false) { + $link = ($confirm) ? "confirmdelete" : "delete"; + return $this->getActionLink($link, "Delete", array("delete", "noprint")); } }