Revision: 2661
          https://sourceforge.net/p/mrbs/code/2661/
Author:   cimorrison
Date:     2013-01-26 15:14:20 +0000 (Sat, 26 Jan 2013)
Log Message:
-----------
Made import accept multiple rooms in the LOCATION property

Modified Paths:
--------------
    mrbs/branches/linked_bookings/web/functions.inc
    mrbs/branches/linked_bookings/web/import.php
    mrbs/branches/linked_bookings/web/lang/lang.en

Modified: mrbs/branches/linked_bookings/web/functions.inc
===================================================================
--- mrbs/branches/linked_bookings/web/functions.inc     2013-01-26 11:11:43 UTC 
(rev 2660)
+++ mrbs/branches/linked_bookings/web/functions.inc     2013-01-26 15:14:20 UTC 
(rev 2661)
@@ -1669,11 +1669,19 @@
 }
 
 
+
+// Gets the full room names for $rooms, which can be a single room_id or
+// an array of room_ids
 function get_full_room_names($rooms)
 {
   global $tbl_room, $tbl_area;
   global $area_room_separator;
   
+  if (!is_array($rooms))
+  {
+    $rooms = array($rooms);
+  }
+  
   $strings = array("A.area_name",
                    "'" . sql_escape($area_room_separator) . "'",
                    "R.room_name");

Modified: mrbs/branches/linked_bookings/web/import.php
===================================================================
--- mrbs/branches/linked_bookings/web/import.php        2013-01-26 11:11:43 UTC 
(rev 2660)
+++ mrbs/branches/linked_bookings/web/import.php        2013-01-26 15:14:20 UTC 
(rev 2661)
@@ -148,23 +148,27 @@
 }
 
 
-function get_room_ids($locations, &$error)
+function get_room_ids($locations, &$errors)
 {
-  global $location_separator;
+  global $location_delimiter;
   
   $room_ids = array();
-  $locations = explode($location_separator, $locations);
-  if (count($locations) > 1)
-  {
-    trigger_error("Multiple locations not yet supported", E_USER_WARNING);
-    // Need to think about what to do about making sure area characteristics
-    // are similar (and also what to do in MRBS generally about a linked 
booking
-    // when area characteristics change after the booking is made)
-  }
+  $locations = explode($location_delimiter, $locations);
+
   foreach ($locations as $location)
   {
-    $room_ids[] = get_room_id($location, $error);
+    $error = '';
+    $room_id = get_room_id($location, $error);
+    if ($room_id === FALSE)
+    {
+      $errors[] = $error;
+    }
+    else
+    {
+      $room_ids[] = $room_id;
+    }
   }
+  
   return $room_ids;
 }
 
@@ -173,7 +177,7 @@
 function process_event($vevent)
 {
   global $import_default_type, $skip;
-  global $morningstarts, $morningstarts_minutes, $resolution;
+  global $morningstarts, $morningstarts_minutes, $resolution, $enable_periods;
   
   // We are going to cache the settings ($resolution etc.) for the rooms
   // in order to avoid lots of database lookups
@@ -238,11 +242,11 @@
         $booking['description'] = $details['value'];
         break;
       case 'LOCATION':
-        $error = '';
-        $booking['rooms'] = get_room_ids($details['value'], $error);
-        if ($booking['rooms'] === FALSE)
+        $errors = array();
+        $booking['rooms'] = get_room_ids($details['value'], $errors);
+        if (!empty($errors))
         {
-          $problems[] = $error;
+          $problems = array_merge($problems, $errors);
         }
         break;
       case 'DTEND':
@@ -322,19 +326,37 @@
     $problems[] = get_vocab("no_LOCATION");
   }
   
-  if (empty($problems))
+  // Get the area settings for these rooms, if we haven't got them already
+  foreach ($booking['rooms'] as $room_id)
   {
-    // Get the area settings for these rooms, if we haven't got them already
-    foreach ($booking['rooms'] as $room_id)
+    if (!isset($room_settings[$room_id]))
     {
-      if (!isset($room_settings[$room_id]))
-      {
-        get_area_settings(get_area($room_id));
-        $room_settings[$room_id]['morningstarts'] = $morningstarts;
-        $room_settings[$room_id]['morningstarts_minutes'] = 
$morningstarts_minutes;
-        $room_settings[$room_id]['resolution'] = $resolution;
-      }
+      get_area_settings(get_area($room_id));
+      $room_settings[$room_id]['enable_periods'] = $enable_periods;
+      $room_settings[$room_id]['morningstarts'] = $morningstarts;
+      $room_settings[$room_id]['morningstarts_minutes'] = 
$morningstarts_minutes;
+      $room_settings[$room_id]['resolution'] = $resolution;
     }
+  }
+  // Check that the areas are suitable
+  foreach ($booking['rooms'] as $room_id)
+  {
+    // We don't know how to import into areas that use periods
+    if ($room_settings[$room_id]['enable_periods'])
+    {
+      $problems[] = get_vocab("cannot_import_into_periods") . " (" . 
get_full_room_names($room_id) . ")";
+    }
+    // All the areas for this linked booking must have the same key settings
+    if ($room_settings[$room_id] !== $room_settings[$booking['rooms'][0]])
+    {
+      $problems[] = get_vocab("area_settings_not_similar");
+    }
+  }
+  
+  if (empty($problems))
+  {
+    $room_id = $booking['rooms'][0];
+    
     // Round the start and end times to slot boundaries
     $date = getdate($booking['start_time']);
     $m = $date['mon'];
@@ -399,6 +421,7 @@
 $import = get_form_var('import', 'string');
 $area_room_order = get_form_var('area_room_order', 'string', 'area_room');
 $area_room_delimiter = get_form_var('area_room_delimiter', 'string', 
$area_room_separator);
+$location_delimiter = get_form_var('location_delimiter', 'string', 
$location_separator);
 $area_room_create = get_form_var('area_room_create', 'string', '0');
 $import_default_type = get_form_var('import_default_type', 'string', 
$default_type);
 $skip = get_form_var('skip', 'string', ((empty($skip_default)) ? '0' : '1'));
@@ -542,6 +565,14 @@
 echo "</div>\n";
 
 echo "<div>\n";
+$params = array('label'       => get_vocab("location_delimiter") . ':',
+                'label_title' => get_vocab("location_delimiter_note"),
+                'name'        => 'location_delimiter',
+                'value'       => $location_delimiter);
+generate_input($params);
+echo "</div>\n";
+
+echo "<div>\n";
 $params = array('label' => get_vocab("area_room_create") . ':',
                 'name'  => 'area_room_create',
                 'value' => $area_room_create);

Modified: mrbs/branches/linked_bookings/web/lang/lang.en
===================================================================
--- mrbs/branches/linked_bookings/web/lang/lang.en      2013-01-26 11:11:43 UTC 
(rev 2660)
+++ mrbs/branches/linked_bookings/web/lang/lang.en      2013-01-26 15:14:20 UTC 
(rev 2661)
@@ -464,10 +464,13 @@
 $vocab["area_room_order_note"]        = "The order of the area and room names 
in the LOCATION property";
 $vocab["area_room"]                   = "Area-Room";
 $vocab["room_area"]                   = "Room-Area";
-$vocab["area_room_delimiter"]         = "Delimiter";
+$vocab["area_room_delimiter"]         = "Area-room delimiter";
 $vocab["area_room_delimiter_note"]    = "The string separating the area and 
room names in the LOCATION property.  " .
                                         "If no delimiter is found MRBS will 
look for a unique room with the same " .
-                                        "name as the LOCATION";
+                                        "name as the LOCATION.";
+$vocab["location_delimiter"]          = "Location delimiter";
+$vocab["location_delimiter_note"]     = "The string separating multiple 
area-room names in the LOCATION property, " .
+                                        "used when a booking spans multiple 
rooms.";
 $vocab["area_room_create"]            = "Create rooms if necessary";
 $vocab["default_type"]                = "Default type";
 $vocab["room_does_not_exist_no_area"] = "room does not exist and cannot be 
added - no area given";
@@ -488,6 +491,8 @@
 $vocab["unsupported_INTERVAL"]        = "MRBS does not support INTERVAL>1 with 
FREQ=";
 $vocab["unsupported_COUNT"]           = "COUNT not yet supported by MRBS";
 $vocab["no_indefinite_repeats"]       = "Indefinite repeats not yet supported 
by MRBS";
+$vocab["cannot_import_into_periods"]  = "Cannot import into rooms using 
periods";
+$vocab["area_settings_not_similar"]   = "Cannot import into areas with 
different settings";
 $vocab["events_imported"]             = "events imported";
 $vocab["events_not_imported"]         = "events not imported";
 
------------------------------------------------------------------------------
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/learnnow-d2d
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits

Reply via email to