Fontayne56 (9th July 2009)
We use MRBS here to control the booking of IT rooms. It's PHP/MYSQL based and is quite flexible. I have been using it for over a year and it stops me getting phone calls every 2 mins by staff asking what rooms are free or if they can book them.
The only problem I have had is that some Teachers book all the rooms up every week to the end of the term even though they are told not to and MRBS only allows you to limit repeat booking and not actual time period. I have coded it to do this now and seems to work ok.
Try at your own risk!!!!! I'm not very good with PHP as I havent done much in it so the code might be a bit sloppy.
The altered files are:
functions.inc
edit_entry_handler.php
config.inc
In functions.inc I have added the following functions:
For edit_entry_handler.php about line 152 where the code reads:Code:# Functions Added By Chris Hindmarch #Function to determine the amount of days between 2 dates function check_allowed($month1, $day1, $year1,$max_days_ahead) { $daysbetween = check_days($month1, $day1, $year1); if ($daysbetween >= $max_days_ahead ) { return(0); } Else { return(1); } } function check_days($month1, $day1, $year1) { # Get Current Date $month2 = date('m'); $day2 = date('d'); $year2 = date('y'); # Turn the dates into a timestamp and subtract the current date from the date supplied. $dateDiff = mktime(0,0,0,$month1, $day1, $year1) - mktime(0,0,0,$month2, $day2, $year2); #Round the date down $dateDiff = floor($dateDiff/60/60/24); return($dateDiff); } #End Added Functions
I have changed that to:Code:# Check for any schedule conflicts in each room we're going to try and # book in $err = ""; foreach ( $rooms as $room_id ) { if ($rep_type != 0 && !empty($reps)) { if(count($reps) < $max_rep_entrys) { for($i = 0; $i < count($reps); $i++) { # calculate diff each time and correct where events # cross DST $diff = $endtime - $starttime; $diff += cross_dst($reps[$i], $reps[$i] + $diff);
I will later reconfigure this to allow the administrator to override this using the functions already included.Code:# Check for any schedule conflicts in each room we're going to try and # book in $err = ""; # Chris Hindmarch Additional code If (check_allowed($_GET["month"], $_GET["day"], $_GET["year"], $max_days_ahead)){ } else{ $err = "<h1>You cannot book more than ".$max_days_ahead." days ahead</h1>"; $hide_title = 1; } #End CH Additional code foreach ( $rooms as $room_id ) { if ($rep_type != 0 && !empty($reps)) { if(count($reps) < $max_rep_entrys) { for($i = 0; $i < count($reps); $i++) { # calculate diff each time and correct where events # cross DST $diff = $endtime - $starttime; $diff += cross_dst($reps[$i], $reps[$i] + $diff);
In the config.inc add the following
$max_days_ahead = 21 or whatever numdays you need.
ps watch out for code wrapped by the forum.
Nice one Chris. I've got a test running here. I've managed to get the weekends not to show, but I couldn't work out the authentification - I wanted a single teacher login so that they could all make provisional bookings. What method do you use?
Also there's a new module for moodle that also does room bookings - to be released in september.
I like MRBS tho' so i'd like to sort that out.

@mark: for single teacher login - just edit the inc file and use a plain text password - the file is self-documented.
I just usein the config.inc and it picks up the username of the current user.Code:$auth["session"] = "nt"
The only problem with having one logon is they can delete each others bookings. At least if it's just them or you then they only have themselves to blame.
I was going to write a bulk import page that uses a CSV to import all the timetabled lessons at one point as going through and adding them manually is a complete pain. I have already done this manually but will be good for next year.
@Ric_ - I haven't seen that! - I asked on the mailing list and some guy gave me a wad of code to add to achieve the same!
@ChrisH - That'd be superb! - agreed - that IS a royal PITA

@mark: It's near the bit hat sets the admin password to administrator/secret by default (not in front of my box so I can't tell you the exact lines). There is a section named 'authentication' (or similar) though.
i'll take a look - thanks
Remeber to send a patch back to the MRBS devs Chris. That way you don't have to maintain it.
Hi all,
I've been setting up MRBS as well, and used Chris' code to implement the 'book ahead' restriction.
We wanted to make it so that the restriction didn't apply to administrators - turned out to be quite easy.
We changed Chris' code in edit_entry_handler - add the underlined code:
I also made it so that the same 'book ahead' restriction applied to the delete code (for why we needed to do this, read on) - in del_entry.php, add the underlined code:Code:If (check_allowed($_GET["month"], $_GET["day"], $_GET["year"], $max_days_ahead) or getAuthorised(2)){ } else{ $err = "<h1>You cannot book more than ".$max_days_ahead." days ahead</h1>"; $hide_title = 1; }
Finally, we also made it so that any logged in user was able to edit existing bookings, not just the owner and administrators. (This was why it was important for us to make the Book Ahead restriction apply to deleting entries as well as adding). Edit mrbs_auth.inc and change the GetWritable function:Code:if(getAuthorised(1) && ($info = mrbsGetEntryInfo($id)) && ($series != 1 || getAuthorised(2))) { $day = strftime("%d", $info["start_time"]); $month = strftime("%m", $info["start_time"]); $year = strftime("%Y", $info["start_time"]); $area = mrbsGetRoomArea($info["room_id"]); if (check_allowed($month, $day, $year, $max_days_ahead) or getAuthorised(2)){ } else{ showAccessDenied($day, $month, $year, $area); exit(); } if (MAIL_ADMIN_ON_DELETE) { include_once "functions_mail.inc"; // Gather all fields values for use in emails. $mail_previous = getPreviousEntryData($id, $series); }
Hope these code changes help anyone else trying to do the same thing!Code:function getWritable($creator, $user) { global $auth; // Always allowed to modify your own stuff if(strcasecmp($creator, $user) == 0) return 1; // if(authGetUserLevel($user, $auth["admin"]) >= 2) if(authGetUserLevel($user, $auth["admin"]) >= 1) return 1; // Unathorised access return 0; }
Fontayne56 (9th July 2009)
Thats great about the admin bit. I have been wanting to do something like this for ages but never ended up looking into it.
Have some rep!

Ah excellent - we too wnat to restrict bookings to 3 weeks in advance - will play with this on Monday![]()
Hi,
Have just performed some more modifications to set a minimum book ahead time. We print off the booking sheet every morning and it's a bit annoying if a teacher goes online and makes a change after that point!
The following will allow you to add the following variables to your config.inc.php:
(We also changed it so that the max_days_ahead value no longer includes 'today', as this made more sense for us. Simple change from >= to > in the check_allowed function.)Code:$max_days_ahead = 14; $min_days_ahead = 1;
Code follows:
functions.inc (insert before the final ?>)
edit_entry_handler.php (insert just after $err = "")Code:#Function to determine the amount of days between 2 dates function check_allowed($month1, $day1, $year1, $max_days_ahead, $min_days_ahead) { $daysbetween = check_days($month1, $day1, $year1); if ($daysbetween > $max_days_ahead or $daysbetween < $min_days_ahead) { return(0); } Else { return(1); } } function check_days($month1, $day1, $year1) { # Get Current Date $month2 = date('m'); $day2 = date('d'); $year2 = date('y'); # Turn the dates into a timestamp and subtract the current date from the date supplied. $dateDiff = mktime(0,0,0,$month1, $day1, $year1) - mktime(0,0,0,$month2, $day2, $year2); #Round the date down $dateDiff = floor($dateDiff/60/60/24); return($dateDiff); }
del_entry.php (insert just before if (MAIL_ADMIN_ON_DELETE)):Code:If (check_allowed($_GET["month"], $_GET["day"], $_GET["year"], $max_days_ahead, $min_days_ahead) or getAuthorised(2)){ } else{ $err = "<h1>You cannot book more than ".$max_days_ahead." or less than ".$min_days_ahead." day(s) ahead</h1>"; $hide_title = 1; }
Hope this helps!Code:if (check_allowed($month, $day, $year, $max_days_ahead, $min_days_ahead) or getAuthorised(2)){ } else{ showAccessDenied($day, $month, $year, $area); exit(); }
LOUD (6th November 2008)
You mention a functions.inc, if is this a file, I can't locate it, so I assume it's something else. Ta

functions.inc should be in the base directory of your mrbs install.
I didn't give you the full picture. I'm using MRBS integrated into Moodle. The function.inc file doesn't exist in the MRBS root folder.![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)