Added tag REL_8.07.26 for changeset aeacd94bc827fecf3c72c2fea69560b0cf787c39
[iserv-mod-room-reservation.git] / includes / mod_roomReservationBookingPage.inc
1 <?php
2 /**
3 * @file mod_roomReservationBookingPage.inc
4 * Page that shows the booking table
5 * @author Roland Hieber (roland.hieber@wilhelm-gym.net)
6 * @date 24.02.2008
7 *
8 * Copyright © 2007 Roland Hieber
9 *
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:
16 *
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
19 *
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
26 * THE SOFTWARE.
27 */
28
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");
35
36 /**
37 * Page that shows the booking table
38 * @todo document, don't forget GET parameters
39 */
40 class mod_roomReservationBookingPage extends mod_roomReservationPage {
41
42 /** (mod_roomReservationConfig) Reference to the configuration object */
43 protected $oCfg;
44 /**
45 * (mod_roomReservationRoomsManager) Reference to the rooms manager object
46 */
47 protected $oRm;
48 /**
49 * (mod_roomReservationBookingsManager) Reference to the bookings manager
50 * object
51 */
52 protected $oBm;
53 /** (timestamp) Starting date of the booking table */
54 protected $tsStart;
55 /** (int) Name of the room to show in the booking table */
56 protected $strRoom;
57
58 /** (mod_roomReservationBookingTable) The booking table */
59 protected $oBt;
60
61 /***************************************************************************/
62 /**
63 * @name Constructor
64 * @{
65 * Constructor
66 * @param $oCfg (mod_roomReservationConfig) Reference to the configuration
67 * object
68 * @param $oRm (mod_roomReservationRoomsManager) Reference to the rooms
69 * manager object
70 * @param $oBm (mod_roomReservationBookingsManager) Reference to the
71 * bookings manager object
72 * @return mod_roomReservationBookingPage
73 */
74 public function __construct(mod_roomReservationConfig &$oCfg,
75 mod_roomReservationRoomsManager &$oRm,
76 mod_roomReservationBookingsManager &$oBm) {
77 $this->oCfg = $oCfg;
78 $this->oRm = $oRm;
79 $this->oBm = $oBm;
80
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");
85
86 parent::__construct($oCfg);
87 $this->setTitle(_c("Room Reservation Schedule"));
88 $this->setIcon("mod_room-reservation_index");
89 }
90
91 /***************************************************************************/
92 /**
93 * @}
94 * @name Initialization
95 * @{
96 */
97
98 /**
99 * Process the REQUEST variables and preset the some variables
100 * @return void
101 */
102 protected function processRequestVariables() {
103 // take all settings from the booking table
104 $this->setRoom($this->oBt->getRoom());
105 $this->setStart($this->oBt->getDate());
106 }
107
108 /***************************************************************************/
109 /**
110 * @}
111 * @name Access to attributes
112 * @{
113 */
114
115 /**
116 * Set the starting date
117 * @param $ts (timestamp)
118 */
119 public function setStart($ts) { $this->tsStart = intval($ts); }
120
121 /**
122 * Set the room to show in the booking table
123 * @param $str (string) Name of the room
124 */
125 public function setRoom($str) { $this->strRoom = $str; }
126
127 /**
128 * Get the starting date
129 * @return int
130 */
131 public function getStart() { return intval($this->tsStart); }
132
133 /**
134 * Get the name of the room to show in the booking table
135 * @return string
136 */
137 public function getRoom() { return $this->strRoom; }
138
139 /***************************************************************************/
140 /**
141 * @}
142 * @name Output
143 * @{
144 */
145
146 /**
147 * Show the page.
148 * @return void
149 */
150 public function doShow() {
151 // Protect access
152 if(!$this->oCfg->userCanView()) {
153 echo sprintf("<p class='err'>%s</p>",
154 MOD_ROOM_RESERVATION_ERROR_ACCESS_DENIED);
155 _PageBlue();
156 die();
157 }
158
159 Title(_c("room-reservation:Book rooms"));
160
161 // Form for room selection
162 /** @todo checkbox for recurring booking */
163 echo sprintf("<form name='room' method='get' action='%s'>",
164 $_SERVER["PHP_SELF"]);
165 echo sprintf("<input type='hidden' name='mod_roomReservationBookingTable".
166 "[date]' value='%d' />\n", $this->getStart());
167
168 // Show rooms only if it is whitelisted
169 try {
170 $aor = $this->oCfg->getWhitelistedRooms();
171 } catch(SQLException $e) {
172 trigger_error($e->getMessage());
173 }
174 if(count($aor) > 0) {
175 echo _c("room-reservation:Room:") . sprintf(" <select onchange=".
176 "'document.forms[\"room\"].submit()' width='250' ".
177 "name='mod_roomReservationBookingTable[room]'>\n", $this->getStart());
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'" : "",
182 $or->getName());
183 }
184 echo sprintf("</select>&nbsp;<%s value='%s' /></form><p />\n",
185 $GLOBALS["stdbtn"], _("Change"));
186 } else {
187 printf("<p>%s</p>\n", _c("room-reservation:No rooms have been ".
188 "configured yet."));
189 return;
190 }
191
192 // Print line with next 5 or so weeks
193 $strSep = "&nbsp;| ";
194 $strLink = sprintf("<a href='%s?mod_roomReservationBookingTable[date]=%%d".
195 "&mod_roomReservationBookingTable[room]=%%s'>%%s</a>",
196 $_SERVER["PHP_SELF"]);
197 echo "<p>".sprintf($strLink, time(), qu($this->getRoom()),
198 _c("room-reservation:Current Week")) . $strSep;
199 echo sprintf($strLink, strtotime("1 week ago", $this->getStart()),
200 qu($this->getRoom()), _c("room-reservation:&lt; Back")) . $strSep;
201 echo sprintf("<b>%s</b>", _sprintf_ord(_c("room-reservation:%d# week"),
202 date("W", $this->getStart()))) . $strSep;
203 for($i = 1; $i <= 5; $i++) {
204 $nNextWeek = strtotime("$i week", $this->getStart());
205 echo sprintf($strLink, $nNextWeek, qu($this->getRoom()), _sprintf_ord(
206 _c("room-reservation:%d# week"), date("W", $nNextWeek)));
207 echo $strSep;
208 }
209 echo sprintf($strLink, strtotime("1 week", $this->getStart()),
210 qu($this->getRoom()), _c("room-reservation:Next &gt;"))."</p>\n";
211
212 $this->oBt->show();
213 }
214 }
215 ?>
This page took 0.053219 seconds and 5 git commands to generate.