config.inc is now touched by the Makefile for standard values, removed .hgignore
[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 $oNewBooking->setUid($nNewUid);
550 $anNextRow[$i] += $this->printBooking($nTs, $ts, $oNewBooking,
551 MOD_ROOM_RESERVATION_BTPB_NEW);
552 }
553
554 // Something else -- print booking link:
555 } else {
556 $anNextRow[$i] += $this->printBookingLink($nTs, $ts);
557 }
558 }
559 }
560 }
561 echo "</tr>\n";
562 }
563 echo "</table><br />";
564 }
565
566 /**
567 * Print a single booking in the booking table.
568 * @param $nTs (int) current timeslice
569 * @param $ts (timestamp) current date
570 * @param $ob (mod_roomReservationBooking) the booking
571 * @param $cFlags (constant) Flags,
572 * See @ref bookingtable_printbooking_flags for more information.
573 * @param $asMsgs (array of strings) Additional messages to be printed
574 * inside the cell, one array element per message
575 * @return (int) the span of the booking
576 */
577 protected function printBooking($nTs, $ts, mod_roomReservationBooking $ob,
578 $cFlags = 0, $asMsgs = array()) {
579 $strAfter = "";
580 $strBefore = "";
581
582 // messages
583 if(count($asMsgs) > 0) {
584 $strBefore .= "<p class='msg'>".nl2br(q(join("\n", $asMsgs)))."</p>\n";
585 }
586
587 // calculate the timespan of the current booking
588 $nSpan = $ob->getTsLast() - $ob->getTsFirst() + 1;
589
590 if(($cFlags & MOD_ROOM_RESERVATION_BTPB_DELETE) ==
591 MOD_ROOM_RESERVATION_BTPB_DELETE) {
592
593 // Restrict access
594 if(!($this->oBm->userIsOwner($ob->getUid()) or
595 $this->oCfg->userIsAdmin())) {
596 $strBefore .= "<p class='msg'>" .
597 MOD_ROOM_RESERVATION_ERROR_ACCESS_DENIED . "</p>\n";
598 #return $nSpan;
599 } else {
600 // print delete form
601 $strWarning = sprintf("<div>%s%s</div>", icon("dlg-warn",
602 array("bg" =>"gb")), _c("room-reservation:<b>Attention:</b> This ".
603 "booking is a recurring booking. If you delete it, the period will ".
604 "be deallocated for <b>every week</b>, not just this single week!"));
605 $strAfter .= sprintf("<p name='form' id='form' style='".
606 "text-align:center'><form action='%s?".
607 "mod_roomReservationBookingTable[action]=submitdelete#form' ".
608 "method='post'>%s%s<br /><%s name='mod_roomReservationBookingTable".
609 "[submitdelete]' value='%s' /> <%s name='".
610 "mod_roomReservationBookingTable[submitdelete]' value='%s' />".
611 "<input type='hidden' name='mod_roomReservationBookingTable[uid]' ".
612 "value='%d' /></form></p>", $_SERVER["PHP_SELF"],
613 _c("room-reservation:Delete this booking?"),
614 ($ob->getInterval() > 0 ? $strWarning : ""), $GLOBALS["smlbtn"],
615 _("Delete"), $GLOBALS["smlbtn"], _("Cancel"), $ob->getUid(),
616 $this->getRoom(), $this->getDate());
617 }
618 } else {
619 // delete and edit links, show only if user is allowed to
620 if($this->oBm->userIsOwner($ob->getUid()) ||
621 $this->oCfg->userIsAdmin()) {
622 /** @todo edit form */
623 $strAfter .= sprintf("<br />(<!-- <a href='%s?".
624 "mod_roomReservationBookingTable[action]=edit&".
625 "mod_roomReservationBookingTable[uid]=%d&".
626 "mod_roomReservationBookingTable[date]=%d#form' title='%s'>%s</a>, -->".
627 "<a href='%s?mod_roomReservationBookingTable[action]=delete&".
628 "mod_roomReservationBookingTable[uid]=%d&".
629 "mod_roomReservationBookingTable[date]=%d#form' title='%s'>%s</a>)",
630 $_SERVER["PHP_SELF"], $ob->getUid(), $ts,
631 _c("room-reservation:Edit this booking"),
632 _c("room-reservation:edit"), $_SERVER["PHP_SELF"], $ob->getUid(),
633 $ts, _c("room-reservation:Delete this booking"),
634 _c("room-reservation:delete"));
635 }
636 }
637
638 // test if booking is new and should be highlighted
639 $strClass = "cell booking".($ob->getInterval() > 0 ? " recurring" : "");
640 if(($cFlags & MOD_ROOM_RESERVATION_BTPB_NEW) ==
641 MOD_ROOM_RESERVATION_BTPB_NEW) {
642 $strClass .= " new";
643 }
644 // Use a different style for the current day
645 $strClass .= (date("Ymd", $ob->getDate()) == date("Ymd") ? " today" : "");
646 /** @todo: add ?subject=... to mailto link */
647 echo sprintf("<td rowspan='%d' class='%s'>%s<a %s>%s</a><br />%s%s</td>\n",
648 $nSpan, $strClass, $strBefore, mailto($ob->getAct()),
649 q(getRealUserName($ob->getAct())), q($ob->getReason()), $strAfter);
650
651 return $nSpan;
652 }
653
654 /**
655 * Print the booking form.
656 * @param $nTs (int) current timeslice
657 * @param $ts (timestamp) current date
658 * @param $asErrors (array of strings) Additional error message to be printed
659 * inside the cell, one array element per message
660 * @return (int) the span of the booking (i.e., 1)
661 */
662 protected function printBookingForm($nTs, $ts, $asErrors = array()) {
663 // Restrict access
664 if(!($this->oCfg->userCanBook() or $this->oCfg->userIsAdmin())) {
665 printf("<td class='err'>%s</td>\n",
666 MOD_ROOM_RESERVATION_ERROR_ACCESS_DENIED);
667 return 1;
668 }
669
670 $strErrors = "<p class='err'>".nl2br(q(join("\n", $asErrors)))."</p>";
671
672 // form to allow fixed bookings for admins
673 $sWeeklyForm = "";
674 if($this->oCfg->userIsAdmin()) {
675 $sWeeklyForm = sprintf("<label for='interval'>%s</label> %s<br />".
676 "<label for='account'>%s</label> <%s name='".
677 "mod_roomReservationBookingTable[account]' id='account' value='%s' ".
678 "size='15' /><br />", _c("room-reservation:Repetition:"),
679 select("mod_roomReservationBookingTable[interval]",
680 $this->nPostInterval, array(0 => _c("Select:None"), 1 =>
681 _c("room-reservation:every week")), array("add" => "id='interval'")),
682 _c("room-reservation:Account, if not yourself:"), $GLOBALS["stdedt"],
683 $this->strPostAccount);
684 }
685
686 echo sprintf("<td name='form' id='form' style='text-align:left'>%s".
687 "<form action='%s?mod_roomReservationBookingTable[action]=".
688 "submit#form' method='post'><label for='tslast'>%s</label> %s".
689 "<br /><label for='reason'>%s</label> <%s id='reason' size='15' ".
690 "value='%s' name='mod_roomReservationBookingTable[reason]' /><br />%s".
691 "<%s name='mod_roomReservationBookingTable[submitbooking]' value='%s' />".
692 "<input type='hidden' name='mod_roomReservationBookingTable[date]' ".
693 "value='%s' /><input type='hidden' name='".
694 "mod_roomReservationBookingTable[room]' value='%s' /><input ".
695 "type='hidden' name='mod_roomReservationBookingTable[tsfirst]' ".
696 "value='%s' /></form></td>\n", (count($asErrors) > 0) ? $strErrors : "",
697 $_SERVER["PHP_SELF"], _c("room-reservation:until:"),
698 select("mod_roomReservationBookingTable[tslast]", $this->getTsLast(),
699 $this->oCfg->getTimesliceEndings(true)), _c("room-reservation:Reason:"),
700 $GLOBALS["stdedt"], $this->getReason(), $sWeeklyForm, $GLOBALS["smlbtn"],
701 _c("room-reservation:Book"), $this->getDate(), $this->getRoom(),
702 $this->getTsFirst());
703 return 1;
704 }
705
706 /**
707 * Print the booking link
708 * @param $nTs (int) current timeslice
709 * @param $ts (timestamp) current date
710 * @param $asMsgs (array of strings) Additional messages to be printed
711 * inside the cell, one array element per message
712 * @return (int) the span of the booking (i.e., 1)
713 */
714 protected function printBookingLink($nTs, $ts, $asMsgs = array()) {
715
716 // Restrict access
717 if(!($this->oCfg->userCanBook() or $this->oCfg->userIsAdmin())) {
718 echo "<td />\n";
719 return 1;
720 }
721
722 // messages
723 $strBefore = "";
724 if(count($asMsgs) > 0) {
725 $strBefore .= "<p class='msg'>".join("<br />", $asMsgs)."</p>\n";
726 }
727
728 // print link to booking if the timeslice is later than now
729 $oTs = $this->oCfg->getTimeslice($nTs);
730 $tsCur = strtotime(date("Y-m-d ", $ts) . date(" G:i",
731 $oTs->getEnd()));
732 if($tsCur > time()) {
733 $strURL = $_SERVER["PHP_SELF"] .
734 sprintf("?mod_roomReservationBookingTable[action]=book&".
735 "mod_roomReservationBookingTable[date]=%d&".
736 "mod_roomReservationBookingTable[room]=%s&".
737 "mod_roomReservationBookingTable[tsfirst]=%d#form", $ts,
738 qu($this->getRoom()), $nTs);
739 echo sprintf("<td class='cell'>%s<a href='%s' title='%s'>%s</a></td>\n",
740 $strBefore, $strURL, _c("room-reservation:Book this room from here"),
741 _c("room-reservation:(Book from here)"));
742 } else {
743 // only print the messages
744 echo sprintf("<td name='form' id='form' class='cell'>%s</td>\n",
745 $strBefore);
746 }
747 return 1;
748 }
749 /** @} */
750 }
751 ?>
This page took 0.072998 seconds and 5 git commands to generate.