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