c325d88bf6908df0193f33c4cfac0b17452dcbe6
[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
122 /***************************************************************************/
123 /**
124 * @name Constructor
125 * @{
126 * Constructor
127 * @param $oCfg (reference to mod_roomReservationConfig) Reference to the
128 * configuration
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
134 */
135 public function __construct(mod_roomReservationConfig &$oCfg,
136 mod_roomReservationRoomsManager &$oRm,
137 mod_roomReservationBookingsManager &$oBm) {
138 $this->oCfg = $oCfg;
139 $this->oRm = $oRm;
140 $this->oBm = $oBm;
141
142 $this->processRequestVariables();
143 $this->addCSS();
144 }
145
146 /***************************************************************************/
147 /**
148 * @}
149 * @name Initialization
150 * @{
151 */
152
153 /**
154 * Process the REQUEST variables and preset the some variables
155 * @return void
156 */
157 protected function processRequestVariables() {
158
159 ########################
160 # FIXME remove this
161 var_export($_GET); echo "<p />";
162 var_export($_POST); echo "<p />";
163 ########################
164
165 // default values
166 $aoRooms = $this->oRm->getRooms();
167 if($aoRooms != array()) {
168 $or = $aoRooms[0];
169 $this->setRoom($or->getName());
170 }
171 $this->setDate(time());
172 $this->setAction(MOD_ROOM_RESERVATION_BT_ACTION_SHOW);
173 $this->nPostInterval = 0;
174
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"] : "");
190 $this->setTsFirst(
191 isset($_GET["mod_roomReservationBookingTable"]["tsfirst"]) ?
192 intval($_GET["mod_roomReservationBookingTable"]["tsfirst"]) : 0);
193 $this->setTsLast($this->getTsFirst());
194
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"]));
201 } else {
202 trigger_error("The UID is invalid.", E_USER_ERROR);
203 }
204 $ob = mod_roomReservationBookingsManager::getBookingByUid(
205 $this->getUid());
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
210 $this->setDate(
211 isset($_GET["mod_roomReservationBookingTable"]["date"]) ?
212 intval($_GET["mod_roomReservationBookingTable"]["date"]) : time());
213 } else {
214 $this->setDate($ob->getDate());
215 }
216 $this->setTsFirst($ob->getTsFirst());
217 }
218 }
219
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
224 $this->setDate(
225 isset($_POST["mod_roomReservationBookingTable"]["date"]) ?
226 intval($_POST["mod_roomReservationBookingTable"]["date"]) : time());
227 $this->setRoom(
228 isset($_POST["mod_roomReservationBookingTable"]["room"]) ?
229 $_POST["mod_roomReservationBookingTable"]["room"] : "");
230 $this->setTsFirst(
231 isset($_POST["mod_roomReservationBookingTable"]["tsfirst"]) ?
232 intval($_POST["mod_roomReservationBookingTable"]["tsfirst"]) : 0);
233 $this->setTsLast(
234 isset($_POST["mod_roomReservationBookingTable"]["tslast"]) ?
235 intval($_POST["mod_roomReservationBookingTable"]["tslast"]) :
236 $this->getTsFirst());
237 $this->setReason(
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"] : "";
246 }
247
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) {
252 $this->setUid(
253 intval($_POST["mod_roomReservationBookingTable"]["uid"]));
254 } else {
255 trigger_error("The UID is invalid.", E_USER_ERROR);
256 }
257 // set the right date, room etc.
258 $ob = mod_roomReservationBookingsManager::getBookingByUid(
259 $this->getUid());
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"] : "");
266 }
267 }
268
269 ################
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());
277 ################
278 }
279
280 /***************************************************************************/
281 /**
282 * @}
283 * @name Access to attributes
284 * @{
285 */
286
287 /**
288 * Set the action that should be done
289 * @param $c (constant) See @ref bookingtable_actions for possible values
290 */
291 protected function setAction($c) { $this->cAction = intval($c); }
292
293 /**
294 * Set the starting timeslice of the requested booking
295 * @param $n (int)
296 */
297 protected function setTsFirst($n) { $this->nTsFirst = intval($n); }
298
299 /**
300 * Set the ending timeslice of the requested booking
301 * @param $n (int)
302 */
303 protected function setTsLast($n) { $this->nTsLast = intval($n); }
304
305 /**
306 * Set the date of the requested booking or the date to be shown in the
307 * booking table
308 * @param $ts (timestamp)
309 */
310 public function setDate($ts) { $this->tsDate = intval($ts); }
311
312 /**
313 * Set the room of the requested booking or the room to be shown in the
314 * booking table
315 * @param $str (string)
316 */
317 protected function setRoom($str) { $this->strRoom = $str; }
318
319 /**
320 * Set the reason of the requested booking
321 * @param $str (string)
322 */
323 protected function setReason($str) { $this->strReason = $str; }
324
325 /**
326 * Set the UID of the booking to be deleted / edited
327 * @param $n (int)
328 */
329 protected function setUid($n) { $this->nUid = intval($n); }
330
331 /**
332 * Set the value of the submit button that the user clicked
333 * @param $str (string)
334 */
335 protected function setSubmitButtonValue($str) {
336 $this->strSubmitButtonValue = $str;
337 }
338
339 /**
340 * Get the name of the room of the requested booking or the room to show in
341 * the booking table
342 * @return string
343 */
344 public function getRoom() { return $this->strRoom; }
345
346 /**
347 * Get the action that should be done
348 * @return constant See @ref bookingtable_actions for possible values
349 */
350 public function getAction() { return $this->cAction; }
351
352 /**
353 * Get the the starting timeslice of the requested booking
354 * @return int
355 */
356 public function getTsFirst() { return $this->nTsFirst; }
357
358 /**
359 * Get the the ending timeslice of the requested booking
360 * @return int
361 */
362 public function getTsLast() { return $this->nTsLast; }
363
364 /**
365 * Get the the date of the requested booking or the date to be shown in the
366 * booking table
367 * @return timestamp
368 */
369 public function getDate() { return $this->tsDate; }
370
371 /**
372 * Get the the reason of the requested booking
373 * @return string
374 */
375 public function getReason() { return $this->strReason; }
376
377 /**
378 * Get the UID of the booking to be deleted / edited
379 * @return int
380 */
381 public function getUid() { return $this->nUid; }
382
383 /**
384 * Get the value of the submit button that the user clicked
385 * @return string
386 */
387 public function getSubmitButtonValue() {
388 return $this->strSubmitButtonValue;
389 }
390
391 /***************************************************************************/
392 /**
393 * @}
394 * @name Output
395 * @{
396 */
397
398 /**
399 * Add the CSS rules needed for this page
400 * @return void
401 */
402 protected function addCSS() {
403 $strCss = <<<CSS
404 #mod_roomReservationBookingTable .msg { font-weight:800; }
405 #mod_roomReservationBookingTable td {
406 vertical-align:middle;
407 height:7em;
408 border:1px solid white; padding:0.4em;
409 }
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%;
421 }
422 CSS;
423 if($this->oCfg->isShowWeekend()) {
424 $strCss .= "#mod_roomReservationBookingTable td.cell { width:13%; }";
425 } else {
426 $strCss .= "#mod_roomReservationBookingTable td.cell { width:18.2%; }";
427 }
428 rrAddCss($strCss);
429 }
430
431 /**
432 * Show the timetable
433 * @return void
434 * @throws AccessException
435 * @todo increase the height of the cells a little
436 */
437 public function show() {
438 // Protect access
439 if(!$this->oCfg->userCanView()) {
440 throw new AccessException(MOD_ROOM_RESERVATION_ERROR_ACCESS_DENIED);
441 return;
442 }
443
444 // Print the header with the days
445 $ncTs = sizeof($this->oCfg->getTimeslices());
446 $nDays = ($this->oCfg->isShowWeekend()) ? 7 : 5;
447
448 echo "<table id='mod_roomReservationBookingTable'><tr>";
449
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)");
460 }
461 echo sprintf("<td class='%s'>%s</td>", $strClass, $strTitle);
462 }
463 echo "</tr>\n";
464
465 // Print timetable
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);
478
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,
485 $nTs)) !== null) {
486 // a booking exists here
487 // print booking or deletion form or handle the deletion form
488
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);
496
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
505 $bSuccess = false;
506 try {
507 $bSuccess = $this->oBm->delete($this->getUid());
508 } catch(Exception $e) {
509 $anNextRow[$i] += $this->printBooking($nTs, $ts, $ob, 0,
510 array($e->getMessage()));
511 }
512 // print booking link and a success message
513 if($bSuccess) {
514 $anNextRow[$i] += $this->printBookingLink($nTs, $ts,
515 array(_c("room-reservation:The booking was deleted.")));
516 }
517 } else {
518 // the user cancelled the request
519 $anNextRow[$i] += $this->printBooking($nTs, $ts, $ob);
520 }
521
522 // Something else -- print booking
523 } else {
524 $anNextRow[$i] += $this->printBooking($nTs, $ts, $ob);
525 }
526 } else {
527 // no booking is here
528 // print booking link, booking form or handle booking form
529 $asErrors = array();
530
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);
537
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())) {
545
546 // try writing the booking to the database
547 $nNewUid = -1;
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);
553 try {
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,
560 $asErrors);
561 }
562 if($nNewUid > 0) {
563 // print new booking and increment the "next row" variable by
564 // the current span
565 $anNextRow[$i] += $this->printBooking($nTs, $ts, $oNewBooking,
566 MOD_ROOM_RESERVATION_BTPB_NEW);
567 }
568
569 // Something else -- print booking link:
570 } else {
571 $anNextRow[$i] += $this->printBookingLink($nTs, $ts);
572 }
573 }
574 }
575 }
576 echo "</tr>\n";
577 }
578 echo "</table><br />";
579 }
580
581 /**
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
591 */
592 protected function printBooking($nTs, $ts, mod_roomReservationBooking $ob,
593 $cFlags = 0, $asMsgs = array()) {
594 $strAfter = "";
595 $strBefore = "";
596
597 // messages
598 if(count($asMsgs) > 0) {
599 $strBefore .= "<p class='msg'>".nl2br(q(join("\n", $asMsgs)))."</p>\n";
600 }
601
602 // calculate the timespan of the current booking
603 $nSpan = $ob->getTsLast() - $ob->getTsFirst() + 1;
604
605 if(($cFlags & MOD_ROOM_RESERVATION_BTPB_DELETE) ==
606 MOD_ROOM_RESERVATION_BTPB_DELETE) {
607
608 // Restrict access
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";
613 #return $nSpan;
614 } else {
615 // print delete form
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());
632 }
633 } else {
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"));
650 }
651 }
652
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) {
657 $strClass .= " new";
658 }
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);
665
666 return $nSpan;
667 }
668
669 /**
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)
676 */
677 protected function printBookingForm($nTs, $ts, $asErrors = array()) {
678 // Restrict access
679 if(!($this->oCfg->userCanBook() or $this->oCfg->userIsAdmin())) {
680 printf("<td class='err'>%s</td>\n",
681 MOD_ROOM_RESERVATION_ERROR_ACCESS_DENIED);
682 return 1;
683 }
684
685 $strErrors = "<p class='err'>".nl2br(q(join("\n", $asErrors)))."</p>";
686
687 // form to allow fixed bookings for admins
688 $sWeeklyForm = "";
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);
699 }
700
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());
718 return 1;
719 }
720
721 /**
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)
728 */
729 protected function printBookingLink($nTs, $ts, $asMsgs = array()) {
730
731 // Restrict access
732 if(!($this->oCfg->userCanBook() or $this->oCfg->userIsAdmin())) {
733 echo "<td />\n";
734 return 1;
735 }
736
737 // messages
738 $strBefore = "";
739 if(count($asMsgs) > 0) {
740 $strBefore .= "<p class='msg'>".join("<br />", $asMsgs)."</p>\n";
741 }
742
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",
746 $oTs->getEnd()));
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)"));
757 } else {
758 // only print the messages
759 echo sprintf("<td name='form' id='form' class='cell'>%s</td>\n",
760 $strBefore);
761 }
762 return 1;
763 }
764 /** @} */
765 }
766 ?>
This page took 0.120015 seconds and 3 git commands to generate.