"Fossies" - the Fresh Open Source Software Archive

Member "mrbs-1.9.2/web/approve_entry_handler.php" (14 Oct 2020, 3369 Bytes) of package /linux/www/mrbs-1.9.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "approve_entry_handler.php" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 1.9.0_vs_1.9.1.

    1 <?php
    2 namespace MRBS;
    3 
    4 use MRBS\Form\Form;
    5 
    6 // Handles actions on bookings awaiting approval
    7 
    8 require "defaultincludes.inc";
    9 require_once "mrbs_sql.inc";
   10 require_once "functions_mail.inc";
   11 
   12 // Get non-standard form variables
   13 $action = get_form_var('action', 'string');
   14 $id = get_form_var('id', 'int');
   15 $series = get_form_var('series', 'int');
   16 $returl = get_form_var('returl', 'string');
   17 $note = get_form_var('note', 'string');
   18 
   19 // Check the CSRF token
   20 Form::checkToken();
   21 
   22 // Check the user is authorised for this page
   23 checkAuthorised(this_page());
   24 $mrbs_user = session()->getCurrentUser();
   25 $mrbs_username = (isset($mrbs_user)) ? $mrbs_user->username : null;
   26 
   27 // Retrieve the booking details
   28 $data = get_booking_info($id, $series);
   29 $room_id = $data['room_id'];
   30 
   31 // Initialise $mail_previous so that we can use it as a parameter for notifyAdminOnBooking
   32 $mail_previous = array();
   33 $start_times = array();
   34 
   35 // Give the return URL a query string if it doesn't already have one
   36 if (strpos($returl, '?') === FALSE)
   37 {
   38   $returl .= "?year=$year&month=$month&day=$day&area=$area&room=$room";
   39 }
   40 
   41 
   42 if (isset($action))
   43 {
   44   if (need_to_send_mail())
   45   {
   46     $is_new_entry = TRUE;  // Treat it as a new entry unless told otherwise
   47   }
   48 
   49   // If we have to approve or reject a booking, check that we have rights to do so
   50   // for this room
   51   if ((($action == "approve") || ($action == "reject"))
   52        && !is_book_admin($room_id))
   53   {
   54     showAccessDenied($view, $view_all, $year, $month, $day, $area, isset($room) ? $room : null);
   55     exit;
   56   }
   57 
   58   switch ($action)
   59   {
   60     // ACTION = "APPROVE"
   61     case 'approve':
   62       if (need_to_send_mail())
   63       {
   64         $is_new_entry = FALSE;
   65         // Get the current booking data, before we change anything, for use in emails
   66         $mail_previous = get_booking_info($id, $series);
   67       }
   68       $start_times = mrbsApproveEntry($id, $series);
   69       $result = ($start_times !== FALSE);
   70       if ($result === FALSE)
   71       {
   72         $returl .= "&error=approve_failed";
   73       }
   74       // Get the new data, which will have the status changed
   75       $data = get_booking_info($id, $series);
   76       break;
   77 
   78 
   79     // ACTION = "MORE_INFO"
   80     case 'more_info':
   81       // update the last reminded time (the ball is back in the
   82       // originator's court, so the clock gets reset)
   83       update_last_reminded($id, $series);
   84       // update the more info field
   85       update_more_info($id, $series, $mrbs_user->username, $note);
   86       $result = TRUE;  // We'll assume success and end an email anyway
   87       break;
   88 
   89 
   90     // ACTION = "REMIND"
   91     case 'remind':
   92       // update the last reminded time
   93       update_last_reminded($id, $series);
   94       $result = TRUE;  // We'll assume success and end an email anyway
   95       break;
   96 
   97     default:
   98       $result = FALSE;  // should not get here
   99       break;
  100 
  101   }  // switch ($action)
  102 
  103 
  104 
  105   // Now send an email if required and the operation was successful
  106   if ($result && need_to_send_mail())
  107   {
  108     // Get the area settings for this area (we will need to know if periods are enabled
  109     // so that we will know whether to include iCalendar information in the email)
  110     get_area_settings($data['area_id']);
  111     // Send the email
  112     notifyAdminOnBooking($data, $mail_previous, $is_new_entry, $series, $start_times, $action, $note);
  113   }
  114 }
  115 
  116 // Now it's all done go back to the previous view
  117 location_header($returl);