+ Post New Thread
Page 1 of 3 123 LastLast
Results 1 to 15 of 31
Scripts Thread, MRBS stop booking X days in advance code mod in Coding and Web Development; We use MRBS here to control the booking of IT rooms. It's PHP/MYSQL based and is quite flexible. I have ...
  1. #1
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    4,993
    Thank Post
    120
    Thanked 286 Times in 263 Posts
    Rep Power
    107

    MRBS stop booking X days in advance code mod

    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:

    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
    For edit_entry_handler.php about line 152 where the code reads:

    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 have changed that to:

    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);
    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.

  2. #2
    mark's Avatar
    Join Date
    Jun 2005
    Posts
    3,986
    Thank Post
    269
    Thanked 52 Times in 46 Posts
    Blog Entries
    2
    Rep Power
    47

    Re: MRBS stop booking X days in advance code mod

    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.

  3. #3

    Ric_'s Avatar
    Join Date
    Jun 2005
    Location
    London
    Posts
    7,592
    Thank Post
    109
    Thanked 770 Times in 598 Posts
    Rep Power
    183

    Re: MRBS stop booking X days in advance code mod

    @mark: for single teacher login - just edit the inc file and use a plain text password - the file is self-documented.

  4. #4
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    4,993
    Thank Post
    120
    Thanked 286 Times in 263 Posts
    Rep Power
    107

    Re: MRBS stop booking X days in advance code mod

    I just use
    Code:
    $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.

  5. #5
    mark's Avatar
    Join Date
    Jun 2005
    Posts
    3,986
    Thank Post
    269
    Thanked 52 Times in 46 Posts
    Blog Entries
    2
    Rep Power
    47

    Re: MRBS stop booking X days in advance code mod

    @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

  6. #6

    Ric_'s Avatar
    Join Date
    Jun 2005
    Location
    London
    Posts
    7,592
    Thank Post
    109
    Thanked 770 Times in 598 Posts
    Rep Power
    183

    Re: MRBS stop booking X days in advance code mod

    @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.

  7. #7
    mark's Avatar
    Join Date
    Jun 2005
    Posts
    3,986
    Thank Post
    269
    Thanked 52 Times in 46 Posts
    Blog Entries
    2
    Rep Power
    47

    Re: MRBS stop booking X days in advance code mod

    i'll take a look - thanks

  8. #8

    Geoff's Avatar
    Join Date
    Jun 2005
    Location
    Fylde, Lancs, UK.
    Posts
    11,813
    Thank Post
    110
    Thanked 586 Times in 507 Posts
    Blog Entries
    1
    Rep Power
    225

    Re: MRBS stop booking X days in advance code mod

    Remeber to send a patch back to the MRBS devs Chris. That way you don't have to maintain it.

  9. #9

    Join Date
    Jun 2007
    Location
    Colchester, Essex, UK
    Posts
    56
    Thank Post
    2
    Thanked 16 Times in 14 Posts
    Rep Power
    21
    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:

    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;
    }
    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(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);
        }
    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:
    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;
    }
    Hope these code changes help anyone else trying to do the same thing!

  10. Thanks to Minkus from:

    Fontayne56 (9th July 2009)

  11. #10
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    4,993
    Thank Post
    120
    Thanked 286 Times in 263 Posts
    Rep Power
    107
    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!

  12. #11

    Gatt's Avatar
    Join Date
    Jan 2006
    Posts
    6,765
    Thank Post
    873
    Thanked 673 Times in 442 Posts
    Rep Power
    502
    Ah excellent - we too wnat to restrict bookings to 3 weeks in advance - will play with this on Monday

  13. #12

    Join Date
    Jun 2007
    Location
    Colchester, Essex, UK
    Posts
    56
    Thank Post
    2
    Thanked 16 Times in 14 Posts
    Rep Power
    21
    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:

    Code:
    $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 ?>)
    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);
    }
    edit_entry_handler.php (insert just after $err = "")
    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;
    }
    del_entry.php (insert just before if (MAIL_ADMIN_ON_DELETE)):
    Code:
        if (check_allowed($month, $day, $year, $max_days_ahead, $min_days_ahead) or getAuthorised(2)){
        }
        else{
        showAccessDenied($day, $month, $year, $area);
        exit();
        }
    Hope this helps!

  14. Thanks to Minkus from:

    LOUD (6th November 2008)

  15. #13

    beeswax's Avatar
    Join Date
    Jul 2005
    Location
    England
    Posts
    2,285
    Thank Post
    285
    Thanked 225 Times in 153 Posts
    Rep Power
    131

    Just a little clarification, please...

    You mention a functions.inc, if is this a file, I can't locate it, so I assume it's something else. Ta

  16. #14

    localzuk's Avatar
    Join Date
    Dec 2006
    Location
    Minehead
    Posts
    18,142
    Thank Post
    522
    Thanked 2,550 Times in 1,979 Posts
    Blog Entries
    24
    Rep Power
    877
    functions.inc should be in the base directory of your mrbs install.

  17. #15

    beeswax's Avatar
    Join Date
    Jul 2005
    Location
    England
    Posts
    2,285
    Thank Post
    285
    Thanked 225 Times in 153 Posts
    Rep Power
    131
    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.

SHARE:
+ Post New Thread
Page 1 of 3 123 LastLast

Similar Threads

  1. Slow days, nothing to do!
    By Samson in forum General Chat
    Replies: 20
    Last Post: 3rd July 2007, 10:33 AM
  2. MRBS
    By j17sparky in forum Web Development
    Replies: 6
    Last Post: 17th November 2006, 03:11 PM
  3. 6 Months In Few Days
    By russdev in forum General EduGeek News/Announcements
    Replies: 2
    Last Post: 6th December 2005, 02:52 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •