ILIAS  release_4-3 Revision
 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 
109  protected function cancel()
110  {
111  $this->ctrl->returnToParent($this);
112  }
113 
121  protected function initForm($a_mode, $a_as_milestone = false)
122  {
123  global $ilUser,$tpl;
124 
125  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
126  include_once('./Services/Calendar/classes/class.ilCalendarRecurrenceGUI.php');
127  include_once('./Services/Calendar/classes/class.ilCalendarCategories.php');
128  include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
129  include_once('./Services/Calendar/classes/class.ilCalendarCategory.php');
130 
131  $this->form = new ilPropertyFormGUI();
132 
133  include_once('./Services/YUI/classes/class.ilYuiUtil.php');
135  $resp_info = false;
136  switch($a_mode)
137  {
138  case 'create':
139  $this->ctrl->saveParameter($this,array('seed','idate'));
140  $this->form->setFormAction($this->ctrl->getFormAction($this));
141  if ($a_as_milestone)
142  {
143  $this->form->setTitle($this->lng->txt('cal_new_ms'));
144  $this->form->addCommandButton('saveMilestone',$this->lng->txt('cal_add_milestone'));
145  $this->form->addCommandButton('cancel',$this->lng->txt('cancel'));
146  }
147  else
148  {
149  $this->form->setTitle($this->lng->txt('cal_new_app'));
150  $this->form->addCommandButton('save',$this->lng->txt('cal_add_appointment'));
151  $this->form->addCommandButton('cancel',$this->lng->txt('cancel'));
152  }
153  break;
154 
155  case 'edit':
156  if ($a_as_milestone)
157  {
158  $this->form->setTitle($this->lng->txt('cal_edit_milestone'));
159  }
160  else
161  {
162  $this->form->setTitle($this->lng->txt('cal_edit_appointment'));
163  }
164  $this->ctrl->saveParameter($this,array('seed','app_id','idate'));
165  $this->form->setFormAction($this->ctrl->getFormAction($this));
166 
167  $ass = new ilCalendarCategoryAssignments($this->app->getEntryId());
168  $cat = $ass->getFirstAssignment();
169  include_once('./Services/Calendar/classes/class.ilCalendarCategory.php');
170  $cat_info = ilCalendarCategories::_getInstance()->getCategoryInfo($cat);
171  $type = ilObject::_lookupType($cat_info['obj_id']);
172  if ($a_as_milestone && $cat_info['type'] == ilCalendarCategory::TYPE_OBJ
173  && ($type == "grp" || $type == "crs"))
174  {
175  $resp_info = true;
176  $this->form->addCommandButton('editResponsibleUsers',$this->lng->txt('cal_change_responsible_users'));
177  }
178  $this->form->addCommandButton('update',$this->lng->txt('save'));
179  // $this->form->addCommandButton('askDelete',$this->lng->txt('delete'));
180  $this->form->addCommandButton('cancel',$this->lng->txt('cancel'));
181  break;
182  }
183  // title
184  $title = new ilTextInputGUI($this->lng->txt('title'),'title');
185  $title->setValue($this->app->getTitle());
186  $title->setRequired(true);
187  $title->setMaxLength(128);
188  $title->setSize(32);
189  $this->form->addItem($title);
190 
191  // calendar selection
192  $calendar = new ilSelectInputGUI($this->lng->txt('cal_category_selection'),'calendar');
193  if($_POST['category'])
194  {
195  $calendar->setValue((int) $_POST['calendar']);
196  $selected_calendar = (int) $_POST['calendar'];
197  }
198  else if($_GET['category_id'])
199  {
200  $calendar->setValue((int) $_GET['category_id']);
201  $selected_calendar = (int) $_GET['category_id'];
202  }
203  elseif($a_mode == 'edit')
204  {
205  $ass = new ilCalendarCategoryAssignments($this->app->getEntryId());
206  $cat = $ass->getFirstAssignment();
207  $calendar->setValue($cat);
208  $selected_calendar = $cat;
209  }
210  elseif(isset($_GET['ref_id']))
211  {
212  include_once('./Services/Calendar/classes/class.ilCalendarCategories.php');
213  $obj_cal = ilObject::_lookupObjId($_GET['ref_id']);
214  $calendar->setValue(ilCalendarCategories::_lookupCategoryIdByObjId($obj_cal));
215  $selected_calendar = ilCalendarCategories::_lookupCategoryIdByObjId($obj_cal);
216  }
217  $calendar->setRequired(true);
218  $cats = ilCalendarCategories::_getInstance($ilUser->getId());
219  $calendar->setOptions($cats->prepareCategoriesOfUserForSelection());
220 
221  include_once './Services/Calendar/classes/class.ilCalendarSettings.php';
222  if(ilCalendarSettings::_getInstance()->isNotificationEnabled())
223  {
224  $notification_cals = $cats->getNotificationCalendars();
225  $notification_cals = count($notification_cals) ? implode(',',$notification_cals) : '';
226  $calendar->addCustomAttribute("onchange=\"ilToggleNotification(new Array(".$notification_cals."));\"");
227  }
228  $this->form->addItem($calendar);
229 
230  if (!$a_as_milestone)
231  {
232  include_once './Services/Form/classes/class.ilDateDurationInputGUI.php';
233  $tpl->addJavaScript('./Services/Form/js/date_duration.js');
234  $dur = new ilDateDurationInputGUI($this->lng->txt('cal_fullday'),'event');
235  $dur->setStartText($this->lng->txt('cal_start'));
236  $dur->setEndText($this->lng->txt('cal_end'));
237  $dur->enableToggleFullTime(
238  $this->lng->txt('cal_fullday_title'),
239  $this->app->isFullday() ? true : false
240  );
241  $dur->setMinuteStepSize(5);
242  $dur->setShowDate(true);
243  $dur->setShowTime(true);
244  $dur->setStart($this->app->getStart());
245  $dur->setEnd($this->app->getEnd());
246  $this->form->addItem($dur);
247 
248  // recurrence
249  include_once('./Services/Calendar/classes/Form/class.ilRecurrenceInputGUI.php');
250  $rec = new ilRecurrenceInputGUI($this->lng->txt('cal_recurrences'),'frequence');
251  $rec->setRecurrence($this->rec);
252  $this->form->addItem($rec);
253 
254  // location
255  $where = new ilTextInputGUI($this->lng->txt('cal_where'),'location');
256  $where->setValue($this->app->getLocation());
257  $where->setMaxLength(128);
258  $where->setSize(32);
259  $this->form->addItem($where);
260  }
261  else
262  {
263  $deadline = new ilDateTimeInputGUI($this->lng->txt('cal_deadline'),'event[start]');
264  $deadline->setDate($this->app->getStart());
265  $deadline->setShowTime(false);
266  $deadline->setMinuteStepSize(5);
267  $this->form->addItem($deadline);
268 
269  // completion
270  $completion_vals = array();
271  for($i = 0; $i <= 100; $i+=5)
272  {
273  $completion_vals[$i] = $i." %";
274  }
275  $compl = new ilSelectInputGUI($this->lng->txt('cal_task_completion'),
276  'completion');
277  $compl->setOptions($completion_vals);
278  $compl->setValue($this->app->getCompletion());
279  $this->form->addItem($compl);
280  }
281 
282  $desc = new ilTextAreaInputGUI($this->lng->txt('description'),'description');
283  $desc->setValue($this->app->getDescription());
284  $desc->setRows(5);
285  $this->form->addItem($desc);
286 
287  if ($a_as_milestone && $a_mode == "edit" && $resp_info)
288  {
289  // users responsible
290  $users = $this->app->readResponsibleUsers();
291  $resp = new ilNonEditableValueGUI($this->lng->txt('cal_responsible'),
292  $users);
293  $delim = "";
294  foreach($users as $r)
295  {
296  $value.= $delim.$r["lastname"].", ".$r["firstname"]." [".$r["login"]."]";
297  $delim = "<br />";
298  }
299  if (count($users) > 0)
300  {
301  $resp->setValue($value);
302  }
303  else
304  {
305  $resp->setValue("-");
306  }
307 
308  $this->form->addItem($resp);
309  }
310 
311 
312  if(ilCalendarSettings::_getInstance()->isUserNotificationEnabled())
313  {
314  $notu = new ilTextWizardInputGUI($this->lng->txt('cal_user_notification'), 'notu');
315  $notu->setInfo($this->lng->txt('cal_user_notification_info'));
316  $notu->setSize(20);
317  $notu->setMaxLength(64);
318 
319  $values = array();
320  foreach($this->notification->getRecipients() as $rcp)
321  {
322  switch ($rcp['type'])
323  {
325  $values[] = ilObjUser::_lookupLogin($rcp['usr_id']);
326  break;
327 
329  $values[] = $rcp['email'];
330  break;
331  }
332  }
333  if(count($values))
334  $notu->setValues($values);
335  else
336  $notu->setValues(array(''));
337  $this->form->addItem($notu);
338  }
339 
340  // Notifications
341  include_once './Services/Calendar/classes/class.ilCalendarSettings.php';
342  if(ilCalendarSettings::_getInstance()->isNotificationEnabled() and count($cats->getNotificationCalendars()))
343  {
344  $selected_cal = new ilCalendarCategory($selected_calendar);
345  $disabled = true;
346  if($selected_cal->getType() == ilCalendarCategory::TYPE_OBJ)
347  {
348  if(ilObject::_lookupType($selected_cal->getObjId()) == 'crs' or ilObject::_lookupType($selected_cal->getObjId()) == 'grp')
349  {
350  $disabled = false;
351  }
352  }
353 
354  $tpl->addJavaScript('./Services/Calendar/js/toggle_notification.js');
355  $not = new ilCheckboxInputGUI($this->lng->txt('cal_cg_notification'),'not');
356  $not->setInfo($this->lng->txt('cal_notification_info'));
357  $not->setValue(1);
358  $not->setChecked($this->app->isNotificationEnabled());
359  $not->setDisabled($disabled);
360  $this->form->addItem($not);
361  }
362  }
363 
364 
371  protected function add()
372  {
373  global $tpl;
374 
375  $this->initForm('create');
376  $tpl->setContent($this->form->getHTML());
377  }
378 
385  protected function addMilestone()
386  {
387  global $tpl;
388 
389  $this->initForm('create', true);
390  $tpl->setContent($this->form->getHTML());
391  }
392 
398  protected function saveMilestone()
399  {
400  $this->save(true);
401  }
402 
408  protected function save($a_as_milestone = false)
409  {
410  global $ilErr;
411 
412  $this->load($a_as_milestone);
413 
414  if($this->app->validate() and $this->notification->validate())
415  {
416  if(!(int) $_POST['calendar'])
417  {
418  $cat_id = $this->createDefaultCalendar();
419  }
420  else
421  {
422  $cat_id = (int) $_POST['calendar'];
423  }
424 
425  $this->app->save();
426  $this->notification->setEntryId($this->app->getEntryId());
427  $this->notification->save();
428  $this->rec->setEntryId($this->app->getEntryId());
429  $this->saveRecurrenceSettings();
430 
431  include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
432  $ass = new ilCalendarCategoryAssignments($this->app->getEntryId());
433  $ass->addAssignment($cat_id);
434 
435  // Send notifications
436  include_once './Services/Calendar/classes/class.ilCalendarSettings.php';
437  if(ilCalendarSettings::_getInstance()->isNotificationEnabled() and (bool) $_POST['not'])
438  {
439  $this->distributeNotifications($cat_id,$this->app->getEntryId(),true);
440  }
441  if(ilCalendarSettings::_getInstance()->isUserNotificationEnabled())
442  {
444  }
445 
446  include_once('./Services/Calendar/classes/class.ilCalendarCategory.php');
447  $cat_info = ilCalendarCategories::_getInstance()->getCategoryInfo($cat_id);
448  $type = ilObject::_lookupType($cat_info['obj_id']);
449 
450  if ($a_as_milestone && $cat_info['type'] == ilCalendarCategory::TYPE_OBJ
451  && ($type == "grp" || $type == "crs"))
452  {
453  ilUtil::sendSuccess($this->lng->txt('cal_created_milestone_resp_q'),true);
454  return $this->showResponsibleUsersList($cat_info['obj_id']);
455  }
456  elseif($a_as_milestone)
457  {
458  ilUtil::sendSuccess($this->lng->txt('cal_created_milestone'),true);
459  $this->ctrl->returnToParent($this);
460  }
461  else
462  {
463  ilUtil::sendSuccess($this->lng->txt('cal_created_appointment'),true);
464  $this->ctrl->returnToParent($this);
465  }
466  }
467  else
468  {
469  ilUtil::sendFailure($ilErr->getMessage());
470  }
471  if ($a_as_milestone)
472  {
473  $this->addMilestone();
474  }
475  else
476  {
477  $this->add();
478  }
479  }
480 
485  protected function distributeUserNotifications()
486  {
487  global $ilUser;
488 
489  include_once './Services/Calendar/classes/class.ilCalendarMailNotification.php';
490  $notification = new ilCalendarMailNotification();
491  $notification->setAppointmentId($this->app->getEntryId());
492 
493  foreach($this->notification->getRecipients() as $rcp)
494  {
495  switch($rcp['type'])
496  {
498  $notification->setSender(ANONYMOUS_USER_ID);
499  $notification->setRecipients(array($rcp['usr_id']));
500  $notification->setType(ilCalendarMailNotification::TYPE_USER);
501  break;
502 
504  $notification->setSender(ANONYMOUS_USER_ID);
505  $notification->setRecipients(array($rcp['email']));
506  $notification->setType(ilCalendarMailNotification::TYPE_USER_ANONYMOUS);
507  break;
508  }
509  $notification->send();
510  }
511  }
512 
513 
518  protected function distributeNotifications($a_cat_id, $app_id, $a_new_appointment = true)
519  {
520  include_once('./Services/Calendar/classes/class.ilCalendarCategory.php');
521  $cat_info = ilCalendarCategories::_getInstance()->getCategoryInfo($a_cat_id);
522 
523  include_once './Services/Calendar/classes/class.ilCalendarMailNotification.php';
524  $notification = new ilCalendarMailNotification();
525  $notification->setAppointmentId($app_id);
526 
527  switch($cat_info['type'])
528  {
530 
531  switch($cat_info['obj_type'])
532  {
533  case 'crs':
534  $ref_ids = ilObject::_getAllReferences($cat_info['obj_id']);
535  $ref_id = current($ref_ids);
536  $notification->setRefId($ref_id);
537  $notification->setType(
538  $a_new_appointment ?
541  break;
542 
543  case 'grp':
544  $ref_ids = ilObject::_getAllReferences($cat_info['obj_id']);
545  $ref_id = current($ref_ids);
546  $notification->setRefId($ref_id);
547  $notification->setType(
548  $a_new_appointment ?
551  break;
552  }
553  break;
554  }
555 
556  $notification->send();
557  }
558 
563  {
564  include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
565  $cat_id = ilCalendarCategoryAssignments::_lookupCategory($this->app->getEntryId());
566  include_once('./Services/Calendar/classes/class.ilCalendarCategory.php');
567  $cat_info = ilCalendarCategories::_getInstance()->getCategoryInfo($cat_id);
568 
569  $this->showResponsibleUsersList($cat_info['obj_id']);
570  }
571 
576  function showResponsibleUsersList($a_grp_id)
577  {
578  global $tpl;
579 
580  include_once("./Services/Calendar/classes/class.ilMilestoneResponsiblesTableGUI.php");
581  $table_gui = new ilMilestoneResponsiblesTableGUI($this, "", $a_grp_id,
582  $this->app->getEntryId());
583  $tpl->setContent($table_gui->getHTML());
584  }
585 
590  {
591  global $ilCtrl;
592 
593  $this->app->writeResponsibleUsers($_POST["user_id"]);
594  $ilCtrl->returnToParent($this);
595  }
596 
604  protected function edit()
605  {
606  global $tpl,$ilUser,$ilErr;
607 
608  include_once('./Services/Calendar/classes/class.ilCalendarCategory.php');
609  include_once('./Services/Calendar/classes/class.ilCalendarCategories.php');
610  include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
611 
612  $cat_id = ilCalendarCategoryAssignments::_lookupCategory($this->app->getEntryId());
613  $cats = ilCalendarCategories::_getInstance($ilUser->getId());
614 
615  if(!$cats->isVisible($cat_id))
616  {
617  $ilErr->raiseError($this->lng->txt('permission_denied'),$ilErr->WARNING);
618  return false;
619  }
620  if(!$cats->isEditable($cat_id) or $this->app->isAutoGenerated())
621  {
622  $this->showInfoScreen();
623  return true;
624  }
625 
626  $this->initForm('edit', $this->app->isMilestone());
627  $tpl->setContent($this->form->getHTML());
628  }
629 
636  protected function showInfoScreen()
637  {
638  global $tpl,$ilUser;
639 
640  include_once("./Services/InfoScreen/classes/class.ilInfoScreenGUI.php");
641  $info = new ilInfoScreenGUI($this);
642  $info->setFormAction($this->ctrl->getFormAction($this));
643 
644  if ($this->app->isMilestone())
645  {
646  $info->addSection($this->lng->txt('cal_ms_details'));
647  }
648  else
649  {
650  $info->addSection($this->lng->txt('cal_details'));
651  }
652 
653  // Appointment
654  $info->addProperty($this->lng->txt('appointment'),
656  $this->app->getStart(),
657  $this->app->getEnd()));
658  $info->addProperty($this->lng->txt('title'),$this->app->getPresentationTitle());
659 
660  // Description
661  if(strlen($desc = $this->app->getDescription()))
662  {
663  $info->addProperty($this->lng->txt('description'),$desc);
664  }
665 
666  // Location
667  if(strlen($loc = $this->app->getLocation()))
668  {
669  $info->addProperty($this->lng->txt('cal_where'),$loc);
670  }
671 
672  // completion
673  if ($this->app->isMilestone() && $this->app->getCompletion() > 0)
674  {
675  $info->addProperty($this->lng->txt('cal_task_completion'),
676  $this->app->getCompletion()." %");
677  }
678 
679  include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
680  $cat_id = ilCalendarCategoryAssignments::_lookupCategory($this->app->getEntryId());
681  $cat_info = ilCalendarCategories::_getInstance()->getCategoryInfo($cat_id);
682  $type = ilObject::_lookupType($cat_info['obj_id']);
683  if ($this->app->isMilestone() && $cat_info['type'] == ilCalendarCategory::TYPE_OBJ
684  && ($type == "grp" || $type == "crs"))
685  {
686  // users responsible
687  $users = $this->app->readResponsibleUsers();
688  $delim = "";
689  foreach($users as $r)
690  {
691  $value.= $delim.$r["lastname"].", ".$r["firstname"]." [".$r["login"]."]";
692  $delim = "<br />";
693  }
694  if (count($users) > 0)
695  {
696  $info->addProperty($this->lng->txt('cal_responsible'),
697  $value);
698  }
699  }
700 
701  $category = new ilCalendarCategory($cat_id);
702 
703  if($category->getType() == ilCalendarCategory::TYPE_OBJ)
704  {
705  $info->addSection($this->lng->txt('additional_info'));
706 
707  $cat_info = ilCalendarCategories::_getInstance()->getCategoryInfo($cat_id);
708  $refs = ilObject::_getAllReferences($cat_info['obj_id']);
709 
710  include_once('./Services/Link/classes/class.ilLink.php');
711  $href = ilLink::_getStaticLink(current($refs),ilObject::_lookupType($cat_info['obj_id']),true);
712  $info->addProperty($this->lng->txt('perma_link'),'<a class="small" href="'.$href.'" target="_top">'.$href.'</a>');
713  }
714 
715  $tpl->setContent($info->getHTML());
716  }
717 
724  protected function update()
725  {
726  global $ilErr;
727 
728  $this->load($this->app->isMilestone());
729 
730  if($this->app->validate() and $this->notification->validate())
731  {
732  if(!(int) $_POST['calendar'])
733  {
734  $cat_id = $this->createDefaultCalendar();
735  }
736  else
737  {
738  $cat_id = (int) $_POST['calendar'];
739  }
740 
741  $this->app->update();
742  $this->notification->save();
743  $this->saveRecurrenceSettings();
744 
745  include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
746  $ass = new ilCalendarCategoryAssignments($this->app->getEntryId());
747  $ass->deleteAssignments();
748  $ass->addAssignment($cat_id);
749 
750  // Send notifications
751  include_once './Services/Calendar/classes/class.ilCalendarSettings.php';
752  if(ilCalendarSettings::_getInstance()->isNotificationEnabled() and (bool) $_POST['not'])
753  {
754  $this->distributeNotifications($cat_id,$this->app->getEntryId(),false);
755  }
756  if(ilCalendarSettings::_getInstance()->isUserNotificationEnabled())
757  {
759  }
760 
761  ilUtil::sendSuccess($this->lng->txt('settings_saved'),true);
762  $this->ctrl->returnToParent($this);
763  }
764  else
765  {
766  ilUtil::sendFailure($ilErr->getMessage());
767  }
768 
769  $this->edit();
770 
771  }
772 
779  protected function askDelete()
780  {
781  global $tpl;
782 
783  include_once('./Services/Utilities/classes/class.ilConfirmationGUI.php');
784 
785  $this->ctrl->saveParameter($this,array('seed','app_id','dt','idate'));
786 
787  $confirm = new ilConfirmationGUI();
788  $confirm->setFormAction($this->ctrl->getFormAction($this));
789  $confirm->setHeaderText($this->lng->txt('cal_delete_app_sure'));
790  $confirm->setCancel($this->lng->txt('cancel'),'cancel');
791  $confirm->addItem('appointments[]',$this->app->getEntryId(),$this->app->getTitle());
792 
793  include_once('./Services/Calendar/classes/class.ilCalendarRecurrences.php');
794  if(sizeof(ilCalendarRecurrences::_getRecurrences($_GET['app_id']))
795  && !$this->app->isMilestone())
796  {
797  $confirm->addButton($this->lng->txt('cal_delete_single'),'deleteexclude');
798  $confirm->setConfirm($this->lng->txt('cal_delete_recurrences'),'delete');
799  }
800  else
801  {
802  $confirm->setConfirm($this->lng->txt('delete'),'delete');
803  }
804 
805  $tpl->setContent($confirm->getHTML());
806 
807  }
808 
816  protected function delete()
817  {
818  foreach($_POST['appointments'] as $app_id)
819  {
820  $app = new ilCalendarEntry($app_id);
821  $app->delete();
822 
823  include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
825 
826  include_once './Services/Calendar/classes/class.ilCalendarUserNotification.php';
828  }
829  ilUtil::sendSuccess($this->lng->txt('cal_deleted_app'),true);
830  $this->ctrl->returnToParent($this);
831  }
832 
840  protected function deleteExclude()
841  {
842  include_once('./Services/Calendar/classes/class.ilCalendarRecurrenceExclusion.php');
843  $excl = new ilCalendarRecurrenceExclusion();
844  $excl->setEntryId($_GET['app_id']);
845  $excl->setDate(new ilDate($_GET['dt'], IL_CAL_UNIX));
846  $excl->save();
847 
848  ilUtil::sendSuccess($this->lng->txt('cal_deleted_app'),true);
849  $this->ctrl->returnToParent($this);
850  }
851 
859  protected function initTimeZone()
860  {
861  global $ilUser;
862 
863  $this->timezone = $ilUser->getTimeZone();
864  }
865 
870  protected function initInitialDate(ilDate $initialDate)
871  {
872  if(!isset($_GET['hour']))
873  {
874  $this->initialDate = clone $initialDate;
875  $this->default_fulltime = true;
876  }
877  else
878  {
879  if((int) $_GET['hour'] < 10)
880  {
881  $time = '0'.(int) $_GET['hour'].':00:00';
882  }
883  else
884  {
885  $time = (int) $_GET['hour'].':00:00';
886  }
887  $this->initialDate = new ilDateTime($initialDate->get(IL_CAL_DATE).' '.$time,IL_CAL_DATETIME,$this->timezone);
888  $this->default_fulltime = false;
889  }
890  }
891 
899  protected function initSeed(ilDate $seed)
900  {
901  $this->seed = clone $seed;
902  $this->default_fulltime = true;
903  }
904 
912  protected function initAppointment($a_app_id = 0)
913  {
914  include_once('./Services/Calendar/classes/class.ilCalendarEntry.php');
915  include_once('./Services/Calendar/classes/class.ilCalendarRecurrences.php');
916  $this->app = new ilCalendarEntry($a_app_id);
917 
918  include_once './Services/Calendar/classes/class.ilCalendarUserNotification.php';
919  $this->notification = new ilCalendarUserNotification($this->app->getEntryId());
920 
921  if(!$a_app_id)
922  {
923  $start = clone $this->initialDate;
924  $this->app->setStart($start);
925 
926  $seed_end = clone $this->initialDate;
927  if($this->default_fulltime)
928  {
929  #$seed_end->increment(IL_CAL_DAY,1);
930  }
931  else
932  {
933  $seed_end->increment(IL_CAL_HOUR,1);
934  }
935  $this->app->setEnd($seed_end);
936  $this->app->setFullday($this->default_fulltime);
937 
938  $this->rec = new ilCalendarRecurrence();
939  }
940  else
941  {
942  $this->rec = ilCalendarRecurrences::_getFirstRecurrence($this->app->getEntryId());
943  }
944 
945  }
946 
954  protected function load($a_as_milestone = false)
955  {
956  if ($a_as_milestone)
957  {
958  $this->app->setMilestone(true);
959  $this->app->setCompletion(ilUtil::stripSlashes($_POST['completion']));
960  }
961 
962  $this->app->setTitle(ilUtil::stripSlashes($_POST['title']));
963  $this->app->setLocation(ilUtil::stripSlashes($_POST['location']));
964  $this->app->setDescription(ilUtil::stripSlashes($_POST['description']));
965  $this->app->setTitle(ilUtil::stripSlashes($_POST['title']));
966  $this->app->enableNotification((int) $_POST['not']);
967  if ($a_as_milestone) // milestones are always fullday events
968  {
969  $this->app->setFullday(true);
970  }
971  else
972  {
973  $this->app->setFullday(isset($_POST['event']['fulltime']) ? true : false);
974  }
975 
976  if($this->app->isFullday())
977  {
978  $start = new ilDate($_POST['event']['start']['date']['y'].'-'.$_POST['event']['start']['date']['m'].'-'.$_POST['event']['start']['date']['d'],
979  IL_CAL_DATE);
980  $this->app->setStart($start);
981 
982  $end = new ilDate($_POST['event']['end']['date']['y'].'-'.$_POST['event']['end']['date']['m'].'-'.$_POST['event']['end']['date']['d'],
983  IL_CAL_DATE);
984 
985  if ($a_as_milestone)
986  {
987  // for milestones is end date = start date
988  $this->app->setEnd($start);
989  }
990  else
991  {
992  $this->app->setEnd($end);
993  }
994  }
995  else
996  {
997  $start_dt['year'] = (int) $_POST['event']['start']['date']['y'];
998  $start_dt['mon'] = (int) $_POST['event']['start']['date']['m'];
999  $start_dt['mday'] = (int) $_POST['event']['start']['date']['d'];
1000  $start_dt['hours'] = (int) $_POST['event']['start']['time']['h'];
1001  $start_dt['minutes'] = (int) $_POST['event']['start']['time']['m'];
1002  $start = new ilDateTime($start_dt,IL_CAL_FKT_GETDATE,$this->timezone);
1003  $this->app->setStart($start);
1004 
1005  $end_dt['year'] = (int) $_POST['event']['end']['date']['y'];
1006  $end_dt['mon'] = (int) $_POST['event']['end']['date']['m'];
1007  $end_dt['mday'] = (int) $_POST['event']['end']['date']['d'];
1008  $end_dt['hours'] = (int) $_POST['event']['end']['time']['h'];
1009  $end_dt['minutes'] = (int) $_POST['event']['end']['time']['m'];
1010  $end = new ilDateTime($end_dt,IL_CAL_FKT_GETDATE,$this->timezone);
1011  $this->app->setEnd($end);
1012  }
1013  $this->loadNotificationRecipients();
1014  $this->loadRecurrenceSettings($a_as_milestone = false);
1015  }
1016 
1017  protected function loadNotificationRecipients()
1018  {
1019  $this->notification->setRecipients(array());
1020 
1021  foreach((array) $_POST['notu'] as $rcp)
1022  {
1023  $rcp = trim(ilUtil::stripSlashes($rcp));
1025 
1026  if(strlen($rcp) == 0)
1027  {
1028  continue;
1029  }
1030 
1031  if($usr_id)
1032  {
1033  $this->notification->addRecipient(
1035  $usr_id
1036  );
1037  }
1038  else
1039  {
1040  $this->notification->addRecipient(
1042  0,
1043  $rcp
1044  );
1045  }
1046  }
1047  }
1048 
1055  protected function loadRecurrenceSettings($a_as_milestone = false)
1056  {
1057  $this->rec->reset();
1058 
1059  switch($_POST['frequence'])
1060  {
1061  case IL_CAL_FREQ_DAILY:
1062  $this->rec->setFrequenceType($_POST['frequence']);
1063  $this->rec->setInterval((int) $_POST['count_DAILY']);
1064  break;
1065 
1066  case IL_CAL_FREQ_WEEKLY:
1067  $this->rec->setFrequenceType($_POST['frequence']);
1068  $this->rec->setInterval((int) $_POST['count_WEEKLY']);
1069  if(is_array($_POST['byday_WEEKLY']))
1070  {
1071  $this->rec->setBYDAY(ilUtil::stripSlashes(implode(',',$_POST['byday_WEEKLY'])));
1072  }
1073  break;
1074 
1075  case IL_CAL_FREQ_MONTHLY:
1076  $this->rec->setFrequenceType($_POST['frequence']);
1077  $this->rec->setInterval((int) $_POST['count_MONTHLY']);
1078  switch((int) $_POST['subtype_MONTHLY'])
1079  {
1080  case 0:
1081  // nothing to do;
1082  break;
1083 
1084  case 1:
1085  switch((int) $_POST['monthly_byday_day'])
1086  {
1087  case 8:
1088  // Weekday
1089  $this->rec->setBYSETPOS((int) $_POST['monthly_byday_num']);
1090  $this->rec->setBYDAY('MO,TU,WE,TH,FR');
1091  break;
1092 
1093  case 9:
1094  // Day of month
1095  $this->rec->setBYMONTHDAY((int) $_POST['monthly_byday_num']);
1096  break;
1097 
1098  default:
1099  $this->rec->setBYDAY((int) $_POST['monthly_byday_num'].$_POST['monthly_byday_day']);
1100  break;
1101  }
1102  break;
1103 
1104  case 2:
1105  $this->rec->setBYMONTHDAY((int) $_POST['monthly_bymonthday']);
1106  break;
1107  }
1108  break;
1109 
1110  case IL_CAL_FREQ_YEARLY:
1111  $this->rec->setFrequenceType($_POST['frequence']);
1112  $this->rec->setInterval((int) $_POST['count_YEARLY']);
1113  switch((int) $_POST['subtype_YEARLY'])
1114  {
1115  case 0:
1116  // nothing to do;
1117  break;
1118 
1119  case 1:
1120  $this->rec->setBYMONTH((int) $_POST['yearly_bymonth_byday']);
1121  $this->rec->setBYDAY((int) $_POST['yearly_byday_num'].$_POST['yearly_byday']);
1122  break;
1123 
1124  case 2:
1125  $this->rec->setBYMONTH((int) $_POST['yearly_bymonth_by_monthday']);
1126  $this->rec->setBYMONTHDAY((int) $_POST['yearly_bymonthday']);
1127  break;
1128  }
1129  break;
1130  }
1131 
1132  // UNTIL
1133  switch((int) $_POST['until_type'])
1134  {
1135  case 1:
1136  $this->rec->setFrequenceUntilDate(null);
1137  // nothing to do
1138  break;
1139 
1140  case 2:
1141  $this->rec->setFrequenceUntilDate(null);
1142  $this->rec->setFrequenceUntilCount((int) $_POST['count']);
1143  break;
1144 
1145  case 3:
1146  $end_dt['year'] = (int) $_POST['until_end']['date']['y'];
1147  $end_dt['mon'] = (int) $_POST['until_end']['date']['m'];
1148  $end_dt['mday'] = (int) $_POST['until_end']['date']['d'];
1149 
1150  $this->rec->setFrequenceUntilCount(0);
1151  $this->rec->setFrequenceUntilDate(new ilDate($end_dt,IL_CAL_FKT_GETDATE,$this->timezone));
1152  break;
1153  }
1154 
1155  }
1156 
1164  protected function saveRecurrenceSettings()
1165  {
1166  switch($_POST['frequence'])
1167  {
1168  case 'NONE':
1169  // No recurrence => delete if there is an recurrence rule
1170  if($this->rec->getRecurrenceId())
1171  {
1172  $this->rec->delete();
1173  }
1174  break;
1175 
1176  default:
1177  if($this->rec->getRecurrenceId())
1178  {
1179  $this->rec->update();
1180  }
1181  else
1182  {
1183  $this->rec->save();
1184  }
1185  break;
1186  }
1187  }
1188 
1195  protected function createDefaultCalendar()
1196  {
1197  global $ilUser,$lng;
1198 
1199  $cat = new ilCalendarCategory();
1200  $cat->setColor(ilCalendarCategory::DEFAULT_COLOR);
1201  $cat->setType(ilCalendarCategory::TYPE_USR);
1202  $cat->setTitle($this->lng->txt('cal_default_calendar'));
1203  $cat->setObjId($ilUser->getId());
1204  return $cat->add();
1205  }
1206 
1211  protected function confirmRegister()
1212  {
1213  global $tpl;
1214 
1215  $entry = new ilCalendarEntry((int) $_GET['app_id']);
1217  new ilDateTime($_GET['dstart'],IL_CAL_UNIX),
1218  new ilDateTime($_GET['dend'],IL_CAL_UNIX)
1219  );
1220 
1221 
1222  include_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
1223  $conf = new ilConfirmationGUI;
1224 
1225  $this->ctrl->setParameter($this,'dstart',(int) $_REQUEST['dstart']);
1226  $this->ctrl->setParameter($this,'dend',(int) $_REQUEST['dend']);
1227 
1228  $conf->setFormAction($this->ctrl->getFormAction($this));
1229  $conf->setHeaderText($this->lng->txt('cal_confirm_reg_info'));
1230  $conf->setConfirm($this->lng->txt('cal_reg_register'), 'register');
1231  $conf->setCancel($this->lng->txt('cancel'), 'cancel');
1232  $conf->addItem('app_id', $entry->getEntryId(), $entry->getTitle().' ('.$start.')');
1233 
1234  $tpl->setContent($conf->getHTML());
1235  }
1236 
1241  protected function register()
1242  {
1243  global $ilUser;
1244 
1245  include_once './Services/Calendar/classes/class.ilCalendarRegistration.php';
1246  $reg = new ilCalendarRegistration((int) $_POST['app_id']);
1247  $reg->register(
1248  $ilUser->getId(),
1249  new ilDateTime((int) $_REQUEST['dstart'],IL_CAL_UNIX),
1250  new ilDateTime((int) $_REQUEST['dend'],IL_CAL_UNIX)
1251  );
1252 
1253  ilUtil::sendSuccess($this->lng->txt('cal_reg_registered'),true);
1254  $this->ctrl->returnToParent($this);
1255  }
1256 
1260  public function confirmUnregister()
1261  {
1262  global $tpl;
1263 
1264 
1265  $entry = new ilCalendarEntry((int) $_GET['app_id']);
1267  $dstart = new ilDateTime($_GET['dstart'],IL_CAL_UNIX),
1268  $dend = new ilDateTime($_GET['dend'],IL_CAL_UNIX)
1269  );
1270 
1271 
1272  include_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
1273  $conf = new ilConfirmationGUI;
1274 
1275  $this->ctrl->setParameter($this,'dstart',(int) $_REQUEST['dstart']);
1276  $this->ctrl->setParameter($this,'dend',(int) $_REQUEST['dend']);
1277 
1278  $conf->setFormAction($this->ctrl->getFormAction($this));
1279  $conf->setHeaderText($this->lng->txt('cal_confirm_unreg_info'));
1280  $conf->setConfirm($this->lng->txt('cal_reg_unregister'), 'unregister');
1281  $conf->setCancel($this->lng->txt('cancel'), 'cancel');
1282  $conf->addItem('app_id', $entry->getEntryId(), $entry->getTitle().' ('.$start.')');
1283 
1284  $tpl->setContent($conf->getHTML());
1285  }
1286 
1291  protected function unregister()
1292  {
1293  global $ilUser;
1294 
1295  include_once './Services/Calendar/classes/class.ilCalendarRegistration.php';
1296  $reg = new ilCalendarRegistration((int) $_POST['app_id']);
1297  $reg->unregister(
1298  $ilUser->getId(),
1299  new ilDateTime((int) $_REQUEST['dstart'],IL_CAL_UNIX),
1300  new ilDateTime((int) $_REQUEST['dend'],IL_CAL_UNIX)
1301  );
1302 
1303  ilUtil::sendSuccess($this->lng->txt('cal_reg_unregistered'),true);
1304  $this->ctrl->returnToParent($this);
1305  }
1306 
1310  public function book()
1311  {
1312  global $ilUser, $tpl;
1313 
1314  $entry = (int)$_GET['app_id'];
1315  $user = (int)$_GET['bkid'];
1316 
1317  include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
1318  include_once 'Services/Booking/classes/class.ilBookingEntry.php';
1319  $entry = new ilCalendarEntry($entry);
1320  $booking = new ilBookingEntry($entry->getContextId());
1321 
1322  $user_settings = ilCalendarUserSettings::_getInstanceByUserId($ilUser->getId());
1323  $timezone = $ilUser->getTimeZone();
1324  switch($user_settings->getTimeFormat())
1325  {
1327  $title = $entry->getStart()->get(IL_CAL_FKT_DATE,'H:i',$timezone);
1328  $title .= "-".$entry->getEnd()->get(IL_CAL_FKT_DATE,'H:i',$timezone);
1329  break;
1330 
1332  $title = $entry->getStart()->get(IL_CAL_FKT_DATE,'h:ia',$timezone);
1333  $title .= "-".$entry->getEnd()->get(IL_CAL_FKT_DATE,'h:ia',$timezone);
1334  break;
1335  }
1336 
1337  $title .= ' '.$entry->getTitle()." (".ilObjUser::_lookupFullname($user).')';
1338 
1339  include_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
1340  $conf = new ilConfirmationGUI;
1341  $conf->setFormAction($this->ctrl->getFormAction($this));
1342  $conf->setHeaderText($this->lng->txt('cal_confirm_booking_info'));
1343  $conf->setConfirm($this->lng->txt('cal_confirm_booking'), 'bookconfirmed');
1344  $conf->setCancel($this->lng->txt('cancel'), 'cancel');
1345  $conf->addItem('app_id', $entry->getEntryId(), $title);
1346 
1347  $tpl->setContent($conf->getHTML());
1348  }
1349 
1353  public function bookconfirmed()
1354  {
1355  global $ilUser;
1356 
1357  $entry = (int)$_POST['app_id'];
1358  $user = (int)$_GET['bkid'];
1359 
1360  include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
1361  include_once 'Services/Booking/classes/class.ilBookingEntry.php';
1362  $entry = new ilCalendarEntry($entry);
1363  $booking = new ilBookingEntry($entry->getContextId());
1364  $booking->book($entry->getEntryId());
1365 
1366  // create user calendar/appointment
1367  include_once './Services/Calendar/classes/class.ilCalendarCategory.php';
1368  include_once './Services/Calendar/classes/class.ilCalendarUtil.php';
1369  include_once './Services/Calendar/classes/class.ilCalendarCategoryAssignments.php';
1370  $user_entry = clone $entry;
1371  $user_entry->save();
1372  $def_cat = ilCalendarUtil::initDefaultCalendarByType(ilCalendarCategory::TYPE_CH,$ilUser->getId(),$this->lng->txt('cal_ch_personal_ch'),true);
1373  $assign = new ilCalendarCategoryAssignments($user_entry->getEntryId());
1374  $assign->addAssignment($def_cat->getCategoryID());
1375 
1376  ilUtil::sendSuccess($this->lng->txt('cal_booking_confirmed'),true);
1377  $this->ctrl->returnToParent($this);
1378  }
1379 
1384  public function cancelBooking()
1385  {
1386  global $ilUser, $tpl;
1387 
1388  $entry = (int)$_GET['app_id'];
1389 
1390  include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
1391  $entry = new ilCalendarEntry($entry);
1392 
1393  $category = $this->calendarEntryToCategory($entry);
1394  if($category->getType() == ilCalendarCategory::TYPE_CH)
1395  {
1396  include_once 'Services/Booking/classes/class.ilBookingEntry.php';
1397  $booking = new ilBookingEntry($entry->getContextId());
1398  if(!$booking->hasBooked($entry->getEntryId()))
1399  {
1400  $this->ctrl->returnToParent($this);
1401  return false;
1402  }
1403 
1404  $entry_title = ' '.$entry->getTitle()." (".ilObjUser::_lookupFullname($booking->getObjId()).')';
1405  }
1406  else if($category->getType() == ilCalendarCategory::TYPE_BOOK)
1407  {
1408  $entry_title = ' '.$entry->getTitle();
1409  }
1410  else
1411  {
1412  $this->ctrl->returnToParent($this);
1413  return false;
1414  }
1415 
1416  $user_settings = ilCalendarUserSettings::_getInstanceByUserId($ilUser->getId());
1417  $timezone = $ilUser->getTimeZone();
1418  switch($user_settings->getTimeFormat())
1419  {
1421  $title = $entry->getStart()->get(IL_CAL_FKT_DATE,'H:i',$timezone);
1422  $title .= "-".$entry->getEnd()->get(IL_CAL_FKT_DATE,'H:i',$timezone);
1423  break;
1424 
1426  $title = $entry->getStart()->get(IL_CAL_FKT_DATE,'h:ia',$timezone);
1427  $title .= "-".$entry->getEnd()->get(IL_CAL_FKT_DATE,'h:ia',$timezone);
1428  break;
1429  }
1430 
1431  include_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
1432  $conf = new ilConfirmationGUI;
1433  $conf->setFormAction($this->ctrl->getFormAction($this));
1434  $conf->setHeaderText($this->lng->txt('cal_cancel_booking_info'));
1435  $conf->setConfirm($this->lng->txt('cal_cancel_booking'), 'cancelconfirmed');
1436  $conf->setCancel($this->lng->txt('cancel'), 'cancel');
1437  $conf->addItem('app_id', $entry->getEntryId(), $title.' - '.$entry_title);
1438 
1439  $tpl->setContent($conf->getHTML());
1440  }
1441 
1446  public function cancelConfirmed()
1447  {
1448  global $ilUser;
1449 
1450  $entry = (int)$_POST['app_id'];
1451  $user = (int)$_GET['bkid'];
1452 
1453  include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
1454  $entry = new ilCalendarEntry($entry);
1455 
1456  $category = $this->calendarEntryToCategory($entry);
1457  if($category->getType() == ilCalendarCategory::TYPE_CH)
1458  {
1459  // find cloned calendar entry in user calendar
1460  include_once 'Services/Calendar/classes/ConsultationHours/class.ilConsultationHourAppointments.php';
1461  $apps = ilConsultationHourAppointments::getAppointmentIds($ilUser->getId(), $entry->getContextId(), $entry->getStart());
1462  if($apps)
1463  {
1464  $ref_entry = new ilCalendarEntry($apps[0]);
1465  $ref_entry->delete();
1466  }
1467 
1468  include_once 'Services/Booking/classes/class.ilBookingEntry.php';
1469  $booking = new ilBookingEntry($entry->getContextId());
1470  $booking->cancelBooking($entry->getEntryId());
1471 
1472  // do NOT delete original entry
1473  }
1474  else if($category->getType() == ilCalendarCategory::TYPE_BOOK)
1475  {
1476  include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
1477  $booking = new ilBookingReservation($entry->getContextId());
1479  $booking->update();
1480 
1481  $entry->delete();
1482  }
1483 
1484  ilUtil::sendSuccess($this->lng->txt('cal_cancel_booking_confirmed'),true);
1485  $this->ctrl->returnToParent($this);
1486  }
1487 
1493  protected function calendarEntryToCategory(ilCalendarEntry $entry)
1494  {
1495  include_once 'Services/Calendar/classes/class.ilCalendarCategoryAssignments.php';
1496  include_once 'Services/Calendar/classes/class.ilCalendarCategory.php';
1497  $assignment = new ilCalendarCategoryAssignments($entry->getEntryId());
1498  $assignment = $assignment->getFirstAssignment();
1499  return new ilCalendarCategory($assignment);
1500  }
1501 
1506  protected function doUserAutoComplete()
1507  {
1508  if(!isset($_GET['autoCompleteField']))
1509  {
1510  $a_fields = array('login','firstname','lastname','email');
1511  }
1512  else
1513  {
1514  $a_fields = array((string) $_GET['autoCompleteField']);
1515  }
1516 
1517  $GLOBALS['ilLog']->write(print_r($a_fields,true));
1518  include_once './Services/User/classes/class.ilUserAutoComplete.php';
1519  $auto = new ilUserAutoComplete();
1520  $auto->setSearchFields($a_fields);
1521  $auto->enableFieldSearchableCheck(true);
1522  echo $auto->getList($_REQUEST['query']);
1523  exit();
1524  }
1525 
1526 }
1527 ?>