Open jberanek opened 8 years ago
These aren't standard achievable with the standard policy settings. You'll need to add some custom policy checks to mrbsCheckPolicy() in mrbs_sql.inc.
Original comment by: campbell-m
Thanks for the response Campbell.
Could you possibly provide me with some guidence on how to approach this sql custom policy checks? Even a resource online would be much appreciated.
Original comment by: *anonymous
Here's the basic logic. You'll need to pad this out a bit - follow the examples in mrbsCheckPolicy() and mrbsCheckInterval().
// (1) Prevent users from booking both rooms out at the same time
$area_id = get_area($booking['room_id']);
// Count how many other bookings in this area overlap with this one
$sql = "SELECT COUNT *
FROM $tbl_entry E, $tbl_room R
WHERE E.end_time > $booking['start_time']
AND E.start_time < $booking['end_time']
AND E.room_id=R.id
AND R.area_id=$area_id
AND R.disabled=0 // assuming it doesn't matter if there's an overlapping booking in a disabled room
AND E.id <> $ignore";
// (2a) Prevent users from booking two consecutive slots in a day but still be able to book more than once a day if required
Even if the slots are for different rooms, two consecutive slots are not allowed
$sql = "SELECT COUNT *
FROM $tbl_entry
WHERE E.start_time = $booking['end_time']
OR E.end_time = $booking['start_time]";
// (2a) Prevent users from booking two consecutive slots in a day for the same room, but still be able to book more than once a day if required
$sql = "SELECT COUNT *
FROM $tbl_entry
WHERE (start_time = $booking['end_time']
OR end_time = $booking['start_time])
AND room_id = $booking['room_id']";
// (3) Restrict all bookings to withe 1hr or 2hr slots
$duration = $booking['end_time'] - $booking['start_time'];
if (($duration != 3600) && ($duration != 7200))
{
// Policy broken
}
Original comment by: campbell-m
I just want to implement (2a) but it stops working with a blank page. Can you please tell me what I'm doing wrong.
if($no_consecutive_enabled) { global $tbl_entry; $sql = "SELECT COUNT * FROM $tbl_entry WHERE (start_time = $booking['end_time'] OR end_time = $booking['start_time']) AND room_id = $booking['room_id']";
$res = db()->query($sql);
}
It doesn't open in browser with this added in creation section of mrbs_sql.inc (line 321).
Original comment by: *anonymous
Try
SELECT COUNT(*)
instead of
SELECT COUNT *
An important thing to note is that if you're going to develop PHP, you're going to have to be able to read the PHP/webserver error log, so you can read what is going wrong.
The other thing I wonder is if you're defined the variable $no_consecutive_enabled
Original comment by: jberanek
Yes, I've defined the var $no_consecutive_enabled in config.inc.php
it gives the error
syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)
Original comment by: *anonymous
I got the error out but it says undefined var error. Is there a way to do this with or without var and after checking that $res>0 what to do or how the message will be printed telling that consecutive booking not allowed.
Also, don't know why it shows one bookin per user per area without me activating it.
Original comment by: *anonymous
it shows
The new booking will conflict with the following policies:
The maximum number of bookings per day per user in this area is 1
but i haven't set this policy.
Original comment by: *anonymous
global $tbl_entry; $sql = "SELECT * FROM $tbl_entry WHERE (start_time = '".$booking['end_time']."' OR end_time = '".$booking['start_time']."') AND room_id = '".$booking['room_id']."'";
$res = db()->query($sql);
if(!$res){$errors[] = get_vocab('no_consecutive');}
this is the code i've right now but it isn't working
i can still book consecutively
Original comment by: *anonymous
Hi There
Hope I can get some assistance with three changes I would like to make with my MRBS setup.
I am using MRBS v 1.5.0 and have one area and two rooms.
Many thanks on any input. Let me know if I need to provide any other information or code snippets.
Reported by: *anonymous
Original Ticket: mrbs/support-requests/965