Revision: 2293
http://mrbs.svn.sourceforge.net/mrbs/?rev=2293&view=rev
Author: cimorrison
Date: 2012-04-17 12:11:35 +0000 (Tue, 17 Apr 2012)
Log Message:
-----------
Added a maximum limit on the total number of bookings that can be made for a
day across all areas
Modified Paths:
--------------
mrbs/trunk/web/lang.en
mrbs/trunk/web/mrbs_sql.inc
mrbs/trunk/web/systemdefaults.inc.php
Modified: mrbs/trunk/web/lang.en
===================================================================
--- mrbs/trunk/web/lang.en 2012-04-16 16:37:48 UTC (rev 2292)
+++ mrbs/trunk/web/lang.en 2012-04-17 12:11:35 UTC (rev 2293)
@@ -179,6 +179,7 @@
$vocab["min_time_before"] = "The minimum interval between now and the
start of a booking is";
$vocab["max_time_before"] = "The maximum interval between now and the
end of a booking is";
$vocab["max_booking_duration"] = "The maximum duration of a booking is";
+$vocab["max_n_per_day_global"] = "The maximum number of bookings per day
per user across the whole system is";
$vocab["skip_and_book"] = "Skip and book";
$vocab["skip_and_book_note"] = "Carry on with the booking, skipping past
the conflicting entries";
Modified: mrbs/trunk/web/mrbs_sql.inc
===================================================================
--- mrbs/trunk/web/mrbs_sql.inc 2012-04-16 16:37:48 UTC (rev 2292)
+++ mrbs/trunk/web/mrbs_sql.inc 2012-04-17 12:11:35 UTC (rev 2293)
@@ -114,6 +114,8 @@
global $min_book_ahead_enabled, $min_book_ahead_secs;
global $max_book_ahead_enabled, $max_book_ahead_secs;
global $max_duration_enabled, $max_duration_secs, $max_duration_periods;
+ global $max_n_per_day_global_enabled, $max_n_per_day_global;
+ global $tbl_entry;
$errors = array();
$secs_in_day = 60*60*24;
@@ -191,6 +193,58 @@
}
}
+ // Check max number of bookings allowed per day for this user
+ if ($max_n_per_day_global_enabled)
+ {
+ // Set up arrays recording the number of existing and proposed bookings
for a day,
+ // indexed by the Unix time at the start of that day. These are static
variables
+ // because we test all the proposed bookings, which could be for multiple
rooms,
+ // before making the booking. (In theory, if MRBS ever supports repeats
with a granularity
+ // of less than a day, eg repeating every hour, then there could also be
multiple
+ // bookings on the same day).
+ static $existing = array();
+ static $proposed = array();
+ // Loop through all the days in the proposed booking, counting how many
bookings
+ // already exist for that day, and incrementing the number of proposed
bookings
+ // by one
+ $start_date = getdate($booking['start_time']);
+ $i = 0;
+ $day_start = mktime(0, 0, 0, $start_date['mon'], $start_date['mday'],
$start_date['year']);
+ while ($day_start < $booking['end_time'])
+ {
+ $day_end = mktime(0, 0, 0, $start_date['mon'], $start_date['mday'] + $i
+ 1, $start_date['year']);
+
+ if (!isset($existing[$day_start]))
+ {
+ $sql = "SELECT COUNT(*)
+ FROM $tbl_entry
+ WHERE start_time<$day_end
+ AND end_time>$day_start
+ AND create_by='" . sql_escape($booking['create_by']) . "'";
+ $existing[$day_start] = sql_query1($sql);
+ if ($existing[$day_start] < 0)
+ {
+ trigger_error(sql_error(), E_USER_WARNING);
+ fatal_error(FALSE, get_vocab("fatal_db_error"));
+ }
+ $proposed[$day_start] = 1;
+ }
+ else
+ {
+ $proposed[$day_start]++;
+ }
+
+ if (($existing[$day_start] + $proposed[$day_start]) >
$max_n_per_day_global)
+ {
+ $errors[] = get_vocab("max_n_per_day_global") . "
$max_n_per_day_global";
+ }
+
+ $day_start = $day_end;
+ $i++;
+ }
+
+ }
+
return $errors;
}
@@ -1267,6 +1321,7 @@
$tmp = mrbsCheckFree($this_booking, $ignore_id, $repeat_id);
+ $skip_this_booking = FALSE;
if (!empty($tmp))
{
// If we've been told to skip past existing bookings, then add
@@ -1275,6 +1330,7 @@
if ($skip)
{
$skip_lists[$this_booking['room_id']][] =
$this_booking['start_time'];
+ $skip_this_booking = TRUE;
}
else
{
@@ -1285,9 +1341,12 @@
// in the future want to display a list of bookings we've skipped
past)
$conflicts = array_merge($conflicts, $tmp);
}
- // if we're not an admin for this room, check that the booking
- // conforms to the booking policy
- if (!auth_book_admin($user, $this_booking['room_id']))
+ // If we're not going to skip past this booking and we're not an
admin for
+ // this room, check that the booking conforms to the booking policy.
+ // (If we're going to skip past this booking then it doesn't matter
whether
+ // it conforms to the policy or not because we're never going to
make it)
+ if (!$skip_this_booking &&
+ !auth_book_admin($user, $this_booking['room_id']))
{
$errors = mrbsCheckPolicy($this_booking);
if (count($errors) > 0)
Modified: mrbs/trunk/web/systemdefaults.inc.php
===================================================================
--- mrbs/trunk/web/systemdefaults.inc.php 2012-04-16 16:37:48 UTC (rev
2292)
+++ mrbs/trunk/web/systemdefaults.inc.php 2012-04-17 12:11:35 UTC (rev
2293)
@@ -238,6 +238,12 @@
$max_duration_secs = 60*60*2; // (seconds) - when using "times"
$max_duration_periods = 2; // (periods) - when using "periods"
+// Set the maximum number of bookings that can be made by any one user.
These are
+// global settings, but you can additionally configure per area settings.
This would
+// allow you to set policies such as allowing a maximum of 2 bookings per day
in total
+// with a maximum of 1 in Area A.
+$max_n_per_day_global_enabled = FALSE;
+$max_n_per_day_global = 2; // max 2 bookings per day in total
/******************
* Display settings
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Better than sec? Nothing is better than sec when it comes to
monitoring Big Data applications. Try Boundary one-second
resolution app monitoring today. Free.
http://p.sf.net/sfu/Boundary-dev2dev
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits