Revision: 1254
http://mrbs.svn.sourceforge.net/mrbs/?rev=1254&view=rev
Author: cimorrison
Date: 2009-11-11 12:20:17 +0000 (Wed, 11 Nov 2009)
Log Message:
-----------
- email notifications implemented on confirmation of provisional bookings
- mrbsGetEntryInfo() replaced by a more extensive mrbsGetBookingInfo() which is
now called by view_entry.php and confirm_entry_handler.php
Modified Paths:
--------------
mrbs/branches/provisional_bookings/web/confirm_entry_handler.php
mrbs/branches/provisional_bookings/web/del_entry.php
mrbs/branches/provisional_bookings/web/functions_mail.inc
mrbs/branches/provisional_bookings/web/lang.en
mrbs/branches/provisional_bookings/web/mrbs_sql.inc
mrbs/branches/provisional_bookings/web/view_entry.php
Modified: mrbs/branches/provisional_bookings/web/confirm_entry_handler.php
===================================================================
--- mrbs/branches/provisional_bookings/web/confirm_entry_handler.php
2009-11-11 00:01:38 UTC (rev 1253)
+++ mrbs/branches/provisional_bookings/web/confirm_entry_handler.php
2009-11-11 12:20:17 UTC (rev 1254)
@@ -45,11 +45,73 @@
showAccessDenied($day, $month, $year, $area, isset($room) ? $room : "");
exit;
}
+
+if (isset($action))
+{
+ $need_to_send_mail = ($mail_settings['admin_on_bookings'] or
$mail_settings['area_admin_on_bookings'] or
+ $mail_settings['room_admin_on_bookings'] or
$mail_settings['booker'] or
+ $mail_settings['book_admin_on_provisional']);
+
+ if ($need_to_send_mail)
+ {
+ // Retrieve the booking details which we will need for the email
+ // (notifyAdminOnBooking relies on them being available as globals)
-// ACTION = "ACCEPT"
-if ($action == "accept")
-{
- mrbsConfirmEntry($id, $series);
+ $row = mrbsGetBookingInfo($id, $series);
+
+ $name = $row['name'];
+ $description = $row['description'];
+ $create_by = $row['create_by'];
+ $type = $row['type'];
+ $status = $row['status'];
+ $starttime = $row['start_time'];
+ $endtime = $row['end_time'];
+ $repeat_id = $row['repeat_id'];
+ $room_name = $row['room_name'];
+ $area_name = $row['area_name'];
+ $duration = ($row['end_time'] - $row['start_time']) -
cross_dst($row['start_time'], $row['end_time']);
+ $rep_type = $row['rep_type'];
+ $rep_enddate = isset($row['rep_enddate']) ? $row['rep_enddate'] :
NULL;
+ $rep_opt = isset($row['rep_opt']) ? $row['rep_opt'] :
NULL;
+ $rep_num_weeks = isset($row['rep_num_weeks']) ? $row['rep_num_weeks'] :
NULL;
+
+ if ($enable_periods)
+ {
+ list($start_period, $start_date) =
period_date_string($row['start_time']);
+ }
+ else
+ {
+ $start_date = time_date_string($row['start_time']);
+ }
+
+ if ($enable_periods)
+ {
+ list( , $end_date) = period_date_string($row['end_time'], -1);
+ }
+ else
+ {
+ $end_date = time_date_string($row['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, $duration, $dur_units,
FALSE) : toTimeString($duration, $dur_units, FALSE);
+
+ }
+
+ // ACTION = "ACCEPT"
+ if ($action == "accept")
+ {
+ if (!mrbsConfirmEntry($id, $series))
+ {
+ $returl .= "&error=accept_failed";
+ }
+ elseif ($need_to_send_mail)
+ {
+ $result = notifyAdminOnBooking(TRUE, $id, $action);
+ }
+ }
}
// Now it's all done go back to the previous view
Modified: mrbs/branches/provisional_bookings/web/del_entry.php
===================================================================
--- mrbs/branches/provisional_bookings/web/del_entry.php 2009-11-11
00:01:38 UTC (rev 1253)
+++ mrbs/branches/provisional_bookings/web/del_entry.php 2009-11-11
12:20:17 UTC (rev 1254)
@@ -30,7 +30,7 @@
$returl .= "?year=$year&month=$month&day=$day&area=$area";
}
-if (getAuthorised(1) && ($info = mrbsGetEntryInfo($id)))
+if (getAuthorised(1) && ($info = mrbsGetBookingInfo($id, FALSE, TRUE)))
{
$day = strftime("%d", $info["start_time"]);
$month = strftime("%m", $info["start_time"]);
Modified: mrbs/branches/provisional_bookings/web/functions_mail.inc
===================================================================
--- mrbs/branches/provisional_bookings/web/functions_mail.inc 2009-11-11
00:01:38 UTC (rev 1253)
+++ mrbs/branches/provisional_bookings/web/functions_mail.inc 2009-11-11
12:20:17 UTC (rev 1254)
@@ -169,7 +169,7 @@
* @param int $new_id used for create a link to the new entry
* @return bool TRUE or PEAR error object if fails
*/
-function notifyAdminOnBooking($new_entry , $new_id)
+function notifyAdminOnBooking($new_entry , $new_id, $action="book")
{
global $url_base, $returl, $name, $description, $area_name;
global $room_name, $starttime, $duration, $dur_units, $end_date, $endtime;
@@ -177,9 +177,15 @@
global $rep_opt, $rep_num_weeks;
global $tbl_room, $tbl_area, $tbl_entry, $tbl_users, $tbl_repeat;
global $mail_previous, $auth;
- global $mail_settings, $weekstarts;
-
- //
+ global $mail_settings, $weekstarts, $provisional_enabled;
+
+ // We will treat Accept, Reject and More_info mailings as new entries
because the
+ // data hasn't changed since the previous time.
+ if (($action == "accept") || ($action == "more_info") || ($action ==
"remind"))
+ {
+ $new_entry = TRUE;
+ }
+
$recipients = array();
$id_table = ($rep_type > 0) ? "rep" : "e";
($mail_settings['admin_on_bookings']) ? $recipients[] =
$mail_settings['recipients'] : '';
@@ -241,6 +247,7 @@
$recipients[] = $mail_previous['room_admin_email'];
}
}
+
if ($mail_settings['booker'])
{
if ('db' == $auth['type'])
@@ -290,16 +297,27 @@
return FALSE;
}
$recipient_list = get_address_list($recipients);
- //
- $subject = get_mail_vocab("mail_subject_entry");
- if ($new_entry)
+
+ // set up the subject and body
+ switch ($action)
{
- $body = get_mail_vocab("mail_body_new_entry") . "\n\n";
+ case "accept":
+ $subject = get_mail_vocab("mail_subject_accepted");
+ $body = get_mail_vocab("mail_body_accepted") . "\n\n";
+ break;
+ default:
+ $subject = get_mail_vocab("mail_subject_entry");
+ 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;
}
- else
- {
- $body = get_mail_vocab("mail_body_changed_entry") . "\n\n";
- }
+
// Set the link to view entry page
if (isset($url_base) && ($url_base != ""))
{
@@ -329,10 +347,13 @@
convertToMailCharset($mail_previous['description']),
$new_entry) . "\n";
- // Status:
- $body .= get_mail_vocab("status") . ": ";
- $body .= ($status == STATUS_CONFIRMED) ? get_mail_vocab("confirmed") :
get_mail_vocab("provisional");
- $body .= "\n";
+ if ($provisional_enabled)
+ {
+ // Status:
+ $body .= get_mail_vocab("status") . ": ";
+ $body .= ($status == STATUS_CONFIRMED) ? get_mail_vocab("confirmed") :
get_mail_vocab("provisional");
+ $body .= "\n";
+ }
// Room:
$body .= get_mail_vocab("room") . ": " .
Modified: mrbs/branches/provisional_bookings/web/lang.en
===================================================================
--- mrbs/branches/provisional_bookings/web/lang.en 2009-11-11 00:01:38 UTC
(rev 1253)
+++ mrbs/branches/provisional_bookings/web/lang.en 2009-11-11 12:20:17 UTC
(rev 1254)
@@ -113,7 +113,8 @@
$vocab["series"] = "Series";
$vocab["request_more_info"] = "Please list the extra information you require";
$vocab["reject_reason"] = "Please give a reason for your rejection of
this reservation request";
-$vocab["send"] = "Send";
+$vocab["send"] = "Send";
+$vocab["accept_failed"] = "The reservation could not be confirmed.";
// Used in edit_entry_handler.php
$vocab["error"] = "Error";
@@ -125,6 +126,14 @@
$vocab["failed_to_acquire"] = "Failed to acquire exclusive database access";
$vocab["invalid_booking"] = "Invalid booking";
$vocab["must_set_description"] = "You must set a brief description for the
booking. Please go back and enter one.";
+$vocab["mail_subject_accepted"] = "Entry approved for $mrbs_company MRBS";
+$vocab["mail_subject_rejected"] = "Entry rejected for $mrbs_company MRBS";
+$vocab["mail_subject_more_info"] = "$mrbs_company MRBS: more information
requested";
+$vocab["mail_subject_reminder"] = "Reminder for $mrbs_company MRBS";
+$vocab["mail_body_accepted"] = "An entry has been approved by the
administrators; here are the details:";
+$vocab["mail_body_rej_entry"] = "An entry has been rejected by the
administrators, here are the details:";
+$vocab["mail_body_more_info"] = "The administrators require more
information about an entry; here are the details:";
+$vocab["mail_body_reminder"] = "Reminder - an entry is awaiting approval;
here are the details:";
$vocab["mail_subject_entry"] = "Entry added/changed for $mrbs_company MRBS";
$vocab["mail_body_new_entry"] = "A new entry has been booked, here are the
details:";
$vocab["mail_body_del_entry"] = "An entry has been deleted, here are the
details:";
Modified: mrbs/branches/provisional_bookings/web/mrbs_sql.inc
===================================================================
--- mrbs/branches/provisional_bookings/web/mrbs_sql.inc 2009-11-11 00:01:38 UTC
(rev 1253)
+++ mrbs/branches/provisional_bookings/web/mrbs_sql.inc 2009-11-11 12:20:17 UTC
(rev 1254)
@@ -562,43 +562,154 @@
}
-/* mrbsGetEntryInfo()
- *
- * Get the booking's entrys
- *
- * $id = The ID for which to get the info for.
- *
- * Returns:
- * nothing = The ID does not exist
- * array = The bookings info
- */
-function mrbsGetEntryInfo($id)
+// mrbsGetBookingInfo($id, $series)
+//
+// Gets all the details for a booking with $id, which is in the
+// repeat table id $series is set, otherwise in the entry table.
+
+// Returns the results in an array with keys the same as the table
+// field names. In the event of an error stops with a fatal error,
+// unless $silent is TRUe, when it returns FALSE.
+function mrbsGetBookingInfo($id, $series, $silent=FALSE)
{
- global $tbl_entry;
+ global $tbl_entry, $tbl_repeat, $tbl_room, $tbl_area;
+ global $provisional_enabled;
- $sql = "SELECT start_time, end_time, entry_type, repeat_id, room_id,
- timestamp, create_by, name, type, description
- FROM $tbl_entry WHERE (id = $id)";
+ if ($series)
+ {
+ $sql = "
+ SELECT $tbl_repeat.name,
+ $tbl_repeat.description,
+ $tbl_repeat.create_by,
+ $tbl_room.room_name,
+ $tbl_area.area_name,
+ $tbl_room.area_id,
+ $tbl_repeat.type,
+ $tbl_repeat.private,
+ $tbl_repeat.room_id,
+ " . sql_syntax_timestamp_to_unix("$tbl_repeat.timestamp") . " AS
last_updated,
+ ($tbl_repeat.end_time - $tbl_repeat.start_time) AS duration,
+ $tbl_repeat.start_time,
+ $tbl_repeat.end_time,
+ $tbl_repeat.rep_type,
+ $tbl_repeat.end_date,
+ $tbl_repeat.rep_opt,
+ $tbl_repeat.rep_num_weeks
+ FROM $tbl_repeat, $tbl_room, $tbl_area
+ WHERE $tbl_repeat.room_id = $tbl_room.id
+ AND $tbl_room.area_id = $tbl_area.id
+ AND $tbl_repeat.id=$id
+ ";
+ }
+ else
+ {
+ $sql = "
+ SELECT $tbl_entry.name,
+ $tbl_entry.description,
+ $tbl_entry.create_by,
+ $tbl_room.room_name,
+ $tbl_room.area_id,
+ $tbl_area.area_name,
+ $tbl_entry.type,
+ $tbl_entry.status,
+ $tbl_entry.private,
+ $tbl_entry.room_id,
+ " . sql_syntax_timestamp_to_unix("$tbl_entry.timestamp") . " AS
last_updated,
+ ($tbl_entry.end_time - $tbl_entry.start_time) AS duration,
+ $tbl_entry.start_time,
+ $tbl_entry.end_time,
+ $tbl_entry.repeat_id
+
+ FROM $tbl_entry, $tbl_room, $tbl_area
+ WHERE $tbl_entry.room_id = $tbl_room.id
+ AND $tbl_room.area_id = $tbl_area.id
+ AND $tbl_entry.id=$id
+ ";
+ }
+
$res = sql_query($sql);
if (! $res)
{
- return;
+ if ($silent)
+ {
+ return FALSE;
+ }
+ else
+ {
+ fatal_error(0, sql_error());
+ }
}
- $ret = "";
- if (sql_count($res) > 0)
+ if (sql_count($res) < 1)
{
- $row = sql_row_keyed($res, 0);
+ if ($silent)
+ {
+ return FALSE;
+ }
+ else
+ {
+ fatal_error(0,
+ ($series ? get_vocab("invalid_series_id") :
get_vocab("invalid_entry_id"))
+ );
+ }
+ }
- if ($row)
+ $row = sql_row_keyed($res, 0);
+ sql_free($res);
+
+ // Get some extra information
+ if ($series)
+ {
+ // Get the status of the booking. For an individual entry it's easy -
+ // we've already got it. For a series, the repeat table does not hold
+ // a status field. Instead the status of a series is defined by the
status
+ // of its members: if any one of them is provisional, then the series as
+ // a whole is considered to be provisional.
+ //
+ // But we won't bother fetching the status with another SQL query if we're
not
+ // using provisional bookings, because we won't be using it.
+ if ($provisional_enabled)
{
- $ret = $row;
+ $sql = "SELECT COUNT(*)
+ FROM $tbl_entry
+ WHERE repeat_id=$id
+ AND status=" . STATUS_PROVISIONAL . "
+ LIMIT 1";
+ $row['status'] = (sql_query1($sql) > 0) ? STATUS_PROVISIONAL :
STATUS_CONFIRMED;
}
}
- sql_free($res);
-
- return $ret;
+ else
+ {
+ // Get the repeat information
+ if (empty($row['repeat_id']))
+ {
+ $row['rep_type'] = 0; // just as a precaution
+ }
+ else
+ {
+ $res = sql_query("SELECT rep_type, end_date, rep_opt, rep_num_weeks
+ FROM $tbl_repeat WHERE id=${row['repeat_id']} LIMIT
1");
+ if (!$res || (!$extra_row = sql_row_keyed($res, 0)))
+ {
+ if ($silent)
+ {
+ return FALSE;
+ }
+ else
+ {
+ fatal_error(TRUE, get_vocab("invalid_series_id"));
+ }
+ }
+ $row['rep_type'] = $extra_row['rep_type'];
+ $row['rep_enddate'] = $extra_row['end_date'];
+ $row['rep_opt'] = $extra_row['rep_opt'];
+ $row['rep_num_weeks'] = $extra_row['rep_num_weeks'];
+ sql_free($res);
+ }
+ }
+
+ return $row;
}
function mrbsGetRoomArea($id)
Modified: mrbs/branches/provisional_bookings/web/view_entry.php
===================================================================
--- mrbs/branches/provisional_bookings/web/view_entry.php 2009-11-11
00:01:38 UTC (rev 1253)
+++ mrbs/branches/provisional_bookings/web/view_entry.php 2009-11-11
12:20:17 UTC (rev 1254)
@@ -2,6 +2,7 @@
// $Id$
require_once "defaultincludes.inc";
+require_once "mrbs_sql.inc";
// Generates a single button
function generateButton($form_action, $id, $series, $action_type, $returl,
$submit_value)
@@ -78,6 +79,7 @@
$series = get_form_var('series', 'int');
$action = get_form_var('action', 'string');
$returl = get_form_var('returl', 'string');
+$error = get_form_var('error', 'string');
// If we dont know the right date then make it up
if (!isset($day) or !isset($month) or !isset($year))
@@ -130,85 +132,15 @@
$series = 1;
}
-if ($series)
-{
- $sql = "
- SELECT $tbl_repeat.name,
- $tbl_repeat.description,
- $tbl_repeat.create_by,
- $tbl_room.room_name,
- $tbl_area.area_name,
- $tbl_room.area_id,
- $tbl_repeat.type,
- $tbl_repeat.private,
- $tbl_repeat.room_id,
- " . sql_syntax_timestamp_to_unix("$tbl_repeat.timestamp") . " AS
last_updated,
- ($tbl_repeat.end_time - $tbl_repeat.start_time) AS duration,
- $tbl_repeat.start_time,
- $tbl_repeat.end_time,
- $tbl_repeat.rep_type,
- $tbl_repeat.end_date,
- $tbl_repeat.rep_opt,
- $tbl_repeat.rep_num_weeks
+$row = mrbsGetBookingInfo($id, $series);
- FROM $tbl_repeat, $tbl_room, $tbl_area
- WHERE $tbl_repeat.room_id = $tbl_room.id
- AND $tbl_room.area_id = $tbl_area.id
- AND $tbl_repeat.id=$id
- ";
-}
-else
-{
- $sql = "
- SELECT $tbl_entry.name,
- $tbl_entry.description,
- $tbl_entry.create_by,
- $tbl_room.room_name,
- $tbl_room.area_id,
- $tbl_area.area_name,
- $tbl_entry.type,
- $tbl_entry.status,
- $tbl_entry.private,
- $tbl_entry.room_id,
- " . sql_syntax_timestamp_to_unix("$tbl_entry.timestamp") . " AS
last_updated,
- ($tbl_entry.end_time - $tbl_entry.start_time) AS duration,
- $tbl_entry.start_time,
- $tbl_entry.end_time,
- $tbl_entry.repeat_id
-
- FROM $tbl_entry, $tbl_room, $tbl_area
- WHERE $tbl_entry.room_id = $tbl_room.id
- AND $tbl_room.area_id = $tbl_area.id
- AND $tbl_entry.id=$id
- ";
-}
-
-$res = sql_query($sql);
-if (! $res)
-{
- fatal_error(0, sql_error());
-}
-
-if (sql_count($res) < 1)
-{
- fatal_error(0,
- ($series ? get_vocab("invalid_series_id") :
get_vocab("invalid_entry_id"))
- );
-}
-
-$row = sql_row_keyed($res, 0);
-sql_free($res);
-
-// Get the area settings for the entry's area. In particular we want
-// to know how to display private/public bookings in this area.
-get_area_settings($row['area_id']);
-
$name = htmlspecialchars($row['name']);
$description = htmlspecialchars($row['description']);
$create_by = htmlspecialchars($row['create_by']);
$room_name = htmlspecialchars($row['room_name']);
$area_name = htmlspecialchars($row['area_name']);
$type = $row['type'];
+$status = $row['status'];
$private = $row['private'];
$room_id = $row['room_id'];
$updated = time_date_string($row['last_updated']);
@@ -218,31 +150,11 @@
$row['end_time']);
$writeable = getWritable($row['create_by'], $user);
-// Get the status of the booking. For an individual entry it's easy -
-// we've already got it. For a series, the repeat table does not hold
-// a status field. Instead the status of a series is defined by the status
-// of its members: if any one of them is provisional, then the series as
-// a whole is considered to be provisional.
-//
-// But we won't bother fetching the status with another SQL query if we're not
-// using provisional bookings, because we won't be using it.
-if ($provisional_enabled)
-{
- if ($series)
- {
- $sql = "SELECT COUNT(*)
- FROM $tbl_entry
- WHERE repeat_id=$id
- AND status=" . STATUS_PROVISIONAL . "
- LIMIT 1";
- $status = (sql_query1($sql) > 0) ? STATUS_PROVISIONAL : STATUS_CONFIRMED;
- }
- else
- {
- $status = $row['status'];
- }
-}
+// Get the area settings for the entry's area. In particular we want
+// to know how to display private/public bookings in this area.
+get_area_settings($row['area_id']);
+
if (is_private_event($private) && !$writeable)
{
$name = "[".get_vocab('private')."]";
@@ -364,10 +276,15 @@
}
echo "</h3>\n";
-?>
-<table id="entry">
-<?php
+echo "<table id=\"entry\">\n";
+
+// Output any error messages
+if (!empty($error))
+{
+ echo "<tr><td> </td><td class=\"error\">" . get_vocab($error) .
"</td></tr>\n";
+}
+
// If we're using provisional bookings, put the buttons to do with managing
// the bookings in the footer
if ($provisional_enabled && ($status == STATUS_PROVISIONAL))
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits