ILIAS  Release_4_0_x_branch Revision 61816
 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  #$parser = new ilICalParser('./extern/Feiertage.ics',ilICalParser::INPUT_FILE);
139  #$parser->setCategoryId(6);
140  #$parser->parse();
141  /*
142  $calc = new ilCalendarRecurrenceCalculator(
143  new ilCalendarEntry(273),
144  new ilCalendarRecurrence(43));
145 
146  $list = $calc->calculateDateList(
147  new ilDateTime('2008-04-01',IL_CAL_DATE),
148  new ilDateTime('2008-04-31',IL_CAL_DATE));
149  */
150  #echo "RESULT: ".$list;
151  /*
152  $zeit = microtime(true);
153 
154  for($i = 0;$i < 1;$i++)
155  {
156  $calc = new ilCalendarRecurrenceCalculator(
157  new ilCalendarEntry(1061),
158  new ilCalendarRecurrence(72));
159 
160  $list = $calc->calculateDateList(
161  new ilDateTime('2008-03-01',IL_CAL_DATE),
162  new ilDateTime('2008-03-31',IL_CAL_DATE));
163  }
164  echo "NEEDS: ".(microtime(true) - $zeit).' seconds.<br>';
165  foreach($list->get() as $event)
166  {
167  echo $event->get(IL_CAL_DATETIME,'',$this->settings->getDefaultTimeZone()).'<br />';
168  }
169  */
170  #$parser = new ilICalParser('./extern/fc.ics',ilICalParser::INPUT_FILE);
171  #$parser->setCategoryId(11);
172  #$parser = new ilICalParser('./Feiertage.ics',ilICalParser::INPUT_FILE);
173  #$parser->parse();
174  #$entry = new ilCalendarEntry(927);
175  /*
176  $timezone = "US/Alaska";
177  echo $entry->getTitle().'<br>';
178  echo $entry->getStart()->get(IL_CAL_DATE,'',$timezone).'<br>';
179  echo $entry->getStart()->get(IL_CAL_DATETIME,'',$timezone).'<br>';
180  echo $entry->getEnd()->get(IL_CAL_DATE,'',$timezone).'<br>';
181  echo $entry->getEnd()->get(IL_CAL_DATETIME,'',$timezone).'<br>';
182 
183  $entry = new ilCalendarEntry(928);
184  echo $entry->getTitle().'<br>';
185  echo $entry->getStart()->get(IL_CAL_DATE,'',$timezone).'<br>';
186  echo $entry->getStart()->get(IL_CAL_DATETIME,'',$timezone).'<br>';
187  echo $entry->getEnd()->get(IL_CAL_DATE,'',$timezone).'<br>';
188  echo $entry->getEnd()->get(IL_CAL_DATETIME,'',$timezone).'<br>';
189  */
190  $this->tabs_gui->setTabActive('settings');
191  $this->initFormSettings();
192  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.settings.html','Services/Calendar');
193  $this->tpl->setVariable('CAL_SETTINGS',$this->form->getHTML());
194  return true;
195  }
196 
202  protected function save()
203  {
204  $this->settings->setEnabled((int) $_POST['enable']);
205  $this->settings->setDefaultWeekStart((int) $_POST['default_week_start']);
206  $this->settings->setDefaultTimeZone(ilUtil::stripSlashes($_POST['default_timezone']));
207  $this->settings->setDefaultTimeFormat((int) $_POST['default_time_format']);
208  $this->settings->setEnableGroupMilestones((int) $_POST['enable_grp_milestones']);
209  $this->settings->setDefaultDayStart((int) $_POST['dst']);
210  $this->settings->setDefaultDayEnd((int) $_POST['den']);
211  $this->settings->enableSynchronisationCache((bool) $_POST['sync_cache']);
212  $this->settings->setSynchronisationCacheMinutes((int) $_POST['sync_cache_time']);
213  $this->settings->setCacheMinutes((int) $_POST['cache_time']);
214  $this->settings->useCache((bool) $_POST['cache']);
215 
216  if(((int) $_POST['den']) < (int) $_POST['dst'])
217  {
218  ilUtil::sendFailure($this->lng->txt('cal_dstart_dend_warn'));
219  $this->settings();
220  return false;
221  }
222 
223  $this->settings->save();
224 
225  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
226  $this->settings();
227  }
228 
234  protected function initCalendarSettings()
235  {
236  include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
238  }
239 
245  protected function initFormSettings()
246  {
247  if(is_object($this->form))
248  {
249  return true;
250  }
251  include_once('Services/Calendar/classes/class.ilCalendarUtil.php');
252  include_once('Services/Form/classes/class.ilPropertyFormGUI.php');
253 
254  $this->form = new ilPropertyFormGUI();
255  $this->form->setFormAction($this->ctrl->getFormAction($this));
256  $this->form->setTitle($this->lng->txt('cal_global_settings'));
257  $this->form->addCommandButton('save',$this->lng->txt('save'));
258  #$this->form->addCommandButton('cancel',$this->lng->txt('cancel'));
259 
260  $check = new ilCheckboxInputGUI($this->lng->txt('enable_calendar'),'enable');
261  $check->setValue(1);
262  $check->setChecked($this->settings->isEnabled() ? true : false);
263  $this->form->addItem($check);
264 
265  $server_tz = new ilNonEditableValueGUI($this->lng->txt('cal_server_tz'));
267  $this->form->addItem($server_tz);
268 
269  $select = new ilSelectInputGUI($this->lng->txt('cal_def_timezone'),'default_timezone');
271  $select->setInfo($this->lng->txt('cal_def_timezone_info'));
272  $select->setValue($this->settings->getDefaultTimeZone());
273  $this->form->addItem($select);
274 
275  $select = new ilSelectInputGUI($this->lng->txt('cal_def_time_format'),'default_time_format');
276  $select->setOptions(array(
279  $select->setInfo($this->lng->txt('cal_def_time_format_info'));
280  $select->setValue($this->settings->getDefaultTimeFormat());
281  $this->form->addItem($select);
282 
283 
284  $radio = new ilRadioGroupInputGUI($this->lng->txt('cal_def_week_start'),'default_week_start');
285  $radio->setValue($this->settings->getDefaultWeekStart());
286 
287  $option = new ilRadioOption($this->lng->txt('l_su'),0);
288  $radio->addOption($option);
289  $option = new ilRadioOption($this->lng->txt('l_mo'),1);
290  $radio->addOption($option);
291 
292  // Calendar cache
293  $cache = new ilRadioGroupInputGUI($this->lng->txt('cal_cache'),'cache');
294  $cache->setValue((int) $this->settings->isCacheUsed());
295  $cache->setInfo($this->lng->txt('cal_cache_info'));
296  $cache->setRequired(true);
297 
298  $sync_cache = new ilRadioOption($this->lng->txt('cal_cache_disabled'),0);
299  $cache->addOption($sync_cache);
300 
301  $sync_cache = new ilRadioOption($this->lng->txt('cal_cache_enabled'),1);
302  $cache->addOption($sync_cache);
303 
304  $cache_t = new ilNumberInputGUI('','cache_time');
305  $cache_t->setValue($this->settings->getCacheMinutes());
306  $cache_t->setMinValue(0);
307  $cache_t->setSize(3);
308  $cache_t->setMaxLength(3);
309  $cache_t->setSuffix($this->lng->txt('form_minutes'));
310  $sync_cache->addSubItem($cache_t);
311  $this->form->addItem($cache);
312 
313  // enable milestone planning in groups
314  $checkm = new ilCheckboxInputGUI($this->lng->txt('cal_enable_group_milestones'),'enable_grp_milestones');
315  $checkm->setValue(1);
316  $checkm->setChecked($this->settings->getEnableGroupMilestones() ? true : false);
317  $checkm->setInfo($this->lng->txt('cal_enable_group_milestones_desc'));
318  $this->form->addItem($checkm);
319 
320  $this->form->addItem($radio);
321 
322  // Day start
323  $day_start = new ilSelectInputGUI($this->lng->txt('cal_day_start'),'dst');
324  $day_start->setOptions(
325  ilCalendarUtil::getHourSelection($this->settings->getDefaultTimeFormat())
326  );
327  $day_start->setValue($this->settings->getDefaultDayStart());
328  $this->form->addItem($day_start);
329 
330  $day_end = new ilSelectInputGUI($this->lng->txt('cal_day_end'),'den');
331  $day_end->setOptions(
332  ilCalendarUtil::getHourSelection($this->settings->getDefaultTimeFormat())
333  );
334  $day_end->setValue($this->settings->getDefaultDayEnd());
335  $this->form->addItem($day_end);
336 
337  // Synchronisation cache
338  $sec = new ilFormSectionHeaderGUI();
339  $sec->setTitle($this->lng->txt('cal_sync_header'));
340  $this->form->addItem($sec);
341 
342  $cache = new ilRadioGroupInputGUI($this->lng->txt('cal_sync_cache'),'sync_cache');
343  $cache->setValue((int) $this->settings->isSynchronisationCacheEnabled());
344  $cache->setInfo($this->lng->txt('cal_sync_cache_info'));
345  $cache->setRequired(true);
346 
347  $sync_cache = new ilRadioOption($this->lng->txt('cal_sync_disabled'),0);
348  $cache->addOption($sync_cache);
349 
350  $sync_cache = new ilRadioOption($this->lng->txt('cal_sync_enabled'),1);
351  $cache->addOption($sync_cache);
352 
353  $cache_t = new ilNumberInputGUI('','sync_cache_time');
354  $cache_t->setValue($this->settings->getSynchronisationCacheMinutes());
355  $cache_t->setMinValue(0);
356  $cache_t->setSize(3);
357  $cache_t->setMaxLength(3);
358  $cache_t->setSuffix($this->lng->txt('form_minutes'));
359  $sync_cache->addSubItem($cache_t);
360 
361  $this->form->addItem($cache);
362 
363  }
364 }
365 ?>