Changeset:
ed4a01ad86b7
https://sourceforge.net/p/mrbs/hg-code/ci/ed4a01ad86b7888047816dc19431c8368d657108
Author:
Campbell Morrison <[email protected]>
Date:
Wed Dec 16 21:19:43 2015 +0000
Log message:
Moved some SQL into mrbs_sql.inc
diffstat:
web/functions_table.inc | 43 +++------------------------------------
web/mrbs_sql.inc | 53 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 57 insertions(+), 39 deletions(-)
diffs (123 lines):
diff -r c2c2c0e1e524 -r ed4a01ad86b7 web/functions_table.inc
--- a/web/functions_table.inc Wed Dec 16 19:07:29 2015 +0000
+++ b/web/functions_table.inc Wed Dec 16 21:19:43 2015 +0000
@@ -1030,52 +1030,17 @@
}
unset($j); // Just so that we pick up any accidental attempt to use it later
- // Get all appointments for this week in the room that we care about.
- //
- // row['room_id'] = Room ID
- // row['start_time'] = Start time
- // row['end_time'] = End time
- // row['type'] = Entry type
- // row['name'] = Entry name (brief description)
- // row['id'] = Entry ID
- // row['description'] = Complete description
- // row['status'] = status code
- // row['create_by'] = User who created entry
- // This data will be retrieved day-by-day
$week_map = array();
for ($j = 0; $j<=($num_of_days-1) ; $j++)
{
- $sql = "SELECT *
- FROM $tbl_entry
- WHERE room_id = $room
- AND start_time <= $pm7[$j] AND end_time > $am7[$j]
- ORDER BY start_time"; // necessary so that multiple bookings
appear in the right order
-
- // Each row returned from the query is a meeting. Build an array of the
- // form: $week_map[room][weekday][slot][x], where x = id, color, data,
long_desc.
- // [slot] is based at 000 (HHMM) for midnight, but only slots within
- // the hours of interest (morningstarts : eveningends) are filled in.
- // [id], [data] and [long_desc] are only filled in when the meeting
- // should be labeled, which is once for each meeting on each weekday.
- // Note: weekday here is relative to the $weekstarts configuration
variable.
- // If 0, then weekday=0 means Sunday. If 1, weekday=0 means Monday.
-
- $res = sql_query($sql);
- if (! $res)
+ $entries = get_entries_by_room($room, $am7[$j], $pm7[$j]);
+ foreach ($entries as $entry)
{
- trigger_error(sql_error(), E_USER_WARNING);
- fatal_error(TRUE, get_vocab("fatal_db_error"));
+ map_add_booking($entry, $week_map[$room][$j], $am7[$j], $pm7[$j]);
}
- else
- {
- for ($i = 0; ($row = sql_row_keyed($res, $i)); $i++)
- {
- map_add_booking($row, $week_map[$room][$j], $am7[$j], $pm7[$j]);
- }
- }
- } // for ($j = 0; ...
+ }
unset($j); // Just so that we pick up any accidental attempt to use it later
// START DISPLAYING THE MAIN TABLE
diff -r c2c2c0e1e524 -r ed4a01ad86b7 web/mrbs_sql.inc
--- a/web/mrbs_sql.inc Wed Dec 16 19:07:29 2015 +0000
+++ b/web/mrbs_sql.inc Wed Dec 16 21:19:43 2015 +0000
@@ -425,6 +425,59 @@
return $errors;
}
+
+// Get all the entries for the area with $area_id in the interval that starts
at $interval_start
+// and ends at $interval_start (both Unix timestamps). Only gets entries for
enabled rooms.
+// Returns an array of entries. Each element of the array is itself an array
with keys
+// corresponding to the entry table columns
+function get_entries_by_area($area_id, $interval_start, $interval_end)
+{
+ global $tbl_entry, $tbl_room;
+
+ $sql = "SELECT E.*
+ FROM $tbl_entry E, $tbl_room R
+ WHERE E.room_id = R.id
+ AND R.area_id = $area_id
+ AND R.disabled = 0
+ AND start_time <= $interval_end AND end_time > $interval_start
+ ORDER BY start_time"; // necessary so that multiple bookings appear
in the right order
+
+ $res = sql_query($sql);
+ if ($res === FALSE)
+ {
+ trigger_error(sql_error(), E_USER_WARNING);
+ fatal_error(FALSE, get_vocab("fatal_db_error"));
+ }
+
+ return sql_all_rows_keyed($res);
+}
+
+
+// Get all the entries for the room with $room_id in the interval that starts
at $interval_start
+// and ends at $interval_start (both Unix timestamps).
+// Returns an array of entries. Each element of the array is itself an array
with keys
+// corresponding to the entry table columns
+function get_entries_by_room($room_id, $interval_start, $interval_end)
+{
+ global $tbl_entry;
+
+ $sql = "SELECT *
+ FROM $tbl_entry
+ WHERE room_id = $room_id
+ AND start_time <= $interval_end AND end_time > $interval_start
+ ORDER BY start_time"; // necessary so that multiple bookings appear
in the right order
+ $res = sql_query($sql);
+
+ if ($res === FALSE)
+ {
+ trigger_error(sql_error(), E_USER_WARNING);
+ fatal_error(TRUE, get_vocab("fatal_db_error"));
+ }
+
+ return sql_all_rows_keyed($res);
+}
+
+
/** mrbsDelEntry()
*
* Delete an entry, or optionally all entries. Will also delete any newly
------------------------------------------------------------------------------
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits