Revision: 1904
          http://mrbs.svn.sourceforge.net/mrbs/?rev=1904&view=rev
Author:   cimorrison
Date:     2011-08-29 12:04:28 +0000 (Mon, 29 Aug 2011)
Log Message:
-----------
Added an option on the booking form to skip past conflicting bookings when 
making repeat bookings.  (To come: an option on the error page to skip past 
conflicting bookings if you've forgotten to check the box on the booking form)

Modified Paths:
--------------
    mrbs/trunk/web/edit_entry.php
    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.php
===================================================================
--- mrbs/trunk/web/edit_entry.php       2011-08-29 09:47:37 UTC (rev 1903)
+++ mrbs/trunk/web/edit_entry.php       2011-08-29 12:04:28 UTC (rev 1904)
@@ -1135,10 +1135,19 @@
       </div>
      
       <?php
+      // Checkbox for skipping past conflicts
       echo "<div>\n";
       $label_text = get_vocab("rep_num_weeks") . ":<br>" . 
get_vocab("rep_for_nweekly");
       generate_input($label_text, 'rep_num_weeks', $rep_num_weeks);
       echo "</div>\n";
+      
+      echo "<div>\n";
+      echo "<label for=\"skip\">" . get_vocab("skip_conflicts") . 
":</label>\n";
+      echo "<input type=\"checkbox\" class=\"checkbox\" " .
+                "id=\"skip\" name=\"skip\" value=\"1\" " .
+                ((!empty($skip_default)) ? " checked=\"checked\"" : "") .
+                ">\n";
+      echo "</div>\n";
 
       echo "</fieldset>\n";
     }

Modified: mrbs/trunk/web/edit_entry_handler.php
===================================================================
--- mrbs/trunk/web/edit_entry_handler.php       2011-08-29 09:47:37 UTC (rev 
1903)
+++ mrbs/trunk/web/edit_entry_handler.php       2011-08-29 12:04:28 UTC (rev 
1904)
@@ -29,6 +29,7 @@
 $rep_id = get_form_var('rep_id', 'int');
 $rep_day = get_form_var('rep_day', 'array'); // array of bools
 $rep_num_weeks = get_form_var('rep_num_weeks', 'int');
+$skip = get_form_var('skip', 'string');  // bool, actually
 $private = get_form_var('private', 'string'); // bool, actually
 $confirmed = get_form_var('confirmed', 'string');
 // Get the start day/month/year and make them the current day/month/year
@@ -429,11 +430,14 @@
 $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
-
+$skip_list = array();     // Holds a 2D array of bookings to skip past.  
Indexed
+                          // by room id and start time
+                          
 // 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 )
 {
+  $skip_list[$room_id] = array();
   if ($rep_type != REP_NONE && !empty($reps))
   {
     if(count($reps) < $max_rep_entrys)
@@ -453,7 +457,20 @@
 
         if (!empty($tmp))
         {
-          $valid_booking = FALSE;
+          // If we've been told to skip past existing bookings, then add
+          // this start time to the list of start times to skip past.
+          // Otherwise it's an invalid booking
+          if ($skip)
+          {
+            $skip_list[$room_id][] = $reps[$i];
+          }
+          else
+          {
+            $valid_booking = FALSE;
+          }
+          // In both cases remember the conflict data.   (We don't at the
+          // moment do anything with the data if we're skipping, but we might
+          // in the future want to display a list of bookings we've skipped 
past)
           $conflicts .= $tmp;
         }
         // if we're not an admin for this room, check that the booking
@@ -467,7 +484,7 @@
             $rules_broken = $rules_broken + $errors;  // array union
           }
         }
-      }
+      } // for
     }
     else
     {
@@ -599,7 +616,7 @@
 
     if ($edit_type == "series")
     {
-      $booking = mrbsCreateRepeatingEntrys($data);
+      $booking = mrbsCreateRepeatingEntrys($data, $skip_list);
       $new_id = $booking['id'];
       $is_repeat_table = $booking['series'];
       $data['id'] = $new_id;  // Add in the id now we know it

Modified: mrbs/trunk/web/lang.en
===================================================================
--- mrbs/trunk/web/lang.en      2011-08-29 09:47:37 UTC (rev 1903)
+++ mrbs/trunk/web/lang.en      2011-08-29 12:04:28 UTC (rev 1904)
@@ -89,6 +89,7 @@
 $vocab["rep_freq"]           = "Frequency";
 $vocab["rep_num_weeks"]      = "Number of weeks";
 $vocab["rep_for_nweekly"]    = "(for n-weekly)";
+$vocab["skip_conflicts"]     = "Skip past conflicts";
 $vocab["ctrl_click"]         = "Use Control-Click to select more than one 
room";
 $vocab["entryid"]            = "Entry ID ";
 $vocab["repeat_id"]          = "Repeat ID "; 

Modified: mrbs/trunk/web/mrbs_sql.inc
===================================================================
--- mrbs/trunk/web/mrbs_sql.inc 2011-08-29 09:47:37 UTC (rev 1903)
+++ mrbs/trunk/web/mrbs_sql.inc 2011-08-29 12:04:28 UTC (rev 1904)
@@ -623,15 +623,18 @@
  * Creates a repeat entry in the data base + all the repeating entrys
  * 
  * $data      - An array containing the entry details
+ * $skip_list - A 2D array of bookings to skip past, indexed by
+ *              room_id and start_time
  * 
  * Returns:
  *   an array
- *   ['id']      - 0 if an error occurred, otherwise an id
+ *   ['id']      - 0 if an error occurred or if no bookings could be
+ *                 made, otherwise an id
  *   ['series']  - boolean: TRUE if the id refers to the repeat table
  *                          FALSE if the id refers to the entry table
  *
  */
-function mrbsCreateRepeatingEntrys($data)
+function mrbsCreateRepeatingEntrys($data, &$skip_list)
 {
   global $max_rep_entrys;
   
@@ -641,12 +644,16 @@
                                  $data['rep_type'], $data['rep_opt'],
                                  $max_rep_entrys, $data['rep_num_weeks']);
 
+  // Don't make any bookings if we've been asked to book up
+  // more entries than we are allowed in a single repeat.
   if (count($reps) > $max_rep_entrys)
   {
     $result['id'] = 0;
     return $result;;
   }
-
+  
+  // If $reps is empty, then this is a single booking, so treat
+  // it differently
   if (empty($reps))
   {
     $data['entry_type'] = ENTRY_SINGLE;
@@ -656,7 +663,23 @@
     $result['series'] = FALSE;
     return $result;
   }
-   
+  
+  // This is a repeat booking.   If we've got to skip past all
+  // the entries, then don't make a booking!
+  if (count($reps) == count($skip_list[$data['room_id']]))
+  {
+    $result['id'] = 0;
+    return $result;;
+  }
+  
+  // Maybe one should also consider adjusting the start_time for
+  // the repeat if the first (or more) entries of the series are
+  // to be skipped.    However I haven't done so here and it gives the
+  // maybe slightly strange result that the start date of the series won't
+  // have an entry on that date.   But then this is no different from 
+  // the way MRBS works at present if you create a series and then
+  // delete the first entry.   (But maybe that's not the way we want it
+  // to behave??)
   $id = mrbsCreateRepeatEntry($data);
     
   if ($id)
@@ -667,14 +690,19 @@
     $endtime = $data['end_time'];
     for ($i = 0; $i < count($reps); $i++)
     {
-      // calculate diff each time and correct where events
-      // cross DST
-      $diff = $endtime - $starttime;
-      $diff += cross_dst($reps[$i], $reps[$i] + $diff);  
-      $data['start_time'] = $reps[$i];
-      $data['end_time'] = $reps[$i] + $diff;
+      // Provided this isn't one of the entries to skip, go ahead
+      // and make the booking
+      if (!in_array($reps[$i], $skip_list[$data['room_id']]))
+      {
+        // calculate diff each time and correct where events
+        // cross DST
+        $diff = $endtime - $starttime;
+        $diff += cross_dst($reps[$i], $reps[$i] + $diff);  
+        $data['start_time'] = $reps[$i];
+        $data['end_time'] = $reps[$i] + $diff;
 
-      $ent_id = mrbsCreateSingleEntry($data);
+        $ent_id = mrbsCreateSingleEntry($data);
+      }
     }
   }
   $result['id'] = $id;

Modified: mrbs/trunk/web/systemdefaults.inc.php
===================================================================
--- mrbs/trunk/web/systemdefaults.inc.php       2011-08-29 09:47:37 UTC (rev 
1903)
+++ mrbs/trunk/web/systemdefaults.inc.php       2011-08-29 12:04:28 UTC (rev 
1904)
@@ -485,6 +485,11 @@
 
 // $is_mandatory_field['entry.terms_and_conditions'] = true;
 
+// Set $skip_default to TRUE if you want the "Skip past conflicts" box
+// on the edit_entry form to be checked by default.  (This will mean that
+// if you make a repeat booking and some of the repeat dates are already
+// booked, MRBS will just skip past those).
+$skip_default = FALSE;
  
 /***********************************************
  * Authentication settings - read AUTHENTICATION

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


------------------------------------------------------------------------------
EMC VNX: the world's simplest storage, starting under $10K
The only unified storage solution that offers unified management 
Up to 160% more powerful than alternatives and 25% more efficient. 
Guaranteed. http://p.sf.net/sfu/emc-vnx-dev2dev
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits

Reply via email to