--- /dev/null
+<?php
+/**
+ * @file mod_roomReservationBookingPage.inc
+ * Page that shows the booking table
+ * @author Roland Hieber (roland.hieber@wilhelm-gym.net)
+ * @date 24.02.2008
+ *
+ * Copyright © 2007 Roland Hieber
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+require_once("share.inc");
+require_once("ctrl.inc");
+require_once("mod_room-reservation/mod_roomReservationPage.inc");
+require_once("mod_room-reservation/mod_roomReservationBookingTable.inc");
+require_once("mod_room-reservation/mod_roomReservationBookingsManager.inc");
+require_once("mod_room-reservation/mod_roomReservationConfig.inc");
+
+/**
+ * Page that shows the booking table
+ * @todo document, don't forget GET parameters
+ */
+class mod_roomReservationBookingPage extends mod_roomReservationPage {
+
+ /** (mod_roomReservationConfig) Reference to the configuration object */
+ protected $oCfg;
+ /**
+ * (mod_roomReservationRoomsManager) Reference to the rooms manager object
+ */
+ protected $oRm;
+ /**
+ * (mod_roomReservationBookingsManager) Reference to the bookings manager
+ * object
+ */
+ protected $oBm;
+ /** (timestamp) Starting date of the booking table */
+ protected $tsStart;
+ /** (int) Name of the room to show in the booking table */
+ protected $strRoom;
+
+ /** (mod_roomReservationBookingTable) The booking table */
+ protected $oBt;
+
+ /***************************************************************************/
+ /**
+ * @name Constructor
+ * @{
+ * Constructor
+ * @param $oCfg (mod_roomReservationConfig) Reference to the configuration
+ * object
+ * @param $oRm (mod_roomReservationRoomsManager) Reference to the rooms
+ * manager object
+ * @param $oBm (mod_roomReservationBookingsManager) Reference to the
+ * bookings manager object
+ * @return mod_roomReservationBookingPage
+ */
+ public function __construct(mod_roomReservationConfig &$oCfg,
+ mod_roomReservationRoomsManager &$oRm,
+ mod_roomReservationBookingsManager &$oBm) {
+ $this->oCfg = $oCfg;
+ $this->oRm = $oRm;
+ $this->oBm = $oBm;
+
+ // create the booking table here, so the CSS is already added
+ /** @todo maybe move it into beforeAddCSS()... ? */
+ $this->oBt = new mod_roomReservationBookingsTable($this->oCfg, $this->oRm,
+ $this->oBm, "?bookingpage[action]=edit", "?bookingpage[action]=delete");
+
+ parent::__construct($oCfg);
+ $this->setTitle(_c("Room Reservation Schedule"));
+ $this->setIcon("mod_room-reservation_index");
+ }
+
+ /***************************************************************************/
+ /**
+ * @}
+ * @name Initialization
+ * @{
+ */
+
+ /**
+ * Process the REQUEST variables and preset the some variables
+ * @return void
+ */
+ protected function processRequestVariables() {
+ // take all settings from the booking table
+ $this->setRoom($this->oBt->getRoom());
+ $this->setStart($this->oBt->getDate());
+ }
+
+ /***************************************************************************/
+ /**
+ * @}
+ * @name Access to attributes
+ * @{
+ */
+
+ /**
+ * Set the starting date
+ * @param $ts (timestamp)
+ */
+ public function setStart($ts) { $this->tsStart = intval($ts); }
+
+ /**
+ * Set the room to show in the booking table
+ * @param $str (string) Name of the room
+ */
+ public function setRoom($str) { $this->strRoom = $str; }
+
+ /**
+ * Get the starting date
+ * @return int
+ */
+ public function getStart() { return intval($this->tsStart); }
+
+ /**
+ * Get the name of the room to show in the booking table
+ * @return string
+ */
+ public function getRoom() { return $this->strRoom; }
+
+ /***************************************************************************/
+ /**
+ * @}
+ * @name Output
+ * @{
+ */
+
+ /**
+ * Show the page.
+ * @return void
+ */
+ public function doShow() {
+ // Protect access
+ if(!$this->oCfg->userCanView()) {
+ echo sprintf("<p class='err'>%s</p>",
+ MOD_ROOM_RESERVATION_ERROR_ACCESS_DENIED);
+ _PageBlue();
+ die();
+ }
+
+ Title(_c("room-reservation:Book rooms"));
+
+ // Form for room selection
+ /** @todo checkbox for recurring booking */
+ echo sprintf("<form name='room' method='get' action='%s'>",
+ $_SERVER["PHP_SELF"]);
+ echo sprintf("<input type='hidden' name='mod_roomReservationBookingTable".
+ "[date]' value='%d' />\n", $this->getStart());
+
+ // Show rooms only if it is whitelisted
+ try {
+ $aor = $this->oCfg->getWhitelistedRooms();
+ } catch(SQLException $e) {
+ trigger_error($e->getMessage());
+ }
+ if(count($aor) > 0) {
+ echo _c("room-reservation:Room:") . sprintf(" <select onchange=".
+ "'document.forms[\"room\"].submit()' width='250' ".
+ "name='mod_roomReservationBookingTable[room]'>\n", $this->getStart());
+ foreach($aor as $or) {
+ // note to myself: no qu() here, seems this is being done automagically
+ echo sprintf("<option value='%s'%s>%s</option>\n", $or->getName(),
+ ($or->getName() == $this->getRoom()) ? " selected='selected'" : "",
+ $or->getName());
+ }
+ echo sprintf("</select> <%s value='%s' /></form><p />\n",
+ $GLOBALS["stdbtn"], _("Change"));
+ } else {
+ printf("<p>%s</p>\n", _c("room-reservation:No rooms have been ".
+ "configured yet."));
+ return;
+ }
+
+ // Print line with next 5 or so weeks
+ $strSep = " | ";
+ $strLink = sprintf("<a href='%s?mod_roomReservationBookingTable[date]=%%d".
+ "&mod_roomReservationBookingTable[room]=%%s'>%%s</a>",
+ $_SERVER["PHP_SELF"]);
+ echo "<p>".sprintf($strLink, time(), qu($this->getRoom()),
+ _c("room-reservation:Current Week")) . $strSep;
+ echo sprintf($strLink, strtotime("1 week ago", $this->getStart()),
+ qu($this->getRoom()), _c("room-reservation:< Back")) . $strSep;
+ echo sprintf("<b>%s</b>", _sprintf_ord(_c("room-reservation:%d# week"),
+ date("W", $this->getStart()))) . $strSep;
+ for($i = 1; $i <= 5; $i++) {
+ $nNextWeek = strtotime("$i week", $this->getStart());
+ echo sprintf($strLink, $nNextWeek, qu($this->getRoom()), _sprintf_ord(
+ _c("room-reservation:%d# week"), date("W", $nNextWeek)));
+ echo $strSep;
+ }
+ echo sprintf($strLink, strtotime("1 week", $this->getStart()),
+ qu($this->getRoom()), _c("room-reservation:Next >"))."</p>\n";
+
+ $this->oBt->show();
+ }
+}
+?>