ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
45  protected $seed = null;
46  protected $user_settings = null;
47 
48  protected $lng;
49  protected $ctrl;
50  protected $tabs_gui;
51  protected $tpl;
52 
53  protected $timezone = 'UTC';
54 
62  public function __construct(ilDate $seed_date)
63  {
64  global $ilCtrl, $lng, $ilUser,$ilTabs,$tpl;
65 
66  $this->seed = $seed_date;
67 
68  $this->tpl = $tpl;
69  $this->lng = $lng;
70  $this->ctrl = $ilCtrl;
71  $this->tabs_gui = $ilTabs;
72  $this->tabs_gui->setSubTabActive('app_month');
73 
74  $this->user_settings = ilCalendarUserSettings::_getInstanceByUserId($ilUser->getId());
75  $this->app_colors = new ilCalendarAppointmentColors($ilUser->getId());
76 
77  $this->timezone = $ilUser->getTimeZone();
78  }
79 
86  public function executeCommand()
87  {
88  global $ilCtrl,$tpl;
89 
90  $this->ctrl->saveParameter($this,'seed');
91 
92  $next_class = $ilCtrl->getNextClass();
93  switch($next_class)
94  {
95  case 'ilcalendarappointmentgui':
96  $this->ctrl->setReturn($this,'');
97  $this->tabs_gui->setSubTabActive($_SESSION['cal_last_tab']);
98 
99  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentGUI.php');
100 
101  // initial date for new calendar appointments
102  $idate = new ilDate($_REQUEST['idate'], IL_CAL_DATE);
103 
104  $app = new ilCalendarAppointmentGUI($this->seed,$idate,(int) $_GET['app_id']);
105  $this->ctrl->forwardCommand($app);
106  break;
107 
108  default:
109  $time = microtime(true);
110  $cmd = $this->ctrl->getCmd("show");
111  $this->$cmd();
112  $tpl->setContent($this->tpl->get());
113 
114  #echo "Zeit: ".(microtime(true) - $time);
115  break;
116  }
117  return true;
118  }
119 
126  public function show()
127  {
128  global $tpl, $ilUser;
129 
130  $this->tpl = new ilTemplate('tpl.month_view.html',true,true,'Services/Calendar');
131 
132  include_once('./Services/YUI/classes/class.ilYuiUtil.php');
135 
136  $navigation = new ilCalendarHeaderNavigationGUI($this,$this->seed,ilDateTime::MONTH);
137  $this->tpl->setVariable('NAVIGATION',$navigation->getHTML());
138 
139  for($i = (int) $this->user_settings->getWeekStart();$i < (7 + (int) $this->user_settings->getWeekStart());$i++)
140  {
141  $this->tpl->setCurrentBlock('month_header_col');
142  $this->tpl->setVariable('TXT_WEEKDAY',ilCalendarUtil::_numericDayToString($i,true));
143  $this->tpl->parseCurrentBlock();
144  }
145 
146  if(isset($_GET["bkid"]))
147  {
148  $user_id = $_GET["bkid"];
149  $disable_empty = true;
150  $no_add = true;
151  }
152  else
153  {
154  $user_id = $ilUser->getId();
155  $disable_empty = false;
156  $no_add = false;
157  }
158  include_once('Services/Calendar/classes/class.ilCalendarSchedule.php');
159  $this->scheduler = new ilCalendarSchedule($this->seed,ilCalendarSchedule::TYPE_MONTH,$user_id,$disable_empty);
160  $this->scheduler->addSubitemCalendars(true);
161  $this->scheduler->calculate();
162 
163  include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
164  $settings = ilCalendarSettings::_getInstance();
165 
166  $counter = 0;
167  foreach(ilCalendarUtil::_buildMonthDayList($this->seed->get(IL_CAL_FKT_DATE,'m'),
168  $this->seed->get(IL_CAL_FKT_DATE,'Y'),
169  $this->user_settings->getWeekStart())->get() as $date)
170  {
171  $counter++;
172  $has_events = (bool)$this->showEvents($date);
173 
174  if(!$no_add)
175  {
176  if ($settings->getEnableGroupMilestones())
177  {
178  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
179  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed',$this->seed->get(IL_CAL_DATE));
180  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','idate',$date->get(IL_CAL_DATE));
181  $this->tpl->setCurrentBlock("new_ms");
182  $this->tpl->setVariable('H_NEW_MS_SRC',ilUtil::getImagePath('ms_add.gif'));
183  $this->tpl->setVariable('H_NEW_MS_ALT',$this->lng->txt('cal_new_ms'));
184  $this->tpl->setVariable('NEW_MS_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','addMilestone'));
185  $this->tpl->parseCurrentBlock();
186  }
187 
188  $this->tpl->setCurrentBlock("new_app");
189  #$this->tpl->setVariable('NEW_SRC',ilUtil::getImagePath('new.gif','calendar'));
190  $this->tpl->setVariable('NEW_SRC',ilUtil::getImagePath('date_add.gif'));
191  $this->tpl->setVariable('NEW_ALT',$this->lng->txt('cal_new_app'));
192  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
193  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','idate',$date->get(IL_CAL_DATE));
194  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed',$this->seed->get(IL_CAL_DATE));
195  $this->tpl->setVariable('ADD_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','add'));
196  $this->tpl->parseCurrentBlock();
197  }
198 
199 
200  $day = $date->get(IL_CAL_FKT_DATE,'j');
201  $month = $date->get(IL_CAL_FKT_DATE,'n');
202 
203  if($day == 1)
204  {
205  $month_day = '1 '.ilCalendarUtil::_numericMonthToString($month,false);
206  }
207  else
208  {
209  $month_day = $day;
210  }
211 
212  if(!$disable_empty || $has_events)
213  {
214  $this->tpl->setCurrentBlock('month_day_link');
215  $this->ctrl->clearParametersByClass('ilcalendardaygui');
216  $this->ctrl->setParameterByClass('ilcalendardaygui','seed',$date->get(IL_CAL_DATE));
217  $this->tpl->setVariable('OPEN_DAY_VIEW',$this->ctrl->getLinkTargetByClass('ilcalendardaygui',''));
218  $this->ctrl->clearParametersByClass('ilcalendardaygui');
219  }
220  else
221  {
222  $this->tpl->setCurrentBlock('month_day_no_link');
223  }
224 
225  $this->tpl->setVariable('MONTH_DAY',$month_day);
226 
227  $this->tpl->parseCurrentBlock();
228 
229 
230  $this->tpl->setCurrentBlock('month_col');
231 
232  include_once('./Services/Calendar/classes/class.ilCalendarUtil.php');
233  if(ilCalendarUtil::_isToday($date))
234  {
235  $this->tpl->setVariable('TD_CLASS','caltoday');
236  }
237  #elseif(ilDateTime::_equals($date,$this->seed,IL_CAL_DAY))
238  #{
239  # $this->tpl->setVariable('TD_CLASS','calnow');
240  #}
241  elseif(ilDateTime::_equals($date,$this->seed,IL_CAL_MONTH))
242  {
243  $this->tpl->setVariable('TD_CLASS','calstd');
244  }
245  elseif(ilDateTime::_before($date,$this->seed,IL_CAL_MONTH))
246  {
247  $this->tpl->setVariable('TD_CLASS','calprev');
248  }
249  else
250  {
251  $this->tpl->setVariable('TD_CLASS','calnext');
252  }
253 
254  $this->tpl->parseCurrentBlock();
255 
256 
257  if($counter and !($counter % 7))
258  {
259  $this->tpl->setCurrentBlock('month_row');
260  $this->tpl->parseCurrentBlock();
261  }
262  }
263  }
264 
271  protected function showEvents(ilDate $date)
272  {
273  global $tree, $ilUser;
274 
275  $count = 0;
276  foreach($this->scheduler->getByDay($date,$this->timezone) as $item)
277  {
278  // booking
279  $booking_subtitle = false;
280  if($item['category_type'] == ilCalendarCategory::TYPE_CH)
281  {
282  include_once 'Services/Booking/classes/class.ilBookingEntry.php';
283  $entry = new ilBookingEntry($item['event']->getContextId());
284  if($entry)
285  {
286  $booking_subtitle = ' '.$item['event']->getTitle();
287  if($entry->isOwner())
288  {
289  $max = (int)$entry->getNumberOfBookings();
290  $current = (int)$entry->getCurrentNumberOfBookings($item['event']->getEntryId());
291  if($max > 1)
292  {
293  $booking_subtitle .= ' ('.$current.'/'.$max.')';
294  }
295  else if($current == $max)
296  {
297  $booking_subtitle .= ' ('.$this->lng->txt('cal_booked_out').')';
298  }
299  else
300  {
301  $booking_subtitle .= ' ('.$this->lng->txt('cal_book_free').')';
302  }
303  }
304  else if($entry->hasBooked($item['event']->getEntryId()))
305  {
306  $booking_subtitle .= ' ('.$this->lng->txt('cal_date_booked').')';
307  }
308  }
309  }
310 
311  $this->tpl->setCurrentBlock('panel_code');
312  $this->tpl->setVariable('NUM',$this->num_appointments);
313  $this->tpl->parseCurrentBlock();
314 
315  // milestone icon
316  if ($item['event']->isMilestone())
317  {
318  $this->tpl->setCurrentBlock('fullday_ms_icon');
319  $this->tpl->setVariable('ALT_FD_MS', $this->lng->txt("cal_milestone"));
320  $this->tpl->setVariable('SRC_FD_MS', ilUtil::getImagePath("icon_ms_s.gif"));
321  $this->tpl->parseCurrentBlock();
322  }
323 
324  $this->tpl->setCurrentBlock('il_event');
325 
326  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentPanelGUI.php');
327  $this->tpl->setVariable('PANEL_DATA',ilCalendarAppointmentPanelGUI::_getInstance($this->seed)->getHTML($item));
328  $this->tpl->setVariable('PANEL_NUM',$this->num_appointments);
329 
330  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
331  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','app_id',$item['event']->getEntryId());
332  $this->tpl->setVariable('EVENT_EDIT_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','edit'));
333  $this->tpl->setVariable('EVENT_NUM',$item['event']->getEntryId());
334 
335  $compl = ($item['event']->isMilestone() && $item['event']->getCompletion() > 0)
336  ? " (".$item['event']->getCompletion()."%)"
337  : "";
338 
339  if($item['event']->isFullDay())
340  {
341  $title = $item['event']->getPresentationTitle().$compl;
342  }
343  else
344  {
345  switch($this->user_settings->getTimeFormat())
346  {
348  $title = $item['event']->getStart()->get(IL_CAL_FKT_DATE,'H:i',$this->timezone);
349  break;
350 
352  $title = $item['event']->getStart()->get(IL_CAL_FKT_DATE,'h:ia',$this->timezone);
353  break;
354  }
355 
356  if(!$booking_subtitle)
357  {
358  $title .= (' '.$item['event']->getPresentationTitle());
359  }
360  else
361  {
362  $title .= $booking_subtitle;
363  }
364  }
365  $this->tpl->setVariable('EVENT_TITLE',$title);
366  $color = $this->app_colors->getColorByAppointment($item['event']->getEntryId());
367  $this->tpl->setVariable('EVENT_BGCOLOR',$color);
368  $this->tpl->setVariable('EVENT_FONTCOLOR',ilCalendarUtil::calculateFontColor($color));
369 
370  $this->tpl->parseCurrentBlock();
371 
372  $this->num_appointments++;
373  $count++;
374  }
375  return $count;
376  }
377 
378 }
379 
380 
381 ?>