ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCalendarPresentationGUI.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 
24 include_once './Services/Calendar/classes/class.ilCalendarSettings.php';
25 
39 {
40  protected $ctrl;
41  protected $lng;
42  protected $tpl;
43  protected $tabs_gui;
44 
52  public function __construct()
53  {
54  global $ilCtrl,$lng,$tpl,$ilTabs,$ilUser;
55 
56  $this->ctrl = $ilCtrl;
57  $this->lng = $lng;
58  $this->lng->loadLanguageModule('dateplaner');
59 
60  $this->tpl = $tpl;
61  $this->tabs_gui = $ilTabs;
62 
63 
64  include_once('./Services/Calendar/classes/class.ilCalendarCategories.php');
65  $cats = ilCalendarCategories::_getInstance($ilUser->getId());
66 
67  include_once './Services/Calendar/classes/class.ilCalendarUserSettings.php';
69  {
71  }
72  else
73  {
75  }
76  }
77 
78 
86  public function executeCommand()
87  {
88  global $ilUser, $ilSetting,$tpl, $ilHelp;
89 
90  include_once('./Services/Calendar/classes/class.ilCalendarSettings.php');
91  if(!ilCalendarSettings::_getInstance()->isEnabled())
92  {
93  ilUtil::sendFailure($this->lng->txt('permission_denied'),true);
94  ilUtil::redirect('ilias.php?baseClass=ilPersonalDesktopGUI');
95  }
96 
97  $this->initSeed();
98  $this->prepareOutput();
99 
100  $next_class = $this->getNextClass();
101  switch($next_class)
102  {
103  case 'ilcalendarinboxgui':
104  $this->tabs_gui->activateTab('cal_upcoming_events_header');
105  $this->forwardToClass('ilcalendarinboxgui');
106  break;
107 
108  case 'ilconsultationhoursgui':
109  $this->tabs_gui->activateTab('app_consultation_hours');
110  $this->tabs_gui->clearTargets();
111 
112  // No side blocks
113  $this->tabs_gui->setBackTarget(
114  $this->lng->txt('cal_back_to_cal'),
115  $this->ctrl->getLinkTargetByClass($this->readLastClass())
116  );
117 
118  include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHoursGUI.php';
119  $gui = new ilConsultationHoursGUI();
120  $this->ctrl->forwardCommand($gui);
121  return true;
122 
123  case 'ilcalendarmonthgui':
124  $this->tabs_gui->activateTab('app_month');
125  $this->forwardToClass('ilcalendarmonthgui');
126  break;
127 
128  case 'ilcalendarweekgui':
129  $this->tabs_gui->activateTab('app_week');
130  $this->forwardToClass('ilcalendarweekgui');
131  break;
132 
133  case 'ilcalendardaygui':
134  $this->tabs_gui->activateTab('app_day');
135  $this->forwardToClass('ilcalendardaygui');
136  break;
137 
138  case 'ilcalendarusersettingsgui':
139  $this->ctrl->setReturn($this,'');
140  $this->tabs_gui->activateTab('settings');
141  $this->setCmdClass('ilcalendarusersettingsgui');
142 
143  include_once('./Services/Calendar/classes/class.ilCalendarUserSettingsGUI.php');
144  $user_settings = new ilCalendarUserSettingsGUI();
145  $this->ctrl->forwardCommand($user_settings);
146  // No side blocks
147  return true;
148 
149  case 'ilcalendarappointmentgui':
150  $this->ctrl->setReturn($this,'');
151  $this->tabs_gui->activateTab($_SESSION['cal_last_tab']);
152 
153  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentGUI.php');
154  $app = new ilCalendarAppointmentGUI($this->seed, $this->seed,(int) $_GET['app_id']);
155  $this->ctrl->forwardCommand($app);
156  break;
157 
158  case 'ilcalendarsubscriptiongui':
159  $this->ctrl->setReturn($this,'');
160  $this->tabs_gui->activateTab($_SESSION['cal_last_tab']);
161  include_once './Services/Calendar/classes/class.ilCalendarSubscriptionGUI.php';
162  $sub = new ilCalendarSubscriptionGUI((int) $_REQUEST['cal_id']);
163  $this->ctrl->forwardCommand($sub);
164  break;
165 
166  case 'ilcalendarcategorygui':
167  $this->ctrl->setReturn($this,'');
168 
169  include_once('Services/Calendar/classes/class.ilCalendarCategoryGUI.php');
170  $category = new ilCalendarCategoryGUI($ilUser->getId(),$this->seed);
171  if($this->ctrl->forwardCommand($category))
172  {
173  $this->tabs_gui->activateTab("cal_manage");
174 
175  // no side blocks
176  return;
177  }
178  else
179  {
180  $this->tabs_gui->activateTab($_SESSION['cal_last_tab']);
181  break;
182  }
183 
184  default:
185  $cmd = $this->ctrl->getCmd("show");
186 
187  $this->$cmd();
188  break;
189  }
190 
191  $this->showSideBlocks();
192 
194 
195  return true;
196  }
197 
203  public function getNextClass()
204  {
205  global $ilUser;
206 
207  if(strlen($next_class = $this->ctrl->getNextClass()))
208  {
209  return $next_class;
210  }
211  if($this->ctrl->getCmdClass() == strtolower(get_class($this)) or $this->ctrl->getCmdClass() == '')
212  {
213  return $this->readLastClass();
214  }
215  }
216 
221  public function readLastClass()
222  {
223  global $ilUser;
224 
225  return $ilUser->getPref('cal_last_class') ? $ilUser->getPref('cal_last_class') : 'ilcalendarinboxgui';
226 
227  }
228 
229  public function setCmdClass($a_class)
230  {
231  // If cmd class == 'ilcalendarpresentationgui' the cmd class is set to the the new forwarded class
232  // otherwise e.g ilcalendarmonthgui tries to forward (back) to ilcalendargui.
233 
234  if($this->ctrl->getCmdClass() == strtolower(get_class($this)))
235  {
236  $this->ctrl->setCmdClass(strtolower($a_class));
237  }
238  return true;
239  }
240 
246  protected function forwardToClass($a_class)
247  {
248  global $ilUser;
249 
250  switch($a_class)
251  {
252  case 'ilcalendarmonthgui':
253  $ilUser->writePref('cal_last_class',$a_class);
254  $_SESSION['cal_last_tab'] = 'app_month';
255  $this->setCmdClass('ilcalendarmonthgui');
256  include_once('./Services/Calendar/classes/class.ilCalendarMonthGUI.php');
257  $month_gui = new ilCalendarMonthGUI($this->seed);
258  $this->ctrl->forwardCommand($month_gui);
259  break;
260 
261  case 'ilcalendarweekgui':
262  $ilUser->writePref('cal_last_class',$a_class);
263  $_SESSION['cal_last_tab'] = 'app_week';
264  $this->setCmdClass('ilcalendarweekgui');
265  include_once('./Services/Calendar/classes/class.ilCalendarWeekGUI.php');
266  $week_gui = new ilCalendarWeekGUI($this->seed);
267  $this->ctrl->forwardCommand($week_gui);
268  break;
269 
270  case 'ilcalendardaygui':
271  $ilUser->writePref('cal_last_class',$a_class);
272  $_SESSION['cal_last_tab'] = 'app_day';
273  $this->setCmdClass('ilcalendardaygui');
274  include_once('./Services/Calendar/classes/class.ilCalendarDayGUI.php');
275  $day_gui = new ilCalendarDayGUI($this->seed);
276  $this->ctrl->forwardCommand($day_gui);
277  break;
278 
279  case 'ilcalendarinboxgui':
280  $ilUser->writePref('cal_last_class',$a_class);
281  $_SESSION['cal_last_tab'] = 'cal_upcoming_events_header';
282  $this->setCmdClass('ilcalendarinboxgui');
283  include_once('./Services/Calendar/classes/class.ilCalendarInboxGUI.php');
284  $inbox_gui = new ilCalendarinboxGUI($this->seed);
285  $this->ctrl->forwardCommand($inbox_gui);
286  break;
287 
288  }
289  }
290 
298  protected function loadHistory()
299  {
300  global $ilUser;
301 
302  $this->ctrl->setCmd('');
303  $history = $ilUser->getPref('cal_last_class') ? $ilUser->getPref('cal_last_class') : 'ilcalendarmonthgui';
304  $this->forwardToClass($history);
305  }
306 
314  protected function showSideBlocks()
315  {
316  global $ilUser, $ilCtrl;
317 
318  $tpl = new ilTemplate('tpl.cal_side_block.html',true,true,'Services/Calendar');
319 
320  include_once('./Services/Calendar/classes/class.ilMiniCalendarGUI.php');
321  $mini = new ilMiniCalendarGUI($this->seed, $this);
322 // $mini->setPresentationMode(ilMiniCalendarGUI::PRESENTATION_CALENDAR);
323  $tpl->setVariable('MINICAL',$mini->getHTML());
324 
325  include_once('./Services/Calendar/classes/class.ilCalendarCategoryGUI.php');
326  $cat = new ilCalendarCategoryGUI($ilUser->getId(),$this->seed);
327  $tpl->setVariable('CATEGORIES', $ilCtrl->getHTML($cat));
328 
329  $this->tpl->setLeftContent($tpl->get());
330  }
331 
332 
340  public function show()
341  {
342  $this->tpl->addCss(ilUtil::getStyleSheetLocation('filesystem','delos.css','Services/Calendar'));
343  }
344 
345 
351  protected function prepareOutput()
352  {
353  global $rbacsystem, $ilHelp;
354 
355  $ilHelp->setScreenIdComponent("cal");
356 
357  $this->tabs_gui->addTarget('cal_upcoming_events_header',$this->ctrl->getLinkTargetByClass('ilCalendarInboxGUI',''));
358 
359  if(
360  $rbacsystem->checkAccess('add_consultation_hours', ilCalendarSettings::_getInstance()->getCalendarSettingsId()) and
361  ilCalendarSettings::_getInstance()->areConsultationHoursEnabled()
362  )
363  {
364  $this->tabs_gui->addTarget('app_consultation_hours',$this->ctrl->getLinkTargetByClass('ilConsultationHoursGUI',''));
365  }
366  $this->tabs_gui->addTarget('app_day',$this->ctrl->getLinkTargetByClass('ilCalendarDayGUI',''));
367  $this->tabs_gui->addTarget('app_week',$this->ctrl->getLinkTargetByClass('ilCalendarWeekGUI',''));
368  $this->tabs_gui->addTarget('app_month',$this->ctrl->getLinkTargetByClass('ilCalendarMonthGUI',''));
369  $this->tabs_gui->addTarget('cal_manage',$this->ctrl->getLinkTargetByClass('ilCalendarCategoryGUI','manage'));
370  $this->tabs_gui->addTarget('settings',$this->ctrl->getLinkTargetByClass('ilCalendarUserSettingsGUI',''));
371  }
372 
378  public function initSeed()
379  {
380  include_once('Services/Calendar/classes/class.ilDate.php');
381  $this->seed = $_REQUEST['seed'] ? new ilDate($_REQUEST['seed'],IL_CAL_DATE) : new ilDate(date('Y-m-d',time()),IL_CAL_DATE);
382  $_GET['seed'] = $this->seed->get(IL_CAL_DATE,'');
383  $this->ctrl->saveParameter($this,array('seed'));
384  }
385 
389  protected function synchroniseExternalCalendars()
390  {
391  global $ilUser;
392 
393 
394  if(!ilCalendarSettings::_getInstance()->isWebCalSyncEnabled())
395  {
396  return false;
397  }
398  // @todo make this thread safe
399 
400  $limit = new ilDateTime(time(),IL_CAL_UNIX);
401  $limit->increment(IL_CAL_HOUR, -1 * ilCalendarSettings::_getInstance()->getWebCalSyncHours());
402 
403  $cats = ilCalendarCategories::_getInstance($ilUser->getId());
404  foreach($cats->getCategoriesInfo() as $cat_id => $info)
405  {
406  if($info['remote'])
407  {
408  // Check for execution
409  $category = new ilCalendarCategory($cat_id);
410 
411  if(ilDateTime::_before($category->getRemoteSyncLastExecution(), $limit))
412  {
413  // update in any case to avoid multiple updates of invalid calendar sources.
414  $category->setRemoteSyncLastExecution(new ilDateTime(time(),IL_CAL_UNIX));
415  $category->update();
416 
417  include_once './Services/Calendar/classes/class.ilCalendarRemoteReader.php';
418  $remote = new ilCalendarRemoteReader($category->getRemoteUrl());
419  $remote->setUser($category->getRemoteUser());
420  $remote->setPass($category->getRemotePass());
421  $remote->read();
422  $remote->import($category);
423  break;
424  }
425  }
426  }
427  }
428 
429 }
430 ?>