ChrisH Posted August 15, 2005 Posted August 15, 2005 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: # 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 For edit_entry_handler.php about line 152 where the code reads: # 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 have changed that to: # 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 = "You cannot book more than ".$max_days_ahead." days ahead"; $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); I will later reconfigure this to allow the administrator to override this using the functions already included. 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.
MkII Posted August 15, 2005 Posted August 15, 2005 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.
Ric_ Posted August 15, 2005 Posted August 15, 2005 @mark: for single teacher login - just edit the inc file and use a plain text password - the file is self-documented.
ChrisH Posted August 15, 2005 Author Posted August 15, 2005 I just use $auth["session"] = "nt" in the config.inc and it picks up the username of the current user. 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.
MkII Posted August 15, 2005 Posted August 15, 2005 @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
Ric_ Posted August 15, 2005 Posted August 15, 2005 @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.
Geoff Posted August 18, 2005 Posted August 18, 2005 Remeber to send a patch back to the MRBS devs Chris. That way you don't have to maintain it.
Minkus Posted January 18, 2008 Posted January 18, 2008 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: If (check_allowed($_GET["month"], $_GET["day"], $_GET["year"], $max_days_ahead)[u] or getAuthorised(2)[/u]){ } else{ $err = "You cannot book more than ".$max_days_ahead." days ahead"; $hide_title = 1; } 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: 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"]); [u]if (check_allowed($month, $day, $year, $max_days_ahead) or getAuthorised(2)){ } else{ showAccessDenied($day, $month, $year, $area); exit(); }[/u] if (MAIL_ADMIN_ON_DELETE) { include_once "functions_mail.inc"; // Gather all fields values for use in emails. $mail_previous = getPreviousEntryData($id, $series); } 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: function getWritable($creator, $user) { global $auth; // Always allowed to modify your own stuff if(strcasecmp($creator, $user) == 0) return 1; [u]// if(authGetUserLevel($user, $auth["admin"]) >= 2) if(authGetUserLevel($user, $auth["admin"]) >= 1)[/u] return 1; // Unathorised access return 0; } Hope these code changes help anyone else trying to do the same thing! 2
ChrisH Posted January 18, 2008 Author Posted January 18, 2008 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!
Gatt Posted January 18, 2008 Posted January 18, 2008 Ah excellent - we too wnat to restrict bookings to 3 weeks in advance - will play with this on Monday
Minkus Posted March 3, 2008 Posted March 3, 2008 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: $max_days_ahead = 14; $min_days_ahead = 1; (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 follows: functions.inc (insert before the final ?>) #Function to determine the amount of days between 2 dates function check_allowed($month1, $day1, $year1, $max_days_ahead[u], $min_days_ahead[/u]) { $daysbetween = check_days($month1, $day1, $year1); if ([u]$daysbetween > $max_days_ahead or $daysbetween < $min_days_ahead[/u]) { 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); } edit_entry_handler.php (insert just after $err = "") If (check_allowed($_GET["month"], $_GET["day"], $_GET["year"], $max_days_ahead[u], $min_days_ahead[/u]) or getAuthorised(2)){ } else{ $err = "You cannot book more than ".$max_days_ahead."[u] or less than ".$min_days_ahead." day(s)[/u] ahead"; $hide_title = 1; } del_entry.php (insert just before if (MAIL_ADMIN_ON_DELETE)): if (check_allowed($month, $day, $year, $max_days_ahead[u], $min_days_ahead[/u]) or getAuthorised(2)){ } else{ showAccessDenied($day, $month, $year, $area); exit(); } Hope this helps! 1
beeswax Posted September 29, 2008 Posted September 29, 2008 You mention a functions.inc, if is this a file, I can't locate it, so I assume it's something else. Ta
localzuk Posted September 29, 2008 Posted September 29, 2008 functions.inc should be in the base directory of your mrbs install.
beeswax Posted September 30, 2008 Posted September 30, 2008 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.
mullet_man Posted December 3, 2008 Posted December 3, 2008 Cheers, just added the code by Minkus and its working a treat. Many thanks Ste.
beeswax Posted January 5, 2009 Posted January 5, 2009 I'm still having difficulties with this. Are we talking of altering the 3 files in the MRBS\web folder? When I've applied the changes the room booking system page fails to load, I just get a blank.
DanRF Posted February 2, 2009 Posted February 2, 2009 Thanks for the post on how to add this feature it was just what we needed at the school I work at. I've added a comment to a feature request for this feature on the MRBS website notifying that the feature has been written by an edugeek member. https://sourceforge.net/tracker/index.php?func=detail&aid=2191070&group_id=5113&atid=355113 So I'm hoping one of the MRBS developers will follow the link here and add the feature into the next version either inspired from the code here or if theres no objections copied from here so next time someone needs this feature or I do an upgrade I won't have to cut and paste code from here. Thanks, Daniel
AdamM Posted March 4, 2009 Posted March 4, 2009 Hi Chris, Did you ever manage to create the bulk upload page for timetabled lessons? I have been looking at MRBS for some time trying to do this but have been unsuccessful so far... MTIA
ChrisH Posted March 4, 2009 Author Posted March 4, 2009 Hi Chris, Did you ever manage to create the bulk upload page for timetabled lessons? I have been looking at MRBS for some time trying to do this but have been unsuccessful so far... MTIA No sorry I never did it in the end as I got lazy when we got another member of staff so I delegated it . I think Webmans booking system might have this functionality? 1
AdamM Posted March 4, 2009 Posted March 4, 2009 Thanks looks like I'll just have to keep plodding on with it Have some Thanks!!
Outlaw27 Posted March 25, 2009 Posted March 25, 2009 Have added minkus code and go the mrbs working to allow booking 5 days in advance. However am getting an error message display above the company title when I try to book more than 5 days in advance Warning: Missing argument 5 for check_allowed(), called in C:\wamp\www\edit_entry_handler.php on line 345 and defined in C:\wamp\www\functions.inc on line 781 Can anyone help solve this problem
Minkus Posted September 25, 2009 Posted September 25, 2009 (edited) Hi all, Have just upgraded to MRBS 1.4.2, and some of the code in the posts above needs updating. Unfortunately I don't seem to be able to edit the originals, so here's an up-to-date version with the latest code: To make it so that any logged-in user can edit an existing booking, not just the owner and administrators: Edit mrbs_auth.inc Inside function getWritable, change if(authGetUserLevel($user) >= 2) to if(authGetUserLevel($user) >= 1) To create a maximum and minimum book-ahead time, which can be bypassed by administrators: Add the following settings to config.inc.php: $max_days_ahead = 14; $min_days_ahead = 1; Add the following to functions.inc before the final '?>': #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); } Add the following to edit_entry_handler.php just after '$rules_broken = array();' $required_level = (isset($max_level) ? $max_level : 2); If (check_allowed($_GET["month"], $_GET["day"], $_GET["year"], $max_days_ahead, $min_days_ahead) or getAuthorised($required_level)){ } else{ $valid_booking = FALSE; $rules_broken[] = "You cannot book more than ".$max_days_ahead." or less than ".$min_days_ahead." day(s) ahead"; } Add the following to del_entry.php just before 'if (MAIL_ADMIN_ON_DELETE)': $required_level = (isset($max_level) ? $max_level : 2); if (check_allowed($month, $day, $year, $max_days_ahead, $min_days_ahead) or getAuthorised($required_level)){ } else{ showAccessDenied($day, $month, $year, $area, ""); exit(); } To prevent non-administrators from creating or deleting a series of repeating entries: Edit edit_entry_handler.php Change if(count($reps) < $max_rep_entrys) to $required_level = (isset($max_level) ? $max_level : 2); if(count($reps) < $max_rep_entrys and getAuthorised($required_level)) Edit del_entry.php Change if (getAuthorised(1) && ($info = mrbsGetEntryInfo($id))) to $required_level = (isset($max_level) ? $max_level : 2); if (getAuthorised(1) && ($info = mrbsGetEntryInfo($id)) && ($series != 1 || getAuthorised($required_level))) Hope this helps! Edited September 25, 2009 by Minkus Updated to use MRBS 1.4.2 $max_level config value
beeswax Posted September 25, 2009 Posted September 25, 2009 I think this is the stand alone version of MRBS not the version which integrates with Moodle?
Outlaw27 Posted October 8, 2009 Posted October 8, 2009 I have entered the excellent code from Minkus to prevent booking more than 5 days in advance. Works perfectly on a wamp virtual server. However when I upload this I am getting a error message for non admin users 'Scheduling Conflict Cannot book more than days in advance' This happens even it if try to book on today's date. Anyone any ideas please
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now