706d7574e2539397e22d9f27d1531ce64fff61c9
[iserv-mod-room-reservation.git] / includes / mod_roomReservationBookingTable.inc
1 <?php
2 /**
3 * @file mod_roomReservationBookingTable.inc
4 * A timetable-like representation of bookings
5 * @author Roland Hieber (roland.hieber@wilhelm-gym.net)
6 * @date 03.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("mod_room-reservation/mod_roomReservationConfig.inc");
30 require_once("mod_room-reservation/mod_roomReservationBookingsManager.inc");
31 require_once("mod_room-reservation/mod_roomReservationRoomsManager.inc");
32
33 /*****************************************************************************/
34 /**
35 * @page bookingtable_actions Actions of a mod_roomReservationBookingTable
36 * instance
37 * @{
38 * The following constants describe the actions that a
39 * mod_roomReservationBookingTable instance can handle. They are used in
40 * processRequestVariables() to determine the action that should be done when
41 * the table is shown.
42 */
43 /** Show the booking table (default action) */
44 define("MOD_ROOM_RESERVATION_BT_ACTION_SHOW", 0);
45 /** Show the form for a new booking */
46 define("MOD_ROOM_RESERVATION_BT_ACTION_BOOK", 1);
47 /** The booking form has been submitted, process the booking */
48 define("MOD_ROOM_RESERVATION_BT_ACTION_SUBMIT", 2);
49 /** Edit a booking */
50 define("MOD_ROOM_RESERVATION_BT_ACTION_EDIT", 3);
51 /** Show the deletion form */
52 define("MOD_ROOM_RESERVATION_BT_ACTION_DELETE", 4);
53 /** The deletion form has been submitted, delete the booking */
54 define("MOD_ROOM_RESERVATION_BT_ACTION_SUBMITDELETE", 5);
55 /** @} */
56
57 /*****************************************************************************/
58 /**
59 * @page bookingtable_printbooking_flags Flags for
60 * mod_roomReservationBookingTable::printBooking
61 * @{
62 * The following constants describe the flags for the second parameter of
63 * mod_roomReservationBookingTable::printBooking().
64 */
65 /**
66 * This booking is new. New bookings are printed with a different background
67 * color.
68 */
69 define("MOD_ROOM_RESERVATION_BTPB_NEW", 2);
70 /** This booking is requested for deletion. Show delete button. */
71 define("MOD_ROOM_RESERVATION_BTPB_DELETE", 4);
72 /** @} */
73
74 /*****************************************************************************/
75 /**
76 * A timetable-like representation of bookings
77 * @todo document
78 */
79 class mod_roomReservationBookingsTable /* extends mclWidget */ {
80
81 /** (mod_roomReservationConfig) Reference to the configuration object */
82 protected $oCfg;
83 /**
84 * (mod_roomReservationRoomsManager) Reference to the rooms manager object
85 */
86 protected $oRm;
87 /**
88 * (mod_roomReservationBookingsManager) Reference to the bookings manager
89 * object
90 */
91 protected $oBm;
92 /**
93 * (constant) The action to be performed.
94 * See @ref bookingtable_actions for a list of possible values.
95 */
96 protected $cAction;
97 /**
98 * (timestamp) The date of the requested booking or the date to show in the
99 * booking table
100 */
101 protected $tsDate;
102 /**
103 * (string) The name of the room of the requested booking or the room to be
104 * shown in the booking table
105 */
106 protected $strRoom;
107 /** (int) The starting timeslice of the requested booking */
108 protected $nTsFirst;
109 /** (int) The ending timeslice of the requested booking */
110 protected $nTsLast;
111 /** (string) The reason of the requested booking */
112 protected $strReason;
113 /** (int) UID of the booking to be deleted / edited */
114 protected $nDeleteUid;
115 /** (string) Value of the button that the user clicked */
116 protected $strSubmitButtonValue;
117 /** (string) Account of the owner, POST data */
118 protected $strPostAccount;
119 /** (int) recurrence interval, POST data */
120 protected $nPostInterval;
121 /** (string) Array of error messages */
122 protected $asErrors = array();
123
124 /***************************************************************************/
125 /**
126 * @name Constructor
127 * @{
128 * Constructor
129 * @param $oCfg (reference to mod_roomReservationConfig) Reference to the
130 * configuration
131 * @param $oRm (reference to mod_roomReservationRoomsManager) Reference to
132 * the rooms manager object
133 * @param $oBm (reference to mod_roomReservationBookingsManager) Reference
134 * to the bookings manager object
135 * @return mod_roomReservationBookingTable
136 */
137 public function __construct(mod_roomReservationConfig &$oCfg,
138 mod_roomReservationRoomsManager &$oRm,
139 mod_roomReservationBookingsManager &$oBm) {
140 $this->oCfg = $oCfg;
141 $this->oRm = $oRm;
142 $this->oBm = $oBm;
143
144 try {
145 $this->processRequestVariables();
146 } catch(Exception $e) {
147 $this->asErrors[] = $e->getMessage();
148 }
149 $this->addCSS();
150 }
151
152 /***************************************************************************/
153 /**
154 * @}
155 * @name Initialization
156 * @{
157 */
158
159 /**
160 * Process the REQUEST variables and preset the some variables. Throws an
161 * exception if the room provided by the GET data is not allowed for booking
162 * @return void
163 * @throws Exception
164 */
165 protected function processRequestVariables() {
166
167 // default values
168 $aoRooms = $this->oCfg->getWhitelistedRooms();
169 if(count($aoRooms) < 1) {
170 $this->setRoom("");
171 } else {
172 $this->setRoom($aoRooms[0]->getName());
173 }
174 $this->setDate(time());
175 $this->setAction(MOD_ROOM_RESERVATION_BT_ACTION_SHOW);
176 $this->nPostInterval = 0;
177
178 // handle GET parameters
179 if(isset($_GET["mod_roomReservationBookingTable"])) {
180 $ga = isset($_GET["mod_roomReservationBookingTable"]["action"]) ?
181 $_GET["mod_roomReservationBookingTable"]["action"] : "";
182 $this->setAction(($ga == "book") ?
183 MOD_ROOM_RESERVATION_BT_ACTION_BOOK : (($ga == "edit") ?
184 MOD_ROOM_RESERVATION_BT_ACTION_EDIT : (($ga == "delete") ?
185 MOD_ROOM_RESERVATION_BT_ACTION_DELETE : (($ga == "submit") ?
186 MOD_ROOM_RESERVATION_BT_ACTION_SUBMIT : (($ga == "submitdelete") ?
187 MOD_ROOM_RESERVATION_BT_ACTION_SUBMITDELETE :
188 MOD_ROOM_RESERVATION_BT_ACTION_SHOW)))));
189 $this->setDate(isset($_GET["mod_roomReservationBookingTable"]["date"]) ?
190 intval($_GET["mod_roomReservationBookingTable"]["date"]) : time());
191 if(isset($_GET["mod_roomReservationBookingTable"]["room"])) {
192 $this->setRoom($_GET["mod_roomReservationBookingTable"]["room"]);
193 }
194 $this->setTsFirst(
195 isset($_GET["mod_roomReservationBookingTable"]["tsfirst"]) ?
196 intval($_GET["mod_roomReservationBookingTable"]["tsfirst"]) : 0);
197 $this->setTsLast($this->getTsFirst());
198
199 // if deletion form is requested, set the right date, room etc.
200 if($this->getAction() == MOD_ROOM_RESERVATION_BT_ACTION_DELETE) {
201 if(isset($_GET["mod_roomReservationBookingTable"]["uid"]) &&
202 $_GET["mod_roomReservationBookingTable"]["uid"] >= 0) {
203 $this->setUid(intval(
204 $_GET["mod_roomReservationBookingTable"]["uid"]));
205 } else {
206 trigger_error("The UID is invalid.", E_USER_ERROR);
207 }
208 $ob = mod_roomReservationBookingsManager::getBookingByUid(
209 $this->getUid());
210 $this->setRoom($ob->getRoom());
211 if($ob->getInterval() > 0) {
212 // don't show the first date when the booking was created, but the
213 // date of the page where the user clicked the delete button
214 $this->setDate(
215 isset($_GET["mod_roomReservationBookingTable"]["date"]) ?
216 intval($_GET["mod_roomReservationBookingTable"]["date"]) : time());
217 } else {
218 $this->setDate($ob->getDate());
219 }
220 $this->setTsFirst($ob->getTsFirst());
221 }
222 }
223
224 if(isset($_POST["mod_roomReservationBookingTable"])) {
225 if(isset($_POST["mod_roomReservationBookingTable"]["submitbooking"])) {
226 // submission of the booking form
227 // let POST variables overwrite the variables
228 $this->setDate(
229 isset($_POST["mod_roomReservationBookingTable"]["date"]) ?
230 intval($_POST["mod_roomReservationBookingTable"]["date"]) : time());
231 $this->setRoom(
232 isset($_POST["mod_roomReservationBookingTable"]["room"]) ?
233 $_POST["mod_roomReservationBookingTable"]["room"] : "");
234 $this->setTsFirst(
235 isset($_POST["mod_roomReservationBookingTable"]["tsfirst"]) ?
236 intval($_POST["mod_roomReservationBookingTable"]["tsfirst"]) : 0);
237 $this->setTsLast(
238 isset($_POST["mod_roomReservationBookingTable"]["tslast"]) ?
239 intval($_POST["mod_roomReservationBookingTable"]["tslast"]) :
240 $this->getTsFirst());
241 $this->setReason(
242 isset($_POST["mod_roomReservationBookingTable"]["reason"]) ?
243 $_POST["mod_roomReservationBookingTable"]["reason"] : "");
244 $this->nPostInterval =
245 isset($_POST["mod_roomReservationBookingTable"]["interval"]) ?
246 intval($_POST["mod_roomReservationBookingTable"]["interval"]) : 0;
247 $this->strPostAccount =
248 isset($_POST["mod_roomReservationBookingTable"]["account"]) ?
249 $_POST["mod_roomReservationBookingTable"]["account"] : "";
250 }
251
252 if(isset($_POST["mod_roomReservationBookingTable"]["submitdelete"])) {
253 // submission of the deletion form
254 if(isset($_POST["mod_roomReservationBookingTable"]["uid"]) &&
255 $_POST["mod_roomReservationBookingTable"]["uid"] >= 0) {
256 $this->setUid(
257 intval($_POST["mod_roomReservationBookingTable"]["uid"]));
258 } else {
259 trigger_error("The UID is invalid.", E_USER_ERROR);
260 }
261 // set the right date, room etc.
262 $ob = mod_roomReservationBookingsManager::getBookingByUid(
263 $this->getUid());
264 $this->setRoom($ob->getRoom());
265 $this->setDate($ob->getDate());
266 $this->setTsFirst($ob->getTsFirst());
267 $this->setSubmitButtonValue(isset(
268 $_POST["mod_roomReservationBookingTable"]["submitdelete"]) ?
269 $_POST["mod_roomReservationBookingTable"]["submitdelete"] : "");
270 }
271 }
272 }
273
274 /***************************************************************************/
275 /**
276 * @}
277 * @name Access to attributes
278 * @{
279 */
280
281 /**
282 * Set the action that should be done
283 * @param $c (constant) See @ref bookingtable_actions for possible values
284 */
285 protected function setAction($c) { $this->cAction = intval($c); }
286
287 /**
288 * Set the starting timeslice of the requested booking
289 * @param $n (int)
290 */
291 protected function setTsFirst($n) { $this->nTsFirst = intval($n); }
292
293 /**
294 * Set the ending timeslice of the requested booking
295 * @param $n (int)
296 */
297 protected function setTsLast($n) { $this->nTsLast = intval($n); }
298
299 /**
300 * Set the date of the requested booking or the date to be shown in the
301 * booking table
302 * @param $ts (timestamp)
303 */
304 public function setDate($ts) { $this->tsDate = intval($ts); }
305
306 /**
307 * Set the room of the requested booking or the room to be shown in the
308 * booking table. Throws an Exception if the room is not allowed for booking.
309 * @param $str (string)
310 * @throws Exception
311 */
312 protected function setRoom($str) {
313 // only allow whitelisted rooms
314 if($this->oCfg->isRoomWhitelisted($str)) {
315 $this->strRoom = $str;
316 } else {
317 throw new Exception(_c("room-reservation:This room is not available ".
318 "for booking."));
319 }
320 }
321
322 /**
323 * Set the reason of the requested booking
324 * @param $str (string)
325 */
326 protected function setReason($str) { $this->strReason = $str; }
327
328 /**
329 * Set the UID of the booking to be deleted / edited
330 * @param $n (int)
331 */
332 protected function setUid($n) { $this->nUid = intval($n); }
333
334 /**
335 * Set the value of the submit button that the user clicked
336 * @param $str (string)
337 */
338 protected function setSubmitButtonValue($str) {
339 $this->strSubmitButtonValue = $str;
340 }
341
342 /**
343 * Get the name of the room of the requested booking or the room to show in
344 * the booking table
345 * @return string
346 */
347 public function getRoom() { return $this->strRoom; }
348
349 /**
350 * Get the action that should be done
351 * @return constant See @ref bookingtable_actions for possible values
352 */
353 public function getAction() { return $this->cAction; }
354
355 /**
356 * Get the the starting timeslice of the requested booking
357 * @return int
358 */
359 public function getTsFirst() { return $this->nTsFirst; }
360
361 /**
362 * Get the the ending timeslice of the requested booking
363 * @return int
364 */
365 public function getTsLast() { return $this->nTsLast; }
366
367 /**
368 * Get the the date of the requested booking or the date to be shown in the
369 * booking table
370 * @return timestamp
371 */
372 public function getDate() { return $this->tsDate; }
373
374 /**
375 * Get the the reason of the requested booking
376 * @return string
377 */
378 public function getReason() { return $this->strReason; }
379
380 /**
381 * Get the UID of the booking to be deleted / edited
382 * @return int
383 */
384 public function getUid() { return $this->nUid; }
385
386 /**
387 * Get the value of the submit button that the user clicked
388 * @return string
389 */
390 public function getSubmitButtonValue() {
391 return $this->strSubmitButtonValue;
392 }
393
394 /***************************************************************************/
395 /**
396 * @}
397 * @name Output
398 * @{
399 */
400
401 /**
402 * Add the CSS rules needed for this page
403 * @return void
404 */
405 protected function addCSS() {
406 $strCss = <<<CSS
407 #mod_roomReservationBookingTable .msg { font-weight:800; }
408 #mod_roomReservationBookingTable td {
409 vertical-align:middle;
410 height:7em;
411 border:1px solid white; padding:0.4em;
412 }
413 #mod_roomReservationBookingTable td.booking { background-color:#5276AB; }
414 #mod_roomReservationBookingTable td.new { background-color:#008015; }
415 #mod_roomReservationBookingTable td.recurring { background-color:#1C4174; }
416 #mod_roomReservationBookingTable td.recurringnew { background-color:#006010; }
417 #mod_roomReservationBookingTable td.heading { font-weight:bold; height:3em; }
418 #mod_roomReservationBookingTable td.lesson { width:9%; }
419 #mod_roomReservationBookingTable td.today { font-style:italic; }
420 #mod_roomReservationBookingTable {
421 border:1px solid white;
422 border-collapse:collapse;
423 text-align:center; width:100%;
424 }
425 CSS;
426 if($this->oCfg->isShowWeekend()) {
427 $strCss .= "#mod_roomReservationBookingTable td.cell { width:13%; }";
428 } else {
429 $strCss .= "#mod_roomReservationBookingTable td.cell { width:18.2%; }";
430 }
431 rrAddCss($strCss);
432 }
433
434 /**
435 * Show the timetable
436 * @return void
437 * @throws AccessException
438 * @todo increase the height of the cells a little
439 */
440 public function show() {
441 // Protect access
442 if(!$this->oCfg->userCanView()) {
443 throw new AccessException(MOD_ROOM_RESERVATION_ERROR_ACCESS_DENIED);
444 return;
445 }
446
447 // print error messages and return if there are any
448 if(count($this->asErrors) > 0) {
449 printf("<p class='err'>%s</p>", join("<br />\n", $this->asErrors));
450 return;
451 }
452
453 // Print the header with the days
454 $ncTs = sizeof($this->oCfg->getTimeslices());
455 $nDays = ($this->oCfg->isShowWeekend()) ? 7 : 5;
456
457 echo "<table id='mod_roomReservationBookingTable'><tr>";
458
459 // Print header with day names
460 echo "<td class='heading' />";
461 for($ts = rrGetMonday($this->getDate()), $i=0; $i < $nDays;
462 $ts = strtotime("1 day", $ts), $i++) {
463 // Use a different color for the current day
464 $strClass = "heading";
465 $strTitle = strftime("%A<br />%x", $ts);
466 if(date("Ymd") === date("Ymd", $ts)) {
467 $strClass .= " today";
468 $strTitle .= " "._c("room-reservation:(today)");
469 }
470 echo sprintf("<td class='%s'>%s</td>", $strClass, $strTitle);
471 }
472 echo "</tr>\n";
473
474 // Print timetable
475 // To take care of bookings with more than one timeslice, we use an array
476 // that tells us which cell in the current column is the next to fill
477 $anNextRow = array_fill(0, $nDays, 0);
478 // Iterate over the timeslices
479 for($nTs = 0; $nTs < $ncTs; $nTs++) {
480 $strLessons = $this->oCfg->isShowLessons() ?_sprintf_ord(
481 _c("room-reservation:%s# lesson"), $nTs + 1) . "<br />" : "";
482 $oTs = $this->oCfg->getTimeslice($nTs);
483 $strTs = sprintf("%s - %s", gmstrftime(_("%#I:%M %p"), $oTs->getBegin()),
484 gmstrftime(_("%#I:%M %p"), $oTs->getEnd()));
485 // First column: Lesson
486 echo sprintf("<tr><td class='lesson'>%s</td>", $strLessons . $strTs);
487
488 // Iterate over the days
489 for($ts = rrGetMonday($this->getDate()), $i = 0; $i <= $nDays;
490 $ts = strtotime("1 day", $ts), $i++) {
491 // Don't print if there is a spanning booking on the current cell
492 if(isset($anNextRow[$i]) && $anNextRow[$i] == $nTs) {
493 if(($ob = $this->oBm->getBookingByTimeslice($this->getRoom(), $ts,
494 $nTs)) !== null) {
495 // a booking exists here
496 // print booking or deletion form or handle the deletion form
497
498 // deletion form is requested:
499 if(($this->getAction() == MOD_ROOM_RESERVATION_BT_ACTION_DELETE) &&
500 (date("Ymd", $this->getDate()) == date("Ymd", $ts)) &&
501 ($this->getTsFirst() == $nTs) &&
502 ($this->getRoom() == $this->getRoom())) {
503 $anNextRow[$i] += $this->printBooking($nTs, $ts, $ob,
504 MOD_ROOM_RESERVATION_BTPB_DELETE);
505
506 // deletion form is submitted:
507 } else if(($this->getAction() ==
508 MOD_ROOM_RESERVATION_BT_ACTION_SUBMITDELETE) &&
509 (date("Ymd", $this->getDate()) == date("Ymd", $ts)) &&
510 ($this->getTsFirst() == $nTs) &&
511 ($this->getRoom() == $this->getRoom())) {
512 if($this->getSubmitButtonValue() == _("Delete")) {
513 // the user clicked the "delete" button
514 $bSuccess = false;
515 try {
516 $bSuccess = $this->oBm->delete($this->getUid());
517 } catch(Exception $e) {
518 $anNextRow[$i] += $this->printBooking($nTs, $ts, $ob, 0,
519 array($e->getMessage()));
520 }
521 // print booking link and a success message
522 if($bSuccess) {
523 $anNextRow[$i] += $this->printBookingLink($nTs, $ts,
524 array(_c("room-reservation:The booking was deleted.")));
525 }
526 } else {
527 // the user cancelled the request
528 $anNextRow[$i] += $this->printBooking($nTs, $ts, $ob);
529 }
530
531 // Something else -- print booking
532 } else {
533 $anNextRow[$i] += $this->printBooking($nTs, $ts, $ob);
534 }
535 } else {
536 // no booking is here
537 // print booking link, booking form or handle booking form
538 $asErrors = array();
539
540 // booking form is requested:
541 if(($this->getAction() == MOD_ROOM_RESERVATION_BT_ACTION_BOOK) &&
542 (date("Ymd", $this->getDate()) == date("Ymd", $ts)) &&
543 ($this->getTsFirst() == $nTs) &&
544 ($this->getRoom() == $this->getRoom())) {
545 $anNextRow[$i] += $this->printBookingForm($nTs, $ts, $asErrors);
546
547 // booking form is submitted:
548 } else if(($this->getAction() ==
549 MOD_ROOM_RESERVATION_BT_ACTION_SUBMIT) &&
550 // only handle the request if the form was in the current cell
551 (date("Ymd", $this->getDate()) == date("Ymd", $ts)) &&
552 ($this->getTsFirst() == $nTs) &&
553 ($this->getRoom() == $this->getRoom())) {
554
555 // try writing the booking to the database
556 $nNewUid = -1;
557 $oNewBooking = new mod_roomReservationBooking($this->getRoom(),
558 $this->getDate(), $this->getTsFirst(), $this->getTsLast(),
559 (trim($this->strPostAccount) == "") ? $_SESSION["act"] :
560 $this->strPostAccount, $this->getReason(),
561 $this->nPostInterval);
562 try {
563 $nNewUid = $this->oBm->write($oNewBooking);
564 } catch(Exception $s) {
565 // print the booking form again with the user's input
566 // @todo check for overlapping bookings and print them
567 $asErrors[] = $s->getMessage();
568 $anNextRow[$i] += $this->printBookingForm($nTs, $ts,
569 $asErrors);
570 }
571 if($nNewUid > 0) {
572 // print new booking and increment the "next row" variable by
573 // the current span
574 $oNewBooking->setUid($nNewUid);
575 $anNextRow[$i] += $this->printBooking($nTs, $ts, $oNewBooking,
576 MOD_ROOM_RESERVATION_BTPB_NEW);
577 }
578
579 // Something else -- print booking link:
580 } else {
581 $anNextRow[$i] += $this->printBookingLink($nTs, $ts);
582 }
583 }
584 }
585 }
586 echo "</tr>\n";
587 }
588 echo "</table><br />";
589 }
590
591 /**
592 * Print a single booking in the booking table.
593 * @param $nTs (int) current timeslice
594 * @param $ts (timestamp) current date
595 * @param $ob (mod_roomReservationBooking) the booking
596 * @param $cFlags (constant) Flags,
597 * See @ref bookingtable_printbooking_flags for more information.
598 * @param $asMsgs (array of strings) Additional messages to be printed
599 * inside the cell, one array element per message
600 * @return (int) the span of the booking
601 */
602 protected function printBooking($nTs, $ts, mod_roomReservationBooking $ob,
603 $cFlags = 0, $asMsgs = array()) {
604 $strAfter = "";
605 $strBefore = "";
606
607 // messages
608 if(count($asMsgs) > 0) {
609 $strBefore .= "<p class='msg'>".nl2br(q(join("\n", $asMsgs)))."</p>\n";
610 }
611
612 // calculate the timespan of the current booking
613 $nSpan = $ob->getTsLast() - $ob->getTsFirst() + 1;
614
615 if(($cFlags & MOD_ROOM_RESERVATION_BTPB_DELETE) ==
616 MOD_ROOM_RESERVATION_BTPB_DELETE) {
617
618 // Restrict access
619 if(!($this->oBm->userIsOwner($ob->getUid()) or
620 $this->oCfg->userIsAdmin())) {
621 $strBefore .= "<p class='msg'>" .
622 MOD_ROOM_RESERVATION_ERROR_ACCESS_DENIED . "</p>\n";
623 #return $nSpan;
624 } else {
625 // print delete form
626 $strWarning = sprintf("<div>%s%s</div>", icon("dlg-warn",
627 array("bg" =>"gb")), _c("room-reservation:<b>Attention:</b> This ".
628 "booking is a recurring booking. If you delete it, the period will ".
629 "be deallocated for <b>every week</b>, not just this single week!"));
630 $strAfter .= sprintf("<p name='form' id='form' style='".
631 "text-align:center'><form action='%s?".
632 "mod_roomReservationBookingTable[action]=submitdelete#form' ".
633 "method='post'>%s%s<br /><%s name='mod_roomReservationBookingTable".
634 "[submitdelete]' value='%s' /> <%s name='".
635 "mod_roomReservationBookingTable[submitdelete]' value='%s' />".
636 "<input type='hidden' name='mod_roomReservationBookingTable[uid]' ".
637 "value='%d' /></form></p>", $_SERVER["PHP_SELF"],
638 _c("room-reservation:Delete this booking?"),
639 ($ob->getInterval() > 0 ? $strWarning : ""), $GLOBALS["smlbtn"],
640 _("Delete"), $GLOBALS["smlbtn"], _("Cancel"), $ob->getUid(),
641 $this->getRoom(), $this->getDate());
642 }
643 } else {
644 // delete and edit links, show only if user is allowed to
645 if($this->oBm->userIsOwner($ob->getUid()) ||
646 $this->oCfg->userIsAdmin()) {
647 /** @todo edit form */
648 $strAfter .= sprintf("<br />(<!-- <a href='%s?".
649 "mod_roomReservationBookingTable[action]=edit&".
650 "mod_roomReservationBookingTable[uid]=%d&".
651 "mod_roomReservationBookingTable[date]=%d#form' title='%s'>%s</a>, -->".
652 "<a href='%s?mod_roomReservationBookingTable[action]=delete&".
653 "mod_roomReservationBookingTable[uid]=%d&".
654 "mod_roomReservationBookingTable[date]=%d#form' title='%s'>%s</a>)",
655 $_SERVER["PHP_SELF"], $ob->getUid(), $ts,
656 _c("room-reservation:Edit this booking"),
657 _c("room-reservation:edit"), $_SERVER["PHP_SELF"], $ob->getUid(),
658 $ts, _c("room-reservation:Delete this booking"),
659 _c("room-reservation:delete"));
660 }
661 }
662
663 // test if booking is new and should be highlighted
664 $strClass = "cell booking".($ob->getInterval() > 0 ? " recurring" : "");
665 if(($cFlags & MOD_ROOM_RESERVATION_BTPB_NEW) ==
666 MOD_ROOM_RESERVATION_BTPB_NEW) {
667 $strClass .= " new";
668 }
669 // Use a different style for the current day
670 $strClass .= (date("Ymd", $ob->getDate()) == date("Ymd") ? " today" : "");
671 /** @todo: add ?subject=... to mailto link */
672 echo sprintf("<td rowspan='%d' class='%s'>%s<a %s>%s</a><br />%s%s</td>\n",
673 $nSpan, $strClass, $strBefore, mailto($ob->getAct()),
674 q(getRealUserName($ob->getAct())), q($ob->getReason()), $strAfter);
675
676 return $nSpan;
677 }
678
679 /**
680 * Print the booking form.
681 * @param $nTs (int) current timeslice
682 * @param $ts (timestamp) current date
683 * @param $asErrors (array of strings) Additional error message to be printed
684 * inside the cell, one array element per message
685 * @return (int) the span of the booking (i.e., 1)
686 */
687 protected function printBookingForm($nTs, $ts, $asErrors = array()) {
688 // Restrict access
689 if(!($this->oCfg->userCanBook() or $this->oCfg->userIsAdmin())) {
690 printf("<td class='err'>%s</td>\n",
691 MOD_ROOM_RESERVATION_ERROR_ACCESS_DENIED);
692 return 1;
693 }
694
695 $strErrors = "<p class='err'>".nl2br(q(join("\n", $asErrors)))."</p>";
696
697 // form to allow fixed bookings for admins
698 $sWeeklyForm = "";
699 if($this->oCfg->userIsAdmin()) {
700 $sWeeklyForm = sprintf("<label for='interval'>%s</label> %s<br />".
701 "<label for='account'>%s</label> <%s name='".
702 "mod_roomReservationBookingTable[account]' id='account' value='%s' ".
703 "size='15' /><br />", _c("room-reservation:Repetition:"),
704 select("mod_roomReservationBookingTable[interval]",
705 $this->nPostInterval, array(0 => _c("Select:None"), 1 =>
706 _c("room-reservation:every week")), array("add" => "id='interval'")),
707 _c("room-reservation:Account, if not yourself:"), $GLOBALS["stdedt"],
708 $this->strPostAccount);
709 }
710
711 echo sprintf("<td name='form' id='form' style='text-align:left'>%s".
712 "<form action='%s?mod_roomReservationBookingTable[action]=".
713 "submit#form' method='post'><label for='tslast'>%s</label> %s".
714 "<br /><label for='reason'>%s</label> <%s id='reason' size='15' ".
715 "value='%s' name='mod_roomReservationBookingTable[reason]' /><br />%s".
716 "<%s name='mod_roomReservationBookingTable[submitbooking]' value='%s' />".
717 "<input type='hidden' name='mod_roomReservationBookingTable[date]' ".
718 "value='%s' /><input type='hidden' name='".
719 "mod_roomReservationBookingTable[room]' value='%s' /><input ".
720 "type='hidden' name='mod_roomReservationBookingTable[tsfirst]' ".
721 "value='%s' /></form></td>\n", (count($asErrors) > 0) ? $strErrors : "",
722 $_SERVER["PHP_SELF"], _c("room-reservation:until:"),
723 select("mod_roomReservationBookingTable[tslast]", $this->getTsLast(),
724 $this->oCfg->getTimesliceEndings(true)), _c("room-reservation:Reason:"),
725 $GLOBALS["stdedt"], $this->getReason(), $sWeeklyForm, $GLOBALS["smlbtn"],
726 _c("room-reservation:Book"), $this->getDate(), $this->getRoom(),
727 $this->getTsFirst());
728 return 1;
729 }
730
731 /**
732 * Print the booking link
733 * @param $nTs (int) current timeslice
734 * @param $ts (timestamp) current date
735 * @param $asMsgs (array of strings) Additional messages to be printed
736 * inside the cell, one array element per message
737 * @return (int) the span of the booking (i.e., 1)
738 */
739 protected function printBookingLink($nTs, $ts, $asMsgs = array()) {
740
741 // Restrict access
742 if(!($this->oCfg->userCanBook() or $this->oCfg->userIsAdmin())) {
743 echo "<td />\n";
744 return 1;
745 }
746
747 // messages
748 $strBefore = "";
749 if(count($asMsgs) > 0) {
750 $strBefore .= "<p class='msg'>".join("<br />", $asMsgs)."</p>\n";
751 }
752
753 // print link to booking if the timeslice is later than now
754 $oTs = $this->oCfg->getTimeslice($nTs);
755 $tsCur = strtotime(date("Y-m-d ", $ts) . date(" G:i",
756 $oTs->getEnd()));
757 if($tsCur > time()) {
758 $strURL = $_SERVER["PHP_SELF"] .
759 sprintf("?mod_roomReservationBookingTable[action]=book&".
760 "mod_roomReservationBookingTable[date]=%d&".
761 "mod_roomReservationBookingTable[room]=%s&".
762 "mod_roomReservationBookingTable[tsfirst]=%d#form", $ts,
763 qu($this->getRoom()), $nTs);
764 echo sprintf("<td class='cell'>%s<a href='%s' title='%s'>%s</a></td>\n",
765 $strBefore, $strURL, _c("room-reservation:Book this room from here"),
766 _c("room-reservation:(Book from here)"));
767 } else {
768 // only print the messages
769 echo sprintf("<td name='form' id='form' class='cell'>%s</td>\n",
770 $strBefore);
771 }
772 return 1;
773 }
774 /** @} */
775 }
776 ?>
This page took 0.078849 seconds and 3 git commands to generate.