Revision: 1838
          http://mrbs.svn.sourceforge.net/mrbs/?rev=1838&view=rev
Author:   cimorrison
Date:     2011-06-21 15:01:31 +0000 (Tue, 21 Jun 2011)

Log Message:
-----------
Implemented an optional limit on the maximum length of a booking for 
non-admins.   At the moment it is a global limit rather than per-area.   It 
also does not yet prevent invalid booking lengths being shown in the edit_entry 
form.

Modified Paths:
--------------
    mrbs/trunk/web/edit_entry_handler.php
    mrbs/trunk/web/lang.en
    mrbs/trunk/web/mrbs_sql.inc
    mrbs/trunk/web/systemdefaults.inc.php

Modified: mrbs/trunk/web/edit_entry_handler.php
===================================================================
--- mrbs/trunk/web/edit_entry_handler.php       2011-06-21 08:51:00 UTC (rev 
1837)
+++ mrbs/trunk/web/edit_entry_handler.php       2011-06-21 15:01:31 UTC (rev 
1838)
@@ -323,6 +323,7 @@
 // Now get the duration, which will be needed for email notifications
 // (We do this before we adjust for DST so that the user sees what they expect 
to see)
 $duration = $endtime - $starttime;
+$duration_seconds = $endtime - $starttime;  // Preserve the duration in 
seconds - we need it later
 $date = getdate($starttime);
 if ($enable_periods)
 {
@@ -428,7 +429,7 @@
 $valid_booking = TRUE;
 $conflicts = "";          // Holds a list of all the conflicts (ideally this 
would be an array)
 $rules_broken = array();  // Holds an array of the rules that have been broken
- 
+
 // Check for any schedule conflicts in each room we're going to try and
 // book in;  also check that the booking conforms to the policy
 foreach ( $rooms as $room_id )
@@ -441,7 +442,7 @@
       {
         // calculate diff each time and correct where events
         // cross DST
-        $diff = $endtime - $starttime;
+        $diff = $duration_seconds;
         $diff += cross_dst($reps[$i], $reps[$i] + $diff);
 
         $tmp = mrbsCheckFree($room_id,
@@ -459,11 +460,11 @@
         // conforms to the booking policy
         if (!auth_book_admin($user, $room_id))
         {
-          $tmp = mrbsCheckPolicy($reps[$i]);
-          if (!empty($tmp))
+          $errors = mrbsCheckPolicy($reps[$i], $duration_seconds);
+          if (count($errors) > 0)
           {
             $valid_booking = FALSE;
-            $rules_broken[] = $tmp;
+            $rules_broken = $rules_broken + $errors;  // array union
           }
         }
       }
@@ -486,11 +487,11 @@
       // conforms to the booking policy
       if (!auth_book_admin($user, $room_id))
       {
-        $tmp = mrbsCheckPolicy($starttime);
-        if (!empty($tmp))
+        $errors = mrbsCheckPolicy($starttime, $duration_seconds);
+        if (count($errors) > 0)
         {
           $valid_booking = FALSE;
-          $rules_broken[] = $tmp;
+          $rules_broken = $rules_broken + $errors;  // Array union
         }
       }
   }

Modified: mrbs/trunk/web/lang.en
===================================================================
--- mrbs/trunk/web/lang.en      2011-06-21 08:51:00 UTC (rev 1837)
+++ mrbs/trunk/web/lang.en      2011-06-21 15:01:31 UTC (rev 1838)
@@ -165,13 +165,14 @@
 $vocab["mail_body_new_entry"]     = "A new entry has been booked, here are the 
details:";
 $vocab["mail_body_changed_entry"] = "An entry has been modified, here are the 
details:";
 $vocab["mail_body_del_entry"]     = "An entry has been deleted, here are the 
details:";
-$vocab["new_value"]           = "New";
-$vocab["old_value"]           = "Old";
-$vocab["deleted_by"]          = "Deleted by";
-$vocab["reason"]              = "Reason";
-$vocab["info_requested"]      = "Information requested";
-$vocab["min_time_before"]     = "The minimum interval between now and the 
start of a booking is";
-$vocab["max_time_before"]     = "The maximum interval between now and the 
start of a booking is";
+$vocab["new_value"]               = "New";
+$vocab["old_value"]               = "Old";
+$vocab["deleted_by"]              = "Deleted by";
+$vocab["reason"]                  = "Reason";
+$vocab["info_requested"]          = "Information requested";
+$vocab["min_time_before"]         = "The minimum interval between now and the 
start of a booking is";
+$vocab["max_time_before"]         = "The maximum interval between now and the 
start of a booking is";
+$vocab["max_booking_duration"]    = "The maximum duration of a booking is";
 
 // Used in pending.php
 $vocab["pending"]            = "Bookings awaiting approval";

Modified: mrbs/trunk/web/mrbs_sql.inc
===================================================================
--- mrbs/trunk/web/mrbs_sql.inc 2011-06-21 08:51:00 UTC (rev 1837)
+++ mrbs/trunk/web/mrbs_sql.inc 2011-06-21 15:01:31 UTC (rev 1838)
@@ -98,19 +98,22 @@
  * to creation)
  * 
  * $starttime - The start of period
+ * $duration  - The duration in seconds
  * $delete    - TRUE: We're intending to delete an entry
  *            - FALSE:  We're intending to create or edit an entry (the 
default)
  * 
  * Returns:
- *   nothing   - The booking is OK
- *   something - An error occured, the return value is human readable
+ *            - An array of human readable errors.   If no errors the array has
+ *              length 0
  */
-function mrbsCheckPolicy($starttime, $delete=FALSE)
+function mrbsCheckPolicy($starttime, $duration, $delete=FALSE)
 {
-  global $min_book_ahead_enabled, $max_book_ahead_enabled, $enable_periods;
-  global $min_book_ahead_secs, $max_book_ahead_secs;
+  global $periods, $enable_periods;
+  global $min_book_ahead_enabled, $min_book_ahead_secs;
+  global $max_book_ahead_enabled, $max_book_ahead_secs;
+  global $max_duration_enabled, $max_duration_secs, $max_duration_periods;
 
-  $error = "";
+  $errors = array();
   $secs_in_day = 60*60*24;
   
   // Because MRBS has no notion of where we are in the day if we're using 
periods,
@@ -118,6 +121,7 @@
   $now = ($enable_periods) ? mktime(0, 0, 0) : time();
   // We'll also round $min_book_ahead_secs and $max_book_ahead_secs down to 
the nearest whole day
   
+  // Check min_book_ahead
   if ($min_book_ahead_enabled)
   {
     if ($enable_periods)
@@ -128,11 +132,11 @@
     if (($starttime - $now) < $min_book_ahead)
     {
       toTimeString($min_book_ahead, $units);
-      $error = get_vocab("min_time_before"). " $min_book_ahead $units";
-      return $error;
+      $errors[] = get_vocab("min_time_before") . " $min_book_ahead $units";
     }
   }
   
+  // Check max_book_ahead
   if ($max_book_ahead_enabled)
   {
     if ($enable_periods)
@@ -143,11 +147,44 @@
     if (($starttime - $now) > $max_book_ahead)
     {
       toTimeString($max_book_ahead, $units);
-      $error = get_vocab("max_time_before"). " $max_book_ahead $units";
-      return $error;
+      $errors[] = get_vocab("max_time_before") . " $max_book_ahead $units";
     }
   }
-  return $error;
+  
+  // Check max_duration
+  if ($max_duration_enabled)
+  {
+    if ($enable_periods)
+    {
+      // Instead of calculating the difference between the start and end times 
and
+      // comparing that with the maximum duration, we add the maximum duration 
to the
+      // start time and compare that with the actual end time
+      $start = getdate($starttime);
+      $start['minutes'] += $max_duration_periods;
+      $n_periods = count($periods);
+      // If we've gone over into another day, adjust the minutes and days 
accordingly
+      while ($start['minutes'] >= $n_periods)
+      {
+        $start['minutes'] -= $n_periods;
+        $start['mday']++;
+      }
+      $max_endtime = mktime($start['hours'], $start['minutes'], 
$start['seconds'],
+                            $start['mon'], $start['mday'], $start['year']);
+      if (($starttime + $duration) > $max_endtime)
+      {
+        $errors[] = get_vocab("max_booking_duration") . " 
$max_duration_periods " .
+                    (($max_duration_periods > 1) ? get_vocab("periods") : 
get_vocab("period_lc"));
+      }
+    }
+    elseif ($duration > $max_duration_secs)
+    {
+      $max_duration = $max_duration_secs;
+      toTimeString($max_duration, $units);
+      $errors[] = get_vocab("max_booking_duration") . " $max_duration $units";
+    }
+  }
+  
+  return $errors;
 }
 
 /** mrbsDelEntry()

Modified: mrbs/trunk/web/systemdefaults.inc.php
===================================================================
--- mrbs/trunk/web/systemdefaults.inc.php       2011-06-21 08:51:00 UTC (rev 
1837)
+++ mrbs/trunk/web/systemdefaults.inc.php       2011-06-21 15:01:31 UTC (rev 
1838)
@@ -201,10 +201,17 @@
  * Booking policies
  ******************/
 
-// Booking policies can all be be configured on a per-area basis, so these 
variables
+// Most booking policies can be configured on a per-area basis, so these 
variables
 // appear in the areadefaults.inc.php file.
 
+// The settings below are global policy settings
 
+// Set a maximum duration for bookings
+$max_duration_enabled = FALSE; // Set to TRUE if you want to enforce a maximum 
duration
+$max_duration_secs = 60*60*2;  // (seconds) - when using "times"
+$max_duration_periods = 2;     // (periods) - when using "periods"
+
+
 /******************
  * Display settings
  ******************/


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

------------------------------------------------------------------------------
EditLive Enterprise is the world's most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits

Reply via email to