ILIAS  Release_4_2_x_branch Revision 61807
 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 
41 {
42  public $ctrl = null;
43 
44  static $block_type = "cal";
45  static $st_data;
46 
52  function ilCalendarBlockGUI($a_skip_init = false)
53  {
54  global $ilCtrl, $lng, $ilUser, $tpl;
55 
57 
58  $this->ctrl = $ilCtrl;
59  $this->setImage(ilUtil::getImagePath("icon_cals_s.gif"));
60 
61  $lng->loadLanguageModule("dateplaner");
62  include_once("./Services/News/classes/class.ilNewsItem.php");
63 
64  $ilCtrl->saveParameter($this, 'bkid');
65 
66  if (!$a_skip_init)
67  {
68  $this->initCategories();
69  $this->setBlockId($ilCtrl->getContextObjId());
70  }
71 
72  $this->setLimit(5); // @todo: needed?
73  $this->setAvailableDetailLevels(2);
74  $this->setEnableNumInfo(false);
75 
76  if(!isset($_GET["bkid"]))
77  {
78  $title = $lng->txt("calendar");
79  }
80  else
81  {
82  $title = $lng->txt("cal_consultation_hours_for")." ".ilObjUser::_lookupFullname($_GET["bkid"]);
83  }
84 
85  $this->setTitle($title);
86  //$this->setRowTemplate("tpl.block_calendar.html", "Services/Calendar");
87  //$this->setData($data);
88  $this->allow_moving = false;
89  //$this->handleView();
90 
91  include_once('Services/Calendar/classes/class.ilDate.php');
92  include_once('Services/Calendar/classes/class.ilCalendarUserSettings.php');
93 
94  $seed_str = "";
95  if ((!isset($_GET["seed"]) || $_GET["seed"] == "") &&
96  isset($_SESSION["il_cal_block_".$this->getBlockType()."_".$this->getBlockId()."_seed"]))
97  {
98  $seed_str = $_SESSION["il_cal_block_".$this->getBlockType()."_".$this->getBlockId()."_seed"];
99  }
100  else if (isset($_GET["seed"]))
101  {
102  $seed_str = $_GET["seed"];
103  }
104 
105  if (isset($_GET["seed"]) && $_GET["seed"] != "")
106  {
107  $_SESSION["il_cal_block_".$this->getBlockType()."_".$this->getBlockId()."_seed"]
108  = $_GET["seed"];
109  }
110 
111  if ($seed_str == "")
112  {
113  $this->seed = new ilDate(time(),IL_CAL_UNIX); // @todo: check this
114  }
115  else
116  {
117  $this->seed = new ilDate($seed_str,IL_CAL_DATE); // @todo: check this
118  }
119  $this->user_settings = ilCalendarUserSettings::_getInstanceByUserId($ilUser->getId());
120 
121  $tpl->addCSS("./Services/Calendar/css/calendar.css");
122  // @todo: this must work differently...
123  $tpl->addCSS("./Services/Calendar/templates/default/delos.css");
124  }
125 
131  static function getBlockType()
132  {
133  return self::$block_type;
134  }
135 
141  static function isRepositoryObject()
142  {
143  return false;
144  }
145 
149  static function getScreenMode()
150  {
151  global $ilCtrl;
152 
153  $cmd_class = $ilCtrl->getCmdClass();
154 
155  if ($cmd_class == "ilcalendarappointmentgui" ||
156  $cmd_class == "ilcalendardaygui" ||
157  $cmd_class == "ilcalendarweekgui" ||
158  $cmd_class == "ilcalendarmonthgui" ||
159  $cmd_class == "ilcalendarinboxgui" ||
160  $cmd_class == "ilconsultationhoursgui" ||
161  $_GET['cmd'] == 'showCalendarSubscription')
162  {
163  return IL_SCREEN_CENTER;
164  }
165 
166  switch($ilCtrl->getCmd())
167  {
168  case "kkk":
169  // return IL_SCREEN_CENTER;
170  // return IL_SCREEN_FULL;
171 
172  default:
173  //return IL_SCREEN_SIDE;
174  break;
175  }
176  }
177 
181  function &executeCommand()
182  {
183  global $ilCtrl,$ilTabs;
184 
185  $next_class = $ilCtrl->getNextClass();
186  $cmd = $ilCtrl->getCmd("getHTML");
187 
188  $this->setSubTabs();
189 
190  switch ($next_class)
191  {
192  case "ilcalendarappointmentgui":
193  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentGUI.php');
194  $app_gui = new ilCalendarAppointmentGUI($this->seed,$this->seed);
195  $ilCtrl->forwardCommand($app_gui);
196  break;
197 
198  case "ilcalendardaygui":
199  $ilTabs->setSubTabActive('app_day');
200  include_once('./Services/Calendar/classes/class.ilCalendarDayGUI.php');
201  $day_gui = new ilCalendarDayGUI($this->seed);
202  $ilCtrl->forwardCommand($day_gui);
203  break;
204 
205  case "ilcalendarweekgui":
206  $ilTabs->setSubTabActive('app_week');
207  include_once('./Services/Calendar/classes/class.ilCalendarWeekGUI.php');
208  $week_gui = new ilCalendarWeekGUI($this->seed);
209  $ilCtrl->forwardCommand($week_gui);
210  break;
211 
212  case "ilcalendarmonthgui":
213  $ilTabs->setSubTabActive('app_month');
214  include_once('./Services/Calendar/classes/class.ilCalendarMonthGUI.php');
215  $month_gui = new ilCalendarMonthGUI($this->seed);
216  $ilCtrl->forwardCommand($month_gui);
217  break;
218 
219  case "ilcalendarinboxgui":
220  include_once('./Services/Calendar/classes/class.ilCalendarInboxGUI.php');
221  $inbox = new ilCalendarInboxGUI($this->seed);
222  $ilCtrl->forwardCommand($inbox);
223  break;
224 
225  case "ilconsultationhoursgui":
226  include_once('./Services/Calendar/classes/ConsultationHours/class.ilConsultationHoursGUI.php');
227  $hours = new ilConsultationHoursGUI($this->seed);
228  $ilCtrl->forwardCommand($hours);
229  break;
230 
231  default:
232  return $this->$cmd();
233  }
234  }
235 
241  public function setEnableEdit($a_enable_edit = 0)
242  {
243  $this->enable_edit = $a_enable_edit;
244  }
245 
251  public function getEnableEdit()
252  {
253  return $this->enable_edit;
254  }
255 
259  function fillDataSection()
260  {
261  if ($this->getCurrentDetailLevel() > 1)
262  {
263  $tpl = new ilTemplate("tpl.calendar_block.html", true, true,
264  "Services/Calendar");
265 
266  $this->addMiniMonth($tpl);
267  $this->setDataSection($tpl->get());
268  }
269  else
270  {
271  $this->setDataSection($this->getOverview());
272  }
273  }
274 
279  function addMiniMonth($a_tpl)
280  {
281  global $ilCtrl, $lng,$ilUser;
282 
283  // weekdays
284  include_once('Services/Calendar/classes/class.ilCalendarUtil.php');
285  $a_tpl->setCurrentBlock('month_header_col');
286  $a_tpl->setVariable('TXT_WEEKDAY', $lng->txt("cal_week_abbrev"));
287  $a_tpl->parseCurrentBlock();
288  for($i = (int) $this->user_settings->getWeekStart();$i < (7 + (int) $this->user_settings->getWeekStart());$i++)
289  {
290  $a_tpl->setCurrentBlock('month_header_col');
291  $a_tpl->setVariable('TXT_WEEKDAY',ilCalendarUtil::_numericDayToString($i,false));
292  $a_tpl->parseCurrentBlock();
293  }
294 
295  if(isset($_GET["bkid"]))
296  {
297  $user_id = $_GET["bkid"];
298  $disable_empty = true;
299  }
300  else
301  {
302  $user_id = $ilUser->getId();
303  $disable_empty = false;
304  }
305  include_once('Services/Calendar/classes/class.ilCalendarSchedule.php');
306  $this->scheduler = new ilCalendarSchedule($this->seed,ilCalendarSchedule::TYPE_MONTH,$user_id,$disable_empty);
307  $this->scheduler->addSubitemCalendars(true);
308  $this->scheduler->calculate();
309 
310  $counter = 0;
311  foreach(ilCalendarUtil::_buildMonthDayList($this->seed->get(IL_CAL_FKT_DATE,'m'),
312  $this->seed->get(IL_CAL_FKT_DATE,'Y'),
313  $this->user_settings->getWeekStart())->get() as $date)
314  {
315  $counter++;
316 
317  $events = $this->scheduler->getByDay($date,$ilUser->getTimeZone());
318  $has_events = (bool)count($events);
319  if($has_events || !$disable_empty)
320  {
321  $a_tpl->setCurrentBlock('month_col_link');
322  }
323  else
324  {
325  $a_tpl->setCurrentBlock('month_col_no_link');
326  }
327 
328  if($disable_empty)
329  {
330  if(!$has_events)
331  {
332  $a_tpl->setVariable('DAY_CLASS','calminiinactive');
333  }
334  else
335  {
336  $week_has_events = true;
337  include_once 'Services/Booking/classes/class.ilBookingEntry.php';
338  foreach($events as $event)
339  {
340  $booking = new ilBookingEntry($event['event']->getContextId());
341  if($booking->hasBooked($event['event']->getEntryId()))
342  {
343  $a_tpl->setVariable('DAY_CLASS','calminiapp');
344  break;
345  }
346  }
347  }
348  }
349  elseif($has_events)
350  {
351  $week_has_events = true;
352  $a_tpl->setVariable('DAY_CLASS','calminiapp');
353  }
354 
355 
356  $day = $date->get(IL_CAL_FKT_DATE,'j');
357  $month = $date->get(IL_CAL_FKT_DATE,'n');
358 
359  $month_day = $day;
360 
361  $ilCtrl->clearParametersByClass('ilcalendardaygui');
362  $ilCtrl->setParameterByClass('ilcalendardaygui','seed',$date->get(IL_CAL_DATE));
363  $a_tpl->setVariable('OPEN_DAY_VIEW', $ilCtrl->getLinkTargetByClass('ilcalendardaygui',''));
364  $ilCtrl->clearParametersByClass('ilcalendardaygui');
365 
366  $a_tpl->setVariable('MONTH_DAY',$month_day);
367 
368  $a_tpl->parseCurrentBlock();
369 
370 
371  $a_tpl->setCurrentBlock('month_col');
372 
373  include_once('./Services/Calendar/classes/class.ilCalendarUtil.php');
374  if(ilCalendarUtil::_isToday($date))
375  {
376  $a_tpl->setVariable('TD_CLASS','calminitoday');
377  }
378  #elseif(ilDateTime::_equals($date,$this->seed,IL_CAL_DAY))
379  #{
380  # $a_tpl->setVariable('TD_CLASS','calmininow');
381  #}
382  elseif(ilDateTime::_equals($date,$this->seed,IL_CAL_MONTH))
383  {
384  $a_tpl->setVariable('TD_CLASS','calministd');
385  }
386  elseif(ilDateTime::_before($date,$this->seed,IL_CAL_MONTH))
387  {
388  $a_tpl->setVariable('TD_CLASS','calminiprev');
389  }
390  else
391  {
392  $a_tpl->setVariable('TD_CLASS','calmininext');
393  }
394 
395  $a_tpl->parseCurrentBlock();
396 
397 
398  if($counter and !($counter % 7))
399  {
400  if(!$disable_empty || $week_has_events)
401  {
402  $a_tpl->setCurrentBlock('month_row_link');
403  $ilCtrl->clearParametersByClass('ilcalendarweekgui');
404  $ilCtrl->setParameterByClass('ilcalendarweekgui','seed',$date->get(IL_CAL_DATE));
405  $a_tpl->setVariable('OPEN_WEEK_VIEW', $ilCtrl->getLinkTargetByClass('ilcalendarweekgui',''));
406  $ilCtrl->clearParametersByClass('ilcalendarweekgui');
407  }
408  else
409  {
410  $a_tpl->setCurrentBlock('month_row_no_link');
411  $a_tpl->setVariable('WEEK_CLASS', 'calminiinactive');
412  }
413  $a_tpl->setVariable('WEEK',
414  $date->get(IL_CAL_FKT_DATE,'W'));
415  $a_tpl->parseCurrentBlock();
416 
417  $a_tpl->setCurrentBlock('month_row');
418  $a_tpl->setVariable('TD_CLASS','calminiweek');
419  $a_tpl->parseCurrentBlock();
420 
421  $week_has_events = false;
422  }
423  }
424  $a_tpl->setCurrentBlock('mini_month');
425  $a_tpl->setVariable('TXT_MONTH_OVERVIEW', $lng->txt("cal_month_overview"));
426  $a_tpl->setVariable('TXT_MONTH',
427  $lng->txt('month_'.$this->seed->get(IL_CAL_FKT_DATE,'m').'_long').
428  ' '.$this->seed->get(IL_CAL_FKT_DATE,'Y'));
429  $myseed = clone($this->seed);
430  $ilCtrl->setParameterByClass('ilcalendarmonthgui','seed',$myseed->get(IL_CAL_DATE));
431  $a_tpl->setVariable('OPEN_MONTH_VIEW',$ilCtrl->getLinkTargetByClass('ilcalendarmonthgui',''));
432 
433  $myseed->increment(ilDateTime::MONTH, -1);
434  $ilCtrl->setParameter($this,'seed',$myseed->get(IL_CAL_DATE));
435 
436  $a_tpl->setVariable('BL_TYPE', $this->getBlockType());
437  $a_tpl->setVariable('BL_ID', $this->getBlockId());
438 
439  $a_tpl->setVariable('PREV_MONTH',
440  $ilCtrl->getLinkTarget($this, "setSeed"));
441  $a_tpl->setVariable('PREV_MONTH_ASYNC',
442  $ilCtrl->getLinkTarget($this, "setSeed", "", true));
443 
444  $myseed->increment(ilDateTime::MONTH, 2);
445  $ilCtrl->setParameter($this,'seed',$myseed->get(IL_CAL_DATE));
446  $a_tpl->setVariable('NEXT_MONTH',
447  $ilCtrl->getLinkTarget($this, "setSeed"));
448  $a_tpl->setVariable('NEXT_MONTH_ASYNC',
449  $ilCtrl->getLinkTarget($this, "setSeed", "", true));
450 
451  $ilCtrl->setParameter($this, 'seed', "");
452  $a_tpl->parseCurrentBlock();
453  }
454 
458  function getHTML()
459  {
460  global $ilCtrl, $lng, $ilUser,$ilAccess;
461 
462  if ($this->getCurrentDetailLevel() == 0)
463  {
464  return "";
465  }
466 
467  // add edit commands
468  #if ($this->getEnableEdit())
469 
472  {
473  $this->addBlockCommand(
474  $this->ctrl->getLinkTarget($this,'showCalendarSubscription'),
475  $lng->txt('ical_export'),
476  '',
477  ilUtil::getImagePath('ical.gif','Services/Calendar'),
478  true
479  );
480  }
481 
482 
483  if($this->mode == ilCalendarCategories::MODE_REPOSITORY)
484  {
485  if(!isset($_GET["bkid"]))
486  {
487  if($ilAccess->checkAccess('edit_event','',(int) $_GET['ref_id']))
488  {
489  $ilCtrl->setParameter($this, "add_mode", "block");
490  $this->addBlockCommand(
491  $ilCtrl->getLinkTargetByClass("ilCalendarAppointmentGUI",
492  "add"),
493  $lng->txt("add_appointment"));
494  $ilCtrl->setParameter($this, "add_mode", "");
495  }
496 
497  global $ilObjDataCache;
498 
499  include_once "Modules/Course/classes/class.ilCourseParticipants.php";
500  $obj_id = $ilObjDataCache->lookupObjId((int) $_GET['ref_id']);
501  $participants = ilCourseParticipants::_getInstanceByObjId($obj_id);
502  $users = array_unique(array_merge($participants->getTutors(), $participants->getAdmins()));
503 
504  include_once 'Services/Booking/classes/class.ilBookingEntry.php';
505  $users = ilBookingEntry::isBookable($users, $obj_id);
506  if($users)
507  {
508  foreach($users as $user_id)
509  {
510  if(!isset($_GET["bkid"]) || $_GET["bkid"] != $user_id)
511  {
512  $ilCtrl->setParameter($this, "bkid", $user_id);
513  $this->addBlockCommand(
514  $ilCtrl->getLinkTargetByClass("ilCalendarMonthGUI",
515  ""),
516  "<br/>".$lng->txt("cal_consultation_hours_for").' '.ilObjUser::_lookupFullname($user_id));
517  }
518  }
519  $ilCtrl->setParameter($this, "bkid", "");
520  }
521  }
522  else
523  {
524  $ilCtrl->setParameter($this, "bkid", "");
525  $this->addBlockCommand(
526  $ilCtrl->getLinkTarget($this),
527  $lng->txt("back"));
528  $ilCtrl->setParameter($this, "bkid", (int)$_GET["bkid"]);
529  }
530  }
531 
532  if ($this->getProperty("settings") == true)
533  {
534  $this->addBlockCommand(
535  $ilCtrl->getLinkTarget($this, "editSettings"),
536  $lng->txt("settings"));
537  }
538 
539  $ilCtrl->setParameterByClass("ilcolumngui", "seed", isset($_GET["seed"]) ? $_GET["seed"] : "");
540  $ret = parent::getHTML();
541  $ilCtrl->setParameterByClass("ilcolumngui", "seed", "");
542 
543  return $ret;
544  }
545 
549  function fillRow($news)
550  {
551  global $ilUser, $ilCtrl, $lng;
552 
553  }
554 
558  function getOverview()
559  {
560  global $ilUser, $lng, $ilCtrl;
561 
562  include_once('./Services/Calendar/classes/class.ilCalendarSchedule.php');
563  $schedule = new ilCalendarSchedule($this->seed,ilCalendarSchedule::TYPE_INBOX);
564  $events = $schedule->getChangedEvents(true);
565 
566  $ilCtrl->setParameterByClass('ilcalendarinboxgui', 'changed', 1);
567  $link = '<a href='.$ilCtrl->getLinkTargetByClass('ilcalendarinboxgui','').'>';
568  $ilCtrl->setParameterByClass('ilcalendarinboxgui', 'changed', '');
569  $text = '<div class="small">'.((int) count($events))." ".$lng->txt("cal_changed_events_header")."</div>";
570  $end_link = '</a>';
571 
572  return $link.$text.$end_link;
573  }
574 
575  function addCloseCommand($a_content_block)
576  {
577  global $lng, $ilCtrl;
578 
579  $a_content_block->addHeaderCommand($ilCtrl->getParentReturn($this),
580  $lng->txt("close"), true);
581  }
582 
590  protected function initCategories()
591  {
593 
594  include_once('./Services/Calendar/classes/class.ilCalendarCategories.php');
595 
596  if(!isset($_GET['bkid']))
597  {
599  }
600  else
601  {
603  }
604  }
605 
611  protected function setSubTabs()
612  {
613  global $ilTabs;
614 
615  $ilTabs->clearSubTabs();
616  return true;
617 
618  // TODO: needs another switch
619  if($_GET['ref_id'])
620  {
621 
622  $ilTabs->addSubTabTarget('app_day',$this->ctrl->getLinkTargetByClass('ilCalendarDayGUI',''));
623  $ilTabs->addSubTabTarget('app_week',$this->ctrl->getLinkTargetByClass('ilCalendarWeekGUI',''));
624  $ilTabs->addSubTabTarget('app_month',$this->ctrl->getLinkTargetByClass('ilCalendarMonthGUI',''));
625  }
626  return true;
627  }
628 
632  function setSeed()
633  {
634  global $ilCtrl, $ilUser;
635 
636  //$ilUser->writePref("il_pd_bkm_mode", 'flat');
637  $_SESSION["il_cal_block_".$this->getBlockType()."_".$this->getBlockId()."_seed"] =
638  $_GET["seed"];
639  if ($ilCtrl->isAsynch())
640  {
641  echo $this->getHTML();
642  exit;
643  }
644  else
645  {
646  $this->returnToUpperContext();
647  }
648  }
649 
654  {
655  global $ilCtrl;
656 
657  $ilCtrl->returnToParent($this);
658  }
659 
660 
661  public function showCalendarSubscription()
662  {
663  global $lng, $ilUser;
664 
665  $tpl = new ilTemplate('tpl.show_calendar_subscription.html',true,true,'Services/Calendar');
666 
667  $tpl->setVariable('TXT_TITLE',$lng->txt('cal_subscription_header'));
668  $tpl->setVariable('TXT_INFO',$lng->txt('cal_subscription_info'));
669  $tpl->setVariable('TXT_CAL_URL',$lng->txt('cal_subscription_url'));
670 
671  include_once './Services/Calendar/classes/class.ilCalendarAuthenticationToken.php';
672 
673  switch($this->mode)
674  {
678  $calendar = 0;
679  break;
680 
681  default:
683  // TODO: calendar id
684  $calendar = ilObject::_lookupObjId((int) $_GET['ref_id']);
685  break;
686  }
687  if($hash = ilCalendarAuthenticationToken::lookupAuthToken($ilUser->getId(), $selection, $calendar))
688  {
689 
690  }
691  else
692  {
693  $token = new ilCalendarAuthenticationToken($ilUser->getId());
694  $token->setSelectionType($selection);
695  $token->setCalendar($calendar);
696  $hash = $token->add();
697  }
698  $url = ILIAS_HTTP_PATH.'/calendar.php?client_id='.CLIENT_ID.'&token='.$hash;
699 
700  $tpl->setVariable('VAL_CAL_URL',$url);
701  $tpl->setVariable('VAL_CAL_URL_TXT',$url);
702 
703  include_once("./Services/PersonalDesktop/classes/class.ilPDContentBlockGUI.php");
704  $content_block = new ilPDContentBlockGUI();
705  $content_block->setContent($tpl->get());
706  $content_block->setTitle($lng->txt("calendar"));
707  #$content_block->setImage(ilUtil::getImagePath("icon_news.gif"));
708  $content_block->addHeaderCommand($this->ctrl->getParentReturn($this),
709  $lng->txt("selected_items_back"));
710 
711  return $content_block->getHTML();
712 
713  }
714 }
715 
716 ?>