ILIAS  release_4-4 Revision
class.ilCalendarMonthGUI.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.ilDate.php');
25 include_once('Services/Calendar/classes/class.ilCalendarHeaderNavigationGUI.php');
26 include_once('Services/Calendar/classes/class.ilCalendarUserSettings.php');
27 include_once('Services/Calendar/classes/class.ilCalendarAppointmentColors.php');
28 
29 
42 {
43  protected $num_appointments = 1;
44  protected $schedule_filters = array();
45 
46  protected $seed = null;
47  protected $user_settings = null;
48 
49  protected $lng;
50  protected $ctrl;
51  protected $tabs_gui;
52  protected $tpl;
53 
54  protected $timezone = 'UTC';
55 
63  public function __construct(ilDate $seed_date)
64  {
65  global $ilCtrl, $lng, $ilUser,$ilTabs,$tpl;
66 
67  $this->seed = $seed_date;
68 
69  $this->tpl = $tpl;
70  $this->lng = $lng;
71  $this->ctrl = $ilCtrl;
72  $this->tabs_gui = $ilTabs;
73  $this->tabs_gui->setSubTabActive('app_month');
74 
75  $this->user_settings = ilCalendarUserSettings::_getInstanceByUserId($ilUser->getId());
76  $this->app_colors = new ilCalendarAppointmentColors($ilUser->getId());
77 
78  $this->timezone = $ilUser->getTimeZone();
79  }
80 
87  public function executeCommand()
88  {
89  global $ilCtrl,$tpl;
90 
91  $this->ctrl->saveParameter($this,'seed');
92 
93  $next_class = $ilCtrl->getNextClass();
94  switch($next_class)
95  {
96  case 'ilcalendarappointmentgui':
97  $this->ctrl->setReturn($this,'');
98  $this->tabs_gui->setSubTabActive($_SESSION['cal_last_tab']);
99 
100  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentGUI.php');
101 
102  // initial date for new calendar appointments
103  $idate = new ilDate($_REQUEST['idate'], IL_CAL_DATE);
104 
105  $app = new ilCalendarAppointmentGUI($this->seed,$idate,(int) $_GET['app_id']);
106  $this->ctrl->forwardCommand($app);
107  break;
108 
109  default:
110  $time = microtime(true);
111  $cmd = $this->ctrl->getCmd("show");
112  $this->$cmd();
113  $tpl->setContent($this->tpl->get());
114 
115  #echo "Zeit: ".(microtime(true) - $time);
116  break;
117  }
118  return true;
119  }
120 
126  public function addScheduleFilter(ilCalendarScheduleFilter $a_filter)
127  {
128  $this->schedule_filters[] = $a_filter;
129  }
130 
137  public function show()
138  {
139  global $tpl, $ilUser;
140 
141  $this->tpl = new ilTemplate('tpl.month_view.html',true,true,'Services/Calendar');
142 
143  include_once('./Services/YUI/classes/class.ilYuiUtil.php');
146 
147  $navigation = new ilCalendarHeaderNavigationGUI($this,$this->seed,ilDateTime::MONTH);
148  $this->tpl->setVariable('NAVIGATION',$navigation->getHTML());
149 
150  for($i = (int) $this->user_settings->getWeekStart();$i < (7 + (int) $this->user_settings->getWeekStart());$i++)
151  {
152  $this->tpl->setCurrentBlock('month_header_col');
153  $this->tpl->setVariable('TXT_WEEKDAY',ilCalendarUtil::_numericDayToString($i,true));
154  $this->tpl->parseCurrentBlock();
155  }
156 
157  if(isset($_GET["bkid"]))
158  {
159  $user_id = $_GET["bkid"];
160  $disable_empty = true;
161  $no_add = true;
162  }
163  else
164  {
165  if($ilUser->getId() == ANONYMOUS_USER_ID)
166  {
167  $user_id = $ilUser->getId();
168  $disable_empty = false;
169  $no_add = true;
170  }
171  else
172  {
173  $user_id = $ilUser->getId();
174  $disable_empty = false;
175  $no_add = false;
176  }
177  }
178 
179  $is_portfolio_embedded = false;
181  {
182  $no_add = true;
183  $is_portfolio_embedded = true;
184  }
185 
186  include_once('Services/Calendar/classes/class.ilCalendarSchedule.php');
187  $this->scheduler = new ilCalendarSchedule($this->seed,ilCalendarSchedule::TYPE_MONTH,$user_id);
188  $this->scheduler->addSubitemCalendars(true);
189  if(sizeof($this->schedule_filters))
190  {
191  foreach($this->schedule_filters as $filter)
192  {
193  $this->scheduler->addFilter($filter);
194  }
195  }
196  $this->scheduler->calculate();
197 
198  include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
199  $settings = ilCalendarSettings::_getInstance();
200 
201  $counter = 0;
202  foreach(ilCalendarUtil::_buildMonthDayList($this->seed->get(IL_CAL_FKT_DATE,'m'),
203  $this->seed->get(IL_CAL_FKT_DATE,'Y'),
204  $this->user_settings->getWeekStart())->get() as $date)
205  {
206  $counter++;
207  $has_events = (bool)$this->showEvents($date);
208 
209  if(!$no_add)
210  {
211  if ($settings->getEnableGroupMilestones())
212  {
213  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
214  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed',$this->seed->get(IL_CAL_DATE));
215  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','idate',$date->get(IL_CAL_DATE));
216  $this->tpl->setCurrentBlock("new_ms");
217  $this->tpl->setVariable('H_NEW_MS_SRC',ilUtil::getImagePath('ms_add.png'));
218  $this->tpl->setVariable('H_NEW_MS_ALT',$this->lng->txt('cal_new_ms'));
219  $this->tpl->setVariable('NEW_MS_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','addMilestone'));
220  $this->tpl->parseCurrentBlock();
221  }
222 
223  $this->tpl->setCurrentBlock("new_app");
224  #$this->tpl->setVariable('NEW_SRC',ilUtil::getImagePath('new.png','calendar'));
225  $this->tpl->setVariable('NEW_SRC',ilUtil::getImagePath('date_add.png'));
226  $this->tpl->setVariable('NEW_ALT',$this->lng->txt('cal_new_app'));
227  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
228  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','idate',$date->get(IL_CAL_DATE));
229  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed',$this->seed->get(IL_CAL_DATE));
230  $this->tpl->setVariable('ADD_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','add'));
231  $this->tpl->parseCurrentBlock();
232  }
233 
234 
235  $day = $date->get(IL_CAL_FKT_DATE,'j');
236  $month = $date->get(IL_CAL_FKT_DATE,'n');
237 
238  if($day == 1)
239  {
240  $month_day = '1 '.ilCalendarUtil::_numericMonthToString($month,false);
241  }
242  else
243  {
244  $month_day = $day;
245  }
246 
247  if(!$is_portfolio_embedded &&
248  (!$disable_empty || $has_events))
249  {
250  $this->tpl->setCurrentBlock('month_day_link');
251  $this->ctrl->clearParametersByClass('ilcalendardaygui');
252  $this->ctrl->setParameterByClass('ilcalendardaygui','seed',$date->get(IL_CAL_DATE));
253  $this->tpl->setVariable('OPEN_DAY_VIEW',$this->ctrl->getLinkTargetByClass('ilcalendardaygui',''));
254  $this->ctrl->clearParametersByClass('ilcalendardaygui');
255  }
256  else
257  {
258  $this->tpl->setCurrentBlock('month_day_no_link');
259  }
260 
261  $this->tpl->setVariable('MONTH_DAY',$month_day);
262 
263  $this->tpl->parseCurrentBlock();
264 
265 
266  $this->tpl->setCurrentBlock('month_col');
267 
268  include_once('./Services/Calendar/classes/class.ilCalendarUtil.php');
269  if(ilCalendarUtil::_isToday($date))
270  {
271  $this->tpl->setVariable('TD_CLASS','caltoday');
272  }
273  #elseif(ilDateTime::_equals($date,$this->seed,IL_CAL_DAY))
274  #{
275  # $this->tpl->setVariable('TD_CLASS','calnow');
276  #}
277  elseif(ilDateTime::_equals($date,$this->seed,IL_CAL_MONTH))
278  {
279  $this->tpl->setVariable('TD_CLASS','calstd');
280  }
281  elseif(ilDateTime::_before($date,$this->seed,IL_CAL_MONTH))
282  {
283  $this->tpl->setVariable('TD_CLASS','calprev');
284  }
285  else
286  {
287  $this->tpl->setVariable('TD_CLASS','calnext');
288  }
289 
290  $this->tpl->parseCurrentBlock();
291 
292 
293  if($counter and !($counter % 7))
294  {
295  $this->tpl->setCurrentBlock('month_row');
296  $this->tpl->parseCurrentBlock();
297  }
298  }
299  }
300 
301  // used in portfolio
302  function getHTML()
303  {
304  $this->show();
305  return $this->tpl->get();
306  }
307 
314  protected function showEvents(ilDate $date)
315  {
316  global $tree, $ilUser;
317 
318  $count = 0;
319 
320 
321  foreach($this->scheduler->getByDay($date,$this->timezone) as $item)
322  {
323  $this->tpl->setCurrentBlock('panel_code');
324  $this->tpl->setVariable('NUM',$this->num_appointments);
325  $this->tpl->parseCurrentBlock();
326 
327  // milestone icon
328  if ($item['event']->isMilestone())
329  {
330  $this->tpl->setCurrentBlock('fullday_ms_icon');
331  $this->tpl->setVariable('ALT_FD_MS', $this->lng->txt("cal_milestone"));
332  $this->tpl->setVariable('SRC_FD_MS', ilUtil::getImagePath("icon_ms_s.png"));
333  $this->tpl->parseCurrentBlock();
334  }
335 
336  $this->tpl->setCurrentBlock('il_event');
337 
338  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentPanelGUI.php');
339  $this->tpl->setVariable('PANEL_DATA',ilCalendarAppointmentPanelGUI::_getInstance($this->seed)->getHTML($item));
340  $this->tpl->setVariable('PANEL_NUM',$this->num_appointments);
341 
342  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
343  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','app_id',$item['event']->getEntryId());
344  $this->tpl->setVariable('EVENT_EDIT_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','edit'));
345  $this->tpl->setVariable('EVENT_NUM',$item['event']->getEntryId());
346 
347  $compl = ($item['event']->isMilestone() && $item['event']->getCompletion() > 0)
348  ? " (".$item['event']->getCompletion()."%)"
349  : "";
350 
351  if($item['event']->isFullDay())
352  {
353  $title = $item['event']->getPresentationTitle().$compl;
354  }
355  else
356  {
357  switch($this->user_settings->getTimeFormat())
358  {
360  $title = $item['event']->getStart()->get(IL_CAL_FKT_DATE,'H:i',$this->timezone);
361  break;
362 
364  $title = $item['event']->getStart()->get(IL_CAL_FKT_DATE,'h:ia',$this->timezone);
365  break;
366  }
367 
368  $title .= (' '.$item['event']->getPresentationTitle());
369  }
370  $this->tpl->setVariable('EVENT_TITLE',$title);
371  $color = $this->app_colors->getColorByAppointment($item['event']->getEntryId());
372  $this->tpl->setVariable('EVENT_BGCOLOR',$color);
373  $this->tpl->setVariable('EVENT_ADD_STYLES',$item['event']->getPresentationStyle());
374  $this->tpl->setVariable('EVENT_FONTCOLOR',ilCalendarUtil::calculateFontColor($color));
375 
376  $this->tpl->parseCurrentBlock();
377 
378  $this->num_appointments++;
379  $count++;
380  }
381  return $count;
382  }
383 
384 }
385 
386 
387 ?>
< a tabindex="-1" style="border-style: none;" href="#" title="Refresh Image" onclick="document.getElementById('siimage').src = './securimage_show.php?sid=' + Math.random(); this.blur(); return false">< img src="./images/refresh.png" alt="Reload Image" height="32" width="32" onclick="this.blur()" align="bottom" border="0"/></a >< br/>< strong > Enter Code *if($_SERVER['REQUEST_METHOD']=='POST' &&@ $_POST['do']=='contact') $_SESSION['ctform']['success']
static _buildMonthDayList($a_month, $a_year, $weekstart)
Build a month day list.
showEvents(ilDate $date)
Show events.
static _getInstance()
get singleton instance
static _numericDayToString($a_day, $a_long=true)
get
$_GET["client_id"]
static _getInstanceByUserId($a_user_id)
get singleton instance
static _before(ilDateTime $start, ilDateTime $end, $a_compare_field='', $a_tz='')
compare two dates and check start is before end This method does not consider tz offsets.
$cmd
Definition: sahs_server.php:35
const IL_CAL_MONTH
addScheduleFilter(ilCalendarScheduleFilter $a_filter)
Add schedule filter.
global $ilCtrl
Definition: ilias.php:18
static _equals(ilDateTime $start, ilDateTime $end, $a_compare_field='', $a_tz='')
Check if two date are equal.
Calendar schedule filter interface.
Class for single dates.
__construct(ilDate $seed_date)
Constructor.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
special template class to simplify handling of ITX/PEAR
const IL_CAL_FKT_DATE
static calculateFontColor($a_html_color_code)
Calculate best font color from html hex color code.
static _getInstance($a_usr_id=0)
get singleton instance
static initPanel($a_resize=false)
Init yui panel.
const IL_CAL_DATE
global $ilUser
Definition: imgupload.php:15
Administrate calendar appointments.
static initDragDrop()
Init YUI Drag and Drop.
static _getInstance(ilDate $seed)
get singleton instance
if($_REQUEST['ilias_path']) define('ILIAS_HTTP_PATH' $_REQUEST['ilias_path']
Definition: index.php:7
static _isToday($date)
check if a date is today
Represents a list of calendar appointments (including recurring events) for a specific user in a give...
executeCommand()
Execute command.