ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilCalendarAppointmentGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2014 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
6 
13 {
14  protected $seed = null;
15  protected $initialDate = null;
16  protected $default_fulltime = true;
17 
18  protected $app = null;
19  protected $rec = null;
20  protected $timezone = null;
21 
22  protected $tpl;
23  protected $lng;
24  protected $ctrl;
25 
29  protected $request;
30 
34  private $logger = null;
35 
43  public function __construct(ilDate $seed, ilDate $initialDate, $a_appointment_id = 0)
44  {
45  global $DIC;
46 
47  $this->lng = $DIC->language();
48  $this->lng->loadLanguageModule('dateplaner');
49  $this->ctrl = $DIC->ctrl();
50  $this->tpl = $DIC->ui()->mainTemplate();
51  $this->logger = $GLOBALS['DIC']->logger()->cal();
52  $this->request = $DIC->http()->request();
53 
54  $this->initTimeZone();
55  $this->initSeed($seed);
56  $this->initInitialDate($initialDate);
57  $this->initAppointment($a_appointment_id);
58  }
59 
60  public function executeCommand()
61  {
62  global $DIC;
63 
64  $ilUser = $DIC['ilUser'];
65  $ilSetting = $DIC['ilSetting'];
66  $tpl = $DIC['tpl'];
67  $ilTabs = $DIC['ilTabs'];
68 
69 
70  // Clear tabs and set back target
71  $ilTabs->clearTargets();
72  $ilTabs->setBackTarget(
73  $this->lng->txt('cal_back_to_cal'),
74  $this->ctrl->getLinkTarget($this, 'cancel')
75  );
76 
77  $next_class = $this->ctrl->getNextClass($this);
78  switch ($next_class) {
79 
80  default:
81  $cmd = $this->ctrl->getCmd("add");
82  $this->$cmd();
83  break;
84  }
85  }
86 
91  public function getAppointment()
92  {
93  return $this->app;
94  }
95 
103  protected function cancel()
104  {
105  $this->ctrl->returnToParent($this);
106  }
107 
115  protected function initForm($a_mode, $a_as_milestone = false, $a_edit_single_app = false)
116  {
117  global $DIC;
118 
119  $ilUser = $DIC['ilUser'];
120  $tpl = $DIC['tpl'];
121 
122  $this->form = new ilPropertyFormGUI();
123 
124  include_once('./Services/YUI/classes/class.ilYuiUtil.php');
126  $resp_info = false;
127  switch ($a_mode) {
128  case 'create':
129  $this->ctrl->saveParameter($this, array('seed','idate'));
130  $this->form->setFormAction($this->ctrl->getFormAction($this));
131  if ($a_as_milestone) {
132  $this->form->setTitle($this->lng->txt('cal_new_ms'));
133  $this->form->addCommandButton('saveMilestone', $this->lng->txt('cal_add_milestone'));
134  $this->form->addCommandButton('cancel', $this->lng->txt('cancel'));
135  } else {
136  $this->form->setTitle($this->lng->txt('cal_new_app'));
137  $this->form->addCommandButton('save', $this->lng->txt('cal_add_appointment'));
138  $this->form->addCommandButton('cancel', $this->lng->txt('cancel'));
139  }
140  break;
141 
142  case 'edit':
143  if ($a_as_milestone) {
144  $this->form->setTitle($this->lng->txt('cal_edit_milestone'));
145  } else {
146  $this->form->setTitle($this->lng->txt('cal_edit_appointment'));
147  }
148  $this->ctrl->saveParameter($this, array('seed','app_id','idate'));
149  $this->form->setFormAction($this->ctrl->getFormAction($this));
150 
151  $ass = new ilCalendarCategoryAssignments($this->app->getEntryId());
152  $cat = $ass->getFirstAssignment();
153  include_once('./Services/Calendar/classes/class.ilCalendarCategory.php');
154  $cat_info = ilCalendarCategories::_getInstance()->getCategoryInfo($cat);
155  $type = ilObject::_lookupType($cat_info['obj_id']);
156  if ($a_as_milestone && $cat_info['type'] == ilCalendarCategory::TYPE_OBJ
157  && ($type == "grp" || $type == "crs")) {
158  $resp_info = true;
159  $this->form->addCommandButton('editResponsibleUsers', $this->lng->txt('cal_change_responsible_users'));
160  }
161  $this->form->addCommandButton('update', $this->lng->txt('save'));
162  // $this->form->addCommandButton('askDelete',$this->lng->txt('delete'));
163  $this->form->addCommandButton('cancel', $this->lng->txt('cancel'));
164  break;
165  }
166  // title
167  $title = new ilTextInputGUI($this->lng->txt('title'), 'title');
168  $title->setValue($this->app->getTitle());
169  $title->setRequired(true);
170  $title->setMaxLength(128);
171  $title->setSize(32);
172  $this->form->addItem($title);
173 
174  // calendar selection
175  $calendar = new ilSelectInputGUI($this->lng->txt('cal_category_selection'), 'calendar');
176  if ($_POST['category']) {
177  $calendar->setValue((int) $_POST['calendar']);
178  $selected_calendar = (int) $_POST['calendar'];
179  } elseif ($_GET['category_id']) {
180  $calendar->setValue((int) $_GET['category_id']);
181  $selected_calendar = (int) $_GET['category_id'];
182  } elseif ($a_mode == 'edit') {
183  $ass = new ilCalendarCategoryAssignments($this->app->getEntryId());
184  $cat = $ass->getFirstAssignment();
185  $calendar->setValue($cat);
186  $selected_calendar = $cat;
187  } elseif (isset($_GET['ref_id'])) {
188  include_once('./Services/Calendar/classes/class.ilCalendarCategories.php');
189  $obj_cal = ilObject::_lookupObjId($_GET['ref_id']);
190  $calendar->setValue(ilCalendarCategories::_lookupCategoryIdByObjId($obj_cal));
191  $selected_calendar = ilCalendarCategories::_lookupCategoryIdByObjId($obj_cal);
193  $cats->readSingleCalendar($selected_calendar);
194  } else {
196  $categories = $cats->prepareCategoriesOfUserForSelection();
197  $selected_calendar = key((array) $categories);
198  $calendar->setValue($selected_calendar);
199  }
200  $calendar->setRequired(true);
202  $calendar->setOptions($cats->prepareCategoriesOfUserForSelection());
203 
204  include_once './Services/Calendar/classes/class.ilCalendarSettings.php';
205  if (ilCalendarSettings::_getInstance()->isNotificationEnabled()) {
206  $notification_cals = $cats->getNotificationCalendars();
207  $notification_cals = count($notification_cals) ? implode(',', $notification_cals) : '';
208  $calendar->addCustomAttribute("onchange=\"ilToggleNotification([" . $notification_cals . "]);\"");
209  }
210  $this->form->addItem($calendar);
211 
212  if (!$a_as_milestone) {
213  include_once './Services/Form/classes/class.ilDateDurationInputGUI.php';
214  $tpl->addJavaScript('./Services/Form/js/date_duration.js');
215  $dur = new ilDateDurationInputGUI($this->lng->txt('cal_fullday'), 'event');
216  $dur->setRequired(true);
217  $dur->enableToggleFullTime(
218  $this->lng->txt('cal_fullday_title'),
219  $this->app->isFullday() ? true : false
220  );
221  $dur->setShowTime(true);
222  $dur->setStart($this->app->getStart());
223  $dur->setEnd($this->app->getEnd());
224  $this->form->addItem($dur);
225 
226  // recurrence
227  include_once('./Services/Calendar/classes/Form/class.ilRecurrenceInputGUI.php');
228  $rec = new ilRecurrenceInputGUI($this->lng->txt('cal_recurrences'), 'frequence');
229  $rec->setRecurrence($this->rec);
230  $this->form->addItem($rec);
231 
232  // location
233  $where = new ilTextInputGUI($this->lng->txt('cal_where'), 'location');
234  $where->setValue($this->app->getLocation());
235  $where->setMaxLength(128);
236  $where->setSize(32);
237  $this->form->addItem($where);
238  } else {
239  $deadline = new ilDateTimeInputGUI($this->lng->txt('cal_deadline'), 'event_start');
240  $deadline->setDate($this->app->getStart());
241  $deadline->setShowTime(false);
242  $deadline->setMinuteStepSize(5);
243  $this->form->addItem($deadline);
244 
245  // completion
246  $completion_vals = array();
247  for ($i = 0; $i <= 100; $i += 5) {
248  $completion_vals[$i] = $i . " %";
249  }
250  $compl = new ilSelectInputGUI(
251  $this->lng->txt('cal_task_completion'),
252  'completion'
253  );
254  $compl->setOptions($completion_vals);
255  $compl->setValue($this->app->getCompletion());
256  $this->form->addItem($compl);
257  }
258 
259  $desc = new ilTextAreaInputGUI($this->lng->txt('description'), 'description');
260  $desc->setValue($this->app->getDescription());
261  $desc->setRows(5);
262  $this->form->addItem($desc);
263 
264  if ($a_as_milestone && $a_mode == "edit" && $resp_info) {
265  // users responsible
266  $users = $this->app->readResponsibleUsers();
267  $resp = new ilNonEditableValueGUI($this->lng->txt('cal_responsible'), "", true);
268  $delim = "";
269  foreach ($users as $r) {
270  $value .= $delim . $r["lastname"] . ", " . $r["firstname"] . " [" . $r["login"] . "]";
271  $delim = "<br />";
272  }
273  if (count($users) > 0) {
274  $resp->setValue($value);
275  } else {
276  $resp->setValue("-");
277  }
278 
279  $this->form->addItem($resp);
280  }
281 
282 
283  if (ilCalendarSettings::_getInstance()->isUserNotificationEnabled()) {
284  $notu = new ilTextWizardInputGUI($this->lng->txt('cal_user_notification'), 'notu');
285  $notu->setInfo($this->lng->txt('cal_user_notification_info'));
286  $notu->setSize(20);
287  $notu->setMaxLength(64);
288 
289  $values = array();
290  foreach ($this->notification->getRecipients() as $rcp) {
291  switch ($rcp['type']) {
293  $values[] = ilObjUser::_lookupLogin($rcp['usr_id']);
294  break;
295 
297  $values[] = $rcp['email'];
298  break;
299  }
300  }
301  if (count($values)) {
302  $notu->setValues($values);
303  } else {
304  $notu->setValues(array(''));
305  }
306  $this->form->addItem($notu);
307  }
308 
309  // Notifications
310  include_once './Services/Calendar/classes/class.ilCalendarSettings.php';
311  if (ilCalendarSettings::_getInstance()->isNotificationEnabled() and count($cats->getNotificationCalendars())) {
312  $selected_cal = new ilCalendarCategory($selected_calendar);
313  $disabled = true;
314  if ($selected_cal->getType() == ilCalendarCategory::TYPE_OBJ) {
315  if (ilObject::_lookupType($selected_cal->getObjId()) == 'crs' or ilObject::_lookupType($selected_cal->getObjId()) == 'grp') {
316  $disabled = false;
317  }
318  }
319 
320  $tpl->addJavaScript('./Services/Calendar/js/toggle_notification.js');
321  $not = new ilCheckboxInputGUI($this->lng->txt('cal_cg_notification'), 'not');
322  $not->setInfo($this->lng->txt('cal_notification_info'));
323  $not->setValue(1);
324  $not->setChecked($this->app->isNotificationEnabled());
325  $not->setDisabled($disabled);
326  $this->form->addItem($not);
327  }
328  }
329 
330 
338  protected function add(ilPropertyFormGUI $form = null)
339  {
340  global $DIC;
341 
342  $ilHelp = $DIC->help();
343 
344  $ilHelp->setScreenIdComponent("cal");
345  $ilHelp->setScreenId("app");
346  $ilHelp->setSubScreenId("create");
347 
348  if (!$form instanceof ilPropertyFormGUI) {
349  $this->initForm('create');
350  }
351  $this->tpl->setContent($this->form->getHTML());
352  }
353 
360  protected function addMilestone()
361  {
362  global $DIC;
363 
364  $tpl = $DIC['tpl'];
365  $ilHelp = $DIC['ilHelp'];
366 
367  $ilHelp->setScreenIdComponent("cal");
368  $ilHelp->setScreenId("app");
369  $ilHelp->setSubScreenId("create_milestone");
370 
371  $this->initForm('create', true);
372  $tpl->setContent($this->form->getHTML());
373  }
374 
380  protected function saveMilestone()
381  {
382  $this->save(true);
383  }
384 
390  protected function save($a_as_milestone = false)
391  {
392  global $DIC;
393 
394  $ilErr = $DIC['ilErr'];
395 
396  $this->load('create', $a_as_milestone);
397 
398  if ($this->app->validate() and $this->notification->validate()) {
399  if (!(int) $_POST['calendar']) {
400  $cat_id = $this->createDefaultCalendar();
401  } else {
402  $cat_id = (int) $_POST['calendar'];
403  }
404 
405  $this->app->save();
406  $this->notification->setEntryId($this->app->getEntryId());
407  $this->notification->save();
408  $this->rec->setEntryId($this->app->getEntryId());
409  $this->saveRecurrenceSettings();
410 
411  include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
412  $ass = new ilCalendarCategoryAssignments($this->app->getEntryId());
413  $ass->addAssignment($cat_id);
414 
415  // Send notifications
416  include_once './Services/Calendar/classes/class.ilCalendarSettings.php';
417  if (ilCalendarSettings::_getInstance()->isNotificationEnabled() and (bool) $_POST['not']) {
418  $this->distributeNotifications($cat_id, $this->app->getEntryId(), true);
419  }
420  if (ilCalendarSettings::_getInstance()->isUserNotificationEnabled()) {
422  }
423 
424  include_once('./Services/Calendar/classes/class.ilCalendarCategory.php');
425  $cat_info = ilCalendarCategories::_getInstance()->getCategoryInfo($cat_id);
426  $type = ilObject::_lookupType($cat_info['obj_id']);
427 
428  if ($a_as_milestone && $cat_info['type'] == ilCalendarCategory::TYPE_OBJ
429  && ($type == "grp" || $type == "crs")) {
430  ilUtil::sendSuccess($this->lng->txt('cal_created_milestone_resp_q'), true);
431  return $this->showResponsibleUsersList($cat_info['obj_id']);
432  } elseif ($a_as_milestone) {
433  ilUtil::sendSuccess($this->lng->txt('cal_created_milestone'), true);
434  $this->ctrl->returnToParent($this);
435  } else {
436  ilUtil::sendSuccess($this->lng->txt('cal_created_appointment'), true);
437  $this->ctrl->returnToParent($this);
438  }
439  } else {
440  $this->form->setValuesByPost();
441  ilUtil::sendFailure($ilErr->getMessage());
442  return $this->add($this->form);
443  }
444  if ($a_as_milestone) {
445  $this->addMilestone();
446  } else {
447  $this->add();
448  }
449  }
450 
455  protected function distributeUserNotifications()
456  {
457  global $DIC;
458 
459  $ilUser = $DIC['ilUser'];
460 
461  include_once './Services/Calendar/classes/class.ilCalendarMailNotification.php';
462  $notification = new ilCalendarMailNotification();
463  $notification->setAppointmentId($this->app->getEntryId());
464 
465  foreach ($this->notification->getRecipients() as $rcp) {
466  switch ($rcp['type']) {
468  $notification->setSender(ANONYMOUS_USER_ID);
469  $notification->setRecipients(array($rcp['usr_id']));
470  $notification->setType(ilCalendarMailNotification::TYPE_USER);
471  break;
472 
474  $notification->setSender(ANONYMOUS_USER_ID);
475  $notification->setRecipients(array($rcp['email']));
476  $notification->setType(ilCalendarMailNotification::TYPE_USER_ANONYMOUS);
477  break;
478  }
479  $notification->send();
480  }
481  }
482 
483 
488  protected function distributeNotifications($a_cat_id, $app_id, $a_new_appointment = true)
489  {
490  include_once('./Services/Calendar/classes/class.ilCalendarCategory.php');
491  $cat_info = ilCalendarCategories::_getInstance()->getCategoryInfo($a_cat_id);
492 
493  include_once './Services/Calendar/classes/class.ilCalendarMailNotification.php';
494  $notification = new ilCalendarMailNotification();
495  $notification->setAppointmentId($app_id);
496 
497  switch ($cat_info['type']) {
499 
500  switch ($cat_info['obj_type']) {
501  case 'crs':
502  $ref_ids = ilObject::_getAllReferences($cat_info['obj_id']);
503  $ref_id = current($ref_ids);
504  $notification->setRefId($ref_id);
505  $notification->setType(
506  $a_new_appointment ?
509  );
510  break;
511 
512  case 'grp':
513  $ref_ids = ilObject::_getAllReferences($cat_info['obj_id']);
514  $ref_id = current($ref_ids);
515  $notification->setRefId($ref_id);
516  $notification->setType(
517  $a_new_appointment ?
520  );
521  break;
522  }
523  break;
524  }
525 
526  $notification->send();
527  }
528 
532  public function editResponsibleUsers()
533  {
534  include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
535  $cat_id = ilCalendarCategoryAssignments::_lookupCategory($this->app->getEntryId());
536  include_once('./Services/Calendar/classes/class.ilCalendarCategory.php');
537  $cat_info = ilCalendarCategories::_getInstance()->getCategoryInfo($cat_id);
538 
539  $this->showResponsibleUsersList($cat_info['obj_id']);
540  }
541 
546  public function showResponsibleUsersList($a_grp_id)
547  {
548  global $DIC;
549 
550  $tpl = $DIC['tpl'];
551 
552  include_once("./Services/Calendar/classes/class.ilMilestoneResponsiblesTableGUI.php");
553  $table_gui = new ilMilestoneResponsiblesTableGUI(
554  $this,
555  "",
556  $a_grp_id,
557  $this->app->getEntryId()
558  );
559  $tpl->setContent($table_gui->getHTML());
560  }
561 
566  {
567  global $DIC;
568 
569  $ilCtrl = $DIC['ilCtrl'];
570 
571  $this->app->writeResponsibleUsers($_POST["user_id"]);
572  $ilCtrl->returnToParent($this);
573  }
574 
579  protected function askEdit()
580  {
581  // check for recurring entries
582  include_once './Services/Calendar/classes/class.ilCalendarRecurrences.php';
584  if (!$rec) {
585  return $this->edit(true);
586  }
587  // Show edit single/all appointments
588  $this->ctrl->saveParameter($this, array('seed','app_id','dt','idate'));
589 
590  include_once('./Services/Utilities/classes/class.ilConfirmationGUI.php');
591  $confirm = new ilConfirmationGUI();
592  $confirm->setFormAction($this->ctrl->getFormAction($this));
593  #$confirm->setHeaderText($this->lng->txt('cal_edit_app_sure'));
594  $confirm->setCancel($this->lng->txt('cancel'), 'cancel');
595  $confirm->addItem('appointments[]', $this->app->getEntryId(), $this->app->getTitle());
596  $confirm->addButton($this->lng->txt('cal_edit_single'), 'editSingle');
597  $confirm->setConfirm($this->lng->txt('cal_edit_recurrences'), 'edit');
598 
599  $GLOBALS['DIC']['tpl']->setContent($confirm->getHTML());
600  }
601 
605  protected function editSingle()
606  {
607  $_REQUEST['rexl'] = 1;
608  $GLOBALS['DIC']['ilCtrl']->setParameter($this, 'rexcl', 1);
609  $this->edit(true);
610  }
611 
620  protected function edit($a_edit_single_app = false, ilPropertyFormGUI $form = null)
621  {
622  global $DIC;
623 
624  $tpl = $DIC->ui()->mainTemplate();
625  $ilUser = $DIC['ilUser'];
626  $ilErr = $DIC['ilErr'];
627  $ilHelp = $DIC['ilHelp'];
628 
629  $ilHelp->setScreenIdComponent("cal");
630  $ilHelp->setScreenId("app");
631  if ($this->app->isMilestone()) {
632  $ilHelp->setSubScreenId("edit_milestone");
633  } else {
634  $ilHelp->setSubScreenId("edit");
635  }
636 
637  include_once('./Services/Calendar/classes/class.ilCalendarCategory.php');
638  include_once('./Services/Calendar/classes/class.ilCalendarCategories.php');
639  include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
640 
641  $GLOBALS['DIC']['ilCtrl']->saveParameter($this, array('seed','app_id','dt','idate'));
642 
643  if ($_REQUEST['rexl']) {
644  $GLOBALS['DIC']['ilCtrl']->setParameter($this, 'rexl', 1);
645  // Calculate new appointment time
646  $duration = $this->getAppointment()->getEnd()->get(IL_CAL_UNIX) - $this->getAppointment()->getStart()->get(IL_CAL_UNIX);
647  include_once './Services/Calendar/classes/class.ilCalendarRecurrenceCalculator.php';
648  $calc = new ilCalendarRecurrenceCalculator($this->getAppointment(), $this->rec);
649 
650  $current_date = new ilDateTime($_REQUEST['dt'], IL_CAL_UNIX);
651 
652  $yesterday = clone $current_date;
653  $yesterday->increment(IL_CAL_DAY, -1);
654  $tomorrow = clone $current_date;
655  $tomorrow->increment(IL_CAL_DAY, 1);
656 
657 
658  foreach ($calc->calculateDateList($current_date, $tomorrow, 1) as $date_entry) {
659  if (ilDateTime::_equals($current_date, $date_entry, IL_CAL_DAY)) {
660  $this->getAppointment()->setStart(new ilDateTime($date_entry->get(IL_CAL_UNIX), IL_CAL_UNIX));
661  $this->getAppointment()->setEnd(new ilDateTime($date_entry->get(IL_CAL_UNIX) + $duration, IL_CAL_UNIX));
662  break;
663  }
664  }
665 
666  // Finally reset recurrence
667  $this->rec = new ilCalendarRecurrence();
668  }
669 
670  $cat_id = ilCalendarCategoryAssignments::_lookupCategory($this->app->getEntryId());
672 
673  if (!$cats->isVisible($cat_id)) {
674  $ilErr->raiseError($this->lng->txt('permission_denied'), $ilErr->WARNING);
675  return false;
676  }
677  if (!$cats->isEditable($cat_id) or $this->app->isAutoGenerated()) {
678  $this->showInfoScreen();
679  return true;
680  }
681  if (!$form instanceof ilPropertyFormGUI) {
682  $this->initForm('edit', $this->app->isMilestone(), $a_edit_single_app);
683  }
684  $tpl->setContent($this->form->getHTML());
685  }
686 
693  protected function showInfoScreen()
694  {
695  global $DIC;
696 
697  $tpl = $DIC['tpl'];
698  $ilUser = $DIC['ilUser'];
699 
700  include_once("./Services/InfoScreen/classes/class.ilInfoScreenGUI.php");
701  $info = new ilInfoScreenGUI($this);
702  $info->setFormAction($this->ctrl->getFormAction($this));
703 
704  if ($this->app->isMilestone()) {
705  $info->addSection($this->lng->txt('cal_ms_details'));
706  } else {
707  $info->addSection($this->lng->txt('cal_details'));
708  }
709 
710  // Appointment
711  $info->addProperty(
712  $this->lng->txt('appointment'),
714  $this->app->getStart(),
715  $this->app->getEnd()
716  )
717  );
718  $info->addProperty($this->lng->txt('title'), $this->app->getPresentationTitle());
719 
720  // Description
721  if (strlen($desc = $this->app->getDescription())) {
722  $info->addProperty($this->lng->txt('description'), $desc);
723  }
724 
725  // Location
726  if (strlen($loc = $this->app->getLocation())) {
727  $info->addProperty($this->lng->txt('cal_where'), $loc);
728  }
729 
730  // completion
731  if ($this->app->isMilestone() && $this->app->getCompletion() > 0) {
732  $info->addProperty(
733  $this->lng->txt('cal_task_completion'),
734  $this->app->getCompletion() . " %"
735  );
736  }
737 
738  include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
739  $cat_id = ilCalendarCategoryAssignments::_lookupCategory($this->app->getEntryId());
740  $cat_info = ilCalendarCategories::_getInstance()->getCategoryInfo($cat_id);
741  $type = ilObject::_lookupType($cat_info['obj_id']);
742  if ($this->app->isMilestone() && $cat_info['type'] == ilCalendarCategory::TYPE_OBJ
743  && ($type == "grp" || $type == "crs")) {
744  // users responsible
745  $users = $this->app->readResponsibleUsers();
746  $delim = "";
747  foreach ($users as $r) {
748  $value .= $delim . $r["lastname"] . ", " . $r["firstname"] . " [" . $r["login"] . "]";
749  $delim = "<br />";
750  }
751  if (count($users) > 0) {
752  $info->addProperty(
753  $this->lng->txt('cal_responsible'),
754  $value
755  );
756  }
757  }
758 
759  $category = new ilCalendarCategory($cat_id);
760 
761  if ($category->getType() == ilCalendarCategory::TYPE_OBJ) {
762  $info->addSection($this->lng->txt('additional_info'));
763 
764  $cat_info = ilCalendarCategories::_getInstance()->getCategoryInfo($cat_id);
765  $refs = ilObject::_getAllReferences($cat_info['obj_id']);
766 
767  include_once('./Services/Link/classes/class.ilLink.php');
768  $href = ilLink::_getStaticLink(current($refs), ilObject::_lookupType($cat_info['obj_id']), true);
769  $info->addProperty($this->lng->txt('perma_link'), '<a class="small" href="' . $href . '" target="_top">' . $href . '</a>');
770  }
771 
772  $tpl->setContent($info->getHTML());
773  }
774 
781  protected function update()
782  {
783  global $DIC;
784 
785  $ilErr = $DIC['ilErr'];
786 
787  $single_editing = ($_REQUEST['rexl'] ? true : false);
788 
789  $this->load('edit', $this->app->isMilestone());
790  if ($this->app->validate() and $this->notification->validate()) {
791  if (!(int) $_POST['calendar']) {
792  $cat_id = $this->createDefaultCalendar();
793  } else {
794  $cat_id = (int) $_POST['calendar'];
795  }
796 
797  if ($single_editing) {
798  $original_id = $this->getAppointment()->getEntryId();
799  $this->getAppointment()->save();
800  $selected_ut = (int) ($this->request->getQueryParams()['dt'] ?? 0);
801  if ($selected_ut > 0) {
802  $exclusion = new ilCalendarRecurrenceExclusion();
803  $exclusion->setEntryId($original_id);
804  $exclusion->setDate(new ilDate($selected_ut, IL_CAL_UNIX));
805  $this->logger->dump($this->getAppointment()->getEntryId());
806  $this->logger->dump(ilDatePresentation::formatDate(new ilDate($selected_ut, IL_CAL_UNIX)));
807  $exclusion->save();
808  }
809  $this->rec = new ilCalendarRecurrence();
810  $this->rec->setEntryId($this->getAppointment()->getEntryId());
811  } else {
812  $this->getAppointment()->update();
813  }
814  $this->notification->save();
815  $this->saveRecurrenceSettings();
816  include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
817  $ass = new ilCalendarCategoryAssignments($this->app->getEntryId());
818  $this->logger->debug($this->app->getEntryId());
819  $ass->deleteAssignments();
820  $ass->addAssignment($cat_id);
821 
822  // Send notifications
823  include_once './Services/Calendar/classes/class.ilCalendarSettings.php';
824  if (ilCalendarSettings::_getInstance()->isNotificationEnabled() and (bool) $_POST['not']) {
825  $this->distributeNotifications($cat_id, $this->app->getEntryId(), false);
826  }
827  if (ilCalendarSettings::_getInstance()->isUserNotificationEnabled()) {
829  }
830 
831  ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'), true);
832  $this->ctrl->returnToParent($this);
833  } else {
834  $this->form->setValuesByPost();
835  ilUtil::sendFailure($ilErr->getMessage());
836  }
837  $this->edit(false, $this->form);
838  }
839 
846  protected function askDelete()
847  {
848  global $DIC;
849 
850  $tpl = $DIC['tpl'];
851 
852  $this->ctrl->saveParameter(
853  $this,
854  [
855  'seed',
856  'app_id',
857  'dt',
858  'idate'
859  ]
860  );
861 
862  $app_id = (int) ($this->request->getQueryParams()['app_id'] ?? 0);
863  if (!$app_id) {
864  ilUtil::sendFailure($this->lng->txt('err_check_input'));
865  $this->ctrl->returnToParent($this);
866  }
867 
868  $entry = new ilCalendarEntry($app_id);
870  if (
871  !count($recs) &&
872  !$this->app->isMilestone()
873  ) {
874  $confirm = new ilConfirmationGUI();
875  $confirm->setFormAction($this->ctrl->getFormAction($this));
876  $confirm->setHeaderText($this->lng->txt('cal_delete_app_sure'));
877  $confirm->setCancel($this->lng->txt('cancel'), 'cancel');
878  $confirm->addItem('appointments[]', $this->app->getEntryId(), $this->app->getTitle());
879  $confirm->setConfirm($this->lng->txt('delete'), 'delete');
880  $this->tpl->setContent($confirm->getHTML());
881  } else {
882  $table = new ilCalendarRecurrenceTableGUI(
883  $this->app,
884  $this,
885  'askDelete'
886  );
887  $table->init();
888  $table->parse();
889  $this->tpl->setContent($table->getHTML());
890  ilUtil::sendQuestion($this->lng->txt('cal_delete_app_sure'));
891  ilUtil::sendInfo($this->lng->txt('cal_recurrence_confirm_deletion'));
892  }
893  }
894 
902  protected function delete()
903  {
904  $app_ids = (array) ($this->request->getParsedBody()['appointment_ids'] ?? []);
905  if (!$app_ids) {
906  $this->logger->dump($app_ids);
907  $app_ids = (array) ($this->request->getQueryParams()['app_id'] ?? []);
908  }
909  if (!$app_ids) {
910  $this->ctrl->returnToParent($this);
911  }
912  foreach ($app_ids as $app_id) {
913  $app = new ilCalendarEntry($app_id);
914  $app->delete();
915 
916  include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
918 
919  include_once './Services/Calendar/classes/class.ilCalendarUserNotification.php';
921  }
922  ilUtil::sendSuccess($this->lng->txt('cal_deleted_app'), true);
923  $this->ctrl->returnToParent($this);
924  }
925 
933  protected function deleteExclude($a_return = true)
934  {
935  $recurrence_ids = (array) ($this->request->getParsedBody()['recurrence_ids'] ?? []);
936  $app_id = (int) ($this->request->getQueryParams()['app_id'] ?? 0);
937  if (!count($recurrence_ids)) {
938  ilUtil::sendFailure($this->lng->txt('select_one'), true);
939  $this->ctrl->redirect($this, 'askDelete');
940  }
941  if (!$app_id) {
942  $this->ctrl->returnToParent($this);
943  }
944  foreach ($recurrence_ids as $rdate) {
945  $exclusion = new ilCalendarRecurrenceExclusion();
946  $exclusion->setEntryId($app_id);
947  $exclusion->setDate(new ilDate($rdate, IL_CAL_UNIX));
948  $exclusion->save();
949  }
950  if ($a_return) {
951  ilUtil::sendSuccess($this->lng->txt('cal_deleted_app'), true);
952  $this->ctrl->returnToParent($this);
953  }
954  }
955 
963  protected function initTimeZone()
964  {
965  global $DIC;
966 
967  $ilUser = $DIC['ilUser'];
968 
969  $this->timezone = $ilUser->getTimeZone();
970  }
971 
976  protected function initInitialDate(ilDate $initialDate)
977  {
978  if (!isset($_GET['hour'])) {
979  $this->initialDate = clone $initialDate;
980  $this->default_fulltime = true;
981  } else {
982  if ((int) $_GET['hour'] < 10) {
983  $time = '0' . (int) $_GET['hour'] . ':00:00';
984  } else {
985  $time = (int) $_GET['hour'] . ':00:00';
986  }
987  $this->initialDate = new ilDateTime($initialDate->get(IL_CAL_DATE) . ' ' . $time, IL_CAL_DATETIME, $this->timezone);
988  $this->default_fulltime = false;
989  }
990  }
991 
999  protected function initSeed(ilDate $seed)
1000  {
1001  $this->seed = clone $seed;
1002  $this->default_fulltime = true;
1003  }
1004 
1012  protected function initAppointment($a_app_id = 0)
1013  {
1014  include_once('./Services/Calendar/classes/class.ilCalendarEntry.php');
1015  include_once('./Services/Calendar/classes/class.ilCalendarRecurrences.php');
1016  $this->app = new ilCalendarEntry($a_app_id);
1017 
1018  include_once './Services/Calendar/classes/class.ilCalendarUserNotification.php';
1019  $this->notification = new ilCalendarUserNotification($this->app->getEntryId());
1020 
1021  if (!$a_app_id) {
1022  $start = clone $this->initialDate;
1023  $this->app->setStart($start);
1024 
1025  $seed_end = clone $this->initialDate;
1026  if ($this->default_fulltime) {
1027  #$seed_end->increment(IL_CAL_DAY,1);
1028  } else {
1029  $seed_end->increment(IL_CAL_HOUR, 1);
1030  }
1031  $this->app->setEnd($seed_end);
1032  $this->app->setFullday($this->default_fulltime);
1033 
1034  $this->rec = new ilCalendarRecurrence();
1035  } else {
1036  $this->rec = ilCalendarRecurrences::_getFirstRecurrence($this->app->getEntryId());
1037  }
1038  }
1039 
1047  protected function load($a_mode, $a_as_milestone = false)
1048  {
1049  // needed for date handling
1050  $this->initForm($a_mode, $a_as_milestone);
1051  $this->form->checkInput();
1052 
1053  if ($a_as_milestone) {
1054  $this->app->setMilestone(true);
1055  $this->app->setCompletion(ilUtil::stripSlashes($_POST['completion']));
1056  }
1057 
1058  $this->app->setTitle(ilUtil::stripSlashes($_POST['title']));
1059  $this->app->setLocation(ilUtil::stripSlashes($_POST['location']));
1060  $this->app->setDescription(ilUtil::stripSlashes($_POST['description']));
1061  $this->app->setTitle(ilUtil::stripSlashes($_POST['title']));
1062  $this->app->enableNotification((int) $_POST['not']);
1063 
1064  if ($a_as_milestone) { // milestones are always fullday events
1065  $start = $this->form->getItemByPostVar('event_start');
1066  $start = $start->getDate();
1067 
1068  $this->app->setFullday(true);
1069 
1070  // for milestones is end date = start date
1071  $this->app->setStart($start);
1072  $this->app->setEnd($start);
1073  } else {
1074  $period = $this->form->getItemByPostVar('event');
1075  $start = $period->getStart();
1076  $end = $period->getEnd();
1077 
1078  $this->app->setFullday($start instanceof ilDate);
1079  $this->app->setStart($start);
1080  $this->app->setEnd($end);
1081  }
1082 
1083  $this->loadNotificationRecipients();
1084  $this->loadRecurrenceSettings($a_as_milestone = false);
1085  }
1086 
1087  protected function loadNotificationRecipients()
1088  {
1089  $this->notification->setRecipients(array());
1090 
1091  foreach ((array) $_POST['notu'] as $rcp) {
1092  $rcp = trim(ilUtil::stripSlashes($rcp));
1093  $usr_id = ilObjUser::_loginExists($rcp);
1094 
1095  if (strlen($rcp) == 0) {
1096  continue;
1097  }
1098 
1099  if ($usr_id) {
1100  $this->notification->addRecipient(
1102  $usr_id
1103  );
1104  } else {
1105  $this->notification->addRecipient(
1107  0,
1108  $rcp
1109  );
1110  }
1111  }
1112  }
1113 
1120  protected function loadRecurrenceSettings($a_as_milestone = false)
1121  {
1122  $this->rec->reset();
1123 
1124  switch ($_POST['frequence']) {
1125  case IL_CAL_FREQ_DAILY:
1126  $this->rec->setFrequenceType($_POST['frequence']);
1127  $this->rec->setInterval((int) $_POST['count_DAILY']);
1128  break;
1129 
1130  case IL_CAL_FREQ_WEEKLY:
1131  $this->rec->setFrequenceType($_POST['frequence']);
1132  $this->rec->setInterval((int) $_POST['count_WEEKLY']);
1133  if (is_array($_POST['byday_WEEKLY'])) {
1134  $this->rec->setBYDAY(ilUtil::stripSlashes(implode(',', $_POST['byday_WEEKLY'])));
1135  }
1136  break;
1137 
1138  case IL_CAL_FREQ_MONTHLY:
1139  $this->rec->setFrequenceType($_POST['frequence']);
1140  $this->rec->setInterval((int) $_POST['count_MONTHLY']);
1141  switch ((int) $_POST['subtype_MONTHLY']) {
1142  case 0:
1143  // nothing to do;
1144  break;
1145 
1146  case 1:
1147  switch ((int) $_POST['monthly_byday_day']) {
1148  case 8:
1149  // Weekday
1150  $this->rec->setBYSETPOS((int) $_POST['monthly_byday_num']);
1151  $this->rec->setBYDAY('MO,TU,WE,TH,FR');
1152  break;
1153 
1154  case 9:
1155  // Day of month
1156  $this->rec->setBYMONTHDAY((int) $_POST['monthly_byday_num']);
1157  break;
1158 
1159  default:
1160  $this->rec->setBYDAY((int) $_POST['monthly_byday_num'] . $_POST['monthly_byday_day']);
1161  break;
1162  }
1163  break;
1164 
1165  case 2:
1166  $this->rec->setBYMONTHDAY((int) $_POST['monthly_bymonthday']);
1167  break;
1168  }
1169  break;
1170 
1171  case IL_CAL_FREQ_YEARLY:
1172  $this->rec->setFrequenceType($_POST['frequence']);
1173  $this->rec->setInterval((int) $_POST['count_YEARLY']);
1174  switch ((int) $_POST['subtype_YEARLY']) {
1175  case 0:
1176  // nothing to do;
1177  break;
1178 
1179  case 1:
1180  $this->rec->setBYMONTH((int) $_POST['yearly_bymonth_byday']);
1181  $this->rec->setBYDAY((int) $_POST['yearly_byday_num'] . $_POST['yearly_byday']);
1182  break;
1183 
1184  case 2:
1185  $this->rec->setBYMONTH((int) $_POST['yearly_bymonth_by_monthday']);
1186  $this->rec->setBYMONTHDAY((int) $_POST['yearly_bymonthday']);
1187  break;
1188  }
1189  break;
1190  }
1191 
1192  // UNTIL
1193  switch ((int) $_POST['until_type']) {
1194  case 1:
1195  $this->rec->setFrequenceUntilDate(null);
1196  // nothing to do
1197  break;
1198 
1199  case 2:
1200  $this->rec->setFrequenceUntilDate(null);
1201  $this->rec->setFrequenceUntilCount((int) $_POST['count']);
1202  break;
1203 
1204  case 3:
1205  $dt = new ilDateTimeInputGUI('', 'until_end');
1206  $dt->setRequired(true);
1207  if ($dt->checkInput()) {
1208  $this->rec->setFrequenceUntilCount(0);
1209  $this->rec->setFrequenceUntilDate($dt->getDate());
1210  }
1211  break;
1212  }
1213  }
1214 
1222  protected function saveRecurrenceSettings()
1223  {
1224  switch ($_POST['frequence']) {
1225  case 'NONE':
1226  case '':
1227  // No recurrence => delete if there is an recurrence rule
1228  if ($this->rec->getRecurrenceId()) {
1229  $this->rec->delete();
1230  }
1231  break;
1232 
1233  default:
1234  if ($this->rec->getRecurrenceId()) {
1235  $this->rec->update();
1236  } else {
1237  $this->rec->save();
1238  }
1239  break;
1240  }
1241  }
1242 
1249  protected function createDefaultCalendar()
1250  {
1251  global $DIC;
1252 
1253  $ilUser = $DIC['ilUser'];
1254  $lng = $DIC['lng'];
1255 
1256  $cat = new ilCalendarCategory();
1257  $cat->setColor(ilCalendarCategory::DEFAULT_COLOR);
1258  $cat->setType(ilCalendarCategory::TYPE_USR);
1259  $cat->setTitle($this->lng->txt('cal_default_calendar'));
1260  $cat->setObjId($ilUser->getId());
1261 
1262  // delete calendar cache
1263  include_once './Services/Calendar/classes/class.ilCalendarCache.php';
1264  ilCalendarCache::getInstance()->deleteUserEntries($ilUser->getId());
1265 
1266  return $cat->add();
1267  }
1268 
1273  protected function confirmRegister()
1274  {
1275  global $DIC;
1276 
1277  $tpl = $DIC['tpl'];
1278 
1279  $entry = new ilCalendarEntry((int) $_GET['app_id']);
1281  new ilDateTime($_GET['dstart'], IL_CAL_UNIX),
1282  new ilDateTime($_GET['dend'], IL_CAL_UNIX)
1283  );
1284 
1285 
1286  include_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
1287  $conf = new ilConfirmationGUI;
1288 
1289  $this->ctrl->setParameter($this, 'dstart', (int) $_REQUEST['dstart']);
1290  $this->ctrl->setParameter($this, 'dend', (int) $_REQUEST['dend']);
1291 
1292  $conf->setFormAction($this->ctrl->getFormAction($this));
1293  $conf->setHeaderText($this->lng->txt('cal_confirm_reg_info'));
1294  $conf->setConfirm($this->lng->txt('cal_reg_register'), 'register');
1295  $conf->setCancel($this->lng->txt('cancel'), 'cancel');
1296  $conf->addItem('app_id', $entry->getEntryId(), $entry->getTitle() . ' (' . $start . ')');
1297 
1298  $tpl->setContent($conf->getHTML());
1299  }
1300 
1305  protected function register()
1306  {
1307  global $DIC;
1308 
1309  $ilUser = $DIC['ilUser'];
1310 
1311  include_once './Services/Calendar/classes/class.ilCalendarRegistration.php';
1312  $reg = new ilCalendarRegistration((int) $_POST['app_id']);
1313  $reg->register(
1314  $ilUser->getId(),
1315  new ilDateTime((int) $_REQUEST['dstart'], IL_CAL_UNIX),
1316  new ilDateTime((int) $_REQUEST['dend'], IL_CAL_UNIX)
1317  );
1318 
1319  ilUtil::sendSuccess($this->lng->txt('cal_reg_registered'), true);
1320  $this->ctrl->returnToParent($this);
1321  }
1322 
1326  public function confirmUnregister()
1327  {
1328  global $DIC;
1329 
1330  $tpl = $DIC['tpl'];
1331 
1332 
1333  $entry = new ilCalendarEntry((int) $_GET['app_id']);
1335  $dstart = new ilDateTime($_GET['dstart'], IL_CAL_UNIX),
1336  $dend = new ilDateTime($_GET['dend'], IL_CAL_UNIX)
1337  );
1338 
1339 
1340  include_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
1341  $conf = new ilConfirmationGUI;
1342 
1343  $this->ctrl->setParameter($this, 'dstart', (int) $_REQUEST['dstart']);
1344  $this->ctrl->setParameter($this, 'dend', (int) $_REQUEST['dend']);
1345 
1346  $conf->setFormAction($this->ctrl->getFormAction($this));
1347  $conf->setHeaderText($this->lng->txt('cal_confirm_unreg_info'));
1348  $conf->setConfirm($this->lng->txt('cal_reg_unregister'), 'unregister');
1349  $conf->setCancel($this->lng->txt('cancel'), 'cancel');
1350  $conf->addItem('app_id', $entry->getEntryId(), $entry->getTitle() . ' (' . $start . ')');
1351 
1352  $tpl->setContent($conf->getHTML());
1353  }
1354 
1359  protected function unregister()
1360  {
1361  global $DIC;
1362 
1363  $ilUser = $DIC['ilUser'];
1364 
1365  include_once './Services/Calendar/classes/class.ilCalendarRegistration.php';
1366  $reg = new ilCalendarRegistration((int) $_POST['app_id']);
1367  $reg->unregister(
1368  $ilUser->getId(),
1369  new ilDateTime((int) $_REQUEST['dstart'], IL_CAL_UNIX),
1370  new ilDateTime((int) $_REQUEST['dend'], IL_CAL_UNIX)
1371  );
1372 
1373  ilUtil::sendSuccess($this->lng->txt('cal_reg_unregistered'), true);
1374  $this->ctrl->returnToParent($this);
1375  }
1376 
1380  public function book()
1381  {
1382  global $DIC;
1383 
1384  $ilUser = $DIC['ilUser'];
1385  $tpl = $DIC['tpl'];
1386 
1387  $entry_id = (int) $_GET['app_id'];
1388  $this->ctrl->saveParameter($this, 'app_id');
1389 
1390  include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
1391  include_once 'Services/Booking/classes/class.ilBookingEntry.php';
1392  $entry = new ilCalendarEntry($entry_id);
1393  $booking = new \ilBookingEntry($entry->getContextId());
1394  $user = $booking->getObjId();
1395 
1396 
1397  $form = $this->initFormConfirmBooking();
1398  $form->getItemByPostVar('date')->setValue(ilDatePresentation::formatPeriod($entry->getStart(), $entry->getEnd()));
1399  $form->getItemByPostVar('title')->setValue($entry->getTitle() . " (" . ilObjUser::_lookupFullname($user) . ')');
1400 
1401  $tpl->setContent($form->getHTML());
1402  return true;
1403  }
1404 
1409  protected function initFormConfirmBooking()
1410  {
1411  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
1412  $form = new ilPropertyFormGUI();
1413  $form->setFormAction($this->ctrl->getFormAction($this));
1414  $form->addCommandButton('bookconfirmed', $this->lng->txt('cal_confirm_booking'));
1415  $form->addCommandButton('cancel', $this->lng->txt('cancel'));
1416 
1417  $date = new ilNonEditableValueGUI($this->lng->txt('appointment'), 'date');
1418  $form->addItem($date);
1419 
1420  $title = new ilNonEditableValueGUI($this->lng->txt('title'), 'title');
1421  $form->addItem($title);
1422 
1423  $message = new ilTextAreaInputGUI($this->lng->txt('cal_ch_booking_message_tbl'), 'comment');
1424  $message->setRows(5);
1425  $form->addItem($message);
1426 
1427  return $form;
1428  }
1429 
1433  public function bookconfirmed()
1434  {
1435  global $DIC;
1436 
1437  $ilUser = $DIC->user();
1438 
1439  $entry = (int) $_REQUEST['app_id'];
1440  $form = $this->initFormConfirmBooking();
1441  if ($form->checkInput()) {
1442  // check if appointment is bookable
1443  include_once './Services/Calendar/classes/class.ilCalendarEntry.php';
1444  $cal_entry = new ilCalendarEntry($entry);
1445 
1446  include_once './Services/Booking/classes/class.ilBookingEntry.php';
1447  $booking = new ilBookingEntry($cal_entry->getContextId());
1448 
1449  if (!$booking->isAppointmentBookableForUser($entry, $GLOBALS['DIC']['ilUser']->getId())) {
1450  ilUtil::sendFailure($this->lng->txt('cal_booking_failed_info'), true);
1451  $this->ctrl->returnToParent($this);
1452  }
1453 
1454  include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourUtils.php';
1456 
1457  include_once './Services/Booking/classes/class.ilBookingEntry.php';
1458  ilBookingEntry::writeBookingMessage($entry, $ilUser->getId(), $form->getInput('comment'));
1459  }
1460  ilUtil::sendSuccess($this->lng->txt('cal_booking_confirmed'), true);
1461  $this->ctrl->returnToParent($this);
1462  }
1463 
1468  public function cancelBooking()
1469  {
1470  global $DIC;
1471 
1472  $ilUser = $DIC['ilUser'];
1473  $tpl = $DIC['tpl'];
1474 
1475  $entry = (int) $_GET['app_id'];
1476 
1477  include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
1478  $entry = new ilCalendarEntry($entry);
1479 
1480  $category = $this->calendarEntryToCategory($entry);
1481  if ($category->getType() == ilCalendarCategory::TYPE_CH) {
1482  include_once 'Services/Booking/classes/class.ilBookingEntry.php';
1483  $booking = new ilBookingEntry($entry->getContextId());
1484  if (!$booking->hasBooked($entry->getEntryId())) {
1485  $this->ctrl->returnToParent($this);
1486  return false;
1487  }
1488 
1489  $entry_title = ' ' . $entry->getTitle() . " (" . ilObjUser::_lookupFullname($booking->getObjId()) . ')';
1490  } elseif ($category->getType() == ilCalendarCategory::TYPE_BOOK) {
1491  $entry_title = ' ' . $entry->getTitle();
1492  } else {
1493  $this->ctrl->returnToParent($this);
1494  return false;
1495  }
1496 
1497  $title = ilDatePresentation::formatPeriod($entry->getStart(), $entry->getEnd());
1498 
1499  include_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
1500  $conf = new ilConfirmationGUI;
1501  $conf->setFormAction($this->ctrl->getFormAction($this));
1502  $conf->setHeaderText($this->lng->txt('cal_cancel_booking_info'));
1503  $conf->setConfirm($this->lng->txt('cal_cancel_booking'), 'cancelconfirmed');
1504  $conf->setCancel($this->lng->txt('cancel'), 'cancel');
1505  $conf->addItem('app_id', $entry->getEntryId(), $title . ' - ' . $entry_title);
1506 
1507  $tpl->setContent($conf->getHTML());
1508  }
1509 
1514  public function cancelConfirmed()
1515  {
1516  global $DIC;
1517 
1518  $ilUser = $DIC['ilUser'];
1519 
1520  $entry = (int) $_POST['app_id'];
1521 
1522  include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
1523  $entry = new ilCalendarEntry($entry);
1524 
1525  $category = $this->calendarEntryToCategory($entry);
1526  if ($category->getType() == ilCalendarCategory::TYPE_CH) {
1527  // find cloned calendar entry in user calendar
1528  include_once 'Services/Calendar/classes/ConsultationHours/class.ilConsultationHourAppointments.php';
1530  $ilUser->getId(),
1531  $entry->getContextId(),
1532  $entry->getStart(),
1534  false
1535  );
1536 
1537  // Fix for wrong, old entries
1538  foreach ((array) $apps as $own_app) {
1539  $ref_entry = new ilCalendarEntry($own_app);
1540  $ref_entry->delete();
1541  }
1542 
1543  include_once 'Services/Booking/classes/class.ilBookingEntry.php';
1544  $booking = new ilBookingEntry($entry->getContextId());
1545  $booking->cancelBooking($entry->getEntryId());
1546 
1547  // do NOT delete original entry
1548  } elseif ($category->getType() == ilCalendarCategory::TYPE_BOOK) {
1549  $booking = new ilBookingReservation($entry->getContextId());
1551  $booking->update();
1552 
1553  $entry->delete();
1554  }
1555 
1556  ilUtil::sendSuccess($this->lng->txt('cal_cancel_booking_confirmed'), true);
1557  $this->ctrl->returnToParent($this);
1558  }
1559 
1565  protected function calendarEntryToCategory(ilCalendarEntry $entry)
1566  {
1567  include_once 'Services/Calendar/classes/class.ilCalendarCategoryAssignments.php';
1568  include_once 'Services/Calendar/classes/class.ilCalendarCategory.php';
1569  $assignment = new ilCalendarCategoryAssignments($entry->getEntryId());
1570  $assignment = $assignment->getFirstAssignment();
1571  return new ilCalendarCategory($assignment);
1572  }
1573 
1578  protected function doUserAutoComplete()
1579  {
1580  if (!isset($_GET['autoCompleteField'])) {
1581  $a_fields = array('login','firstname','lastname','email');
1582  } else {
1583  $a_fields = array((string) $_GET['autoCompleteField']);
1584  }
1585 
1586  include_once './Services/User/classes/class.ilUserAutoComplete.php';
1587  $auto = new ilUserAutoComplete();
1588  $auto->setSearchFields($a_fields);
1589  $auto->enableFieldSearchableCheck(true);
1590  $auto->setMoreLinkAvailable(true);
1591 
1592  if (($_REQUEST['fetchall'])) {
1593  $auto->setLimit(ilUserAutoComplete::MAX_ENTRIES);
1594  }
1595 
1596  echo $auto->getList($_REQUEST['query']);
1597  exit();
1598  }
1599 }
static _lookupLogin($a_user_id)
lookup login
getAppointment()
Get current appointment.
static getInstance()
get singleton instance
static _lookupCategory($a_cal_id)
Lookup category id.
static _getRecurrences($a_cal_id)
get all recurrences of an appointment
const IL_CAL_FREQ_MONTHLY
Model for a calendar entry.
static _getInstance()
get singleton instance
cancelConfirmed()
Cancel consultation appointment or ressource booking, was confirmed This will delete the calendar ent...
exit
Definition: login.php:29
Class ilInfoScreenGUI.
const IL_CAL_DATETIME
const ANONYMOUS_USER_ID
Definition: constants.php:25
setStatus($a_status)
Set booking status.
This class represents a property form user interface.
$type
$_GET["client_id"]
const IL_CAL_HOUR
setFormAction($a_form_action)
static _lookupFullname($a_user_id)
Lookup Full Name.
static _getFirstRecurrence($a_cal_id)
get first recurrence
This class represents an input GUI for recurring events/appointments (course events or calendar appoi...
Distributes calendar mail notifications.
edit($a_edit_single_app=false, ilPropertyFormGUI $form=null)
edit appointment
initAppointment($a_app_id=0)
init appointment
getEntryId()
get entry id
static getAppointmentIds($a_user_id, $a_context_id=null, $a_start=null, $a_type=null, $a_check_owner=true)
Get all appointment ids.
setValue($a_value)
Set Value.
Booking definition.
initInitialDate(ilDate $initialDate)
init initial date
static _lookupCategoryIdByObjId($a_obj_id)
lookup category by obj_id
This class represents a checkbox property in a property form.
saveMilestoneResponsibleUsers()
Save milestone responsibilites.
Stores calendar categories.
const IL_CAL_UNIX
unregister()
Unregister calendar, was confirmed.
editResponsibleUsers()
Edit responsible users.
askEdit()
Check edit single apppointment / edit all appointments for recurring appointments.
TableGUI class for selection of milestone responsibles.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date public.
static _getAllReferences($a_id)
get all reference ids of object
get($a_format, $a_format_str='', $a_tz='')
get formatted date
$ilErr
Definition: raiseError.php:18
deleteExclude($a_return=true)
delete single item of recurrence list
Auto completion class for user lists.
This class represents a date/time property in a property form.
confirmUnregister()
Confirmation screen to unregister calendar.
setInfo($a_info)
Set Information Text.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
static _loginExists($a_login, $a_user_id=0)
check if a login name already exists You may exclude a user from the check by giving his user id as 2...
const IL_CAL_DAY
input GUI for a time span (start and end date)
static writeBookingMessage($a_entry_id, $a_usr_id, $a_message)
Write booking message.
static _equals(ilDateTime $start, ilDateTime $end, $a_compare_field='', $a_tz='')
Check if two date are equal.
Class for single dates.
Calculates an ilDateList for a given calendar entry and recurrence rule.
distributeUserNotifications()
Send mail to selected users ilObjUser $ilUser.
const IL_CAL_FREQ_DAILY
Model of calendar entry recurrcences.
const IL_CAL_FREQ_YEARLY
calendarEntryToCategory(ilCalendarEntry $entry)
Get category object of given calendar entry.
static _lookupObjId($a_id)
registration for calendar appointments
global $DIC
Definition: goto.php:24
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
setDate(ilDateTime $a_date=null)
set date E.g $dt_form->setDate(new ilDateTime(time(),IL_CAL_UTC)); or $dt_form->setDate(new ilDateTim...
cancelBooking($a_entry_id, $a_user_id=false)
cancel calendar booking for user
notification()
Definition: notification.php:2
save($a_as_milestone=false)
save appointment
initForm($a_mode, $a_as_milestone=false, $a_edit_single_app=false)
init form
static initDomEvent(ilGlobalTemplateInterface $a_main_tpl=null)
Init YUI DomEvent.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static sendQuestion($a_info="", $a_keep=false)
Send Question to Screen.
static _deleteByAppointmentId($a_app_id)
Delete appointment assignment.
static _getInstance($a_usr_id=0)
get singleton instance
cancelBooking()
Confirmation screen to cancel consultation appointment or ressource booking depends on calendar categ...
distributeNotifications($a_cat_id, $app_id, $a_new_appointment=true)
Distribute mail notifications.
static _lookupType($a_id, $a_reference=false)
lookup object type
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
bookconfirmed()
Book consultation appointment, was confirmed.
__construct(ilDate $seed, ilDate $initialDate, $a_appointment_id=0)
load($a_mode, $a_as_milestone=false)
load post
loadRecurrenceSettings($a_as_milestone=false)
load recurrence settings
add(ilPropertyFormGUI $form=null)
add new appointment
const IL_CAL_DATE
static formatPeriod(ilDateTime $start, ilDateTime $end, $a_skip_starting_day=false)
Format a period of two date Shows: 14.
This class represents a non editable value in a property form.
editSingle()
Edit one single appointment ^.
Administrate calendar appointments.
global $ilSetting
Definition: privfeed.php:17
This class represents a text area property in a property form.
saveRecurrenceSettings()
save recurrence settings
$message
Definition: xapiexit.php:14
Stores exclusion dates for calendar recurrences.
createDefaultCalendar()
Create a default calendar.
$ilUser
Definition: imgupload.php:18
This class represents a text wizard property in a property form.
book()
Confirmation screen for booking of consultation appointment.
static deleteCalendarEntry($a_cal_id)
Delete notification for a calendar entry ilDB $ilDB.
$_POST["username"]
setRequired($a_required)
Set Required.
const IL_CAL_FREQ_WEEKLY
confirmRegister()
Register to an appointment.
Class ilCalendarRecurrenceTableGUI.
showResponsibleUsersList($a_grp_id)
Show responsible uses of a milestone (default set is participants of group)
$i
Definition: metadata.php:24
Confirmation screen class.
static bookAppointment($a_usr_id, $a_app_id)
Book an appointment.