Revision: 2572
          https://sourceforge.net/p/mrbs/code/2572/
Author:   cimorrison
Date:     2012-12-07 17:22:05 +0000 (Fri, 07 Dec 2012)
Log Message:
-----------
Fixed bug causing incorrect email notifications to be issued when members of a 
series were deleted (see SF Bugs #247)

Modified Paths:
--------------
    mrbs/trunk/web/del_entry.php
    mrbs/trunk/web/functions_mail.inc
    mrbs/trunk/web/mrbs_sql.inc

Modified: mrbs/trunk/web/del_entry.php
===================================================================
--- mrbs/trunk/web/del_entry.php        2012-12-07 16:45:18 UTC (rev 2571)
+++ mrbs/trunk/web/del_entry.php        2012-12-07 17:22:05 UTC (rev 2572)
@@ -74,14 +74,14 @@
       }
     }
     sql_begin();
-    $result = mrbsDelEntry(getUserName(), $id, $series, 1);
+    $start_times = mrbsDelEntry(getUserName(), $id, $series, 1);
     sql_commit();
     // [At the moment MRBS does not inform the user if it was only able to
     // delete some members of a series but not all.    This could happen for
-    // example if a booking policy is in force thgat prevents the deletion of 
entries
+    // example if a booking policy is in force that prevents the deletion of 
entries
     // in the past.   It would be better to inform the user that the operation 
has only
     // been partially successful]
-    if ($result)
+    if ($start_times !== FALSE)
     {
       // Send a mail to the Administrator
       if ($notify_by_email)
@@ -96,11 +96,11 @@
         }
         if (isset($action) && ($action == "reject"))
         {
-          $result = notifyAdminOnDelete($mail_previous, $series, $action, 
$note);
+          $result = notifyAdminOnDelete($mail_previous, $series, $start_times, 
$action, $note);
         }
         else
         {
-          $result = notifyAdminOnDelete($mail_previous, $series);
+          $result = notifyAdminOnDelete($mail_previous, $series, $start_times);
         }
       }
       Header("Location: $returl");

Modified: mrbs/trunk/web/functions_mail.inc
===================================================================
--- mrbs/trunk/web/functions_mail.inc   2012-12-07 16:45:18 UTC (rev 2571)
+++ mrbs/trunk/web/functions_mail.inc   2012-12-07 17:22:05 UTC (rev 2572)
@@ -357,7 +357,11 @@
 
 
 // Generate a list of repeat dates for a series
-function create_repeat_list($data, $action, $as_html)
+//
+// $reps is an array of start_times that have been created/modified/deleted.
+// If not specified the function works them out for itself from the repeat data
+// [In the future it would be better if everything passed in $reps]
+function create_repeat_list($data, $action, $as_html, $reps=NULL)
 {
   global $max_rep_entrys;
   
@@ -387,15 +391,18 @@
     }
   }
   
-  $reps = mrbsGetRepeatEntryList($data['start_time'], 
-                                 $data['end_date'],
-                                 $rep_details, 
-                                 $max_rep_entrys);
+  if (!isset($reps))
+  {
+    $reps = mrbsGetRepeatEntryList($data['start_time'], 
+                                   $data['end_date'],
+                                   $rep_details, 
+                                   $max_rep_entrys);
   
-  // Remove any dates that could not be booked due to conflicts                
               
-  if (!empty($data['skip_list']))
-  {
-    $reps = array_diff($reps, $data['skip_list']);
+    // Remove any dates that could not be booked due to conflicts              
                 
+    if (!empty($data['skip_list']))
+    {
+      $reps = array_diff($reps, $data['skip_list']);
+    }
   }
                                                          
   $result .= create_date_list($reps, $as_html);
@@ -415,7 +422,9 @@
 }
 
 
-function create_body($data, $mail_previous, $compare, $series, $action, 
$as_html=FALSE, $note='')
+// $start_times is an array of start_times that have been 
created/modified/deleted.
+// If not specified the function works them out for itself from the repeat data
+function create_body($data, $mail_previous, $compare, $series, $action, 
$as_html=FALSE, $note='', $start_times=NULL)
 {
   global $returl, $mrbs_company;
   global $enable_periods, $approval_enabled, $confirmation_enabled;
@@ -763,7 +772,7 @@
   // be booked due to conflicts.
   if ($data['rep_type'] != REP_NONE)
   {
-    $body .= create_repeat_list($data, $action, $as_html);
+    $body .= create_repeat_list($data, $action, $as_html, $start_times);
   }
   
   if ($as_html)
@@ -1005,11 +1014,12 @@
  *
  * @param   array   $data      contains deleted entry data for email body
  * @param   bool    $series    whether this is a series or not
+ * @param   array   $start_times an array of start times that have been deleted
  * @param   string  $action    the booking action (eg "delete", "more_info", 
etc.)
  * @param   string  $note      a note that is used with "reject"
  * @return  bool    TRUE or PEAR error object if fails
  */
-function notifyAdminOnDelete($data, $series=FALSE, $action="delete", $note="")
+function notifyAdminOnDelete($data, $series=FALSE, $start_times, 
$action="delete", $note="")
 {
   global $mail_settings, $enable_periods;
   
@@ -1055,13 +1065,13 @@
   
   // Create the text body
   $text_body = array();
-  $text_body['content'] = create_body($data, NULL, FALSE, $series, $action, 
FALSE, $note);
+  $text_body['content'] = create_body($data, NULL, FALSE, $series, $action, 
FALSE, $note, $start_times);
   
   // Create the HTML body
   $html_body = array();
   if ($mail_settings['html'])
   {
-    $html_body['content'] = create_body($data, NULL, FALSE, $series, $action, 
TRUE, $note);
+    $html_body['content'] = create_body($data, NULL, FALSE, $series, $action, 
TRUE, $note, $start_times);
     $html_body['cid'] = generate_global_uid("html");
   }
   

Modified: mrbs/trunk/web/mrbs_sql.inc
===================================================================
--- mrbs/trunk/web/mrbs_sql.inc 2012-12-07 16:45:18 UTC (rev 2571)
+++ mrbs/trunk/web/mrbs_sql.inc 2012-12-07 17:22:05 UTC (rev 2572)
@@ -387,19 +387,21 @@
  * $series - If set, delete the series, except user modified entries
  * $all    - If set, include user modified entries in the series delete
  *
- * Returns:
- *   0        - An error occured
- *   non-zero - The entry was deleted
+ * Returns FALSE if an error occured, otherwise an array of start_times that
+ * have been deleted
+ *
  */
 function mrbsDelEntry($user, $id, $series, $all)
 {
   global $tbl_entry, $tbl_repeat;
+  
+  $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");
   if (($res === FALSE) || (sql_count($res) <= 0))
   {
-    return 0;
+    return FALSE;
   }
   $row = sql_row_keyed($res, 0);
   $repeat_id = $row['repeat_id'];
@@ -418,8 +420,6 @@
 
   $res = sql_query($sql);
 
-  $removed = 0;
-
   for ($i = 0; ($row = sql_row_keyed($res, $i)); $i++)
   {
     if(!getWritable($row['create_by'], $user, $room_id))
@@ -441,7 +441,7 @@
    
     if (sql_command("DELETE FROM $tbl_entry WHERE id=" . $row['id']) > 0)
     {
-      $removed++;
+      $start_times[] = $row['start_time'];
     }
   }
 
@@ -451,7 +451,8 @@
     sql_command("DELETE FROM $tbl_repeat WHERE id=$repeat_id");
   }
 
-  return $removed > 0;
+  asort($start_times);
+  return $start_times;
 }
 
 /** mrbsCreateEntry()
------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits

Reply via email to