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