ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCalendarBlockGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2008 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/Block/classes/class.ilBlockGUI.php");
25 include_once './Services/Calendar/classes/class.ilCalendarCategories.php';
26 
40 {
41  public $ctrl = null;
42 
43  static $block_type = "cal";
44  static $st_data;
45 
51  function ilCalendarBlockGUI($a_skip_init = false)
52  {
53  global $ilCtrl, $lng, $ilUser, $tpl;
54 
56 
57  $this->ctrl = $ilCtrl;
58  $this->setImage(ilUtil::getImagePath("icon_cals_s.gif"));
59 
60  $lng->loadLanguageModule("dateplaner");
61  include_once("./Services/News/classes/class.ilNewsItem.php");
62 
63  if (!$a_skip_init)
64  {
65  $this->initCategories();
66  $this->setBlockId($ilCtrl->getContextObjId());
67  }
68 
69  $this->setLimit(5); // @todo: needed?
70  $this->setAvailableDetailLevels(2);
71  $this->setEnableNumInfo(false);
72 
73  $this->setTitle($lng->txt("calendar"));
74  //$this->setRowTemplate("tpl.block_calendar.html", "Services/Calendar");
75  //$this->setData($data);
76  $this->allow_moving = false;
77  //$this->handleView();
78 
79  include_once('Services/Calendar/classes/class.ilDate.php');
80  include_once('Services/Calendar/classes/class.ilCalendarUserSettings.php');
81 
82  $seed_str = ($_GET["seed"] == "")
83  ? $_SESSION["il_cal_block_".$this->getBlockType()."_".$this->getBlockId()."_seed"]
84  : $_GET["seed"];
85 
86  if ($_GET["seed"] != "")
87  {
88  $_SESSION["il_cal_block_".$this->getBlockType()."_".$this->getBlockId()."_seed"]
89  = $_GET["seed"];
90  }
91 
92  if ($seed_str == "")
93  {
94  $this->seed = new ilDate(time(),IL_CAL_UNIX); // @todo: check this
95  }
96  else
97  {
98  $this->seed = new ilDate($seed_str,IL_CAL_DATE); // @todo: check this
99  }
100  $this->user_settings = ilCalendarUserSettings::_getInstanceByUserId($ilUser->getId());
101 
102  $tpl->addCSS("./Services/Calendar/css/calendar.css");
103  // @todo: this must work differently...
104  $tpl->addCSS("./Services/Calendar/templates/default/delos.css");
105  }
106 
112  static function getBlockType()
113  {
114  return self::$block_type;
115  }
116 
122  static function isRepositoryObject()
123  {
124  return false;
125  }
126 
130  static function getScreenMode()
131  {
132  global $ilCtrl;
133 
134  $cmd_class = $ilCtrl->getCmdClass();
135 
136  if ($cmd_class == "ilcalendarappointmentgui" ||
137  $cmd_class == "ilcalendardaygui" ||
138  $cmd_class == "ilcalendarweekgui" ||
139  $cmd_class == "ilcalendarmonthgui" ||
140  $cmd_class == "ilcalendarinboxgui" ||
141  $_GET['cmd'] == 'showCalendarSubscription')
142  {
143  return IL_SCREEN_CENTER;
144  }
145 
146  switch($ilCtrl->getCmd())
147  {
148  case "kkk":
149  // return IL_SCREEN_CENTER;
150  // return IL_SCREEN_FULL;
151 
152  default:
153  //return IL_SCREEN_SIDE;
154  break;
155  }
156  }
157 
161  function &executeCommand()
162  {
163  global $ilCtrl,$ilTabs;
164 
165  $next_class = $ilCtrl->getNextClass();
166  $cmd = $ilCtrl->getCmd("getHTML");
167 
168  $this->setSubTabs();
169 
170  switch ($next_class)
171  {
172  case "ilcalendarappointmentgui":
173  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentGUI.php');
174  $app_gui = new ilCalendarAppointmentGUI($this->seed);
175  $ilCtrl->forwardCommand($app_gui);
176  break;
177 
178  case "ilcalendardaygui":
179  $ilTabs->setSubTabActive('app_day');
180  include_once('./Services/Calendar/classes/class.ilCalendarDayGUI.php');
181  $day_gui = new ilCalendarDayGUI($this->seed);
182  $ilCtrl->forwardCommand($day_gui);
183  break;
184 
185  case "ilcalendarweekgui":
186  $ilTabs->setSubTabActive('app_week');
187  include_once('./Services/Calendar/classes/class.ilCalendarWeekGUI.php');
188  $week_gui = new ilCalendarWeekGUI($this->seed);
189  $ilCtrl->forwardCommand($week_gui);
190  break;
191 
192  case "ilcalendarmonthgui":
193  $ilTabs->setSubTabActive('app_month');
194  include_once('./Services/Calendar/classes/class.ilCalendarMonthGUI.php');
195  $month_gui = new ilCalendarMonthGUI($this->seed);
196  $ilCtrl->forwardCommand($month_gui);
197  break;
198 
199  case "ilcalendarinboxgui":
200  include_once('./Services/Calendar/classes/class.ilCalendarInboxGUI.php');
201  $inbox = new ilCalendarInboxGUI($this->seed);
202  $ilCtrl->forwardCommand($inbox);
203  break;
204 
205  default:
206  return $this->$cmd();
207  }
208  }
209 
215  public function setEnableEdit($a_enable_edit = 0)
216  {
217  $this->enable_edit = $a_enable_edit;
218  }
219 
225  public function getEnableEdit()
226  {
227  return $this->enable_edit;
228  }
229 
233  function fillDataSection()
234  {
235  if ($this->getCurrentDetailLevel() > 1)
236  {
237  $tpl = new ilTemplate("tpl.calendar_block.html", true, true,
238  "Services/Calendar");
239 
240  $this->addMiniMonth($tpl);
241  $this->setDataSection($tpl->get());
242  }
243  else
244  {
245  $this->setDataSection($this->getOverview());
246  }
247  }
248 
253  function addMiniMonth($a_tpl)
254  {
255  global $ilCtrl, $lng,$ilUser;
256 
257  // weekdays
258  include_once('Services/Calendar/classes/class.ilCalendarUtil.php');
259  $a_tpl->setCurrentBlock('month_header_col');
260  $a_tpl->setVariable('TXT_WEEKDAY', $lng->txt("cal_week_abbrev"));
261  $a_tpl->parseCurrentBlock();
262  for($i = (int) $this->user_settings->getWeekStart();$i < (7 + (int) $this->user_settings->getWeekStart());$i++)
263  {
264  $a_tpl->setCurrentBlock('month_header_col');
265  $a_tpl->setVariable('TXT_WEEKDAY',ilCalendarUtil::_numericDayToString($i,false));
266  $a_tpl->parseCurrentBlock();
267  }
268 
269  include_once('Services/Calendar/classes/class.ilCalendarSchedule.php');
270  $this->scheduler = new ilCalendarSchedule($this->seed,ilCalendarSchedule::TYPE_MONTH);
271  $this->scheduler->addSubitemCalendars(true);
272  $this->scheduler->calculate();
273 
274  $counter = 0;
275  foreach(ilCalendarUtil::_buildMonthDayList($this->seed->get(IL_CAL_FKT_DATE,'m'),
276  $this->seed->get(IL_CAL_FKT_DATE,'Y'),
277  $this->user_settings->getWeekStart())->get() as $date)
278  {
279  $counter++;
280  //$this->showEvents($date);
281 
282 
283  $a_tpl->setCurrentBlock('month_col');
284 
285  if(count($this->scheduler->getByDay($date,$ilUser->getTimeZone())))
286  {
287  $a_tpl->setVariable('DAY_CLASS','calminiapp');
288  #$a_tpl->setVariable('TD_CLASS','calminiapp');
289  }
290  include_once('./Services/Calendar/classes/class.ilCalendarUtil.php');
291  if(ilCalendarUtil::_isToday($date))
292  {
293  $a_tpl->setVariable('TD_CLASS','calminitoday');
294  }
295  #elseif(ilDateTime::_equals($date,$this->seed,IL_CAL_DAY))
296  #{
297  # $a_tpl->setVariable('TD_CLASS','calmininow');
298  #}
299  elseif(ilDateTime::_equals($date,$this->seed,IL_CAL_MONTH))
300  {
301  $a_tpl->setVariable('TD_CLASS','calministd');
302  }
303  elseif(ilDateTime::_before($date,$this->seed,IL_CAL_MONTH))
304  {
305  $a_tpl->setVariable('TD_CLASS','calminiprev');
306  }
307  else
308  {
309  $a_tpl->setVariable('TD_CLASS','calmininext');
310  }
311 
312  $day = $date->get(IL_CAL_FKT_DATE,'j');
313  $month = $date->get(IL_CAL_FKT_DATE,'n');
314 
315  $month_day = $day;
316 
317  $ilCtrl->clearParametersByClass('ilcalendardaygui');
318  $ilCtrl->setParameterByClass('ilcalendardaygui','seed',$date->get(IL_CAL_DATE));
319  $a_tpl->setVariable('OPEN_DAY_VIEW', $ilCtrl->getLinkTargetByClass('ilcalendardaygui',''));
320  $ilCtrl->clearParametersByClass('ilcalendardaygui');
321 
322  $a_tpl->setVariable('MONTH_DAY',$month_day);
323  //$this->tpl->setVariable('NEW_SRC',ilUtil::getImagePath('new.gif','calendar'));
324  //$this->tpl->setVariable('NEW_ALT',$this->lng->txt('cal_new_app'));
325  //$this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
326  //$this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed',$date->get(IL_CAL_DATE));
327  //$this->tpl->setVariable('ADD_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','add'));
328 
329  //$this->tpl->setVariable('OPEN_SRC',ilUtil::getImagePath('open.gif','calendar'));
330  $a_tpl->parseCurrentBlock();
331 
332  if($counter and !($counter % 7))
333  {
334  $a_tpl->setCurrentBlock('month_row');
335  $ilCtrl->clearParametersByClass('ilcalendarweekgui');
336  $ilCtrl->setParameterByClass('ilcalendarweekgui','seed',$date->get(IL_CAL_DATE));
337  $a_tpl->setVariable('OPEN_WEEK_VIEW', $ilCtrl->getLinkTargetByClass('ilcalendarweekgui',''));
338  $ilCtrl->clearParametersByClass('ilcalendarweekgui');
339  $a_tpl->setVariable('TD_CLASS','calminiweek');
340  $a_tpl->setVariable('WEEK',
341  $date->get(IL_CAL_FKT_DATE,'W'));
342  $a_tpl->parseCurrentBlock();
343  }
344  }
345  $a_tpl->setCurrentBlock('mini_month');
346  $a_tpl->setVariable('TXT_MONTH_OVERVIEW', $lng->txt("cal_month_overview"));
347  $a_tpl->setVariable('TXT_MONTH',
348  $lng->txt('month_'.$this->seed->get(IL_CAL_FKT_DATE,'m').'_long').
349  ' '.$this->seed->get(IL_CAL_FKT_DATE,'Y'));
350  $myseed = clone($this->seed);
351  $ilCtrl->setParameterByClass('ilcalendarmonthgui','seed',$myseed->get(IL_CAL_DATE));
352  $a_tpl->setVariable('OPEN_MONTH_VIEW',$ilCtrl->getLinkTargetByClass('ilcalendarmonthgui',''));
353 
354  $myseed->increment(ilDateTime::MONTH, -1);
355  $ilCtrl->setParameter($this,'seed',$myseed->get(IL_CAL_DATE));
356 
357  $a_tpl->setVariable('BL_TYPE', $this->getBlockType());
358  $a_tpl->setVariable('BL_ID', $this->getBlockId());
359 
360  $a_tpl->setVariable('PREV_MONTH',
361  $ilCtrl->getLinkTarget($this, "setSeed"));
362  $a_tpl->setVariable('PREV_MONTH_ASYNC',
363  $ilCtrl->getLinkTarget($this, "setSeed", "", true));
364 
365  $myseed->increment(ilDateTime::MONTH, 2);
366  $ilCtrl->setParameter($this,'seed',$myseed->get(IL_CAL_DATE));
367  $a_tpl->setVariable('NEXT_MONTH',
368  $ilCtrl->getLinkTarget($this, "setSeed"));
369  $a_tpl->setVariable('NEXT_MONTH_ASYNC',
370  $ilCtrl->getLinkTarget($this, "setSeed", "", true));
371 
372  $ilCtrl->setParameter($this, 'seed', "");
373  $a_tpl->parseCurrentBlock();
374  }
375 
379  function getHTML()
380  {
381  global $ilCtrl, $lng, $ilUser,$ilAccess;
382 
383  if ($this->getCurrentDetailLevel() == 0)
384  {
385  return "";
386  }
387 
388  // add edit commands
389  #if ($this->getEnableEdit())
390 
393  {
394  $this->addBlockCommand(
395  $this->ctrl->getLinkTarget($this,'showCalendarSubscription'),
396  $lng->txt('ical_export'),
397  '',
398  ilUtil::getImagePath('ical.gif','Services/Calendar'),
399  true
400  );
401  }
402 
403 
404  if($this->mode == ilCalendarCategories::MODE_REPOSITORY and
405  $ilAccess->checkAccess('edit_event','',(int) $_GET['ref_id']))
406  {
407 
408  $ilCtrl->setParameter($this, "add_mode", "block");
409  $this->addBlockCommand(
410  $ilCtrl->getLinkTargetByClass("ilCalendarAppointmentGUI",
411  "add"),
412  $lng->txt("add_appointment"));
413  $ilCtrl->setParameter($this, "add_mode", "");
414  }
415 
416  if ($this->getProperty("settings") == true)
417  {
418  $this->addBlockCommand(
419  $ilCtrl->getLinkTarget($this, "editSettings"),
420  $lng->txt("settings"));
421  }
422 
423  $ilCtrl->setParameterByClass("ilcolumngui", "seed", $_GET["seed"]);
424  $ret = parent::getHTML();
425  $ilCtrl->setParameterByClass("ilcolumngui", "seed", "");
426 
427  return $ret;
428  }
429 
433  function fillRow($news)
434  {
435  global $ilUser, $ilCtrl, $lng;
436 
437  }
438 
442  function getOverview()
443  {
444  global $ilUser, $lng, $ilCtrl;
445 
446  include_once('./Services/Calendar/classes/class.ilCalendarSchedule.php');
447  $schedule = new ilCalendarSchedule($this->seed,ilCalendarSchedule::TYPE_INBOX);
448  $events = $schedule->getChangedEvents(true);
449 
450  $link = '<a href='.$ilCtrl->getLinkTargetByClass('ilcalendarinboxgui','').'>';
451  $text = '<div class="small">'.((int) count($events))." ".$lng->txt("cal_changed_events_header")."</div>";
452  $end_link = '</a>';
453 
454  return $link.$text.$end_link;
455  }
456 
457  function addCloseCommand($a_content_block)
458  {
459  global $lng, $ilCtrl;
460 
461  $a_content_block->addHeaderCommand($ilCtrl->getParentReturn($this),
462  $lng->txt("close"), true);
463  }
464 
472  protected function initCategories()
473  {
475 
476  include_once('./Services/Calendar/classes/class.ilCalendarCategories.php');
478  }
479 
485  protected function setSubTabs()
486  {
487  global $ilTabs;
488 
489  $ilTabs->clearSubTabs();
490  return true;
491 
492  // TODO: needs another switch
493  if($_GET['ref_id'])
494  {
495 
496  $ilTabs->addSubTabTarget('app_day',$this->ctrl->getLinkTargetByClass('ilCalendarDayGUI',''));
497  $ilTabs->addSubTabTarget('app_week',$this->ctrl->getLinkTargetByClass('ilCalendarWeekGUI',''));
498  $ilTabs->addSubTabTarget('app_month',$this->ctrl->getLinkTargetByClass('ilCalendarMonthGUI',''));
499  }
500  return true;
501  }
502 
506  function setSeed()
507  {
508  global $ilCtrl, $ilUser;
509 
510  //$ilUser->writePref("il_pd_bkm_mode", 'flat');
511  $_SESSION["il_cal_block_".$this->getBlockType()."_".$this->getBlockId()."_seed"] =
512  $_GET["seed"];
513  if ($ilCtrl->isAsynch())
514  {
515  echo $this->getHTML();
516  exit;
517  }
518  else
519  {
520  $this->returnToUpperContext();
521  }
522  }
523 
528  {
529  global $ilCtrl;
530 
531  $ilCtrl->returnToParent($this);
532  }
533 
534 
535  public function showCalendarSubscription()
536  {
537  global $lng, $ilUser;
538 
539  $tpl = new ilTemplate('tpl.show_calendar_subscription.html',true,true,'Services/Calendar');
540 
541  $tpl->setVariable('TXT_TITLE',$lng->txt('cal_subscription_header'));
542  $tpl->setVariable('TXT_INFO',$lng->txt('cal_subscription_info'));
543  $tpl->setVariable('TXT_CAL_URL',$lng->txt('cal_subscription_url'));
544 
545  include_once './Services/Calendar/classes/class.ilCalendarAuthenticationToken.php';
546 
547  switch($this->mode)
548  {
552  $calendar = 0;
553  break;
554 
555  default:
557  // TODO: calendar id
558  $calendar = ilObject::_lookupObjId((int) $_GET['ref_id']);
559  break;
560  }
561  if($hash = ilCalendarAuthenticationToken::lookupAuthToken($ilUser->getId(), $selection, $calendar))
562  {
563  ;
564  }
565  else
566  {
567  $token = new ilCalendarAuthenticationToken($ilUser->getId());
568  $token->setSelectionType($selection);
569  $token->setCalendar($calendar);
570  $hash = $token->add();
571  }
572  $url = ILIAS_HTTP_PATH.'/calendar.php?client_id='.CLIENT_ID.'&token='.$hash;
573 
574  $tpl->setVariable('VAL_CAL_URL',$url);
575  $tpl->setVariable('VAL_CAL_URL_TXT',$url);
576 
577  include_once("./Services/PersonalDesktop/classes/class.ilPDContentBlockGUI.php");
578  $content_block = new ilPDContentBlockGUI();
579  $content_block->setContent($tpl->get());
580  $content_block->setTitle($lng->txt("calendar"));
581  #$content_block->setImage(ilUtil::getImagePath("icon_news.gif"));
582  $content_block->addHeaderCommand($this->ctrl->getParentReturn($this),
583  $lng->txt("selected_items_back"));
584 
585  return $content_block->getHTML();
586 
587  }
588 }
589 
590 ?>