Add ability to delete schedules
authorSteve Sutton <steve@gaslightmedia.com>
Tue, 12 Aug 2014 17:12:43 +0000 (13:12 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Tue, 12 Aug 2014 17:12:43 +0000 (13:12 -0400)
Adding the ability to delete a schedule.

Toolkit/Schedule/IndexController.php
Toolkit/Schedule/ListSchedules.php
Toolkit/Schedule/templates/listSchedules.html

index 2d6768c..b9f6e69 100644 (file)
@@ -6,9 +6,9 @@ class Toolkit_Schedule_IndexController
 {
     /**
      * indexAction
-     * 
+     *
      * default action if none found
-     * 
+     *
      * @return type string HTML
      */
     public function indexAction()
@@ -17,13 +17,13 @@ class Toolkit_Schedule_IndexController
         $html = $schedues->toHtml($this->registry);
         return $html;
     }
-    
+
     /**
      * editAction
-     * 
+     *
      * edit action if set as ac=edit
-     * 
-     * @return type 
+     *
+     * @return type
      */
     public function editAction()
     {
@@ -31,4 +31,40 @@ class Toolkit_Schedule_IndexController
         $html = $schedule->toHtml($this->registry);
         return $html;
     }
+
+    public function deleteAction()
+    {
+        $scheduleId = filter_var($_REQUEST['id'], FILTER_VALIDATE_INT);
+        if ($scheduleId) {
+            try {
+                $sql = "
+                DELETE
+                  FROM schedules
+                 WHERE id = :id";
+                $stmt = $this->registry->dbh->prepare($sql);
+                $stmt->bindParam(':id', $scheduleId, PDO::PARAM_INT);
+                $stmt->execute();
+
+                $sql = "
+                DELETE
+                  FROM departures
+                 WHERE schedule_id = :id";
+                $stmt = $this->registry->dbh->prepare($sql);
+                $stmt->bindParam(':id', $scheduleId, PDO::PARAM_INT);
+                $stmt->execute();
+
+                $sql = "
+                DELETE
+                  FROM departure_dates
+                 WHERE schedule_id = :id";
+                $stmt = $this->registry->dbh->prepare($sql);
+                $stmt->bindParam(':id', $scheduleId, PDO::PARAM_INT);
+                $stmt->execute();
+            } catch(PDOException $e) {
+                Toolkit_Common::handleError($e);
+            }
+        }
+        header('Location: schedules.php');
+        exit;
+    }
 }
index 4dfceff..18fea0a 100644 (file)
@@ -23,6 +23,8 @@ class Toolkit_Schedule_ListSchedules
         $tpl = new HTML_Template_Flexy($registry->flexyOptions);
         $page = new stdClass();
         $page->baseUrl = BASE_URL;
+        $page->deleteUrlBase
+            = MEDIA_BASE_URL . 'admin/schedules.php?ac=Delete&id=';
         $page->editLinkUrlBase
             = MEDIA_BASE_URL . 'admin/schedules.php?rt=Edit&id=';
         $whichActiveSql = "
index 821c7e1..1127cca 100644 (file)
@@ -8,7 +8,14 @@
     <legend>Boat Schedules</legend>
     <div flexy:foreach="schedules,schedule" class="panel">
         <label>
-            {schedule[name]:h}<a class="edit tiny button right" href="{baseUrl:h}admin/schedules.php?ac=Edit&id={schedule[id]:h}">Edit</a>
+        <a
+            onClick="return(confirm('Are you sure you want to Delete This schedule?'));"
+            class="delete tiny button right"
+            href="{deleteUrlBase:h}{schedule[id]:h}">Delete</a>
+            <span style="margin: 0 20px;">{schedule[name]:h}</span>
+        <a
+            class="edit tiny button left"
+            href="{baseUrl:h}admin/schedules.php?ac=Edit&id={schedule[id]:h}">Edit</a>
         </label>
 
     </div>