ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilObjBookingPoolGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once "./Services/Object/classes/class.ilObjectGUI.php";
5
18{
23 function __construct($a_data, $a_id, $a_call_by_reference, $a_prepare_output = true)
24 {
25 $this->type = "book";
26 parent::__construct($a_data,$a_id,$a_call_by_reference,$a_prepare_output);
27 $this->lng->loadLanguageModule("book");
28
29 include_once("./Modules/BookingManager/classes/class.ilBookingObject.php");
30 if ((int) $_REQUEST['object_id'] > 0 && ilBookingObject::lookupPoolId((int) $_REQUEST['object_id']) != $this->object->getId())
31 {
32 throw new ilException("Booking Object ID does not match Booking Pool.");
33 }
34 }
35
41 function executeCommand()
42 {
43 global $tpl, $ilTabs, $ilNavigationHistory, $ilUser;
44
45 $next_class = $this->ctrl->getNextClass($this);
46 $cmd = $this->ctrl->getCmd();
47
48 if(!$next_class && $cmd == 'render')
49 {
50 if($ilUser->getId() != ANONYMOUS_USER_ID)
51 {
52 $this->ctrl->setCmdClass('ilBookingObjectGUI');
53 $next_class = $this->ctrl->getNextClass($this);
54 }
55 else
56 {
57 $this->ctrl->redirect($this, "infoscreen");
58 }
59 }
60
61 if(substr($cmd, 0, 4) == 'book')
62 {
63 $next_class = '';
64 }
65
66 $ilNavigationHistory->addItem($this->ref_id,
67 "./goto.php?target=book_".$this->ref_id, "book");
68
69 $this->prepareOutput();
70
71 switch($next_class)
72 {
73 case 'ilpermissiongui':
74 $this->checkPermission('edit_permission');
75 $this->tabs_gui->setTabActive('perm_settings');
76 include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
77 $perm_gui = new ilPermissionGUI($this);
78 $ret =& $this->ctrl->forwardCommand($perm_gui);
79 break;
80
81 case 'ilbookingobjectgui':
82 if (!$this->checkPermissionBool('read') && $this->checkPermissionBool('visible')) {
83 $this->ctrl->redirect($this, "infoScreen");
84 }
85 $this->checkPermission('read');
86 $this->tabs_gui->setTabActive('render');
87 include_once("Modules/BookingManager/classes/class.ilBookingObjectGUI.php");
88 $object_gui = new ilBookingObjectGUI($this);
89 $ret =& $this->ctrl->forwardCommand($object_gui);
90 break;
91
92 case 'ilbookingschedulegui':
93 $this->checkPermission('write');
94 $this->tabs_gui->setTabActive('schedules');
95 include_once("Modules/BookingManager/classes/class.ilBookingScheduleGUI.php");
96 $schedule_gui = new ilBookingScheduleGUI($this);
97 $ret =& $this->ctrl->forwardCommand($schedule_gui);
98 break;
99
100 case 'ilpublicuserprofilegui':
101 $this->checkPermission('read');
102 $ilTabs->clearTargets();
103 include_once("Services/User/classes/class.ilPublicUserProfileGUI.php");
104 $profile = new ilPublicUserProfileGUI((int)$_GET["user_id"]);
105 $profile->setBackUrl($this->ctrl->getLinkTarget($this, 'log'));
106 $ret = $this->ctrl->forwardCommand($profile);
107 $tpl->setContent($ret);
108 break;
109
110 case 'ilinfoscreengui':
111 $this->checkPermission('visible');
112 $this->infoScreen();
113 break;
114
115 case "ilcommonactiondispatchergui":
116 $this->checkPermission('read');
117 include_once("Services/Object/classes/class.ilCommonActionDispatcherGUI.php");
119 $this->ctrl->forwardCommand($gui);
120 break;
121
122 case "ilobjectcopygui":
123 $this->checkPermission('copy');
124 include_once "./Services/Object/classes/class.ilObjectCopyGUI.php";
125 $cp = new ilObjectCopyGUI($this);
126 $cp->setType("book");
127 $this->ctrl->forwardCommand($cp);
128 break;
129
130 case 'ilobjectmetadatagui';
131 $this->checkPermission('write');
132 $this->tabs_gui->setTabActive('meta_data');
133 include_once 'Services/Object/classes/class.ilObjectMetaDataGUI.php';
134 $md_gui = new ilObjectMetaDataGUI($this->object, 'bobj');
135 $this->ctrl->forwardCommand($md_gui);
136 break;
137
138 default:
139 if (!in_array($cmd, ["create", "save", "infoScreen"])) {
140 $this->checkPermission('read');
141 }
142 $cmd = $this->ctrl->getCmd();
143 $cmd .= 'Object';
144 $this->$cmd();
145 break;
146 }
147
148 $this->addHeaderAction();
149 return true;
150 }
151
152 protected function initCreationForms($a_new_type)
153 {
154 $forms = parent::initCreationForms($a_new_type);
155 unset($forms[self::CFORM_IMPORT]);
156
157 return $forms;
158 }
159
160 protected function afterSave(ilObject $a_new_object)
161 {
162 $a_new_object->setOffline(true);
163 $a_new_object->update();
164
165 // always send a message
166 ilUtil::sendSuccess($this->lng->txt("book_pool_added"),true);
167 $this->ctrl->setParameter($this, "ref_id", $a_new_object->getRefId());
168 $this->ctrl->redirect($this, "edit");
169 }
170
171 public function editObject()
172 {
173 // if we have no schedules yet - show info
174 include_once "Modules/BookingManager/classes/class.ilBookingSchedule.php";
175 if($this->object->getScheduleType() != ilObjBookingPool::TYPE_NO_SCHEDULE &&
176 !sizeof(ilBookingSchedule::getList($this->object->getId())))
177 {
178 ilUtil::sendInfo($this->lng->txt("book_schedule_warning_edit"));
179 }
180
181 return parent::editObject();
182 }
183
184 protected function initEditCustomForm(ilPropertyFormGUI $a_form)
185 {
186 $online = new ilCheckboxInputGUI($this->lng->txt("online"), "online");
187 $a_form->addItem($online);
188
189 $type = new ilRadioGroupInputGUI($this->lng->txt("book_schedule_type"), "stype");
190 $type->setRequired(true);
191 $a_form->addItem($type);
192
193 // #14478
194 include_once "Modules/BookingManager/classes/class.ilBookingObject.php";
195 if(sizeof(ilBookingObject::getList($this->object->getId())))
196 {
197 $type->setDisabled(true);
198 }
199
200 $fixed = new ilRadioOption($this->lng->txt("book_schedule_type_fixed"), ilObjBookingPool::TYPE_FIX_SCHEDULE);
201 $fixed->setInfo($this->lng->txt("book_schedule_type_fixed_info"));
202 $type->addOption($fixed);
203
204 $none = new ilRadioOption($this->lng->txt("book_schedule_type_none"), ilObjBookingPool::TYPE_NO_SCHEDULE);
205 $none->setInfo($this->lng->txt("book_schedule_type_none_info"));
206 $type->addOption($none);
207
208 $limit = new ilNumberInputGUI($this->lng->txt("book_overall_limit"), "limit");
209 $limit->setSize(4);
210 $limit->setMinValue(1);
211 $limit->setInfo($this->lng->txt("book_overall_limit_info"));
212 $none->addSubItem($limit);
213
214 $public = new ilCheckboxInputGUI($this->lng->txt("book_public_log"), "public");
215 $public->setInfo($this->lng->txt("book_public_log_info"));
216 $a_form->addItem($public);
217
218 $period = new ilNumberInputGUI($this->lng->txt("book_reservation_filter_period"), "period");
219 $period->setInfo($this->lng->txt("book_reservation_filter_period_info"));
220 $period->setSuffix($this->lng->txt("days"));
221 $period->setSize(3);
222 $period->setMinValue(0);
223 $a_form->addItem($period);
224
225 // additional features
226 $feat = new ilFormSectionHeaderGUI();
227 $feat->setTitle($this->lng->txt('obj_features'));
228 $a_form->addItem($feat);
229
230 }
231
232 protected function getEditFormCustomValues(array &$a_values)
233 {
234 $a_values["online"] = !$this->object->isOffline();
235 $a_values["public"] = $this->object->hasPublicLog();
236 $a_values["stype"] = $this->object->getScheduleType();
237 $a_values["limit"] = $this->object->getOverallLimit();
238 $a_values["period"] = $this->object->getReservationFilterPeriod();
239 }
240
241 protected function updateCustom(ilPropertyFormGUI $a_form)
242 {
243 $this->object->setOffline(!$a_form->getInput('online'));
244 $this->object->setPublicLog($a_form->getInput('public'));
245 $this->object->setScheduleType($a_form->getInput('stype'));
246 $this->object->setOverallLimit($a_form->getInput('limit') ? $a_form->getInput('limit') : null);
247 $this->object->setReservationFilterPeriod(strlen($a_form->getInput('period')) ? (int)$a_form->getInput('period') : null);
248
249 include_once './Services/Container/classes/class.ilContainer.php';
250 include_once './Services/Object/classes/class.ilObjectServiceSettingsGUI.php';
252 $this->object->getId(),
253 $a_form,
255 );
256 }
257
259 {
260 include_once './Services/Container/classes/class.ilContainer.php';
261 include_once './Services/Object/classes/class.ilObjectServiceSettingsGUI.php';
263 $this->object->getId(),
264 $a_form,
266 );
267 }
268
272 function setTabs()
273 {
274 global $ilHelp, $ilUser;
275
276 if (in_array($this->ctrl->getCmd(), array("create", "save")) && !$this->ctrl->getNextClass())
277 {
278 return;
279 }
280
281 $ilHelp->setScreenIdComponent("book");
282
283 if ($this->checkPermissionBool('read'))
284 {
285 if($ilUser->getId() != ANONYMOUS_USER_ID)
286 {
287 $this->tabs_gui->addTab("render",
288 $this->lng->txt("book_booking_types"),
289 $this->ctrl->getLinkTarget($this, "render"));
290 }
291
292 $this->tabs_gui->addTab("info",
293 $this->lng->txt("info_short"),
294 $this->ctrl->getLinkTarget($this, "infoscreen"));
295
296 if($ilUser->getId() != ANONYMOUS_USER_ID || $this->object->hasPublicLog())
297 {
298 $this->tabs_gui->addTab("log",
299 $this->lng->txt("book_log"),
300 $this->ctrl->getLinkTarget($this, "log"));
301 }
302 }
303
304 if ($this->checkPermissionBool('write'))
305 {
306 if($this->object->getScheduleType() != ilObjBookingPool::TYPE_NO_SCHEDULE)
307 {
308 $this->tabs_gui->addTab("schedules",
309 $this->lng->txt("book_schedules"),
310 $this->ctrl->getLinkTargetByClass("ilbookingschedulegui", "render"));
311 }
312
313 $this->tabs_gui->addTab("settings",
314 $this->lng->txt("settings"),
315 $this->ctrl->getLinkTarget($this, "edit"));
316
317 // meta data
318 include_once "Services/Object/classes/class.ilObjectMetaDataGUI.php";
319 $mdgui = new ilObjectMetaDataGUI($this->object, "bobj");
320 $mdtab = $mdgui->getTab();
321 if($mdtab)
322 {
323 $this->tabs_gui->addTarget("meta_data",
324 $mdtab,
325 "",
326 "ilobjectmetadatagui");
327 }
328 }
329
330 if($this->checkPermissionBool('edit_permission'))
331 {
332 $this->tabs_gui->addTab("perm_settings",
333 $this->lng->txt("perm_settings"),
334 $this->ctrl->getLinkTargetByClass("ilpermissiongui", "perm"));
335 }
336 }
337
338 protected function setHelpId($a_id)
339 {
340 global $ilHelp;
341
342 $object_subtype = ($this->object->getScheduleType() == ilObjBookingPool::TYPE_FIX_SCHEDULE)
343 ? '-schedule'
344 : '-nonschedule';
345
346 $ilHelp->setScreenIdComponent('book');
347 $ilHelp->setScreenId('object'.$object_subtype);
348 $ilHelp->setSubScreenId($a_id);
349 }
350
354 function bookObject()
355 {
356 global $tpl;
357
358 $this->tabs_gui->clearTargets();
359 $this->tabs_gui->setBackTarget($this->lng->txt('book_back_to_list'), $this->ctrl->getLinkTarget($this, 'render'));
360
361 $this->setHelpId("book");
362
363 include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
364 $obj = new ilBookingObject((int)$_GET['object_id']);
365
366 $this->lng->loadLanguageModule("dateplaner");
367 $this->ctrl->setParameter($this, 'object_id', $obj->getId());
368
369 if($this->object->getScheduleType() == ilObjBookingPool::TYPE_FIX_SCHEDULE)
370 {
371 include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
372 $schedule = new ilBookingSchedule($obj->getScheduleId());
373
374 $tpl->setContent($this->renderSlots($schedule, array($obj->getId()), $obj->getTitle()));
375 }
376 else
377 {
378 include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
379 $cgui = new ilConfirmationGUI();
380 $cgui->setHeaderText($this->lng->txt("book_confirm_booking_no_schedule"));
381
382 $cgui->setFormAction($this->ctrl->getFormAction($this));
383 $cgui->setCancel($this->lng->txt("cancel"), "render");
384 $cgui->setConfirm($this->lng->txt("confirm"), "confirmedBooking");
385
386 $cgui->addItem("object_id", $obj->getId(), $obj->getTitle());
387
388 $tpl->setContent($cgui->getHTML());
389 }
390 }
391
392 protected function renderSlots(ilBookingSchedule $schedule, array $object_ids, $title)
393 {
394 global $ilUser;
395
396 // fix
397 if(!$schedule->getRaster())
398 {
399 $mytpl = new ilTemplate('tpl.booking_reservation_fix.html', true, true, 'Modules/BookingManager');
400
401 $mytpl->setVariable('FORM_ACTION', $this->ctrl->getFormAction($this));
402 $mytpl->setVariable('TXT_TITLE', $this->lng->txt('book_reservation_title'));
403 $mytpl->setVariable('TXT_INFO', $this->lng->txt('book_reservation_fix_info'));
404 $mytpl->setVariable('TXT_OBJECT', $title);
405 $mytpl->setVariable('TXT_CMD_BOOK', $this->lng->txt('book_confirm_booking'));
406 $mytpl->setVariable('TXT_CMD_CANCEL', $this->lng->txt('cancel'));
407
408 include_once 'Services/Calendar/classes/class.ilCalendarUserSettings.php';
409
410 $user_settings = ilCalendarUserSettings::_getInstanceByUserId($ilUser->getId());
411
412 $morning_aggr = $user_settings->getDayStart();
413 $evening_aggr = $user_settings->getDayEnd();
414 $hours = array();
415 for($i = $morning_aggr;$i <= $evening_aggr;$i++)
416 {
417 switch($user_settings->getTimeFormat())
418 {
420 if ($morning_aggr > 0 && $i == $morning_aggr)
421 {
422 $hours[$i] = sprintf('%02d:00',0)."-";
423 }
424 $hours[$i].= sprintf('%02d:00',$i);
425 if ($evening_aggr < 23 && $i == $evening_aggr)
426 {
427 $hours[$i].= "-".sprintf('%02d:00',23);
428 }
429 break;
430
432 if ($morning_aggr > 0 && $i == $morning_aggr)
433 {
434 $hours[$i] = date('h a',mktime(0,0,0,1,1,2000))."-";
435 }
436 $hours[$i].= date('h a',mktime($i,0,0,1,1,2000));
437 if ($evening_aggr < 23 && $i == $evening_aggr)
438 {
439 $hours[$i].= "-".date('h a',mktime(23,0,0,1,1,2000));
440 }
441 break;
442 }
443 }
444
445 if(isset($_GET['seed']))
446 {
447 $find_first_open = false;
448 $seed = new ilDate($_GET['seed'], IL_CAL_DATE);
449 }
450 else
451 {
452 $find_first_open = true;
453 $seed = isset($_GET['sseed'])
454 ? new ilDate($_GET['sseed'], IL_CAL_DATE)
455 : new ilDate(time(), IL_CAL_UNIX);
456 }
457
458 include_once 'Services/Calendar/classes/class.ilCalendarUtil.php';
459 include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
460 $week_start = $user_settings->getWeekStart();
461
462 if(!$find_first_open)
463 {
464 $dates = array();
465 $this->buildDatesBySchedule($week_start, $hours, $schedule, $object_ids, $seed, $dates);
466 }
467 else
468 {
469 $dates = array();
470
471 //loop for 1 week
472 $has_open_slot = $this->buildDatesBySchedule($week_start, $hours, $schedule, $object_ids, $seed, $dates);
473
474 // find first open slot
475 if(!$has_open_slot)
476 {
477 // 1 year is limit for search
478 $limit = clone($seed);
479 $limit->increment(ilDate::YEAR, 1);
480 $limit = $limit->get(IL_CAL_UNIX);
481
482 while(!$has_open_slot && $seed->get(IL_CAL_UNIX) < $limit)
483 {
484 $seed->increment(ilDate::WEEK, 1);
485
486 $dates = array();
487 $has_open_slot = $this->buildDatesBySchedule($week_start, $hours, $schedule, $object_ids, $seed, $dates);
488 }
489 }
490 }
491
492 include_once 'Services/Calendar/classes/class.ilCalendarHeaderNavigationGUI.php';
493 $navigation = new ilCalendarHeaderNavigationGUI($this,$seed,ilDateTime::WEEK,'book');
494 $mytpl->setVariable('NAVIGATION', $navigation->getHTML());
495
496 foreach(ilCalendarUtil::_buildWeekDayList($seed,$week_start)->get() as $date)
497 {
498 $date_info = $date->get(IL_CAL_FKT_GETDATE,'','UTC');
499
500 $mytpl->setCurrentBlock('weekdays');
501 $mytpl->setVariable('TXT_WEEKDAY', ilCalendarUtil:: _numericDayToString($date_info['wday']));
502 $mytpl->setVariable('TXT_DATE', $date_info['mday'].' '.ilCalendarUtil:: _numericMonthToString($date_info['mon']));
503 $mytpl->parseCurrentBlock();
504 }
505
506 include_once 'Services/Calendar/classes/class.ilCalendarAppointmentColors.php';
507 include_once 'Services/Calendar/classes/class.ilCalendarUtil.php';
508 $color = array();
510 for($loop = 0; $loop < 7; $loop++)
511 {
512 $col = $all[$loop];
514 $color[$loop+1] = 'border-bottom: 1px solid '.$col.'; background-color: '.$col.'; color: '.$fnt;
515 }
516
517 $counter = 0;
518 foreach($dates as $hour => $days)
519 {
520 $caption = $days;
521 $caption = array_shift($caption);
522
523 for($loop = 1; $loop < 8; $loop++)
524 {
525 if(!isset($days[$loop]))
526 {
527 $mytpl->setCurrentBlock('dates');
528 $mytpl->setVariable('DUMMY', '&nbsp;');
529 $mytpl->parseCurrentBlock();
530 }
531 else
532 {
533 if(isset($days[$loop]['captions']))
534 {
535 foreach($days[$loop]['captions'] as $slot_id => $slot_caption)
536 {
537 $mytpl->setCurrentBlock('choice');
538 $mytpl->setVariable('TXT_DATE', $slot_caption);
539 $mytpl->setVariable('VALUE_DATE', $slot_id);
540 $mytpl->setVariable('DATE_COLOR', $color[$loop]);
541 $mytpl->setVariable('TXT_AVAILABLE',
542 sprintf($this->lng->txt('book_reservation_available'),
543 $days[$loop]['available'][$slot_id]));
544 $mytpl->parseCurrentBlock();
545 }
546
547 $mytpl->setCurrentBlock('dates');
548 $mytpl->setVariable('DUMMY', '');
549 $mytpl->parseCurrentBlock();
550 }
551 else if(isset($days[$loop]['in_slot']))
552 {
553 $mytpl->setCurrentBlock('dates');
554 $mytpl->setVariable('DATE_COLOR', $color[$loop]);
555 $mytpl->parseCurrentBlock();
556 }
557 else
558 {
559 $mytpl->setCurrentBlock('dates');
560 $mytpl->setVariable('DUMMY', '&nbsp;');
561 $mytpl->parseCurrentBlock();
562 }
563 }
564 }
565
566 $mytpl->setCurrentBlock('slots');
567 $mytpl->setVariable('TXT_HOUR', $caption);
568 if($counter%2)
569 {
570 $mytpl->setVariable('CSS_ROW', 'tblrow1');
571 }
572 else
573 {
574 $mytpl->setVariable('CSS_ROW', 'tblrow2');
575 }
576 $mytpl->parseCurrentBlock();
577
578 $counter++;
579 }
580 }
581 // flexible
582 else
583 {
584 // :TODO: inactive for now
585 }
586
587 return $mytpl->get();
588 }
589
590 protected function buildDatesBySchedule($week_start, array $hours, $schedule, array $object_ids, $seed, array &$dates)
591 {
592 global $ilUser;
593
594 include_once 'Services/Calendar/classes/class.ilCalendarUserSettings.php';
595 $user_settings = ilCalendarUserSettings::_getInstanceByUserId($ilUser->getId());
596
597 $map = array('mo', 'tu', 'we', 'th', 'fr', 'sa', 'su');
598 $definition = $schedule->getDefinition();
599
600 $av_from = ($schedule->getAvailabilityFrom() && !$schedule->getAvailabilityFrom()->isNull())
601 ? $schedule->getAvailabilityFrom()->get(IL_CAL_DATE)
602 : null;
603 $av_to = ($schedule->getAvailabilityTo() && !$schedule->getAvailabilityTo()->isNull())
604 ? $schedule->getAvailabilityTo()->get(IL_CAL_DATE)
605 : null;
606
607 $has_open_slot = false;
608 foreach(ilCalendarUtil::_buildWeekDayList($seed,$week_start)->get() as $date)
609 {
610 $date_info = $date->get(IL_CAL_FKT_GETDATE,'','UTC');
611
612 #24045 and #24936
613 if($av_from || $av_to)
614 {
615 $today = $date->get(IL_CAL_DATE);
616
617 if ($av_from && $av_from > $today)
618 {
619 continue;
620 }
621
622 if($av_to && $av_to < $today)
623 {
624 continue;
625 }
626 }
627
628 $slots = array();
629 if(isset($definition[$map[$date_info['isoday']-1]]))
630 {
631 $slots = array();
632 foreach($definition[$map[$date_info['isoday']-1]] as $slot)
633 {
634 $slot = explode('-', $slot);
635 $slots[] = array('from'=>str_replace(':', '', $slot[0]),
636 'to'=>str_replace(':', '', $slot[1]));
637 }
638 }
639
640 $last = array_pop(array_keys($hours));
641 $slot_captions = array();
642 foreach($hours as $hour => $period)
643 {
644 $dates[$hour][0] = $period;
645
646 $period = explode("-", $period);
647
648 // #13738
649 if($user_settings->getTimeFormat() == ilCalendarSettings::TIME_FORMAT_12)
650 {
651 $period[0] = date("H", strtotime($period[0]));
652 if(sizeof($period) == 2)
653 {
654 $period[1] = date("H", strtotime($period[1]));
655 }
656 }
657
658 if(sizeof($period) == 1)
659 {
660 $period_from = (int)substr($period[0], 0, 2)."00";
661 $period_to = (int)substr($period[0], 0, 2)."59";
662 }
663 else
664 {
665 $period_from = (int)substr($period[0], 0, 2)."00";
666 $period_to = (int)substr($period[1], 0, 2)."59";
667 }
668
669 $column = $date_info['isoday'];
670 if(!$week_start)
671 {
672 if($column < 7)
673 {
674 $column++;
675 }
676 else
677 {
678 $column = 1;
679 }
680 }
681
682 if(sizeof($slots))
683 {
684 $in = false;
685 foreach($slots as $slot)
686 {
687 $slot_from = mktime(substr($slot['from'], 0, 2), substr($slot['from'], 2, 2), 0, $date_info["mon"], $date_info["mday"], $date_info["year"]);
688 $slot_to = mktime(substr($slot['to'], 0, 2), substr($slot['to'], 2, 2), 0, $date_info["mon"], $date_info["mday"], $date_info["year"]);
689
690 // always single object, we can sum up
691 $nr_available = (array)ilBookingReservation::getAvailableObject($object_ids, $slot_from, $slot_to-1, false, true);
692
693 // any objects available?
694 if(!array_sum($nr_available))
695 {
696 continue;
697 }
698
699 // check deadline
700 if($schedule->getDeadline() >= 0)
701 {
702 // 0-n hours before slots begins
703 if($slot_from < (time()+$schedule->getDeadline()*60*60))
704 {
705 continue;
706 }
707 }
708 else
709 {
710 // running slots can be booked, only ended slots are invalid
711 if($slot_to < time())
712 {
713 continue;
714 }
715 }
716
717 // is slot active in current hour?
718 if((int)$slot['from'] < $period_to && (int)$slot['to'] > $period_from)
719 {
720 $from = ilDatePresentation::formatDate(new ilDateTime($slot_from, IL_CAL_UNIX));
721 $from = array_pop(explode(' ', $from));
723 $to = array_pop(explode(' ', $to));
724
725 // show caption (first hour) of slot
726 $id = $slot_from.'_'.$slot_to;
727 if(!in_array($id, $slot_captions))
728 {
729 $dates[$hour][$column]['captions'][$id] = $from.'-'.$to;
730 $dates[$hour][$column]['available'][$id] = array_sum($nr_available);
731 $slot_captions[] = $id;
732 }
733
734 $in = true;
735 }
736 }
737 // (any) active slot
738 if($in)
739 {
740 $has_open_slot = true;
741 $dates[$hour][$column]['in_slot'] = $in;
742 }
743 }
744 }
745 }
746
747 return $has_open_slot;
748 }
749
754 {
755 global $ilUser;
756
757 include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
758 include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
759
760 $success = false;
761 $rsv_ids = array();
762
763 if($this->object->getScheduleType() == ilObjBookingPool::TYPE_NO_SCHEDULE)
764 {
765 if($_POST['object_id'])
766 {
767 $object_id = $_POST['object_id'];
768 if($object_id)
769 {
771 !ilBookingReservation::getObjectReservationForUser($object_id, $ilUser->getId())) // #18304
772 {
773 $rsv_ids[] = $this->processBooking($object_id);
774 $success = $object_id;
775 }
776 else
777 {
778 // #11852
779 ilUtil::sendFailure($this->lng->txt('book_reservation_failed_overbooked'), true);
780 $this->ctrl->redirect($this, 'render');
781 }
782 }
783 }
784 }
785 else
786 {
787 if(!isset($_POST['date']))
788 {
789 ilUtil::sendFailure($this->lng->txt('select_one'));
790 return $this->bookObject();
791 }
792
793 // single object reservation(s)
794 if(isset($_GET['object_id']))
795 {
796 $confirm = array();
797
798 $object_id = (int)$_GET['object_id'];
799 if($object_id)
800 {
801 $group_id = null;
802 $nr = ilBookingObject::getNrOfItemsForObjects(array($object_id));
803 // needed for recurrence
804 if(true) // if($nr[$object_id] > 1 || sizeof($_POST['date']) > 1)
805 {
807 }
808 foreach($_POST['date'] as $date)
809 {
810 $fromto = explode('_', $date);
811 $fromto[1]--;
812
813 $counter = ilBookingReservation::getAvailableObject(array($object_id), $fromto[0], $fromto[1], false, true);
814 $counter = $counter[$object_id];
815 if($counter)
816 {
817 // needed for recurrence
818 if(true) // if($counter > 1)
819 {
820 $confirm[$object_id."_".$fromto[0]."_".($fromto[1]+1)] = $counter;
821 }
822 else
823 {
824 $rsv_ids[] = $this->processBooking($object_id, $fromto[0], $fromto[1], $group_id);
825 $success = $object_id;
826 }
827 }
828 }
829 }
830
831 if(sizeof($confirm))
832 {
833 return $this->confirmBookingNumbers($confirm, $group_id);
834 }
835 }
836 /*
837 // group object reservation(s)
838 else
839 {
840 $all_object_ids = array();
841 foreach(ilBookingObject::getList((int)$_GET['type_id']) as $item)
842 {
843 $all_object_ids[] = $item['booking_object_id'];
844 }
845
846 $possible_objects = $counter = array();
847 sort($_POST['date']);
848 foreach($_POST['date'] as $date)
849 {
850 $fromto = explode('_', $date);
851 $fromto[1]--;
852 $possible_objects[$date] = ilBookingReservation::getAvailableObject($all_object_ids, $fromto[0], $fromto[1], false);
853 foreach($possible_objects[$date] as $obj_id)
854 {
855 $counter[$obj_id]++;
856 }
857 }
858
859 if(max($counter))
860 {
861 // we prefer the objects which are available for most slots
862 arsort($counter);
863 $counter = array_keys($counter);
864
865 // book each slot
866 foreach($possible_objects as $date => $available_ids)
867 {
868 $fromto = explode('_', $date);
869 $fromto[1]--;
870
871 // find "best" object for slot
872 foreach($counter as $best_object_id)
873 {
874 if(in_array($best_object_id, $available_ids))
875 {
876 $object_id = $best_object_id;
877 break;
878 }
879 }
880 $this->processBooking($object_id, $fromto[0], $fromto[1]);
881 $success = true;
882 }
883 }
884 }
885 */
886 }
887
888 if($success)
889 {
890 $this->handleBookingSuccess($success, $rsv_ids);
891 }
892 else
893 {
894 ilUtil::sendFailure($this->lng->txt('book_reservation_failed'), true);
895 $this->ctrl->redirect($this, 'book');
896 }
897 }
898
899 protected function handleBookingSuccess($a_obj_id, array $a_rsv_ids = null)
900 {
901 ilUtil::sendSuccess($this->lng->txt('book_reservation_confirmed'), true);
902
903 // show post booking information?
904 include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
905 $obj = new ilBookingObject($a_obj_id);
906 $pfile = $obj->getPostFile();
907 $ptext = $obj->getPostText();
908 if(trim($ptext) || $pfile)
909 {
910 if(sizeof($a_rsv_ids))
911 {
912 $this->ctrl->setParameterByClass('ilbookingobjectgui', 'rsv_ids', implode(";", $a_rsv_ids));
913 }
914 $this->ctrl->setParameterByClass('ilbookingobjectgui', 'object_id', $obj->getId());
915 $this->ctrl->redirectByClass('ilbookingobjectgui', 'displayPostInfo');
916 }
917 else
918 {
919 $this->ctrl->redirect($this, 'render');
920 }
921 }
922
923 protected function initBookingNumbersForm(array $a_objects_counter, $a_group_id, $a_reload = false)
924 {
925 include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
926 $form = new ilPropertyFormGUI();
927 $form->setFormAction($this->ctrl->getFormAction($this, "confirmedBooking"));
928 $form->setTitle($this->lng->txt("book_confirm_booking_schedule_number_of_objects"));
929 $form->setDescription($this->lng->txt("book_confirm_booking_schedule_number_of_objects_info"));
930
931 include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
932 $section = false;
933 $min_date = null;
934 foreach($a_objects_counter as $id => $counter)
935 {
936 $id = explode("_", $id);
937 $book_id = $id[0]."_".$id[1]."_".$id[2]."_".$counter;
938
939 $obj = new ilBookingObject($id[0]);
940
941 if(!$section)
942 {
944 $section->setTitle($obj->getTitle());
945 $form->addItem($section);
946
947 $section = true;
948 }
949
950 $period = /* $this->lng->txt("book_period").": ". */
952 new ilDateTime($id[1], IL_CAL_UNIX),
953 new ilDateTime($id[2], IL_CAL_UNIX));
954
955 $nr_field = new ilNumberInputGUI($period, "conf_nr__".$book_id);
956 $nr_field->setValue(1);
957 $nr_field->setSize(3);
958 $nr_field->setMaxValue($counter);
959 $nr_field->setMinValue($counter ? 1 : 0);
960 $nr_field->setRequired(true);
961 $form->addItem($nr_field);
962
963 if(!$min_date || $id[1] < $min_date)
964 {
965 $min_date = $id[1];
966 }
967 }
968
969 // recurrence
970 $this->lng->loadLanguageModule("dateplaner");
971 $rec_mode = new ilSelectInputGUI($this->lng->txt("cal_recurrences"), "recm");
972 $rec_mode->setRequired(true);
973 $rec_mode->setOptions(array(
974 "-1" => $this->lng->txt("cal_no_recurrence"),
975 1 => $this->lng->txt("cal_weekly"),
976 2 => $this->lng->txt("r_14"),
977 4 => $this->lng->txt("r_4_weeks")
978 ));
979 $form->addItem($rec_mode);
980
981 $rec_end = new ilDateTimeInputGUI($this->lng->txt("cal_repeat_until"), "rece");
982 $rec_end->setRequired(true);
983 $rec_mode->addSubItem($rec_end);
984
985 if(!$a_reload)
986 {
987 // show date only if active recurrence
988 $rec_mode->setHideSubForm(true, '>= 1');
989
990 if($min_date)
991 {
992 $rec_end->setDate(new ilDateTime($min_date, IL_CAL_UNIX));
993 }
994 }
995 else
996 {
997 // recurrence may not be changed on reload
998 $rec_mode->setDisabled(true);
999 $rec_end->setDisabled(true);
1000 }
1001
1002 if($a_group_id)
1003 {
1004 $grp = new ilHiddenInputGUI("grp_id");
1005 $grp->setValue($a_group_id);
1006 $form->addItem($grp);
1007 }
1008
1009 $form->addCommandButton("confirmedBookingNumbers", $this->lng->txt("confirm"));
1010 $form->addCommandButton("render", $this->lng->txt("cancel"));
1011
1012 return $form;
1013 }
1014
1015 function confirmBookingNumbers(array $a_objects_counter, $a_group_id, ilPropertyFormGUI $a_form = null)
1016 {
1017 global $tpl;
1018
1019 $this->tabs_gui->clearTargets();
1020 $this->tabs_gui->setBackTarget($this->lng->txt('book_back_to_list'), $this->ctrl->getLinkTarget($this, 'render'));
1021
1022 if(!$a_form)
1023 {
1024 $a_form = $this->initBookingNumbersForm($a_objects_counter, $a_group_id);
1025 }
1026
1027 $tpl->setContent($a_form->getHTML());
1028 }
1029
1030 protected function addDaysDate($a_date, $a_days)
1031 {
1032 $date = date_parse($a_date);
1033 $stamp = mktime(0, 0, 1, $date["month"], $date["day"]+$a_days, $date["year"]);
1034 return date("Y-m-d", $stamp);
1035 }
1036
1037 protected function addDaysStamp($a_stamp, $a_days)
1038 {
1039 $date = getDate($a_stamp);
1040 return mktime($date["hours"], $date["minutes"], $date["seconds"],
1041 $date["mon"], $date["mday"]+$a_days, $date["year"]);
1042 }
1043
1045 {
1046 include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
1047 include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
1048
1049 // convert post data to initial form config
1050 $counter = array();
1051 $current_first = $obj_id = null;
1052 foreach(array_keys($_POST) as $id)
1053 {
1054 if(substr($id, 0, 9) == "conf_nr__")
1055 {
1056 $id = explode("_", substr($id, 9));
1057 $counter[$id[0]."_".$id[1]."_".$id[2]] = (int)$id[3];
1058 if(!$current_first)
1059 {
1060 $current_first = date("Y-m-d", $id[1]);
1061 }
1062 }
1063 }
1064
1065 // recurrence
1066
1067 // checkInput() has not been called yet, so we have to improvise
1068 include_once 'Services/Calendar/classes/class.ilCalendarUtil.php';
1069 $end = ilCalendarUtil::parseIncomingDate($_POST["rece"], null);
1070
1071 if((int)$_POST["recm"] > 0 && $end && $current_first)
1072 {
1073 ksort($counter);
1074 $end = $end->get(IL_CAL_DATE);
1075 $cycle = (int)$_POST["recm"]*7;
1076 $cut = 0;
1077 $org = $counter;
1078 while($cut < 1000 && $this->addDaysDate($current_first, $cycle) <= $end)
1079 {
1080 $cut++;
1081 $current_first = null;
1082 foreach($org as $item_id => $max)
1083 {
1084 $parts = explode("_", $item_id);
1085 $obj_id = $parts[0];
1086
1087 $from = $this->addDaysStamp($parts[1], $cycle*$cut);
1088 $to = $this->addDaysStamp($parts[2], $cycle*$cut);
1089
1090 $new_item_id = $obj_id."_".$from."_".$to;
1091
1092 // form reload because of validation errors
1093 if(!isset($counter[$new_item_id]) && date("Y-m-d", $to) <= $end)
1094 {
1095 // get max available for added dates
1096 $new_max = ilBookingReservation::getAvailableObject(array($obj_id), $from, $to-1, false, true);
1097 $new_max = (int)$new_max[$obj_id];
1098
1099 $counter[$new_item_id] = $new_max;
1100
1101 if(!$current_first)
1102 {
1103 $current_first = date("Y-m-d", $from);
1104 }
1105
1106 // clone input
1107 $_POST["conf_nr__".$new_item_id."_".$new_max] = $_POST["conf_nr__".$item_id."_".$max];
1108 }
1109 }
1110 }
1111 }
1112
1113 $group_id = $_POST["grp_id"];
1114
1115 $form = $this->initBookingNumbersForm($counter, $group_id, true);
1116 if($form->checkInput())
1117 {
1118 $success = false;
1119 $rsv_ids = array();
1120 foreach($counter as $id => $all_nr)
1121 {
1122 $book_nr = $form->getInput("conf_nr__".$id."_".$all_nr);
1123 $parts = explode("_", $id);
1124 $obj_id = $parts[0];
1125 $from = $parts[1];
1126 $to = $parts[2]-1;
1127
1128 // get currently available slots
1129 $counter = ilBookingReservation::getAvailableObject(array($obj_id), $from, $to, false, true);
1131 if($counter)
1132 {
1133 // we can only book what is left
1134 $book_nr = min($book_nr, $counter);
1135 for($loop = 0; $loop < $book_nr; $loop++)
1136 {
1137 $rsv_ids[] = $this->processBooking($obj_id, $from, $to, $group_id);
1138 $success = $obj_id;
1139 }
1140 }
1141 }
1142 if($success)
1143 {
1144 $this->handleBookingSuccess($success, $rsv_ids);
1145 }
1146 else
1147 {
1148 ilUtil::sendFailure($this->lng->txt('book_reservation_failed'), true);
1149 $this->ctrl->redirect($this, 'render');
1150 }
1151 }
1152 else
1153 {
1154 // ilDateTimeInputGUI does NOT add hidden values on disabled!
1155
1156 $rece_array = explode(".", $_POST['rece']);
1157
1158 $rece_day = str_pad($rece_array[0], 2, "0", STR_PAD_LEFT);
1159 $rece_month = str_pad($rece_array[1], 2, "0", STR_PAD_LEFT);
1160 $rece_year = $rece_array[2];
1161
1162 // ilDateTimeInputGUI will choke on POST array format
1163 $_POST["rece"] = null;
1164
1165 $form->setValuesByPost();
1166
1167 $rece_date = new ilDate($rece_year."-".$rece_month."-".$rece_day, IL_CAL_DATE);
1168
1169 $form->getItemByPostVar("rece")->setDate($rece_date);
1170 $form->getItemByPostVar("recm")->setHideSubForm($_POST["recm"] < 1);
1171
1172 $hidden_date = new ilHiddenInputGUI("rece");
1173 $hidden_date->setValue($rece_date);
1174 $form->addItem($hidden_date);
1175
1176 return $this->confirmBookingNumbers($counter, $group_id, $form);
1177 }
1178 }
1179
1189 function processBooking($a_object_id, $a_from = null, $a_to = null, $a_group_id = null)
1190 {
1191 global $ilUser;
1192
1193 // #11995
1194 $this->checkPermission('read');
1195
1196 include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
1197 $reservation = new ilBookingReservation();
1198 $reservation->setObjectId($a_object_id);
1199 $reservation->setUserId($ilUser->getID());
1200 $reservation->setFrom($a_from);
1201 $reservation->setTo($a_to);
1202 $reservation->setGroupId($a_group_id);
1203 $reservation->save();
1204
1205 if($a_from)
1206 {
1207 $this->lng->loadLanguageModule('dateplaner');
1208 include_once 'Services/Calendar/classes/class.ilCalendarUtil.php';
1209 include_once 'Services/Calendar/classes/class.ilCalendarCategory.php';
1210 $def_cat = ilCalendarUtil::initDefaultCalendarByType(ilCalendarCategory::TYPE_BOOK,$ilUser->getId(),$this->lng->txt('cal_ch_personal_book'),true);
1211
1212 include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
1213 $object = new ilBookingObject($a_object_id);
1214
1215 include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
1216 $entry = new ilCalendarEntry;
1217 $entry->setStart(new ilDateTime($a_from, IL_CAL_UNIX));
1218 $entry->setEnd(new ilDateTime($a_to, IL_CAL_UNIX));
1219 $entry->setTitle($this->lng->txt('book_cal_entry').' '.$object->getTitle());
1220 $entry->setContextId($reservation->getId());
1221 $entry->save();
1222
1223 include_once 'Services/Calendar/classes/class.ilCalendarCategoryAssignments.php';
1224 $assignment = new ilCalendarCategoryAssignments($entry->getEntryId());
1225 $assignment->addAssignment($def_cat->getCategoryId());
1226 }
1227
1228 return $reservation->getId();
1229 }
1230
1234 function logObject()
1235 {
1236 global $tpl;
1237
1238 $this->tabs_gui->setTabActive('log');
1239
1240 $show_all = ($this->checkPermissionBool('write') || $this->object->hasPublicLog());
1241
1242 $filter = null;
1243 if($_GET["object_id"])
1244 {
1245 $filter["object"] = (int)$_GET["object_id"];
1246 }
1247
1248 include_once 'Modules/BookingManager/classes/class.ilBookingReservationsTableGUI.php';
1249 $table = new ilBookingReservationsTableGUI($this, 'log', $this->ref_id,
1250 $this->object->getId(), $show_all,
1251 ($this->object->getScheduleType() != ilObjBookingPool::TYPE_NO_SCHEDULE),
1252 $filter);
1253 $tpl->setContent($table->getHTML());
1254 }
1255
1257 {
1258 global $tpl;
1259
1260 $this->tabs_gui->clearTargets();
1261 $this->tabs_gui->setBackTarget($this->lng->txt("back"),
1262 $this->ctrl->getLinkTarget($this, "log"));
1263
1264 $show_all = ($this->checkPermissionBool('write') || $this->object->hasPublicLog());
1265
1266 $filter = null;
1267 if($_GET["object_id"])
1268 {
1269 $filter["object"] = (int)$_GET["object_id"];
1270 }
1271
1272 include_once 'Modules/BookingManager/classes/class.ilBookingReservationsTableGUI.php';
1273 $table = new ilBookingReservationsTableGUI($this, 'log', $this->ref_id,
1274 $this->object->getId(), $show_all,
1275 ($this->object->getScheduleType() != ilObjBookingPool::TYPE_NO_SCHEDULE),
1276 $filter, $_GET["reservation_id"]);
1277 $tpl->setContent($table->getHTML());
1278 }
1279
1284 {
1285 $this->tabs_gui->setTabActive('log');
1286
1287 if(!$_POST['reservation_id'])
1288 {
1289 ilUtil::sendFailure($this->lng->txt('select_one'));
1290 return $this->logObject();
1291 }
1292
1293 if ($this->checkPermissionBool('write'))
1294 {
1295 include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
1296 ilBookingReservation::changeStatus($_POST['reservation_id'], (int)$_POST['tstatus']);
1297 }
1298
1299 ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
1300 return $this->ctrl->redirect($this, 'log');
1301 }
1302
1307 {
1308 $show_all = ($this->checkPermissionBool('write') || $this->object->hasPublicLog());
1309
1310 include_once 'Modules/BookingManager/classes/class.ilBookingReservationsTableGUI.php';
1311 $table = new ilBookingReservationsTableGUI($this, 'log', $this->ref_id,
1312 $this->object->getId(), $show_all,
1313 ($this->object->getScheduleType() != ilObjBookingPool::TYPE_NO_SCHEDULE));
1314 $table->resetOffset();
1315 $table->writeFilterToSession();
1316 $this->logObject();
1317 }
1318
1323 {
1324 $show_all = ($this->checkPermissionBool('write') || $this->object->hasPublicLog());
1325
1326 include_once 'Modules/BookingManager/classes/class.ilBookingReservationsTableGUI.php';
1327 $table = new ilBookingReservationsTableGUI($this, 'log', $this->ref_id,
1328 $this->object->getId(), $show_all,
1329 ($this->object->getScheduleType() != ilObjBookingPool::TYPE_NO_SCHEDULE));
1330 $table->resetOffset();
1331 $table->resetFilter();
1332 $this->logObject();
1333 }
1334
1335 public static function _goto($a_target)
1336 {
1337 global $ilAccess, $lng;
1338
1339 if ($ilAccess->checkAccess("read", "", $a_target))
1340 {
1341 ilObjectGUI::_gotoRepositoryNode($a_target, "render");
1342 }
1343 else if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID))
1344 {
1345 ilUtil::sendFailure(sprintf($lng->txt("msg_no_perm_read_item"),
1348 }
1349 }
1350
1357 {
1358 $this->ctrl->setCmd("showSummary");
1359 $this->ctrl->setCmdClass("ilinfoscreengui");
1360 $this->infoScreen();
1361 }
1362
1363 function infoScreen()
1364 {
1365 global $ilCtrl;
1366
1367 $this->tabs_gui->setTabActive('info');
1368
1369 $this->checkPermission("visible");
1370
1371 include_once("./Services/InfoScreen/classes/class.ilInfoScreenGUI.php");
1372 $info = new ilInfoScreenGUI($this);
1373
1374 $info->enablePrivateNotes();
1375
1376 if ($this->checkPermissionBool("read"))
1377 {
1378 $info->enableNews();
1379 }
1380
1381 // no news editing for files, just notifications
1382 $info->enableNewsEditing(false);
1383 if ($this->checkPermissionBool("write"))
1384 {
1385 $news_set = new ilSetting("news");
1386 $enable_internal_rss = $news_set->get("enable_rss_for_internal");
1387
1388 if ($enable_internal_rss)
1389 {
1390 $info->setBlockProperty("news", "settings", true);
1391 $info->setBlockProperty("news", "public_notifications_option", true);
1392 }
1393 }
1394
1395 // forward the command
1396 if ($ilCtrl->getNextClass() == "ilinfoscreengui")
1397 {
1398 $ilCtrl->forwardCommand($info);
1399 }
1400 else
1401 {
1402 return $ilCtrl->getHTML($info);
1403 }
1404 }
1405
1406 protected function getLogReservationIds()
1407 {
1408 if($_POST["mrsv"])
1409 {
1410 return $_POST["mrsv"];
1411 }
1412 else if($_GET["reservation_id"])
1413 {
1414 return array($_GET["reservation_id"]);
1415 }
1416 }
1417
1419 {
1420 global $ilCtrl, $lng, $tpl, $ilUser;
1421
1422 $ids = $this->getLogReservationIds();
1423 if(!sizeof($ids))
1424 {
1425 $this->ctrl->redirect($this, 'log');
1426 }
1427
1428 include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
1429 include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
1430
1431 $max = array();
1432 foreach($ids as $idx => $id)
1433 {
1434 if(!is_numeric($id))
1435 {
1436 list($obj_id, $user_id, $from, $to) = explode("_", $id);
1437
1438 $valid_ids = array();
1439 foreach(ilBookingObject::getList($this->object->getId()) as $item)
1440 {
1441 $valid_ids[$item["booking_object_id"]] = $item["title"];
1442 }
1443
1444 if(($this->checkPermissionBool("write") || $user_id == $ilUser->getId()) &&
1445 $from > time() &&
1446 in_array($obj_id, array_keys($valid_ids)))
1447 {
1448 $rsv_ids = ilBookingReservation::getCancelDetails($obj_id, $user_id, $from, $to);
1449 if(!sizeof($rsv_ids))
1450 {
1451 unset($ids[$idx]);
1452 }
1453 if(sizeof($rsv_ids) > 1)
1454 {
1455 $max[$id] = sizeof($rsv_ids);
1456 $ids[$idx] = $rsv_ids;
1457 }
1458 else
1459 {
1460 // only 1 in group? treat as normal reservation
1461 $ids[$idx] = array_shift($rsv_ids);
1462 }
1463 }
1464 else
1465 {
1466 unset($ids[$idx]);
1467 }
1468 }
1469 }
1470
1471 if(!sizeof($ids))
1472 {
1473 $this->ctrl->redirect($this, 'log');
1474 }
1475
1476 // show form instead
1477 if(sizeof($max) && max($max) > 1)
1478 {
1479 return $this->rsvConfirmCancelAggregationObject($ids);
1480 }
1481
1482 $this->tabs_gui->clearTargets();
1483 $this->tabs_gui->setBackTarget($lng->txt("back"),
1484 $ilCtrl->getLinkTarget($this, "log"));
1485
1486 $this->setHelpId("cancel_booking");
1487
1488 include_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
1489 $conf = new ilConfirmationGUI();
1490 $conf->setFormAction($ilCtrl->getFormAction($this, 'rsvCancel'));
1491 $conf->setHeaderText($lng->txt('book_confirm_cancel'));
1492 $conf->setConfirm($lng->txt('book_set_cancel'), 'rsvCancel');
1493 $conf->setCancel($lng->txt('cancel'), 'log');
1494
1495 foreach($ids as $id)
1496 {
1497 $rsv = new ilBookingReservation($id);
1498 $obj = new ilBookingObject($rsv->getObjectId());
1499
1500 $details = $obj->getTitle();
1501 if($this->object->getScheduleType() != ilObjBookingPool::TYPE_NO_SCHEDULE)
1502 {
1503 $details .= ", ".ilDatePresentation::formatPeriod(
1504 new ilDateTime($rsv->getFrom(), IL_CAL_UNIX),
1505 new ilDateTime($rsv->getTo()+1, IL_CAL_UNIX));
1506 }
1507
1508 $conf->addItem('rsv_id[]', $id, $details);
1509 }
1510
1511 $tpl->setContent($conf->getHTML());
1512 }
1513
1515 {
1516 include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
1517 $form = new ilPropertyFormGUI();
1518 $form->setFormAction($this->ctrl->getFormAction($this, "rsvCancel"));
1519 $form->setTitle($this->lng->txt("book_confirm_cancel_aggregation"));
1520
1521 include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
1522 include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
1523
1525
1526 foreach($a_ids as $idx => $ids)
1527 {
1528 if(is_array($ids))
1529 {
1530 $first = $ids;
1531 $first = array_shift($first);
1532 }
1533 else
1534 {
1535 $first = $ids;
1536 }
1537
1538 $rsv = new ilBookingReservation($first);
1539 $obj = new ilBookingObject($rsv->getObjectId());
1540
1541 $caption = $obj->getTitle().", ".ilDatePresentation::formatPeriod(
1542 new ilDateTime($rsv->getFrom(), IL_CAL_UNIX),
1543 new ilDateTime($rsv->getTo()+1, IL_CAL_UNIX));
1544
1545 // #17869
1546 if(is_array($ids))
1547 {
1548 $caption .= " (".sizeof($ids).")";
1549 }
1550
1551 $item = new ilNumberInputGUI($caption, "rsv_id_".$idx);
1552 $item->setRequired(true);
1553 $item->setMinValue(0);
1554 $item->setSize(4);
1555 $form->addItem($item);
1556
1557 if(is_array($ids))
1558 {
1559 $item->setMaxValue(sizeof($ids));
1560
1561 foreach($ids as $id)
1562 {
1563 $hidden = new ilHiddenInputGUI("rsv_aggr[".$idx."][]");
1564 $hidden->setValue($id);
1565 $form->addItem($hidden);
1566 }
1567 }
1568 else
1569 {
1570 $item->setMaxValue(1);
1571
1572 $hidden = new ilHiddenInputGUI("rsv_aggr[".$idx."]");
1573 $hidden->setValue($ids);
1574 $form->addItem($hidden);
1575 }
1576
1577 if($_POST["rsv_id_".$idx])
1578 {
1579 $item->setValue((int)$_POST["rsv_id_".$idx]);
1580 }
1581 }
1582
1583 $form->addCommandButton("rsvCancel", $this->lng->txt("confirm"));
1584 $form->addCommandButton("log", $this->lng->txt("cancel"));
1585
1586 return $form;
1587 }
1588
1589 function rsvConfirmCancelAggregationObject(array $a_ids = null)
1590 {
1591 global $tpl, $ilCtrl, $lng;
1592
1593 $this->tabs_gui->clearTargets();
1594 $this->tabs_gui->setBackTarget($lng->txt("back"),
1595 $ilCtrl->getLinkTarget($this, "log"));
1596
1597 $this->setHelpId("cancel_booking");
1598
1599 // #13511
1600 ilUtil::sendQuestion($lng->txt("book_confirm_cancel"));
1601
1602 $form = $this->rsvConfirmCancelAggregationForm($a_ids);
1603
1604 $tpl->setContent($form->getHTML());
1605 }
1606
1608 {
1609 global $ilUser, $tpl, $lng, $ilCtrl;
1610
1611 $ids = $_POST["rsv_id"];
1612
1613 // parse aggregation form
1614 if($_POST["rsv_aggr"])
1615 {
1616 $form = $this->rsvConfirmCancelAggregationForm($_POST["rsv_aggr"]);
1617 if(!$form->checkInput())
1618 {
1619 $this->tabs_gui->clearTargets();
1620 $this->tabs_gui->setBackTarget($lng->txt("back"),
1621 $ilCtrl->getLinkTarget($this, "log"));
1622
1623 return $tpl->setContent($form->getHTML());
1624 }
1625
1626 $ids = array();
1627 foreach($_POST["rsv_aggr"] as $idx => $aggr_ids)
1628 {
1629 $max = (int)$_POST["rsv_id_".$idx];
1630 if($max)
1631 {
1632 if(!is_array($aggr_ids))
1633 {
1634 $ids[] = $aggr_ids;
1635 }
1636 else
1637 {
1638 $aggr_ids = array_slice($aggr_ids, 0, $max);
1639 $ids = array_merge($ids, $aggr_ids);
1640 }
1641 }
1642 }
1643 }
1644
1645 if($ids)
1646 {
1647 include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
1648 foreach($ids as $id)
1649 {
1650 $obj = new ilBookingReservation($id);
1651
1652 if (!$this->checkPermissionBool("write") && $obj->getUserId() != $ilUser->getId())
1653 {
1654 ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
1655 $this->ctrl->redirect($this, 'log');
1656 }
1657
1659 $obj->update();
1660
1661 if($this->object->getScheduleType() != ilObjBookingPool::TYPE_NO_SCHEDULE)
1662 {
1663 // remove user calendar entry (#11086)
1664 $cal_entry_id = $obj->getCalendarEntry();
1665 if($cal_entry_id)
1666 {
1667 include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
1668 $entry = new ilCalendarEntry($cal_entry_id);
1669 $entry->delete();
1670 }
1671 }
1672 }
1673 }
1674
1675 ilUtil::sendSuccess($this->lng->txt('settings_saved'));
1676 $this->logObject();
1677 }
1678
1680 {
1681 $this->checkPermission("write");
1682
1683 $ids = $this->getLogReservationIds();
1684 if($ids)
1685 {
1686 include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
1687 foreach($ids as $id)
1688 {
1689 $obj = new ilBookingReservation($id);
1690 $obj->setStatus(ilBookingReservation::STATUS_IN_USE);
1691 $obj->update();
1692 }
1693 }
1694
1695 ilUtil::sendSuccess($this->lng->txt('settings_saved'));
1696 $this->logObject();
1697 }
1698
1700 {
1701 $this->checkPermission("write");
1702
1703 $ids = $this->getLogReservationIds();
1704 if($ids)
1705 {
1706 include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
1707 foreach($ids as $id)
1708 {
1709 $obj = new ilBookingReservation($id);
1710 $obj->setStatus(NULL);
1711 $obj->update();
1712 }
1713 }
1714
1715 ilUtil::sendSuccess($this->lng->txt('settings_saved'));
1716 $this->logObject();
1717 }
1718
1720 {
1721 global $tpl, $ilCtrl;
1722
1723 $this->tabs_gui->clearTargets();
1724
1725 $user_id = (int)$_GET['user_id'];
1726
1727 include_once 'Services/User/classes/class.ilPublicUserProfileGUI.php';
1728 $profile = new ilPublicUserProfileGUI($user_id);
1729 $profile->setBackUrl($this->ctrl->getLinkTarget($this, 'log'));
1730 $tpl->setContent($ilCtrl->getHTML($profile));
1731 }
1732
1733 public function addLocatorItems()
1734 {
1735 global $ilLocator;
1736
1737 if (is_object($this->object))
1738 {
1739 $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, "render"), "", $_GET["ref_id"]);
1740 }
1741 }
1742}
1743
1744?>
sprintf('%.4f', $callTime)
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
$column
Definition: 39dropdown.php:62
$success
Definition: Utf8Test.php:86
if(php_sapi_name() !='cli') $in
Definition: Utf8Test.php:37
$section
Definition: Utf8Test.php:83
$_GET["client_id"]
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_FKT_GETDATE
const IL_CAL_DATE
const IL_CAL_UNIX
Class ilBookingObjectGUI.
a bookable ressource
static lookupPoolId($object_id)
Lookup pool id.
static getNrOfItemsForObjects(array $a_obj_ids)
Get nr of available items
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)
List all reservations.
static getAvailableObject(array $a_ids, $a_from, $a_to, $a_return_single=true, $a_return_counter=false)
Check if any of given objects are bookable.
static getCancelDetails($a_obj_id, $a_user_id, $a_from, $a_to)
Get reservation ids from aggregated id for cancellation.
static getNewGroupId()
Get next group id
static isObjectAvailableNoSchedule($a_obj_id)
Class ilBookingScheduleGUI.
schedule for booking ressource
getRaster()
Get booking raster.
static getList($a_pool_id)
Get list of booking objects for given pool.
static _getColorsByType($a_type)
get selectable colors
Model for a calendar entry.
setStart($a_start)
@access public
static _getInstanceByUserId($a_user_id)
get singleton instance
static parseIncomingDate($a_value, $a_add_time=null)
Try to parse incoming value to date object.
static _numericDayToString($a_day, $a_long=true)
get
static _buildWeekDayList($a_day, $a_weekstart)
build week day list
static calculateFontColor($a_html_color_code)
Calculate best font color from html hex color code.
static _numericMonthToString($a_month, $a_long=true)
numeric month to string
static initDefaultCalendarByType($a_type_id, $a_usr_id, $a_title, $a_create=false)
Init the default calendar for given type and user.
This class represents a checkbox property in a property form.
static getInstanceFromAjaxCall()
(Re-)Build instance from ajax call
Confirmation screen class.
static formatPeriod(ilDateTime $start, ilDateTime $end)
Format a period of two date Shows: 14.
static setUseRelativeDates($a_status)
set use relative dates
static formatDate(ilDateTime $date)
Format a date @access public.
This class represents a date/time property in a property form.
@classDescription Date and time handling
Class for single dates.
Base class for ILIAS Exception handling.
This class represents a section header in a property form.
This class represents a hidden form property in a property form.
Class ilInfoScreenGUI.
This class represents a number property in a property form.
Class ilObjBookingPoolGUI.
confirmBookingNumbers(array $a_objects_counter, $a_group_id, ilPropertyFormGUI $a_form=null)
buildDatesBySchedule($week_start, array $hours, $schedule, array $object_ids, $seed, array &$dates)
applyLogFilterObject()
Apply filter from reservations table gui.
addExternalEditFormCustom(ilPropertyFormGUI $a_form)
bookObject()
First step in booking process.
__construct($a_data, $a_id, $a_call_by_reference, $a_prepare_output=true)
Constructor.
afterSave(ilObject $a_new_object)
Post (successful) object creation hook.
changeStatusObject()
Change status of given reservations.
getEditFormCustomValues(array &$a_values)
Add values to custom edit fields.
processBooking($a_object_id, $a_from=null, $a_to=null, $a_group_id=null)
Book object for date.
initCreationForms($a_new_type)
Init creation froms.
initEditCustomForm(ilPropertyFormGUI $a_form)
Add custom fields to update form.
rsvConfirmCancelAggregationObject(array $a_ids=null)
renderSlots(ilBookingSchedule $schedule, array $object_ids, $title)
handleBookingSuccess($a_obj_id, array $a_rsv_ids=null)
infoScreenObject()
this one is called from the info button in the repository not very nice to set cmdClass/Cmd manually,...
confirmedBookingObject()
Book object - either of type or specific - for given dates.
initBookingNumbersForm(array $a_objects_counter, $a_group_id, $a_reload=false)
updateCustom(ilPropertyFormGUI $a_form)
Insert custom update form values into object.
resetLogFilterObject()
Reset filter in reservations table gui.
addLocatorItems()
should be overwritten to add object specific items (repository items are preloaded)
GUI class for the workflow of copying objects.
Class ilObjectGUI Basic methods of all Output classes.
checkPermission($a_perm, $a_cmd="", $a_type="", $a_ref_id=null)
Check permission and redirect on error.
prepareOutput($a_show_subobjects=true)
prepare output
static _gotoRepositoryNode($a_ref_id, $a_cmd="frameset")
Goto repository root.
static _gotoRepositoryRoot($a_raise_error=false)
Goto repository root.
checkPermissionBool($a_perm, $a_cmd="", $a_type="", $a_ref_id=null)
Check permission.
addHeaderAction()
Add header action menu.
Class ilObjectMetaDataGUI.
static initServiceSettingsForm($a_obj_id, ilPropertyFormGUI $form, $services)
Init service settings form.
static updateServiceSettingsForm($a_obj_id, ilPropertyFormGUI $form, $services)
Update service settings.
Class ilObject Basic functions for all objects.
static _lookupObjId($a_id)
update()
update object in db
static _lookupTitle($a_id)
lookup object title
getRefId()
get reference id @access public
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
This class represents a property form user interface.
addItem($a_item)
Add Item (Property, SectionHeader).
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
GUI class for public user profile presentation.
This class represents a property in a property form.
This class represents an option in a radio group.
This class represents a selection list property in a property form.
ILIAS Setting Class.
special template class to simplify handling of ITX/PEAR
static sendQuestion($a_info="", $a_keep=false)
Send Question to Screen.
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
$counter
$info
Definition: example_052.php:80
global $ilCtrl
Definition: ilias.php:18
$ret
Definition: parser.php:6
$cmd
Definition: sahs_server.php:35
$ilUser
Definition: imgupload.php:18