ILIAS  Release_4_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 $default_fulltime = true;
40 
41  protected $app = null;
42  protected $rec = null;
43  protected $timezone = null;
44 
45  protected $tpl;
46  protected $lng;
47  protected $ctrl;
48 
56  public function __construct(ilDate $seed,$a_appointment_id = 0)
57  {
58  global $ilCtrl,$lng;
59 
60  $this->lng = $lng;
61  $lng->loadLanguageModule('dateplaner');
62  $this->ctrl = $ilCtrl;
63 
64  $this->initTimeZone();
65  $this->initSeed($seed);
66  $this->initAppointment($a_appointment_id);
67  }
68 
76  public function executeCommand()
77  {
78  global $ilUser, $ilSetting,$tpl;
79 
80  $next_class = $this->ctrl->getNextClass($this);
81  switch($next_class)
82  {
83 
84  default:
85  $cmd = $this->ctrl->getCmd("add");
86  $this->$cmd();
87  break;
88  }
89  return true;
90  }
91 
99  protected function cancel()
100  {
101  $this->ctrl->returnToParent($this);
102  }
103 
111  protected function initForm($a_mode, $a_as_milestone = false)
112  {
113  global $ilUser,$tpl;
114 
115  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
116  include_once('./Services/Calendar/classes/class.ilCalendarRecurrenceGUI.php');
117  include_once('./Services/Calendar/classes/class.ilCalendarCategories.php');
118  include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
119  include_once('./Services/Calendar/classes/class.ilCalendarCategory.php');
120 
121  $this->form = new ilPropertyFormGUI();
122 
123  include_once('./Services/YUI/classes/class.ilYuiUtil.php');
125  $resp_info = false;
126  switch($a_mode)
127  {
128  case 'create':
129  $this->ctrl->saveParameter($this,array('seed'));
130  $this->form->setFormAction($this->ctrl->getFormAction($this));
131  if ($a_as_milestone)
132  {
133  $this->form->setTitle($this->lng->txt('cal_new_ms'));
134  $this->form->addCommandButton('saveMilestone',$this->lng->txt('cal_add_milestone'));
135  $this->form->addCommandButton('cancel',$this->lng->txt('cancel'));
136  }
137  else
138  {
139  $this->form->setTitle($this->lng->txt('cal_new_app'));
140  $this->form->addCommandButton('save',$this->lng->txt('cal_add_appointment'));
141  $this->form->addCommandButton('cancel',$this->lng->txt('cancel'));
142  }
143  break;
144 
145  case 'edit':
146  if ($a_as_milestone)
147  {
148  $this->form->setTitle($this->lng->txt('cal_edit_milestone'));
149  }
150  else
151  {
152  $this->form->setTitle($this->lng->txt('cal_edit_appointment'));
153  }
154  $this->ctrl->saveParameter($this,array('seed','app_id'));
155  $this->form->setFormAction($this->ctrl->getFormAction($this));
156 
157  $ass = new ilCalendarCategoryAssignments($this->app->getEntryId());
158  $cat = $ass->getFirstAssignment();
159  include_once('./Services/Calendar/classes/class.ilCalendarCategory.php');
160  $cat_info = ilCalendarCategories::_getInstance()->getCategoryInfo($cat);
161  $type = ilObject::_lookupType($cat_info['obj_id']);
162  if ($a_as_milestone && $cat_info['type'] == ilCalendarCategory::TYPE_OBJ
163  && ($type == "grp" || $type == "crs"))
164  {
165  $resp_info = true;
166  $this->form->addCommandButton('editResponsibleUsers',$this->lng->txt('cal_change_responsible_users'));
167  }
168  $this->form->addCommandButton('update',$this->lng->txt('save'));
169  $this->form->addCommandButton('askDelete',$this->lng->txt('delete'));
170  $this->form->addCommandButton('cancel',$this->lng->txt('cancel'));
171  break;
172  }
173  // title
174  $title = new ilTextInputGUI($this->lng->txt('title'),'title');
175  $title->setValue($this->app->getTitle());
176  $title->setRequired(true);
177  $title->setMaxLength(128);
178  $title->setSize(32);
179  $this->form->addItem($title);
180 
181  // calendar selection
182  $calendar = new ilSelectInputGUI($this->lng->txt('cal_category_selection'),'calendar');
183  if($_POST['category'])
184  {
185  $calendar->setValue((int) $_POST['calendar']);
186  }
187  elseif($a_mode == 'edit')
188  {
189  $ass = new ilCalendarCategoryAssignments($this->app->getEntryId());
190  $cat = $ass->getFirstAssignment();
191  $calendar->setValue($cat);
192  }
193  elseif(isset($_GET['ref_id']))
194  {
195  include_once('./Services/Calendar/classes/class.ilCalendarCategories.php');
196  $obj_cal = ilObject::_lookupObjId($_GET['ref_id']);
197  $calendar->setValue(ilCalendarCategories::_lookupCategoryIdByObjId($obj_cal));
198  }
199  $calendar->setRequired(true);
200  $cats = ilCalendarCategories::_getInstance($ilUser->getId());
201  $calendar->setOptions($cats->prepareCategoriesOfUserForSelection());
202  $this->form->addItem($calendar);
203 
204  if (!$a_as_milestone)
205  {
206  include_once './Services/Form/classes/class.ilDateDurationInputGUI.php';
207  #$tpl->addJavaScript('./Modules/Session/js/toggle_session_time.js');
208  $tpl->addJavaScript('./Services/Form/js/date_duration.js');
209  $dur = new ilDateDurationInputGUI($this->lng->txt('cal_fullday'),'event');
210  $dur->setStartText($this->lng->txt('cal_start'));
211  $dur->setEndText($this->lng->txt('cal_end'));
212  $dur->enableToggleFullTime(
213  $this->lng->txt('cal_fullday_title'),
214  $this->app->isFullday() ? true : false
215  );
216  $dur->setMinuteStepSize(5);
217  $dur->setShowDate(true);
218  $dur->setShowTime(true);
219  $dur->setStart($this->app->getStart());
220  $dur->setEnd($this->app->getEnd());
221  $this->form->addItem($dur);
222 
223  /*
224  $tpl->addJavaScript('./Services/Calendar/js/toggle_appointment_time.js');
225  $fullday = new ilCheckboxInputGUI($this->lng->txt('cal_fullday'),'fullday');
226  $fullday->setChecked($this->app->isFullday() ? true : false);
227  $fullday->setOptionTitle($this->lng->txt('cal_fullday_title'));
228  $fullday->setAdditionalAttributes('onchange="ilToggleAppointmentTime(this);"');
229  $this->form->addItem($fullday);
230 
231  $start = new ilDateTimeInputGUI($this->lng->txt('cal_start'),'start');
232  $start->setDate($this->app->getStart());
233  $start->setShowTime(true);
234  $start->setMinuteStepSize(5);
235  $this->form->addItem($start);
236  #$fullday->addSubItem($start);
237 
238  $end = new ilDateTimeInputGUI($this->lng->txt('cal_end'),'end');
239  $end->setDate($this->app->getEnd());
240  $end->setShowTime(true);
241  $end->setMinuteStepSize(5);
242  #$fullday->addSubItem($end);
243  $this->form->addItem($end);
244  */
245 
246  // recurrence
247  include_once('./Services/Calendar/classes/Form/class.ilRecurrenceInputGUI.php');
248  $rec = new ilRecurrenceInputGUI($this->lng->txt('cal_recurrences'),'frequence');
249  $rec->setRecurrence($this->rec);
250  $this->form->addItem($rec);
251 
252  // location
253  $where = new ilTextInputGUI($this->lng->txt('cal_where'),'location');
254  $where->setValue($this->app->getLocation());
255  $where->setMaxLength(128);
256  $where->setSize(32);
257  $this->form->addItem($where);
258  }
259  else
260  {
261  $deadline = new ilDateTimeInputGUI($this->lng->txt('cal_deadline'),'event[start]');
262  $deadline->setDate($this->app->getStart());
263  $deadline->setShowTime(false);
264  $deadline->setMinuteStepSize(5);
265  $this->form->addItem($deadline);
266 
267  // completion
268  $completion_vals = array();
269  for($i = 0; $i <= 100; $i+=5)
270  {
271  $completion_vals[$i] = $i." %";
272  }
273  $compl = new ilSelectInputGUI($this->lng->txt('cal_task_completion'),
274  'completion');
275  $compl->setOptions($completion_vals);
276  $compl->setValue($this->app->getCompletion());
277  $this->form->addItem($compl);
278  }
279 
280  $desc = new ilTextAreaInputGUI($this->lng->txt('description'),'description');
281  $desc->setValue($this->app->getDescription());
282  $desc->setCols(3);
283  $this->form->addItem($desc);
284 
285  if ($a_as_milestone && $a_mode == "edit" && $resp_info)
286  {
287  // users responsible
288  $users = $this->app->readResponsibleUsers();
289  $resp = new ilNonEditableValueGUI($this->lng->txt('cal_responsible'),
290  $users);
291  $delim = "";
292  foreach($users as $r)
293  {
294  $value.= $delim.$r["lastname"].", ".$r["firstname"]." [".$r["login"]."]";
295  $delim = "<br />";
296  }
297  if (count($users) > 0)
298  {
299  $resp->setValue($value);
300  }
301  else
302  {
303  $resp->setValue("-");
304  }
305 
306  $this->form->addItem($resp);
307  }
308  }
309 
310 
317  protected function add()
318  {
319  global $tpl;
320 
321  $this->initForm('create');
322  $tpl->setContent($this->form->getHTML());
323  }
324 
331  protected function addMilestone()
332  {
333  global $tpl;
334 
335  $this->initForm('create', true);
336  $tpl->setContent($this->form->getHTML());
337  }
338 
344  protected function saveMilestone()
345  {
346  $this->save(true);
347  }
348 
354  protected function save($a_as_milestone = false)
355  {
356  global $ilErr;
357 
358  $this->load($a_as_milestone);
359 
360  if($this->app->validate())
361  {
362  if(!(int) $_POST['calendar'])
363  {
364  $cat_id = $this->createDefaultCalendar();
365  }
366  else
367  {
368  $cat_id = (int) $_POST['calendar'];
369  }
370 
371  $this->app->save();
372  $this->rec->setEntryId($this->app->getEntryId());
373  $this->saveRecurrenceSettings();
374 
375  include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
376  $ass = new ilCalendarCategoryAssignments($this->app->getEntryId());
377  $ass->addAssignment($cat_id);
378 
379  include_once('./Services/Calendar/classes/class.ilCalendarCategory.php');
380  $cat_info = ilCalendarCategories::_getInstance()->getCategoryInfo($cat_id);
381  $type = ilObject::_lookupType($cat_info['obj_id']);
382 
383  if ($a_as_milestone && $cat_info['type'] == ilCalendarCategory::TYPE_OBJ
384  && ($type == "grp" || $type == "crs"))
385  {
386  ilUtil::sendSuccess($this->lng->txt('cal_created_milestone_resp_q'),true);
387  return $this->showResponsibleUsersList($cat_info['obj_id']);
388  }
389  elseif($a_as_milestone)
390  {
391  ilUtil::sendSuccess($this->lng->txt('cal_created_milestone'),true);
392  $this->ctrl->returnToParent($this);
393  }
394  else
395  {
396  ilUtil::sendSuccess($this->lng->txt('cal_created_appointment'),true);
397  $this->ctrl->returnToParent($this);
398  }
399  }
400  else
401  {
402  ilUtil::sendFailure($ilErr->getMessage());
403  }
404  if ($a_as_milestone)
405  {
406  $this->addMilestone();
407  }
408  else
409  {
410  $this->add();
411  }
412 
413  }
414 
419  {
420  include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
421  $cat_id = ilCalendarCategoryAssignments::_lookupCategory($this->app->getEntryId());
422  include_once('./Services/Calendar/classes/class.ilCalendarCategory.php');
423  $cat_info = ilCalendarCategories::_getInstance()->getCategoryInfo($cat_id);
424 
425  $this->showResponsibleUsersList($cat_info['obj_id']);
426  }
427 
432  function showResponsibleUsersList($a_grp_id)
433  {
434  global $tpl;
435 
436  include_once("./Services/Calendar/classes/class.ilMilestoneResponsiblesTableGUI.php");
437  $table_gui = new ilMilestoneResponsiblesTableGUI($this, "", $a_grp_id,
438  $this->app->getEntryId());
439  $tpl->setContent($table_gui->getHTML());
440  }
441 
446  {
447  global $ilCtrl;
448 
449  $this->app->writeResponsibleUsers($_POST["user_id"]);
450  $ilCtrl->returnToParent($this);
451  }
452 
460  protected function edit()
461  {
462  global $tpl,$ilUser,$ilErr;
463 
464  include_once('./Services/Calendar/classes/class.ilCalendarCategory.php');
465  include_once('./Services/Calendar/classes/class.ilCalendarCategories.php');
466  include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
467 
468  $cat_id = ilCalendarCategoryAssignments::_lookupCategory($this->app->getEntryId());
469  $cats = ilCalendarCategories::_getInstance($ilUser->getId());
470 
471  if(!$cats->isVisible($cat_id))
472  {
473  $ilErr->raiseError($this->lng->txt('permission_denied'),$ilErr->WARNING);
474  return false;
475  }
476  if(!$cats->isEditable($cat_id) or $this->app->isAutoGenerated())
477  {
478  $this->showInfoScreen();
479  return true;
480  }
481 
482  $this->initForm('edit', $this->app->isMilestone());
483  $tpl->setContent($this->form->getHTML());
484  }
485 
492  protected function showInfoScreen()
493  {
494  global $tpl,$ilUser;
495 
496  include_once("./Services/InfoScreen/classes/class.ilInfoScreenGUI.php");
497  $info = new ilInfoScreenGUI($this);
498  $info->setFormAction($this->ctrl->getFormAction($this));
499 
500  if ($this->app->isMilestone())
501  {
502  $info->addSection($this->lng->txt('cal_ms_details'));
503  }
504  else
505  {
506  $info->addSection($this->lng->txt('cal_details'));
507  }
508 
509  // Appointment
510  $info->addProperty($this->lng->txt('appointment'),
512  $this->app->getStart(),
513  $this->app->getEnd()));
514  $info->addProperty($this->lng->txt('title'),$this->app->getPresentationTitle());
515 
516  // Description
517  if(strlen($desc = $this->app->getDescription()))
518  {
519  $info->addProperty($this->lng->txt('description'),$desc);
520  }
521 
522  // Location
523  if(strlen($loc = $this->app->getLocation()))
524  {
525  $info->addProperty($this->lng->txt('cal_where'),$loc);
526  }
527 
528  // completion
529  if ($this->app->isMilestone() && $this->app->getCompletion() > 0)
530  {
531  $info->addProperty($this->lng->txt('cal_task_completion'),
532  $this->app->getCompletion()." %");
533  }
534 
535  include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
536  $cat_id = ilCalendarCategoryAssignments::_lookupCategory($this->app->getEntryId());
537  $cat_info = ilCalendarCategories::_getInstance()->getCategoryInfo($cat_id);
538  $type = ilObject::_lookupType($cat_info['obj_id']);
539  if ($this->app->isMilestone() && $cat_info['type'] == ilCalendarCategory::TYPE_OBJ
540  && ($type == "grp" || $type == "crs"))
541  {
542  // users responsible
543  $users = $this->app->readResponsibleUsers();
544  $delim = "";
545  foreach($users as $r)
546  {
547  $value.= $delim.$r["lastname"].", ".$r["firstname"]." [".$r["login"]."]";
548  $delim = "<br />";
549  }
550  if (count($users) > 0)
551  {
552  $info->addProperty($this->lng->txt('cal_responsible'),
553  $value);
554  }
555  }
556 
557  $category = new ilCalendarCategory($cat_id);
558 
559  if($category->getType() == ilCalendarCategory::TYPE_OBJ)
560  {
561  $info->addSection($this->lng->txt('additional_info'));
562 
563  $cat_info = ilCalendarCategories::_getInstance()->getCategoryInfo($cat_id);
564  $refs = ilObject::_getAllReferences($cat_info['obj_id']);
565 
566  include_once('classes/class.ilLink.php');
567  $href = ilLink::_getStaticLink(current($refs),ilObject::_lookupType($cat_info['obj_id']),true);
568  $info->addProperty($this->lng->txt('perma_link'),'<a class="small" href="'.$href.'" target="_top">'.$href.'</a>');
569  }
570 
571  $tpl->setContent($info->getHTML());
572  }
573 
580  protected function update()
581  {
582  global $ilErr;
583 
584  $this->load($this->app->isMilestone());
585 
586  if($this->app->validate())
587  {
588  if(!(int) $_POST['calendar'])
589  {
590  $cat_id = $this->createDefaultCalendar();
591  }
592  else
593  {
594  $cat_id = (int) $_POST['calendar'];
595  }
596 
597  $this->app->update();
598  $this->saveRecurrenceSettings();
599 
600  include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
601  $ass = new ilCalendarCategoryAssignments($this->app->getEntryId());
602  $ass->deleteAssignments();
603  $ass->addAssignment($cat_id);
604 
605  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
606  $this->ctrl->returnToParent($this);
607  }
608  else
609  {
610  ilUtil::sendFailure($ilErr->getMessage());
611  }
612 
613  $this->edit();
614 
615  }
616 
623  protected function askDelete()
624  {
625  global $tpl;
626 
627  include_once('./Services/Utilities/classes/class.ilConfirmationGUI.php');
628 
629  $this->ctrl->saveParameter($this,array('seed','app_id'));
630 
631  $confirm = new ilConfirmationGUI();
632  $confirm->setFormAction($this->ctrl->getFormAction($this));
633  $confirm->setHeaderText($this->lng->txt('cal_delete_app_sure'));
634  $confirm->setCancel($this->lng->txt('cancel'),'edit');
635  $confirm->setConfirm($this->lng->txt('delete'),'delete');
636  $confirm->addItem('appointments[]',$this->app->getEntryId(),$this->app->getTitle());
637  $tpl->setContent($confirm->getHTML());
638 
639  }
640 
648  protected function delete()
649  {
650  foreach($_POST['appointments'] as $app_id)
651  {
652  $app = new ilCalendarEntry($app_id);
653  $app->delete();
654 
655  include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
657  }
658  ilUtil::sendSuccess($this->lng->txt('cal_deleted_app'),true);
659  $this->ctrl->returnToParent($this);
660  }
661 
669  protected function initTimeZone()
670  {
671  global $ilUser;
672 
673  $this->timezone = $ilUser->getTimeZone();
674  }
675 
683  protected function initSeed(ilDate $seed)
684  {
685  if(!isset($_GET['hour']))
686  {
687  $this->seed = clone $seed;
688  $this->default_fulltime = true;
689  }
690  else
691  {
692  if((int) $_GET['hour'] < 10)
693  {
694  $time = '0'.(int) $_GET['hour'].':00:00';
695  }
696  else
697  {
698  $time = (int) $_GET['hour'].':00:00';
699  }
700  $this->seed = new ilDateTime($seed->get(IL_CAL_DATE).' '.$time,IL_CAL_DATETIME,$this->timezone);
701  $this->default_fulltime = false;
702  }
703 
704  }
705 
713  protected function initAppointment($a_app_id = 0)
714  {
715  include_once('./Services/Calendar/classes/class.ilCalendarEntry.php');
716  include_once('./Services/Calendar/classes/class.ilCalendarRecurrences.php');
717  $this->app = new ilCalendarEntry($a_app_id);
718 
719  if(!$a_app_id)
720  {
721  $start = clone $this->seed;
722  $this->app->setStart($start);
723 
724  $seed_end = clone $this->seed;
725  if($this->default_fulltime)
726  {
727  #$seed_end->increment(IL_CAL_DAY,1);
728  }
729  else
730  {
731  $seed_end->increment(IL_CAL_HOUR,1);
732  }
733  $this->app->setEnd($seed_end);
734  $this->app->setFullday($this->default_fulltime);
735 
736  $this->rec = new ilCalendarRecurrence();
737  }
738  else
739  {
740  $this->rec = ilCalendarRecurrences::_getFirstRecurrence($this->app->getEntryId());
741  }
742 
743  }
744 
752  protected function load($a_as_milestone = false)
753  {
754  if ($a_as_milestone)
755  {
756  $this->app->setMilestone(true);
757  $this->app->setCompletion(ilUtil::stripSlashes($_POST['completion']));
758  }
759 
760  $this->app->setTitle(ilUtil::stripSlashes($_POST['title']));
761  $this->app->setLocation(ilUtil::stripSlashes($_POST['location']));
762  $this->app->setDescription(ilUtil::stripSlashes($_POST['description']));
763  $this->app->setTitle(ilUtil::stripSlashes($_POST['title']));
764  if ($a_as_milestone) // milestones are always fullday events
765  {
766  $this->app->setFullday(true);
767  }
768  else
769  {
770  $this->app->setFullday(isset($_POST['event']['fulltime']) ? true : false);
771  }
772 
773  if($this->app->isFullday())
774  {
775  $start = new ilDate($_POST['event']['start']['date']['y'].'-'.$_POST['event']['start']['date']['m'].'-'.$_POST['event']['start']['date']['d'],
776  IL_CAL_DATE);
777  $this->app->setStart($start);
778 
779  $end = new ilDate($_POST['event']['end']['date']['y'].'-'.$_POST['event']['end']['date']['m'].'-'.$_POST['event']['end']['date']['d'],
780  IL_CAL_DATE);
781 
782  if ($a_as_milestone)
783  {
784  // for milestones is end date = start date
785  $this->app->setEnd($start);
786  }
787  else
788  {
789  $this->app->setEnd($end);
790  }
791  }
792  else
793  {
794  $start_dt['year'] = (int) $_POST['event']['start']['date']['y'];
795  $start_dt['mon'] = (int) $_POST['event']['start']['date']['m'];
796  $start_dt['mday'] = (int) $_POST['event']['start']['date']['d'];
797  $start_dt['hours'] = (int) $_POST['event']['start']['time']['h'];
798  $start_dt['minutes'] = (int) $_POST['event']['start']['time']['m'];
799  $start = new ilDateTime($start_dt,IL_CAL_FKT_GETDATE,$this->timezone);
800  $this->app->setStart($start);
801 
802  $end_dt['year'] = (int) $_POST['event']['end']['date']['y'];
803  $end_dt['mon'] = (int) $_POST['event']['end']['date']['m'];
804  $end_dt['mday'] = (int) $_POST['event']['end']['date']['d'];
805  $end_dt['hours'] = (int) $_POST['event']['end']['time']['h'];
806  $end_dt['minutes'] = (int) $_POST['event']['end']['time']['m'];
807  $end = new ilDateTime($end_dt,IL_CAL_FKT_GETDATE,$this->timezone);
808  $this->app->setEnd($end);
809  }
810  $this->loadRecurrenceSettings($a_as_milestone = false);
811  }
812 
819  protected function loadRecurrenceSettings($a_as_milestone = false)
820  {
821  $this->rec->reset();
822 
823  switch($_POST['frequence'])
824  {
825  case IL_CAL_FREQ_DAILY:
826  $this->rec->setFrequenceType($_POST['frequence']);
827  $this->rec->setInterval((int) $_POST['count_DAILY']);
828  break;
829 
830  case IL_CAL_FREQ_WEEKLY:
831  $this->rec->setFrequenceType($_POST['frequence']);
832  $this->rec->setInterval((int) $_POST['count_WEEKLY']);
833  if(is_array($_POST['byday_WEEKLY']))
834  {
835  $this->rec->setBYDAY(ilUtil::stripSlashes(implode(',',$_POST['byday_WEEKLY'])));
836  }
837  break;
838 
839  case IL_CAL_FREQ_MONTHLY:
840  $this->rec->setFrequenceType($_POST['frequence']);
841  $this->rec->setInterval((int) $_POST['count_MONTHLY']);
842  switch((int) $_POST['subtype_MONTHLY'])
843  {
844  case 0:
845  // nothing to do;
846  break;
847 
848  case 1:
849  switch((int) $_POST['monthly_byday_day'])
850  {
851  case 8:
852  // Weekday
853  $this->rec->setBYSETPOS((int) $_POST['monthly_byday_num']);
854  $this->rec->setBYDAY('MO,TU,WE,TH,FR');
855  break;
856 
857  case 9:
858  // Day of month
859  $this->rec->setBYMONTHDAY((int) $_POST['monthly_byday_num']);
860  break;
861 
862  default:
863  $this->rec->setBYDAY((int) $_POST['monthly_byday_num'].$_POST['monthly_byday_day']);
864  break;
865  }
866  break;
867 
868  case 2:
869  $this->rec->setBYMONTHDAY((int) $_POST['monthly_bymonthday']);
870  break;
871  }
872  break;
873 
874  case IL_CAL_FREQ_YEARLY:
875  $this->rec->setFrequenceType($_POST['frequence']);
876  $this->rec->setInterval((int) $_POST['count_YEARLY']);
877  switch((int) $_POST['subtype_YEARLY'])
878  {
879  case 0:
880  // nothing to do;
881  break;
882 
883  case 1:
884  $this->rec->setBYMONTH((int) $_POST['yearly_bymonth_byday']);
885  $this->rec->setBYDAY((int) $_POST['yearly_byday_num'].$_POST['yearly_byday']);
886  break;
887 
888  case 2:
889  $this->rec->setBYMONTH((int) $_POST['yearly_bymonth_by_monthday']);
890  $this->rec->setBYMONTHDAY((int) $_POST['yearly_bymonthday']);
891  break;
892  }
893  break;
894  }
895 
896  // UNTIL
897  switch((int) $_POST['until_type'])
898  {
899  case 1:
900  // nothing to do
901  break;
902 
903  case 2:
904  $this->rec->setFrequenceUntilCount((int) $_POST['count']);
905  break;
906  }
907 
908  }
909 
917  protected function saveRecurrenceSettings()
918  {
919  switch($_POST['frequence'])
920  {
921  case 'NONE':
922  // No recurrence => delete if there is an recurrence rule
923  if($this->rec->getRecurrenceId())
924  {
925  $this->rec->delete();
926  }
927  break;
928 
929  default:
930  if($this->rec->getRecurrenceId())
931  {
932  $this->rec->update();
933  }
934  else
935  {
936  $this->rec->save();
937  }
938  break;
939  }
940  }
941 
948  protected function createDefaultCalendar()
949  {
950  global $ilUser,$lng;
951 
952  $cat = new ilCalendarCategory();
953  $cat->setColor(ilCalendarCategory::DEFAULT_COLOR);
954  $cat->setType(ilCalendarCategory::TYPE_USR);
955  $cat->setTitle($this->lng->txt('cal_default_calendar'));
956  $cat->setObjId($ilUser->getId());
957  return $cat->add();
958  }
959 
960 }
961 ?>