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