Jump to content

MRBS stop booking X days in advance code mod


Recommended Posts

Posted

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.

Posted

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.

Posted

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.

Posted

@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

Posted
@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.
  • 2 years later...
Posted

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!

  • Thanks 2
Posted

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!

  • 1 month later...
Posted

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!

  • Thanks 1
  • 6 months later...
  • 2 months later...
  • 1 month later...
Posted
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.
  • 4 weeks later...
Posted

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

  • 1 month later...
Posted

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

Posted
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 :p . I think Webmans booking system might have this functionality?

  • Thanks 1
  • 3 weeks later...
Posted

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

  • 5 months later...
Posted (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 by Minkus
Updated to use MRBS 1.4.2 $max_level config value
  • 2 weeks later...
Posted

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...