Revision: 1905
          http://mrbs.svn.sourceforge.net/mrbs/?rev=1905&view=rev
Author:   cimorrison
Date:     2011-08-29 18:15:19 +0000 (Mon, 29 Aug 2011)
Log Message:
-----------
Added list of skipped bookings to iCal notifications.  (Still to come - adding 
them to ordinary email notifications)

Modified Paths:
--------------
    mrbs/trunk/web/approve_entry_handler.php
    mrbs/trunk/web/edit_entry_handler.php
    mrbs/trunk/web/functions_ical.inc
    mrbs/trunk/web/functions_mail.inc

Modified: mrbs/trunk/web/approve_entry_handler.php
===================================================================
--- mrbs/trunk/web/approve_entry_handler.php    2011-08-29 12:04:28 UTC (rev 
1904)
+++ mrbs/trunk/web/approve_entry_handler.php    2011-08-29 18:15:19 UTC (rev 
1905)
@@ -99,7 +99,8 @@
     // so that we will kniow whether to include iCalendar information in the 
email)
     get_area_settings($data['area_id']);
     // Send the email
-    $result = notifyAdminOnBooking($data, $mail_previous, $is_new_entry, 
$series, $action, $note);
+    $skip_list = array();
+    $result = notifyAdminOnBooking($data, $skip_list, $mail_previous, 
$is_new_entry, $series, $action, $note);
   }
 }
 

Modified: mrbs/trunk/web/edit_entry_handler.php
===================================================================
--- mrbs/trunk/web/edit_entry_handler.php       2011-08-29 12:04:28 UTC (rev 
1904)
+++ mrbs/trunk/web/edit_entry_handler.php       2011-08-29 18:15:19 UTC (rev 
1905)
@@ -670,7 +670,7 @@
           $mail_previous = array();
         }
         // Send the email
-        $result = notifyAdminOnBooking($data, $mail_previous, !isset($id), 
$is_repeat_table);
+        $result = notifyAdminOnBooking($data, $skip_list, $mail_previous, 
!isset($id), $is_repeat_table);
       }
     }   
   } // end foreach $rooms

Modified: mrbs/trunk/web/functions_ical.inc
===================================================================
--- mrbs/trunk/web/functions_ical.inc   2011-08-29 12:04:28 UTC (rev 1904)
+++ mrbs/trunk/web/functions_ical.inc   2011-08-29 18:15:19 UTC (rev 1905)
@@ -414,13 +414,41 @@
 }
 
 
+// Create a comma separated list of dates for use with the EXDATE property.
+// The TZID parameter if used must be added separately
+function create_exdate_list($dates)
+{
+  global $vtimezone, $timezone;
+  
+  $results = array();
+  
+  foreach ($dates as $date)
+  {
+    if ($vtimezone === FALSE)
+    {
+      $results[] = gmdate(RFC5545_FORMAT . '\Z', $date);
+    }
+    else
+    {
+      $results[] = date(RFC5545_FORMAT, $date);
+    }
+  }
+  return implode(',', $results);
+}
+
+
 // Create an RFC 5545 iCalendar Event component
+//
+// $skip_list     an optional 7th parameter containing a 2D array of dates to
+//                skip in a series.  Indexed by room_id and start_time
 function create_ical_event($method, $data, $text_description, 
$html_description, $addresses, $series=FALSE)
 {
   require_once "functions_mail.inc";
   
   global $confirmation_enabled, $mail_settings, $timezone, $vtimezone;
   
+  $skip_list = (func_num_args() > 6) ? func_get_arg(6) : array();
+  
   $use_html = $mail_settings['html'] && !empty($html_description);
   
   $results = array();
@@ -463,6 +491,12 @@
   if ($series)
   {
     $results[] = "RRULE:" . create_rrule($data);
+    if (!empty($skip_list[$data['room_id']]))
+    {
+      $results[] = "EXDATE" . 
+                   (($vtimezone === FALSE) ? ":" : ";TZID=$timezone:") .
+                   create_exdate_list($skip_list[$data['room_id']]);
+    }
   }
   $results[] = "SUMMARY:" . ical_escape_text($data['name']);
   // Put the HTML version in an ALTREP, just in case there are any Calendars 
out there

Modified: mrbs/trunk/web/functions_mail.inc
===================================================================
--- mrbs/trunk/web/functions_mail.inc   2011-08-29 12:04:28 UTC (rev 1904)
+++ mrbs/trunk/web/functions_mail.inc   2011-08-29 18:15:19 UTC (rev 1905)
@@ -793,6 +793,8 @@
  * Send email to administrator to notify a new/changed entry.
  *
  * @param array   $data          contains the data for this entry
+ * @param array   $skip_list     a 2D array containing a list of dates in a 
series to skip
+ *                               indexed by room_id and start_time
  * @param array   $mail_previous contains the data for the previous entry, or 
is an empty array
  * @param bool    $new_entry     whether this is a new entry or not
  * @param bool    $series        whether this is a series or not
@@ -800,7 +802,7 @@
  * @param string  $note          a note that is used with "more_info"
  * @return bool                  TRUE or PEAR error object if fails
  */
-function notifyAdminOnBooking($data, $mail_previous, $new_entry, $series, 
$action="book", $note='')
+function notifyAdminOnBooking($data, &$skip_list, $mail_previous, $new_entry, 
$series, $action="book", $note='')
 {
   global $mail_settings, $enable_periods;
   
@@ -883,7 +885,7 @@
   {
     $attachment['method']   = "REQUEST";
     $ical_components = array();
-    $ical_components[] = create_ical_event($attachment['method'], $data, 
$text_body, $html_body, $addresses, $series);
+    $ical_components[] = create_ical_event($attachment['method'], $data, 
$text_body, $html_body, $addresses, $series, $skip_list);
     $attachment['content']  = create_icalendar($attachment['method'], 
$ical_components);
     $attachment['name']     = $mail_settings['ics_filename'] . ".ics";
   }

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