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