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