ILIAS  Release_3_10_x_branch Revision 61812
 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 
39 {
41  const CAL_MODE_PD = 2;
42 
43  public $ctrl = null;
44 
45  static $block_type = "cal";
46  static $st_data;
47 
53  function ilCalendarBlockGUI($a_skip_init = false)
54  {
55  global $ilCtrl, $lng, $ilUser, $tpl;
56 
58 
59  $this->ctrl = $ilCtrl;
60  $this->setImage(ilUtil::getImagePath("icon_cals_s.gif"));
61 
62  $lng->loadLanguageModule("dateplaner");
63  include_once("./Services/News/classes/class.ilNewsItem.php");
64 
65  if (!$a_skip_init)
66  {
67  $this->initCategories();
68  $this->setBlockId($ilCtrl->getContextObjId());
69  }
70 
71  $this->setLimit(5); // @todo: needed?
72  $this->setAvailableDetailLevels(2);
73  $this->setEnableNumInfo(false);
74 
75  $this->setTitle($lng->txt("calendar"));
76  //$this->setRowTemplate("tpl.block_calendar.html", "Services/Calendar");
77  //$this->setData($data);
78  $this->allow_moving = false;
79  //$this->handleView();
80 
81  include_once('Services/Calendar/classes/class.ilDate.php');
82  include_once('Services/Calendar/classes/class.ilCalendarUserSettings.php');
83 
84  $seed_str = ($_GET["seed"] == "")
85  ? $_SESSION["il_cal_block_".$this->getBlockType()."_".$this->getBlockId()."_seed"]
86  : $_GET["seed"];
87 
88  if ($_GET["seed"] != "")
89  {
90  $_SESSION["il_cal_block_".$this->getBlockType()."_".$this->getBlockId()."_seed"]
91  = $_GET["seed"];
92  }
93 
94  if ($seed_str == "")
95  {
96  $this->seed = new ilDate(time(),IL_CAL_UNIX); // @todo: check this
97  }
98  else
99  {
100  $this->seed = new ilDate($seed_str,IL_CAL_DATE); // @todo: check this
101  }
102  $this->user_settings = ilCalendarUserSettings::_getInstanceByUserId($ilUser->getId());
103 
104  $tpl->addCSS("./Services/Calendar/css/calendar.css");
105  // @todo: this must work differently...
106  $tpl->addCSS("./Services/Calendar/templates/default/delos.css");
107  }
108 
114  static function getBlockType()
115  {
116  return self::$block_type;
117  }
118 
124  static function isRepositoryObject()
125  {
126  return false;
127  }
128 
132  static function getScreenMode()
133  {
134  global $ilCtrl;
135 
136  $cmd_class = $ilCtrl->getCmdClass();
137 
138  if ($cmd_class == "ilcalendarappointmentgui" ||
139  $cmd_class == "ilcalendardaygui" ||
140  $cmd_class == "ilcalendarweekgui" ||
141  $cmd_class == "ilcalendarmonthgui" ||
142  $cmd_class == "ilcalendarinboxgui")
143  {
144  return IL_SCREEN_CENTER;
145  }
146 
147  switch($ilCtrl->getCmd())
148  {
149  case "kkk":
150  // return IL_SCREEN_CENTER;
151  // return IL_SCREEN_FULL;
152 
153  default:
154  //return IL_SCREEN_SIDE;
155  break;
156  }
157  }
158 
162  function &executeCommand()
163  {
164  global $ilCtrl,$ilTabs;
165 
166  $next_class = $ilCtrl->getNextClass();
167  $cmd = $ilCtrl->getCmd("getHTML");
168 
169  $this->setSubTabs();
170 
171  switch ($next_class)
172  {
173  case "ilcalendarappointmentgui":
174  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentGUI.php');
175  $app_gui = new ilCalendarAppointmentGUI($this->seed);
176  $ilCtrl->forwardCommand($app_gui);
177  break;
178 
179  case "ilcalendardaygui":
180  $ilTabs->setSubTabActive('app_day');
181  include_once('./Services/Calendar/classes/class.ilCalendarDayGUI.php');
182  $day_gui = new ilCalendarDayGUI($this->seed);
183  $ilCtrl->forwardCommand($day_gui);
184  break;
185 
186  case "ilcalendarweekgui":
187  $ilTabs->setSubTabActive('app_week');
188  include_once('./Services/Calendar/classes/class.ilCalendarWeekGUI.php');
189  $week_gui = new ilCalendarWeekGUI($this->seed);
190  $ilCtrl->forwardCommand($week_gui);
191  break;
192 
193  case "ilcalendarmonthgui":
194  $ilTabs->setSubTabActive('app_month');
195  include_once('./Services/Calendar/classes/class.ilCalendarMonthGUI.php');
196  $month_gui = new ilCalendarMonthGUI($this->seed);
197  $ilCtrl->forwardCommand($month_gui);
198  break;
199 
200  case "ilcalendarinboxgui":
201  include_once('./Services/Calendar/classes/class.ilCalendarInboxGUI.php');
202  $inbox = new ilCalendarInboxGUI($this->seed);
203  $ilCtrl->forwardCommand($inbox);
204  break;
205 
206  default:
207  return $this->$cmd();
208  }
209  }
210 
216  public function setEnableEdit($a_enable_edit = 0)
217  {
218  $this->enable_edit = $a_enable_edit;
219  }
220 
226  public function getEnableEdit()
227  {
228  return $this->enable_edit;
229  }
230 
234  function fillDataSection()
235  {
236  if ($this->getCurrentDetailLevel() > 1)
237  {
238  $tpl = new ilTemplate("tpl.calendar_block.html", true, true,
239  "Services/Calendar");
240 
241  $this->addMiniMonth($tpl);
242  $this->setDataSection($tpl->get());
243  }
244  else
245  {
246  $this->setDataSection($this->getOverview());
247  }
248  }
249 
254  function addMiniMonth($a_tpl)
255  {
256  global $ilCtrl, $lng,$ilUser;
257 
258  // weekdays
259  include_once('Services/Calendar/classes/class.ilCalendarUtil.php');
260  for($i = (int) $this->user_settings->getWeekStart();$i < (7 + (int) $this->user_settings->getWeekStart());$i++)
261  {
262  $a_tpl->setCurrentBlock('month_header_col');
263  $a_tpl->setVariable('TXT_WEEKDAY',ilCalendarUtil::_numericDayToString($i,false));
264  $a_tpl->parseCurrentBlock();
265  }
266  $a_tpl->setCurrentBlock('month_header_col');
267  $a_tpl->setVariable('TXT_WEEKDAY', "&nbsp;");
268  $a_tpl->parseCurrentBlock();
269 
270  include_once('Services/Calendar/classes/class.ilCalendarSchedule.php');
271  $this->scheduler = new ilCalendarSchedule($this->seed,ilCalendarSchedule::TYPE_MONTH);
272  $this->scheduler->addSubitemCalendars(true);
273  $this->scheduler->calculate();
274 
275  $counter = 0;
276  foreach(ilCalendarUtil::_buildMonthDayList($this->seed->get(IL_CAL_FKT_DATE,'m'),
277  $this->seed->get(IL_CAL_FKT_DATE,'Y'),
278  $this->user_settings->getWeekStart())->get() as $date)
279  {
280  $counter++;
281  //$this->showEvents($date);
282 
283 
284  $a_tpl->setCurrentBlock('month_col');
285 
286  if(count($this->scheduler->getByDay($date,$ilUser->getTimeZone())))
287  {
288  $a_tpl->setVariable('DAY_CLASS','calminiapp');
289  #$a_tpl->setVariable('TD_CLASS','calminiapp');
290  }
291  include_once('./Services/Calendar/classes/class.ilCalendarUtil.php');
292  if(ilCalendarUtil::_isToday($date))
293  {
294  $a_tpl->setVariable('TD_CLASS','calminitoday');
295  }
296  elseif(ilDateTime::_equals($date,$this->seed,IL_CAL_DAY))
297  {
298  $a_tpl->setVariable('TD_CLASS','calmininow');
299  }
300  elseif(ilDateTime::_equals($date,$this->seed,IL_CAL_MONTH))
301  {
302  $a_tpl->setVariable('TD_CLASS','calministd');
303  }
304  elseif(ilDateTime::_before($date,$this->seed,IL_CAL_MONTH))
305  {
306  $a_tpl->setVariable('TD_CLASS','calminiprev');
307  }
308  else
309  {
310  $a_tpl->setVariable('TD_CLASS','calmininext');
311  }
312 
313  $day = $date->get(IL_CAL_FKT_DATE,'j');
314  $month = $date->get(IL_CAL_FKT_DATE,'n');
315 
316  $month_day = $day;
317 
318  $ilCtrl->clearParametersByClass('ilcalendardaygui');
319  $ilCtrl->setParameterByClass('ilcalendardaygui','seed',$date->get(IL_CAL_DATE));
320  $a_tpl->setVariable('OPEN_DAY_VIEW', $ilCtrl->getLinkTargetByClass('ilcalendardaygui',''));
321  $ilCtrl->clearParametersByClass('ilcalendardaygui');
322 
323  $a_tpl->setVariable('MONTH_DAY',$month_day);
324  //$this->tpl->setVariable('NEW_SRC',ilUtil::getImagePath('new.gif','calendar'));
325  //$this->tpl->setVariable('NEW_ALT',$this->lng->txt('cal_new_app'));
326  //$this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
327  //$this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed',$date->get(IL_CAL_DATE));
328  //$this->tpl->setVariable('ADD_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','add'));
329 
330  //$this->tpl->setVariable('OPEN_SRC',ilUtil::getImagePath('open.gif','calendar'));
331  $a_tpl->parseCurrentBlock();
332 
333  if($counter and !($counter % 7))
334  {
335  $a_tpl->setCurrentBlock('month_row');
336  $ilCtrl->clearParametersByClass('ilcalendarweekgui');
337  $ilCtrl->setParameterByClass('ilcalendarweekgui','seed',$date->get(IL_CAL_DATE));
338  $a_tpl->setVariable('OPEN_WEEK_VIEW', $ilCtrl->getLinkTargetByClass('ilcalendarweekgui',''));
339  $ilCtrl->clearParametersByClass('ilcalendarweekgui');
340  $a_tpl->setVariable('TD_CLASS','calminiweek');
341  $a_tpl->setVariable('WEEK',
342  $date->get(IL_CAL_FKT_DATE,'W'));
343  $a_tpl->parseCurrentBlock();
344  }
345  }
346  $a_tpl->setCurrentBlock('mini_month');
347 
348  $a_tpl->setVariable('TXT_MONTH',
349  $lng->txt('month_'.$this->seed->get(IL_CAL_FKT_DATE,'m').'_long').
350  ' '.$this->seed->get(IL_CAL_FKT_DATE,'Y'));
351  $myseed = clone($this->seed);
352  $ilCtrl->setParameterByClass('ilcalendarmonthgui','seed',$myseed->get(IL_CAL_DATE));
353  $a_tpl->setVariable('OPEN_MONTH_VIEW',$ilCtrl->getLinkTargetByClass('ilcalendarmonthgui',''));
354 
355  $myseed->increment(ilDateTime::MONTH, -1);
356  $ilCtrl->setParameter($this,'seed',$myseed->get(IL_CAL_DATE));
357 
358  $a_tpl->setVariable('BL_TYPE', $this->getBlockType());
359  $a_tpl->setVariable('BL_ID', $this->getBlockId());
360 
361  $a_tpl->setVariable('PREV_MONTH',
362  $ilCtrl->getLinkTarget($this, "setSeed"));
363  $a_tpl->setVariable('PREV_MONTH_ASYNC',
364  $ilCtrl->getLinkTarget($this, "setSeed", "", true));
365 
366  $myseed->increment(ilDateTime::MONTH, 2);
367  $ilCtrl->setParameter($this,'seed',$myseed->get(IL_CAL_DATE));
368  $a_tpl->setVariable('NEXT_MONTH',
369  $ilCtrl->getLinkTarget($this, "setSeed"));
370  $a_tpl->setVariable('NEXT_MONTH_ASYNC',
371  $ilCtrl->getLinkTarget($this, "setSeed", "", true));
372 
373  $ilCtrl->setParameter($this, 'seed', "");
374  $a_tpl->parseCurrentBlock();
375  }
376 
380  function getHTML()
381  {
382  global $ilCtrl, $lng, $ilUser;
383 
384  if ($this->getCurrentDetailLevel() == 0)
385  {
386  return "";
387  }
388 
389  // add edit commands
390  if ($this->getEnableEdit())
391  {
392  $ilCtrl->setParameter($this, "add_mode", "block");
393  $this->addBlockCommand(
394  $ilCtrl->getLinkTargetByClass("ilCalendarAppointmentGUI",
395  "add"),
396  $lng->txt("add"));
397  $ilCtrl->setParameter($this, "add_mode", "");
398  }
399 
400  if ($this->getProperty("settings") == true)
401  {
402  $this->addBlockCommand(
403  $ilCtrl->getLinkTarget($this, "editSettings"),
404  $lng->txt("settings"));
405  }
406 
407  $ilCtrl->setParameterByClass("ilcolumngui", "seed", $_GET["seed"]);
408  $ret = parent::getHTML();
409  $ilCtrl->setParameterByClass("ilcolumngui", "seed", "");
410 
411  return $ret;
412  }
413 
417  function fillRow($news)
418  {
419  global $ilUser, $ilCtrl, $lng;
420 
421  }
422 
426  function getOverview()
427  {
428  global $ilUser, $lng, $ilCtrl;
429 
430  include_once('./Services/Calendar/classes/class.ilCalendarSchedule.php');
431  $schedule = new ilCalendarSchedule($this->seed,ilCalendarSchedule::TYPE_INBOX);
432  $events = $schedule->getChangedEvents(true);
433 
434  $link = '<a href='.$ilCtrl->getLinkTargetByClass('ilcalendarinboxgui','').'>';
435  $text = '<div class="small">'.((int) count($events))." ".$lng->txt("cal_changed_events_header")."</div>";
436  $end_link = '</a>';
437 
438  return $link.$text.$end_link;
439  }
440 
441  function addCloseCommand($a_content_block)
442  {
443  global $lng, $ilCtrl;
444 
445  $a_content_block->addHeaderCommand($ilCtrl->getParentReturn($this),
446  $lng->txt("close"), true);
447  }
448 
456  protected function initCategories()
457  {
458  $this->mode = self::CAL_MODE_REPOSITORY;
459  if(!is_object($this->categories))
460  {
461  include_once('./Services/Calendar/classes/class.ilCalendarCategories.php');
462  $this->categories = ilCalendarCategories::_getInstance()->initialize(
464  (int)$_GET['ref_id']);
465  }
466  }
467 
473  protected function setSubTabs()
474  {
475  global $ilTabs;
476 
477  $ilTabs->clearSubTabs();
478  return true;
479 
480  // TODO: needs another switch
481  if($_GET['ref_id'])
482  {
483 
484  $ilTabs->addSubTabTarget('app_day',$this->ctrl->getLinkTargetByClass('ilCalendarDayGUI',''));
485  $ilTabs->addSubTabTarget('app_week',$this->ctrl->getLinkTargetByClass('ilCalendarWeekGUI',''));
486  $ilTabs->addSubTabTarget('app_month',$this->ctrl->getLinkTargetByClass('ilCalendarMonthGUI',''));
487  }
488  return true;
489  }
490 
494  function setSeed()
495  {
496  global $ilCtrl, $ilUser;
497 
498  //$ilUser->writePref("il_pd_bkm_mode", 'flat');
499  $_SESSION["il_cal_block_".$this->getBlockType()."_".$this->getBlockId()."_seed"] =
500  $_GET["seed"];
501  if ($ilCtrl->isAsynch())
502  {
503  echo $this->getHTML();
504  exit;
505  }
506  else
507  {
508  $this->returnToUpperContext();
509  }
510  }
511 
516  {
517  global $ilCtrl;
518 
519  $ilCtrl->returnToParent($this);
520  }
521 }
522 
523 ?>