Revision: 1663
http://mrbs.svn.sourceforge.net/mrbs/?rev=1663&view=rev
Author: cimorrison
Date: 2010-12-02 15:06:26 +0000 (Thu, 02 Dec 2010)
Log Message:
-----------
- Added the full details (including custom fields) to the iCalendar description.
- Added escaping of text fields in the iCalendar object
Modified Paths:
--------------
mrbs/branches/ics_attachments/web/functions_mail.inc
Modified: mrbs/branches/ics_attachments/web/functions_mail.inc
===================================================================
--- mrbs/branches/ics_attachments/web/functions_mail.inc 2010-12-02
12:24:14 UTC (rev 1662)
+++ mrbs/branches/ics_attachments/web/functions_mail.inc 2010-12-02
15:06:26 UTC (rev 1663)
@@ -291,6 +291,264 @@
return $email;
}
+
+function create_text_body($data, $new_entry, $new_id, $series, $action)
+{
+ global $mail_previous, $note, $returl;
+ global $enable_periods, $approval_enabled, $confirmation_enabled;
+ global $typel, $mail_settings, $standard_fields, $weekstarts, $url_base;
+ global $tbl_entry;
+
+ // set up the body
+ switch ($action)
+ {
+ case "approve":
+ $body = get_mail_vocab("mail_body_approved") . "\n\n";
+ break;
+ case "more_info":
+ $body = get_mail_vocab("mail_body_more_info") . "\n\n";
+ $body .= get_mail_vocab("info_requested") . ": ";
+ $body .= convertToMailCharset($note) . "\n\n";
+ break;
+ case "remind":
+ $body = get_mail_vocab("mail_body_reminder") . "\n\n";
+ break;
+ default:
+ if ($new_entry)
+ {
+ $body = get_mail_vocab("mail_body_new_entry") . "\n\n";
+ }
+ else
+ {
+ $body = get_mail_vocab("mail_body_changed_entry") . "\n\n";
+ }
+ break;
+ }
+
+ // Set the link to view entry page
+ if (isset($url_base) && ($url_base != ""))
+ {
+ $body .= "$url_base/view_entry.php?id=$new_id";
+ }
+ else
+ {
+ ('' != $returl) ? $url = explode(basename($returl), $returl) : '';
+ $body .= $url[0] . "view_entry.php?id=$new_id";
+ }
+ if ($series)
+ {
+ $body .= "&series=1";
+ }
+ $body .= "\n";
+ // Displays/don't displays entry details
+ if ($mail_settings['details'])
+ {
+ $body .= "\n" . get_mail_vocab("namebooker") . ": ";
+ $body .= compareEntries(convertToMailCharset($data['name']),
+ convertToMailCharset($mail_previous['namebooker']),
+ $new_entry) . "\n";
+
+ // Description:
+ $body .= get_mail_vocab("description") . ": ";
+ $body .= compareEntries(convertToMailCharset($data['description']),
+
convertToMailCharset($mail_previous['description']),
+ $new_entry) . "\n";
+
+ if ($confirmation_enabled)
+ {
+ // Confirmation status:
+ $body .= get_mail_vocab("confirmation_status") . ": ";
+ $old_status = ($mail_previous['status'] & STATUS_TENTATIVE) ?
get_mail_vocab("tentative") : get_mail_vocab("confirmed");
+ $new_status = ($data['status'] & STATUS_TENTATIVE) ?
get_mail_vocab("tentative") : get_mail_vocab("confirmed");
+ $body .= compareEntries($new_status, $old_status, $new_entry) . "\n";
+ }
+
+ if ($approval_enabled)
+ {
+ // Approval status:
+ $body .= get_mail_vocab("approval_status") . ": ";
+ $old_status = ($mail_previous['status'] & STATUS_AWAITING_APPROVAL) ?
get_mail_vocab("awaiting_approval") : get_mail_vocab("approved");
+ $new_status = ($data['status'] & STATUS_AWAITING_APPROVAL) ?
get_mail_vocab("awaiting_approval") : get_mail_vocab("approved");
+ $body .= compareEntries($new_status, $old_status, $new_entry) . "\n";
+ }
+
+ // Room:
+ $body .= get_mail_vocab("room") . ": " .
+ compareEntries(convertToMailCharset($data['area_name']),
+ convertToMailCharset($mail_previous['area_name']),
+ $new_entry);
+ $body .= " - " . compareEntries(convertToMailCharset($data['room_name']),
+
convertToMailCharset($mail_previous['room_name']),
+ $new_entry) . "\n";
+
+ // Start time
+ if ($enable_periods)
+ {
+ list( $start_period, $entry_start_date) =
getMailPeriodDateString($data['start_time']);
+ }
+ else
+ {
+ $entry_start_date = getMailTimeDateString($data['start_time']);
+ }
+ $body .= get_mail_vocab("start_date") . ": ";
+ $body .= compareEntries($entry_start_date,
+ $mail_previous['entry_start_date'],
+ $new_entry) . "\n";
+
+ // Duration
+ $body .= get_mail_vocab("duration") . ": " .
+ compareEntries($data['duration'],
+ $mail_previous['duration'],
+ $new_entry);
+ $body .= " " . compareEntries(get_mail_vocab($data['dur_units']),
+ $mail_previous['dur_units'],
+ $new_entry) . "\n";
+
+ // End time
+ $myendtime = $data['end_time'];
+ if ( $enable_periods )
+ {
+ list($end_period, $entry_end_date) =
getMailPeriodDateString($myendtime, -1);
+ }
+ else
+ {
+ $entry_end_date = getMailTimeDateString($myendtime);
+ }
+ $body .= get_mail_vocab("end_date") . ": ";
+ $body .= compareEntries($entry_end_date,
+ $mail_previous['entry_end_date'],
+ $new_entry) ."\n";
+
+ // Type of booking
+ $body .= get_mail_vocab("type") . ": ";
+ if ($new_entry)
+ {
+ $body .= $typel[$data['type']];
+ }
+ else
+ {
+ $temp = $mail_previous['type'];
+ $body .= compareEntries($typel[$data['type']],
+ $typel[$temp],
+ $new_entry);
+ }
+
+ // Created by
+ $body .= "\n" . get_mail_vocab("createdby") . ": " .
+ compareEntries(convertToMailCharset($data['create_by']),
+ convertToMailCharset($mail_previous['createdby']),
+ $new_entry) . "\n";
+
+ // Custom fields
+ $fields = sql_field_info($tbl_entry);
+ foreach ($fields as $field)
+ {
+ if (!in_array($field['name'], $standard_fields['entry']))
+ {
+ $key = $field['name'];
+ $value = (isset($data['custom_fields'][$key])) ?
$data['custom_fields'][$key] : '';
+ // Convert any booleans or pseudo-booleans to text strings (in the
mail language)
+ if (($field['nature'] == 'boolean') ||
+ (($field['nature'] == 'integer') && isset($field['length']) &&
($field['length'] <= 2)) )
+ {
+ $value = ($value) ? get_mail_vocab("yes") : get_mail_vocab("no");
+ if (!$new_entry)
+ {
+ $mail_previous[$key] = ($mail_previous[$key]) ?
get_mail_vocab("yes") : get_mail_vocab("no");
+ }
+ }
+ $body .= get_mail_field_name($tbl_entry, $key) . ": ";
+ $body .= compareEntries(convertToMailCharset($value),
+ convertToMailCharset($mail_previous[$key]),
+ $new_entry) . "\n";
+ }
+ }
+
+ // Last updated
+ $body .= get_mail_vocab("lastupdate") . ": " .
+ compareEntries(getMailTimeDateString(time()),
+ $mail_previous['updated'],
+ $new_entry);
+
+ // Repeat Type
+ $body .= "\n" . get_mail_vocab("rep_type");
+ if ($new_entry)
+ {
+ $body .= ": " . get_mail_vocab("rep_type_" . $data['rep_type']);
+ }
+ else
+ {
+ $temp = $mail_previous['rep_type'];
+ $body .= ": " . compareEntries(get_mail_vocab("rep_type_" .
$data['rep_type']),
+ get_mail_vocab("rep_type_$temp"),
+ $new_entry);
+ }
+
+ // Details if a series
+ if ($data['rep_type'] != REP_NONE)
+ {
+ $opt = "";
+ if (($data['rep_type'] == REP_WEEKLY) || ($data['rep_type'] ==
REP_N_WEEKLY))
+ {
+ // Display day names according to language and preferred weekday start.
+ for ($i = 0; $i < 7; $i++)
+ {
+ $daynum = ($i + $weekstarts) % 7;
+ if ($data['rep_opt'][$daynum])
+ {
+ $opt .= day_name($daynum) . " ";
+ }
+ }
+ }
+ if ($data['rep_type'] == REP_N_WEEKLY)
+ {
+ $body .= "\n" . get_mail_vocab("rep_num_weeks");
+ $body .= ": " . compareEntries($data['rep_num_weeks'],
+ $mail_previous["rep_num_weeks"],
+ $new_entry);
+ }
+
+ if($opt || $mail_previous["rep_opt_list"])
+ {
+ $body .= "\n" . get_mail_vocab("rep_rep_day");
+ $body .= ": " . compareEntries($opt,
+ $mail_previous["rep_opt_list"],
+ $new_entry);
+ }
+
+ $body .= "\n" . get_mail_vocab("rep_end_date");
+ if ($new_entry)
+ {
+ $body .= ": " . getMailTimeDateString($data['end_date'], FALSE);
+ }
+ else
+ {
+ $temp = getMailTimeDateString($data['end_date'], FALSE);
+ $body .= ": " .
+ compareEntries($temp,
+ getMailTimeDateString($mail_previous['end_date'],
FALSE),
+ $new_entry) . "\n";
+ }
+ }
+ $body .= "\n";
+ }
+ return $body;
+}
+
+// Escape text for use in an iCalendar object
+function ical_escape_text($str)
+{
+ // Escape '\'
+ $str = str_replace("\\", "\\\\", $str);
+ // Escape ';'
+ $str = str_replace(";", "\;", $str);
+ // Escape ','
+ $str = str_replace(",", "\,", $str);
+ // Escape '\n'
+ $str = str_replace("\n", "\\n", $str);
+ return $str;
+}
+
// Create an iCalendar Recurrence Rule
function create_rrule($data)
{
@@ -356,12 +614,12 @@
}
$rule .= ";UNTIL=" . gmdate(RFC5545_FORMAT . '\Z', $data['end_date']);
-
return $rule;
}
+
// Creates an iCalendar object in RFC 5545 format
-function create_icalendar($data, $method, $series=FALSE)
+function create_icalendar($method, $data, $description, $series=FALSE)
{
require_once "version.inc";
@@ -388,9 +646,9 @@
}
$results[] = "DTSTART;TZID=$timezone:" . date(RFC5545_FORMAT,
$data['start_time']);
$results[] = "DTEND;TZID=$timezone:" . date(RFC5545_FORMAT,
$data['end_time']);
- $results[] = "SUMMARY:" . $data['name'];
- $results[] = "DESCRIPTION:" . $data['description'];
- $results[] = "LOCATION:" . $data['area_name'] . " - " . $data['room_name'];
+ $results[] = "SUMMARY:" . ical_escape_text($data['name']);
+ $results[] = "DESCRIPTION:" . ical_escape_text($description);
+ $results[] = "LOCATION:" . ical_escape_text($data['area_name'] . " - " .
$data['room_name']);
$results[] = "SEQUENCE:" . $data['ical_sequence'];
// If this is an individual member of a series then set the recurrence id
if ($data['entry_type'] == 2)
@@ -407,7 +665,7 @@
$result = implode($eol, $results);
$result .= $eol; // Has to end with a CRLF
-
+
return $result;
}
@@ -424,11 +682,8 @@
*/
function notifyAdminOnBooking($new_entry, $new_id, $series, $action="book")
{
- global $data, $mail_previous, $note;
- global $url_base, $returl;
- global $auth, $weekstarts, $typel, $mail_settings, $standard_fields;
- global $enable_periods, $approval_enabled, $confirmation_enabled;
- global $tbl_entry;
+ global $data, $mail_previous;
+ global $auth, $mail_settings, $approval_enabled;
$recipients = array();
$cc = array();
@@ -521,251 +776,39 @@
$recipient_list = get_address_list($recipients);
$cc_list = get_address_list($cc);
- // set up the subject and body
+ // set up the subject
switch ($action)
{
case "approve":
$subject = get_mail_vocab("mail_subject_approved");
- $body = get_mail_vocab("mail_body_approved") . "\n\n";
break;
case "more_info":
$subject = get_mail_vocab("mail_subject_more_info");
- $body = get_mail_vocab("mail_body_more_info") . "\n\n";
- $body .= get_mail_vocab("info_requested") . ": ";
- $body .= convertToMailCharset($note) . "\n\n";
break;
case "remind":
$subject = get_mail_vocab("mail_subject_reminder");
- $body = get_mail_vocab("mail_body_reminder") . "\n\n";
break;
default:
if ($new_entry)
{
$subject = get_mail_vocab("mail_subject_new_entry");
- $body = get_mail_vocab("mail_body_new_entry") . "\n\n";
}
else
{
$subject = get_mail_vocab("mail_subject_changed_entry");
- $body = get_mail_vocab("mail_body_changed_entry") . "\n\n";
}
break;
}
- // Set the link to view entry page
- if (isset($url_base) && ($url_base != ""))
- {
- $body .= "$url_base/view_entry.php?id=$new_id";
- }
- else
- {
- ('' != $returl) ? $url = explode(basename($returl), $returl) : '';
- $body .= $url[0] . "view_entry.php?id=$new_id";
- }
- if ($series)
- {
- $body .= "&series=1";
- }
- $body .= "\n";
- // Displays/don't displays entry details
- if ($mail_settings['details'])
- {
- $body .= "\n" . get_mail_vocab("namebooker") . ": ";
- $body .= compareEntries(convertToMailCharset($data['name']),
- convertToMailCharset($mail_previous['namebooker']),
- $new_entry) . "\n";
-
- // Description:
- $body .= get_mail_vocab("description") . ": ";
- $body .= compareEntries(convertToMailCharset($data['description']),
-
convertToMailCharset($mail_previous['description']),
- $new_entry) . "\n";
-
- if ($confirmation_enabled)
- {
- // Confirmation status:
- $body .= get_mail_vocab("confirmation_status") . ": ";
- $old_status = ($mail_previous['status'] & STATUS_TENTATIVE) ?
get_mail_vocab("tentative") : get_mail_vocab("confirmed");
- $new_status = ($data['status'] & STATUS_TENTATIVE) ?
get_mail_vocab("tentative") : get_mail_vocab("confirmed");
- $body .= compareEntries($new_status, $old_status, $new_entry) . "\n";
- }
-
- if ($approval_enabled)
- {
- // Approval status:
- $body .= get_mail_vocab("approval_status") . ": ";
- $old_status = ($mail_previous['status'] & STATUS_AWAITING_APPROVAL) ?
get_mail_vocab("awaiting_approval") : get_mail_vocab("approved");
- $new_status = ($data['status'] & STATUS_AWAITING_APPROVAL) ?
get_mail_vocab("awaiting_approval") : get_mail_vocab("approved");
- $body .= compareEntries($new_status, $old_status, $new_entry) . "\n";
- }
-
- // Room:
- $body .= get_mail_vocab("room") . ": " .
- compareEntries(convertToMailCharset($data['area_name']),
- convertToMailCharset($mail_previous['area_name']),
- $new_entry);
- $body .= " - " . compareEntries(convertToMailCharset($data['room_name']),
-
convertToMailCharset($mail_previous['room_name']),
- $new_entry) . "\n";
-
- // Start time
- if ($enable_periods)
- {
- list( $start_period, $entry_start_date) =
getMailPeriodDateString($data['start_time']);
- }
- else
- {
- $entry_start_date = getMailTimeDateString($data['start_time']);
- }
- $body .= get_mail_vocab("start_date") . ": ";
- $body .= compareEntries($entry_start_date,
- $mail_previous['entry_start_date'],
- $new_entry) . "\n";
-
- // Duration
- $body .= get_mail_vocab("duration") . ": " .
- compareEntries($data['duration'],
- $mail_previous['duration'],
- $new_entry);
- $body .= " " . compareEntries(get_mail_vocab($data['dur_units']),
- $mail_previous['dur_units'],
- $new_entry) . "\n";
-
- // End time
- $myendtime = $data['end_time'];
- if ( $enable_periods )
- {
- list($end_period, $entry_end_date) =
getMailPeriodDateString($myendtime, -1);
- }
- else
- {
- $entry_end_date = getMailTimeDateString($myendtime);
- }
- $body .= get_mail_vocab("end_date") . ": ";
- $body .= compareEntries($entry_end_date,
- $mail_previous['entry_end_date'],
- $new_entry) ."\n";
-
- // Type of booking
- $body .= get_mail_vocab("type") . ": ";
- if ($new_entry)
- {
- $body .= $typel[$data['type']];
- }
- else
- {
- $temp = $mail_previous['type'];
- $body .= compareEntries($typel[$data['type']],
- $typel[$temp],
- $new_entry);
- }
-
- // Created by
- $body .= "\n" . get_mail_vocab("createdby") . ": " .
- compareEntries(convertToMailCharset($data['create_by']),
- convertToMailCharset($mail_previous['createdby']),
- $new_entry) . "\n";
-
- // Custom fields
- $fields = sql_field_info($tbl_entry);
- foreach ($fields as $field)
- {
- if (!in_array($field['name'], $standard_fields['entry']))
- {
- $key = $field['name'];
- $value = (isset($data['custom_fields'][$key])) ?
$data['custom_fields'][$key] : '';
- // Convert any booleans or pseudo-booleans to text strings (in the
mail language)
- if (($field['nature'] == 'boolean') ||
- (($field['nature'] == 'integer') && isset($field['length']) &&
($field['length'] <= 2)) )
- {
- $value = ($value) ? get_mail_vocab("yes") : get_mail_vocab("no");
- if (!$new_entry)
- {
- $mail_previous[$key] = ($mail_previous[$key]) ?
get_mail_vocab("yes") : get_mail_vocab("no");
- }
- }
- $body .= get_mail_field_name($tbl_entry, $key) . ": ";
- $body .= compareEntries(convertToMailCharset($value),
- convertToMailCharset($mail_previous[$key]),
- $new_entry) . "\n";
- }
- }
-
- // Last updated
- $body .= get_mail_vocab("lastupdate") . ": " .
- compareEntries(getMailTimeDateString(time()),
- $mail_previous['updated'],
- $new_entry);
-
- // Repeat Type
- $body .= "\n" . get_mail_vocab("rep_type");
- if ($new_entry)
- {
- $body .= ": " . get_mail_vocab("rep_type_" . $data['rep_type']);
- }
- else
- {
- $temp = $mail_previous['rep_type'];
- $body .= ": " . compareEntries(get_mail_vocab("rep_type_" .
$data['rep_type']),
- get_mail_vocab("rep_type_$temp"),
- $new_entry);
- }
-
- // Details if a series
- if ($data['rep_type'] != REP_NONE)
- {
- $opt = "";
- if (($data['rep_type'] == REP_WEEKLY) || ($data['rep_type'] ==
REP_N_WEEKLY))
- {
- // Display day names according to language and preferred weekday start.
- for ($i = 0; $i < 7; $i++)
- {
- $daynum = ($i + $weekstarts) % 7;
- if ($data['rep_opt'][$daynum])
- {
- $opt .= day_name($daynum) . " ";
- }
- }
- }
- if ($data['rep_type'] == REP_N_WEEKLY)
- {
- $body .= "\n" . get_mail_vocab("rep_num_weeks");
- $body .= ": " . compareEntries($data['rep_num_weeks'],
- $mail_previous["rep_num_weeks"],
- $new_entry);
- }
-
- if($opt || $mail_previous["rep_opt_list"])
- {
- $body .= "\n" . get_mail_vocab("rep_rep_day");
- $body .= ": " . compareEntries($opt,
- $mail_previous["rep_opt_list"],
- $new_entry);
- }
-
- $body .= "\n" . get_mail_vocab("rep_end_date");
- if ($new_entry)
- {
- $body .= ": " . getMailTimeDateString($data['end_date'], FALSE);
- }
- else
- {
- $temp = getMailTimeDateString($data['end_date'], FALSE);
- $body .= ": " .
- compareEntries($temp,
- getMailTimeDateString($mail_previous['end_date'],
FALSE),
- $new_entry) . "\n";
- }
- }
- $body .= "\n";
- }
+ // Create the text body
+ $body = create_text_body($data, $new_entry, $new_id, $series, $action);
// Create the iCalendar if required
$attachment = array();
if ($mail_settings['icalendar'])
{
$attachment['method'] = "REQUEST";
- $attachment['content'] = create_icalendar($data, $attachment['method'],
$series);
+ $attachment['content'] = create_icalendar($attachment['method'], $data,
$body, $series);
$attachment['name'] = "meeting.ics";
}
@@ -962,7 +1005,7 @@
if ($mail_settings['icalendar'])
{
$attachment['method'] = "CANCEL";
- $attachment['content'] = create_icalendar($mail_previous,
$attachment['method'], $series);
+ $attachment['content'] = create_icalendar($attachment['method'],
$mail_previous, $mail_previous['description'], $series);
$attachment['name'] = "meeting.ics";
}
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