ILIAS  Release_4_2_x_branch Revision 61807
 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  elseif($ilUser->getId() == ANONYMOUS_USER_ID)
153  {
154  $user_id = $ilUser->getId();
155  $disable_empty = false;
156  $no_add = true;
157  }
158  else
159  {
160  $user_id = $ilUser->getId();
161  $disable_empty = false;
162  $no_add = false;
163  }
164  include_once('Services/Calendar/classes/class.ilCalendarSchedule.php');
165  $this->scheduler = new ilCalendarSchedule($this->seed,ilCalendarSchedule::TYPE_MONTH,$user_id,$disable_empty);
166  $this->scheduler->addSubitemCalendars(true);
167  $this->scheduler->calculate();
168 
169  include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
170  $settings = ilCalendarSettings::_getInstance();
171 
172  $counter = 0;
173  foreach(ilCalendarUtil::_buildMonthDayList($this->seed->get(IL_CAL_FKT_DATE,'m'),
174  $this->seed->get(IL_CAL_FKT_DATE,'Y'),
175  $this->user_settings->getWeekStart())->get() as $date)
176  {
177  $counter++;
178  $has_events = (bool)$this->showEvents($date);
179 
180  if(!$no_add)
181  {
182  if ($settings->getEnableGroupMilestones())
183  {
184  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
185  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed',$this->seed->get(IL_CAL_DATE));
186  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','idate',$date->get(IL_CAL_DATE));
187  $this->tpl->setCurrentBlock("new_ms");
188  $this->tpl->setVariable('H_NEW_MS_SRC',ilUtil::getImagePath('ms_add.gif'));
189  $this->tpl->setVariable('H_NEW_MS_ALT',$this->lng->txt('cal_new_ms'));
190  $this->tpl->setVariable('NEW_MS_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','addMilestone'));
191  $this->tpl->parseCurrentBlock();
192  }
193 
194  $this->tpl->setCurrentBlock("new_app");
195  #$this->tpl->setVariable('NEW_SRC',ilUtil::getImagePath('new.gif','calendar'));
196  $this->tpl->setVariable('NEW_SRC',ilUtil::getImagePath('date_add.gif'));
197  $this->tpl->setVariable('NEW_ALT',$this->lng->txt('cal_new_app'));
198  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
199  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','idate',$date->get(IL_CAL_DATE));
200  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed',$this->seed->get(IL_CAL_DATE));
201  $this->tpl->setVariable('ADD_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','add'));
202  $this->tpl->parseCurrentBlock();
203  }
204 
205 
206  $day = $date->get(IL_CAL_FKT_DATE,'j');
207  $month = $date->get(IL_CAL_FKT_DATE,'n');
208 
209  if($day == 1)
210  {
211  $month_day = '1 '.ilCalendarUtil::_numericMonthToString($month,false);
212  }
213  else
214  {
215  $month_day = $day;
216  }
217 
218  if(!$disable_empty || $has_events)
219  {
220  $this->tpl->setCurrentBlock('month_day_link');
221  $this->ctrl->clearParametersByClass('ilcalendardaygui');
222  $this->ctrl->setParameterByClass('ilcalendardaygui','seed',$date->get(IL_CAL_DATE));
223  $this->tpl->setVariable('OPEN_DAY_VIEW',$this->ctrl->getLinkTargetByClass('ilcalendardaygui',''));
224  $this->ctrl->clearParametersByClass('ilcalendardaygui');
225  }
226  else
227  {
228  $this->tpl->setCurrentBlock('month_day_no_link');
229  }
230 
231  $this->tpl->setVariable('MONTH_DAY',$month_day);
232 
233  $this->tpl->parseCurrentBlock();
234 
235 
236  $this->tpl->setCurrentBlock('month_col');
237 
238  include_once('./Services/Calendar/classes/class.ilCalendarUtil.php');
239  if(ilCalendarUtil::_isToday($date))
240  {
241  $this->tpl->setVariable('TD_CLASS','caltoday');
242  }
243  #elseif(ilDateTime::_equals($date,$this->seed,IL_CAL_DAY))
244  #{
245  # $this->tpl->setVariable('TD_CLASS','calnow');
246  #}
247  elseif(ilDateTime::_equals($date,$this->seed,IL_CAL_MONTH))
248  {
249  $this->tpl->setVariable('TD_CLASS','calstd');
250  }
251  elseif(ilDateTime::_before($date,$this->seed,IL_CAL_MONTH))
252  {
253  $this->tpl->setVariable('TD_CLASS','calprev');
254  }
255  else
256  {
257  $this->tpl->setVariable('TD_CLASS','calnext');
258  }
259 
260  $this->tpl->parseCurrentBlock();
261 
262 
263  if($counter and !($counter % 7))
264  {
265  $this->tpl->setCurrentBlock('month_row');
266  $this->tpl->parseCurrentBlock();
267  }
268  }
269  }
270 
277  protected function showEvents(ilDate $date)
278  {
279  global $tree, $ilUser;
280 
281  $count = 0;
282  foreach($this->scheduler->getByDay($date,$this->timezone) as $item)
283  {
284  // booking
285  $booking_subtitle = false;
286  if($item['category_type'] == ilCalendarCategory::TYPE_CH)
287  {
288  include_once 'Services/Booking/classes/class.ilBookingEntry.php';
289  $entry = new ilBookingEntry($item['event']->getContextId());
290  if($entry)
291  {
292  $booking_subtitle = ' '.$item['event']->getTitle();
293  if($entry->isOwner())
294  {
295  $max = (int)$entry->getNumberOfBookings();
296  $current = (int)$entry->getCurrentNumberOfBookings($item['event']->getEntryId());
297  if($max > 1)
298  {
299  $booking_subtitle .= ' ('.$current.'/'.$max.')';
300  }
301  else if($current == $max)
302  {
303  $booking_subtitle .= ' ('.$this->lng->txt('cal_booked_out').')';
304  }
305  else
306  {
307  $booking_subtitle .= ' ('.$this->lng->txt('cal_book_free').')';
308  }
309  }
310  else if($entry->hasBooked($item['event']->getEntryId()))
311  {
312  $booking_subtitle .= ' ('.$this->lng->txt('cal_date_booked').')';
313  }
314  }
315  }
316 
317  $this->tpl->setCurrentBlock('panel_code');
318  $this->tpl->setVariable('NUM',$this->num_appointments);
319  $this->tpl->parseCurrentBlock();
320 
321  // milestone icon
322  if ($item['event']->isMilestone())
323  {
324  $this->tpl->setCurrentBlock('fullday_ms_icon');
325  $this->tpl->setVariable('ALT_FD_MS', $this->lng->txt("cal_milestone"));
326  $this->tpl->setVariable('SRC_FD_MS', ilUtil::getImagePath("icon_ms_s.gif"));
327  $this->tpl->parseCurrentBlock();
328  }
329 
330  $this->tpl->setCurrentBlock('il_event');
331 
332  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentPanelGUI.php');
333  $this->tpl->setVariable('PANEL_DATA',ilCalendarAppointmentPanelGUI::_getInstance($this->seed)->getHTML($item));
334  $this->tpl->setVariable('PANEL_NUM',$this->num_appointments);
335 
336  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
337  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','app_id',$item['event']->getEntryId());
338  $this->tpl->setVariable('EVENT_EDIT_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','edit'));
339  $this->tpl->setVariable('EVENT_NUM',$item['event']->getEntryId());
340 
341  $compl = ($item['event']->isMilestone() && $item['event']->getCompletion() > 0)
342  ? " (".$item['event']->getCompletion()."%)"
343  : "";
344 
345  if($item['event']->isFullDay())
346  {
347  $title = $item['event']->getPresentationTitle().$compl;
348  }
349  else
350  {
351  switch($this->user_settings->getTimeFormat())
352  {
354  $title = $item['event']->getStart()->get(IL_CAL_FKT_DATE,'H:i',$this->timezone);
355  break;
356 
358  $title = $item['event']->getStart()->get(IL_CAL_FKT_DATE,'h:ia',$this->timezone);
359  break;
360  }
361 
362  if(!$booking_subtitle)
363  {
364  $title .= (' '.$item['event']->getPresentationTitle());
365  }
366  else
367  {
368  $title .= $booking_subtitle;
369  }
370  }
371  $this->tpl->setVariable('EVENT_TITLE',$title);
372  $color = $this->app_colors->getColorByAppointment($item['event']->getEntryId());
373  $this->tpl->setVariable('EVENT_BGCOLOR',$color);
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 ?>