Revision: 2616
          https://sourceforge.net/p/mrbs/code/2616/
Author:   cimorrison
Date:     2012-12-27 11:46:42 +0000 (Thu, 27 Dec 2012)
Log Message:
-----------
Made deletion of bookings work with the new tables

Modified Paths:
--------------
    mrbs/branches/linked_bookings/web/mrbs_sql.inc

Modified: mrbs/branches/linked_bookings/web/mrbs_sql.inc
===================================================================
--- mrbs/branches/linked_bookings/web/mrbs_sql.inc      2012-12-27 10:26:44 UTC 
(rev 2615)
+++ mrbs/branches/linked_bookings/web/mrbs_sql.inc      2012-12-27 11:46:42 UTC 
(rev 2616)
@@ -395,12 +395,16 @@
  */
 function mrbsDelEntry($user, $id, $series, $all)
 {
-  global $tbl_entry, $tbl_repeat;
+  global $tbl_entry, $tbl_repeat, $tbl_room_entry;
   
   $start_times = array();
 
   // Get the repeat_id and room_id for this entry
-  $res = sql_query("SELECT repeat_id, room_id FROM $tbl_entry WHERE id=$id 
LIMIT 1");
+  $res = sql_query("SELECT E.repeat_id, RE.room_id
+                      FROM $tbl_entry E, $tbl_room_entry RE
+                     WHERE E.id=$id
+                       AND E.id=RE.entry_id
+                     LIMIT 1");
   if (($res === FALSE) || (sql_count($res) <= 0))
   {
     return FALSE;
@@ -409,7 +413,11 @@
   $repeat_id = $row['repeat_id'];
   $room_id = $row['room_id'];
 
-  $sql = "SELECT start_time, end_time, room_id, create_by, id, entry_type FROM 
$tbl_entry WHERE ";
+  $sql = "SELECT start_time, end_time, RE.room_id,
+                 create_by, E.id, entry_type
+            FROM $tbl_entry E, $tbl_room_entry RE
+           WHERE E.id=RE.entry_id
+             AND ";
    
   if ($series)
   {
@@ -417,7 +425,7 @@
   }
   else
   {
-    $sql .= "id=$id";
+    $sql .= "E.id=$id";
   }
 
   $res = sql_query($sql);
@@ -428,7 +436,7 @@
     {
       continue;
     }
-   
+
     if ($series && $row['entry_type'] == ENTRY_RPT_CHANGED && !$all)
     {
       continue;
@@ -440,7 +448,8 @@
     {
       continue;
     }
-   
+    
+    // No need to delete the room_entry row as the delete will cascade through
     if (sql_command("DELETE FROM $tbl_entry WHERE id=" . $row['id']) > 0)
     {
       $start_times[] = $row['start_time'];
@@ -450,6 +459,7 @@
   if ($repeat_id > 0 &&
       sql_query1("SELECT count(*) FROM $tbl_entry WHERE repeat_id=$repeat_id") 
== 0)
   {
+    // No need to delete the room_repeat row as the delete will cascade through
     sql_command("DELETE FROM $tbl_repeat WHERE id=$repeat_id");
   }
 
------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122712
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits

Reply via email to