Revision: 2643
https://sourceforge.net/p/mrbs/code/2643/
Author: cimorrison
Date: 2013-01-17 11:40:08 +0000 (Thu, 17 Jan 2013)
Log Message:
-----------
Made email notifications work with the new tables
Modified Paths:
--------------
mrbs/branches/linked_bookings/web/dbsys.inc
mrbs/branches/linked_bookings/web/functions.inc
mrbs/branches/linked_bookings/web/functions_ical.inc
mrbs/branches/linked_bookings/web/functions_mail.inc
mrbs/branches/linked_bookings/web/mrbs_sql.inc
mrbs/branches/linked_bookings/web/mysql.inc
mrbs/branches/linked_bookings/web/mysqli.inc
mrbs/branches/linked_bookings/web/pgsql.inc
Modified: mrbs/branches/linked_bookings/web/dbsys.inc
===================================================================
--- mrbs/branches/linked_bookings/web/dbsys.inc 2013-01-16 19:54:15 UTC (rev
2642)
+++ mrbs/branches/linked_bookings/web/dbsys.inc 2013-01-17 11:40:08 UTC (rev
2643)
@@ -421,6 +421,29 @@
}
+// Returns the syntax for a CONCAT statement
+// Requires any strings to be escaped and enclosed in single quotes
+function sql_syntax_concat($strings)
+{
+ if (func_num_args() > 1)
+ {
+ $handle = func_get_arg(1);
+ $db_sys = $handle['system'];
+ $db_conn = $handle['connection'];
+ }
+ else
+ {
+ global $dbsys;
+
+ $db_sys = $dbsys;
+ $db_conn = null;
+ }
+
+ $f = "sql_${db_sys}_syntax_concat";
+ return $f($strings, $db_conn);
+}
+
+
// Returns the syntax for converting a timestamp into a "UNIX timestamp"
function sql_syntax_timestamp_to_unix($fieldname)
{
Modified: mrbs/branches/linked_bookings/web/functions.inc
===================================================================
--- mrbs/branches/linked_bookings/web/functions.inc 2013-01-16 19:54:15 UTC
(rev 2642)
+++ mrbs/branches/linked_bookings/web/functions.inc 2013-01-17 11:40:08 UTC
(rev 2643)
@@ -1587,6 +1587,28 @@
}
+function get_full_room_names($rooms)
+{
+ global $tbl_room, $tbl_area;
+
+ $strings = array("A.area_name",
+ "'" . sql_escape(' - ') . "'",
+ "R.room_name");
+ $sql = "SELECT " . sql_syntax_concat($strings) . "
+ FROM $tbl_room R, $tbl_area A
+ WHERE R.id IN (" . implode(',', $rooms) . ") AND R.area_id = A.id
+ ORDER BY A.area_name, R.sort_key";
+ $room_names = sql_query_array($sql);
+ if ($room_names === FALSE)
+ {
+ trigger_error(sql_error(), E_USER_WARNING);
+ fatal_error(TRUE, get_vocab("fatal_db_error"));
+ }
+
+ return $room_names;
+}
+
+
// Clean up a row from the area table, making sure there are no nulls, casting
// boolean fields into bools and doing some sanity checking
function clean_area_row($row)
Modified: mrbs/branches/linked_bookings/web/functions_ical.inc
===================================================================
--- mrbs/branches/linked_bookings/web/functions_ical.inc 2013-01-16
19:54:15 UTC (rev 2642)
+++ mrbs/branches/linked_bookings/web/functions_ical.inc 2013-01-17
11:40:08 UTC (rev 2643)
@@ -883,7 +883,7 @@
{
$results[] = "X-ALT-DESC;FMTTYPE=text/html:" .
ical_escape_text($html_description['content']);
}
- $results[] = "LOCATION:" . ical_escape_text($data['area_name'] . " - " .
$data['room_name']);
+ $results[] = "LOCATION:" . ical_escape_text(implode(', ',
$data['room_names']));
$results[] = "SEQUENCE:" . $data['ical_sequence'];
// If this is an individual member of a series then set the recurrence id
if (!$series && ($data['entry_type'] != ENTRY_SINGLE))
Modified: mrbs/branches/linked_bookings/web/functions_mail.inc
===================================================================
--- mrbs/branches/linked_bookings/web/functions_mail.inc 2013-01-16
19:54:15 UTC (rev 2642)
+++ mrbs/branches/linked_bookings/web/functions_mail.inc 2013-01-17
11:40:08 UTC (rev 2643)
@@ -240,7 +240,7 @@
}
-// Get the area_admin_email for an entry $id
+// Get the area_admin_emails for an entry $id
// If $series is set this is an entry in the repeat table, otherwise the entry
table
// Returns an empty string in the case of an error
function get_area_admin_email($id, $series=FALSE)
@@ -252,21 +252,20 @@
(($series) ? "$tbl_room_repeat" : "$tbl_room_entry") . " J
WHERE " . (($series) ? "J.repeat_id" : "J.entry_id") . "=$id
AND R.id=J.room_id
- AND A.id=R.area_id
- LIMIT 1";
+ AND A.id=R.area_id";
- $email = sql_query1($sql);
+ $emails = sql_query_array($sql);
- if ($email == -1)
+ if ($emails === FALSE)
{
- // The result can be -1 if there's an error or if there are no matching
rows
- $email = "";
+ trigger_error(sql_error(), E_USER_WARNING);
+ fatal_error(TRUE, get_vocab("fatal_db_error"));
}
- return $email;
+ return implode(',', $emails);
}
-// Get the room_admin_email for an entry $id
+// Get the room_admin_emails for an entry $id
// If $series is set this is an entry in the repeat table, otherwise the entry
table
// Returns an empty string in the case of an error
function get_room_admin_email($id, $series=FALSE)
@@ -277,17 +276,16 @@
FROM $tbl_room R, " .
(($series) ? "$tbl_room_repeat" : "$tbl_room_entry") . " J
WHERE " . (($series) ? "J.repeat_id" : "J.entry_id") . "=$id
- AND R.id=J.room_id
- LIMIT 1";
+ AND R.id=J.room_id";
- $email = sql_query1($sql);
+ $emails = sql_query_array($sql);
- if ($email == -1)
+ if ($emails === FALSE)
{
- // The result can be -1 if there's an error or if there are no matching
rows
- $email = "";
+ trigger_error(sql_error(), E_USER_WARNING);
+ fatal_error(TRUE, get_vocab("fatal_db_error"));
}
- return $email;
+ return implode(',', $emails);
}
@@ -560,11 +558,9 @@
}
// Room:
- $new_room = $data['area_name'] . " - " . $data['room_name'];
- $old_room = $mail_previous['area_name'] . " - " .
$mail_previous['room_name'];
$body .= create_body_table_row (get_mail_vocab("room"),
- $new_room,
- $old_room,
+ implode(', ', $data['room_names']),
+ implode(', ',
$mail_previous['room_names']),
$compare, $as_html);
// Start time
@@ -899,8 +895,8 @@
// Add some values to the $data array before we go and create the addresses
if (!$new_entry)
{
- $data['area_admin_email'] = (!empty($mail_previous['area_admin_email'])) ?
$mail_previous['area_admin_email'] : NULL;
- $data['room_admin_email'] = (!empty($mail_previous['room_admin_email'])) ?
$mail_previous['room_admin_email'] : NULL;
+ $data['area_admin_email'] = (!empty($mail_previous['area_admin_email'])) ?
implode(',', $mail_previous['area_admin_email']) : NULL;
+ $data['room_admin_email'] = (!empty($mail_previous['room_admin_email'])) ?
implode(',', $mail_previous['room_admin_email']) : NULL;
}
// Set up the addresses (from, to and cc)
Modified: mrbs/branches/linked_bookings/web/mrbs_sql.inc
===================================================================
--- mrbs/branches/linked_bookings/web/mrbs_sql.inc 2013-01-16 19:54:15 UTC
(rev 2642)
+++ mrbs/branches/linked_bookings/web/mrbs_sql.inc 2013-01-17 11:40:08 UTC
(rev 2643)
@@ -1249,11 +1249,11 @@
$booking['rooms'][] = $row['room_id'];
if (isset($row['area_admin_email']) && ($row['area_admin_email'] != ''))
{
- $booking['area_admin_email'][] = array($row['area_admin_email']);
+ $booking['area_admin_email'][] = $row['area_admin_email'];
}
if (isset($row['room_admin_email']) && ($row['room_admin_email'] != ''))
{
- $booking['room_admin_email'][] = array($row['room_admin_email']);
+ $booking['room_admin_email'][] = $row['room_admin_email'];
}
}
}
@@ -1702,19 +1702,10 @@
(!isset($id) && $mail_settings['on_new']))
{
require_once "functions_mail.inc";
- // Get room name and area name for email notifications.
- // Would be better to avoid a database access just for that.
- // Ran only if we need details
+ // Get room names for email notifications.
if ($mail_settings['details'])
{
- $sql = "SELECT R.room_name, A.area_name
- FROM $tbl_room R, $tbl_area A
- WHERE R.id=$room_id AND R.area_id = A.id
- LIMIT 1";
- $res = sql_query($sql);
- $row = sql_row_keyed($res, 0);
- $booking['room_name'] = $row['room_name'];
- $booking['area_name'] = $row['area_name'];
+ $booking['room_names'] = get_full_room_names($booking['rooms']);
}
// If this is a modified entry then get the previous entry data
// so that we can highlight the changes
Modified: mrbs/branches/linked_bookings/web/mysql.inc
===================================================================
--- mrbs/branches/linked_bookings/web/mysql.inc 2013-01-16 19:54:15 UTC (rev
2642)
+++ mrbs/branches/linked_bookings/web/mysql.inc 2013-01-17 11:40:08 UTC (rev
2643)
@@ -269,6 +269,16 @@
}
+// Returns the syntax for a CONCAT statement
+// Requires any strings to be escaped and enclosed in single quotes
+function sql_mysql_syntax_concat($strings, $db_conn = null)
+{
+ sql_mysql_ensure_handle($db_conn);
+
+ return "CONCAT(" . implode(',', $strings) . ")";
+}
+
+
// Generate non-standard SQL to output a TIMESTAMP as a Unix-time:
function sql_mysql_syntax_timestamp_to_unix($fieldname, $db_conn = null)
{
Modified: mrbs/branches/linked_bookings/web/mysqli.inc
===================================================================
--- mrbs/branches/linked_bookings/web/mysqli.inc 2013-01-16 19:54:15 UTC
(rev 2642)
+++ mrbs/branches/linked_bookings/web/mysqli.inc 2013-01-17 11:40:08 UTC
(rev 2643)
@@ -277,6 +277,16 @@
}
+// Returns the syntax for a CONCAT statement
+// Requires any strings to be escaped and enclosed in single quotes
+function sql_mysqli_syntax_concat($strings, $db_conn = null)
+{
+ sql_mysqli_ensure_handle($db_conn);
+
+ return "CONCAT(" . implode(',', $strings) . ")";
+}
+
+
// Generate non-standard SQL to output a TIMESTAMP as a Unix-time:
function sql_mysqli_syntax_timestamp_to_unix($fieldname, $db_conn = null)
{
Modified: mrbs/branches/linked_bookings/web/pgsql.inc
===================================================================
--- mrbs/branches/linked_bookings/web/pgsql.inc 2013-01-16 19:54:15 UTC (rev
2642)
+++ mrbs/branches/linked_bookings/web/pgsql.inc 2013-01-17 11:40:08 UTC (rev
2643)
@@ -286,6 +286,18 @@
}
+// Returns the syntax for a CONCAT statement
+// Requires any strings to be escaped and enclosed in single quotes
+function sql_pgsql_syntax_concat($strings, $db_conn = null)
+{
+ sql_pgsql_ensure_handle($db_conn);
+
+ // CONCAT didn't exist in early versions of PostgreSQL and (I think)
+ // in some versions only took two arguments
+ return implode('||', $strings);
+}
+
+
// Generate non-standard SQL to output a TIMESTAMP as a Unix-time:
function sql_pgsql_syntax_timestamp_to_unix($fieldname, $db_conn = null)
{
------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122712
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits