ILIAS  Release_4_4_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->setMinuteStepSize(5);
251  $dur->setShowDate(true);
252  $dur->setShowTime(true);
253  $dur->setStart($this->app->getStart());
254  $dur->setEnd($this->app->getEnd());
255  $this->form->addItem($dur);
256 
257  // recurrence
258  include_once('./Services/Calendar/classes/Form/class.ilRecurrenceInputGUI.php');
259  $rec = new ilRecurrenceInputGUI($this->lng->txt('cal_recurrences'),'frequence');
260  $rec->setRecurrence($this->rec);
261  $this->form->addItem($rec);
262 
263  // location
264  $where = new ilTextInputGUI($this->lng->txt('cal_where'),'location');
265  $where->setValue($this->app->getLocation());
266  $where->setMaxLength(128);
267  $where->setSize(32);
268  $this->form->addItem($where);
269  }
270  else
271  {
272  $deadline = new ilDateTimeInputGUI($this->lng->txt('cal_deadline'),'event[start]');
273  $deadline->setDate($this->app->getStart());
274  $deadline->setShowTime(false);
275  $deadline->setMinuteStepSize(5);
276  $this->form->addItem($deadline);
277 
278  // completion
279  $completion_vals = array();
280  for($i = 0; $i <= 100; $i+=5)
281  {
282  $completion_vals[$i] = $i." %";
283  }
284  $compl = new ilSelectInputGUI($this->lng->txt('cal_task_completion'),
285  'completion');
286  $compl->setOptions($completion_vals);
287  $compl->setValue($this->app->getCompletion());
288  $this->form->addItem($compl);
289  }
290 
291  $desc = new ilTextAreaInputGUI($this->lng->txt('description'),'description');
292  $desc->setValue($this->app->getDescription());
293  $desc->setRows(5);
294  $this->form->addItem($desc);
295 
296  if ($a_as_milestone && $a_mode == "edit" && $resp_info)
297  {
298  // users responsible
299  $users = $this->app->readResponsibleUsers();
300  $resp = new ilNonEditableValueGUI($this->lng->txt('cal_responsible'),
301  $users);
302  $delim = "";
303  foreach($users as $r)
304  {
305  $value.= $delim.$r["lastname"].", ".$r["firstname"]." [".$r["login"]."]";
306  $delim = "<br />";
307  }
308  if (count($users) > 0)
309  {
310  $resp->setValue($value);
311  }
312  else
313  {
314  $resp->setValue("-");
315  }
316 
317  $this->form->addItem($resp);
318  }
319 
320 
321  if(ilCalendarSettings::_getInstance()->isUserNotificationEnabled())
322  {
323  $notu = new ilTextWizardInputGUI($this->lng->txt('cal_user_notification'), 'notu');
324  $notu->setInfo($this->lng->txt('cal_user_notification_info'));
325  $notu->setSize(20);
326  $notu->setMaxLength(64);
327 
328  $values = array();
329  foreach($this->notification->getRecipients() as $rcp)
330  {
331  switch ($rcp['type'])
332  {
334  $values[] = ilObjUser::_lookupLogin($rcp['usr_id']);
335  break;
336 
338  $values[] = $rcp['email'];
339  break;
340  }
341  }
342  if(count($values))
343  $notu->setValues($values);
344  else
345  $notu->setValues(array(''));
346  $this->form->addItem($notu);
347  }
348 
349  // Notifications
350  include_once './Services/Calendar/classes/class.ilCalendarSettings.php';
351  if(ilCalendarSettings::_getInstance()->isNotificationEnabled() and count($cats->getNotificationCalendars()))
352  {
353  $selected_cal = new ilCalendarCategory($selected_calendar);
354  $disabled = true;
355  if($selected_cal->getType() == ilCalendarCategory::TYPE_OBJ)
356  {
357  if(ilObject::_lookupType($selected_cal->getObjId()) == 'crs' or ilObject::_lookupType($selected_cal->getObjId()) == 'grp')
358  {
359  $disabled = false;
360  }
361  }
362 
363  $tpl->addJavaScript('./Services/Calendar/js/toggle_notification.js');
364  $not = new ilCheckboxInputGUI($this->lng->txt('cal_cg_notification'),'not');
365  $not->setInfo($this->lng->txt('cal_notification_info'));
366  $not->setValue(1);
367  $not->setChecked($this->app->isNotificationEnabled());
368  $not->setDisabled($disabled);
369  $this->form->addItem($not);
370  }
371  }
372 
373 
380  protected function add()
381  {
382  global $tpl, $ilHelp;
383 
384  $ilHelp->setScreenIdComponent("cal");
385  $ilHelp->setScreenId("app");
386  $ilHelp->setSubScreenId("create");
387 
388  $this->initForm('create');
389  $tpl->setContent($this->form->getHTML());
390  }
391 
398  protected function addMilestone()
399  {
400  global $tpl, $ilHelp;
401 
402  $ilHelp->setScreenIdComponent("cal");
403  $ilHelp->setScreenId("app");
404  $ilHelp->setSubScreenId("create_milestone");
405 
406  $this->initForm('create', true);
407  $tpl->setContent($this->form->getHTML());
408  }
409 
415  protected function saveMilestone()
416  {
417  $this->save(true);
418  }
419 
425  protected function save($a_as_milestone = false)
426  {
427  global $ilErr;
428 
429  $this->load($a_as_milestone);
430 
431  if($this->app->validate() and $this->notification->validate())
432  {
433  if(!(int) $_POST['calendar'])
434  {
435  $cat_id = $this->createDefaultCalendar();
436  }
437  else
438  {
439  $cat_id = (int) $_POST['calendar'];
440  }
441 
442  $this->app->save();
443  $this->notification->setEntryId($this->app->getEntryId());
444  $this->notification->save();
445  $this->rec->setEntryId($this->app->getEntryId());
446  $this->saveRecurrenceSettings();
447 
448  include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
449  $ass = new ilCalendarCategoryAssignments($this->app->getEntryId());
450  $ass->addAssignment($cat_id);
451 
452  // Send notifications
453  include_once './Services/Calendar/classes/class.ilCalendarSettings.php';
454  if(ilCalendarSettings::_getInstance()->isNotificationEnabled() and (bool) $_POST['not'])
455  {
456  $this->distributeNotifications($cat_id,$this->app->getEntryId(),true);
457  }
458  if(ilCalendarSettings::_getInstance()->isUserNotificationEnabled())
459  {
461  }
462 
463  include_once('./Services/Calendar/classes/class.ilCalendarCategory.php');
464  $cat_info = ilCalendarCategories::_getInstance()->getCategoryInfo($cat_id);
465  $type = ilObject::_lookupType($cat_info['obj_id']);
466 
467  if ($a_as_milestone && $cat_info['type'] == ilCalendarCategory::TYPE_OBJ
468  && ($type == "grp" || $type == "crs"))
469  {
470  ilUtil::sendSuccess($this->lng->txt('cal_created_milestone_resp_q'),true);
471  return $this->showResponsibleUsersList($cat_info['obj_id']);
472  }
473  elseif($a_as_milestone)
474  {
475  ilUtil::sendSuccess($this->lng->txt('cal_created_milestone'),true);
476  $this->ctrl->returnToParent($this);
477  }
478  else
479  {
480  ilUtil::sendSuccess($this->lng->txt('cal_created_appointment'),true);
481  $this->ctrl->returnToParent($this);
482  }
483  }
484  else
485  {
486  ilUtil::sendFailure($ilErr->getMessage());
487  }
488  if ($a_as_milestone)
489  {
490  $this->addMilestone();
491  }
492  else
493  {
494  $this->add();
495  }
496  }
497 
502  protected function distributeUserNotifications()
503  {
504  global $ilUser;
505 
506  include_once './Services/Calendar/classes/class.ilCalendarMailNotification.php';
507  $notification = new ilCalendarMailNotification();
508  $notification->setAppointmentId($this->app->getEntryId());
509 
510  foreach($this->notification->getRecipients() as $rcp)
511  {
512  switch($rcp['type'])
513  {
515  $notification->setSender(ANONYMOUS_USER_ID);
516  $notification->setRecipients(array($rcp['usr_id']));
517  $notification->setType(ilCalendarMailNotification::TYPE_USER);
518  break;
519 
521  $notification->setSender(ANONYMOUS_USER_ID);
522  $notification->setRecipients(array($rcp['email']));
523  $notification->setType(ilCalendarMailNotification::TYPE_USER_ANONYMOUS);
524  break;
525  }
526  $notification->send();
527  }
528  }
529 
530 
535  protected function distributeNotifications($a_cat_id, $app_id, $a_new_appointment = true)
536  {
537  include_once('./Services/Calendar/classes/class.ilCalendarCategory.php');
538  $cat_info = ilCalendarCategories::_getInstance()->getCategoryInfo($a_cat_id);
539 
540  include_once './Services/Calendar/classes/class.ilCalendarMailNotification.php';
541  $notification = new ilCalendarMailNotification();
542  $notification->setAppointmentId($app_id);
543 
544  switch($cat_info['type'])
545  {
547 
548  switch($cat_info['obj_type'])
549  {
550  case 'crs':
551  $ref_ids = ilObject::_getAllReferences($cat_info['obj_id']);
552  $ref_id = current($ref_ids);
553  $notification->setRefId($ref_id);
554  $notification->setType(
555  $a_new_appointment ?
558  break;
559 
560  case 'grp':
561  $ref_ids = ilObject::_getAllReferences($cat_info['obj_id']);
562  $ref_id = current($ref_ids);
563  $notification->setRefId($ref_id);
564  $notification->setType(
565  $a_new_appointment ?
568  break;
569  }
570  break;
571  }
572 
573  $notification->send();
574  }
575 
580  {
581  include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
582  $cat_id = ilCalendarCategoryAssignments::_lookupCategory($this->app->getEntryId());
583  include_once('./Services/Calendar/classes/class.ilCalendarCategory.php');
584  $cat_info = ilCalendarCategories::_getInstance()->getCategoryInfo($cat_id);
585 
586  $this->showResponsibleUsersList($cat_info['obj_id']);
587  }
588 
593  function showResponsibleUsersList($a_grp_id)
594  {
595  global $tpl;
596 
597  include_once("./Services/Calendar/classes/class.ilMilestoneResponsiblesTableGUI.php");
598  $table_gui = new ilMilestoneResponsiblesTableGUI($this, "", $a_grp_id,
599  $this->app->getEntryId());
600  $tpl->setContent($table_gui->getHTML());
601  }
602 
607  {
608  global $ilCtrl;
609 
610  $this->app->writeResponsibleUsers($_POST["user_id"]);
611  $ilCtrl->returnToParent($this);
612  }
613 
618  protected function askEdit()
619  {
620  // check for recurring entries
621  include_once './Services/Calendar/classes/class.ilCalendarRecurrences.php';
623  if(!$rec)
624  {
625  return $this->edit();
626  }
627  // Show edit single/all appointments
628  $this->ctrl->saveParameter($this,array('seed','app_id','dt','idate'));
629 
630  include_once('./Services/Utilities/classes/class.ilConfirmationGUI.php');
631  $confirm = new ilConfirmationGUI();
632  $confirm->setFormAction($this->ctrl->getFormAction($this));
633  #$confirm->setHeaderText($this->lng->txt('cal_edit_app_sure'));
634  $confirm->setCancel($this->lng->txt('cancel'),'cancel');
635  $confirm->addItem('appointments[]',$this->app->getEntryId(),$this->app->getTitle());
636  $confirm->addButton($this->lng->txt('cal_edit_single'),'editSingle');
637  $confirm->setConfirm($this->lng->txt('cal_edit_recurrences'),'edit');
638 
639  $GLOBALS['tpl']->setContent($confirm->getHTML());
640  }
641 
645  protected function editSingle()
646  {
647  $_REQUEST['rexl'] = 1;
648  $GLOBALS['ilCtrl']->setParameter($this,'rexcl',1);
649  $this->edit(true);
650  }
651 
659  protected function edit($a_edit_single_app = false)
660  {
661  global $tpl,$ilUser,$ilErr, $ilHelp;
662 
663  $ilHelp->setScreenIdComponent("cal");
664  $ilHelp->setScreenId("app");
665  if ($this->app->isMilestone())
666  {
667  $ilHelp->setSubScreenId("edit_milestone");
668  }
669  else
670  {
671  $ilHelp->setSubScreenId("edit");
672  }
673 
674  include_once('./Services/Calendar/classes/class.ilCalendarCategory.php');
675  include_once('./Services/Calendar/classes/class.ilCalendarCategories.php');
676  include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
677 
678  $GLOBALS['ilCtrl']->saveParameter($this,array('seed','app_id','dt','idate'));
679 
680  if($_REQUEST['rexl'])
681  {
682  $GLOBALS['ilCtrl']->setParameter($this,'rexl',1);
683 
684  // Calculate new appointment time
685  $duration = $this->getAppointment()->getEnd()->get(IL_CAL_UNIX) - $this->getAppointment()->getStart()->get(IL_CAL_UNIX);
686  include_once './Services/Calendar/classes/class.ilCalendarRecurrenceCalculator.php';
687  $calc = new ilCalendarRecurrenceCalculator($this->getAppointment(), $this->rec);
688 
689  $current_date = new ilDateTime($_REQUEST['dt'],IL_CAL_UNIX);
690 
691  $yesterday = clone $current_date;
692  $yesterday->increment(IL_CAL_DAY,-1);
693  $tomorrow = clone $current_date;
694  $tomorrow->increment(IL_CAL_DAY, 1);
695 
696 
697  foreach($calc->calculateDateList($current_date, $tomorrow, 1) as $date_entry)
698  {
699  if(ilDateTime::_equals($current_date, $date_entry,IL_CAL_DAY))
700  {
701  $this->getAppointment()->setStart(new ilDateTime($date_entry->get(IL_CAL_UNIX),IL_CAL_UNIX));
702  $this->getAppointment()->setEnd(new ilDateTime($date_entry->get(IL_CAL_UNIX) + $duration,IL_CAL_UNIX));
703  break;
704  }
705  }
706 
707  // Finally reset recurrence
708  $this->rec = new ilCalendarRecurrence();
709  }
710 
711  $cat_id = ilCalendarCategoryAssignments::_lookupCategory($this->app->getEntryId());
712  $cats = ilCalendarCategories::_getInstance($ilUser->getId());
713 
714  if(!$cats->isVisible($cat_id))
715  {
716  $ilErr->raiseError($this->lng->txt('permission_denied'),$ilErr->WARNING);
717  return false;
718  }
719  if(!$cats->isEditable($cat_id) or $this->app->isAutoGenerated())
720  {
721  $this->showInfoScreen();
722  return true;
723  }
724 
725  $this->initForm('edit', $this->app->isMilestone(), $a_edit_single_app);
726  $tpl->setContent($this->form->getHTML());
727  }
728 
735  protected function showInfoScreen()
736  {
737  global $tpl,$ilUser;
738 
739  include_once("./Services/InfoScreen/classes/class.ilInfoScreenGUI.php");
740  $info = new ilInfoScreenGUI($this);
741  $info->setFormAction($this->ctrl->getFormAction($this));
742 
743  if ($this->app->isMilestone())
744  {
745  $info->addSection($this->lng->txt('cal_ms_details'));
746  }
747  else
748  {
749  $info->addSection($this->lng->txt('cal_details'));
750  }
751 
752  // Appointment
753  $info->addProperty($this->lng->txt('appointment'),
755  $this->app->getStart(),
756  $this->app->getEnd()));
757  $info->addProperty($this->lng->txt('title'),$this->app->getPresentationTitle());
758 
759  // Description
760  if(strlen($desc = $this->app->getDescription()))
761  {
762  $info->addProperty($this->lng->txt('description'),$desc);
763  }
764 
765  // Location
766  if(strlen($loc = $this->app->getLocation()))
767  {
768  $info->addProperty($this->lng->txt('cal_where'),$loc);
769  }
770 
771  // completion
772  if ($this->app->isMilestone() && $this->app->getCompletion() > 0)
773  {
774  $info->addProperty($this->lng->txt('cal_task_completion'),
775  $this->app->getCompletion()." %");
776  }
777 
778  include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
779  $cat_id = ilCalendarCategoryAssignments::_lookupCategory($this->app->getEntryId());
780  $cat_info = ilCalendarCategories::_getInstance()->getCategoryInfo($cat_id);
781  $type = ilObject::_lookupType($cat_info['obj_id']);
782  if ($this->app->isMilestone() && $cat_info['type'] == ilCalendarCategory::TYPE_OBJ
783  && ($type == "grp" || $type == "crs"))
784  {
785  // users responsible
786  $users = $this->app->readResponsibleUsers();
787  $delim = "";
788  foreach($users as $r)
789  {
790  $value.= $delim.$r["lastname"].", ".$r["firstname"]." [".$r["login"]."]";
791  $delim = "<br />";
792  }
793  if (count($users) > 0)
794  {
795  $info->addProperty($this->lng->txt('cal_responsible'),
796  $value);
797  }
798  }
799 
800  $category = new ilCalendarCategory($cat_id);
801 
802  if($category->getType() == ilCalendarCategory::TYPE_OBJ)
803  {
804  $info->addSection($this->lng->txt('additional_info'));
805 
806  $cat_info = ilCalendarCategories::_getInstance()->getCategoryInfo($cat_id);
807  $refs = ilObject::_getAllReferences($cat_info['obj_id']);
808 
809  include_once('./Services/Link/classes/class.ilLink.php');
810  $href = ilLink::_getStaticLink(current($refs),ilObject::_lookupType($cat_info['obj_id']),true);
811  $info->addProperty($this->lng->txt('perma_link'),'<a class="small" href="'.$href.'" target="_top">'.$href.'</a>');
812  }
813 
814  $tpl->setContent($info->getHTML());
815  }
816 
823  protected function update()
824  {
825  global $ilErr;
826 
827  $single_editing = ($_REQUEST['rexl'] ? true : false);
828 
829  $this->load($this->app->isMilestone());
830 
831  if($this->app->validate() and $this->notification->validate())
832  {
833  if(!(int) $_POST['calendar'])
834  {
835  $cat_id = $this->createDefaultCalendar();
836  }
837  else
838  {
839  $cat_id = (int) $_POST['calendar'];
840  }
841 
842  if($single_editing)
843  {
844  $this->getAppointment()->save();
845  $this->deleteExclude(false);
846 
847  $this->rec = new ilCalendarRecurrence();
848  $this->rec->setEntryId($this->getAppointment()->getEntryId());
849  }
850  else
851  {
852  $this->getAppointment()->update();
853  }
854  $this->notification->save();
855  $this->saveRecurrenceSettings();
856 
857  include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
858  $ass = new ilCalendarCategoryAssignments($this->app->getEntryId());
859  $GLOBALS['ilLog']->write($this->app->getEntryId());
860  $ass->deleteAssignments();
861  $ass->addAssignment($cat_id);
862 
863  // Send notifications
864  include_once './Services/Calendar/classes/class.ilCalendarSettings.php';
865  if(ilCalendarSettings::_getInstance()->isNotificationEnabled() and (bool) $_POST['not'])
866  {
867  $this->distributeNotifications($cat_id,$this->app->getEntryId(),false);
868  }
869  if(ilCalendarSettings::_getInstance()->isUserNotificationEnabled())
870  {
872  }
873 
874  ilUtil::sendSuccess($this->lng->txt('settings_saved'),true);
875  $this->ctrl->returnToParent($this);
876  }
877  else
878  {
879  ilUtil::sendFailure($ilErr->getMessage());
880  }
881 
882  $this->edit();
883 
884  }
885 
892  protected function askDelete()
893  {
894  global $tpl;
895 
896  include_once('./Services/Utilities/classes/class.ilConfirmationGUI.php');
897 
898  $this->ctrl->saveParameter($this,array('seed','app_id','dt','idate'));
899 
900  $confirm = new ilConfirmationGUI();
901  $confirm->setFormAction($this->ctrl->getFormAction($this));
902  $confirm->setHeaderText($this->lng->txt('cal_delete_app_sure'));
903  $confirm->setCancel($this->lng->txt('cancel'),'cancel');
904  $confirm->addItem('appointments[]',$this->app->getEntryId(),$this->app->getTitle());
905 
906  include_once('./Services/Calendar/classes/class.ilCalendarRecurrences.php');
907  if(sizeof(ilCalendarRecurrences::_getRecurrences($_GET['app_id']))
908  && !$this->app->isMilestone())
909  {
910  $confirm->addButton($this->lng->txt('cal_delete_single'),'deleteexclude');
911  $confirm->setConfirm($this->lng->txt('cal_delete_recurrences'),'delete');
912  }
913  else
914  {
915  $confirm->setConfirm($this->lng->txt('delete'),'delete');
916  }
917 
918  $tpl->setContent($confirm->getHTML());
919 
920  }
921 
929  protected function delete()
930  {
931  foreach($_POST['appointments'] as $app_id)
932  {
933  $app = new ilCalendarEntry($app_id);
934  $app->delete();
935 
936  include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
938 
939  include_once './Services/Calendar/classes/class.ilCalendarUserNotification.php';
941  }
942  ilUtil::sendSuccess($this->lng->txt('cal_deleted_app'),true);
943  $this->ctrl->returnToParent($this);
944  }
945 
953  protected function deleteExclude($a_return = true)
954  {
955  include_once('./Services/Calendar/classes/class.ilCalendarRecurrenceExclusion.php');
956  $excl = new ilCalendarRecurrenceExclusion();
957  $excl->setEntryId($_REQUEST['app_id']);
958  $excl->setDate(new ilDate($_REQUEST['dt'], IL_CAL_UNIX));
959  $excl->save();
960 
961  if($a_return)
962  {
963  ilUtil::sendSuccess($this->lng->txt('cal_deleted_app'),true);
964  $this->ctrl->returnToParent($this);
965  }
966  }
967 
975  protected function initTimeZone()
976  {
977  global $ilUser;
978 
979  $this->timezone = $ilUser->getTimeZone();
980  }
981 
986  protected function initInitialDate(ilDate $initialDate)
987  {
988  if(!isset($_GET['hour']))
989  {
990  $this->initialDate = clone $initialDate;
991  $this->default_fulltime = true;
992  }
993  else
994  {
995  if((int) $_GET['hour'] < 10)
996  {
997  $time = '0'.(int) $_GET['hour'].':00:00';
998  }
999  else
1000  {
1001  $time = (int) $_GET['hour'].':00:00';
1002  }
1003  $this->initialDate = new ilDateTime($initialDate->get(IL_CAL_DATE).' '.$time,IL_CAL_DATETIME,$this->timezone);
1004  $this->default_fulltime = false;
1005  }
1006  }
1007 
1015  protected function initSeed(ilDate $seed)
1016  {
1017  $this->seed = clone $seed;
1018  $this->default_fulltime = true;
1019  }
1020 
1028  protected function initAppointment($a_app_id = 0)
1029  {
1030  include_once('./Services/Calendar/classes/class.ilCalendarEntry.php');
1031  include_once('./Services/Calendar/classes/class.ilCalendarRecurrences.php');
1032  $this->app = new ilCalendarEntry($a_app_id);
1033 
1034  include_once './Services/Calendar/classes/class.ilCalendarUserNotification.php';
1035  $this->notification = new ilCalendarUserNotification($this->app->getEntryId());
1036 
1037  if(!$a_app_id)
1038  {
1039  $start = clone $this->initialDate;
1040  $this->app->setStart($start);
1041 
1042  $seed_end = clone $this->initialDate;
1043  if($this->default_fulltime)
1044  {
1045  #$seed_end->increment(IL_CAL_DAY,1);
1046  }
1047  else
1048  {
1049  $seed_end->increment(IL_CAL_HOUR,1);
1050  }
1051  $this->app->setEnd($seed_end);
1052  $this->app->setFullday($this->default_fulltime);
1053 
1054  $this->rec = new ilCalendarRecurrence();
1055  }
1056  else
1057  {
1058  $this->rec = ilCalendarRecurrences::_getFirstRecurrence($this->app->getEntryId());
1059  }
1060 
1061  }
1062 
1070  protected function load($a_as_milestone = false)
1071  {
1072  if ($a_as_milestone)
1073  {
1074  $this->app->setMilestone(true);
1075  $this->app->setCompletion(ilUtil::stripSlashes($_POST['completion']));
1076  }
1077 
1078  $this->app->setTitle(ilUtil::stripSlashes($_POST['title']));
1079  $this->app->setLocation(ilUtil::stripSlashes($_POST['location']));
1080  $this->app->setDescription(ilUtil::stripSlashes($_POST['description']));
1081  $this->app->setTitle(ilUtil::stripSlashes($_POST['title']));
1082  $this->app->enableNotification((int) $_POST['not']);
1083  if ($a_as_milestone) // milestones are always fullday events
1084  {
1085  $this->app->setFullday(true);
1086  }
1087  else
1088  {
1089  $this->app->setFullday(isset($_POST['event']['fulltime']) ? true : false);
1090  }
1091 
1092  if($this->app->isFullday())
1093  {
1094  $start = new ilDate($_POST['event']['start']['date']['y'].'-'.$_POST['event']['start']['date']['m'].'-'.$_POST['event']['start']['date']['d'],
1095  IL_CAL_DATE);
1096  $this->app->setStart($start);
1097 
1098  $end = new ilDate($_POST['event']['end']['date']['y'].'-'.$_POST['event']['end']['date']['m'].'-'.$_POST['event']['end']['date']['d'],
1099  IL_CAL_DATE);
1100 
1101  if ($a_as_milestone)
1102  {
1103  // for milestones is end date = start date
1104  $this->app->setEnd($start);
1105  }
1106  else
1107  {
1108  $this->app->setEnd($end);
1109  }
1110  }
1111  else
1112  {
1113  $start_dt['year'] = (int) $_POST['event']['start']['date']['y'];
1114  $start_dt['mon'] = (int) $_POST['event']['start']['date']['m'];
1115  $start_dt['mday'] = (int) $_POST['event']['start']['date']['d'];
1116  $start_dt['hours'] = (int) $_POST['event']['start']['time']['h'];
1117  $start_dt['minutes'] = (int) $_POST['event']['start']['time']['m'];
1118  $start = new ilDateTime($start_dt,IL_CAL_FKT_GETDATE,$this->timezone);
1119  $this->app->setStart($start);
1120 
1121  $end_dt['year'] = (int) $_POST['event']['end']['date']['y'];
1122  $end_dt['mon'] = (int) $_POST['event']['end']['date']['m'];
1123  $end_dt['mday'] = (int) $_POST['event']['end']['date']['d'];
1124  $end_dt['hours'] = (int) $_POST['event']['end']['time']['h'];
1125  $end_dt['minutes'] = (int) $_POST['event']['end']['time']['m'];
1126  $end = new ilDateTime($end_dt,IL_CAL_FKT_GETDATE,$this->timezone);
1127  $this->app->setEnd($end);
1128  }
1129  $this->loadNotificationRecipients();
1130  $this->loadRecurrenceSettings($a_as_milestone = false);
1131  }
1132 
1133  protected function loadNotificationRecipients()
1134  {
1135  $this->notification->setRecipients(array());
1136 
1137  foreach((array) $_POST['notu'] as $rcp)
1138  {
1139  $rcp = trim(ilUtil::stripSlashes($rcp));
1141 
1142  if(strlen($rcp) == 0)
1143  {
1144  continue;
1145  }
1146 
1147  if($usr_id)
1148  {
1149  $this->notification->addRecipient(
1151  $usr_id
1152  );
1153  }
1154  else
1155  {
1156  $this->notification->addRecipient(
1158  0,
1159  $rcp
1160  );
1161  }
1162  }
1163  }
1164 
1171  protected function loadRecurrenceSettings($a_as_milestone = false)
1172  {
1173  $this->rec->reset();
1174 
1175  switch($_POST['frequence'])
1176  {
1177  case IL_CAL_FREQ_DAILY:
1178  $this->rec->setFrequenceType($_POST['frequence']);
1179  $this->rec->setInterval((int) $_POST['count_DAILY']);
1180  break;
1181 
1182  case IL_CAL_FREQ_WEEKLY:
1183  $this->rec->setFrequenceType($_POST['frequence']);
1184  $this->rec->setInterval((int) $_POST['count_WEEKLY']);
1185  if(is_array($_POST['byday_WEEKLY']))
1186  {
1187  $this->rec->setBYDAY(ilUtil::stripSlashes(implode(',',$_POST['byday_WEEKLY'])));
1188  }
1189  break;
1190 
1191  case IL_CAL_FREQ_MONTHLY:
1192  $this->rec->setFrequenceType($_POST['frequence']);
1193  $this->rec->setInterval((int) $_POST['count_MONTHLY']);
1194  switch((int) $_POST['subtype_MONTHLY'])
1195  {
1196  case 0:
1197  // nothing to do;
1198  break;
1199 
1200  case 1:
1201  switch((int) $_POST['monthly_byday_day'])
1202  {
1203  case 8:
1204  // Weekday
1205  $this->rec->setBYSETPOS((int) $_POST['monthly_byday_num']);
1206  $this->rec->setBYDAY('MO,TU,WE,TH,FR');
1207  break;
1208 
1209  case 9:
1210  // Day of month
1211  $this->rec->setBYMONTHDAY((int) $_POST['monthly_byday_num']);
1212  break;
1213 
1214  default:
1215  $this->rec->setBYDAY((int) $_POST['monthly_byday_num'].$_POST['monthly_byday_day']);
1216  break;
1217  }
1218  break;
1219 
1220  case 2:
1221  $this->rec->setBYMONTHDAY((int) $_POST['monthly_bymonthday']);
1222  break;
1223  }
1224  break;
1225 
1226  case IL_CAL_FREQ_YEARLY:
1227  $this->rec->setFrequenceType($_POST['frequence']);
1228  $this->rec->setInterval((int) $_POST['count_YEARLY']);
1229  switch((int) $_POST['subtype_YEARLY'])
1230  {
1231  case 0:
1232  // nothing to do;
1233  break;
1234 
1235  case 1:
1236  $this->rec->setBYMONTH((int) $_POST['yearly_bymonth_byday']);
1237  $this->rec->setBYDAY((int) $_POST['yearly_byday_num'].$_POST['yearly_byday']);
1238  break;
1239 
1240  case 2:
1241  $this->rec->setBYMONTH((int) $_POST['yearly_bymonth_by_monthday']);
1242  $this->rec->setBYMONTHDAY((int) $_POST['yearly_bymonthday']);
1243  break;
1244  }
1245  break;
1246  }
1247 
1248  // UNTIL
1249  switch((int) $_POST['until_type'])
1250  {
1251  case 1:
1252  $this->rec->setFrequenceUntilDate(null);
1253  // nothing to do
1254  break;
1255 
1256  case 2:
1257  $this->rec->setFrequenceUntilDate(null);
1258  $this->rec->setFrequenceUntilCount((int) $_POST['count']);
1259  break;
1260 
1261  case 3:
1262  $end_dt['year'] = (int) $_POST['until_end']['date']['y'];
1263  $end_dt['mon'] = (int) $_POST['until_end']['date']['m'];
1264  $end_dt['mday'] = (int) $_POST['until_end']['date']['d'];
1265 
1266  $this->rec->setFrequenceUntilCount(0);
1267  $this->rec->setFrequenceUntilDate(new ilDate($end_dt,IL_CAL_FKT_GETDATE,$this->timezone));
1268  break;
1269  }
1270 
1271  }
1272 
1280  protected function saveRecurrenceSettings()
1281  {
1282  switch($_POST['frequence'])
1283  {
1284  case 'NONE':
1285  // No recurrence => delete if there is an recurrence rule
1286  if($this->rec->getRecurrenceId())
1287  {
1288  $this->rec->delete();
1289  }
1290  break;
1291 
1292  default:
1293  if($this->rec->getRecurrenceId())
1294  {
1295  $this->rec->update();
1296  }
1297  else
1298  {
1299  $this->rec->save();
1300  }
1301  break;
1302  }
1303  }
1304 
1311  protected function createDefaultCalendar()
1312  {
1313  global $ilUser,$lng;
1314 
1315  $cat = new ilCalendarCategory();
1316  $cat->setColor(ilCalendarCategory::DEFAULT_COLOR);
1317  $cat->setType(ilCalendarCategory::TYPE_USR);
1318  $cat->setTitle($this->lng->txt('cal_default_calendar'));
1319  $cat->setObjId($ilUser->getId());
1320  return $cat->add();
1321  }
1322 
1327  protected function confirmRegister()
1328  {
1329  global $tpl;
1330 
1331  $entry = new ilCalendarEntry((int) $_GET['app_id']);
1333  new ilDateTime($_GET['dstart'],IL_CAL_UNIX),
1334  new ilDateTime($_GET['dend'],IL_CAL_UNIX)
1335  );
1336 
1337 
1338  include_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
1339  $conf = new ilConfirmationGUI;
1340 
1341  $this->ctrl->setParameter($this,'dstart',(int) $_REQUEST['dstart']);
1342  $this->ctrl->setParameter($this,'dend',(int) $_REQUEST['dend']);
1343 
1344  $conf->setFormAction($this->ctrl->getFormAction($this));
1345  $conf->setHeaderText($this->lng->txt('cal_confirm_reg_info'));
1346  $conf->setConfirm($this->lng->txt('cal_reg_register'), 'register');
1347  $conf->setCancel($this->lng->txt('cancel'), 'cancel');
1348  $conf->addItem('app_id', $entry->getEntryId(), $entry->getTitle().' ('.$start.')');
1349 
1350  $tpl->setContent($conf->getHTML());
1351  }
1352 
1357  protected function register()
1358  {
1359  global $ilUser;
1360 
1361  include_once './Services/Calendar/classes/class.ilCalendarRegistration.php';
1362  $reg = new ilCalendarRegistration((int) $_POST['app_id']);
1363  $reg->register(
1364  $ilUser->getId(),
1365  new ilDateTime((int) $_REQUEST['dstart'],IL_CAL_UNIX),
1366  new ilDateTime((int) $_REQUEST['dend'],IL_CAL_UNIX)
1367  );
1368 
1369  ilUtil::sendSuccess($this->lng->txt('cal_reg_registered'),true);
1370  $this->ctrl->returnToParent($this);
1371  }
1372 
1376  public function confirmUnregister()
1377  {
1378  global $tpl;
1379 
1380 
1381  $entry = new ilCalendarEntry((int) $_GET['app_id']);
1383  $dstart = new ilDateTime($_GET['dstart'],IL_CAL_UNIX),
1384  $dend = new ilDateTime($_GET['dend'],IL_CAL_UNIX)
1385  );
1386 
1387 
1388  include_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
1389  $conf = new ilConfirmationGUI;
1390 
1391  $this->ctrl->setParameter($this,'dstart',(int) $_REQUEST['dstart']);
1392  $this->ctrl->setParameter($this,'dend',(int) $_REQUEST['dend']);
1393 
1394  $conf->setFormAction($this->ctrl->getFormAction($this));
1395  $conf->setHeaderText($this->lng->txt('cal_confirm_unreg_info'));
1396  $conf->setConfirm($this->lng->txt('cal_reg_unregister'), 'unregister');
1397  $conf->setCancel($this->lng->txt('cancel'), 'cancel');
1398  $conf->addItem('app_id', $entry->getEntryId(), $entry->getTitle().' ('.$start.')');
1399 
1400  $tpl->setContent($conf->getHTML());
1401  }
1402 
1407  protected function unregister()
1408  {
1409  global $ilUser;
1410 
1411  include_once './Services/Calendar/classes/class.ilCalendarRegistration.php';
1412  $reg = new ilCalendarRegistration((int) $_POST['app_id']);
1413  $reg->unregister(
1414  $ilUser->getId(),
1415  new ilDateTime((int) $_REQUEST['dstart'],IL_CAL_UNIX),
1416  new ilDateTime((int) $_REQUEST['dend'],IL_CAL_UNIX)
1417  );
1418 
1419  ilUtil::sendSuccess($this->lng->txt('cal_reg_unregistered'),true);
1420  $this->ctrl->returnToParent($this);
1421  }
1422 
1426  public function book()
1427  {
1428  global $ilUser, $tpl;
1429 
1430  $entry = (int)$_GET['app_id'];
1431  $user = (int)$_GET['bkid'];
1432 
1433  $this->ctrl->saveParameter($this,'app_id');
1434 
1435  include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
1436  include_once 'Services/Booking/classes/class.ilBookingEntry.php';
1437  $entry = new ilCalendarEntry($entry);
1438 
1439  $form = $this->initFormConfirmBooking();
1440  $form->getItemByPostVar('date')->setValue(ilDatePresentation::formatPeriod($entry->getStart(), $entry->getEnd()));
1441  $form->getItemByPostVar('title')->setValue($entry->getTitle()." (".ilObjUser::_lookupFullname($user).')');
1442 
1443  $tpl->setContent($form->getHTML());
1444  return true;
1445  }
1446 
1451  protected function initFormConfirmBooking()
1452  {
1453  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
1454  $form = new ilPropertyFormGUI();
1455  $form->setFormAction($this->ctrl->getFormAction($this));
1456  $form->addCommandButton('bookconfirmed',$this->lng->txt('cal_confirm_booking'));
1457  $form->addCommandButton('cancel',$this->lng->txt('cancel'));
1458 
1459  $date = new ilNonEditableValueGUI($this->lng->txt('appointment'),'date');
1460  $form->addItem($date);
1461 
1462  $title = new ilNonEditableValueGUI($this->lng->txt('title'),'title');
1463  $form->addItem($title);
1464 
1465  $message = new ilTextAreaInputGUI($this->lng->txt('cal_ch_booking_message_tbl'), 'comment');
1466  $message->setRows(5);
1467  $form->addItem($message);
1468 
1469  return $form;
1470  }
1471 
1475  public function bookconfirmed()
1476  {
1477  global $ilUser;
1478 
1479  $entry = (int) $_REQUEST['app_id'];
1480  $user = (int) $_REQUEST['bkid'];
1481 
1482  $form = $this->initFormConfirmBooking();
1483  if($form->checkInput())
1484  {
1485  // check if appointment is bookable
1486  include_once './Services/Calendar/classes/class.ilCalendarEntry.php';
1487  $cal_entry = new ilCalendarEntry($entry);
1488 
1489  include_once './Services/Booking/classes/class.ilBookingEntry.php';
1490  $booking = new ilBookingEntry($cal_entry->getContextId());
1491 
1492  if(!$booking->isAppointmentBookableForUser($entry, $GLOBALS['ilUser']->getId()))
1493  {
1494  ilUtil::sendFailure($this->lng->txt('cal_booking_failed_info'), true);
1495  $this->ctrl->returnToParent($this);
1496  }
1497 
1498  include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourUtils.php';
1499  ilConsultationHourUtils::bookAppointment($ilUser->getId(), $entry);
1500 
1501  include_once './Services/Booking/classes/class.ilBookingEntry.php';
1502  ilBookingEntry::writeBookingMessage($entry, $ilUser->getId(), $form->getInput('comment'));
1503  }
1504  ilUtil::sendSuccess($this->lng->txt('cal_booking_confirmed'),true);
1505  $this->ctrl->returnToParent($this);
1506  }
1507 
1512  public function cancelBooking()
1513  {
1514  global $ilUser, $tpl;
1515 
1516  $entry = (int)$_GET['app_id'];
1517 
1518  include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
1519  $entry = new ilCalendarEntry($entry);
1520 
1521  $category = $this->calendarEntryToCategory($entry);
1522  if($category->getType() == ilCalendarCategory::TYPE_CH)
1523  {
1524  include_once 'Services/Booking/classes/class.ilBookingEntry.php';
1525  $booking = new ilBookingEntry($entry->getContextId());
1526  if(!$booking->hasBooked($entry->getEntryId()))
1527  {
1528  $this->ctrl->returnToParent($this);
1529  return false;
1530  }
1531 
1532  $entry_title = ' '.$entry->getTitle()." (".ilObjUser::_lookupFullname($booking->getObjId()).')';
1533  }
1534  else if($category->getType() == ilCalendarCategory::TYPE_BOOK)
1535  {
1536  $entry_title = ' '.$entry->getTitle();
1537  }
1538  else
1539  {
1540  $this->ctrl->returnToParent($this);
1541  return false;
1542  }
1543 
1544  $title = ilDatePresentation::formatPeriod($entry->getStart(), $entry->getEnd());
1545 
1546  include_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
1547  $conf = new ilConfirmationGUI;
1548  $conf->setFormAction($this->ctrl->getFormAction($this));
1549  $conf->setHeaderText($this->lng->txt('cal_cancel_booking_info'));
1550  $conf->setConfirm($this->lng->txt('cal_cancel_booking'), 'cancelconfirmed');
1551  $conf->setCancel($this->lng->txt('cancel'), 'cancel');
1552  $conf->addItem('app_id', $entry->getEntryId(), $title.' - '.$entry_title);
1553 
1554  $tpl->setContent($conf->getHTML());
1555  }
1556 
1561  public function cancelConfirmed()
1562  {
1563  global $ilUser;
1564 
1565  $entry = (int)$_POST['app_id'];
1566  $user = (int)$_GET['bkid'];
1567 
1568  include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
1569  $entry = new ilCalendarEntry($entry);
1570 
1571  $category = $this->calendarEntryToCategory($entry);
1572  if($category->getType() == ilCalendarCategory::TYPE_CH)
1573  {
1574  // find cloned calendar entry in user calendar
1575  include_once 'Services/Calendar/classes/ConsultationHours/class.ilConsultationHourAppointments.php';
1576  $GLOBALS['ilLog']->dump($entry->getStart());
1578  $ilUser->getId(),
1579  $entry->getContextId(),
1580  $entry->getStart(),
1582  false);
1583  $GLOBALS['ilLog']->dump($apps);
1584 
1585  // Fix for wrong, old entries
1586  foreach((array) $apps as $own_app)
1587  {
1588  $ref_entry = new ilCalendarEntry($own_app);
1589  $ref_entry->delete();
1590  }
1591 
1592  include_once 'Services/Booking/classes/class.ilBookingEntry.php';
1593  $booking = new ilBookingEntry($entry->getContextId());
1594  $booking->cancelBooking($entry->getEntryId());
1595 
1596  // do NOT delete original entry
1597  }
1598  else if($category->getType() == ilCalendarCategory::TYPE_BOOK)
1599  {
1600  include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
1601  $booking = new ilBookingReservation($entry->getContextId());
1603  $booking->update();
1604 
1605  $entry->delete();
1606  }
1607 
1608  ilUtil::sendSuccess($this->lng->txt('cal_cancel_booking_confirmed'),true);
1609  $this->ctrl->returnToParent($this);
1610  }
1611 
1617  protected function calendarEntryToCategory(ilCalendarEntry $entry)
1618  {
1619  include_once 'Services/Calendar/classes/class.ilCalendarCategoryAssignments.php';
1620  include_once 'Services/Calendar/classes/class.ilCalendarCategory.php';
1621  $assignment = new ilCalendarCategoryAssignments($entry->getEntryId());
1622  $assignment = $assignment->getFirstAssignment();
1623  return new ilCalendarCategory($assignment);
1624  }
1625 
1630  protected function doUserAutoComplete()
1631  {
1632  if(!isset($_GET['autoCompleteField']))
1633  {
1634  $a_fields = array('login','firstname','lastname','email');
1635  }
1636  else
1637  {
1638  $a_fields = array((string) $_GET['autoCompleteField']);
1639  }
1640 
1641  $GLOBALS['ilLog']->write(print_r($a_fields,true));
1642  include_once './Services/User/classes/class.ilUserAutoComplete.php';
1643  $auto = new ilUserAutoComplete();
1644  $auto->setSearchFields($a_fields);
1645  $auto->enableFieldSearchableCheck(true);
1646  echo $auto->getList($_REQUEST['query']);
1647  exit();
1648  }
1649 
1650 }
1651 ?>