Revision: 1681
http://mrbs.svn.sourceforge.net/mrbs/?rev=1681&view=rev
Author: cimorrison
Date: 2010-12-09 14:37:48 +0000 (Thu, 09 Dec 2010)
Log Message:
-----------
Simplified code
Modified Paths:
--------------
mrbs/branches/ics_attachments/web/approve_entry_handler.php
mrbs/branches/ics_attachments/web/del_entry.php
mrbs/branches/ics_attachments/web/edit_entry_handler.php
mrbs/branches/ics_attachments/web/functions_mail.inc
mrbs/branches/ics_attachments/web/mrbs_sql.inc
Modified: mrbs/branches/ics_attachments/web/approve_entry_handler.php
===================================================================
--- mrbs/branches/ics_attachments/web/approve_entry_handler.php 2010-12-08
19:46:51 UTC (rev 1680)
+++ mrbs/branches/ics_attachments/web/approve_entry_handler.php 2010-12-09
14:37:48 UTC (rev 1681)
@@ -20,6 +20,9 @@
checkAuthorised();
$user = getUserName();
+// Initialise $mail_previous so that we can use it as a parameter for
notifyAdminOnBooking
+$mail_previous = array();
+
// Give the return URL a query string if it doesn't already have one
if (strpos($returl, '?') === FALSE)
{
@@ -51,7 +54,7 @@
{
$is_new_entry = FALSE;
// Get the current booking data, before we change anything, for use in
emails
- $mail_previous = getPreviousEntryData($id, $series);
+ $mail_previous = mrbsGetBookingInfo($id, $series);
}
$result = mrbsApproveEntry($id, $series);
if (!$result)
@@ -92,34 +95,7 @@
{
// Retrieve the booking details which we will need for the email
$data = mrbsGetBookingInfo($id, $series);
-
- // Process some special fields
- $data['duration'] = ($data['end_time'] - $data['start_time']) -
cross_dst($data['start_time'], $data['end_time']);
-
- if ($enable_periods)
- {
- list($start_period, $start_date) =
period_date_string($data['start_time']);
- }
- else
- {
- $start_date = time_date_string($data['start_time']);
- }
-
- if ($enable_periods)
- {
- list( , $end_date) = period_date_string($data['end_time'], -1);
- }
- else
- {
- $end_date = time_date_string($data['end_time']);
- }
-
- // The optional last parameters below are set to FALSE because we don't
want the units
- // translated - otherwise they will end up getting translated twice,
resulting
- // in an undefined index error.
- $enable_periods ? toPeriodString($start_period, $data['duration'],
$data['dur_units'], FALSE) : toTimeString($data['duration'],
$data['dur_units'], FALSE);
-
- $result = notifyAdminOnBooking($is_new_entry, $series, $action);
+ $result = notifyAdminOnBooking($data, $mail_previous, $is_new_entry,
$series, $action, $note);
}
}
Modified: mrbs/branches/ics_attachments/web/del_entry.php
===================================================================
--- mrbs/branches/ics_attachments/web/del_entry.php 2010-12-08 19:46:51 UTC
(rev 1680)
+++ mrbs/branches/ics_attachments/web/del_entry.php 2010-12-09 14:37:48 UTC
(rev 1681)
@@ -69,7 +69,7 @@
{
require_once "functions_mail.inc";
// Gather all fields values for use in emails.
- $mail_previous = getPreviousEntryData($id, FALSE);
+ $mail_previous = mrbsGetBookingInfo($id, FALSE);
// If this is an individual entry of a series then force the entry_type
// to be 2, so that when we create the iCalendar object we know that
// we only want to delete the individual entry
Modified: mrbs/branches/ics_attachments/web/edit_entry_handler.php
===================================================================
--- mrbs/branches/ics_attachments/web/edit_entry_handler.php 2010-12-08
19:46:51 UTC (rev 1680)
+++ mrbs/branches/ics_attachments/web/edit_entry_handler.php 2010-12-09
14:37:48 UTC (rev 1681)
@@ -632,21 +632,25 @@
$data['room_name'] = $row['room_name'];
$data['area_name'] = $row['area_name'];
}
- // If this is a modified entry then call
- // getPreviousEntryData to prepare entry comparison.
+ // If this is a modified entry then get the previous entry data
+ // so that we can highlight the changes
if (isset($id))
{
if ($edit_type == "series")
{
- $mail_previous = getPreviousEntryData($repeat_id, TRUE);
+ $mail_previous = mrbsGetBookingInfo($repeat_id, TRUE);
}
else
{
- $mail_previous = getPreviousEntryData($id, FALSE);
+ $mail_previous = mrbsGetBookingInfo($id, FALSE);
}
}
+ else
+ {
+ $mail_previous = array();
+ }
// Send the email
- $result = notifyAdminOnBooking(!isset($id), $is_repeat_table);
+ $result = notifyAdminOnBooking($data, $mail_previous, !isset($id),
$is_repeat_table);
}
}
} // end foreach $rooms
Modified: mrbs/branches/ics_attachments/web/functions_mail.inc
===================================================================
--- mrbs/branches/ics_attachments/web/functions_mail.inc 2010-12-08
19:46:51 UTC (rev 1680)
+++ mrbs/branches/ics_attachments/web/functions_mail.inc 2010-12-09
14:37:48 UTC (rev 1681)
@@ -154,6 +154,23 @@
}
}
+
+function getMailDateString($time)
+{
+ global $enable_periods;
+
+ if ($enable_periods)
+ {
+ list($entry_period, $entry_date) = getMailPeriodDateString($time);
+ }
+ else
+ {
+ $entry_date = getMailTimeDateString($time);
+ }
+ return $entry_date;
+}
+
+
function mail_strftime($format,$t)
{
$string = utf8_strftime($format,$t);
@@ -298,6 +315,28 @@
return $email;
}
+
+// Returns a list of repeat days as a string (eg "Thursday Friday")
+//
+// $rep_opt an array of repeat days or
+// a string of repeat days that can be used as an array
+function get_rep_day_list($rep_opt)
+{
+ global $weekstarts;
+
+ $rep_day_list = "";
+ for ($i = 0; $i < 7; $i++)
+ {
+ $daynum = ($i + $weekstarts) % 7;
+ if ($rep_opt[$daynum])
+ {
+ $rep_day_list .= day_name($daynum) . " ";
+ }
+ }
+ return $rep_day_list;
+}
+
+
function create_body_table_row($label, $new, $old, $compare, $as_html=FALSE)
{
$result = ($as_html) ? "<tr>\n" : "";
@@ -332,11 +371,11 @@
return $result;
}
-function create_body($data, $compare, $series, $action, $as_html=FALSE)
+function create_body($data, $compare, $series, $action, $as_html=FALSE,
$note='')
{
- global $mail_previous, $note, $returl, $mrbs_company;
+ global $mail_previous, $returl, $mrbs_company;
global $enable_periods, $approval_enabled, $confirmation_enabled;
- global $typel, $mail_settings, $standard_fields, $weekstarts, $url_base;
+ global $typel, $mail_settings, $standard_fields, $url_base;
global $tbl_entry;
// set up the body
@@ -491,40 +530,33 @@
$compare, $as_html);
// Start time
- if ($enable_periods)
- {
- list($start_period, $entry_start_date) =
getMailPeriodDateString($data['start_time']);
- }
- else
- {
- $entry_start_date = getMailTimeDateString($data['start_time']);
- }
$body .= create_body_table_row (get_mail_vocab("start_date"),
- $entry_start_date,
- $mail_previous['entry_start_date'],
+ getMailDateString($data['start_time']),
+
getMailDateString($mail_previous['start_time']),
$compare, $as_html);
// Duration
- $new_duration = $data['duration'] . " " . $data['dur_units'];
- $old_duration = $mail_previous['duration'] . " " .
$mail_previous['dur_units'];
+ $new_duration = $data['duration'] . " " .
get_mail_vocab($data['dur_units']);
+ $old_duration = $mail_previous['duration'] . " " .
get_mail_vocab($mail_previous['dur_units']);
$body .= create_body_table_row (get_mail_vocab("duration"),
$new_duration,
$old_duration,
$compare, $as_html);
// End time
- $myendtime = $data['end_time'];
- if ( $enable_periods )
+ $this_endtime = $data['end_time'];
+ $previous_endtime = ($compare) ? $mail_previous['end_time'] : 0;
+ if ($enable_periods)
{
- list($end_period, $entry_end_date) =
getMailPeriodDateString($myendtime, -1);
+ // If we are using periods then the end_time is the end of the last
+ // period. We therefore need to subtract 60 seconds from it so that
+ // we get the name of that period, rather than the name of the next one.
+ $this_endtime = $this_endtime - 60;
+ $previous_endtime = $previous_endtime - 60;
}
- else
- {
- $entry_end_date = getMailTimeDateString($myendtime);
- }
$body .= create_body_table_row (get_mail_vocab("end_date"),
- $entry_end_date,
- $mail_previous['entry_end_date'],
+ getMailDateString($this_endtime),
+ getMailDateString($previous_endtime),
$compare, $as_html);
// Type of booking
@@ -592,19 +624,13 @@
// Repeat days
if (($data['rep_type'] == REP_WEEKLY) || ($data['rep_type'] ==
REP_N_WEEKLY))
{
+
// Display day names according to language and preferred weekday start.
- $opt = "";
- for ($i = 0; $i < 7; $i++)
- {
- $daynum = ($i + $weekstarts) % 7;
- if ($data['rep_opt'][$daynum])
- {
- $opt .= day_name($daynum) . " ";
- }
- }
+ $opt = get_rep_day_list($data['rep_opt']);
+ $opt_previous = ($compare) ?
get_rep_day_list($mail_previous['rep_opt']) : "";
$body .= create_body_table_row (get_mail_vocab("rep_rep_day"),
$opt,
- $mail_previous["rep_opt_list"],
+ $opt_previous,
$compare, $as_html);
}
@@ -743,13 +769,17 @@
/**
* Send email to administrator to notify a new/changed entry.
*
- * @param bool $new_entry to know if this is a new entry or not
- * @return bool TRUE or PEAR error object if fails
+ * @param array $data contains the data for this entry
+ * @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
+ * @param string $action the booking action (eg "delete", "more_info",
etc.)
+ * @param string $note a note that is used with "more_info"
+ * @return bool TRUE or PEAR error object if fails
*/
-function notifyAdminOnBooking($new_entry, $series, $action="book")
+function notifyAdminOnBooking($data, $mail_previous, $new_entry, $series,
$action="book", $note='')
{
- global $data, $mail_previous;
- global $auth, $mail_settings;
+ global $mail_settings;
// Add some values to the $data array before we go and create the addresses
if (!$new_entry)
@@ -792,13 +822,13 @@
// Create the text body
$compare = !$new_entry;
$text_body = array();
- $text_body['content'] = create_body($data, $compare, $series, $action);
+ $text_body['content'] = create_body($data, $compare, $series, $action,
FALSE, $note);
// Create the HTML body
$html_body = array();
if ($mail_settings['html'])
{
- $html_body['content'] = create_body($data, $compare, $series, $action,
TRUE);
+ $html_body['content'] = create_body($data, $compare, $series, $action,
TRUE, $note);
$html_body['cid'] = generate_global_uid("html");
}
@@ -832,17 +862,18 @@
/**
* Send email to administrator to notify a new/changed entry.
*
- * @param array $mail_previous contains deleted entry data forr email body
+ * @param array $data contains deleted entry data for email body
+ * @param bool $series whether this is a series or not
+ * @param string $action the booking action (eg "delete", "more_info",
etc.)
+ * @param string $note a note that is used with "reject"
* @return bool TRUE or PEAR error object if fails
*/
-function notifyAdminOnDelete($mail_previous, $series=FALSE, $action="delete",
$note="")
+function notifyAdminOnDelete($data, $series=FALSE, $action="delete", $note="")
{
- global $typel, $enable_periods, $auth;
- global $mail_settings, $standard_fields, $tbl_entry;
- global $approval_enabled, $confirmation_enabled;
-
+ global $mail_settings;
+
// Set up the addresses (from, to and cc)
- $addresses = create_addresses($mail_previous, $action);
+ $addresses = create_addresses($data, $action);
if ($addresses === FALSE)
{
return;
@@ -859,15 +890,14 @@
}
// Create the text body
- $data = $mail_previous;
$text_body = array();
- $text_body['content'] = create_body($data, FALSE, $series, $action, FALSE);
+ $text_body['content'] = create_body($data, FALSE, $series, $action, FALSE,
$note);
// Create the HTML body
$html_body = array();
if ($mail_settings['html'])
{
- $html_body['content'] = create_body($data, FALSE, $series, $action, TRUE);
+ $html_body['content'] = create_body($data, FALSE, $series, $action, TRUE,
$note);
$html_body['cid'] = generate_global_uid("html");
}
@@ -876,106 +906,21 @@
if ($mail_settings['icalendar'])
{
$attachment['method'] = "CANCEL";
- $attachment['content'] = create_icalendar($attachment['method'],
$mail_previous, $text_body, $html_body, $addresses, $series);
+ $attachment['content'] = create_icalendar($attachment['method'], $data,
$text_body, $html_body, $addresses, $series);
$attachment['name'] = "meeting.ics";
}
-
+
$result = sendMail($addresses,
$subject,
$text_body,
$html_body,
$attachment,
get_mail_charset());
+
return $result;
}
// }}}
-// {{{ getPreviousEntryData()
-
-/**
- * Gather all fields values for an entry. Used for emails to get previous
- * entry state.
- *
- * @param int $id entry id to get data
- * @param int $series TRUE if this is the id of an entry in the repeat
table
- FALSE if this is the id of an entry in the entry
table
- * @return bool TRUE or PEAR error object if fails
- */
-function getPreviousEntryData($id, $series)
-{
- global $enable_periods, $weekstarts;
-
- // Get the data for the booking
- $data = mrbsGetBookingInfo($id, $series);
-
- // Now process some special fields
- $data['id'] = $id;
-
- // Now get the start time, end time and duration.
- if ($enable_periods)
- {
- list( $data['start_period'], $data['entry_start_date']) =
getMailPeriodDateString($data['start_time']);
- list( $data['end_period'] , $data['entry_end_date']) =
getMailPeriodDateString($data['end_time'], -1);
- // need to make DST correct in opposite direction to entry creation
- // so that user see what he expects to see
- $data['duration'] -= cross_dst($data['start_time'], $data['end_time']);
- // Don't translate the units at this stage, as they'll get translated into
the
- // browser language rather than the mail language. We'll translate them
later.
- toPeriodString($data['start_period'], $data['duration'],
$data['dur_units'], FALSE);
- }
- else
- {
- $data['entry_start_date'] = getMailTimeDateString($data['start_time']);
- $data['entry_end_date'] = getMailTimeDateString($data['end_time']);
- // need to make DST correct in opposite direction to entry creation
- // so that user see what he expects to see
- $data['duration'] -= cross_dst($data['start_time'], $data['end_time']);
- // Don't translate the units at this stage, as they'll get translated into
the
- // browser language rather than the mail language. We'll translate them
later.
- toTimeString($data['duration'], $data['dur_units'], FALSE);
- }
- // Now translate the duration units into the mail language
- $data['dur_units'] = get_mail_vocab($data['dur_units']);
-
- // Next, process any repeat information
- if ($data['rep_type'] != REP_NONE)
- {
- // get the names of the repeat days
- switch($data['rep_type'])
- {
- case 2:
- case 6:
- $rep_day[0] = $data['rep_opt'][0] != "0";
- $rep_day[1] = $data['rep_opt'][1] != "0";
- $rep_day[2] = $data['rep_opt'][2] != "0";
- $rep_day[3] = $data['rep_opt'][3] != "0";
- $rep_day[4] = $data['rep_opt'][4] != "0";
- $rep_day[5] = $data['rep_opt'][5] != "0";
- $rep_day[6] = $data['rep_opt'][6] != "0";
- break;
- default:
- $rep_day = array(0, 0, 0, 0, 0, 0, 0);
- }
- $data['rep_opt_list'] = "";
- for ($i = 0; $i < 7; $i++)
- {
- $wday = ($i + $weekstarts) % 7;
- if ($rep_day[$wday])
- $data['rep_opt_list'] .= day_name($wday) . " ";
- }
-
- // Sanitise the rep_num_weeks
- if ($data['rep_type'] != REP_N_WEEKLY)
- {
- $data['rep_num_weeks'] = "";
- }
- }
-
- // return entry previous data as an array
- return $data;
-}
-
-// }}}
// {{{ sendMail()
/**
Modified: mrbs/branches/ics_attachments/web/mrbs_sql.inc
===================================================================
--- mrbs/branches/ics_attachments/web/mrbs_sql.inc 2010-12-08 19:46:51 UTC
(rev 1680)
+++ mrbs/branches/ics_attachments/web/mrbs_sql.inc 2010-12-09 14:37:48 UTC
(rev 1681)
@@ -640,22 +640,34 @@
$now = time();
if ($series)
{
- $sql = "UPDATE $tbl_repeat SET reminded=$now WHERE id=$id";
+ $sql = "UPDATE $tbl_repeat
+ SET reminded=$now,
+ ical_sequence=ical_sequence+1
+ WHERE id=$id";
if (sql_command($sql) >= 0)
{
- $sql = "UPDATE $tbl_entry SET reminded=$now WHERE repeat_id=$id";
+ $sql = "UPDATE $tbl_entry
+ SET reminded=$now,
+ ical_sequence=ical_sequence+1
+ WHERE repeat_id=$id";
return sql_command($sql);
}
}
else
{
- $sql = "UPDATE $tbl_entry SET reminded=$now WHERE id=$id";
+ $sql = "UPDATE $tbl_entry
+ SET reminded=$now,
+ ical_sequence=ical_sequence+1
+ WHERE id=$id";
if (sql_command($sql) > 0)
{
$repeat_id = sql_query1("SELECT repeat_id FROM $tbl_entry WHERE id=$id
LIMIT 1");
if ($repeat_id >= 0)
{
- $sql = "UPDATE $tbl_repeat SET reminded=$now WHERE id=$repeat_id";
+ $sql = "UPDATE $tbl_repeat
+ SET reminded=$now,
+ ical_sequence=ical_sequence+1
+ WHERE id=$repeat_id";
return sql_command($sql);
}
}
@@ -691,6 +703,9 @@
// Approve an entry with id $id. If series is set to TRUE
// then the id is the id in the repeat table and we must approve
// all the individual entries.
+// We also update the ical_sequence number so that any emails that
+// are generated will be treated by calendar clients as referring
+// to the same meeting, rather than a new meeting.
// Returns FALSE on failure, TRUE on success
function mrbsApproveEntry($id, $series)
{
@@ -700,13 +715,15 @@
{
// First update the repeat table
$sql = "UPDATE $tbl_repeat
- SET status=status&(~" . STATUS_AWAITING_APPROVAL . ")
+ SET status=status&(~" . STATUS_AWAITING_APPROVAL . "),
+ ical_sequence=ical_sequence+1
WHERE id=$id";
if (sql_command($sql) > 0) // We expect there to be one row affected
{
// Then update the entry table
$sql = "UPDATE $tbl_entry
- SET status=status&(~" . STATUS_AWAITING_APPROVAL . ")
+ SET status=status&(~" . STATUS_AWAITING_APPROVAL . "),
+ ical_sequence=ical_sequence+1
WHERE repeat_id=$id";
// It's possible that there will be no rows affected if all the
// entries have previously been individually approved
@@ -720,7 +737,8 @@
else
{
$sql = "UPDATE $tbl_entry
- SET status=status&(~" . STATUS_AWAITING_APPROVAL . ")
+ SET status=status&(~" . STATUS_AWAITING_APPROVAL . "),
+ ical_sequence=ical_sequence+1
WHERE id=$id";
return (sql_command($sql) > 0); // We expect there to be one row affected
}
@@ -854,6 +872,22 @@
$row = sql_row_keyed($res, 0);
sql_free($res);
+ // Now get the start time, end time and duration.
+ // Need to make DST correct in opposite direction to entry creation
+ // so that user see what he expects to see
+ $row['duration'] -= cross_dst($row['start_time'], $row['end_time']);
+ // Don't translate the units at this stage. We'll translate them later.
+ if ($enable_periods)
+ {
+ $time = getdate($row['start_time']);
+ $start_period = $time['minutes'];
+ toPeriodString($start_period, $row['duration'], $row['dur_units'], FALSE);
+ }
+ else
+ {
+ toTimeString($row['duration'], $row['dur_units'], FALSE);
+ }
+
// Get some extra information
if ($series)
{
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
This SF Dev2Dev email is sponsored by:
WikiLeaks The End of the Free Internet
http://p.sf.net/sfu/therealnews-com
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits