ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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;
36 
37  $next_class = $this->ctrl->getNextClass($this);
38  $cmd = $this->ctrl->getCmd();
39 
40  if(!$next_class && $cmd == 'render')
41  {
42  $this->ctrl->setCmdClass('ilBookingObjectGUI');
43  $next_class = $this->ctrl->getNextClass($this);
44  }
45 
46  if(substr($cmd, 0, 4) == 'book')
47  {
48  $next_class = '';
49  }
50 
51  $ilNavigationHistory->addItem($this->ref_id,
52  "./goto.php?target=book_".$this->ref_id, "book");
53 
54  $this->prepareOutput();
55 
56  switch($next_class)
57  {
58  case 'ilpermissiongui':
59  $this->tabs_gui->setTabActive('perm_settings');
60  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
61  $perm_gui =& new ilPermissionGUI($this);
62  $ret =& $this->ctrl->forwardCommand($perm_gui);
63  break;
64 
65  case 'ilbookingobjectgui':
66  $this->tabs_gui->setTabActive('render');
67  include_once("Modules/BookingManager/classes/class.ilBookingObjectGUI.php");
68  $object_gui =& new ilBookingObjectGUI($this);
69  $ret =& $this->ctrl->forwardCommand($object_gui);
70  break;
71 
72  case 'ilbookingschedulegui':
73  $this->tabs_gui->setTabActive('schedules');
74  include_once("Modules/BookingManager/classes/class.ilBookingScheduleGUI.php");
75  $schedule_gui =& new ilBookingScheduleGUI($this);
76  $ret =& $this->ctrl->forwardCommand($schedule_gui);
77  break;
78 
79  case 'ilpublicuserprofilegui':
80  $ilTabs->clearTargets();
81  include_once("Services/User/classes/class.ilPublicUserProfileGUI.php");
82  $profile = new ilPublicUserProfileGUI((int)$_GET["user_id"]);
83  $profile->setBackUrl($this->ctrl->getLinkTarget($this, 'log'));
84  $ret = $this->ctrl->forwardCommand($profile);
85  $tpl->setContent($ret);
86  break;
87 
88  case 'ilinfoscreengui':
89  $this->infoScreen();
90  break;
91 
92  case "ilcommonactiondispatchergui":
93  include_once("Services/Object/classes/class.ilCommonActionDispatcherGUI.php");
95  $this->ctrl->forwardCommand($gui);
96  break;
97 
98  case "ilobjectcopygui":
99  include_once "./Services/Object/classes/class.ilObjectCopyGUI.php";
100  $cp = new ilObjectCopyGUI($this);
101  $cp->setType("book");
102  $this->ctrl->forwardCommand($cp);
103  break;
104 
105  default:
106  $cmd = $this->ctrl->getCmd();
107  $cmd .= 'Object';
108  $this->$cmd();
109  break;
110  }
111 
112  $this->addHeaderAction();
113  return true;
114  }
115 
116  protected function initCreationForms($a_new_type)
117  {
118  $forms = parent::initCreationForms($a_new_type);
119  unset($forms[self::CFORM_IMPORT]);
120 
121  return $forms;
122  }
123 
124  protected function afterSave(ilObject $a_new_object)
125  {
126  $a_new_object->setOffline(true);
127  $a_new_object->update();
128 
129  // always send a message
130  ilUtil::sendSuccess($this->lng->txt("book_pool_added"),true);
131  $this->ctrl->setParameter($this, "ref_id", $a_new_object->getRefId());
132  $this->ctrl->redirect($this, "edit");
133  }
134 
135  public function editObject()
136  {
137  // if we have no schedules yet - show info
138  include_once "Modules/BookingManager/classes/class.ilBookingSchedule.php";
139  if($this->object->getScheduleType() != ilObjBookingPool::TYPE_NO_SCHEDULE &&
140  !sizeof(ilBookingSchedule::getList($this->object->getId())))
141  {
142  ilUtil::sendInfo($this->lng->txt("book_schedule_warning_edit"));
143  }
144 
145  return parent::editObject();
146  }
147 
148  protected function initEditCustomForm(ilPropertyFormGUI $a_form)
149  {
150  $online = new ilCheckboxInputGUI($this->lng->txt("online"), "online");
151  $a_form->addItem($online);
152 
153  $type = new ilRadioGroupInputGUI($this->lng->txt("book_schedule_type"), "stype");
154  $type->setRequired(true);
155  $a_form->addItem($type);
156 
157  // #14478
158  include_once "Modules/BookingManager/classes/class.ilBookingObject.php";
159  if(sizeof(ilBookingObject::getList($this->object->getId())))
160  {
161  $type->setDisabled(true);
162  }
163 
164  $fixed = new ilRadioOption($this->lng->txt("book_schedule_type_fixed"), ilObjBookingPool::TYPE_FIX_SCHEDULE);
165  $fixed->setInfo($this->lng->txt("book_schedule_type_fixed_info"));
166  $type->addOption($fixed);
167 
168  $none = new ilRadioOption($this->lng->txt("book_schedule_type_none"), ilObjBookingPool::TYPE_NO_SCHEDULE);
169  $none->setInfo($this->lng->txt("book_schedule_type_none_info"));
170  $type->addOption($none);
171 
172  $public = new ilCheckboxInputGUI($this->lng->txt("book_public_log"), "public");
173  $public->setInfo($this->lng->txt("book_public_log_info"));
174  $a_form->addItem($public);
175  }
176 
177  protected function getEditFormCustomValues(array &$a_values)
178  {
179  $a_values["online"] = !$this->object->isOffline();
180  $a_values["public"] = $this->object->hasPublicLog();
181  $a_values["stype"] = $this->object->getScheduleType();
182  }
183 
184  protected function updateCustom(ilPropertyFormGUI $a_form)
185  {
186  $this->object->setOffline(!$a_form->getInput('online'));
187  $this->object->setPublicLog($a_form->getInput('public'));
188  $this->object->setScheduleType($a_form->getInput('stype'));
189  }
190 
194  function setTabs()
195  {
196  global $ilAccess, $ilHelp;
197 
198  if (in_array($this->ctrl->getCmd(), array("create", "save")) && !$this->ctrl->getNextClass())
199  {
200  return;
201  }
202 
203  $ilHelp->setScreenIdComponent("book");
204 
205  $this->tabs_gui->addTab("render",
206  $this->lng->txt("book_booking_types"),
207  $this->ctrl->getLinkTarget($this, "render"));
208 
209  $this->tabs_gui->addTab("info",
210  $this->lng->txt("info_short"),
211  $this->ctrl->getLinkTarget($this, "infoscreen"));
212 
213  $this->tabs_gui->addTab("log",
214  $this->lng->txt("book_log"),
215  $this->ctrl->getLinkTarget($this, "log"));
216 
217  if ($ilAccess->checkAccess('write', '', $this->object->getRefId()))
218  {
219  if($this->object->getScheduleType() != ilObjBookingPool::TYPE_NO_SCHEDULE)
220  {
221  $this->tabs_gui->addTab("schedules",
222  $this->lng->txt("book_schedules"),
223  $this->ctrl->getLinkTargetByClass("ilbookingschedulegui", "render"));
224  }
225 
226  $this->tabs_gui->addTab("settings",
227  $this->lng->txt("settings"),
228  $this->ctrl->getLinkTarget($this, "edit"));
229  }
230 
231  if($ilAccess->checkAccess('edit_permission', '', $this->object->getRefId()))
232  {
233  $this->tabs_gui->addTab("perm_settings",
234  $this->lng->txt("perm_settings"),
235  $this->ctrl->getLinkTargetByClass("ilpermissiongui", "perm"));
236  }
237  }
238 
242  function bookObject()
243  {
244  global $tpl;
245 
246  $this->tabs_gui->clearTargets();
247  $this->tabs_gui->setBackTarget($this->lng->txt('book_back_to_list'), $this->ctrl->getLinkTarget($this, 'render'));
248 
249  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
250  $obj = new ilBookingObject((int)$_GET['object_id']);
251 
252  $this->lng->loadLanguageModule("dateplaner");
253  $this->ctrl->setParameter($this, 'object_id', $obj->getId());
254 
255  if($this->object->getScheduleType() == ilObjBookingPool::TYPE_FIX_SCHEDULE)
256  {
257  include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
258  $schedule = new ilBookingSchedule($obj->getScheduleId());
259 
260  $tpl->setContent($this->renderSlots($schedule, array($obj->getId()), $obj->getTitle()));
261  }
262  else
263  {
264  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
265  $cgui = new ilConfirmationGUI();
266  $cgui->setHeaderText($this->lng->txt("book_confirm_booking_no_schedule"));
267 
268  $cgui->setFormAction($this->ctrl->getFormAction($this));
269  $cgui->setCancel($this->lng->txt("cancel"), "render");
270  $cgui->setConfirm($this->lng->txt("confirm"), "confirmedBooking");
271 
272  $cgui->addItem("object_id", $obj->getId(), $obj->getTitle());
273 
274  $tpl->setContent($cgui->getHTML());
275  }
276  }
277 
278  protected function renderSlots(ilBookingSchedule $schedule, array $object_ids, $title)
279  {
280  global $ilUser;
281 
282  // fix
283  if(!$schedule->getRaster())
284  {
285  $mytpl = new ilTemplate('tpl.booking_reservation_fix.html', true, true, 'Modules/BookingManager');
286 
287  $mytpl->setVariable('FORM_ACTION', $this->ctrl->getFormAction($this));
288  $mytpl->setVariable('TXT_TITLE', $this->lng->txt('book_reservation_title'));
289  $mytpl->setVariable('TXT_INFO', $this->lng->txt('book_reservation_fix_info'));
290  $mytpl->setVariable('TXT_OBJECT', $title);
291  $mytpl->setVariable('TXT_CMD_BOOK', $this->lng->txt('book_confirm_booking'));
292  $mytpl->setVariable('TXT_CMD_CANCEL', $this->lng->txt('cancel'));
293 
294  include_once 'Services/Calendar/classes/class.ilCalendarUserSettings.php';
295 
296  $user_settings = ilCalendarUserSettings::_getInstanceByUserId($ilUser->getId());
297 
298  $morning_aggr = $user_settings->getDayStart();
299  $evening_aggr = $user_settings->getDayEnd();
300  $hours = array();
301  for($i = $morning_aggr;$i <= $evening_aggr;$i++)
302  {
303  switch($user_settings->getTimeFormat())
304  {
306  if ($morning_aggr > 0 && $i == $morning_aggr)
307  {
308  $hours[$i] = sprintf('%02d:00',0)."-";
309  }
310  $hours[$i].= sprintf('%02d:00',$i);
311  if ($evening_aggr < 23 && $i == $evening_aggr)
312  {
313  $hours[$i].= "-".sprintf('%02d:00',23);
314  }
315  break;
316 
318  if ($morning_aggr > 0 && $i == $morning_aggr)
319  {
320  $hours[$i] = date('h a',mktime(0,0,0,1,1,2000))."-";
321  }
322  $hours[$i].= date('h a',mktime($i,0,0,1,1,2000));
323  if ($evening_aggr < 23 && $i == $evening_aggr)
324  {
325  $hours[$i].= "-".date('h a',mktime(23,0,0,1,1,2000));
326  }
327  break;
328  }
329  }
330 
331  if(isset($_GET['seed']))
332  {
333  $find_first_open = false;
334  $seed = new ilDate($_GET['seed'], IL_CAL_DATE);
335  }
336  else
337  {
338  $find_first_open = true;
339  $seed = new ilDate(time(), IL_CAL_UNIX);
340  }
341 
342  include_once 'Services/Calendar/classes/class.ilCalendarUtil.php';
343  include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
344  $week_start = $user_settings->getWeekStart();
345 
346  if(!$find_first_open)
347  {
348  $dates = array();
349  $this->buildDatesBySchedule($week_start, $hours, $schedule, $object_ids, $seed, $dates);
350  }
351  else
352  {
353  $dates = array();
354  $has_open_slot = $this->buildDatesBySchedule($week_start, $hours, $schedule, $object_ids, $seed, $dates);
355 
356  // find first open slot
357  if(!$has_open_slot)
358  {
359  // 1 year is limit for search
360  $limit = clone($seed);
361  $limit->increment(ilDate::YEAR, 1);
362  $limit = $limit->get(IL_CAL_UNIX);
363 
364  while(!$has_open_slot && $seed->get(IL_CAL_UNIX) < $limit)
365  {
366  $seed->increment(ilDate::WEEK, 1);
367 
368  $dates = array();
369  $has_open_slot = $this->buildDatesBySchedule($week_start, $hours, $schedule, $object_ids, $seed, $dates);
370  }
371  }
372  }
373 
374  include_once 'Services/Calendar/classes/class.ilCalendarHeaderNavigationGUI.php';
375  $navigation = new ilCalendarHeaderNavigationGUI($this,$seed,ilDateTime::WEEK,'book');
376  $mytpl->setVariable('NAVIGATION', $navigation->getHTML());
377 
378  foreach(ilCalendarUtil::_buildWeekDayList($seed,$week_start)->get() as $date)
379  {
380  $date_info = $date->get(IL_CAL_FKT_GETDATE,'','UTC');
381 
382  $mytpl->setCurrentBlock('weekdays');
383  $mytpl->setVariable('TXT_WEEKDAY', ilCalendarUtil:: _numericDayToString($date_info['wday']));
384  $mytpl->setVariable('TXT_DATE', $date_info['mday'].' '.ilCalendarUtil:: _numericMonthToString($date_info['mon']));
385  $mytpl->parseCurrentBlock();
386  }
387 
388  include_once 'Services/Calendar/classes/class.ilCalendarAppointmentColors.php';
389  include_once 'Services/Calendar/classes/class.ilCalendarUtil.php';
390  $color = array();
392  for($loop = 0; $loop < 7; $loop++)
393  {
394  $col = $all[$loop];
396  $color[$loop+1] = 'border-bottom: 1px solid '.$col.'; background-color: '.$col.'; color: '.$fnt;
397  }
398 
399  $counter = 0;
400  foreach($dates as $hour => $days)
401  {
402  $caption = $days;
403  $caption = array_shift($caption);
404 
405  for($loop = 1; $loop < 8; $loop++)
406  {
407  if(!isset($days[$loop]))
408  {
409  $mytpl->setCurrentBlock('dates');
410  $mytpl->setVariable('DUMMY', '&nbsp;');
411  $mytpl->parseCurrentBlock();
412  }
413  else
414  {
415  if(isset($days[$loop]['captions']))
416  {
417  foreach($days[$loop]['captions'] as $slot_id => $slot_caption)
418  {
419  $mytpl->setCurrentBlock('choice');
420  $mytpl->setVariable('TXT_DATE', $slot_caption);
421  $mytpl->setVariable('VALUE_DATE', $slot_id);
422  $mytpl->setVariable('DATE_COLOR', $color[$loop]);
423  $mytpl->setVariable('TXT_AVAILABLE',
424  sprintf($this->lng->txt('book_reservation_available'),
425  $days[$loop]['available'][$slot_id]));
426  $mytpl->parseCurrentBlock();
427  }
428 
429  $mytpl->setCurrentBlock('dates');
430  $mytpl->setVariable('DUMMY', '');
431  $mytpl->parseCurrentBlock();
432  }
433  else if(isset($days[$loop]['in_slot']))
434  {
435  $mytpl->setCurrentBlock('dates');
436  $mytpl->setVariable('DATE_COLOR', $color[$loop]);
437  $mytpl->parseCurrentBlock();
438  }
439  else
440  {
441  $mytpl->setCurrentBlock('dates');
442  $mytpl->setVariable('DUMMY', '&nbsp;');
443  $mytpl->parseCurrentBlock();
444  }
445  }
446  }
447 
448  $mytpl->setCurrentBlock('slots');
449  $mytpl->setVariable('TXT_HOUR', $caption);
450  if($counter%2)
451  {
452  $mytpl->setVariable('CSS_ROW', 'tblrow1');
453  }
454  else
455  {
456  $mytpl->setVariable('CSS_ROW', 'tblrow2');
457  }
458  $mytpl->parseCurrentBlock();
459 
460  $counter++;
461  }
462  }
463  // flexible
464  else
465  {
466  // :TODO: inactive for now
467  }
468 
469  return $mytpl->get();
470  }
471 
472  protected function buildDatesBySchedule($week_start, array $hours, $schedule, array $object_ids, $seed, array &$dates)
473  {
474  global $ilUser;
475 
476  include_once 'Services/Calendar/classes/class.ilCalendarUserSettings.php';
477  $user_settings = ilCalendarUserSettings::_getInstanceByUserId($ilUser->getId());
478 
479  $map = array('mo', 'tu', 'we', 'th', 'fr', 'sa', 'su');
480  $definition = $schedule->getDefinition();
481 
482  $has_open_slot = false;
483  foreach(ilCalendarUtil::_buildWeekDayList($seed,$week_start)->get() as $date)
484  {
485  $date_info = $date->get(IL_CAL_FKT_GETDATE,'','UTC');
486 
487  $slots = array();
488  if(isset($definition[$map[$date_info['isoday']-1]]))
489  {
490  $slots = array();
491  foreach($definition[$map[$date_info['isoday']-1]] as $slot)
492  {
493  $slot = explode('-', $slot);
494  $slots[] = array('from'=>str_replace(':', '', $slot[0]),
495  'to'=>str_replace(':', '', $slot[1]));
496  }
497  }
498 
499  $last = array_pop(array_keys($hours));
500  $slot_captions = array();
501  foreach($hours as $hour => $period)
502  {
503  $dates[$hour][0] = $period;
504 
505  $period = explode("-", $period);
506 
507  // #13738
508  if($user_settings->getTimeFormat() == ilCalendarSettings::TIME_FORMAT_12)
509  {
510  if(stristr($period[0], "pm"))
511  {
512  $period[0] = (int)$period[0]+12;
513  }
514  else
515  {
516  $period[0] = (int)$period[0];
517  if($period[0] == 12)
518  {
519  $period[0] = 0;
520  }
521  }
522  if(sizeof($period) == 2)
523  {
524  if(stristr($period[1], "pm"))
525  {
526  $period[1] = (int)$period[1]+12;
527  }
528  else
529  {
530  $period[1] = (int)$period[1];
531  if($period[1] == 12)
532  {
533  $period[1] = 0;
534  }
535  }
536  }
537  }
538 
539  if(sizeof($period) == 1)
540  {
541  $period_from = (int)substr($period[0], 0, 2)."00";
542  $period_to = (int)substr($period[0], 0, 2)."59";
543  }
544  else
545  {
546  $period_from = (int)substr($period[0], 0, 2)."00";
547  $period_to = (int)substr($period[1], 0, 2)."59";
548  }
549 
550  $column = $date_info['isoday'];
551  if(!$week_start)
552  {
553  if($column < 7)
554  {
555  $column++;
556  }
557  else
558  {
559  $column = 1;
560  }
561  }
562 
563  if(sizeof($slots))
564  {
565  $in = false;
566  foreach($slots as $slot)
567  {
568  $slot_from = mktime(substr($slot['from'], 0, 2), substr($slot['from'], 2, 2), 0, $date_info["mon"], $date_info["mday"], $date_info["year"]);
569  $slot_to = mktime(substr($slot['to'], 0, 2), substr($slot['to'], 2, 2), 0, $date_info["mon"], $date_info["mday"], $date_info["year"]);
570 
571  // always single object, we can sum up
572  $nr_available = (array)ilBookingReservation::getAvailableObject($object_ids, $slot_from, $slot_to-1, false, true);
573 
574  // check deadline
575  if($slot_from < (time()+$schedule->getDeadline()*60*60) || !array_sum($nr_available))
576  {
577  continue;
578  }
579 
580  // is slot active in current hour?
581  if((int)$slot['from'] < $period_to && (int)$slot['to'] > $period_from)
582  {
583  $from = ilDatePresentation::formatDate(new ilDateTime($slot_from, IL_CAL_UNIX));
584  $from = array_pop(explode(' ', $from));
586  $to = array_pop(explode(' ', $to));
587 
588  // show caption (first hour) of slot
589  $id = $slot_from.'_'.$slot_to;
590  if(!in_array($id, $slot_captions))
591  {
592  $dates[$hour][$column]['captions'][$id] = $from.'-'.$to;
593  $dates[$hour][$column]['available'][$id] = array_sum($nr_available);
594  $slot_captions[] = $id;
595  }
596 
597  $in = true;
598  }
599  }
600  // (any) active slot
601  if($in)
602  {
603  $has_open_slot = true;
604  $dates[$hour][$column]['in_slot'] = $in;
605  }
606  }
607  }
608  }
609 
610  return $has_open_slot;
611  }
612 
617  {
618  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
619  include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
620 
621  $success = false;
622 
623  if($this->object->getScheduleType() == ilObjBookingPool::TYPE_NO_SCHEDULE)
624  {
625  if($_POST['object_id'])
626  {
627  $object_id = $_POST['object_id'];
628  if($object_id)
629  {
631  {
632  $this->processBooking($object_id);
633  $success = $object_id;
634  }
635  else
636  {
637  // #11852
638  ilUtil::sendFailure($this->lng->txt('book_reservation_failed_overbooked'), true);
639  $this->ctrl->redirect($this, 'render');
640  }
641  }
642  }
643  }
644  else
645  {
646  if(!isset($_POST['date']))
647  {
648  ilUtil::sendFailure($this->lng->txt('select_one'));
649  return $this->bookObject();
650  }
651 
652  // single object reservation(s)
653  if(isset($_GET['object_id']))
654  {
655  $confirm = array();
656 
657  $object_id = (int)$_GET['object_id'];
658  if($object_id)
659  {
660  $group_id = null;
661  $nr = ilBookingObject::getNrOfItemsForObjects(array($object_id));
662  if($nr[$object_id] > 1 || sizeof($_POST['date']) > 1)
663  {
665  }
666  foreach($_POST['date'] as $date)
667  {
668  $fromto = explode('_', $date);
669  $fromto[1]--;
670 
671  $counter = ilBookingReservation::getAvailableObject(array($object_id), $fromto[0], $fromto[1], false, true);
672  $counter = $counter[$object_id];
673  if($counter)
674  {
675  if($counter > 1)
676  {
677  $confirm[$object_id."_".$fromto[0]."_".($fromto[1]+1)] = $counter;
678  }
679  else
680  {
681  $this->processBooking($object_id, $fromto[0], $fromto[1], $group_id);
682  $success = $object_id;
683  }
684  }
685  }
686  }
687 
688  if(sizeof($confirm))
689  {
690  return $this->confirmBookingNumbers($confirm, $group_id);
691  }
692  }
693  /*
694  // group object reservation(s)
695  else
696  {
697  $all_object_ids = array();
698  foreach(ilBookingObject::getList((int)$_GET['type_id']) as $item)
699  {
700  $all_object_ids[] = $item['booking_object_id'];
701  }
702 
703  $possible_objects = $counter = array();
704  sort($_POST['date']);
705  foreach($_POST['date'] as $date)
706  {
707  $fromto = explode('_', $date);
708  $fromto[1]--;
709  $possible_objects[$date] = ilBookingReservation::getAvailableObject($all_object_ids, $fromto[0], $fromto[1], false);
710  foreach($possible_objects[$date] as $obj_id)
711  {
712  $counter[$obj_id]++;
713  }
714  }
715 
716  if(max($counter))
717  {
718  // we prefer the objects which are available for most slots
719  arsort($counter);
720  $counter = array_keys($counter);
721 
722  // book each slot
723  foreach($possible_objects as $date => $available_ids)
724  {
725  $fromto = explode('_', $date);
726  $fromto[1]--;
727 
728  // find "best" object for slot
729  foreach($counter as $best_object_id)
730  {
731  if(in_array($best_object_id, $available_ids))
732  {
733  $object_id = $best_object_id;
734  break;
735  }
736  }
737  $this->processBooking($object_id, $fromto[0], $fromto[1]);
738  $success = true;
739  }
740  }
741  }
742  */
743  }
744 
745  if($success)
746  {
748  }
749  else
750  {
751  ilUtil::sendFailure($this->lng->txt('book_reservation_failed'), true);
752  $this->ctrl->redirect($this, 'book');
753  }
754  }
755 
756  protected function handleBookingSuccess($a_obj_id)
757  {
758  ilUtil::sendSuccess($this->lng->txt('book_reservation_confirmed'), true);
759 
760  // show post booking information?
761  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
762  $obj = new ilBookingObject($a_obj_id);
763  $pfile = $obj->getPostFile();
764  $ptext = $obj->getPostText();
765  if(trim($ptext) || $pfile)
766  {
767  $this->ctrl->setParameterByClass('ilbookingobjectgui', 'object_id', $obj->getId());
768  $this->ctrl->redirectByClass('ilbookingobjectgui', 'displayPostInfo');
769  }
770  else
771  {
772  $this->ctrl->redirect($this, 'render');
773  }
774  }
775 
776  protected function initBookingNumbersForm(array $a_objects_counter, $a_group_id)
777  {
778  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
779  $form = new ilPropertyFormGUI();
780  $form->setFormAction($this->ctrl->getFormAction($this, "confirmedBooking"));
781  $form->setTitle($this->lng->txt("book_confirm_booking_schedule_number_of_objects"));
782  $form->setDescription($this->lng->txt("book_confirm_booking_schedule_number_of_objects_info"));
783 
784  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
785  $section = false;
786  foreach($a_objects_counter as $id => $counter)
787  {
788  $id = explode("_", $id);
789  $book_id = $id[0]."_".$id[1]."_".$id[2]."_".$counter;
790 
791  $obj = new ilBookingObject($id[0]);
792 
793  if(!$section)
794  {
796  $section->setTitle($obj->getTitle());
797  $form->addItem($section);
798 
799  $section = true;
800  }
801 
802  $period = /* $this->lng->txt("book_period").": ". */
804  new ilDateTime($id[1], IL_CAL_UNIX),
805  new ilDateTime($id[2], IL_CAL_UNIX));
806 
807  $nr_field = new ilNumberInputGUI($period, "conf_nr__".$book_id);
808  $nr_field->setValue(1);
809  $nr_field->setSize(3);
810  $nr_field->setMaxValue($counter);
811  $nr_field->setMinValue(1);
812  $nr_field->setRequired(true);
813  $form->addItem($nr_field);
814  }
815 
816  if($a_group_id)
817  {
818  $grp = new ilHiddenInputGUI("grp_id");
819  $grp->setValue($a_group_id);
820  $form->addItem($grp);
821  }
822 
823  $form->addCommandButton("confirmedBookingNumbers", $this->lng->txt("confirm"));
824  $form->addCommandButton("render", $this->lng->txt("cancel"));
825 
826  return $form;
827  }
828 
829  function confirmBookingNumbers(array $a_objects_counter, $a_group_id, ilPropertyFormGUI $a_form = null)
830  {
831  global $tpl;
832 
833  $this->tabs_gui->clearTargets();
834  $this->tabs_gui->setBackTarget($this->lng->txt('book_back_to_list'), $this->ctrl->getLinkTarget($this, 'render'));
835 
836  if(!$a_form)
837  {
838  $a_form = $this->initBookingNumbersForm($a_objects_counter, $a_group_id);
839  }
840 
841  $tpl->setContent($a_form->getHTML());
842  }
843 
845  {
846  // convert post data to initial form config
847  $counter = array();
848  foreach(array_keys($_POST) as $id)
849  {
850  if(substr($id, 0, 9) == "conf_nr__")
851  {
852  $id = explode("_", substr($id, 9));
853  $counter[$id[0]."_".$id[1]."_".$id[2]] = $id[3];
854  }
855  }
856 
857  $group_id = $_POST["grp_id"];
858 
859  $form = $this->initBookingNumbersForm($counter, $group_id);
860  if($form->checkInput())
861  {
862  include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
863 
864  $success = false;
865  foreach($counter as $id => $all_nr)
866  {
867  $book_nr = $form->getInput("conf_nr__".$id."_".$all_nr);
868  $parts = explode("_", $id);
869  $obj_id = $parts[0];
870  $from = $parts[1];
871  $to = $parts[2]-1;
872 
873  // get currently available slots
874  $counter = ilBookingReservation::getAvailableObject(array($obj_id), $from, $to, false, true);
875  $counter = $counter[$obj_id];
876  if($counter)
877  {
878  // we can only book what is left
879  $book_nr = min($book_nr, $counter);
880  for($loop = 0; $loop < $book_nr; $loop++)
881  {
882  $this->processBooking($obj_id, $from, $to, $group_id);
883  $success = $obj_id;
884  }
885  }
886  }
887  if($success)
888  {
890  }
891  else
892  {
893  ilUtil::sendFailure($this->lng->txt('book_reservation_failed'), true);
894  $this->ctrl->redirect($this, 'render');
895  }
896  }
897  else
898  {
899  $form->setValuesByPost();
900  return $this->confirmBookingNumbers($counter, $group_id, $form);
901  }
902  }
903 
912  function processBooking($a_object_id, $a_from = null, $a_to = null, $a_group_id = null)
913  {
914  global $ilUser, $ilAccess;
915 
916  // #11995
917  if(!$ilAccess->checkAccess('read', '', $this->object->getRefId()))
918  {
919  $this->ilias->raiseError($this->lng->txt("msg_no_perm_read"),$this->ilias->error_obj->MESSAGE);
920  };
921 
922  include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
923  $reservation = new ilBookingReservation();
924  $reservation->setObjectId($a_object_id);
925  $reservation->setUserId($ilUser->getID());
926  $reservation->setFrom($a_from);
927  $reservation->setTo($a_to);
928  $reservation->setGroupId($a_group_id);
929  $reservation->save();
930 
931  if($a_from)
932  {
933  $this->lng->loadLanguageModule('dateplaner');
934  include_once 'Services/Calendar/classes/class.ilCalendarUtil.php';
935  include_once 'Services/Calendar/classes/class.ilCalendarCategory.php';
936  $def_cat = ilCalendarUtil::initDefaultCalendarByType(ilCalendarCategory::TYPE_BOOK,$ilUser->getId(),$this->lng->txt('cal_ch_personal_book'),true);
937 
938  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
939  $object = new ilBookingObject($a_object_id);
940 
941  include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
942  $entry = new ilCalendarEntry;
943  $entry->setStart(new ilDateTime($a_from, IL_CAL_UNIX));
944  $entry->setEnd(new ilDateTime($a_to, IL_CAL_UNIX));
945  $entry->setTitle($this->lng->txt('book_cal_entry').' '.$object->getTitle());
946  $entry->setContextId($reservation->getId());
947  $entry->save();
948 
949  include_once 'Services/Calendar/classes/class.ilCalendarCategoryAssignments.php';
950  $assignment = new ilCalendarCategoryAssignments($entry->getEntryId());
951  $assignment->addAssignment($def_cat->getCategoryId());
952  }
953  }
954 
958  function logObject()
959  {
960  global $tpl, $ilAccess;
961 
962  $this->tabs_gui->setTabActive('log');
963 
964  $show_all = ($ilAccess->checkAccess('write', '', $this->object->getRefId()) ||
965  $this->object->hasPublicLog());
966 
967  $filter = null;
968  if($_GET["object_id"])
969  {
970  $filter["object"] = (int)$_GET["object_id"];
971  }
972 
973  include_once 'Modules/BookingManager/classes/class.ilBookingReservationsTableGUI.php';
974  $table = new ilBookingReservationsTableGUI($this, 'log', $this->ref_id,
975  $this->object->getId(), $show_all,
976  ($this->object->getScheduleType() != ilObjBookingPool::TYPE_NO_SCHEDULE),
977  $filter);
978  $tpl->setContent($table->getHTML());
979  }
980 
981  function logDetailsObject()
982  {
983  global $tpl, $ilAccess;
984 
985  $this->tabs_gui->clearTargets();
986  $this->tabs_gui->setBackTarget($this->lng->txt("back"),
987  $this->ctrl->getLinkTarget($this, "log"));
988 
989  $show_all = ($ilAccess->checkAccess('write', '', $this->object->getRefId()) ||
990  $this->object->hasPublicLog());
991 
992  $filter = null;
993  if($_GET["object_id"])
994  {
995  $filter["object"] = (int)$_GET["object_id"];
996  }
997 
998  include_once 'Modules/BookingManager/classes/class.ilBookingReservationsTableGUI.php';
999  $table = new ilBookingReservationsTableGUI($this, 'log', $this->ref_id,
1000  $this->object->getId(), $show_all,
1001  ($this->object->getScheduleType() != ilObjBookingPool::TYPE_NO_SCHEDULE),
1002  $filter, $_GET["reservation_id"]);
1003  $tpl->setContent($table->getHTML());
1004  }
1005 
1010  {
1011  global $ilAccess;
1012 
1013  $this->tabs_gui->setTabActive('log');
1014 
1015  if(!$_POST['reservation_id'])
1016  {
1017  ilUtil::sendFailure($this->lng->txt('select_one'));
1018  return $this->logObject();
1019  }
1020 
1021  if ($ilAccess->checkAccess('write', '', $this->object->getRefId()))
1022  {
1023  include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
1024  ilBookingReservation::changeStatus($_POST['reservation_id'], (int)$_POST['tstatus']);
1025  }
1026 
1027  ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
1028  return $this->ctrl->redirect($this, 'log');
1029  }
1030 
1035  {
1036  global $ilAccess;
1037 
1038  $show_all = ($ilAccess->checkAccess('write', '', $this->object->getRefId()) ||
1039  $this->object->hasPublicLog());
1040 
1041  include_once 'Modules/BookingManager/classes/class.ilBookingReservationsTableGUI.php';
1042  $table = new ilBookingReservationsTableGUI($this, 'log', $this->ref_id,
1043  $this->object->getId(), $show_all,
1044  ($this->object->getScheduleType() != ilObjBookingPool::TYPE_NO_SCHEDULE));
1045  $table->resetOffset();
1046  $table->writeFilterToSession();
1047  $this->logObject();
1048  }
1049 
1054  {
1055  global $ilAccess;
1056 
1057  $show_all = ($ilAccess->checkAccess('write', '', $this->object->getRefId()) ||
1058  $this->object->hasPublicLog());
1059 
1060  include_once 'Modules/BookingManager/classes/class.ilBookingReservationsTableGUI.php';
1061  $table = new ilBookingReservationsTableGUI($this, 'log', $this->ref_id,
1062  $this->object->getId(), $show_all,
1063  ($this->object->getScheduleType() != ilObjBookingPool::TYPE_NO_SCHEDULE));
1064  $table->resetOffset();
1065  $table->resetFilter();
1066  $this->logObject();
1067  }
1068 
1069  function _goto($a_target)
1070  {
1071  global $ilAccess, $ilErr, $lng;
1072 
1073  if ($ilAccess->checkAccess("read", "", $a_target))
1074  {
1075  ilObjectGUI::_gotoRepositoryNode($a_target, "render");
1076  }
1077  else if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID))
1078  {
1079  ilUtil::sendFailure(sprintf($lng->txt("msg_no_perm_read_item"),
1080  ilObject::_lookupTitle(ilObject::_lookupObjId($a_target))), true);
1082  }
1083 
1084  $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
1085  }
1086 
1092  function infoScreenObject()
1093  {
1094  $this->ctrl->setCmd("showSummary");
1095  $this->ctrl->setCmdClass("ilinfoscreengui");
1096  $this->infoScreen();
1097  }
1098 
1099  function infoScreen()
1100  {
1101  global $ilAccess, $ilCtrl;
1102 
1103  $this->tabs_gui->setTabActive('info');
1104 
1105  if (!$ilAccess->checkAccess("visible", "", $this->ref_id))
1106  {
1107  $this->ilias->raiseError($this->lng->txt("msg_no_perm_read"),$this->ilias->error_obj->MESSAGE);
1108  }
1109 
1110  include_once("./Services/InfoScreen/classes/class.ilInfoScreenGUI.php");
1111  $info = new ilInfoScreenGUI($this);
1112 
1113  $info->enablePrivateNotes();
1114 
1115  if ($ilAccess->checkAccess("read", "", $_GET["ref_id"]))
1116  {
1117  $info->enableNews();
1118  }
1119 
1120  // no news editing for files, just notifications
1121  $info->enableNewsEditing(false);
1122  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"]))
1123  {
1124  $news_set = new ilSetting("news");
1125  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
1126 
1127  if ($enable_internal_rss)
1128  {
1129  $info->setBlockProperty("news", "settings", true);
1130  $info->setBlockProperty("news", "public_notifications_option", true);
1131  }
1132  }
1133 
1134  // forward the command
1135  if ($ilCtrl->getNextClass() == "ilinfoscreengui")
1136  {
1137  $ilCtrl->forwardCommand($info);
1138  }
1139  else
1140  {
1141  return $ilCtrl->getHTML($info);
1142  }
1143  }
1144 
1145  protected function getLogReservationIds()
1146  {
1147  if($_POST["mrsv"])
1148  {
1149  return $_POST["mrsv"];
1150  }
1151  else if((int)$_GET["reservation_id"])
1152  {
1153  return array((int)$_GET["reservation_id"]);
1154  }
1155  }
1156 
1158  {
1159  global $ilCtrl, $lng, $tpl;
1160 
1161  $ids = $this->getLogReservationIds();
1162  if(!$ids)
1163  {
1164  $this->ctrl->redirect($this, 'log');
1165  }
1166 
1167  $this->tabs_gui->clearTargets();
1168  $this->tabs_gui->setBackTarget($lng->txt("back"),
1169  $ilCtrl->getLinkTarget($this, "log"));
1170 
1171  include_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
1172  $conf = new ilConfirmationGUI();
1173  $conf->setFormAction($ilCtrl->getFormAction($this, 'rsvCancel'));
1174  $conf->setHeaderText($lng->txt('book_confirm_cancel'));
1175  $conf->setConfirm($lng->txt('book_set_cancel'), 'rsvCancel');
1176  $conf->setCancel($lng->txt('cancel'), 'log');
1177 
1178  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
1179  include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
1180  foreach($ids as $id)
1181  {
1182  $rsv = new ilBookingReservation($id);
1183  $obj = new ilBookingObject($rsv->getObjectId());
1184 
1185  $details = $obj->getTitle();
1186  if($this->object->getScheduleType() != ilObjBookingPool::TYPE_NO_SCHEDULE)
1187  {
1188  $details .= ", ".ilDatePresentation::formatPeriod(
1189  new ilDateTime($rsv->getFrom(), IL_CAL_UNIX),
1190  new ilDateTime($rsv->getTo(), IL_CAL_UNIX));
1191  }
1192 
1193  $conf->addItem('rsv_id[]', $id, $details);
1194  }
1195 
1196  $tpl->setContent($conf->getHTML());
1197  }
1198 
1199  function rsvCancelObject()
1200  {
1201  global $ilAccess, $ilUser;
1202 
1203  $ids = $_POST["rsv_id"];
1204  if($ids)
1205  {
1206  include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
1207  foreach($ids as $id)
1208  {
1209  $obj = new ilBookingReservation($id);
1210 
1211  if (!$ilAccess->checkAccess("write", "", $this->ref_id) && $obj->getUserId() != $ilUser->getId())
1212  {
1213  ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
1214  $this->ctrl->redirect($this, 'log');
1215  }
1216 
1217  $obj->setStatus(ilBookingReservation::STATUS_CANCELLED);
1218  $obj->update();
1219 
1220  if($this->object->getScheduleType() != ilObjBookingPool::TYPE_NO_SCHEDULE)
1221  {
1222  // remove user calendar entry (#11086)
1223  $cal_entry_id = $obj->getCalendarEntry();
1224  if($cal_entry_id)
1225  {
1226  include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
1227  $entry = new ilCalendarEntry($cal_entry_id);
1228  $entry->delete();
1229  }
1230  }
1231  }
1232  }
1233 
1234  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
1235  $this->logObject();
1236  }
1237 
1238  /*
1239  function rsvUncancelObject()
1240  {
1241  global $ilAccess;
1242 
1243  if(!$ilAccess->checkAccess("write", "", $this->ref_id))
1244  {
1245  ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
1246  $this->ctrl->redirect($this, 'log');
1247  }
1248 
1249  $ids = $this->getLogReservationIds();
1250  if($ids)
1251  {
1252  include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
1253  foreach($ids as $id)
1254  {
1255  $obj = new ilBookingReservation($id);
1256  $obj->setStatus(NULL);
1257  $obj->update();
1258  }
1259  }
1260 
1261  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
1262  $this->logObject();
1263  }
1264  */
1265 
1266  function rsvInUseObject()
1267  {
1268  global $ilAccess;
1269 
1270  if(!$ilAccess->checkAccess("write", "", $this->ref_id))
1271  {
1272  ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
1273  $this->ctrl->redirect($this, 'log');
1274  }
1275 
1276  $ids = $this->getLogReservationIds();
1277  if($ids)
1278  {
1279  include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
1280  foreach($ids as $id)
1281  {
1282  $obj = new ilBookingReservation($id);
1283  $obj->setStatus(ilBookingReservation::STATUS_IN_USE);
1284  $obj->update();
1285  }
1286  }
1287 
1288  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
1289  $this->logObject();
1290  }
1291 
1293  {
1294  global $ilAccess;
1295 
1296  if(!$ilAccess->checkAccess("write", "", $this->ref_id))
1297  {
1298  ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
1299  $this->ctrl->redirect($this, 'log');
1300  }
1301 
1302  $ids = $this->getLogReservationIds();
1303  if($ids)
1304  {
1305  include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
1306  foreach($ids as $id)
1307  {
1308  $obj = new ilBookingReservation($id);
1309  $obj->setStatus(NULL);
1310  $obj->update();
1311  }
1312  }
1313 
1314  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
1315  $this->logObject();
1316  }
1317 
1319  {
1320  global $tpl, $ilCtrl;
1321 
1322  $this->tabs_gui->clearTargets();
1323 
1324  $user_id = (int)$_GET['user_id'];
1325 
1326  include_once 'Services/User/classes/class.ilPublicUserProfileGUI.php';
1327  $profile = new ilPublicUserProfileGUI($user_id);
1328  $profile->setBackUrl($this->ctrl->getLinkTarget($this, 'log'));
1329  $tpl->setContent($ilCtrl->getHTML($profile));
1330  }
1331 
1332  public function addLocatorItems()
1333  {
1334  global $ilLocator;
1335 
1336  if (is_object($this->object))
1337  {
1338  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, "render"), "", $_GET["ref_id"]);
1339  }
1340  }
1341 }
1342 
1343 ?>