Revision: 2298
          http://mrbs.svn.sourceforge.net/mrbs/?rev=2298&view=rev
Author:   cimorrison
Date:     2012-05-24 19:54:18 +0000 (Thu, 24 May 2012)
Log Message:
-----------
Fixed bug where the max bookings per period limit was being supposedly breached 
when editing an existing entry

Modified Paths:
--------------
    mrbs/trunk/web/mrbs_sql.inc

Modified: mrbs/trunk/web/mrbs_sql.inc
===================================================================
--- mrbs/trunk/web/mrbs_sql.inc 2012-05-23 09:17:11 UTC (rev 2297)
+++ mrbs/trunk/web/mrbs_sql.inc 2012-05-24 19:54:18 UTC (rev 2298)
@@ -100,7 +100,7 @@
 // bookings in the interval of type $interval_type (can be 'day', 'week', 
'month' or
 // 'year').   If $only_area is set then only the bookings in the same are 
considered.
 // Returns NULL if OK, otherwise an error string.
-function checkInterval(&$booking, $interval_type='day', $only_area=FALSE)
+function checkInterval(&$booking, $ignore, $repignore, $interval_type='day', 
$only_area=FALSE)
 {
   global $max_per_interval_global, $max_per_interval_area;
   global $tbl_entry, $tbl_room;
@@ -182,6 +182,15 @@
       {
         $sql .= " AND R.area_id=$area_id";
       }
+      if ($ignore > 0)
+      {
+        $sql .= " AND E.id <> $ignore";
+      }
+      if ($repignore > 0)
+      {
+        $sql .= " AND E.repeat_id <> $repignore";
+      }
+      
       $existing[$location][$interval_type][$interval_start] = sql_query1($sql);
       if ($existing[$location][$interval_type][$interval_start] < 0)
       {
@@ -194,7 +203,7 @@
     {
       $proposed[$location][$interval_type][$interval_start]++;
     }
-    
+
     $max_allowed = ($only_area) ? $max_per_interval_area[$interval_type] : 
$max_per_interval_global[$interval_type];
     if (($existing[$location][$interval_type][$interval_start] + 
$proposed[$location][$interval_type][$interval_start]) >
          $max_allowed)
@@ -232,7 +241,7 @@
  *            - An array of human readable errors.   If no errors the array has
  *              length 0
  */
-function mrbsCheckPolicy(&$booking, $delete=FALSE)
+function mrbsCheckPolicy(&$booking, $ignore, $repignore, $delete=FALSE)
 {
   global $periods, $enable_periods;
   global $min_book_ahead_enabled, $min_book_ahead_secs;
@@ -324,7 +333,7 @@
     // globally
     if (!empty($max_per_interval_global_enabled[$interval_type]) && !$delete)
     {
-      $tmp = checkInterval($booking, $interval_type, FALSE);
+      $tmp = checkInterval($booking, $ignore, $repignore, $interval_type, 
FALSE);
       if (isset($tmp))
       {
         $errors[] = $tmp;
@@ -333,7 +342,7 @@
     // for the area
     if (!empty($max_per_interval_area_enabled[$interval_type]) && !$delete)
     {
-      $tmp = checkInterval($booking, $interval_type, TRUE);
+      $tmp = checkInterval($booking, $ignore, $repignore, $interval_type, 
TRUE);
       if (isset($tmp))
       {
         $errors[] = $tmp;
@@ -403,7 +412,7 @@
     // check that the booking policies allow us to delete this entry
     if (!$is_book_admin)
     {
-      $tmp = mrbsCheckPolicy($row, TRUE);
+      $tmp = mrbsCheckPolicy($row, 0, 0, TRUE);
       if (!empty($tmp))
       {
         continue;
@@ -1444,7 +1453,7 @@
           if (!$skip_this_booking &&
               !auth_book_admin($user, $this_booking['room_id']))
           {
-            $errors = mrbsCheckPolicy($this_booking);
+            $errors = mrbsCheckPolicy($this_booking, $ignore_id, $repeat_id);
             if (count($errors) > 0)
             {
               $valid_booking = FALSE;
@@ -1471,7 +1480,7 @@
         // conforms to the booking policy
         if (!auth_book_admin($user, $booking['room_id']))
         {
-          $errors = mrbsCheckPolicy($booking);
+          $errors = mrbsCheckPolicy($booking, $ignore_id, 0);
           if (count($errors) > 0)
           {
             $valid_booking = FALSE;

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits

Reply via email to