ILIAS  release_4-3 Revision
 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  if ($ilAccess->checkAccess('write', '', $this->object->getRefId()) ||
214  $this->object->hasPublicLog())
215  {
216  $this->tabs_gui->addTab("log",
217  $this->lng->txt("book_log"),
218  $this->ctrl->getLinkTarget($this, "log"));
219  }
220 
221  if ($ilAccess->checkAccess('write', '', $this->object->getRefId()))
222  {
223  if($this->object->getScheduleType() != ilObjBookingPool::TYPE_NO_SCHEDULE)
224  {
225  $this->tabs_gui->addTab("schedules",
226  $this->lng->txt("book_schedules"),
227  $this->ctrl->getLinkTargetByClass("ilbookingschedulegui", "render"));
228  }
229 
230  $this->tabs_gui->addTab("settings",
231  $this->lng->txt("settings"),
232  $this->ctrl->getLinkTarget($this, "edit"));
233  }
234 
235  if($ilAccess->checkAccess('edit_permission', '', $this->object->getRefId()))
236  {
237  $this->tabs_gui->addTab("perm_settings",
238  $this->lng->txt("perm_settings"),
239  $this->ctrl->getLinkTargetByClass("ilpermissiongui", "perm"));
240  }
241  }
242 
246  function bookObject()
247  {
248  global $tpl;
249 
250  $this->tabs_gui->clearTargets();
251  $this->tabs_gui->setBackTarget($this->lng->txt('book_back_to_list'), $this->ctrl->getLinkTarget($this, 'render'));
252 
253  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
254  $obj = new ilBookingObject((int)$_GET['object_id']);
255 
256  $this->lng->loadLanguageModule("dateplaner");
257  $this->ctrl->setParameter($this, 'object_id', $obj->getId());
258 
259  if($this->object->getScheduleType() == ilObjBookingPool::TYPE_FIX_SCHEDULE)
260  {
261  include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
262  $schedule = new ilBookingSchedule($obj->getScheduleId());
263 
264  $tpl->setContent($this->renderSlots($schedule, array($obj->getId()), $obj->getTitle()));
265  }
266  else
267  {
268  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
269  $cgui = new ilConfirmationGUI();
270  $cgui->setHeaderText($this->lng->txt("book_confirm_booking_no_schedule"));
271 
272  $cgui->setFormAction($this->ctrl->getFormAction($this));
273  $cgui->setCancel($this->lng->txt("cancel"), "render");
274  $cgui->setConfirm($this->lng->txt("confirm"), "confirmedBooking");
275 
276  $cgui->addItem("object_id", $obj->getId(), $obj->getTitle());
277 
278  $tpl->setContent($cgui->getHTML());
279  }
280  }
281 
282  protected function renderSlots(ilBookingSchedule $schedule, array $object_ids, $title)
283  {
284  global $ilUser;
285 
286  // fix
287  if(!$schedule->getRaster())
288  {
289  $mytpl = new ilTemplate('tpl.booking_reservation_fix.html', true, true, 'Modules/BookingManager');
290 
291  $mytpl->setVariable('FORM_ACTION', $this->ctrl->getFormAction($this));
292  $mytpl->setVariable('TXT_TITLE', $this->lng->txt('book_reservation_title'));
293  $mytpl->setVariable('TXT_INFO', $this->lng->txt('book_reservation_fix_info'));
294  $mytpl->setVariable('TXT_OBJECT', $title);
295  $mytpl->setVariable('TXT_CMD_BOOK', $this->lng->txt('book_confirm_booking'));
296  $mytpl->setVariable('TXT_CMD_CANCEL', $this->lng->txt('cancel'));
297 
298  include_once 'Services/Calendar/classes/class.ilCalendarUserSettings.php';
299 
300  $user_settings = ilCalendarUserSettings::_getInstanceByUserId($ilUser->getId());
301 
302  $morning_aggr = $user_settings->getDayStart();
303  $evening_aggr = $user_settings->getDayEnd();
304  $hours = array();
305  for($i = $morning_aggr;$i <= $evening_aggr;$i++)
306  {
307  switch($user_settings->getTimeFormat())
308  {
310  if ($morning_aggr > 0 && $i == $morning_aggr)
311  {
312  $hours[$i] = sprintf('%02d:00',0)."-";
313  }
314  $hours[$i].= sprintf('%02d:00',$i);
315  if ($evening_aggr < 23 && $i == $evening_aggr)
316  {
317  $hours[$i].= "-".sprintf('%02d:00',23);
318  }
319  break;
320 
322  if ($morning_aggr > 0 && $i == $morning_aggr)
323  {
324  $hours[$i] = date('h a',mktime(0,0,0,1,1,2000))."-";
325  }
326  $hours[$i].= date('h a',mktime($i,0,0,1,1,2000));
327  if ($evening_aggr < 23 && $i == $evening_aggr)
328  {
329  $hours[$i].= "-".date('h a',mktime(23,0,0,1,1,2000));
330  }
331  break;
332  }
333  }
334 
335  if(isset($_GET['seed']))
336  {
337  $find_first_open = false;
338  $seed = new ilDate($_GET['seed'], IL_CAL_DATE);
339  }
340  else
341  {
342  $find_first_open = true;
343  $seed = new ilDate(time(), IL_CAL_UNIX);
344  }
345 
346  include_once 'Services/Calendar/classes/class.ilCalendarUtil.php';
347  include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
348  $week_start = $user_settings->getWeekStart();
349 
350  if(!$find_first_open)
351  {
352  $dates = array();
353  $this->buildDatesBySchedule($week_start, $hours, $schedule, $object_ids, $seed, $dates);
354  }
355  else
356  {
357  $dates = array();
358  $has_open_slot = $this->buildDatesBySchedule($week_start, $hours, $schedule, $object_ids, $seed, $dates);
359 
360  // find first open slot
361  if(!$has_open_slot)
362  {
363  // 1 year is limit for search
364  $limit = clone($seed);
365  $limit->increment(ilDate::YEAR, 1);
366  $limit = $limit->get(IL_CAL_UNIX);
367 
368  while(!$has_open_slot && $seed->get(IL_CAL_UNIX) < $limit)
369  {
370  $seed->increment(ilDate::WEEK, 1);
371 
372  $dates = array();
373  $has_open_slot = $this->buildDatesBySchedule($week_start, $hours, $schedule, $object_ids, $seed, $dates);
374  }
375  }
376  }
377 
378  include_once 'Services/Calendar/classes/class.ilCalendarHeaderNavigationGUI.php';
379  $navigation = new ilCalendarHeaderNavigationGUI($this,$seed,ilDateTime::WEEK,'book');
380  $mytpl->setVariable('NAVIGATION', $navigation->getHTML());
381 
382  foreach(ilCalendarUtil::_buildWeekDayList($seed,$week_start)->get() as $date)
383  {
384  $date_info = $date->get(IL_CAL_FKT_GETDATE,'','UTC');
385 
386  $mytpl->setCurrentBlock('weekdays');
387  $mytpl->setVariable('TXT_WEEKDAY', ilCalendarUtil:: _numericDayToString($date_info['wday']));
388  $mytpl->setVariable('TXT_DATE', $date_info['mday'].' '.ilCalendarUtil:: _numericMonthToString($date_info['mon']));
389  $mytpl->parseCurrentBlock();
390  }
391 
392  include_once 'Services/Calendar/classes/class.ilCalendarAppointmentColors.php';
393  include_once 'Services/Calendar/classes/class.ilCalendarUtil.php';
394  $color = array();
396  for($loop = 0; $loop < 7; $loop++)
397  {
398  $col = $all[$loop];
400  $color[$loop+1] = 'border-bottom: 1px solid '.$col.'; background-color: '.$col.'; color: '.$fnt;
401  }
402 
403  $counter = 0;
404  foreach($dates as $hour => $days)
405  {
406  $caption = $days;
407  $caption = array_shift($caption);
408 
409  for($loop = 1; $loop < 8; $loop++)
410  {
411  if(!isset($days[$loop]))
412  {
413  $mytpl->setCurrentBlock('dates');
414  $mytpl->setVariable('DUMMY', '&nbsp;');
415  $mytpl->parseCurrentBlock();
416  }
417  else
418  {
419  if(isset($days[$loop]['captions']))
420  {
421  foreach($days[$loop]['captions'] as $slot_id => $slot_caption)
422  {
423  $mytpl->setCurrentBlock('choice');
424  $mytpl->setVariable('TXT_DATE', $slot_caption);
425  $mytpl->setVariable('VALUE_DATE', $slot_id);
426  $mytpl->setVariable('DATE_COLOR', $color[$loop]);
427  $mytpl->parseCurrentBlock();
428  }
429 
430  $mytpl->setCurrentBlock('dates');
431  $mytpl->setVariable('DUMMY', '');
432  $mytpl->parseCurrentBlock();
433  }
434  else if(isset($days[$loop]['in_slot']))
435  {
436  $mytpl->setCurrentBlock('dates');
437  $mytpl->setVariable('DATE_COLOR', $color[$loop]);
438  $mytpl->parseCurrentBlock();
439  }
440  else
441  {
442  $mytpl->setCurrentBlock('dates');
443  $mytpl->setVariable('DUMMY', '&nbsp;');
444  $mytpl->parseCurrentBlock();
445  }
446  }
447  }
448 
449  $mytpl->setCurrentBlock('slots');
450  $mytpl->setVariable('TXT_HOUR', $caption);
451  if($counter%2)
452  {
453  $mytpl->setVariable('CSS_ROW', 'tblrow1');
454  }
455  else
456  {
457  $mytpl->setVariable('CSS_ROW', 'tblrow2');
458  }
459  $mytpl->parseCurrentBlock();
460 
461  $counter++;
462  }
463  }
464  // flexible
465  else
466  {
467  // :TODO: inactive for now
468  }
469 
470  return $mytpl->get();
471  }
472 
473  protected function buildDatesBySchedule($week_start, array $hours, $schedule, array $object_ids, $seed, array &$dates)
474  {
475  global $ilUser;
476 
477  include_once 'Services/Calendar/classes/class.ilCalendarUserSettings.php';
478  $user_settings = ilCalendarUserSettings::_getInstanceByUserId($ilUser->getId());
479 
480  $map = array('mo', 'tu', 'we', 'th', 'fr', 'sa', 'su');
481  $definition = $schedule->getDefinition();
482 
483  $has_open_slot = false;
484  foreach(ilCalendarUtil::_buildWeekDayList($seed,$week_start)->get() as $date)
485  {
486  $date_info = $date->get(IL_CAL_FKT_GETDATE,'','UTC');
487 
488  $slots = array();
489  if(isset($definition[$map[$date_info['isoday']-1]]))
490  {
491  $slots = array();
492  foreach($definition[$map[$date_info['isoday']-1]] as $slot)
493  {
494  $slot = explode('-', $slot);
495  $slots[] = array('from'=>str_replace(':', '', $slot[0]),
496  'to'=>str_replace(':', '', $slot[1]));
497  }
498  }
499 
500  $last = array_pop(array_keys($hours));
501  $slot_captions = array();
502  foreach($hours as $hour => $period)
503  {
504  $dates[$hour][0] = $period;
505 
506  $period = explode("-", $period);
507 
508  // #13738
509  if($user_settings->getTimeFormat() == ilCalendarSettings::TIME_FORMAT_12)
510  {
511  if(stristr($period[0], "pm"))
512  {
513  $period[0] = (int)$period[0]+12;
514  }
515  else
516  {
517  $period[0] = (int)$period[0];
518  if($period[0] == 12)
519  {
520  $period[0] = 0;
521  }
522  }
523  if(sizeof($period) == 2)
524  {
525  if(stristr($period[1], "pm"))
526  {
527  $period[1] = (int)$period[1]+12;
528  }
529  else
530  {
531  $period[1] = (int)$period[1];
532  if($period[1] == 12)
533  {
534  $period[1] = 0;
535  }
536  }
537  }
538  }
539 
540  if(sizeof($period) == 1)
541  {
542  $period_from = (int)substr($period[0], 0, 2)."00";
543  $period_to = (int)substr($period[0], 0, 2)."59";
544  }
545  else
546  {
547  $period_from = (int)substr($period[0], 0, 2)."00";
548  $period_to = (int)substr($period[1], 0, 2)."59";
549  }
550 
551  $column = $date_info['isoday'];
552  if(!$week_start)
553  {
554  if($column < 7)
555  {
556  $column++;
557  }
558  else
559  {
560  $column = 1;
561  }
562  }
563 
564  if(sizeof($slots))
565  {
566  $in = false;
567  foreach($slots as $slot)
568  {
569  $slot_from = mktime(substr($slot['from'], 0, 2), substr($slot['from'], 2, 2), 0, $date_info["mon"], $date_info["mday"], $date_info["year"]);
570  $slot_to = mktime(substr($slot['to'], 0, 2), substr($slot['to'], 2, 2), 0, $date_info["mon"], $date_info["mday"], $date_info["year"]);
571 
572  // check deadline
573  if($slot_from < (time()+$schedule->getDeadline()*60*60) || !ilBookingReservation::getAvailableObject($object_ids, $slot_from, $slot_to-1))
574  {
575  continue;
576  }
577 
578  // is slot active in current hour?
579  if((int)$slot['from'] < $period_to && (int)$slot['to'] > $period_from)
580  {
581  $from = ilDatePresentation::formatDate(new ilDateTime($slot_from, IL_CAL_UNIX));
582  $from = array_pop(explode(' ', $from));
584  $to = array_pop(explode(' ', $to));
585 
586  // show caption (first hour) of slot
587  $id = $slot_from.'_'.$slot_to;
588  if(!in_array($id, $slot_captions))
589  {
590  $dates[$hour][$column]['captions'][$id] = $from.'-'.$to;
591  $slot_captions[] = $id;
592  }
593 
594  $in = true;
595  }
596  }
597  // (any) active slot
598  if($in)
599  {
600  $has_open_slot = true;
601  $dates[$hour][$column]['in_slot'] = $in;
602  }
603  }
604  }
605  }
606 
607  return $has_open_slot;
608  }
609 
614  {
615  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
616  include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
617 
618  $success = false;
619 
620  if($this->object->getScheduleType() == ilObjBookingPool::TYPE_NO_SCHEDULE)
621  {
622  if($_POST['object_id'])
623  {
624  $object_id = $_POST['object_id'];
625  if($object_id)
626  {
628  {
629  $this->processBooking($object_id);
630  $success = $object_id;
631  }
632  else
633  {
634  // #11852
635  ilUtil::sendFailure($this->lng->txt('book_reservation_failed_overbooked'), true);
636  $this->ctrl->redirect($this, 'render');
637  }
638  }
639  }
640  }
641  else
642  {
643  if(!isset($_POST['date']))
644  {
645  ilUtil::sendFailure($this->lng->txt('select_one'));
646  return $this->bookObject();
647  }
648 
649  // single object reservation(s)
650  if(isset($_GET['object_id']))
651  {
652  $object_id = (int)$_GET['object_id'];
653  if($object_id)
654  {
655  foreach($_POST['date'] as $date)
656  {
657  $fromto = explode('_', $date);
658  $fromto[1]--;
659 
660  if(ilBookingReservation::getAvailableObject(array($object_id), $fromto[0], $fromto[1]));
661  {
662  $this->processBooking($object_id, $fromto[0], $fromto[1]);
663  $success = $object_id;
664  }
665  }
666  }
667  }
668  /*
669  // group object reservation(s)
670  else
671  {
672  $all_object_ids = array();
673  foreach(ilBookingObject::getList((int)$_GET['type_id']) as $item)
674  {
675  $all_object_ids[] = $item['booking_object_id'];
676  }
677 
678  $possible_objects = $counter = array();
679  sort($_POST['date']);
680  foreach($_POST['date'] as $date)
681  {
682  $fromto = explode('_', $date);
683  $fromto[1]--;
684  $possible_objects[$date] = ilBookingReservation::getAvailableObject($all_object_ids, $fromto[0], $fromto[1], false);
685  foreach($possible_objects[$date] as $obj_id)
686  {
687  $counter[$obj_id]++;
688  }
689  }
690 
691  if(max($counter))
692  {
693  // we prefer the objects which are available for most slots
694  arsort($counter);
695  $counter = array_keys($counter);
696 
697  // book each slot
698  foreach($possible_objects as $date => $available_ids)
699  {
700  $fromto = explode('_', $date);
701  $fromto[1]--;
702 
703  // find "best" object for slot
704  foreach($counter as $best_object_id)
705  {
706  if(in_array($best_object_id, $available_ids))
707  {
708  $object_id = $best_object_id;
709  break;
710  }
711  }
712  $this->processBooking($object_id, $fromto[0], $fromto[1]);
713  $success = true;
714  }
715  }
716  }
717  */
718  }
719 
720  if($success)
721  {
722  ilUtil::sendSuccess($this->lng->txt('book_reservation_confirmed'), true);
723 
724  // show post booking information?
725  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
726  $obj = new ilBookingObject($success);
727  $pfile = $obj->getPostFile();
728  $ptext = $obj->getPostText();
729  if(trim($ptext) || $pfile)
730  {
731  $this->ctrl->setParameterByClass('ilbookingobjectgui', 'object_id', $obj->getId());
732  $this->ctrl->redirectByClass('ilbookingobjectgui', 'displayPostInfo');
733  }
734  else
735  {
736  $this->ctrl->redirect($this, 'render');
737  }
738  }
739  else
740  {
741  ilUtil::sendFailure($this->lng->txt('book_reservation_failed'), true);
742  $this->ctrl->redirect($this, 'book');
743  }
744  }
745 
753  function processBooking($a_object_id, $a_from = null, $a_to = null)
754  {
755  global $ilUser, $ilAccess;
756 
757  // #11995
758  if(!$ilAccess->checkAccess('read', '', $this->object->getRefId()))
759  {
760  $this->ilias->raiseError($this->lng->txt("msg_no_perm_read"),$this->ilias->error_obj->MESSAGE);
761  };
762 
763  include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
764  $reservation = new ilBookingReservation();
765  $reservation->setObjectId($a_object_id);
766  $reservation->setUserId($ilUser->getID());
767  $reservation->setFrom($a_from);
768  $reservation->setTo($a_to);
769  $reservation->save();
770 
771  if($a_from)
772  {
773  $this->lng->loadLanguageModule('dateplaner');
774  include_once 'Services/Calendar/classes/class.ilCalendarUtil.php';
775  include_once 'Services/Calendar/classes/class.ilCalendarCategory.php';
776  $def_cat = ilCalendarUtil::initDefaultCalendarByType(ilCalendarCategory::TYPE_BOOK,$ilUser->getId(),$this->lng->txt('cal_ch_personal_book'),true);
777 
778  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
779  $object = new ilBookingObject($a_object_id);
780 
781  include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
782  $entry = new ilCalendarEntry;
783  $entry->setStart(new ilDateTime($a_from, IL_CAL_UNIX));
784  $entry->setEnd(new ilDateTime($a_to, IL_CAL_UNIX));
785  $entry->setTitle($this->lng->txt('book_cal_entry').' '.$object->getTitle());
786  $entry->setContextId($reservation->getId());
787  $entry->save();
788 
789  include_once 'Services/Calendar/classes/class.ilCalendarCategoryAssignments.php';
790  $assignment = new ilCalendarCategoryAssignments($entry->getEntryId());
791  $assignment->addAssignment($def_cat->getCategoryId());
792  }
793  }
794 
798  function logObject()
799  {
800  global $tpl;
801 
802  $this->tabs_gui->setTabActive('log');
803 
804  include_once 'Modules/BookingManager/classes/class.ilBookingReservationsTableGUI.php';
805  $table = new ilBookingReservationsTableGUI($this, 'log', $this->ref_id,
806  $this->object->getId(), ($this->object->getScheduleType() != ilObjBookingPool::TYPE_NO_SCHEDULE));
807  $tpl->setContent($table->getHTML());
808  }
809 
814  {
815  global $ilAccess;
816 
817  $this->tabs_gui->setTabActive('log');
818 
819  if(!$_POST['reservation_id'])
820  {
821  ilUtil::sendFailure($this->lng->txt('select_one'));
822  return $this->logObject();
823  }
824 
825  if ($ilAccess->checkAccess('write', '', $this->object->getRefId()))
826  {
827  include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
828  ilBookingReservation::changeStatus($_POST['reservation_id'], (int)$_POST['tstatus']);
829  }
830 
831  ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
832  return $this->ctrl->redirect($this, 'log');
833  }
834 
839  {
840  include_once 'Modules/BookingManager/classes/class.ilBookingReservationsTableGUI.php';
841  $table = new ilBookingReservationsTableGUI($this, 'log', $this->ref_id,
842  $this->object->getId(), ($this->object->getScheduleType() != ilObjBookingPool::TYPE_NO_SCHEDULE));
843  $table->resetOffset();
844  $table->writeFilterToSession();
845  $this->logObject();
846  }
847 
852  {
853  include_once 'Modules/BookingManager/classes/class.ilBookingReservationsTableGUI.php';
854  $table = new ilBookingReservationsTableGUI($this, 'log', $this->ref_id,
855  $this->object->getId(), ($this->object->getScheduleType() != ilObjBookingPool::TYPE_NO_SCHEDULE));
856  $table->resetOffset();
857  $table->resetFilter();
858  $this->logObject();
859  }
860 
861  function _goto($a_target)
862  {
863  global $ilAccess, $ilErr, $lng;
864 
865  if ($ilAccess->checkAccess("read", "", $a_target))
866  {
867  ilObjectGUI::_gotoRepositoryNode($a_target, "render");
868  }
869  else if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID))
870  {
871  ilUtil::sendFailure(sprintf($lng->txt("msg_no_perm_read_item"),
874  }
875 
876  $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
877  }
878 
884  function infoScreenObject()
885  {
886  $this->ctrl->setCmd("showSummary");
887  $this->ctrl->setCmdClass("ilinfoscreengui");
888  $this->infoScreen();
889  }
890 
891  function infoScreen()
892  {
893  global $ilAccess, $ilCtrl;
894 
895  $this->tabs_gui->setTabActive('info');
896 
897  if (!$ilAccess->checkAccess("visible", "", $this->ref_id))
898  {
899  $this->ilias->raiseError($this->lng->txt("msg_no_perm_read"),$this->ilias->error_obj->MESSAGE);
900  }
901 
902  include_once("./Services/InfoScreen/classes/class.ilInfoScreenGUI.php");
903  $info = new ilInfoScreenGUI($this);
904 
905  $info->enablePrivateNotes();
906 
907  if ($ilAccess->checkAccess("read", "", $_GET["ref_id"]))
908  {
909  $info->enableNews();
910  }
911 
912  // no news editing for files, just notifications
913  $info->enableNewsEditing(false);
914  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"]))
915  {
916  $news_set = new ilSetting("news");
917  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
918 
919  if ($enable_internal_rss)
920  {
921  $info->setBlockProperty("news", "settings", true);
922  $info->setBlockProperty("news", "public_notifications_option", true);
923  }
924  }
925 
926  // forward the command
927  if ($ilCtrl->getNextClass() == "ilinfoscreengui")
928  {
929  $ilCtrl->forwardCommand($info);
930  }
931  else
932  {
933  return $ilCtrl->getHTML($info);
934  }
935  }
936 
937  function rsvCancelObject()
938  {
939  global $ilAccess, $ilUser;
940 
941  $this->tabs_gui->setTabActive('log');
942 
943  $id = (int)$_GET['reservation_id'];
944  include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
945  $obj = new ilBookingReservation($id);
946 
947  if (!$ilAccess->checkAccess("write", "", $this->ref_id) && $obj->getUserId() != $ilUser->getId())
948  {
949  ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
950  $this->ctrl->redirect($this, 'log');
951  }
952 
954  $obj->update();
955 
956  if($this->object->getScheduleType() != ilObjBookingPool::TYPE_NO_SCHEDULE)
957  {
958  // remove user calendar entry (#11086)
959  $cal_entry_id = $obj->getCalendarEntry();
960  if($cal_entry_id)
961  {
962  include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
963  $entry = new ilCalendarEntry($cal_entry_id);
964  $entry->delete();
965  }
966  }
967 
968  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
969  $this->logObject();
970  }
971 
972  function rsvUncancelObject()
973  {
974  global $ilAccess;
975 
976  $this->tabs_gui->setTabActive('log');
977 
978  if (!$ilAccess->checkAccess("write", "", $this->ref_id))
979  {
980  ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
981  $this->ctrl->redirect($this, 'log');
982  }
983 
984  $id = (int)$_GET['reservation_id'];
985  include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
986  $obj = new ilBookingReservation($id);
987  $obj->setStatus(NULL);
988  $obj->update();
989 
990  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
991  $this->logObject();
992  }
993 
994  function rsvInUseObject()
995  {
996  global $ilAccess;
997 
998  $this->tabs_gui->setTabActive('log');
999 
1000  if (!$ilAccess->checkAccess("write", "", $this->ref_id))
1001  {
1002  ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
1003  $this->ctrl->redirect($this, 'log');
1004  }
1005 
1006  $id = (int)$_GET['reservation_id'];
1007  include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
1008  $obj = new ilBookingReservation($id);
1009  $obj->setStatus(ilBookingReservation::STATUS_IN_USE);
1010  $obj->update();
1011 
1012  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
1013  $this->logObject();
1014  }
1015 
1017  {
1018  global $ilAccess;
1019 
1020  $this->tabs_gui->setTabActive('log');
1021 
1022  if (!$ilAccess->checkAccess("write", "", $this->ref_id))
1023  {
1024  ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
1025  $this->ctrl->redirect($this, 'log');
1026  }
1027 
1028  $id = (int)$_GET['reservation_id'];
1029  include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
1030  $obj = new ilBookingReservation($id);
1031  $obj->setStatus(NULL);
1032  $obj->update();
1033 
1034  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
1035  $this->logObject();
1036  }
1037 
1039  {
1040  global $tpl, $ilCtrl;
1041 
1042  $this->tabs_gui->clearTargets();
1043 
1044  $user_id = (int)$_GET['user_id'];
1045 
1046  include_once 'Services/User/classes/class.ilPublicUserProfileGUI.php';
1047  $profile = new ilPublicUserProfileGUI($user_id);
1048  $profile->setBackUrl($this->ctrl->getLinkTarget($this, 'log'));
1049  $tpl->setContent($ilCtrl->getHTML($profile));
1050  }
1051 
1052  public function addLocatorItems()
1053  {
1054  global $ilLocator;
1055 
1056  if (is_object($this->object))
1057  {
1058  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, "render"), "", $_GET["ref_id"]);
1059  }
1060  }
1061 }
1062 
1063 ?>