ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilBookingReservationsGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4
12{
16 protected $help;
17
21 protected $context_obj_id;
22
31 {
32 global $DIC;
33
34 $this->tpl = $DIC->ui()->mainTemplate();
35 $this->pool = $pool;
36 $this->ctrl = $DIC->ctrl();
37 $this->ref_id = $pool->getRefId();
38 $this->lng = $DIC->language();
39 $this->access = $DIC->access();
40 $this->tabs_gui = $DIC->tabs();
41 $this->help = $help;
42 $this->user = $DIC->user();
43
44 $this->book_obj_id = (int) $_REQUEST['object_id'];
45
46 $this->context_obj_id = $context_obj_id;
47
48 // user who's reservation is being tackled (e.g. canceled)
49 $this->booked_user = (int) $_REQUEST['bkusr'];
50 if ($this->booked_user == 0) {
51 $this->booked_user = $DIC->user()->getId();
52 }
53 // we get this from the reservation screen
54 $this->reservation_id = ilUtil::stripSlashes($_GET["reservation_id"]);
55
56 $this->ctrl->saveParameter($this, ["object_id", "bkusr"]);
57
58 if ((int) $_REQUEST['object_id'] > 0 && ilBookingObject::lookupPoolId((int) $_REQUEST['object_id']) != $this->pool->getId()) {
59 throw new ilException("Booking Object ID does not match Booking Pool.");
60 }
61 }
62
67 protected function getLogReservationIds()
68 {
69 if (is_array($_POST["mrsv"])) {
70 return $_POST["mrsv"];
71 } elseif ($this->reservation_id > 0) {
72 return array($this->reservation_id);
73 }
74 return [];
75 }
76
77
81 public function executeCommand()
82 {
83 $ctrl = $this->ctrl;
84
85 $next_class = $ctrl->getNextClass($this);
86 $cmd = $ctrl->getCmd("log");
87
88 switch ($next_class) {
89 default:
90 if (in_array($cmd, array("log", "logDetails", "changeStatusObject", "rsvConfirmCancelUser", "rsvCancelUser",
91 "applyLogFilter", "resetLogFilter", "rsvConfirmCancel", "rsvCancel", "back", "rsvConfirmDelete", "rsvDelete"))) {
92 $this->$cmd();
93 }
94 }
95 }
96
100 protected function setHelpId(string $a_id)
101 {
102 $this->help->setHelpId($a_id);
103 }
104
108 public function log()
109 {
111 $table = $this->getReservationsTable();
112 $tpl->setContent($table->getHTML());
113 }
114
121 protected function getReservationsTable($reservation_id = null)
122 {
123 $show_all = ($this->checkPermissionBool('write') || $this->pool->hasPublicLog());
124
125 $filter = null;
126 if ($this->book_obj_id > 0) {
127 $filter["object"] = $this->book_obj_id;
128 }
129 // coming from participants tab to cancel reservations.
130 if ($_GET['user_id']) {
131 $filter["user_id"] = (int) $_GET['user_id'];
132 }
133 $context_filter = ($this->context_obj_id > 0)
134 ? [$this->context_obj_id]
135 : null;
136
138 $this,
139 'log',
140 $this->ref_id,
141 $this->pool->getId(),
142 $show_all,
143 ($this->pool->getScheduleType() == ilObjBookingPool::TYPE_FIX_SCHEDULE),
144 $filter,
145 $reservation_id,
146 $context_filter
147 );
148 }
149
150
151 public function logDetails()
152 {
154
155 $this->tabs_gui->clearTargets();
156 $this->tabs_gui->setBackTarget(
157 $this->lng->txt("back"),
158 $this->ctrl->getLinkTarget($this, "log")
159 );
160
161 $table = $this->getReservationsTable($this->reservation_id);
162 $tpl->setContent($table->getHTML());
163 }
164
168 public function changeStatusObject()
169 {
170 if (!$_POST['reservation_id']) {
171 ilUtil::sendFailure($this->lng->txt('select_one'));
172 $this->log();
173 }
174
175 if ($this->checkPermissionBool('write')) {
176 ilBookingReservation::changeStatus($_POST['reservation_id'], (int) $_POST['tstatus']);
177 }
178
179 ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
180 $this->ctrl->redirect($this, 'log');
181 }
182
186 public function applyLogFilter()
187 {
188 $table = $this->getReservationsTable();
189 $table->resetOffset();
190 $table->writeFilterToSession();
191 $this->log();
192 }
193
197 public function resetLogFilter()
198 {
199 $table = $this->getReservationsTable();
200 $table->resetOffset();
201 $table->resetFilter();
202 $this->log();
203 }
204
211 protected function checkPermissionBool($a_perm)
212 {
213 $ilAccess = $this->access;
214
215 return $ilAccess->checkAccess($a_perm, "", $this->ref_id);
216 }
217
218 //
219 // Cancelation reservations
220 //
221
231 public function rsvConfirmCancelUser()
232 {
233 $ilCtrl = $this->ctrl;
236 $id = $this->book_obj_id;
237 if (!$id) {
238 return;
239 }
240
241 $this->setHelpId("cancel_booking");
242
243 $conf = new ilConfirmationGUI();
244 $conf->setFormAction($ilCtrl->getFormAction($this));
245 $conf->setHeaderText($lng->txt('book_confirm_cancel'));
246
247 $type = new ilBookingObject($id);
248 $conf->addItem('object_id', $id, $type->getTitle());
249 $conf->setConfirm($lng->txt('book_set_cancel'), 'rsvCancelUser');
250 $conf->setCancel($lng->txt('cancel'), 'back');
251
252 $tpl->setContent($conf->getHTML());
253 }
254
258 public function rsvCancelUser()
259 {
261
262 $id = $this->book_obj_id;
263 $user_id = $this->booked_user;
264
265 if (!$id || !$user_id) {
266 return;
267 }
268
270 $obj = new ilBookingReservation($id);
271 if ($obj->getUserId() != $user_id) {
272 ilUtil::sendFailure($lng->txt('permission_denied'), true);
273 $this->back();
274 }
275
277 $obj->update();
278
279 ilUtil::sendSuccess($lng->txt('settings_saved'), true);
280 $this->back();
281 }
282
286 protected function back()
287 {
288 $this->ctrl->redirect($this, "log");
289 }
290
294 public function rsvConfirmCancel()
295 {
296 $ilCtrl = $this->ctrl;
299 $ilUser = $this->user;
300
301 $ids = $this->getLogReservationIds();
302 if (!is_array($ids) || !sizeof($ids)) {
303 $this->back();
304 }
305
306 $max = array();
307 foreach ($ids as $idx => $id) {
308 if (!is_numeric($id)) {
309 list($obj_id, $user_id, $from, $to) = explode("_", $id);
310
311 $valid_ids = array();
312 foreach (ilBookingObject::getList($this->pool->getId()) as $item) {
313 $valid_ids[$item["booking_object_id"]] = $item["title"];
314 }
315
316 if (($this->checkPermissionBool("write") || $user_id == $ilUser->getId()) &&
317 $from > time() &&
318 in_array($obj_id, array_keys($valid_ids))) {
319 $rsv_ids = ilBookingReservation::getCancelDetails($obj_id, $user_id, $from, $to);
320 if (!sizeof($rsv_ids)) {
321 unset($ids[$idx]);
322 }
323 if (sizeof($rsv_ids) > 1) {
324 $max[$id] = sizeof($rsv_ids);
325 $ids[$idx] = $rsv_ids;
326 } else {
327 // only 1 in group? treat as normal reservation
328 $ids[$idx] = array_shift($rsv_ids);
329 }
330 } else {
331 unset($ids[$idx]);
332 }
333 }
334 }
335
336 if (!is_array($ids) || !sizeof($ids)) {
337 $this->ctrl->redirect($this, 'log');
338 }
339
340 // show form instead
341 if (sizeof($max) && max($max) > 1) {
342 $this->rsvConfirmCancelAggregation($ids);
343 return;
344 }
345
346 $this->tabs_gui->clearTargets();
347 $this->tabs_gui->setBackTarget(
348 $lng->txt("back"),
349 $ilCtrl->getLinkTargetByClass("ilBookingReservationsGUI", "")
350 );
351
352 $this->setHelpId("cancel_booking");
353
354 $conf = new ilConfirmationGUI();
355 $conf->setFormAction($ilCtrl->getFormAction($this, 'rsvCancel'));
356 $conf->setHeaderText($lng->txt('book_confirm_cancel'));
357 $conf->setConfirm($lng->txt('book_set_cancel'), 'rsvCancel');
358 $conf->setCancel($lng->txt('cancel'), 'back');
359
360 foreach ($ids as $id) {
361 $rsv = new ilBookingReservation($id);
362 $obj = new ilBookingObject($rsv->getObjectId());
363
364 $details = $obj->getTitle();
365 if ($this->pool->getScheduleType() != ilObjBookingPool::TYPE_NO_SCHEDULE) {
366 $details .= ", " . ilDatePresentation::formatPeriod(
367 new ilDateTime($rsv->getFrom(), IL_CAL_UNIX),
368 new ilDateTime($rsv->getTo() + 1, IL_CAL_UNIX)
369 );
370 }
371
372 $conf->addItem('rsv_id[]', $id, $details);
373 }
374
375 $tpl->setContent($conf->getHTML());
376 }
377
378
384 public function rsvConfirmCancelAggregation(array $a_ids = null)
385 {
387 $ilCtrl = $this->ctrl;
389
390 $this->tabs_gui->clearTargets();
391 $this->tabs_gui->setBackTarget(
392 $lng->txt("back"),
393 $ilCtrl->getLinkTarget($this, "log")
394 );
395
396 $this->setHelpId("cancel_booking");
397
398 // #13511
399 ilUtil::sendQuestion($lng->txt("book_confirm_cancel"));
400
401 $form = $this->rsvConfirmCancelAggregationForm($a_ids);
402
403 $tpl->setContent($form->getHTML());
404 }
405
412 public function rsvConfirmCancelAggregationForm($a_ids)
413 {
414 $form = new ilPropertyFormGUI();
415 $form->setFormAction($this->ctrl->getFormAction($this, "rsvCancel"));
416 $form->setTitle($this->lng->txt("book_confirm_cancel_aggregation"));
417
419
420 foreach ($a_ids as $idx => $ids) {
421 if (is_array($ids)) {
422 $first = $ids;
423 $first = array_shift($first);
424 } else {
425 $first = $ids;
426 }
427
428 $rsv = new ilBookingReservation($first);
429 $obj = new ilBookingObject($rsv->getObjectId());
430
431 $caption = $obj->getTitle() . ", " . ilDatePresentation::formatPeriod(
432 new ilDateTime($rsv->getFrom(), IL_CAL_UNIX),
433 new ilDateTime($rsv->getTo() + 1, IL_CAL_UNIX)
434 );
435
436 // #17869
437 if (is_array($ids)) {
438 $caption .= " (" . sizeof($ids) . ")";
439 }
440
441 $item = new ilNumberInputGUI($caption, "rsv_id_" . $idx);
442 $item->setRequired(true);
443 $item->setMinValue(0);
444 $item->setSize(4);
445 $form->addItem($item);
446
447 if (is_array($ids)) {
448 $item->setMaxValue(sizeof($ids));
449
450 foreach ($ids as $id) {
451 $hidden = new ilHiddenInputGUI("rsv_aggr[" . $idx . "][]");
452 $hidden->setValue($id);
453 $form->addItem($hidden);
454 }
455 } else {
456 $item->setMaxValue(1);
457
458 $hidden = new ilHiddenInputGUI("rsv_aggr[" . $idx . "]");
459 $hidden->setValue($ids);
460 $form->addItem($hidden);
461 }
462
463 if ($_POST["rsv_id_" . $idx]) {
464 $item->setValue((int) $_POST["rsv_id_" . $idx]);
465 }
466 }
467
468 $form->addCommandButton("rsvCancel", $this->lng->txt("confirm"));
469 $form->addCommandButton("log", $this->lng->txt("cancel"));
470
471 return $form;
472 }
473
477 public function rsvCancel()
478 {
479 $ilUser = $this->user;
482 $ilCtrl = $this->ctrl;
483
484 // simple version of reservation id
485 $ids = $_POST["rsv_id"];
486
487 // aggregated version: determine reservation ids
488 if ($_POST["rsv_aggr"]) {
489 $form = $this->rsvConfirmCancelAggregationForm($_POST["rsv_aggr"]);
490 if (!$form->checkInput()) {
491 $this->tabs_gui->clearTargets();
492 $this->tabs_gui->setBackTarget(
493 $lng->txt("back"),
494 $ilCtrl->getLinkTarget($this, "log")
495 );
496
497 return $tpl->setContent($form->getHTML());
498 }
499
500 $ids = array();
501 foreach ($_POST["rsv_aggr"] as $idx => $aggr_ids) {
502 $max = (int) $_POST["rsv_id_" . $idx];
503 if ($max) {
504 if (!is_array($aggr_ids)) {
505 $ids[] = $aggr_ids;
506 } else {
507 $aggr_ids = array_slice($aggr_ids, 0, $max);
508 $ids = array_merge($ids, $aggr_ids);
509 }
510 }
511 }
512 }
513
514 // for all reservation ids -> set reservation status to cancelled (and remove calendar entry)
515 if ($ids) {
516 foreach ($ids as $id) {
517 $res = new ilBookingReservation($id);
518
519 // either write permission or own booking
520 $cancel_allowed_per_read = ($this->checkPermissionBool("read") && ($res->getUserId() == $ilUser->getId()));
521 $cancel_allowed_per_write = ($this->checkPermissionBool("write"));
522 if (!$cancel_allowed_per_read && !$cancel_allowed_per_write) {
523 ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
524 $this->ctrl->redirect($this, 'log');
525 }
526
528 $res->update();
529
530 if ($this->pool->getScheduleType() != ilObjBookingPool::TYPE_NO_SCHEDULE) {
531 // remove user calendar entry (#11086)
532 $cal_entry_id = $res->getCalendarEntry();
533 if ($cal_entry_id) {
534 $entry = new ilCalendarEntry($cal_entry_id);
535 $entry->delete();
536 }
537 }
538 }
539 }
540
541 ilUtil::sendSuccess($this->lng->txt('settings_saved'));
542 $this->log();
543 return "";
544 }
545
546 public function rsvConfirmDelete()
547 {
548 global $DIC;
549 if (!$this->checkPermissionBool("write")) {
550 ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
551 $this->ctrl->redirect($this, 'log');
552 }
553
554 $this->tabs_gui->clearTargets();
555 $this->tabs_gui->setBackTarget(
556 $this->lng->txt("back"),
557 $this->ctrl->getLinkTarget($this, "log")
558 );
559
560 $conf = new ilConfirmationGUI();
561 $conf->setFormAction($this->ctrl->getFormAction($this, 'rsvDelete'));
562 $conf->setHeaderText($this->lng->txt('book_confirm_delete'));
563 $conf->setConfirm($this->lng->txt('book_set_delete'), 'rsvDelete');
564 $conf->setCancel($this->lng->txt('cancel'), 'log');
565
566 if ($this->pool->getScheduleType() == ilObjBookingPool::TYPE_FIX_SCHEDULE) {
567 list($obj_id, $user_id, $from, $to) = explode("_",
568 $DIC->http()->request()->getQueryParams()['reservation_id']);
569 $ids = ilBookingReservation::getCancelDetails($obj_id, $user_id, $from, $to);
570 $rsv_id = $ids[0];
571 } else {
572 $rsv_id = $DIC->http()->request()->getQueryParams()['reservation_id'];
573 $ids = [$rsv_id];
574 }
575 $rsv = new ilBookingReservation($rsv_id);
576 $obj = new ilBookingObject($rsv->getObjectId());
577
578 $details = sprintf($this->lng->txt('X_reservations_of'), count($ids)) . ' ' . $obj->getTitle();
579 if ($this->pool->getScheduleType() == ilObjBookingPool::TYPE_FIX_SCHEDULE) {
580 $details .= ", " . ilDatePresentation::formatPeriod(
581 new ilDateTime($rsv->getFrom(), IL_CAL_UNIX),
582 new ilDateTime($rsv->getTo() + 1, IL_CAL_UNIX)
583 );
584 }
585
586 $conf->addItem('rsv_ids', implode(',', $ids), $details);
587 $this->tpl->setContent($conf->getHTML());
588 }
589
590 public function rsvDelete()
591 {
592 global $DIC;
593 $get = $DIC->http()->request()->getParsedBody()['rsv_ids'];
594 if ($get) {
595 foreach (explode(',', $get) as $id) {
596 $res = new ilBookingReservation($id);
597 $obj = new ilBookingObject($res->getObjectId());
598 if ($obj->getPoolId() != $this->pool->getId() || !$this->checkPermissionBool("write")) {
599 ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
600 $this->ctrl->redirect($this, 'log');
601 }
602 if ($this->pool->getScheduleType() != ilObjBookingPool::TYPE_NO_SCHEDULE) {
603 $cal_entry_id = $res->getCalendarEntry();
604 if ($cal_entry_id) {
605 include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
606 $entry = new ilCalendarEntry($cal_entry_id);
607 $entry->delete();
608 }
609 }
610 $res->delete();
611 }
612 }
613 ilUtil::sendSuccess($this->lng->txt('reservation_deleted'), true);
614 $this->ctrl->redirect($this, 'log');
615 }
616}
user()
Definition: user.php:4
$_GET["client_id"]
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
Help adapter for booking manager.
a bookable ressource
static lookupPoolId($object_id)
Lookup pool id.
static getList($a_pool_id, $a_title=null)
Get list of booking objects for given type.
static getObjectReservationForUser($a_object_id, $a_user_id, $a_multi=false)
static changeStatus(array $a_ids, $a_status)
Batch update reservation status.
static getCancelDetails($a_obj_id, $a_user_id, $a_from, $a_to)
Get reservation ids from aggregated id for cancellation.
rsvCancel()
(C2.b) Cancel reservations (coming from C2 or C2.a)
rsvConfirmCancelAggregation(array $a_ids=null)
(C2.a) Cancel aggregated booking from reservations screen (with and without schedule) called in (C2)
checkPermissionBool($a_perm)
Check permission.
rsvConfirmCancelAggregationForm($a_ids)
Form being used in (C2.a)
rsvConfirmCancelUser()
(C1) Confirmation screen for canceling booking without schedule from booking objects screen or from p...
getReservationsTable($reservation_id=null)
Get reservationsTable.
getLogReservationIds()
Reservations IDs as currently provided from.
changeStatusObject()
Change status of given reservations.
resetLogFilter()
Reset filter in reservations table gui.
rsvConfirmCancel()
(C2) Confirmation screen for canceling booking from reservations screen (with and without schedule)
__construct(ilObjBookingPool $pool, ilBookingHelpAdapter $help, int $context_obj_id=0)
ilBookingReservationsGUI constructor.
applyLogFilter()
Apply filter from reservations table gui.
Model for a calendar entry.
Confirmation screen class.
static setUseRelativeDates($a_status)
set use relative dates
static formatPeriod(ilDateTime $start, ilDateTime $end, $a_skip_starting_day=false)
Format a period of two date Shows: 14.
@classDescription Date and time handling
Base class for ILIAS Exception handling.
This class represents a hidden form property in a property form.
This class represents a number property in a property form.
Class ilObjBookingPool.
getRefId()
get reference id @access public
This class represents a property form user interface.
static sendQuestion($a_info="", $a_keep=false)
Send Question to Screen.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
help()
Definition: help.php:2
global $ilCtrl
Definition: ilias.php:18
$type
$lng
foreach($_POST as $key=> $value) $res
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
$ilUser
Definition: imgupload.php:18
$DIC
Definition: xapitoken.php:46