Revision: 1658
http://mrbs.svn.sourceforge.net/mrbs/?rev=1658&view=rev
Author: cimorrison
Date: 2010-12-02 10:15:22 +0000 (Thu, 02 Dec 2010)
Log Message:
-----------
Switched to using globally unique ids for the iCalendar uids.
Modified Paths:
--------------
mrbs/branches/ics_attachments/web/dbsys.inc
mrbs/branches/ics_attachments/web/edit_entry.php
mrbs/branches/ics_attachments/web/edit_entry_handler.php
mrbs/branches/ics_attachments/web/functions_mail.inc
mrbs/branches/ics_attachments/web/internalconfig.inc.php
mrbs/branches/ics_attachments/web/mrbs_sql.inc
mrbs/branches/ics_attachments/web/systemdefaults.inc.php
Added Paths:
-----------
mrbs/branches/ics_attachments/web/upgrade/23/
mrbs/branches/ics_attachments/web/upgrade/23/mysql.sql
mrbs/branches/ics_attachments/web/upgrade/23/pgsql.sql
Modified: mrbs/branches/ics_attachments/web/dbsys.inc
===================================================================
--- mrbs/branches/ics_attachments/web/dbsys.inc 2010-11-30 16:08:14 UTC (rev
1657)
+++ mrbs/branches/ics_attachments/web/dbsys.inc 2010-12-02 10:15:22 UTC (rev
1658)
@@ -15,7 +15,7 @@
$tbl_variables = $db_tbl_prefix . "variables";
-$db_schema_version = 22;
+$db_schema_version = 23;
$local_db_schema_version = 1;
Modified: mrbs/branches/ics_attachments/web/edit_entry.php
===================================================================
--- mrbs/branches/ics_attachments/web/edit_entry.php 2010-11-30 16:08:14 UTC
(rev 1657)
+++ mrbs/branches/ics_attachments/web/edit_entry.php 2010-12-02 10:15:22 UTC
(rev 1658)
@@ -204,12 +204,32 @@
case 'info_user':
case 'info_text':
break;
-
+
+ // These columns cannot be made private
+ case 'room_id':
+ // We need to preserve the original room_id for existing bookings and
pass
+ // it through to edit_entry_handler. We need this because we need
to know
+ // in edit_entry_handler which room contains the original booking.
It's
+ // possible in this form to select multiple rooms, or even change the
room.
+ // We will need to know which booking is the "original booking"
because the
+ // original booking will keep the same ical_uid and have the
ical_sequence
+ // incremented, whereas new bookings will have a new ical_uid and
start with
+ // an ical_sequence of 0. (If there is more than one room when we
get to
+ // edit_entry_handler and the original room isn't among them, then we
will
+ // just have to make an arbitrary choice as to which is the room
containing
+ // the original booking.)
+ $original_room_id = $row['room_id'];
+ case 'ical_uid':
+ case 'ical_sequence':
+ case 'entry_type':
+ $$column = $row[$column];
+ break;
+
+ // These columns can be made private [not sure about 'type' though -
haven't
+ // checked whether it makes sense/works to make the 'type' column
private]
case 'name':
case 'description':
case 'type':
- case 'room_id':
- case 'entry_type':
$$column = ($keep_private && $is_private_field["entry.$column"]) ? ''
: $row[$column];
break;
@@ -318,12 +338,12 @@
else
{
// It is a new booking. The data comes from whichever button the user clicked
- $edit_type = "series";
- $name = "";
- $create_by = $user;
- $description = "";
- $type = $default_type;
- $room_id = $room;
+ $edit_type = "series";
+ $name = "";
+ $create_by = $user;
+ $description = "";
+ $type = $default_type;
+ $room_id = $room;
$rep_id = 0;
$rep_type = REP_NONE;
$rep_end_day = $day;
@@ -1160,7 +1180,19 @@
<input type="hidden" name="create_by" value="<?php echo $create_by?>">
<input type="hidden" name="rep_id" value="<?php echo $rep_id?>">
<input type="hidden" name="edit_type" value="<?php echo $edit_type?>">
- <?php
+ <?php
+ // The original_room_id will only be set if this was an existing booking.
+ // If it is an existing booking then edit_entry_handler needs to know the
+ // original room id and the ical_uid and the ical_sequence, because it will
+ // have to keep the ical_uid and increment the ical_sequence for the room
that
+ // contained the original booking. If it's a new booking it will generate
a new
+ // ical_uid and start the ical_sequence at 0.
+ if (isset($original_room_id))
+ {
+ echo "<input type=\"hidden\" name=\"original_room_id\"
value=\"$original_room_id\">\n";
+ echo "<input type=\"hidden\" name=\"ical_uid\" value=\"$ical_uid\">\n";
+ echo "<input type=\"hidden\" name=\"ical_sequence\"
value=\"$ical_sequence\">\n";
+ }
if(isset($id) && !isset($copy))
{
echo "<input type=\"hidden\" name=\"id\" value=\"$id\">\n";
Modified: mrbs/branches/ics_attachments/web/edit_entry_handler.php
===================================================================
--- mrbs/branches/ics_attachments/web/edit_entry_handler.php 2010-11-30
16:08:14 UTC (rev 1657)
+++ mrbs/branches/ics_attachments/web/edit_entry_handler.php 2010-12-02
10:15:22 UTC (rev 1658)
@@ -4,6 +4,44 @@
require_once "defaultincludes.inc";
require_once "mrbs_sql.inc";
+// Generate a globally unique id for use with iCalendar
+//
+// "A good method to assure uniqueness is to put the
+// domain name or a domain literal IP address of the host on which
+// the identifier was created on the right-hand side of an "@", and
+// on the left-hand side, put a combination of the current calendar
+// date and time of day (i.e., formatted in as a DATE-TIME value)
+// along with some other currently unique (perhaps sequential)
+// identifier available on the system (for example, a process id
+// number)." (RFC 5545)
+//
+// We will generate a uid of the form "mrbs-uniqid-md5h...@domain_name"
+// where uniqid is time based and is generated by uniqid() and the
+// MD5hash is the first 8 characters of the MD5 hash of the $str -
+// typically this will be something specific to the booking such as
+// the brief description.
+function generate_ical_uid($str)
+{
+ $uid = uniqid('MRBS-');
+ $uid .= "-" . substr(md5($str), 0, 8);
+ $uid .= "@";
+ // Add on the domain name if possible, if not the server name,
+ // otherwise 'MRBS'
+ if (empty($_SERVER['SERVER_NAME']))
+ {
+ $uid .= 'MRBS';
+ }
+ elseif (strpos($_SERVER['SERVER_NAME'], 'www.') === 0)
+ {
+ $uid .= substr($_SERVER['SERVER_NAME'], 4);
+ }
+ else
+ {
+ $uid .= $_SERVER['SERVER_NAME'];
+ }
+ return $uid;
+}
+
// Get non-standard form variables
$create_by = get_form_var('create_by', 'string');
$name = get_form_var('name', 'string');
@@ -14,6 +52,9 @@
$all_day = get_form_var('all_day', 'string'); // bool, actually
$type = get_form_var('type', 'string');
$rooms = get_form_var('rooms', 'array');
+$original_room_id = get_form_var('original_room_id', 'int');
+$ical_uid = get_form_var('ical_uid', 'int');
+$ical_sequence = get_form_var('ical_sequence', 'int');
$returl = get_form_var('returl', 'string');
$rep_id = get_form_var('rep_id', 'int');
$edit_type = get_form_var('edit_type', 'string');
@@ -536,6 +577,37 @@
// Assemble the data in an array
$data = array();
+
+ // We need to work out whether this is the original booking being modified,
+ // because, if it is, we keep the ical_uid and increment the ical_sequence.
+ // We consider this to be the original booking if there was an original
+ // booking in the first place (in which case the original room id will be
set) and
+ // (a) this is the same room as the original booking
+ // or (b) there is only one room in the new set of bookings, in which
case
+ // what has happened is that the booking has been changed to be in
+ // a new room
+ // or (c) the new set of rooms does not include the original room, in
which
+ // case we will make the arbitrary assumption that the original
booking
+ // has been moved to the first room in the list and the bookings
in the
+ // other rooms are clones and will be treated as new bookings.
+
+ if (isset($original_room_id) &&
+ (($original_room_id == $room_id) ||
+ (count($rooms) == 1) ||
+ (($rooms[0] == $room_id) && !in_array($original_room_id, $rooms))))
+ {
+ // This is an existing booking which has been changed. Keep the
+ // original ical_uid and increment the sequence number.
+ $data['ical_uid'] = $ical_uid;
+ $data['ical_sequence'] = $ical_sequence + 1;
+ }
+ else
+ {
+ // This is a new booking. We generate a new ical_uid and start
+ // the sequence at 0.
+ $data['ical_uid'] = generate_ical_uid($name);
+ $data['ical_sequence'] = 0;
+ }
$data['start_time'] = $starttime;
$data['end_time'] = $endtime;
$data['room_id'] = $room_id;
Modified: mrbs/branches/ics_attachments/web/functions_mail.inc
===================================================================
--- mrbs/branches/ics_attachments/web/functions_mail.inc 2010-11-30
16:08:14 UTC (rev 1657)
+++ mrbs/branches/ics_attachments/web/functions_mail.inc 2010-12-02
10:15:22 UTC (rev 1658)
@@ -16,8 +16,6 @@
//
// $Id$
-define ('RFC5545_FORMAT', 'Ymd\THis'); // Format for expressing Vcalendar
dates
-
// {{{ convertToMailCharset()
/**
@@ -382,8 +380,8 @@
// The event
$results[] = "BEGIN:VEVENT";
- $results[] = "UID:" . $data['id']; // STILL TO DO: make this globally
unique
- $results[] = "DTSTAMP:" . gmdate(RFC5545_FORMAT . '\Z');
+ $results[] = "UID:" . $data['ical_uid']; // compulsory
+ $results[] = "DTSTAMP:" . gmdate(RFC5545_FORMAT . '\Z'); // compulsory
if ($series)
{
$results[] = "RRULE:" . create_rrule($data);
@@ -393,11 +391,7 @@
$results[] = "SUMMARY:" . $data['name'];
$results[] = "DESCRIPTION:" . $data['description'];
$results[] = "LOCATION:" . $data['area_name'] . " - " . $data['room_name'];
- // Set the Sequence number to be 0, unless we are cancelling in which case
- // it will be 1 (the next in sequence). This works because if an event is
- // modified it gets a new id, rather than keeping the same id and having the
- // sequence number incremented.
- $results[] = "SEQUENCE:" . (($method=="CANCEL") ? "1" : "0");
+ $results[] = "SEQUENCE:" . $data['ical_sequence'];
if ($confirmation_enabled)
{
$results[] = "STATUS:". (($data['status'] & STATUS_TENTATIVE) ?
"TENTATIVE" : "CONFIRMED");
@@ -763,7 +757,7 @@
// Create the iCalendar if required
$attachment = array();
- if ($mail_settings['ics'])
+ if ($mail_settings['icalendar'])
{
$attachment['method'] = "REQUEST";
$attachment['content'] = create_icalendar($data, $attachment['method'],
$series);
@@ -960,7 +954,7 @@
// Set up the attachment
$attachment = array();
- if ($mail_settings['ics'])
+ if ($mail_settings['icalendar'])
{
$attachment['method'] = "CANCEL";
$attachment['content'] = create_icalendar($mail_previous,
$attachment['method'], $series);
@@ -1195,7 +1189,7 @@
// do something
}
- if ($mail_settings['ics'])
+ if ($mail_settings['icalendar'])
{
// Add the text version of the iCalendar
$mime_params['content_type'] = "text/calendar; method=" .
$attachment['method'];
Modified: mrbs/branches/ics_attachments/web/internalconfig.inc.php
===================================================================
--- mrbs/branches/ics_attachments/web/internalconfig.inc.php 2010-11-30
16:08:14 UTC (rev 1657)
+++ mrbs/branches/ics_attachments/web/internalconfig.inc.php 2010-12-02
10:15:22 UTC (rev 1658)
@@ -114,6 +114,14 @@
define('REP_MONTHLY_SAMEDAY', 5);
define('REP_N_WEEKLY', 6);
+
+/***************************************************
+ * iCalendar constants - internal use, do not change
+ ***************************************************/
+
+define ('RFC5545_FORMAT', 'Ymd\THis'); // Format for expressing iCalendar
dates
+
+
/****************************************************************
* DATABASE TABLES - internal use, do not change
****************************************************************/
@@ -141,7 +149,9 @@
'reminded',
'info_time',
'info_user',
- 'info_text');
+ 'info_text',
+ 'ical_uid',
+ 'ical_sequence');
$standard_fields['repeat'] = array('id',
'start_time',
@@ -160,7 +170,9 @@
'reminded',
'info_time',
'info_user',
- 'info_text');
+ 'info_text',
+ 'ical_uid',
+ 'ical_sequence');
$standard_fields['room'] = array('id',
'disabled',
Modified: mrbs/branches/ics_attachments/web/mrbs_sql.inc
===================================================================
--- mrbs/branches/ics_attachments/web/mrbs_sql.inc 2010-11-30 16:08:14 UTC
(rev 1657)
+++ mrbs/branches/ics_attachments/web/mrbs_sql.inc 2010-12-02 10:15:22 UTC
(rev 1658)
@@ -254,6 +254,7 @@
case 'end_date':
case 'room_id':
case 'status':
+ case 'ical_sequence':
$sql_col[] = $key;
$sql_val[] = $data[$key];
break;
@@ -263,6 +264,7 @@
case 'name':
case 'type':
case 'description':
+ case 'ical_uid':
$sql_col[] = $key;
$sql_val[] = "'" . addslashes($data[$key]) . "'";
break;
Modified: mrbs/branches/ics_attachments/web/systemdefaults.inc.php
===================================================================
--- mrbs/branches/ics_attachments/web/systemdefaults.inc.php 2010-11-30
16:08:14 UTC (rev 1657)
+++ mrbs/branches/ics_attachments/web/systemdefaults.inc.php 2010-12-02
10:15:22 UTC (rev 1658)
@@ -769,10 +769,10 @@
// -------------
// These settings determine what should be included in the email
// Set to TRUE or FALSE as required
-$mail_settings['details'] = FALSE; // Set to TRUE if you want full booking
details;
- // otherwise you just get a link to the
entry
-$mail_settings['ics'] = FALSE; // Set to TRUE to include a .ics attachment
- // which can be imported into a calendar
+$mail_settings['details'] = FALSE; // Set to TRUE if you want full booking
details;
+ // otherwise you just get a link to the
entry
+$mail_settings['icalendar'] = FALSE; // Set to TRUE to include iCalendar
details
+ // which can be imported into a calendar
// HOW TO EMAIL - CHARACTER SET AND LANGUAGE
// -----------------------------------------
Added: mrbs/branches/ics_attachments/web/upgrade/23/mysql.sql
===================================================================
--- mrbs/branches/ics_attachments/web/upgrade/23/mysql.sql
(rev 0)
+++ mrbs/branches/ics_attachments/web/upgrade/23/mysql.sql 2010-12-02
10:15:22 UTC (rev 1658)
@@ -0,0 +1,11 @@
+# $Id$
+
+# Add UID and SEQUENCE columns for use with iCalendar
+
+ALTER TABLE %DB_TBL_PREFIX%entry
+ADD COLUMN ical_uid varchar(255) DEFAULT '' NOT NULL,
+ADD COLUMN ical_sequence smallint DEFAULT 0 NOT NULL;
+
+ALTER TABLE %DB_TBL_PREFIX%repeat
+ADD COLUMN ical_uid varchar(255) DEFAULT '' NOT NULL,
+ADD COLUMN ical_sequence smallint DEFAULT 0 NOT NULL;
Property changes on: mrbs/branches/ics_attachments/web/upgrade/23/mysql.sql
___________________________________________________________________
Added: svn:keywords
+ Id
Added: svn:eol-style
+ native
Added: mrbs/branches/ics_attachments/web/upgrade/23/pgsql.sql
===================================================================
--- mrbs/branches/ics_attachments/web/upgrade/23/pgsql.sql
(rev 0)
+++ mrbs/branches/ics_attachments/web/upgrade/23/pgsql.sql 2010-12-02
10:15:22 UTC (rev 1658)
@@ -0,0 +1,11 @@
+-- $Id$
+
+-- Add UID and SEQUENCE columns for use with iCalendar
+
+ALTER TABLE %DB_TBL_PREFIX%entry
+ADD COLUMN ical_uid varchar(255) DEFAULT '' NOT NULL,
+ADD COLUMN ical_sequence smallint DEFAULT 0 NOT NULL;
+
+ALTER TABLE %DB_TBL_PREFIX%repeat
+ADD COLUMN ical_uid varchar(255) DEFAULT '' NOT NULL,
+ADD COLUMN ical_sequence smallint DEFAULT 0 NOT NULL;
Property changes on: mrbs/branches/ics_attachments/web/upgrade/23/pgsql.sql
___________________________________________________________________
Added: svn:keywords
+ Id
Added: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Increase Visibility of Your 3D Game App & Earn a Chance To Win $500!
Tap into the largest installed PC base & get more eyes on your game by
optimizing for Intel(R) Graphics Technology. Get started today with the
Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs.
http://p.sf.net/sfu/intelisp-dev2dev
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits