X-Git-Url: https://git.rohieb.name/iserv-mod-room-reservation.git/blobdiff_plain/c28965b6f095c30c7a9cc886d54c2a5d94304f46..ada3bd52df2712a6c6ead81aa646d5ec47aeeca2:/includes/mod_roomReservationBookingTable.inc?ds=sidebyside diff --git a/includes/mod_roomReservationBookingTable.inc b/includes/mod_roomReservationBookingTable.inc index c70ddc1..706d757 100644 --- a/includes/mod_roomReservationBookingTable.inc +++ b/includes/mod_roomReservationBookingTable.inc @@ -118,6 +118,8 @@ class mod_roomReservationBookingsTable /* extends mclWidget */ { protected $strPostAccount; /** (int) recurrence interval, POST data */ protected $nPostInterval; + /** (string) Array of error messages */ + protected $asErrors = array(); /***************************************************************************/ /** @@ -139,7 +141,11 @@ class mod_roomReservationBookingsTable /* extends mclWidget */ { $this->oRm = $oRm; $this->oBm = $oBm; - $this->processRequestVariables(); + try { + $this->processRequestVariables(); + } catch(Exception $e) { + $this->asErrors[] = $e->getMessage(); + } $this->addCSS(); } @@ -151,16 +157,19 @@ class mod_roomReservationBookingsTable /* extends mclWidget */ { */ /** - * Process the REQUEST variables and preset the some variables + * Process the REQUEST variables and preset the some variables. Throws an + * exception if the room provided by the GET data is not allowed for booking * @return void + * @throws Exception */ protected function processRequestVariables() { // default values - $aoRooms = $this->oRm->getRooms(); - if($aoRooms != array()) { - $or = $aoRooms[0]; - $this->setRoom($or->getName()); + $aoRooms = $this->oCfg->getWhitelistedRooms(); + if(count($aoRooms) < 1) { + $this->setRoom(""); + } else { + $this->setRoom($aoRooms[0]->getName()); } $this->setDate(time()); $this->setAction(MOD_ROOM_RESERVATION_BT_ACTION_SHOW); @@ -179,8 +188,9 @@ class mod_roomReservationBookingsTable /* extends mclWidget */ { MOD_ROOM_RESERVATION_BT_ACTION_SHOW))))); $this->setDate(isset($_GET["mod_roomReservationBookingTable"]["date"]) ? intval($_GET["mod_roomReservationBookingTable"]["date"]) : time()); - $this->setRoom(isset($_GET["mod_roomReservationBookingTable"]["room"]) ? - $_GET["mod_roomReservationBookingTable"]["room"] : ""); + if(isset($_GET["mod_roomReservationBookingTable"]["room"])) { + $this->setRoom($_GET["mod_roomReservationBookingTable"]["room"]); + } $this->setTsFirst( isset($_GET["mod_roomReservationBookingTable"]["tsfirst"]) ? intval($_GET["mod_roomReservationBookingTable"]["tsfirst"]) : 0); @@ -295,10 +305,19 @@ class mod_roomReservationBookingsTable /* extends mclWidget */ { /** * Set the room of the requested booking or the room to be shown in the - * booking table + * booking table. Throws an Exception if the room is not allowed for booking. * @param $str (string) + * @throws Exception */ - protected function setRoom($str) { $this->strRoom = $str; } + protected function setRoom($str) { + // only allow whitelisted rooms + if($this->oCfg->isRoomWhitelisted($str)) { + $this->strRoom = $str; + } else { + throw new Exception(_c("room-reservation:This room is not available ". + "for booking.")); + } + } /** * Set the reason of the requested booking @@ -424,7 +443,13 @@ CSS; throw new AccessException(MOD_ROOM_RESERVATION_ERROR_ACCESS_DENIED); return; } - + + // print error messages and return if there are any + if(count($this->asErrors) > 0) { + printf("

%s

", join("
\n", $this->asErrors)); + return; + } + // Print the header with the days $ncTs = sizeof($this->oCfg->getTimeslices()); $nDays = ($this->oCfg->isShowWeekend()) ? 7 : 5; @@ -455,8 +480,8 @@ CSS; $strLessons = $this->oCfg->isShowLessons() ?_sprintf_ord( _c("room-reservation:%s# lesson"), $nTs + 1) . "
" : ""; $oTs = $this->oCfg->getTimeslice($nTs); - $strTs = sprintf("%s - %s", strftime(_("%#I:%M %p"), $oTs->getBegin()), - strftime(_("%#I:%M %p"), $oTs->getEnd())); + $strTs = sprintf("%s - %s", gmstrftime(_("%#I:%M %p"), $oTs->getBegin()), + gmstrftime(_("%#I:%M %p"), $oTs->getEnd())); // First column: Lesson echo sprintf("%s", $strLessons . $strTs); @@ -546,6 +571,7 @@ CSS; if($nNewUid > 0) { // print new booking and increment the "next row" variable by // the current span + $oNewBooking->setUid($nNewUid); $anNextRow[$i] += $this->printBooking($nTs, $ts, $oNewBooking, MOD_ROOM_RESERVATION_BTPB_NEW); }