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 $this->setDate(time());
175 $this->setAction(MOD_ROOM_RESERVATION_BT_ACTION_SHOW);
176 $this->nPostInterval = 0;
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"]);
195 isset($_GET["mod_roomReservationBookingTable"]["tsfirst"]) ?
196 intval($_GET["mod_roomReservationBookingTable"]["tsfirst"]) : 0);
197 $this->setTsLast($this->getTsFirst());
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"]));
206 trigger_error("The UID is invalid.", E_USER_ERROR);
208 $ob = mod_roomReservationBookingsManager::getBookingByUid(
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
215 isset($_GET["mod_roomReservationBookingTable"]["date"]) ?
216 intval($_GET["mod_roomReservationBookingTable"]["date"]) : time());
218 $this->setDate($ob->getDate());
220 $this->setTsFirst($ob->getTsFirst());
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
229 isset($_POST["mod_roomReservationBookingTable"]["date"]) ?
230 intval($_POST["mod_roomReservationBookingTable"]["date"]) : time());
232 isset($_POST["mod_roomReservationBookingTable"]["room"]) ?
233 $_POST["mod_roomReservationBookingTable"]["room"] : "");
235 isset($_POST["mod_roomReservationBookingTable"]["tsfirst"]) ?
236 intval($_POST["mod_roomReservationBookingTable"]["tsfirst"]) : 0);
238 isset($_POST["mod_roomReservationBookingTable"]["tslast"]) ?
239 intval($_POST["mod_roomReservationBookingTable"]["tslast"]) :
240 $this->getTsFirst());
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"] : "";
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) {
257 intval($_POST["mod_roomReservationBookingTable"]["uid"]));
259 trigger_error("The UID is invalid.", E_USER_ERROR);
261 // set the right date, room etc.
262 $ob = mod_roomReservationBookingsManager::getBookingByUid(
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"] : "");
274 /***************************************************************************/
277 * @name Access to attributes
282 * Set the action that should be done
283 * @param $c (constant) See @ref bookingtable_actions for possible values
285 protected function setAction($c) { $this->cAction = intval($c); }
288 * Set the starting timeslice of the requested booking
291 protected function setTsFirst($n) { $this->nTsFirst = intval($n); }
294 * Set the ending timeslice of the requested booking
297 protected function setTsLast($n) { $this->nTsLast = intval($n); }
300 * Set the date of the requested booking or the date to be shown in the
302 * @param $ts (timestamp)
304 public function setDate($ts) { $this->tsDate = intval($ts); }
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)
312 protected function setRoom($str) {
313 // only allow whitelisted rooms
314 if($this->oCfg->isRoomWhitelisted($str)) {
315 $this->strRoom = $str;
317 throw new Exception(_c("room-reservation:This room is not available ".
323 * Set the reason of the requested booking
324 * @param $str (string)
326 protected function setReason($str) { $this->strReason = $str; }
329 * Set the UID of the booking to be deleted / edited
332 protected function setUid($n) { $this->nUid = intval($n); }
335 * Set the value of the submit button that the user clicked
336 * @param $str (string)
338 protected function setSubmitButtonValue($str) {
339 $this->strSubmitButtonValue = $str;
343 * Get the name of the room of the requested booking or the room to show in
347 public function getRoom() { return $this->strRoom; }
350 * Get the action that should be done
351 * @return constant See @ref bookingtable_actions for possible values
353 public function getAction() { return $this->cAction; }
356 * Get the the starting timeslice of the requested booking
359 public function getTsFirst() { return $this->nTsFirst; }
362 * Get the the ending timeslice of the requested booking
365 public function getTsLast() { return $this->nTsLast; }
368 * Get the the date of the requested booking or the date to be shown in the
372 public function getDate() { return $this->tsDate; }
375 * Get the the reason of the requested booking
378 public function getReason() { return $this->strReason; }
381 * Get the UID of the booking to be deleted / edited
384 public function getUid() { return $this->nUid; }
387 * Get the value of the submit button that the user clicked
390 public function getSubmitButtonValue() {
391 return $this->strSubmitButtonValue;
394 /***************************************************************************/
402 * Add the CSS rules needed for this page
405 protected function addCSS() {
407 #mod_roomReservationBookingTable .msg { font-weight:800; }
408 #mod_roomReservationBookingTable td {
409 vertical-align:middle;
411 border:1px solid white; padding:0.4em;
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%;
426 if($this->oCfg->isShowWeekend()) {
427 $strCss .= "#mod_roomReservationBookingTable td.cell { width:13%; }";
429 $strCss .= "#mod_roomReservationBookingTable td.cell { width:18.2%; }";
437 * @throws AccessException
438 * @todo increase the height of the cells a little
440 public function show() {
442 if(!$this->oCfg->userCanView()) {
443 throw new AccessException(MOD_ROOM_RESERVATION_ERROR_ACCESS_DENIED);
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));
453 // Print the header with the days
454 $ncTs = sizeof($this->oCfg->getTimeslices());
455 $nDays = ($this->oCfg->isShowWeekend()) ? 7 : 5;
457 echo "<table id='mod_roomReservationBookingTable'><tr>";
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)");
470 echo sprintf("<td class='%s'>%s</td>", $strClass, $strTitle);
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);
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,
495 // a booking exists here
496 // print booking or deletion form or handle the deletion form
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);
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
516 $bSuccess = $this->oBm->delete($this->getUid());
517 } catch(Exception $e) {
518 $anNextRow[$i] += $this->printBooking($nTs, $ts, $ob, 0,
519 array($e->getMessage()));
521 // print booking link and a success message
523 $anNextRow[$i] += $this->printBookingLink($nTs, $ts,
524 array(_c("room-reservation:The booking was deleted.")));
527 // the user cancelled the request
528 $anNextRow[$i] += $this->printBooking($nTs, $ts, $ob);
531 // Something else -- print booking
533 $anNextRow[$i] += $this->printBooking($nTs, $ts, $ob);
536 // no booking is here
537 // print booking link, booking form or handle booking form
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);
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())) {
555 // try writing the booking to the database
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);
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,
572 // print new booking and increment the "next row" variable by
574 $oNewBooking->setUid($nNewUid);
575 $anNextRow[$i] += $this->printBooking($nTs, $ts, $oNewBooking,
576 MOD_ROOM_RESERVATION_BTPB_NEW);
579 // Something else -- print booking link:
581 $anNextRow[$i] += $this->printBookingLink($nTs, $ts);
588 echo "</table><br />";
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
602 protected function printBooking($nTs, $ts, mod_roomReservationBooking $ob,
603 $cFlags = 0, $asMsgs = array()) {
608 if(count($asMsgs) > 0) {
609 $strBefore .= "<p class='msg'>".nl2br(q(join("\n", $asMsgs)))."</p>\n";
612 // calculate the timespan of the current booking
613 $nSpan = $ob->getTsLast() - $ob->getTsFirst() + 1;
615 if(($cFlags & MOD_ROOM_RESERVATION_BTPB_DELETE) ==
616 MOD_ROOM_RESERVATION_BTPB_DELETE) {
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";
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());
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"));
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) {
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);
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)
687 protected function printBookingForm($nTs, $ts, $asErrors = array()) {
689 if(!($this->oCfg->userCanBook() or $this->oCfg->userIsAdmin())) {
690 printf("<td class='err'>%s</td>\n",
691 MOD_ROOM_RESERVATION_ERROR_ACCESS_DENIED);
695 $strErrors = "<p class='err'>".nl2br(q(join("\n", $asErrors)))."</p>";
697 // form to allow fixed bookings for admins
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);
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());
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)
739 protected function printBookingLink($nTs, $ts, $asMsgs = array()) {
742 if(!($this->oCfg->userCanBook() or $this->oCfg->userIsAdmin())) {
749 if(count($asMsgs) > 0) {
750 $strBefore .= "<p class='msg'>".join("<br />", $asMsgs)."</p>\n";
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",
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)"));
768 // only print the messages
769 echo sprintf("<td name='form' id='form' class='cell'>%s</td>\n",