ILIAS  release_7 Revision v7.30-3-g800a261c036
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 $this->service = $DIC->bookingManager()->internal();
44 $this->ui = $DIC->ui();
45 $this->toolbar = $DIC->toolbar();
46
47 $this->book_obj_id = (int) $_REQUEST['object_id'];
48
49 $this->context_obj_id = $context_obj_id;
50
51 // user who's reservation is being tackled (e.g. canceled)
52 $this->booked_user = (int) $_REQUEST['bkusr'];
53 if ($this->booked_user == 0) {
54 $this->booked_user = $DIC->user()->getId();
55 }
56 // we get this from the reservation screen
57 $this->reservation_id = ilUtil::stripSlashes($_GET["reservation_id"]);
58
59 $this->ctrl->saveParameter($this, ["object_id", "bkusr"]);
60
61 if ((int) $_REQUEST['object_id'] > 0 && ilBookingObject::lookupPoolId((int) $_REQUEST['object_id']) != $this->pool->getId()) {
62 throw new ilException("Booking Object ID does not match Booking Pool.");
63 }
64 }
65
70 protected function getLogReservationIds()
71 {
72 if (is_array($_POST["mrsv"])) {
73 return $_POST["mrsv"];
74 } elseif ($this->reservation_id > 0) {
75 return array($this->reservation_id);
76 }
77 return [];
78 }
79
80
84 public function executeCommand()
85 {
86 $ctrl = $this->ctrl;
87
88 $next_class = $ctrl->getNextClass($this);
89 $cmd = $ctrl->getCmd("log");
90
91 switch ($next_class) {
92 default:
93 if (in_array($cmd, array("log", "logDetails", "changeStatusObject", "rsvConfirmCancelUser", "rsvCancelUser",
94 "applyLogFilter", "resetLogFilter", "rsvConfirmCancel", "rsvCancel", "back", "rsvConfirmDelete", "rsvDelete", "confirmResetRun", "resetRun"))) {
95 $this->$cmd();
96 }
97 }
98 }
99
103 protected function setHelpId(string $a_id)
104 {
105 $this->help->setHelpId($a_id);
106 }
107
111 public function log()
112 {
115 $table = $this->getReservationsTable();
116 $tpl->setContent($table->getHTML());
117 }
118
125 protected function getReservationsTable($reservation_id = null)
126 {
127 $show_all = ($this->checkPermissionBool('write') || $this->pool->hasPublicLog());
128
129 $filter = null;
130 if ($this->book_obj_id > 0) {
131 $filter["object"] = $this->book_obj_id;
132 }
133 // coming from participants tab to cancel reservations.
134 if ($_GET['user_id']) {
135 $filter["user_id"] = (int) $_GET['user_id'];
136 }
137 $context_filter = ($this->context_obj_id > 0)
138 ? [$this->context_obj_id]
139 : null;
140
142 $this,
143 'log',
144 $this->ref_id,
145 $this->pool->getId(),
146 $show_all,
147 ($this->pool->getScheduleType() == ilObjBookingPool::TYPE_FIX_SCHEDULE),
148 $filter,
149 $reservation_id,
150 $context_filter
151 );
152 }
153
154
155 public function logDetails()
156 {
158
159 $this->tabs_gui->clearTargets();
160 $this->tabs_gui->setBackTarget(
161 $this->lng->txt("back"),
162 $this->ctrl->getLinkTarget($this, "log")
163 );
164
165 $table = $this->getReservationsTable($this->reservation_id);
166 $tpl->setContent($table->getHTML());
167 }
168
172 public function changeStatusObject()
173 {
174 if (!$_POST['reservation_id']) {
175 ilUtil::sendFailure($this->lng->txt('select_one'));
176 $this->log();
177 }
178
179 if ($this->checkPermissionBool('write')) {
180 ilBookingReservation::changeStatus($_POST['reservation_id'], (int) $_POST['tstatus']);
181 }
182
183 ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
184 $this->ctrl->redirect($this, 'log');
185 }
186
190 public function applyLogFilter()
191 {
192 $table = $this->getReservationsTable();
193 $table->resetOffset();
194 $table->writeFilterToSession();
195 $this->log();
196 }
197
201 public function resetLogFilter()
202 {
203 $table = $this->getReservationsTable();
204 $table->resetOffset();
205 $table->resetFilter();
206 $this->log();
207 }
208
215 protected function checkPermissionBool($a_perm)
216 {
217 $ilAccess = $this->access;
218
219 return $ilAccess->checkAccess($a_perm, "", $this->ref_id);
220 }
221
222 //
223 // Cancelation reservations
224 //
225
235 public function rsvConfirmCancelUser()
236 {
237 $ilCtrl = $this->ctrl;
240 $id = $this->book_obj_id;
241 if (!$id) {
242 return;
243 }
244
245 $this->setHelpId("cancel_booking");
246
247 $conf = new ilConfirmationGUI();
248 $conf->setFormAction($ilCtrl->getFormAction($this));
249 $conf->setHeaderText($lng->txt('book_confirm_cancel'));
250
251 $type = new ilBookingObject($id);
252 $conf->addItem('object_id', $id, $type->getTitle());
253 $conf->setConfirm($lng->txt('book_set_cancel'), 'rsvCancelUser');
254 $conf->setCancel($lng->txt('cancel'), 'back');
255
256 $tpl->setContent($conf->getHTML());
257 }
258
262 public function rsvCancelUser()
263 {
265
266 $id = $this->book_obj_id;
267 $user_id = $this->booked_user;
268
269 if (!$id || !$user_id) {
270 return;
271 }
272
274 $obj = new ilBookingReservation($id);
275 if ($obj->getUserId() != $user_id) {
276 ilUtil::sendFailure($lng->txt('permission_denied'), true);
277 $this->back();
278 }
279
281 $obj->update();
282
283 ilUtil::sendSuccess($lng->txt('settings_saved'), true);
284 $this->back();
285 }
286
290 protected function back()
291 {
292 $this->ctrl->redirect($this, "log");
293 }
294
298 public function rsvConfirmCancel()
299 {
300 $ilCtrl = $this->ctrl;
303 $ilUser = $this->user;
304
305 $ids = $this->getLogReservationIds();
306 if (!is_array($ids) || !sizeof($ids)) {
307 $this->back();
308 }
309
310 $max = array();
311 foreach ($ids as $idx => $id) {
312 if (!is_numeric($id)) {
313 list($obj_id, $user_id, $from, $to) = explode("_", $id);
314
315 $valid_ids = array();
316 foreach (ilBookingObject::getList($this->pool->getId()) as $item) {
317 $valid_ids[$item["booking_object_id"]] = $item["title"];
318 }
319
320 if (($this->checkPermissionBool("write") || $user_id == $ilUser->getId()) &&
321 $from > time() &&
322 in_array($obj_id, array_keys($valid_ids))) {
323 $rsv_ids = ilBookingReservation::getCancelDetails($obj_id, $user_id, $from, $to);
324 if (!sizeof($rsv_ids)) {
325 unset($ids[$idx]);
326 }
327 if (sizeof($rsv_ids) > 1) {
328 $max[$id] = sizeof($rsv_ids);
329 $ids[$idx] = $rsv_ids;
330 } else {
331 // only 1 in group? treat as normal reservation
332 $ids[$idx] = array_shift($rsv_ids);
333 }
334 } else {
335 unset($ids[$idx]);
336 }
337 }
338 }
339
340 if (!is_array($ids) || !sizeof($ids)) {
341 $this->ctrl->redirect($this, 'log');
342 }
343
344 // show form instead
345 if (sizeof($max) && max($max) > 1) {
346 $this->rsvConfirmCancelAggregation($ids);
347 return;
348 }
349
350 $this->tabs_gui->clearTargets();
351 $this->tabs_gui->setBackTarget(
352 $lng->txt("back"),
353 $ilCtrl->getLinkTargetByClass("ilBookingReservationsGUI", "")
354 );
355
356 $this->setHelpId("cancel_booking");
357
358 $conf = new ilConfirmationGUI();
359 $conf->setFormAction($ilCtrl->getFormAction($this, 'rsvCancel'));
360 $conf->setHeaderText($lng->txt('book_confirm_cancel'));
361 $conf->setConfirm($lng->txt('book_set_cancel'), 'rsvCancel');
362 $conf->setCancel($lng->txt('cancel'), 'back');
363
364 foreach ($ids as $id) {
365 $rsv = new ilBookingReservation($id);
366 $obj = new ilBookingObject($rsv->getObjectId());
367
368 $details = $obj->getTitle();
369 if ($this->pool->getScheduleType() != ilObjBookingPool::TYPE_NO_SCHEDULE) {
370 $details .= ", " . ilDatePresentation::formatPeriod(
371 new ilDateTime($rsv->getFrom(), IL_CAL_UNIX),
372 new ilDateTime($rsv->getTo() + 1, IL_CAL_UNIX)
373 );
374 }
375
376 $conf->addItem('rsv_id[]', $id, $details);
377 }
378
379 $tpl->setContent($conf->getHTML());
380 }
381
382
388 public function rsvConfirmCancelAggregation(array $a_ids = null)
389 {
391 $ilCtrl = $this->ctrl;
393
394 $this->tabs_gui->clearTargets();
395 $this->tabs_gui->setBackTarget(
396 $lng->txt("back"),
397 $ilCtrl->getLinkTarget($this, "log")
398 );
399
400 $this->setHelpId("cancel_booking");
401
402 // #13511
403 ilUtil::sendQuestion($lng->txt("book_confirm_cancel"));
404
405 $form = $this->rsvConfirmCancelAggregationForm($a_ids);
406
407 $tpl->setContent($form->getHTML());
408 }
409
416 public function rsvConfirmCancelAggregationForm($a_ids)
417 {
418 $form = new ilPropertyFormGUI();
419 $form->setFormAction($this->ctrl->getFormAction($this, "rsvCancel"));
420 $form->setTitle($this->lng->txt("book_confirm_cancel_aggregation"));
421
423
424 foreach ($a_ids as $idx => $ids) {
425 if (is_array($ids)) {
426 $first = $ids;
427 $first = array_shift($first);
428 } else {
429 $first = $ids;
430 }
431
432 $rsv = new ilBookingReservation($first);
433 $obj = new ilBookingObject($rsv->getObjectId());
434
435 $caption = $obj->getTitle() . ", " . ilDatePresentation::formatPeriod(
436 new ilDateTime($rsv->getFrom(), IL_CAL_UNIX),
437 new ilDateTime($rsv->getTo() + 1, IL_CAL_UNIX)
438 );
439
440 // #17869
441 if (is_array($ids)) {
442 $caption .= " (" . sizeof($ids) . ")";
443 }
444
445 $item = new ilNumberInputGUI($caption, "rsv_id_" . $idx);
446 $item->setRequired(true);
447 $item->setMinValue(0);
448 $item->setSize(4);
449 $form->addItem($item);
450
451 if (is_array($ids)) {
452 $item->setMaxValue(sizeof($ids));
453
454 foreach ($ids as $id) {
455 $hidden = new ilHiddenInputGUI("rsv_aggr[" . $idx . "][]");
456 $hidden->setValue($id);
457 $form->addItem($hidden);
458 }
459 } else {
460 $item->setMaxValue(1);
461
462 $hidden = new ilHiddenInputGUI("rsv_aggr[" . $idx . "]");
463 $hidden->setValue($ids);
464 $form->addItem($hidden);
465 }
466
467 if ($_POST["rsv_id_" . $idx]) {
468 $item->setValue((int) $_POST["rsv_id_" . $idx]);
469 }
470 }
471
472 $form->addCommandButton("rsvCancel", $this->lng->txt("confirm"));
473 $form->addCommandButton("log", $this->lng->txt("cancel"));
474
475 return $form;
476 }
477
481 public function rsvCancel()
482 {
483 $ilUser = $this->user;
486 $ilCtrl = $this->ctrl;
487
488 // simple version of reservation id
489 $ids = $_POST["rsv_id"];
490
491 // aggregated version: determine reservation ids
492 if ($_POST["rsv_aggr"]) {
493 $form = $this->rsvConfirmCancelAggregationForm($_POST["rsv_aggr"]);
494 if (!$form->checkInput()) {
495 $this->tabs_gui->clearTargets();
496 $this->tabs_gui->setBackTarget(
497 $lng->txt("back"),
498 $ilCtrl->getLinkTarget($this, "log")
499 );
500
501 return $tpl->setContent($form->getHTML());
502 }
503
504 $ids = array();
505 foreach ($_POST["rsv_aggr"] as $idx => $aggr_ids) {
506 $max = (int) $_POST["rsv_id_" . $idx];
507 if ($max) {
508 if (!is_array($aggr_ids)) {
509 $ids[] = $aggr_ids;
510 } else {
511 $aggr_ids = array_slice($aggr_ids, 0, $max);
512 $ids = array_merge($ids, $aggr_ids);
513 }
514 }
515 }
516 }
517
518 // for all reservation ids -> set reservation status to cancelled (and remove calendar entry)
519 if ($ids) {
520 foreach ($ids as $id) {
521 $res = new ilBookingReservation($id);
522
523 // either write permission or own booking
524 $cancel_allowed_per_read = ($this->checkPermissionBool("read") && ($res->getUserId() == $ilUser->getId()));
525 $cancel_allowed_per_write = ($this->checkPermissionBool("write"));
526 if (!$cancel_allowed_per_read && !$cancel_allowed_per_write) {
527 ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
528 $this->ctrl->redirect($this, 'log');
529 }
530
532 $res->update();
533
534 if ($this->pool->getScheduleType() != ilObjBookingPool::TYPE_NO_SCHEDULE) {
535 // remove user calendar entry (#11086)
536 $cal_entry_id = $res->getCalendarEntry();
537 if ($cal_entry_id) {
538 $entry = new ilCalendarEntry($cal_entry_id);
539 $entry->delete();
540 }
541 }
542 }
543 }
544
545 ilUtil::sendSuccess($this->lng->txt('settings_saved'));
546 $this->log();
547 return "";
548 }
549
550 public function rsvConfirmDelete()
551 {
552 global $DIC;
553 if (!$this->checkPermissionBool("write")) {
554 ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
555 $this->ctrl->redirect($this, 'log');
556 }
557
558 $ids = $this->getLogReservationIds();
559 if (!is_array($ids) || !sizeof($ids)) {
560 $this->back();
561 }
562
563 $this->tabs_gui->clearTargets();
564 $this->tabs_gui->setBackTarget(
565 $this->lng->txt("back"),
566 $this->ctrl->getLinkTarget($this, "log")
567 );
568
569 $conf = new ilConfirmationGUI();
570 $conf->setFormAction($this->ctrl->getFormAction($this, 'rsvDelete'));
571 $conf->setHeaderText($this->lng->txt('book_confirm_delete'));
572 $conf->setConfirm($this->lng->txt('book_set_delete'), 'rsvDelete');
573 $conf->setCancel($this->lng->txt('cancel'), 'log');
574
575 if ($this->pool->getScheduleType() == ilObjBookingPool::TYPE_FIX_SCHEDULE) {
576 foreach ($ids as $idx => $id) {
577 list($obj_id, $user_id, $from, $to) = explode("_", $id);
578 $rsv_ids = ilBookingReservation::getCancelDetails($obj_id, $user_id, $from, $to);
579 $rsv_id = $rsv_ids[0];
580
581 $rsv = new ilBookingReservation($rsv_id);
582 $obj = new ilBookingObject($rsv->getObjectId());
583
584 $details = sprintf($this->lng->txt('X_reservations_of'), count($rsv_ids)) . ' ' . $obj->getTitle();
585 $details .= ", " . ilDatePresentation::formatPeriod(
586 new ilDateTime($rsv->getFrom(), IL_CAL_UNIX),
587 new ilDateTime($rsv->getTo() + 1, IL_CAL_UNIX)
588 );
589 $conf->addItem('mrsv[]', $id, $details);
590 }
591 } else {
592 foreach ($ids as $idx => $rsv_id) {
593 $rsv = new ilBookingReservation($rsv_id);
594 $obj = new ilBookingObject($rsv->getObjectId());
595 $details = sprintf($this->lng->txt('X_reservations_of'), 1) . ' ' . $obj->getTitle();
596 $conf->addItem('mrsv[]', $rsv_id, $details);
597 }
598 }
599 $this->tpl->setContent($conf->getHTML());
600 }
601
602 public function rsvDelete()
603 {
604 global $DIC;
605 $get = $DIC->http()->request()->getParsedBody()['mrsv'];
606 if ($get) {
607 foreach ($get as $id) {
608 if ($this->pool->getScheduleType() == ilObjBookingPool::TYPE_FIX_SCHEDULE) {
609 list($obj_id, $user_id, $from, $to) = explode("_", $id);
610 $rsv_ids = ilBookingReservation::getCancelDetails($obj_id, $user_id, $from, $to);
611 } else {
612 $rsv_ids = [$id];
613 }
614 foreach ($rsv_ids as $rsv_id) {
615 $res = new ilBookingReservation($rsv_id);
616 $obj = new ilBookingObject($res->getObjectId());
617 if ($obj->getPoolId() != $this->pool->getId() || !$this->checkPermissionBool("write")) {
618 ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
619 $this->ctrl->redirect($this, 'log');
620 }
621 if ($this->pool->getScheduleType() != ilObjBookingPool::TYPE_NO_SCHEDULE) {
622 $cal_entry_id = $res->getCalendarEntry();
623 if ($cal_entry_id) {
624 include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
625 $entry = new ilCalendarEntry($cal_entry_id);
626 $entry->delete();
627 }
628 }
629 $res->delete();
630 }
631 }
632 }
633 ilUtil::sendSuccess($this->lng->txt('reservation_deleted'), true);
634 $this->ctrl->redirect($this, 'log');
635 }
636
637 protected function showRerunPreferenceAssignment() : void
638 {
639 if (!$this->checkPermissionBool('write')) {
640 return;
641 }
642 if ($this->pool->getScheduleType() === ilObjBookingPool::TYPE_NO_SCHEDULE_PREFERENCES) {
643 $pref_manager = $this->service->domain()->preferences($this->pool);
644 if ($pref_manager->hasRun()) {
645 $this->toolbar->addComponent($this->ui->factory()->button()->standard(
646 $this->lng->txt("book_rerun_assignments"),
647 $this->ctrl->getLinkTarget($this, "confirmResetRun")
648 ));
649 }
650 }
651 }
652
653 protected function confirmResetRun()
654 {
655 if (!$this->checkPermissionBool('write')) {
656 return;
657 }
658 $this->tabs_gui->activateTab("log");
659 $mess = $this->ui->factory()->messageBox()->confirmation($this->lng->txt("book_rerun_confirmation"))->withButtons(
660 [
661 $this->ui->factory()->button()->standard(
662 $this->lng->txt("book_rerun_assignments"),
663 $this->ctrl->getLinkTarget($this, "resetRun")
664 ),
665 $this->ui->factory()->button()->standard(
666 $this->lng->txt("cancel"),
667 $this->ctrl->getLinkTarget($this, "log")
668 )
669 ]
670 );
671 $this->tpl->setContent(
672 $this->ui->renderer()->render($mess)
673 );
674 }
675
676 protected function resetRun()
677 {
678 if (!$this->checkPermissionBool('write')) {
679 return;
680 }
681 if ($this->pool->getScheduleType() === ilObjBookingPool::TYPE_NO_SCHEDULE_PREFERENCES
682 && $this->access->checkAccess("write", "", $this->pool->getRefId())) {
683 $pref_manager = $this->service->domain()->preferences($this->pool);
684 $repo = $this->service->repo()->getPreferencesRepo();
685 $pref_manager->resetRun();
686 $pref_manager->storeBookings(
687 $repo->getPreferences($this->pool->getId())
688 );
689 }
690 $this->ctrl->redirect($this, "log");
691 }
692
693}
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
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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
global $DIC
Definition: goto.php:24
help()
Definition: help.php:2
$ilUser
Definition: imgupload.php:18
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
$type
$lng
foreach($_POST as $key=> $value) $res
ui()
Definition: ui.php:5