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;
122 /***************************************************************************/
127 * @param $oCfg (reference to mod_roomReservationConfig) Reference to the
129 * @param $oRm (reference to mod_roomReservationRoomsManager) Reference to
130 * the rooms manager object
131 * @param $oBm (reference to mod_roomReservationBookingsManager) Reference
132 * to the bookings manager object
133 * @return mod_roomReservationBookingTable
135 public function __construct(mod_roomReservationConfig &$oCfg,
136 mod_roomReservationRoomsManager &$oRm,
137 mod_roomReservationBookingsManager &$oBm) {
142 $this->processRequestVariables();
146 /***************************************************************************/
149 * @name Initialization
154 * Process the REQUEST variables and preset the some variables
157 protected function processRequestVariables() {
159 ########################
161 var_export($_GET); echo "<p />";
162 var_export($_POST); echo "<p />";
163 ########################
166 $aoRooms = $this->oRm->getRooms();
167 if($aoRooms != array()) {
169 $this->setRoom($or->getName());
171 $this->setDate(time());
172 $this->setAction(MOD_ROOM_RESERVATION_BT_ACTION_SHOW);
173 $this->nPostInterval = 0;
175 // handle GET parameters
176 if(isset($_GET["mod_roomReservationBookingTable"])) {
177 $ga = isset($_GET["mod_roomReservationBookingTable"]["action"]) ?
178 $_GET["mod_roomReservationBookingTable"]["action"] : "";
179 $this->setAction(($ga == "book") ?
180 MOD_ROOM_RESERVATION_BT_ACTION_BOOK : (($ga == "edit") ?
181 MOD_ROOM_RESERVATION_BT_ACTION_EDIT : (($ga == "delete") ?
182 MOD_ROOM_RESERVATION_BT_ACTION_DELETE : (($ga == "submit") ?
183 MOD_ROOM_RESERVATION_BT_ACTION_SUBMIT : (($ga == "submitdelete") ?
184 MOD_ROOM_RESERVATION_BT_ACTION_SUBMITDELETE :
185 MOD_ROOM_RESERVATION_BT_ACTION_SHOW)))));
186 $this->setDate(isset($_GET["mod_roomReservationBookingTable"]["date"]) ?
187 intval($_GET["mod_roomReservationBookingTable"]["date"]) : time());
188 $this->setRoom(isset($_GET["mod_roomReservationBookingTable"]["room"]) ?
189 $_GET["mod_roomReservationBookingTable"]["room"] : "");
191 isset($_GET["mod_roomReservationBookingTable"]["tsfirst"]) ?
192 intval($_GET["mod_roomReservationBookingTable"]["tsfirst"]) : 0);
193 $this->setTsLast($this->getTsFirst());
195 // if deletion form is requested, set the right date, room etc.
196 if($this->getAction() == MOD_ROOM_RESERVATION_BT_ACTION_DELETE) {
197 if(isset($_GET["mod_roomReservationBookingTable"]["uid"]) &&
198 $_GET["mod_roomReservationBookingTable"]["uid"] >= 0) {
199 $this->setUid(intval(
200 $_GET["mod_roomReservationBookingTable"]["uid"]));
202 trigger_error("The UID is invalid.", E_USER_ERROR);
204 $ob = mod_roomReservationBookingsManager::getBookingByUid(
206 $this->setRoom($ob->getRoom());
207 if($ob->getInterval() > 0) {
208 // don't show the first date when the booking was created, but the
209 // date of the page where the user clicked the delete button
211 isset($_GET["mod_roomReservationBookingTable"]["date"]) ?
212 intval($_GET["mod_roomReservationBookingTable"]["date"]) : time());
214 $this->setDate($ob->getDate());
216 $this->setTsFirst($ob->getTsFirst());
220 if(isset($_POST["mod_roomReservationBookingTable"])) {
221 if(isset($_POST["mod_roomReservationBookingTable"]["submitbooking"])) {
222 // submission of the booking form
223 // let POST variables overwrite the variables
225 isset($_POST["mod_roomReservationBookingTable"]["date"]) ?
226 intval($_POST["mod_roomReservationBookingTable"]["date"]) : time());
228 isset($_POST["mod_roomReservationBookingTable"]["room"]) ?
229 $_POST["mod_roomReservationBookingTable"]["room"] : "");
231 isset($_POST["mod_roomReservationBookingTable"]["tsfirst"]) ?
232 intval($_POST["mod_roomReservationBookingTable"]["tsfirst"]) : 0);
234 isset($_POST["mod_roomReservationBookingTable"]["tslast"]) ?
235 intval($_POST["mod_roomReservationBookingTable"]["tslast"]) :
236 $this->getTsFirst());
238 isset($_POST["mod_roomReservationBookingTable"]["reason"]) ?
239 $_POST["mod_roomReservationBookingTable"]["reason"] : "");
240 $this->nPostInterval =
241 isset($_POST["mod_roomReservationBookingTable"]["interval"]) ?
242 intval($_POST["mod_roomReservationBookingTable"]["interval"]) : 0;
243 $this->strPostAccount =
244 isset($_POST["mod_roomReservationBookingTable"]["account"]) ?
245 $_POST["mod_roomReservationBookingTable"]["account"] : "";
248 if(isset($_POST["mod_roomReservationBookingTable"]["submitdelete"])) {
249 // submission of the deletion form
250 if(isset($_POST["mod_roomReservationBookingTable"]["uid"]) &&
251 $_POST["mod_roomReservationBookingTable"]["uid"] >= 0) {
253 intval($_POST["mod_roomReservationBookingTable"]["uid"]));
255 trigger_error("The UID is invalid.", E_USER_ERROR);
257 // set the right date, room etc.
258 $ob = mod_roomReservationBookingsManager::getBookingByUid(
260 $this->setRoom($ob->getRoom());
261 $this->setDate($ob->getDate());
262 $this->setTsFirst($ob->getTsFirst());
263 $this->setSubmitButtonValue(isset(
264 $_POST["mod_roomReservationBookingTable"]["submitdelete"]) ?
265 $_POST["mod_roomReservationBookingTable"]["submitdelete"] : "");
270 /** FIXME remove this */
271 echo sprintf("date: %s <br />", $this->getDate());
272 echo sprintf("room: %s <br />", $this->getRoom());
273 echo sprintf("reason: %s <br />", $this->getReason());
274 echo sprintf("tsfirst: %s <br />", $this->getTsFirst());
275 echo sprintf("tslast: %s <br />", $this->getTsLast());
276 echo sprintf("action: %s <br />", $this->getAction());
280 /***************************************************************************/
283 * @name Access to attributes
288 * Set the action that should be done
289 * @param $c (constant) See @ref bookingtable_actions for possible values
291 protected function setAction($c) { $this->cAction = intval($c); }
294 * Set the starting timeslice of the requested booking
297 protected function setTsFirst($n) { $this->nTsFirst = intval($n); }
300 * Set the ending timeslice of the requested booking
303 protected function setTsLast($n) { $this->nTsLast = intval($n); }
306 * Set the date of the requested booking or the date to be shown in the
308 * @param $ts (timestamp)
310 public function setDate($ts) { $this->tsDate = intval($ts); }
313 * Set the room of the requested booking or the room to be shown in the
315 * @param $str (string)
317 protected function setRoom($str) { $this->strRoom = $str; }
320 * Set the reason of the requested booking
321 * @param $str (string)
323 protected function setReason($str) { $this->strReason = $str; }
326 * Set the UID of the booking to be deleted / edited
329 protected function setUid($n) { $this->nUid = intval($n); }
332 * Set the value of the submit button that the user clicked
333 * @param $str (string)
335 protected function setSubmitButtonValue($str) {
336 $this->strSubmitButtonValue = $str;
340 * Get the name of the room of the requested booking or the room to show in
344 public function getRoom() { return $this->strRoom; }
347 * Get the action that should be done
348 * @return constant See @ref bookingtable_actions for possible values
350 public function getAction() { return $this->cAction; }
353 * Get the the starting timeslice of the requested booking
356 public function getTsFirst() { return $this->nTsFirst; }
359 * Get the the ending timeslice of the requested booking
362 public function getTsLast() { return $this->nTsLast; }
365 * Get the the date of the requested booking or the date to be shown in the
369 public function getDate() { return $this->tsDate; }
372 * Get the the reason of the requested booking
375 public function getReason() { return $this->strReason; }
378 * Get the UID of the booking to be deleted / edited
381 public function getUid() { return $this->nUid; }
384 * Get the value of the submit button that the user clicked
387 public function getSubmitButtonValue() {
388 return $this->strSubmitButtonValue;
391 /***************************************************************************/
399 * Add the CSS rules needed for this page
402 protected function addCSS() {
404 #mod_roomReservationBookingTable .msg { font-weight:800; }
405 #mod_roomReservationBookingTable td {
406 vertical-align:middle;
408 border:1px solid white; padding:0.4em;
410 #mod_roomReservationBookingTable td.booking { background-color:#5276AB; }
411 #mod_roomReservationBookingTable td.new { background-color:#008015; }
412 #mod_roomReservationBookingTable td.recurring { background-color:#1C4174; }
413 #mod_roomReservationBookingTable td.recurringnew { background-color:#006010; }
414 #mod_roomReservationBookingTable td.heading { font-weight:bold; height:3em; }
415 #mod_roomReservationBookingTable td.lesson { width:9%; }
416 #mod_roomReservationBookingTable td.today { font-style:italic; }
417 #mod_roomReservationBookingTable {
418 border:1px solid white;
419 border-collapse:collapse;
420 text-align:center; width:100%;
423 if($this->oCfg->isShowWeekend()) {
424 $strCss .= "#mod_roomReservationBookingTable td.cell { width:13%; }";
426 $strCss .= "#mod_roomReservationBookingTable td.cell { width:18.2%; }";
434 * @throws AccessException
435 * @todo increase the height of the cells a little
437 public function show() {
439 if(!$this->oCfg->userCanView()) {
440 throw new AccessException(MOD_ROOM_RESERVATION_ERROR_ACCESS_DENIED);
444 // Print the header with the days
445 $ncTs = sizeof($this->oCfg->getTimeslices());
446 $nDays = ($this->oCfg->isShowWeekend()) ? 7 : 5;
448 echo "<table id='mod_roomReservationBookingTable'><tr>";
450 // Print header with day names
451 echo "<td class='heading' />";
452 for($ts = rrGetMonday($this->getDate()), $i=0; $i < $nDays;
453 $ts = strtotime("1 day", $ts), $i++) {
454 // Use a different color for the current day
455 $strClass = "heading";
456 $strTitle = strftime("%A<br />%x", $ts);
457 if(date("Ymd") === date("Ymd", $ts)) {
458 $strClass .= " today";
459 $strTitle .= " "._c("room-reservation:(today)");
461 echo sprintf("<td class='%s'>%s</td>", $strClass, $strTitle);
466 // To take care of bookings with more than one timeslice, we use an array
467 // that tells us which cell in the current column is the next to fill
468 $anNextRow = array_fill(0, $nDays, 0);
469 // Iterate over the timeslices
470 for($nTs = 0; $nTs < $ncTs; $nTs++) {
471 $strLessons = $this->oCfg->isShowLessons() ?_sprintf_ord(
472 _c("room-reservation:%s# lesson"), $nTs + 1) . "<br />" : "";
473 $oTs = $this->oCfg->getTimeslice($nTs);
474 $strTs = sprintf("%s - %s", strftime(_("%#I:%M %p"), $oTs->getBegin()),
475 strftime(_("%#I:%M %p"), $oTs->getEnd()));
476 // First column: Lesson
477 echo sprintf("<tr><td class='lesson'>%s</td>", $strLessons . $strTs);
479 // Iterate over the days
480 for($ts = rrGetMonday($this->getDate()), $i = 0; $i <= $nDays;
481 $ts = strtotime("1 day", $ts), $i++) {
482 // Don't print if there is a spanning booking on the current cell
483 if(isset($anNextRow[$i]) && $anNextRow[$i] == $nTs) {
484 if(($ob = $this->oBm->getBookingByTimeslice($this->getRoom(), $ts,
486 // a booking exists here
487 // print booking or deletion form or handle the deletion form
489 // deletion form is requested:
490 if(($this->getAction() == MOD_ROOM_RESERVATION_BT_ACTION_DELETE) &&
491 (date("Ymd", $this->getDate()) == date("Ymd", $ts)) &&
492 ($this->getTsFirst() == $nTs) &&
493 ($this->getRoom() == $this->getRoom())) {
494 $anNextRow[$i] += $this->printBooking($nTs, $ts, $ob,
495 MOD_ROOM_RESERVATION_BTPB_DELETE);
497 // deletion form is submitted:
498 } else if(($this->getAction() ==
499 MOD_ROOM_RESERVATION_BT_ACTION_SUBMITDELETE) &&
500 (date("Ymd", $this->getDate()) == date("Ymd", $ts)) &&
501 ($this->getTsFirst() == $nTs) &&
502 ($this->getRoom() == $this->getRoom())) {
503 if($this->getSubmitButtonValue() == _("Delete")) {
504 // the user clicked the "delete" button
507 $bSuccess = $this->oBm->delete($this->getUid());
508 } catch(Exception $e) {
509 $anNextRow[$i] += $this->printBooking($nTs, $ts, $ob, 0,
510 array($e->getMessage()));
512 // print booking link and a success message
514 $anNextRow[$i] += $this->printBookingLink($nTs, $ts,
515 array(_c("room-reservation:The booking was deleted.")));
518 // the user cancelled the request
519 $anNextRow[$i] += $this->printBooking($nTs, $ts, $ob);
522 // Something else -- print booking
524 $anNextRow[$i] += $this->printBooking($nTs, $ts, $ob);
527 // no booking is here
528 // print booking link, booking form or handle booking form
531 // booking form is requested:
532 if(($this->getAction() == MOD_ROOM_RESERVATION_BT_ACTION_BOOK) &&
533 (date("Ymd", $this->getDate()) == date("Ymd", $ts)) &&
534 ($this->getTsFirst() == $nTs) &&
535 ($this->getRoom() == $this->getRoom())) {
536 $anNextRow[$i] += $this->printBookingForm($nTs, $ts, $asErrors);
538 // booking form is submitted:
539 } else if(($this->getAction() ==
540 MOD_ROOM_RESERVATION_BT_ACTION_SUBMIT) &&
541 // only handle the request if the form was in the current cell
542 (date("Ymd", $this->getDate()) == date("Ymd", $ts)) &&
543 ($this->getTsFirst() == $nTs) &&
544 ($this->getRoom() == $this->getRoom())) {
546 // try writing the booking to the database
548 $oNewBooking = new mod_roomReservationBooking($this->getRoom(),
549 $this->getDate(), $this->getTsFirst(), $this->getTsLast(),
550 (trim($this->strPostAccount) == "") ? $_SESSION["act"] :
551 $this->strPostAccount, $this->getReason(),
552 $this->nPostInterval);
554 $nNewUid = $this->oBm->write($oNewBooking);
555 } catch(Exception $s) {
556 // print the booking form again with the user's input
557 // @todo check for overlapping bookings and print them
558 $asErrors[] = $s->getMessage();
559 $anNextRow[$i] += $this->printBookingForm($nTs, $ts,
563 // print new booking and increment the "next row" variable by
565 $anNextRow[$i] += $this->printBooking($nTs, $ts, $oNewBooking,
566 MOD_ROOM_RESERVATION_BTPB_NEW);
569 // Something else -- print booking link:
571 $anNextRow[$i] += $this->printBookingLink($nTs, $ts);
578 echo "</table><br />";
582 * Print a single booking in the booking table.
583 * @param $nTs (int) current timeslice
584 * @param $ts (timestamp) current date
585 * @param $ob (mod_roomReservationBooking) the booking
586 * @param $cFlags (constant) Flags,
587 * See @ref bookingtable_printbooking_flags for more information.
588 * @param $asMsgs (array of strings) Additional messages to be printed
589 * inside the cell, one array element per message
590 * @return (int) the span of the booking
592 protected function printBooking($nTs, $ts, mod_roomReservationBooking $ob,
593 $cFlags = 0, $asMsgs = array()) {
598 if(count($asMsgs) > 0) {
599 $strBefore .= "<p class='msg'>".nl2br(q(join("\n", $asMsgs)))."</p>\n";
602 // calculate the timespan of the current booking
603 $nSpan = $ob->getTsLast() - $ob->getTsFirst() + 1;
605 if(($cFlags & MOD_ROOM_RESERVATION_BTPB_DELETE) ==
606 MOD_ROOM_RESERVATION_BTPB_DELETE) {
609 if(!($this->oBm->userIsOwner($ob->getUid()) or
610 $this->oCfg->userIsAdmin())) {
611 $strBefore .= "<p class='msg'>" .
612 MOD_ROOM_RESERVATION_ERROR_ACCESS_DENIED . "</p>\n";
616 $strWarning = sprintf("<div>%s%s</div>", icon("dlg-warn",
617 array("bg" =>"gb")), _c("room-reservation:<b>Attention:</b> This ".
618 "booking is a recurring booking. If you delete it, the period will ".
619 "be deallocated for <b>every week</b>, not just this single week!"));
620 $strAfter .= sprintf("<p name='form' id='form' style='".
621 "text-align:center'><form action='%s?".
622 "mod_roomReservationBookingTable[action]=submitdelete#form' ".
623 "method='post'>%s%s<br /><%s name='mod_roomReservationBookingTable".
624 "[submitdelete]' value='%s' /> <%s name='".
625 "mod_roomReservationBookingTable[submitdelete]' value='%s' />".
626 "<input type='hidden' name='mod_roomReservationBookingTable[uid]' ".
627 "value='%d' /></form></p>", $_SERVER["PHP_SELF"],
628 _c("room-reservation:Delete this booking?"),
629 ($ob->getInterval() > 0 ? $strWarning : ""), $GLOBALS["smlbtn"],
630 _("Delete"), $GLOBALS["smlbtn"], _("Cancel"), $ob->getUid(),
631 $this->getRoom(), $this->getDate());
634 // delete and edit links, show only if user is allowed to
635 if($this->oBm->userIsOwner($ob->getUid()) ||
636 $this->oCfg->userIsAdmin()) {
637 /** @todo edit form */
638 $strAfter .= sprintf("<br />(<!-- <a href='%s?".
639 "mod_roomReservationBookingTable[action]=edit&".
640 "mod_roomReservationBookingTable[uid]=%d&".
641 "mod_roomReservationBookingTable[date]=%d#form' title='%s'>%s</a>, -->".
642 "<a href='%s?mod_roomReservationBookingTable[action]=delete&".
643 "mod_roomReservationBookingTable[uid]=%d&".
644 "mod_roomReservationBookingTable[date]=%d#form' title='%s'>%s</a>)",
645 $_SERVER["PHP_SELF"], $ob->getUid(), $ts,
646 _c("room-reservation:Edit this booking"),
647 _c("room-reservation:edit"), $_SERVER["PHP_SELF"], $ob->getUid(),
648 $ts, _c("room-reservation:Delete this booking"),
649 _c("room-reservation:delete"));
653 // test if booking is new and should be highlighted
654 $strClass = "cell booking".($ob->getInterval() > 0 ? " recurring" : "");
655 if(($cFlags & MOD_ROOM_RESERVATION_BTPB_NEW) ==
656 MOD_ROOM_RESERVATION_BTPB_NEW) {
659 // Use a different style for the current day
660 $strClass .= (date("Ymd", $ob->getDate()) == date("Ymd") ? " today" : "");
661 /** @todo: add ?subject=... to mailto link */
662 echo sprintf("<td rowspan='%d' class='%s'>%s<a %s>%s</a><br />%s%s</td>\n",
663 $nSpan, $strClass, $strBefore, mailto($ob->getAct()),
664 q(getRealUserName($ob->getAct())), q($ob->getReason()), $strAfter);
670 * Print the booking form.
671 * @param $nTs (int) current timeslice
672 * @param $ts (timestamp) current date
673 * @param $asErrors (array of strings) Additional error message to be printed
674 * inside the cell, one array element per message
675 * @return (int) the span of the booking (i.e., 1)
677 protected function printBookingForm($nTs, $ts, $asErrors = array()) {
679 if(!($this->oCfg->userCanBook() or $this->oCfg->userIsAdmin())) {
680 printf("<td class='err'>%s</td>\n",
681 MOD_ROOM_RESERVATION_ERROR_ACCESS_DENIED);
685 $strErrors = "<p class='err'>".nl2br(q(join("\n", $asErrors)))."</p>";
687 // form to allow fixed bookings for admins
689 if($this->oCfg->userIsAdmin()) {
690 $sWeeklyForm = sprintf("<label for='interval'>%s</label> %s<br />".
691 "<label for='account'>%s</label> <%s name='".
692 "mod_roomReservationBookingTable[account]' id='account' value='%s' ".
693 "size='15' /><br />", _c("room-reservation:Repetition:"),
694 select("mod_roomReservationBookingTable[interval]",
695 $this->nPostInterval, array(0 => _c("Select:None"), 1 =>
696 _c("room-reservation:every week")), array("add" => "id='interval'")),
697 _c("room-reservation:Account, if not yourself:"), $GLOBALS["stdedt"],
698 $this->strPostAccount);
701 echo sprintf("<td name='form' id='form' style='text-align:left'>%s".
702 "<form action='%s?mod_roomReservationBookingTable[action]=".
703 "submit#form' method='post'><label for='tslast'>%s</label> %s".
704 "<br /><label for='reason'>%s</label> <%s id='reason' size='15' ".
705 "value='%s' name='mod_roomReservationBookingTable[reason]' /><br />%s".
706 "<%s name='mod_roomReservationBookingTable[submitbooking]' value='%s' />".
707 "<input type='hidden' name='mod_roomReservationBookingTable[date]' ".
708 "value='%s' /><input type='hidden' name='".
709 "mod_roomReservationBookingTable[room]' value='%s' /><input ".
710 "type='hidden' name='mod_roomReservationBookingTable[tsfirst]' ".
711 "value='%s' /></form></td>\n", (count($asErrors) > 0) ? $strErrors : "",
712 $_SERVER["PHP_SELF"], _c("room-reservation:until:"),
713 select("mod_roomReservationBookingTable[tslast]", $this->getTsLast(),
714 $this->oCfg->getTimesliceEndings(true)), _c("room-reservation:Reason:"),
715 $GLOBALS["stdedt"], $this->getReason(), $sWeeklyForm, $GLOBALS["smlbtn"],
716 _c("room-reservation:Book"), $this->getDate(), $this->getRoom(),
717 $this->getTsFirst());
722 * Print the booking link
723 * @param $nTs (int) current timeslice
724 * @param $ts (timestamp) current date
725 * @param $asMsgs (array of strings) Additional messages to be printed
726 * inside the cell, one array element per message
727 * @return (int) the span of the booking (i.e., 1)
729 protected function printBookingLink($nTs, $ts, $asMsgs = array()) {
732 if(!($this->oCfg->userCanBook() or $this->oCfg->userIsAdmin())) {
739 if(count($asMsgs) > 0) {
740 $strBefore .= "<p class='msg'>".join("<br />", $asMsgs)."</p>\n";
743 // print link to booking if the timeslice is later than now
744 $oTs = $this->oCfg->getTimeslice($nTs);
745 $tsCur = strtotime(date("Y-m-d ", $ts) . date(" G:i",
747 if($tsCur > time()) {
748 $strURL = $_SERVER["PHP_SELF"] .
749 sprintf("?mod_roomReservationBookingTable[action]=book&".
750 "mod_roomReservationBookingTable[date]=%d&".
751 "mod_roomReservationBookingTable[room]=%s&".
752 "mod_roomReservationBookingTable[tsfirst]=%d#form", $ts,
753 qu($this->getRoom()), $nTs);
754 echo sprintf("<td class='cell'>%s<a href='%s' title='%s'>%s</a></td>\n",
755 $strBefore, $strURL, _c("room-reservation:Book this room from here"),
756 _c("room-reservation:(Book from here)"));
758 // only print the messages
759 echo sprintf("<td name='form' id='form' class='cell'>%s</td>\n",