ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjCalendarSettingsGUI.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 
34 include_once('./classes/class.ilObjectGUI.php');
35 
37 {
38 
44  public function __construct($a_data, $a_id, $a_call_by_reference = true, $a_prepare_output = true)
45  {
46  global $lng;
47 
48  $this->type = 'cals';
49  parent::ilObjectGUI($a_data, $a_id, $a_call_by_reference, $a_prepare_output);
50 
51  $this->lng = $lng;
52  $this->lng->loadLanguageModule('dateplaner');
53  $this->lng->loadLanguageModule('jscalendar');
54  }
55 
62  public function executeCommand()
63  {
64  global $ilErr,$ilAccess;
65 
66  $next_class = $this->ctrl->getNextClass($this);
67  $cmd = $this->ctrl->getCmd();
68 
69  $this->prepareOutput();
70 
71  if(!$ilAccess->checkAccess('read','',$this->object->getRefId()))
72  {
73  $ilErr->raiseError($this->lng->txt('no_permission'),$ilErr->WARNING);
74  }
75 
76  switch($next_class)
77  {
78  case 'ilpermissiongui':
79  $this->tabs_gui->setTabActive('perm_settings');
80  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
81  $perm_gui =& new ilPermissionGUI($this);
82  $ret =& $this->ctrl->forwardCommand($perm_gui);
83  break;
84 
85  default:
86  $this->tabs_gui->setTabActive('settings');
87  $this->initCalendarSettings();
88  if(!$cmd || $cmd == 'view')
89  {
90  $cmd = "settings";
91  }
92 
93  $this->$cmd();
94  break;
95  }
96  return true;
97  }
98 
99 
106  public function getAdminTabs()
107  {
108  global $rbacsystem, $ilAccess;
109 
110  if ($ilAccess->checkAccess("read",'',$this->object->getRefId()))
111  {
112  $this->tabs_gui->addTarget("settings",
113  $this->ctrl->getLinkTarget($this, "settings"),
114  array("settings", "view"));
115  }
116 
117  if ($ilAccess->checkAccess('edit_permission','',$this->object->getRefId()))
118  {
119  $this->tabs_gui->addTarget("perm_settings",
120  $this->ctrl->getLinkTargetByClass('ilpermissiongui',"perm"),
121  array(),'ilpermissiongui');
122  }
123  }
124 
128  public function settings()
129  {
130  include_once('./Services/Calendar/classes/class.ilDateTime.php');
131 
132  include_once('./Services/Calendar/classes/iCal/class.ilICalParser.php');
133 
134  include_once('./Services/Calendar/classes/class.ilCalendarRecurrenceCalculator.php');
135  include_once('./Services/Calendar/classes/class.ilCalendarRecurrence.php');
136  include_once('./Services/Calendar/classes/class.ilCalendarEntry.php');
137 
138 
139  #$parser = new ilICalParser('./extern/Feiertage.ics',ilICalParser::INPUT_FILE);
140  #$parser->setCategoryId(6);
141  #$parser->parse();
142  /*
143  $calc = new ilCalendarRecurrenceCalculator(
144  new ilCalendarEntry(273),
145  new ilCalendarRecurrence(43));
146 
147  $list = $calc->calculateDateList(
148  new ilDateTime('2008-04-01',IL_CAL_DATE),
149  new ilDateTime('2008-04-31',IL_CAL_DATE));
150  */
151  #echo "RESULT: ".$list;
152  /*
153  $zeit = microtime(true);
154 
155  for($i = 0;$i < 1;$i++)
156  {
157  $calc = new ilCalendarRecurrenceCalculator(
158  new ilCalendarEntry(1061),
159  new ilCalendarRecurrence(72));
160 
161  $list = $calc->calculateDateList(
162  new ilDateTime('2008-03-01',IL_CAL_DATE),
163  new ilDateTime('2008-03-31',IL_CAL_DATE));
164  }
165  echo "NEEDS: ".(microtime(true) - $zeit).' seconds.<br>';
166  foreach($list->get() as $event)
167  {
168  echo $event->get(IL_CAL_DATETIME,'',$this->settings->getDefaultTimeZone()).'<br />';
169  }
170  */
171  #$parser = new ilICalParser('./extern/fc.ics',ilICalParser::INPUT_FILE);
172  #$parser->setCategoryId(11);
173  #$parser = new ilICalParser('./Feiertage.ics',ilICalParser::INPUT_FILE);
174  #$parser->parse();
175  #$entry = new ilCalendarEntry(927);
176  /*
177  $timezone = "US/Alaska";
178  echo $entry->getTitle().'<br>';
179  echo $entry->getStart()->get(IL_CAL_DATE,'',$timezone).'<br>';
180  echo $entry->getStart()->get(IL_CAL_DATETIME,'',$timezone).'<br>';
181  echo $entry->getEnd()->get(IL_CAL_DATE,'',$timezone).'<br>';
182  echo $entry->getEnd()->get(IL_CAL_DATETIME,'',$timezone).'<br>';
183 
184  $entry = new ilCalendarEntry(928);
185  echo $entry->getTitle().'<br>';
186  echo $entry->getStart()->get(IL_CAL_DATE,'',$timezone).'<br>';
187  echo $entry->getStart()->get(IL_CAL_DATETIME,'',$timezone).'<br>';
188  echo $entry->getEnd()->get(IL_CAL_DATE,'',$timezone).'<br>';
189  echo $entry->getEnd()->get(IL_CAL_DATETIME,'',$timezone).'<br>';
190  */
191  $this->tabs_gui->setTabActive('settings');
192  $this->initFormSettings();
193  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.settings.html','Services/Calendar');
194  $this->tpl->setVariable('CAL_SETTINGS',$this->form->getHTML());
195  return true;
196  }
197 
203  protected function save()
204  {
205  $this->settings->setEnabled((int) $_POST['enable']);
206  $this->settings->setDefaultWeekStart((int) $_POST['default_week_start']);
207  $this->settings->setDefaultTimeZone(ilUtil::stripSlashes($_POST['default_timezone']));
208  $this->settings->setDefaultDateFormat((int) $_POST['default_date_format']);
209  $this->settings->setDefaultTimeFormat((int) $_POST['default_time_format']);
210  $this->settings->setEnableGroupMilestones((int) $_POST['enable_grp_milestones']);
211  $this->settings->setDefaultDayStart((int) $_POST['dst']);
212  $this->settings->setDefaultDayEnd((int) $_POST['den']);
213  $this->settings->enableSynchronisationCache((bool) $_POST['sync_cache']);
214  $this->settings->setSynchronisationCacheMinutes((int) $_POST['sync_cache_time']);
215  $this->settings->setCacheMinutes((int) $_POST['cache_time']);
216  $this->settings->useCache((bool) $_POST['cache']);
217  $this->settings->enableNotification((bool) $_POST['cn']);
218  $this->settings->enableConsultationHours((bool) $_POST['ch']);
219  $this->settings->enableCGRegistration((bool) $_POST['cgr']);
220 
221  if(((int) $_POST['den']) < (int) $_POST['dst'])
222  {
223  ilUtil::sendFailure($this->lng->txt('cal_dstart_dend_warn'));
224  $this->settings();
225  return false;
226  }
227 
228  $this->settings->save();
229 
230  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
231  $this->settings();
232  }
233 
239  protected function initCalendarSettings()
240  {
241  include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
243  }
244 
250  protected function initFormSettings()
251  {
252  if(is_object($this->form))
253  {
254  return true;
255  }
256  include_once('Services/Calendar/classes/class.ilCalendarUtil.php');
257  include_once('Services/Form/classes/class.ilPropertyFormGUI.php');
258 
259  $this->form = new ilPropertyFormGUI();
260  $this->form->setFormAction($this->ctrl->getFormAction($this));
261  $this->form->setTitle($this->lng->txt('cal_global_settings'));
262  $this->form->addCommandButton('save',$this->lng->txt('save'));
263  #$this->form->addCommandButton('cancel',$this->lng->txt('cancel'));
264 
265  $check = new ilCheckboxInputGUI($this->lng->txt('enable_calendar'),'enable');
266  $check->setValue(1);
267  $check->setChecked($this->settings->isEnabled() ? true : false);
268  $this->form->addItem($check);
269 
270  $server_tz = new ilNonEditableValueGUI($this->lng->txt('cal_server_tz'));
272  $this->form->addItem($server_tz);
273 
274  $select = new ilSelectInputGUI($this->lng->txt('cal_def_timezone'),'default_timezone');
276  $select->setInfo($this->lng->txt('cal_def_timezone_info'));
277  $select->setValue($this->settings->getDefaultTimeZone());
278  $this->form->addItem($select);
279 
280  $year = date("Y");
281  $select = new ilSelectInputGUI($this->lng->txt('cal_def_date_format'),'default_date_format');
282  $select->setOptions(array(
283  ilCalendarSettings::DATE_FORMAT_DMY => '31.10.'.$year,
284  ilCalendarSettings::DATE_FORMAT_YMD => $year."-10-31",
285  ilCalendarSettings::DATE_FORMAT_MDY => "10/31/".$year));
286  $select->setInfo($this->lng->txt('cal_def_date_format_info'));
287  $select->setValue($this->settings->getDefaultDateFormat());
288  $this->form->addItem($select);
289 
290  $select = new ilSelectInputGUI($this->lng->txt('cal_def_time_format'),'default_time_format');
291  $select->setOptions(array(
294  $select->setInfo($this->lng->txt('cal_def_time_format_info'));
295  $select->setValue($this->settings->getDefaultTimeFormat());
296  $this->form->addItem($select);
297 
298  $radio = new ilRadioGroupInputGUI($this->lng->txt('cal_def_week_start'),'default_week_start');
299  $radio->setValue($this->settings->getDefaultWeekStart());
300 
301  $option = new ilRadioOption($this->lng->txt('l_su'),0);
302  $radio->addOption($option);
303  $option = new ilRadioOption($this->lng->txt('l_mo'),1);
304  $radio->addOption($option);
305 
306  // Calendar cache
307  $cache = new ilRadioGroupInputGUI($this->lng->txt('cal_cache'),'cache');
308  $cache->setValue((int) $this->settings->isCacheUsed());
309  $cache->setInfo($this->lng->txt('cal_cache_info'));
310  $cache->setRequired(true);
311 
312  $sync_cache = new ilRadioOption($this->lng->txt('cal_cache_disabled'),0);
313  $cache->addOption($sync_cache);
314 
315  $sync_cache = new ilRadioOption($this->lng->txt('cal_cache_enabled'),1);
316  $cache->addOption($sync_cache);
317 
318  $cache_t = new ilNumberInputGUI('','cache_time');
319  $cache_t->setValue($this->settings->getCacheMinutes());
320  $cache_t->setMinValue(0);
321  $cache_t->setSize(3);
322  $cache_t->setMaxLength(3);
323  $cache_t->setSuffix($this->lng->txt('form_minutes'));
324  $sync_cache->addSubItem($cache_t);
325  $this->form->addItem($cache);
326 
327  // enable milestone planning in groups
328  $checkm = new ilCheckboxInputGUI($this->lng->txt('cal_enable_group_milestones'),'enable_grp_milestones');
329  $checkm->setValue(1);
330  $checkm->setChecked($this->settings->getEnableGroupMilestones() ? true : false);
331  $checkm->setInfo($this->lng->txt('cal_enable_group_milestones_desc'));
332  $this->form->addItem($checkm);
333 
334  $this->form->addItem($radio);
335 
336  // Day start
337  $day_start = new ilSelectInputGUI($this->lng->txt('cal_day_start'),'dst');
338  $day_start->setOptions(
339  ilCalendarUtil::getHourSelection($this->settings->getDefaultTimeFormat())
340  );
341  $day_start->setValue($this->settings->getDefaultDayStart());
342  $this->form->addItem($day_start);
343 
344  $day_end = new ilSelectInputGUI($this->lng->txt('cal_day_end'),'den');
345  $day_end->setOptions(
346  ilCalendarUtil::getHourSelection($this->settings->getDefaultTimeFormat())
347  );
348  $day_end->setValue($this->settings->getDefaultDayEnd());
349  $this->form->addItem($day_end);
350 
351  // Consultation hours
352  $con = new ilFormSectionHeaderGUI();
353  $con->setTitle($this->lng->txt('cal_ch_form_header'));
354  $this->form->addItem($con);
355 
356  $ch = new ilCheckboxInputGUI($this->lng->txt('cal_ch_form'),'ch');
357  $ch->setInfo($this->lng->txt('cal_ch_form_info'));
358  $ch->setValue(1);
359  $ch->setChecked($this->settings->areConsultationHoursEnabled());
360  $this->form->addItem($ch);
361 
362  // Synchronisation cache
363  $sec = new ilFormSectionHeaderGUI();
364  $sec->setTitle($this->lng->txt('cal_sync_header'));
365  $this->form->addItem($sec);
366 
367  $cache = new ilRadioGroupInputGUI($this->lng->txt('cal_sync_cache'),'sync_cache');
368  $cache->setValue((int) $this->settings->isSynchronisationCacheEnabled());
369  $cache->setInfo($this->lng->txt('cal_sync_cache_info'));
370  $cache->setRequired(true);
371 
372  $sync_cache = new ilRadioOption($this->lng->txt('cal_sync_disabled'),0);
373  $cache->addOption($sync_cache);
374 
375  $sync_cache = new ilRadioOption($this->lng->txt('cal_sync_enabled'),1);
376  $cache->addOption($sync_cache);
377 
378  $cache_t = new ilNumberInputGUI('','sync_cache_time');
379  $cache_t->setValue($this->settings->getSynchronisationCacheMinutes());
380  $cache_t->setMinValue(0);
381  $cache_t->setSize(3);
382  $cache_t->setMaxLength(3);
383  $cache_t->setSuffix($this->lng->txt('form_minutes'));
384  $sync_cache->addSubItem($cache_t);
385 
386  $this->form->addItem($cache);
387 
388  // Notifications
389  $not = new ilFormSectionHeaderGUI();
390  $not->setTitle($this->lng->txt('notifications'));
391  $this->form->addItem($not);
392 
393  $cgn = new ilCheckboxInputGUI($this->lng->txt('cal_notification'),'cn');
394  $cgn->setValue(1);
395  $cgn->setChecked($this->settings->isNotificationEnabled());
396  $cgn->setInfo($this->lng->txt('cal_adm_notification_info'));
397  $this->form->addItem($cgn);
398 
399  // Registration
400  $book = new ilFormSectionHeaderGUI();
401  $book->setTitle($this->lng->txt('cal_registrations'));
402  $this->form->addItem($book);
403 
404  $cgn = new ilCheckboxInputGUI($this->lng->txt('cal_cg_registrations'),'cgr');
405  $cgn->setValue(1);
406  $cgn->setChecked($this->settings->isCGRegistrationEnabled());
407  $cgn->setInfo($this->lng->txt('cal_cg_registration_info'));
408  $this->form->addItem($cgn);
409 
410  }
411 }
412 ?>