ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCalendarAppointmentGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
33 include_once('./Services/Calendar/classes/class.ilTimeZone.php');
34 include_once('./Services/Calendar/classes/class.ilDateTime.php');
35 
37 {
38  protected $seed = null;
39  protected $initialDate = null;
40  protected $default_fulltime = true;
41 
42  protected $app = null;
43  protected $rec = null;
44  protected $timezone = null;
45 
46  protected $tpl;
47  protected $lng;
48  protected $ctrl;
49 
57  public function __construct(ilDate $seed,ilDate $initialDate, $a_appointment_id = 0)
58  {
59  global $ilCtrl,$lng;
60 
61  $this->lng = $lng;
62  $lng->loadLanguageModule('dateplaner');
63  $this->ctrl = $ilCtrl;
64 
65  $this->initTimeZone();
66  $this->initSeed($seed);
67  $this->initInitialDate($initialDate);
68  $this->initAppointment($a_appointment_id);
69  }
70 
78  public function executeCommand()
79  {
80  global $ilUser, $ilSetting,$tpl, $ilTabs;
81 
82 
83  // Clear tabs and set back target
84  $ilTabs->clearTargets();
85  $ilTabs->setBackTarget(
86  $this->lng->txt('cal_back_to_cal'),
87  $this->ctrl->getLinkTarget($this,'cancel')
88  );
89 
90  $next_class = $this->ctrl->getNextClass($this);
91  switch($next_class)
92  {
93 
94  default:
95  $cmd = $this->ctrl->getCmd("add");
96  $this->$cmd();
97  break;
98  }
99  return true;
100  }
101 
106  public function getAppointment()
107  {
108  return $this->app;
109  }
110 
118  protected function cancel()
119  {
120  $this->ctrl->returnToParent($this);
121  }
122 
130  protected function initForm($a_mode, $a_as_milestone = false, $a_edit_single_app = false)
131  {
132  global $ilUser,$tpl;
133 
134  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
135  include_once('./Services/Calendar/classes/class.ilCalendarRecurrenceGUI.php');
136  include_once('./Services/Calendar/classes/class.ilCalendarCategories.php');
137  include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
138  include_once('./Services/Calendar/classes/class.ilCalendarCategory.php');
139 
140  $this->form = new ilPropertyFormGUI();
141 
142  include_once('./Services/YUI/classes/class.ilYuiUtil.php');
144  $resp_info = false;
145  switch($a_mode)
146  {
147  case 'create':
148  $this->ctrl->saveParameter($this,array('seed','idate'));
149  $this->form->setFormAction($this->ctrl->getFormAction($this));
150  if ($a_as_milestone)
151  {
152  $this->form->setTitle($this->lng->txt('cal_new_ms'));
153  $this->form->addCommandButton('saveMilestone',$this->lng->txt('cal_add_milestone'));
154  $this->form->addCommandButton('cancel',$this->lng->txt('cancel'));
155  }
156  else
157  {
158  $this->form->setTitle($this->lng->txt('cal_new_app'));
159  $this->form->addCommandButton('save',$this->lng->txt('cal_add_appointment'));
160  $this->form->addCommandButton('cancel',$this->lng->txt('cancel'));
161  }
162  break;
163 
164  case 'edit':
165  if ($a_as_milestone)
166  {
167  $this->form->setTitle($this->lng->txt('cal_edit_milestone'));
168  }
169  else
170  {
171  $this->form->setTitle($this->lng->txt('cal_edit_appointment'));
172  }
173  $this->ctrl->saveParameter($this,array('seed','app_id','idate'));
174  $this->form->setFormAction($this->ctrl->getFormAction($this));
175 
176  $ass = new ilCalendarCategoryAssignments($this->app->getEntryId());
177  $cat = $ass->getFirstAssignment();
178  include_once('./Services/Calendar/classes/class.ilCalendarCategory.php');
179  $cat_info = ilCalendarCategories::_getInstance()->getCategoryInfo($cat);
180  $type = ilObject::_lookupType($cat_info['obj_id']);
181  if ($a_as_milestone && $cat_info['type'] == ilCalendarCategory::TYPE_OBJ
182  && ($type == "grp" || $type == "crs"))
183  {
184  $resp_info = true;
185  $this->form->addCommandButton('editResponsibleUsers',$this->lng->txt('cal_change_responsible_users'));
186  }
187  $this->form->addCommandButton('update',$this->lng->txt('save'));
188  // $this->form->addCommandButton('askDelete',$this->lng->txt('delete'));
189  $this->form->addCommandButton('cancel',$this->lng->txt('cancel'));
190  break;
191  }
192  // title
193  $title = new ilTextInputGUI($this->lng->txt('title'),'title');
194  $title->setValue($this->app->getTitle());
195  $title->setRequired(true);
196  $title->setMaxLength(128);
197  $title->setSize(32);
198  $this->form->addItem($title);
199 
200  // calendar selection
201  $calendar = new ilSelectInputGUI($this->lng->txt('cal_category_selection'),'calendar');
202  if($_POST['category'])
203  {
204  $calendar->setValue((int) $_POST['calendar']);
205  $selected_calendar = (int) $_POST['calendar'];
206  }
207  else if($_GET['category_id'])
208  {
209  $calendar->setValue((int) $_GET['category_id']);
210  $selected_calendar = (int) $_GET['category_id'];
211  }
212  elseif($a_mode == 'edit')
213  {
214  $ass = new ilCalendarCategoryAssignments($this->app->getEntryId());
215  $cat = $ass->getFirstAssignment();
216  $calendar->setValue($cat);
217  $selected_calendar = $cat;
218  }
219  elseif(isset($_GET['ref_id']))
220  {
221  include_once('./Services/Calendar/classes/class.ilCalendarCategories.php');
222  $obj_cal = ilObject::_lookupObjId($_GET['ref_id']);
223  $calendar->setValue(ilCalendarCategories::_lookupCategoryIdByObjId($obj_cal));
224  $selected_calendar = ilCalendarCategories::_lookupCategoryIdByObjId($obj_cal);
225  }
226  $calendar->setRequired(true);
227  $cats = ilCalendarCategories::_getInstance($ilUser->getId());
228  $calendar->setOptions($cats->prepareCategoriesOfUserForSelection());
229 
230  include_once './Services/Calendar/classes/class.ilCalendarSettings.php';
231  if(ilCalendarSettings::_getInstance()->isNotificationEnabled())
232  {
233  $notification_cals = $cats->getNotificationCalendars();
234  $notification_cals = count($notification_cals) ? implode(',',$notification_cals) : '';
235  $calendar->addCustomAttribute("onchange=\"ilToggleNotification(new Array(".$notification_cals."));\"");
236  }
237  $this->form->addItem($calendar);
238 
239  if (!$a_as_milestone)
240  {
241  include_once './Services/Form/classes/class.ilDateDurationInputGUI.php';
242  $tpl->addJavaScript('./Services/Form/js/date_duration.js');
243  $dur = new ilDateDurationInputGUI($this->lng->txt('cal_fullday'),'event');
244  $dur->setStartText($this->lng->txt('cal_start'));
245  $dur->setEndText($this->lng->txt('cal_end'));
246  $dur->enableToggleFullTime(
247  $this->lng->txt('cal_fullday_title'),
248  $this->app->isFullday() ? true : false
249  );
250  $dur->setShowTime(true);
251  $dur->setStart($this->app->getStart());
252  $dur->setEnd($this->app->getEnd());
253  $this->form->addItem($dur);
254 
255  // recurrence
256  include_once('./Services/Calendar/classes/Form/class.ilRecurrenceInputGUI.php');
257  $rec = new ilRecurrenceInputGUI($this->lng->txt('cal_recurrences'),'frequence');
258  $rec->setRecurrence($this->rec);
259  $this->form->addItem($rec);
260 
261  // location
262  $where = new ilTextInputGUI($this->lng->txt('cal_where'),'location');
263  $where->setValue($this->app->getLocation());
264  $where->setMaxLength(128);
265  $where->setSize(32);
266  $this->form->addItem($where);
267  }
268  else
269  {
270  $deadline = new ilDateTimeInputGUI($this->lng->txt('cal_deadline'),'event[start]');
271  $deadline->setDate($this->app->getStart());
272  $deadline->setShowTime(false);
273  $deadline->setMinuteStepSize(5);
274  $this->form->addItem($deadline);
275 
276  // completion
277  $completion_vals = array();
278  for($i = 0; $i <= 100; $i+=5)
279  {
280  $completion_vals[$i] = $i." %";
281  }
282  $compl = new ilSelectInputGUI($this->lng->txt('cal_task_completion'),
283  'completion');
284  $compl->setOptions($completion_vals);
285  $compl->setValue($this->app->getCompletion());
286  $this->form->addItem($compl);
287  }
288 
289  $desc = new ilTextAreaInputGUI($this->lng->txt('description'),'description');
290  $desc->setValue($this->app->getDescription());
291  $desc->setRows(5);
292  $this->form->addItem($desc);
293 
294  if ($a_as_milestone && $a_mode == "edit" && $resp_info)
295  {
296  // users responsible
297  $users = $this->app->readResponsibleUsers();
298  $resp = new ilNonEditableValueGUI($this->lng->txt('cal_responsible'),
299  $users);
300  $delim = "";
301  foreach($users as $r)
302  {
303  $value.= $delim.$r["lastname"].", ".$r["firstname"]." [".$r["login"]."]";
304  $delim = "<br />";
305  }
306  if (count($users) > 0)
307  {
308  $resp->setValue($value);
309  }
310  else
311  {
312  $resp->setValue("-");
313  }
314 
315  $this->form->addItem($resp);
316  }
317 
318 
319  if(ilCalendarSettings::_getInstance()->isUserNotificationEnabled())
320  {
321  $notu = new ilTextWizardInputGUI($this->lng->txt('cal_user_notification'), 'notu');
322  $notu->setInfo($this->lng->txt('cal_user_notification_info'));
323  $notu->setSize(20);
324  $notu->setMaxLength(64);
325 
326  $values = array();
327  foreach($this->notification->getRecipients() as $rcp)
328  {
329  switch ($rcp['type'])
330  {
332  $values[] = ilObjUser::_lookupLogin($rcp['usr_id']);
333  break;
334 
336  $values[] = $rcp['email'];
337  break;
338  }
339  }
340  if(count($values))
341  $notu->setValues($values);
342  else
343  $notu->setValues(array(''));
344  $this->form->addItem($notu);
345  }
346 
347  // Notifications
348  include_once './Services/Calendar/classes/class.ilCalendarSettings.php';
349  if(ilCalendarSettings::_getInstance()->isNotificationEnabled() and count($cats->getNotificationCalendars()))
350  {
351  $selected_cal = new ilCalendarCategory($selected_calendar);
352  $disabled = true;
353  if($selected_cal->getType() == ilCalendarCategory::TYPE_OBJ)
354  {
355  if(ilObject::_lookupType($selected_cal->getObjId()) == 'crs' or ilObject::_lookupType($selected_cal->getObjId()) == 'grp')
356  {
357  $disabled = false;
358  }
359  }
360 
361  $tpl->addJavaScript('./Services/Calendar/js/toggle_notification.js');
362  $not = new ilCheckboxInputGUI($this->lng->txt('cal_cg_notification'),'not');
363  $not->setInfo($this->lng->txt('cal_notification_info'));
364  $not->setValue(1);
365  $not->setChecked($this->app->isNotificationEnabled());
366  $not->setDisabled($disabled);
367  $this->form->addItem($not);
368  }
369  }
370 
371 
378  protected function add()
379  {
380  global $tpl, $ilHelp;
381 
382  $ilHelp->setScreenIdComponent("cal");
383  $ilHelp->setScreenId("app");
384  $ilHelp->setSubScreenId("create");
385 
386  $this->initForm('create');
387  $tpl->setContent($this->form->getHTML());
388  }
389 
396  protected function addMilestone()
397  {
398  global $tpl, $ilHelp;
399 
400  $ilHelp->setScreenIdComponent("cal");
401  $ilHelp->setScreenId("app");
402  $ilHelp->setSubScreenId("create_milestone");
403 
404  $this->initForm('create', true);
405  $tpl->setContent($this->form->getHTML());
406  }
407 
413  protected function saveMilestone()
414  {
415  $this->save(true);
416  }
417 
423  protected function save($a_as_milestone = false)
424  {
425  global $ilErr;
426 
427  $this->load($a_as_milestone);
428 
429  if($this->app->validate() and $this->notification->validate())
430  {
431  if(!(int) $_POST['calendar'])
432  {
433  $cat_id = $this->createDefaultCalendar();
434  }
435  else
436  {
437  $cat_id = (int) $_POST['calendar'];
438  }
439 
440  $this->app->save();
441  $this->notification->setEntryId($this->app->getEntryId());
442  $this->notification->save();
443  $this->rec->setEntryId($this->app->getEntryId());
444  $this->saveRecurrenceSettings();
445 
446  include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
447  $ass = new ilCalendarCategoryAssignments($this->app->getEntryId());
448  $ass->addAssignment($cat_id);
449 
450  // Send notifications
451  include_once './Services/Calendar/classes/class.ilCalendarSettings.php';
452  if(ilCalendarSettings::_getInstance()->isNotificationEnabled() and (bool) $_POST['not'])
453  {
454  $this->distributeNotifications($cat_id,$this->app->getEntryId(),true);
455  }
456  if(ilCalendarSettings::_getInstance()->isUserNotificationEnabled())
457  {
459  }
460 
461  include_once('./Services/Calendar/classes/class.ilCalendarCategory.php');
462  $cat_info = ilCalendarCategories::_getInstance()->getCategoryInfo($cat_id);
463  $type = ilObject::_lookupType($cat_info['obj_id']);
464 
465  if ($a_as_milestone && $cat_info['type'] == ilCalendarCategory::TYPE_OBJ
466  && ($type == "grp" || $type == "crs"))
467  {
468  ilUtil::sendSuccess($this->lng->txt('cal_created_milestone_resp_q'),true);
469  return $this->showResponsibleUsersList($cat_info['obj_id']);
470  }
471  elseif($a_as_milestone)
472  {
473  ilUtil::sendSuccess($this->lng->txt('cal_created_milestone'),true);
474  $this->ctrl->returnToParent($this);
475  }
476  else
477  {
478  ilUtil::sendSuccess($this->lng->txt('cal_created_appointment'),true);
479  $this->ctrl->returnToParent($this);
480  }
481  }
482  else
483  {
484  ilUtil::sendFailure($ilErr->getMessage());
485  }
486  if ($a_as_milestone)
487  {
488  $this->addMilestone();
489  }
490  else
491  {
492  $this->add();
493  }
494  }
495 
500  protected function distributeUserNotifications()
501  {
502  global $ilUser;
503 
504  include_once './Services/Calendar/classes/class.ilCalendarMailNotification.php';
505  $notification = new ilCalendarMailNotification();
506  $notification->setAppointmentId($this->app->getEntryId());
507 
508  foreach($this->notification->getRecipients() as $rcp)
509  {
510  switch($rcp['type'])
511  {
513  $notification->setSender(ANONYMOUS_USER_ID);
514  $notification->setRecipients(array($rcp['usr_id']));
515  $notification->setType(ilCalendarMailNotification::TYPE_USER);
516  break;
517 
519  $notification->setSender(ANONYMOUS_USER_ID);
520  $notification->setRecipients(array($rcp['email']));
521  $notification->setType(ilCalendarMailNotification::TYPE_USER_ANONYMOUS);
522  break;
523  }
524  $notification->send();
525  }
526  }
527 
528 
533  protected function distributeNotifications($a_cat_id, $app_id, $a_new_appointment = true)
534  {
535  include_once('./Services/Calendar/classes/class.ilCalendarCategory.php');
536  $cat_info = ilCalendarCategories::_getInstance()->getCategoryInfo($a_cat_id);
537 
538  include_once './Services/Calendar/classes/class.ilCalendarMailNotification.php';
539  $notification = new ilCalendarMailNotification();
540  $notification->setAppointmentId($app_id);
541 
542  switch($cat_info['type'])
543  {
545 
546  switch($cat_info['obj_type'])
547  {
548  case 'crs':
549  $ref_ids = ilObject::_getAllReferences($cat_info['obj_id']);
550  $ref_id = current($ref_ids);
551  $notification->setRefId($ref_id);
552  $notification->setType(
553  $a_new_appointment ?
556  break;
557 
558  case 'grp':
559  $ref_ids = ilObject::_getAllReferences($cat_info['obj_id']);
560  $ref_id = current($ref_ids);
561  $notification->setRefId($ref_id);
562  $notification->setType(
563  $a_new_appointment ?
566  break;
567  }
568  break;
569  }
570 
571  $notification->send();
572  }
573 
578  {
579  include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
580  $cat_id = ilCalendarCategoryAssignments::_lookupCategory($this->app->getEntryId());
581  include_once('./Services/Calendar/classes/class.ilCalendarCategory.php');
582  $cat_info = ilCalendarCategories::_getInstance()->getCategoryInfo($cat_id);
583 
584  $this->showResponsibleUsersList($cat_info['obj_id']);
585  }
586 
591  function showResponsibleUsersList($a_grp_id)
592  {
593  global $tpl;
594 
595  include_once("./Services/Calendar/classes/class.ilMilestoneResponsiblesTableGUI.php");
596  $table_gui = new ilMilestoneResponsiblesTableGUI($this, "", $a_grp_id,
597  $this->app->getEntryId());
598  $tpl->setContent($table_gui->getHTML());
599  }
600 
605  {
606  global $ilCtrl;
607 
608  $this->app->writeResponsibleUsers($_POST["user_id"]);
609  $ilCtrl->returnToParent($this);
610  }
611 
616  protected function askEdit()
617  {
618  // check for recurring entries
619  include_once './Services/Calendar/classes/class.ilCalendarRecurrences.php';
621  if(!$rec)
622  {
623  return $this->edit(TRUE);
624  }
625  // Show edit single/all appointments
626  $this->ctrl->saveParameter($this,array('seed','app_id','dt','idate'));
627 
628  include_once('./Services/Utilities/classes/class.ilConfirmationGUI.php');
629  $confirm = new ilConfirmationGUI();
630  $confirm->setFormAction($this->ctrl->getFormAction($this));
631  #$confirm->setHeaderText($this->lng->txt('cal_edit_app_sure'));
632  $confirm->setCancel($this->lng->txt('cancel'),'cancel');
633  $confirm->addItem('appointments[]',$this->app->getEntryId(),$this->app->getTitle());
634  $confirm->addButton($this->lng->txt('cal_edit_single'),'editSingle');
635  $confirm->setConfirm($this->lng->txt('cal_edit_recurrences'),'edit');
636 
637  $GLOBALS['tpl']->setContent($confirm->getHTML());
638  }
639 
643  protected function editSingle()
644  {
645  $_REQUEST['rexl'] = 1;
646  $GLOBALS['ilCtrl']->setParameter($this,'rexcl',1);
647  $this->edit(true);
648  }
649 
657  protected function edit($a_edit_single_app = false)
658  {
659  global $tpl,$ilUser,$ilErr, $ilHelp;
660 
661  $ilHelp->setScreenIdComponent("cal");
662  $ilHelp->setScreenId("app");
663  if ($this->app->isMilestone())
664  {
665  $ilHelp->setSubScreenId("edit_milestone");
666  }
667  else
668  {
669  $ilHelp->setSubScreenId("edit");
670  }
671 
672  include_once('./Services/Calendar/classes/class.ilCalendarCategory.php');
673  include_once('./Services/Calendar/classes/class.ilCalendarCategories.php');
674  include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
675 
676  $GLOBALS['ilCtrl']->saveParameter($this,array('seed','app_id','dt','idate'));
677 
678  if($_REQUEST['rexl'])
679  {
680  $GLOBALS['ilCtrl']->setParameter($this,'rexl',1);
681 
682  // Calculate new appointment time
683  $duration = $this->getAppointment()->getEnd()->get(IL_CAL_UNIX) - $this->getAppointment()->getStart()->get(IL_CAL_UNIX);
684  include_once './Services/Calendar/classes/class.ilCalendarRecurrenceCalculator.php';
685  $calc = new ilCalendarRecurrenceCalculator($this->getAppointment(), $this->rec);
686 
687  $current_date = new ilDateTime($_REQUEST['dt'],IL_CAL_UNIX);
688 
689  $yesterday = clone $current_date;
690  $yesterday->increment(IL_CAL_DAY,-1);
691  $tomorrow = clone $current_date;
692  $tomorrow->increment(IL_CAL_DAY, 1);
693 
694 
695  foreach($calc->calculateDateList($current_date, $tomorrow, 1) as $date_entry)
696  {
697  if(ilDateTime::_equals($current_date, $date_entry,IL_CAL_DAY))
698  {
699  $this->getAppointment()->setStart(new ilDateTime($date_entry->get(IL_CAL_UNIX),IL_CAL_UNIX));
700  $this->getAppointment()->setEnd(new ilDateTime($date_entry->get(IL_CAL_UNIX) + $duration,IL_CAL_UNIX));
701  break;
702  }
703  }
704 
705  // Finally reset recurrence
706  $this->rec = new ilCalendarRecurrence();
707  }
708 
709  $cat_id = ilCalendarCategoryAssignments::_lookupCategory($this->app->getEntryId());
710  $cats = ilCalendarCategories::_getInstance($ilUser->getId());
711 
712  if(!$cats->isVisible($cat_id))
713  {
714  $ilErr->raiseError($this->lng->txt('permission_denied'),$ilErr->WARNING);
715  return false;
716  }
717  if(!$cats->isEditable($cat_id) or $this->app->isAutoGenerated())
718  {
719  $this->showInfoScreen();
720  return true;
721  }
722 
723  $this->initForm('edit', $this->app->isMilestone(), $a_edit_single_app);
724  $tpl->setContent($this->form->getHTML());
725  }
726 
733  protected function showInfoScreen()
734  {
735  global $tpl,$ilUser;
736 
737  include_once("./Services/InfoScreen/classes/class.ilInfoScreenGUI.php");
738  $info = new ilInfoScreenGUI($this);
739  $info->setFormAction($this->ctrl->getFormAction($this));
740 
741  if ($this->app->isMilestone())
742  {
743  $info->addSection($this->lng->txt('cal_ms_details'));
744  }
745  else
746  {
747  $info->addSection($this->lng->txt('cal_details'));
748  }
749 
750  // Appointment
751  $info->addProperty($this->lng->txt('appointment'),
753  $this->app->getStart(),
754  $this->app->getEnd()));
755  $info->addProperty($this->lng->txt('title'),$this->app->getPresentationTitle());
756 
757  // Description
758  if(strlen($desc = $this->app->getDescription()))
759  {
760  $info->addProperty($this->lng->txt('description'),$desc);
761  }
762 
763  // Location
764  if(strlen($loc = $this->app->getLocation()))
765  {
766  $info->addProperty($this->lng->txt('cal_where'),$loc);
767  }
768 
769  // completion
770  if ($this->app->isMilestone() && $this->app->getCompletion() > 0)
771  {
772  $info->addProperty($this->lng->txt('cal_task_completion'),
773  $this->app->getCompletion()." %");
774  }
775 
776  include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
777  $cat_id = ilCalendarCategoryAssignments::_lookupCategory($this->app->getEntryId());
778  $cat_info = ilCalendarCategories::_getInstance()->getCategoryInfo($cat_id);
779  $type = ilObject::_lookupType($cat_info['obj_id']);
780  if ($this->app->isMilestone() && $cat_info['type'] == ilCalendarCategory::TYPE_OBJ
781  && ($type == "grp" || $type == "crs"))
782  {
783  // users responsible
784  $users = $this->app->readResponsibleUsers();
785  $delim = "";
786  foreach($users as $r)
787  {
788  $value.= $delim.$r["lastname"].", ".$r["firstname"]." [".$r["login"]."]";
789  $delim = "<br />";
790  }
791  if (count($users) > 0)
792  {
793  $info->addProperty($this->lng->txt('cal_responsible'),
794  $value);
795  }
796  }
797 
798  $category = new ilCalendarCategory($cat_id);
799 
800  if($category->getType() == ilCalendarCategory::TYPE_OBJ)
801  {
802  $info->addSection($this->lng->txt('additional_info'));
803 
804  $cat_info = ilCalendarCategories::_getInstance()->getCategoryInfo($cat_id);
805  $refs = ilObject::_getAllReferences($cat_info['obj_id']);
806 
807  include_once('./Services/Link/classes/class.ilLink.php');
808  $href = ilLink::_getStaticLink(current($refs),ilObject::_lookupType($cat_info['obj_id']),true);
809  $info->addProperty($this->lng->txt('perma_link'),'<a class="small" href="'.$href.'" target="_top">'.$href.'</a>');
810  }
811 
812  $tpl->setContent($info->getHTML());
813  }
814 
821  protected function update()
822  {
823  global $ilErr;
824 
825  $single_editing = ($_REQUEST['rexl'] ? true : false);
826 
827  $this->load($this->app->isMilestone());
828 
829  if($this->app->validate() and $this->notification->validate())
830  {
831  if(!(int) $_POST['calendar'])
832  {
833  $cat_id = $this->createDefaultCalendar();
834  }
835  else
836  {
837  $cat_id = (int) $_POST['calendar'];
838  }
839 
840  if($single_editing)
841  {
842  $this->getAppointment()->save();
843  $this->deleteExclude(false);
844 
845  $this->rec = new ilCalendarRecurrence();
846  $this->rec->setEntryId($this->getAppointment()->getEntryId());
847  }
848  else
849  {
850  $this->getAppointment()->update();
851  }
852  $this->notification->save();
853  $this->saveRecurrenceSettings();
854 
855  include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
856  $ass = new ilCalendarCategoryAssignments($this->app->getEntryId());
857  $GLOBALS['ilLog']->write($this->app->getEntryId());
858  $ass->deleteAssignments();
859  $ass->addAssignment($cat_id);
860 
861  // Send notifications
862  include_once './Services/Calendar/classes/class.ilCalendarSettings.php';
863  if(ilCalendarSettings::_getInstance()->isNotificationEnabled() and (bool) $_POST['not'])
864  {
865  $this->distributeNotifications($cat_id,$this->app->getEntryId(),false);
866  }
867  if(ilCalendarSettings::_getInstance()->isUserNotificationEnabled())
868  {
870  }
871 
872  ilUtil::sendSuccess($this->lng->txt('settings_saved'),true);
873  $this->ctrl->returnToParent($this);
874  }
875  else
876  {
877  ilUtil::sendFailure($ilErr->getMessage());
878  }
879 
880  $this->edit();
881 
882  }
883 
890  protected function askDelete()
891  {
892  global $tpl;
893 
894  include_once('./Services/Utilities/classes/class.ilConfirmationGUI.php');
895 
896  $this->ctrl->saveParameter($this,array('seed','app_id','dt','idate'));
897 
898  $confirm = new ilConfirmationGUI();
899  $confirm->setFormAction($this->ctrl->getFormAction($this));
900  $confirm->setHeaderText($this->lng->txt('cal_delete_app_sure'));
901  $confirm->setCancel($this->lng->txt('cancel'),'cancel');
902  $confirm->addItem('appointments[]',$this->app->getEntryId(),$this->app->getTitle());
903 
904  include_once('./Services/Calendar/classes/class.ilCalendarRecurrences.php');
905  if(sizeof(ilCalendarRecurrences::_getRecurrences($_GET['app_id']))
906  && !$this->app->isMilestone())
907  {
908  $confirm->addButton($this->lng->txt('cal_delete_single'),'deleteexclude');
909  $confirm->setConfirm($this->lng->txt('cal_delete_recurrences'),'delete');
910  }
911  else
912  {
913  $confirm->setConfirm($this->lng->txt('delete'),'delete');
914  }
915 
916  $tpl->setContent($confirm->getHTML());
917 
918  }
919 
927  protected function delete()
928  {
929  foreach($_POST['appointments'] as $app_id)
930  {
931  $app = new ilCalendarEntry($app_id);
932  $app->delete();
933 
934  include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
936 
937  include_once './Services/Calendar/classes/class.ilCalendarUserNotification.php';
939  }
940  ilUtil::sendSuccess($this->lng->txt('cal_deleted_app'),true);
941  $this->ctrl->returnToParent($this);
942  }
943 
951  protected function deleteExclude($a_return = true)
952  {
953  include_once('./Services/Calendar/classes/class.ilCalendarRecurrenceExclusion.php');
954  $excl = new ilCalendarRecurrenceExclusion();
955  $excl->setEntryId($_REQUEST['app_id']);
956  $excl->setDate(new ilDate($_REQUEST['dt'], IL_CAL_UNIX));
957  $excl->save();
958 
959  if($a_return)
960  {
961  ilUtil::sendSuccess($this->lng->txt('cal_deleted_app'),true);
962  $this->ctrl->returnToParent($this);
963  }
964  }
965 
973  protected function initTimeZone()
974  {
975  global $ilUser;
976 
977  $this->timezone = $ilUser->getTimeZone();
978  }
979 
984  protected function initInitialDate(ilDate $initialDate)
985  {
986  if(!isset($_GET['hour']))
987  {
988  $this->initialDate = clone $initialDate;
989  $this->default_fulltime = true;
990  }
991  else
992  {
993  if((int) $_GET['hour'] < 10)
994  {
995  $time = '0'.(int) $_GET['hour'].':00:00';
996  }
997  else
998  {
999  $time = (int) $_GET['hour'].':00:00';
1000  }
1001  $this->initialDate = new ilDateTime($initialDate->get(IL_CAL_DATE).' '.$time,IL_CAL_DATETIME,$this->timezone);
1002  $this->default_fulltime = false;
1003  }
1004  }
1005 
1013  protected function initSeed(ilDate $seed)
1014  {
1015  $this->seed = clone $seed;
1016  $this->default_fulltime = true;
1017  }
1018 
1026  protected function initAppointment($a_app_id = 0)
1027  {
1028  include_once('./Services/Calendar/classes/class.ilCalendarEntry.php');
1029  include_once('./Services/Calendar/classes/class.ilCalendarRecurrences.php');
1030  $this->app = new ilCalendarEntry($a_app_id);
1031 
1032  include_once './Services/Calendar/classes/class.ilCalendarUserNotification.php';
1033  $this->notification = new ilCalendarUserNotification($this->app->getEntryId());
1034 
1035  if(!$a_app_id)
1036  {
1037  $start = clone $this->initialDate;
1038  $this->app->setStart($start);
1039 
1040  $seed_end = clone $this->initialDate;
1041  if($this->default_fulltime)
1042  {
1043  #$seed_end->increment(IL_CAL_DAY,1);
1044  }
1045  else
1046  {
1047  $seed_end->increment(IL_CAL_HOUR,1);
1048  }
1049  $this->app->setEnd($seed_end);
1050  $this->app->setFullday($this->default_fulltime);
1051 
1052  $this->rec = new ilCalendarRecurrence();
1053  }
1054  else
1055  {
1056  $this->rec = ilCalendarRecurrences::_getFirstRecurrence($this->app->getEntryId());
1057  }
1058 
1059  }
1060 
1068  protected function load($a_as_milestone = false)
1069  {
1070  if ($a_as_milestone)
1071  {
1072  $this->app->setMilestone(true);
1073  $this->app->setCompletion(ilUtil::stripSlashes($_POST['completion']));
1074  }
1075 
1076  $this->app->setTitle(ilUtil::stripSlashes($_POST['title']));
1077  $this->app->setLocation(ilUtil::stripSlashes($_POST['location']));
1078  $this->app->setDescription(ilUtil::stripSlashes($_POST['description']));
1079  $this->app->setTitle(ilUtil::stripSlashes($_POST['title']));
1080  $this->app->enableNotification((int) $_POST['not']);
1081  if ($a_as_milestone) // milestones are always fullday events
1082  {
1083  $this->app->setFullday(true);
1084  }
1085  else
1086  {
1087  $this->app->setFullday(isset($_POST['event']['fulltime']) ? true : false);
1088  }
1089 
1090  if($this->app->isFullday())
1091  {
1092  $start = new ilDate($_POST['event']['start']['date']['y'].'-'.$_POST['event']['start']['date']['m'].'-'.$_POST['event']['start']['date']['d'],
1093  IL_CAL_DATE);
1094  $this->app->setStart($start);
1095 
1096  $end = new ilDate($_POST['event']['end']['date']['y'].'-'.$_POST['event']['end']['date']['m'].'-'.$_POST['event']['end']['date']['d'],
1097  IL_CAL_DATE);
1098 
1099  if ($a_as_milestone)
1100  {
1101  // for milestones is end date = start date
1102  $this->app->setEnd($start);
1103  }
1104  else
1105  {
1106  $this->app->setEnd($end);
1107  }
1108  }
1109  else
1110  {
1111  $start_dt['year'] = (int) $_POST['event']['start']['date']['y'];
1112  $start_dt['mon'] = (int) $_POST['event']['start']['date']['m'];
1113  $start_dt['mday'] = (int) $_POST['event']['start']['date']['d'];
1114  $start_dt['hours'] = (int) $_POST['event']['start']['time']['h'];
1115  $start_dt['minutes'] = (int) $_POST['event']['start']['time']['m'];
1116  $start = new ilDateTime($start_dt,IL_CAL_FKT_GETDATE,$this->timezone);
1117  $this->app->setStart($start);
1118 
1119  $end_dt['year'] = (int) $_POST['event']['end']['date']['y'];
1120  $end_dt['mon'] = (int) $_POST['event']['end']['date']['m'];
1121  $end_dt['mday'] = (int) $_POST['event']['end']['date']['d'];
1122  $end_dt['hours'] = (int) $_POST['event']['end']['time']['h'];
1123  $end_dt['minutes'] = (int) $_POST['event']['end']['time']['m'];
1124  $end = new ilDateTime($end_dt,IL_CAL_FKT_GETDATE,$this->timezone);
1125  $this->app->setEnd($end);
1126  }
1127  $this->loadNotificationRecipients();
1128  $this->loadRecurrenceSettings($a_as_milestone = false);
1129  }
1130 
1131  protected function loadNotificationRecipients()
1132  {
1133  $this->notification->setRecipients(array());
1134 
1135  foreach((array) $_POST['notu'] as $rcp)
1136  {
1137  $rcp = trim(ilUtil::stripSlashes($rcp));
1138  $usr_id = ilObjUser::_loginExists($rcp);
1139 
1140  if(strlen($rcp) == 0)
1141  {
1142  continue;
1143  }
1144 
1145  if($usr_id)
1146  {
1147  $this->notification->addRecipient(
1149  $usr_id
1150  );
1151  }
1152  else
1153  {
1154  $this->notification->addRecipient(
1156  0,
1157  $rcp
1158  );
1159  }
1160  }
1161  }
1162 
1169  protected function loadRecurrenceSettings($a_as_milestone = false)
1170  {
1171  $this->rec->reset();
1172 
1173  switch($_POST['frequence'])
1174  {
1175  case IL_CAL_FREQ_DAILY:
1176  $this->rec->setFrequenceType($_POST['frequence']);
1177  $this->rec->setInterval((int) $_POST['count_DAILY']);
1178  break;
1179 
1180  case IL_CAL_FREQ_WEEKLY:
1181  $this->rec->setFrequenceType($_POST['frequence']);
1182  $this->rec->setInterval((int) $_POST['count_WEEKLY']);
1183  if(is_array($_POST['byday_WEEKLY']))
1184  {
1185  $this->rec->setBYDAY(ilUtil::stripSlashes(implode(',',$_POST['byday_WEEKLY'])));
1186  }
1187  break;
1188 
1189  case IL_CAL_FREQ_MONTHLY:
1190  $this->rec->setFrequenceType($_POST['frequence']);
1191  $this->rec->setInterval((int) $_POST['count_MONTHLY']);
1192  switch((int) $_POST['subtype_MONTHLY'])
1193  {
1194  case 0:
1195  // nothing to do;
1196  break;
1197 
1198  case 1:
1199  switch((int) $_POST['monthly_byday_day'])
1200  {
1201  case 8:
1202  // Weekday
1203  $this->rec->setBYSETPOS((int) $_POST['monthly_byday_num']);
1204  $this->rec->setBYDAY('MO,TU,WE,TH,FR');
1205  break;
1206 
1207  case 9:
1208  // Day of month
1209  $this->rec->setBYMONTHDAY((int) $_POST['monthly_byday_num']);
1210  break;
1211 
1212  default:
1213  $this->rec->setBYDAY((int) $_POST['monthly_byday_num'].$_POST['monthly_byday_day']);
1214  break;
1215  }
1216  break;
1217 
1218  case 2:
1219  $this->rec->setBYMONTHDAY((int) $_POST['monthly_bymonthday']);
1220  break;
1221  }
1222  break;
1223 
1224  case IL_CAL_FREQ_YEARLY:
1225  $this->rec->setFrequenceType($_POST['frequence']);
1226  $this->rec->setInterval((int) $_POST['count_YEARLY']);
1227  switch((int) $_POST['subtype_YEARLY'])
1228  {
1229  case 0:
1230  // nothing to do;
1231  break;
1232 
1233  case 1:
1234  $this->rec->setBYMONTH((int) $_POST['yearly_bymonth_byday']);
1235  $this->rec->setBYDAY((int) $_POST['yearly_byday_num'].$_POST['yearly_byday']);
1236  break;
1237 
1238  case 2:
1239  $this->rec->setBYMONTH((int) $_POST['yearly_bymonth_by_monthday']);
1240  $this->rec->setBYMONTHDAY((int) $_POST['yearly_bymonthday']);
1241  break;
1242  }
1243  break;
1244  }
1245 
1246  // UNTIL
1247  switch((int) $_POST['until_type'])
1248  {
1249  case 1:
1250  $this->rec->setFrequenceUntilDate(null);
1251  // nothing to do
1252  break;
1253 
1254  case 2:
1255  $this->rec->setFrequenceUntilDate(null);
1256  $this->rec->setFrequenceUntilCount((int) $_POST['count']);
1257  break;
1258 
1259  case 3:
1260  $end_dt['year'] = (int) $_POST['until_end']['date']['y'];
1261  $end_dt['mon'] = (int) $_POST['until_end']['date']['m'];
1262  $end_dt['mday'] = (int) $_POST['until_end']['date']['d'];
1263 
1264  $this->rec->setFrequenceUntilCount(0);
1265  $this->rec->setFrequenceUntilDate(new ilDate($end_dt,IL_CAL_FKT_GETDATE,$this->timezone));
1266  break;
1267  }
1268 
1269  }
1270 
1278  protected function saveRecurrenceSettings()
1279  {
1280  switch($_POST['frequence'])
1281  {
1282  case 'NONE':
1283  case '':
1284  // No recurrence => delete if there is an recurrence rule
1285  if($this->rec->getRecurrenceId())
1286  {
1287  $this->rec->delete();
1288  }
1289  break;
1290 
1291  default:
1292  if($this->rec->getRecurrenceId())
1293  {
1294  $this->rec->update();
1295  }
1296  else
1297  {
1298  $this->rec->save();
1299  }
1300  break;
1301  }
1302  }
1303 
1310  protected function createDefaultCalendar()
1311  {
1312  global $ilUser,$lng;
1313 
1314  $cat = new ilCalendarCategory();
1315  $cat->setColor(ilCalendarCategory::DEFAULT_COLOR);
1316  $cat->setType(ilCalendarCategory::TYPE_USR);
1317  $cat->setTitle($this->lng->txt('cal_default_calendar'));
1318  $cat->setObjId($ilUser->getId());
1319  return $cat->add();
1320  }
1321 
1326  protected function confirmRegister()
1327  {
1328  global $tpl;
1329 
1330  $entry = new ilCalendarEntry((int) $_GET['app_id']);
1332  new ilDateTime($_GET['dstart'],IL_CAL_UNIX),
1333  new ilDateTime($_GET['dend'],IL_CAL_UNIX)
1334  );
1335 
1336 
1337  include_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
1338  $conf = new ilConfirmationGUI;
1339 
1340  $this->ctrl->setParameter($this,'dstart',(int) $_REQUEST['dstart']);
1341  $this->ctrl->setParameter($this,'dend',(int) $_REQUEST['dend']);
1342 
1343  $conf->setFormAction($this->ctrl->getFormAction($this));
1344  $conf->setHeaderText($this->lng->txt('cal_confirm_reg_info'));
1345  $conf->setConfirm($this->lng->txt('cal_reg_register'), 'register');
1346  $conf->setCancel($this->lng->txt('cancel'), 'cancel');
1347  $conf->addItem('app_id', $entry->getEntryId(), $entry->getTitle().' ('.$start.')');
1348 
1349  $tpl->setContent($conf->getHTML());
1350  }
1351 
1356  protected function register()
1357  {
1358  global $ilUser;
1359 
1360  include_once './Services/Calendar/classes/class.ilCalendarRegistration.php';
1361  $reg = new ilCalendarRegistration((int) $_POST['app_id']);
1362  $reg->register(
1363  $ilUser->getId(),
1364  new ilDateTime((int) $_REQUEST['dstart'],IL_CAL_UNIX),
1365  new ilDateTime((int) $_REQUEST['dend'],IL_CAL_UNIX)
1366  );
1367 
1368  ilUtil::sendSuccess($this->lng->txt('cal_reg_registered'),true);
1369  $this->ctrl->returnToParent($this);
1370  }
1371 
1375  public function confirmUnregister()
1376  {
1377  global $tpl;
1378 
1379 
1380  $entry = new ilCalendarEntry((int) $_GET['app_id']);
1382  $dstart = new ilDateTime($_GET['dstart'],IL_CAL_UNIX),
1383  $dend = new ilDateTime($_GET['dend'],IL_CAL_UNIX)
1384  );
1385 
1386 
1387  include_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
1388  $conf = new ilConfirmationGUI;
1389 
1390  $this->ctrl->setParameter($this,'dstart',(int) $_REQUEST['dstart']);
1391  $this->ctrl->setParameter($this,'dend',(int) $_REQUEST['dend']);
1392 
1393  $conf->setFormAction($this->ctrl->getFormAction($this));
1394  $conf->setHeaderText($this->lng->txt('cal_confirm_unreg_info'));
1395  $conf->setConfirm($this->lng->txt('cal_reg_unregister'), 'unregister');
1396  $conf->setCancel($this->lng->txt('cancel'), 'cancel');
1397  $conf->addItem('app_id', $entry->getEntryId(), $entry->getTitle().' ('.$start.')');
1398 
1399  $tpl->setContent($conf->getHTML());
1400  }
1401 
1406  protected function unregister()
1407  {
1408  global $ilUser;
1409 
1410  include_once './Services/Calendar/classes/class.ilCalendarRegistration.php';
1411  $reg = new ilCalendarRegistration((int) $_POST['app_id']);
1412  $reg->unregister(
1413  $ilUser->getId(),
1414  new ilDateTime((int) $_REQUEST['dstart'],IL_CAL_UNIX),
1415  new ilDateTime((int) $_REQUEST['dend'],IL_CAL_UNIX)
1416  );
1417 
1418  ilUtil::sendSuccess($this->lng->txt('cal_reg_unregistered'),true);
1419  $this->ctrl->returnToParent($this);
1420  }
1421 
1425  public function book()
1426  {
1427  global $ilUser, $tpl;
1428 
1429  $entry = (int)$_GET['app_id'];
1430  $user = (int)$_GET['bkid'];
1431 
1432  $this->ctrl->saveParameter($this,'app_id');
1433 
1434  include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
1435  include_once 'Services/Booking/classes/class.ilBookingEntry.php';
1436  $entry = new ilCalendarEntry($entry);
1437 
1438  $form = $this->initFormConfirmBooking();
1439  $form->getItemByPostVar('date')->setValue(ilDatePresentation::formatPeriod($entry->getStart(), $entry->getEnd()));
1440  $form->getItemByPostVar('title')->setValue($entry->getTitle()." (".ilObjUser::_lookupFullname($user).')');
1441 
1442  $tpl->setContent($form->getHTML());
1443  return true;
1444  }
1445 
1450  protected function initFormConfirmBooking()
1451  {
1452  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
1453  $form = new ilPropertyFormGUI();
1454  $form->setFormAction($this->ctrl->getFormAction($this));
1455  $form->addCommandButton('bookconfirmed',$this->lng->txt('cal_confirm_booking'));
1456  $form->addCommandButton('cancel',$this->lng->txt('cancel'));
1457 
1458  $date = new ilNonEditableValueGUI($this->lng->txt('appointment'),'date');
1459  $form->addItem($date);
1460 
1461  $title = new ilNonEditableValueGUI($this->lng->txt('title'),'title');
1462  $form->addItem($title);
1463 
1464  $message = new ilTextAreaInputGUI($this->lng->txt('cal_ch_booking_message_tbl'), 'comment');
1465  $message->setRows(5);
1466  $form->addItem($message);
1467 
1468  return $form;
1469  }
1470 
1474  public function bookconfirmed()
1475  {
1476  global $ilUser;
1477 
1478  $entry = (int) $_REQUEST['app_id'];
1479  $user = (int) $_REQUEST['bkid'];
1480 
1481  $form = $this->initFormConfirmBooking();
1482  if($form->checkInput())
1483  {
1484  // check if appointment is bookable
1485  include_once './Services/Calendar/classes/class.ilCalendarEntry.php';
1486  $cal_entry = new ilCalendarEntry($entry);
1487 
1488  include_once './Services/Booking/classes/class.ilBookingEntry.php';
1489  $booking = new ilBookingEntry($cal_entry->getContextId());
1490 
1491  if(!$booking->isAppointmentBookableForUser($entry, $GLOBALS['ilUser']->getId()))
1492  {
1493  ilUtil::sendFailure($this->lng->txt('cal_booking_failed_info'), true);
1494  $this->ctrl->returnToParent($this);
1495  }
1496 
1497  include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourUtils.php';
1498  ilConsultationHourUtils::bookAppointment($ilUser->getId(), $entry);
1499 
1500  include_once './Services/Booking/classes/class.ilBookingEntry.php';
1501  ilBookingEntry::writeBookingMessage($entry, $ilUser->getId(), $form->getInput('comment'));
1502  }
1503  ilUtil::sendSuccess($this->lng->txt('cal_booking_confirmed'),true);
1504  $this->ctrl->returnToParent($this);
1505  }
1506 
1511  public function cancelBooking()
1512  {
1513  global $ilUser, $tpl;
1514 
1515  $entry = (int)$_GET['app_id'];
1516 
1517  include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
1518  $entry = new ilCalendarEntry($entry);
1519 
1520  $category = $this->calendarEntryToCategory($entry);
1521  if($category->getType() == ilCalendarCategory::TYPE_CH)
1522  {
1523  include_once 'Services/Booking/classes/class.ilBookingEntry.php';
1524  $booking = new ilBookingEntry($entry->getContextId());
1525  if(!$booking->hasBooked($entry->getEntryId()))
1526  {
1527  $this->ctrl->returnToParent($this);
1528  return false;
1529  }
1530 
1531  $entry_title = ' '.$entry->getTitle()." (".ilObjUser::_lookupFullname($booking->getObjId()).')';
1532  }
1533  else if($category->getType() == ilCalendarCategory::TYPE_BOOK)
1534  {
1535  $entry_title = ' '.$entry->getTitle();
1536  }
1537  else
1538  {
1539  $this->ctrl->returnToParent($this);
1540  return false;
1541  }
1542 
1543  $title = ilDatePresentation::formatPeriod($entry->getStart(), $entry->getEnd());
1544 
1545  include_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
1546  $conf = new ilConfirmationGUI;
1547  $conf->setFormAction($this->ctrl->getFormAction($this));
1548  $conf->setHeaderText($this->lng->txt('cal_cancel_booking_info'));
1549  $conf->setConfirm($this->lng->txt('cal_cancel_booking'), 'cancelconfirmed');
1550  $conf->setCancel($this->lng->txt('cancel'), 'cancel');
1551  $conf->addItem('app_id', $entry->getEntryId(), $title.' - '.$entry_title);
1552 
1553  $tpl->setContent($conf->getHTML());
1554  }
1555 
1560  public function cancelConfirmed()
1561  {
1562  global $ilUser;
1563 
1564  $entry = (int)$_POST['app_id'];
1565  $user = (int)$_GET['bkid'];
1566 
1567  include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
1568  $entry = new ilCalendarEntry($entry);
1569 
1570  $category = $this->calendarEntryToCategory($entry);
1571  if($category->getType() == ilCalendarCategory::TYPE_CH)
1572  {
1573  // find cloned calendar entry in user calendar
1574  include_once 'Services/Calendar/classes/ConsultationHours/class.ilConsultationHourAppointments.php';
1575  $GLOBALS['ilLog']->dump($entry->getStart());
1577  $ilUser->getId(),
1578  $entry->getContextId(),
1579  $entry->getStart(),
1581  false);
1582  $GLOBALS['ilLog']->dump($apps);
1583 
1584  // Fix for wrong, old entries
1585  foreach((array) $apps as $own_app)
1586  {
1587  $ref_entry = new ilCalendarEntry($own_app);
1588  $ref_entry->delete();
1589  }
1590 
1591  include_once 'Services/Booking/classes/class.ilBookingEntry.php';
1592  $booking = new ilBookingEntry($entry->getContextId());
1593  $booking->cancelBooking($entry->getEntryId());
1594 
1595  // do NOT delete original entry
1596  }
1597  else if($category->getType() == ilCalendarCategory::TYPE_BOOK)
1598  {
1599  include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
1600  $booking = new ilBookingReservation($entry->getContextId());
1602  $booking->update();
1603 
1604  $entry->delete();
1605  }
1606 
1607  ilUtil::sendSuccess($this->lng->txt('cal_cancel_booking_confirmed'),true);
1608  $this->ctrl->returnToParent($this);
1609  }
1610 
1616  protected function calendarEntryToCategory(ilCalendarEntry $entry)
1617  {
1618  include_once 'Services/Calendar/classes/class.ilCalendarCategoryAssignments.php';
1619  include_once 'Services/Calendar/classes/class.ilCalendarCategory.php';
1620  $assignment = new ilCalendarCategoryAssignments($entry->getEntryId());
1621  $assignment = $assignment->getFirstAssignment();
1622  return new ilCalendarCategory($assignment);
1623  }
1624 
1629  protected function doUserAutoComplete()
1630  {
1631  if(!isset($_GET['autoCompleteField']))
1632  {
1633  $a_fields = array('login','firstname','lastname','email');
1634  }
1635  else
1636  {
1637  $a_fields = array((string) $_GET['autoCompleteField']);
1638  }
1639 
1640  $GLOBALS['ilLog']->write(print_r($a_fields,true));
1641  include_once './Services/User/classes/class.ilUserAutoComplete.php';
1642  $auto = new ilUserAutoComplete();
1643  $auto->setSearchFields($a_fields);
1644  $auto->enableFieldSearchableCheck(true);
1645  $auto->setMoreLinkAvailable(true);
1646 
1647  if(($_REQUEST['fetchall']))
1648  {
1649  $auto->setLimit(ilUserAutoComplete::MAX_ENTRIES);
1650  }
1651 
1652  echo $auto->getList($_REQUEST['query']);
1653  exit();
1654  }
1655 
1656 }
1657 ?>