Confirm deletion.
authorIain Patterson <me@iain.cx>
Mon, 13 May 2013 10:52:21 +0000 (06:52 -0400)
committerIain Patterson <me@iain.cx>
Mon, 13 May 2013 12:48:49 +0000 (08:48 -0400)
Show a second link to confirm the deletion of an object rather than
simply deleting immediately.

lib/area.php
lib/city.php
lib/contact.php
lib/donation.php
lib/hub.php
lib/order.php
propel/build/classes/ReadifoodObject.php

index 2aa5e2d..8872a43 100644 (file)
     return $area->getId();
   }
 
     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 "<p>Error deleting $name!</p>\n";
-      /* XXX: Why? Check for addresses in use... */
-      return false;
-    }
-
-    return true;
-  }
-
   function show_area_delivery_days_form($days) {
     global $week;
     echo "Delivery days:";
   function show_area_delivery_days_form($days) {
     global $week;
     echo "Delivery days:";
     return true;
   }
 
     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 "<h3>Confirm deletion</h3>\n";
+    echo "<p>You must confirm deletion of area " . $area->getName() . ": " . $area->getDeleteLink(true) . "</p>\n";
+  }
+
   function delete_area($name, $id = null, &$city_id = null) {
   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);
 
     if (isset($id)) $area = get_area_by_id($id);
     else $area = get_area_by_name($name);
   if (count($args)) {
     switch ($args[0]) {
       case "delete":
   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;
     }
         delete_area($name, $id, $city_id);
       break;
     }
index b901163..dd60e36 100644 (file)
     return $city->getId();
   }
 
     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 "<h3>Confirm deletion</h3>\n";
+    echo "<p>You must confirm deletion of city " . $city->getName() . ": " . $city->getDeleteLink(true) . "</p>\n";
+  }
+
   function delete_city($name, $id = null) {
     if (! check_admin(1, "delete a city")) return;
 
   function delete_city($name, $id = null) {
     if (! check_admin(1, "delete a city")) return;
 
   if (count($args)) {
     switch ($args[0]) {
       case "delete":
   if (count($args)) {
     switch ($args[0]) {
       case "delete":
+        confirm_delete_city($name, $id);
+      break;
+
+      case "confirmdelete":
         delete_city($name, $id);
       break;
 
         delete_city($name, $id);
       break;
 
index a4610a7..de4dc82 100644 (file)
     return $contact->getId();
   }
 
     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 "<h3>Confirm deletion</h3>\n";
+    echo "<p>You must confirm deletion of contact " . $contact->getDisplayname() . ": " . $contact->getDeleteLink(true) . "</p>\n";
+  }
+
   function delete_contact($name, $id = null, &$city_id = null) {
     if (! check_admin(1, "delete a contact")) return;
 
   function delete_contact($name, $id = null, &$city_id = null) {
     if (! check_admin(1, "delete a contact")) return;
 
   if (count($args)) {
     switch ($args[0]) {
       case "delete":
   if (count($args)) {
     switch ($args[0]) {
       case "delete":
+        confirm_delete_contact($name, $id);
+      break;
+
+      case "confirmdelete":
         delete_contact($name, $id);
       break;
     }
         delete_contact($name, $id);
       break;
     }
index be3710c..4d928fb 100644 (file)
     return $donation->getId();
   }
 
     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 "<h3>Confirm deletion</h3>\n";
+    echo "<p>You must confirm deletion of donation $id: " . $donation->getDeleteLink(true) . "</p>\n";
+  }
+
   function delete_donation($id = null) {
     if (! check_admin(1, "delete a donation")) return;
 
   function delete_donation($id = null) {
     if (! check_admin(1, "delete a donation")) return;
 
   if (count($args)) {
     switch ($args[0]) {
       case "delete":
   if (count($args)) {
     switch ($args[0]) {
       case "delete":
+        confirm_delete_donation($id);
+      break;
+
+      case "confirmdelete":
         delete_donation($id);
       break;
     }
         delete_donation($id);
       break;
     }
index 51aec9a..7a18d47 100644 (file)
     return $hub->getId();
   }
 
     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 "<h3>Confirm deletion</h3>\n";
+    echo "<p>You must confirm deletion of hub " . $hub->getDisplayname() . ": " . $hub->getDeleteLink(true) . "</p>\n";
+  }
+
   function delete_hub($name, $id = null, &$city_id = null) {
     if (! check_admin(1, "delete a hub")) return;
 
   function delete_hub($name, $id = null, &$city_id = null) {
     if (! check_admin(1, "delete a hub")) return;
 
   if (count($args)) {
     switch ($args[0]) {
       case "delete":
   if (count($args)) {
     switch ($args[0]) {
       case "delete":
+        confirm_delete_hub($name, $id);
+      break;
+
+      case "confirmdelete":
         delete_hub($name, $id);
       break;
     }
         delete_hub($name, $id);
       break;
     }
index d48f214..114dfaf 100644 (file)
     return $order->getId();
   }
 
     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 "<h3>Confirm deletion</h3>\n";
+    echo "<p>You must confirm deletion of order $id: " . $order->getDeleteLink(true) . "</p>\n";
+  }
+
   function delete_order($id = null) {
     if (! check_admin(1, "delete an order")) return;
 
   function delete_order($id = null) {
     if (! check_admin(1, "delete an order")) return;
 
   if (count($args)) {
     switch ($args[0]) {
       case "delete":
   if (count($args)) {
     switch ($args[0]) {
       case "delete":
+        confirm_delete_order($id);
+      break;
+
+      case "confirmdelete":
         delete_order($id);
       break;
     }
         delete_order($id);
       break;
     }
index 9993239..6ea785b 100644 (file)
@@ -22,8 +22,9 @@
       return $this->getLink($blurb, sprintf("%s/%s", $this->getURL(), urlencode($action)), array_unique(array_merge($classes, array("small"))));
     }
 
       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"));
     }
   }
 
     }
   }