3 * @file mod_roomReservationBookingPage.inc
4 * Page that shows the booking table
5 * @author Roland Hieber (roland.hieber@wilhelm-gym.net)
8 * Copyright © 2007 Roland Hieber
10 * Permission is hereby granted, free of charge, to any person obtaining
11 * copy of this software and associated documentation files (the "Software"),
12 * to deal in the Software without restriction, including without limitation
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 * and/or sell copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29 require_once("share.inc");
30 require_once("ctrl.inc");
31 require_once("mod_room-reservation/mod_roomReservationPage.inc");
32 require_once("mod_room-reservation/mod_roomReservationBookingTable.inc");
33 require_once("mod_room-reservation/mod_roomReservationBookingsManager.inc");
34 require_once("mod_room-reservation/mod_roomReservationConfig.inc");
37 * Page that shows the booking table
38 * @todo document, don't forget GET parameters
40 class mod_roomReservationBookingPage extends mod_roomReservationPage {
42 /** (mod_roomReservationConfig) Reference to the configuration object */
45 * (mod_roomReservationRoomsManager) Reference to the rooms manager object
49 * (mod_roomReservationBookingsManager) Reference to the bookings manager
53 /** (timestamp) Starting date of the booking table */
55 /** (int) Name of the room to show in the booking table */
58 /** (mod_roomReservationBookingTable) The booking table */
61 /***************************************************************************/
66 * @param $oCfg (mod_roomReservationConfig) Reference to the configuration
68 * @param $oRm (mod_roomReservationRoomsManager) Reference to the rooms
70 * @param $oBm (mod_roomReservationBookingsManager) Reference to the
71 * bookings manager object
72 * @return mod_roomReservationBookingPage
74 public function __construct(mod_roomReservationConfig &$oCfg,
75 mod_roomReservationRoomsManager &$oRm,
76 mod_roomReservationBookingsManager &$oBm) {
81 // create the booking table here, so the CSS is already added
82 /** @todo maybe move it into beforeAddCSS()... ? */
83 $this->oBt = new mod_roomReservationBookingsTable($this->oCfg, $this->oRm,
84 $this->oBm, "?bookingpage[action]=edit", "?bookingpage[action]=delete");
86 parent::__construct($oCfg);
87 $this->setTitle(_c("Room Reservation Schedule"));
88 $this->setIcon("mod_room-reservation_index");
91 /***************************************************************************/
94 * @name Initialization
99 * Process the REQUEST variables and preset the some variables
102 protected function processRequestVariables() {
103 // take all settings from the booking table
104 $this->setRoom($this->oBt->getRoom());
105 $this->setStart($this->oBt->getDate());
108 /***************************************************************************/
111 * @name Access to attributes
116 * Set the starting date
117 * @param $ts (timestamp)
119 public function setStart($ts) { $this->tsStart = intval($ts); }
122 * Set the room to show in the booking table
123 * @param $str (string) Name of the room
125 public function setRoom($str) { $this->strRoom = $str; }
128 * Get the starting date
131 public function getStart() { return intval($this->tsStart); }
134 * Get the name of the room to show in the booking table
137 public function getRoom() { return $this->strRoom; }
139 /***************************************************************************/
150 public function doShow() {
152 if(!$this->oCfg->userCanView()) {
153 echo sprintf("<p class='err'>%s</p>",
154 MOD_ROOM_RESERVATION_ERROR_ACCESS_DENIED);
159 if($this->oRm->getRooms() == array()) {
160 echo sprintf("<p>%s</p>\n", _c("room-reservation:No rooms have been ".
166 Title(_c("room-reservation:Book rooms"));
168 // Form for room selection
169 /** @todo checkbox for recurring booking */
170 echo sprintf("<form name='room' method='get' action='%s'>",
171 $_SERVER["PHP_SELF"]);
172 echo sprintf("<input type='hidden' name='mod_roomReservationBookingTable".
173 "[date]' value='%d' />\n", $this->getStart());
174 echo _c("room-reservation:Room:") . sprintf(" <select onchange=".
175 "'document.forms[\"room\"].submit()' width='250' ".
176 "name='mod_roomReservationBookingTable[room]'>\n", $this->getStart());
177 $aor = $this->oRm->getRooms();
178 foreach($aor as $or) {
179 // note to myself: no qu() here, seems this is being done automagically
180 echo sprintf("<option value='%s'%s>%s</option>\n", $or->getName(),
181 ($or->getName() == $this->getRoom()) ? " selected='selected'" : "",
184 echo sprintf("</select> <%s value='%s' /></form><p />\n",
185 $GLOBALS["stdbtn"], _("Change"));
187 // Print line with next 5 or so weeks
188 $strSep = " | ";
189 $strLink = sprintf("<a href='%s?mod_roomReservationBookingTable[date]=%%d".
190 "&mod_roomReservationBookingTable[room]=%%s'>%%s</a>",
191 $_SERVER["PHP_SELF"]);
192 echo "<p>".sprintf($strLink, time(), qu($this->getRoom()),
193 _c("room-reservation:Current Week")) . $strSep;
194 echo sprintf($strLink, strtotime("1 week ago", $this->getStart()),
195 qu($this->getRoom()), _c("room-reservation:< Back")) . $strSep;
196 echo sprintf("<b>%s</b>", _sprintf_ord(_c("room-reservation:%d# week"),
197 date("W", $this->getStart()))) . $strSep;
198 for($i = 1; $i <= 5; $i++) {
199 $nNextWeek = strtotime("$i week", $this->getStart());
200 echo sprintf($strLink, $nNextWeek, qu($this->getRoom()), _sprintf_ord(
201 _c("room-reservation:%d# week"), date("W", $nNextWeek)));
204 echo sprintf($strLink, strtotime("1 week", $this->getStart()),
205 qu($this->getRoom()), _c("room-reservation:Next >"))."</p>\n";