3 * @file mod_roomReservationBookingTable.inc
4 * A timetable-like representation of bookings
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("mod_room-reservation/mod_roomReservationConfig.inc");
30 require_once("mod_room-reservation/mod_roomReservationBookingsManager.inc");
31 require_once("mod_room-reservation/mod_roomReservationRoomsManager.inc");
33 /*****************************************************************************/
35 * @page bookingtable_actions Actions of a mod_roomReservationBookingTable
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
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);
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);
57 /*****************************************************************************/
59 * @page bookingtable_printbooking_flags Flags for
60 * mod_roomReservationBookingTable::printBooking
62 * The following constants describe the flags for the second parameter of
63 * mod_roomReservationBookingTable::printBooking().
66 * This booking is new. New bookings are printed with a different background
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);
74 /*****************************************************************************/
76 * A timetable-like representation of bookings
79 class mod_roomReservationBookingsTable /* extends mclWidget */ {
81 /** (mod_roomReservationConfig) Reference to the configuration object */
84 * (mod_roomReservationRoomsManager) Reference to the rooms manager object
88 * (mod_roomReservationBookingsManager) Reference to the bookings manager
93 * (constant) The action to be performed.
94 * See @ref bookingtable_actions for a list of possible values.
98 * (timestamp) The date of the requested booking or the date to show in the
103 * (string) The name of the room of the requested booking or the room to be
104 * shown in the booking table
107 /** (int) The starting timeslice of the requested booking */
109 /** (int) The ending timeslice of the requested booking */
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();
124 /***************************************************************************/
129 * @param $oCfg (reference to mod_roomReservationConfig) Reference to the
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
137 public function __construct(mod_roomReservationConfig &$oCfg,
138 mod_roomReservationRoomsManager &$oRm,
139 mod_roomReservationBookingsManager &$oBm) {
145 $this->processRequestVariables();
146 } catch(Exception $e) {
147 $this->asErrors[] = $e->getMessage();
152 /***************************************************************************/
155 * @name Initialization
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
165 protected function processRequestVariables() {
168 $aoRooms = $this->oCfg->getWhitelistedRooms();
169 if(count($aoRooms) < 1) {
172 $this->setRoom($aoRooms[0]->getName());
174 // if weekends are not shown, show the next week already on saturday
175 if(!$this->oCfg->isShowWeekend() and date("w") == 6) {
176 $this->setDate(strtotime("monday"));
178 $this->setDate(time());
180 $this->setAction(MOD_ROOM_RESERVATION_BT_ACTION_SHOW);
181 $this->nPostInterval = 0;
183 // handle GET parameters
184 if(isset($_GET["mod_roomReservationBookingTable"])) {
185 $ga = isset($_GET["mod_roomReservationBookingTable"]["action"]) ?
186 $_GET["mod_roomReservationBookingTable"]["action"] : "";
187 $this->setAction(($ga == "book") ?
188 MOD_ROOM_RESERVATION_BT_ACTION_BOOK : (($ga == "edit") ?
189 MOD_ROOM_RESERVATION_BT_ACTION_EDIT : (($ga == "delete") ?
190 MOD_ROOM_RESERVATION_BT_ACTION_DELETE : (($ga == "submit") ?
191 MOD_ROOM_RESERVATION_BT_ACTION_SUBMIT : (($ga == "submitdelete") ?
192 MOD_ROOM_RESERVATION_BT_ACTION_SUBMITDELETE :
193 MOD_ROOM_RESERVATION_BT_ACTION_SHOW)))));
194 $this->setDate(isset($_GET["mod_roomReservationBookingTable"]["date"]) ?
195 intval($_GET["mod_roomReservationBookingTable"]["date"]) : time());
196 if(isset($_GET["mod_roomReservationBookingTable"]["room"])) {
197 $this->setRoom($_GET["mod_roomReservationBookingTable"]["room"]);
200 isset($_GET["mod_roomReservationBookingTable"]["tsfirst"]) ?
201 intval($_GET["mod_roomReservationBookingTable"]["tsfirst"]) : 0);
202 $this->setTsLast($this->getTsFirst());
204 // if deletion form is requested, set the right date, room etc.
205 if($this->getAction() == MOD_ROOM_RESERVATION_BT_ACTION_DELETE) {
206 if(isset($_GET["mod_roomReservationBookingTable"]["uid"]) &&
207 $_GET["mod_roomReservationBookingTable"]["uid"] >= 0) {
208 $this->setUid(intval(
209 $_GET["mod_roomReservationBookingTable"]["uid"]));
211 trigger_error("The UID is invalid.", E_USER_ERROR);
213 $ob = mod_roomReservationBookingsManager::getBookingByUid(
215 $this->setRoom($ob->getRoom());
216 if($ob->getInterval() > 0) {
217 // don't show the first date when the booking was created, but the
218 // date of the page where the user clicked the delete button
220 isset($_GET["mod_roomReservationBookingTable"]["date"]) ?
221 intval($_GET["mod_roomReservationBookingTable"]["date"]) : time());
223 $this->setDate($ob->getDate());
225 $this->setTsFirst($ob->getTsFirst());
229 if(isset($_POST["mod_roomReservationBookingTable"])) {
230 if(isset($_POST["mod_roomReservationBookingTable"]["submitbooking"])) {
231 // submission of the booking form
232 // let POST variables overwrite the variables
234 isset($_POST["mod_roomReservationBookingTable"]["date"]) ?
235 intval($_POST["mod_roomReservationBookingTable"]["date"]) : time());
237 isset($_POST["mod_roomReservationBookingTable"]["room"]) ?
238 $_POST["mod_roomReservationBookingTable"]["room"] : "");
240 isset($_POST["mod_roomReservationBookingTable"]["tsfirst"]) ?
241 intval($_POST["mod_roomReservationBookingTable"]["tsfirst"]) : 0);
243 isset($_POST["mod_roomReservationBookingTable"]["tslast"]) ?
244 intval($_POST["mod_roomReservationBookingTable"]["tslast"]) :
245 $this->getTsFirst());
247 isset($_POST["mod_roomReservationBookingTable"]["reason"]) ?
248 $_POST["mod_roomReservationBookingTable"]["reason"] : "");
249 $this->nPostInterval =
250 isset($_POST["mod_roomReservationBookingTable"]["interval"]) ?
251 intval($_POST["mod_roomReservationBookingTable"]["interval"]) : 0;
252 $this->strPostAccount =
253 isset($_POST["mod_roomReservationBookingTable"]["account"]) ?
254 $_POST["mod_roomReservationBookingTable"]["account"] : "";
257 if(isset($_POST["mod_roomReservationBookingTable"]["submitdelete"])) {
258 // submission of the deletion form
259 if(isset($_POST["mod_roomReservationBookingTable"]["uid"]) &&
260 $_POST["mod_roomReservationBookingTable"]["uid"] >= 0) {
262 intval($_POST["mod_roomReservationBookingTable"]["uid"]));
264 trigger_error("The UID is invalid.", E_USER_ERROR);
266 // set the right date, room etc.
267 $ob = mod_roomReservationBookingsManager::getBookingByUid(
269 $this->setRoom($ob->getRoom());
270 $this->setDate($ob->getDate());
271 $this->setTsFirst($ob->getTsFirst());
272 $this->setSubmitButtonValue(isset(
273 $_POST["mod_roomReservationBookingTable"]["submitdelete"]) ?
274 $_POST["mod_roomReservationBookingTable"]["submitdelete"] : "");
279 /***************************************************************************/
282 * @name Access to attributes
287 * Set the action that should be done
288 * @param $c (constant) See @ref bookingtable_actions for possible values
290 protected function setAction($c) { $this->cAction = intval($c); }
293 * Set the starting timeslice of the requested booking
296 protected function setTsFirst($n) { $this->nTsFirst = intval($n); }
299 * Set the ending timeslice of the requested booking
302 protected function setTsLast($n) { $this->nTsLast = intval($n); }
305 * Set the date of the requested booking or the date to be shown in the
307 * @param $ts (timestamp)
309 public function setDate($ts) { $this->tsDate = intval($ts); }
312 * Set the room of the requested booking or the room to be shown in the
313 * booking table. Throws an Exception if the room is not allowed for booking.
314 * @param $str (string)
317 protected function setRoom($str) {
318 // only allow whitelisted rooms
319 if($this->oCfg->isRoomWhitelisted($str)) {
320 $this->strRoom = $str;
322 throw new Exception(_c("room-reservation:This room is not available ".
328 * Set the reason of the requested booking
329 * @param $str (string)
331 protected function setReason($str) { $this->strReason = $str; }
334 * Set the UID of the booking to be deleted / edited
337 protected function setUid($n) { $this->nUid = intval($n); }
340 * Set the value of the submit button that the user clicked
341 * @param $str (string)
343 protected function setSubmitButtonValue($str) {
344 $this->strSubmitButtonValue = $str;
348 * Get the name of the room of the requested booking or the room to show in
352 public function getRoom() { return $this->strRoom; }
355 * Get the action that should be done
356 * @return constant See @ref bookingtable_actions for possible values
358 public function getAction() { return $this->cAction; }
361 * Get the the starting timeslice of the requested booking
364 public function getTsFirst() { return $this->nTsFirst; }
367 * Get the the ending timeslice of the requested booking
370 public function getTsLast() { return $this->nTsLast; }
373 * Get the the date of the requested booking or the date to be shown in the
377 public function getDate() { return $this->tsDate; }
380 * Get the the reason of the requested booking
383 public function getReason() { return $this->strReason; }
386 * Get the UID of the booking to be deleted / edited
389 public function getUid() { return $this->nUid; }
392 * Get the value of the submit button that the user clicked
395 public function getSubmitButtonValue() {
396 return $this->strSubmitButtonValue;
399 /***************************************************************************/
407 * Add the CSS rules needed for this page
410 protected function addCSS() {
412 #mod_roomReservationBookingTable .msg { font-weight:800; }
413 #mod_roomReservationBookingTable td {
414 vertical-align: middle;
416 border: 1px solid white;
419 #mod_roomReservationBookingTable td.booking { background-color:#5276AB; }
420 #mod_roomReservationBookingTable td.new { background-color:#008015; }
421 #mod_roomReservationBookingTable td.recurring { background-color:#1C4174; }
422 #mod_roomReservationBookingTable td.recurringnew { background-color:#006010; }
423 #mod_roomReservationBookingTable td.heading { font-weight:bold; height:3em; }
424 #mod_roomReservationBookingTable td.lesson { width:9%; }
425 #mod_roomReservationBookingTable td.today { font-style:italic; }
426 #mod_roomReservationBookingTable {
427 border:1px solid white;
428 border-collapse:collapse;
429 text-align:center; width:100%;
432 if($this->oCfg->isShowWeekend()) {
433 $strCss .= "#mod_roomReservationBookingTable td.cell { width:13%; }";
435 $strCss .= "#mod_roomReservationBookingTable td.cell { width:18.2%; }";
443 * @throws AccessException
444 * @todo increase the height of the cells a little
446 public function show() {
448 if(!$this->oCfg->userCanView()) {
449 throw new AccessException(MOD_ROOM_RESERVATION_ERROR_ACCESS_DENIED);
453 // print error messages and return if there are any
454 if(count($this->asErrors) > 0) {
455 printf("<p class='err'>%s</p>", join("<br />\n", $this->asErrors));
459 // Print the header with the days
460 $ncTs = sizeof($this->oCfg->getTimeslices());
461 $nDays = ($this->oCfg->isShowWeekend()) ? 7 : 5;
463 echo "<table id='mod_roomReservationBookingTable'><tr>";
465 // Print header with day names
466 echo "<td class='heading' />";
467 for($ts = rrGetMonday($this->getDate()), $i=0; $i < $nDays;
468 $ts = strtotime("1 day", $ts), $i++) {
469 // Use a different color for the current day
470 $strClass = "heading";
471 $strTitle = strftime("%A<br />%x", $ts);
472 if(date("Ymd") === date("Ymd", $ts)) {
473 $strClass .= " today";
474 $strTitle .= " "._c("room-reservation:(today)");
476 echo sprintf("<td class='%s'>%s</td>", $strClass, $strTitle);
481 // To take care of bookings with more than one timeslice, we use an array
482 // that tells us which cell in the current column is the next to fill
483 $anNextRow = array_fill(0, $nDays, 0);
484 // Iterate over the timeslices
485 for($nTs = 0; $nTs < $ncTs; $nTs++) {
486 $strLessons = $this->oCfg->isShowLessons() ?_sprintf_ord(
487 _c("room-reservation:%s# lesson"), $nTs + 1) . "<br />" : "";
488 $oTs = $this->oCfg->getTimeslice($nTs);
489 $strTs = sprintf("%s - %s", gmstrftime(_("%#I:%M %p"), $oTs->getBegin()),
490 gmstrftime(_("%#I:%M %p"), $oTs->getEnd()));
491 // First column: Lesson
492 echo sprintf("<tr><td class='lesson'>%s</td>", $strLessons . $strTs);
494 // Iterate over the days
495 for($ts = rrGetMonday($this->getDate()), $i = 0; $i <= $nDays;
496 $ts = strtotime("1 day", $ts), $i++) {
497 // Don't print if there is a spanning booking on the current cell
498 if(isset($anNextRow[$i]) && $anNextRow[$i] == $nTs) {
499 if(($ob = $this->oBm->getBookingByTimeslice($this->getRoom(), $ts,
501 // a booking exists here
502 // print booking or deletion form or handle the deletion form
504 // deletion form is requested:
505 if(($this->getAction() == MOD_ROOM_RESERVATION_BT_ACTION_DELETE) &&
506 (date("Ymd", $this->getDate()) == date("Ymd", $ts)) &&
507 ($this->getTsFirst() == $nTs) &&
508 ($this->getRoom() == $this->getRoom())) {
509 $anNextRow[$i] += $this->printBooking($nTs, $ts, $ob,
510 MOD_ROOM_RESERVATION_BTPB_DELETE);
512 // deletion form is submitted:
513 } else if(($this->getAction() ==
514 MOD_ROOM_RESERVATION_BT_ACTION_SUBMITDELETE) &&
515 (date("Ymd", $this->getDate()) == date("Ymd", $ts)) &&
516 ($this->getTsFirst() == $nTs) &&
517 ($this->getRoom() == $this->getRoom())) {
518 if($this->getSubmitButtonValue() == _("Delete")) {
519 // the user clicked the "delete" button
522 $bSuccess = $this->oBm->delete($this->getUid());
523 } catch(Exception $e) {
524 $anNextRow[$i] += $this->printBooking($nTs, $ts, $ob, 0,
525 array($e->getMessage()));
527 // print booking link and a success message
529 $anNextRow[$i] += $this->printBookingLink($nTs, $ts,
530 array(_c("room-reservation:The booking was deleted.")));
533 // the user cancelled the request
534 $anNextRow[$i] += $this->printBooking($nTs, $ts, $ob);
537 // Something else -- print booking
539 $anNextRow[$i] += $this->printBooking($nTs, $ts, $ob);
542 // no booking is here
543 // print booking link, booking form or handle booking form
546 // booking form is requested:
547 if(($this->getAction() == MOD_ROOM_RESERVATION_BT_ACTION_BOOK) &&
548 (date("Ymd", $this->getDate()) == date("Ymd", $ts)) &&
549 ($this->getTsFirst() == $nTs) &&
550 ($this->getRoom() == $this->getRoom())) {
551 $anNextRow[$i] += $this->printBookingForm($nTs, $ts, $asErrors);
553 // booking form is submitted:
554 } else if(($this->getAction() ==
555 MOD_ROOM_RESERVATION_BT_ACTION_SUBMIT) &&
556 // only handle the request if the form was in the current cell
557 (date("Ymd", $this->getDate()) == date("Ymd", $ts)) &&
558 ($this->getTsFirst() == $nTs) &&
559 ($this->getRoom() == $this->getRoom())) {
561 // try writing the booking to the database
563 $oNewBooking = new mod_roomReservationBooking($this->getRoom(),
564 $this->getDate(), $this->getTsFirst(), $this->getTsLast(),
565 (trim($this->strPostAccount) == "") ? $_SESSION["act"] :
566 $this->strPostAccount, $this->getReason(),
567 $this->nPostInterval);
569 $nNewUid = $this->oBm->write($oNewBooking);
570 } catch(Exception $s) {
571 // print the booking form again with the user's input
572 // @todo check for overlapping bookings and print them
573 $asErrors[] = $s->getMessage();
574 $anNextRow[$i] += $this->printBookingForm($nTs, $ts,
578 // print new booking and increment the "next row" variable by
580 $oNewBooking->setUid($nNewUid);
581 $anNextRow[$i] += $this->printBooking($nTs, $ts, $oNewBooking,
582 MOD_ROOM_RESERVATION_BTPB_NEW);
585 // Something else -- print booking link:
587 $anNextRow[$i] += $this->printBookingLink($nTs, $ts);
594 echo "</table><br />";
598 * Print a single booking in the booking table.
599 * @param $nTs (int) current timeslice
600 * @param $ts (timestamp) current date
601 * @param $ob (mod_roomReservationBooking) the booking
602 * @param $cFlags (constant) Flags,
603 * See @ref bookingtable_printbooking_flags for more information.
604 * @param $asMsgs (array of strings) Additional messages to be printed
605 * inside the cell, one array element per message
606 * @return (int) the span of the booking
608 protected function printBooking($nTs, $ts, mod_roomReservationBooking $ob,
609 $cFlags = 0, $asMsgs = array()) {
614 if(count($asMsgs) > 0) {
615 $strBefore .= "<p class='msg'>".nl2br(q(join("\n", $asMsgs)))."</p>\n";
618 // calculate the timespan of the current booking
619 $nSpan = $ob->getTsLast() - $ob->getTsFirst() + 1;
621 if(($cFlags & MOD_ROOM_RESERVATION_BTPB_DELETE) ==
622 MOD_ROOM_RESERVATION_BTPB_DELETE) {
625 if(!($this->oBm->userIsOwner($ob->getUid()) or
626 $this->oCfg->userIsAdmin())) {
627 $strBefore .= "<p class='msg'>" .
628 MOD_ROOM_RESERVATION_ERROR_ACCESS_DENIED . "</p>\n";
632 $strWarning = sprintf("<div>%s%s</div>", icon("dlg-warn",
633 array("bg" =>"gb")), _c("room-reservation:<b>Attention:</b> This ".
634 "booking is a recurring booking. If you delete it, the period will ".
635 "be deallocated for <b>every week</b>, not just this single week!"));
636 $strAfter .= sprintf("<p name='form' id='form' style='".
637 "text-align:center'><form action='%s?".
638 "mod_roomReservationBookingTable[action]=submitdelete#form' ".
639 "method='post'>%s%s<br /><%s name='mod_roomReservationBookingTable".
640 "[submitdelete]' value='%s' /> <%s name='".
641 "mod_roomReservationBookingTable[submitdelete]' value='%s' />".
642 "<input type='hidden' name='mod_roomReservationBookingTable[uid]' ".
643 "value='%d' /></form></p>", $_SERVER["PHP_SELF"],
644 _c("room-reservation:Delete this booking?"),
645 ($ob->getInterval() > 0 ? $strWarning : ""), $GLOBALS["smlbtn"],
646 _("Delete"), $GLOBALS["smlbtn"], _("Cancel"), $ob->getUid(),
647 $this->getRoom(), $this->getDate());
650 // delete and edit links, show only if user is allowed to
651 if($this->oBm->userIsOwner($ob->getUid()) ||
652 $this->oCfg->userIsAdmin()) {
653 /** @todo edit form */
654 $strAfter .= sprintf("<br />(<!-- <a href='%s?".
655 "mod_roomReservationBookingTable[action]=edit&".
656 "mod_roomReservationBookingTable[uid]=%d&".
657 "mod_roomReservationBookingTable[date]=%d#form' title='%s'>%s</a>, -->".
658 "<a href='%s?mod_roomReservationBookingTable[action]=delete&".
659 "mod_roomReservationBookingTable[uid]=%d&".
660 "mod_roomReservationBookingTable[date]=%d#form' title='%s'>%s</a>)",
661 $_SERVER["PHP_SELF"], $ob->getUid(), $ts,
662 _c("room-reservation:Edit this booking"),
663 _c("room-reservation:edit"), $_SERVER["PHP_SELF"], $ob->getUid(),
664 $ts, _c("room-reservation:Delete this booking"),
665 _c("room-reservation:delete"));
669 // test if booking is new and should be highlighted
670 $strClass = "cell booking".($ob->getInterval() > 0 ? " recurring" : "");
671 if(($cFlags & MOD_ROOM_RESERVATION_BTPB_NEW) ==
672 MOD_ROOM_RESERVATION_BTPB_NEW) {
675 // Use a different style for the current day
676 $strClass .= (date("Ymd", $ob->getDate()) == date("Ymd") ? " today" : "");
677 /** @todo: add ?subject=... to mailto link */
678 echo sprintf("<td rowspan='%d' class='%s'>%s<a %s>%s</a><br />%s%s</td>\n",
679 $nSpan, $strClass, $strBefore, mailto($ob->getAct()),
680 q(getRealUserName($ob->getAct())), q($ob->getReason()), $strAfter);
686 * Print the booking form.
687 * @param $nTs (int) current timeslice
688 * @param $ts (timestamp) current date
689 * @param $asErrors (array of strings) Additional error message to be printed
690 * inside the cell, one array element per message
691 * @return (int) the span of the booking (i.e., 1)
693 protected function printBookingForm($nTs, $ts, $asErrors = array()) {
695 if(!($this->oCfg->userCanBook() or $this->oCfg->userIsAdmin())) {
696 printf("<td class='err'>%s</td>\n",
697 MOD_ROOM_RESERVATION_ERROR_ACCESS_DENIED);
701 $strErrors = "<p class='err'>".nl2br(q(join("\n", $asErrors)))."</p>";
703 // form to allow fixed bookings for admins
705 if($this->oCfg->userIsAdmin()) {
706 $sWeeklyForm = sprintf("<label for='interval'>%s</label> %s<br />".
707 "<label for='account'>%s</label> <%s name='".
708 "mod_roomReservationBookingTable[account]' id='account' value='%s' ".
709 "size='15' /><br />", _c("room-reservation:Repetition:"),
710 select("mod_roomReservationBookingTable[interval]",
711 $this->nPostInterval, array(0 => _c("Select:None"), 1 =>
712 _c("room-reservation:every week")), array("add" => "id='interval'")),
713 _c("room-reservation:Account, if not yourself:"), $GLOBALS["stdedt"],
714 $this->strPostAccount);
717 echo sprintf("<td name='form' id='form' style='text-align:left'>%s".
718 "<form action='%s?mod_roomReservationBookingTable[action]=".
719 "submit#form' method='post'><label for='tslast'>%s</label> %s".
720 "<br /><label for='reason'>%s</label> <%s id='reason' size='15' ".
721 "value='%s' name='mod_roomReservationBookingTable[reason]' /><br />%s".
722 "<%s name='mod_roomReservationBookingTable[submitbooking]' value='%s' />".
723 "<input type='hidden' name='mod_roomReservationBookingTable[date]' ".
724 "value='%s' /><input type='hidden' name='".
725 "mod_roomReservationBookingTable[room]' value='%s' /><input ".
726 "type='hidden' name='mod_roomReservationBookingTable[tsfirst]' ".
727 "value='%s' /></form></td>\n", (count($asErrors) > 0) ? $strErrors : "",
728 $_SERVER["PHP_SELF"], _c("room-reservation:until:"),
729 select("mod_roomReservationBookingTable[tslast]", $this->getTsLast(),
730 $this->oCfg->getTimesliceEndings(true)), _c("room-reservation:Reason:"),
731 $GLOBALS["stdedt"], $this->getReason(), $sWeeklyForm, $GLOBALS["smlbtn"],
732 _c("room-reservation:Book"), $this->getDate(), $this->getRoom(),
733 $this->getTsFirst());
738 * Print the booking link
739 * @param $nTs (int) current timeslice
740 * @param $ts (timestamp) current date
741 * @param $asMsgs (array of strings) Additional messages to be printed
742 * inside the cell, one array element per message
743 * @return (int) the span of the booking (i.e., 1)
745 protected function printBookingLink($nTs, $ts, $asMsgs = array()) {
748 if(!($this->oCfg->userCanBook() or $this->oCfg->userIsAdmin())) {
755 if(count($asMsgs) > 0) {
756 $strBefore .= "<p class='msg'>".join("<br />", $asMsgs)."</p>\n";
759 // print link to booking if the timeslice is later than now
760 $oTs = $this->oCfg->getTimeslice($nTs);
761 // note: only the timeslices are in GMT!
762 $tsCur = strtotime(date("Y-m-d ", $ts) . gmdate(" G:i",
764 if($tsCur > time()) {
765 $strURL = $_SERVER["PHP_SELF"] .
766 sprintf("?mod_roomReservationBookingTable[action]=book&".
767 "mod_roomReservationBookingTable[date]=%d&".
768 "mod_roomReservationBookingTable[room]=%s&".
769 "mod_roomReservationBookingTable[tsfirst]=%d#form", $ts,
770 qu($this->getRoom()), $nTs);
771 echo sprintf("<td class='cell'>%s<a href='%s' title='%s'>%s</a></td>\n",
772 $strBefore, $strURL, _c("room-reservation:Book this room from here"),
773 _c("room-reservation:(Book from here)"));
775 // only print the messages
776 echo sprintf("<td name='form' id='form' class='cell'>%s</td>\n",