ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilCalendarAppointmentPanelGUI.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
24include_once './Services/Calendar/classes/class.ilCalendarSettings.php';
25
35{
36 protected $seed = null;
37
38 protected static $counter = 0;
39 protected static $instance = null;
40
41 protected $settings = null;
42
43 protected $tpl = null;
44 protected $lng = null;
45 protected $ctrl = null;
46
54 protected function __construct(ilDate $seed = null)
55 {
56 global $lng,$ilCtrl;
57
58 $this->lng = $lng;
59 $this->ctrl = $ilCtrl;
61
62 $this->seed = $seed;
63 }
64
73 public static function _getInstance(ilDate $seed)
74 {
75 if (isset(self::$instance) and self::$instance) {
76 return self::$instance;
77 }
78 return self::$instance = new ilCalendarAppointmentPanelGUI($seed);
79 }
80
84 public function getSeed()
85 {
86 return $this->seed;
87 }
88
89
97 public function getHTML($a_app)
98 {
99 global $tree,$lng,$ilUser;
100
102
103 $this->tpl = new ilTemplate('tpl.appointment_panel.html', true, true, 'Services/Calendar');
104
105 // Panel variables
106 $this->tpl->setVariable('PANEL_NUM', self::$counter);
107 $this->tpl->setVariable('PANEL_TITLE', str_replace(' ()', '', $a_app['event']->getPresentationTitle(false)));
108 if ($a_app["event"]->isMilestone()) {
109 $this->tpl->setVariable('PANEL_DETAILS', $this->lng->txt('cal_ms_details'));
110 } else {
111 $this->tpl->setVariable('PANEL_DETAILS', $this->lng->txt('cal_details'));
112 }
113 $this->tpl->setVariable('PANEL_TXT_DATE', $this->lng->txt('date'));
114
115 if ($a_app['fullday']) {
116 $this->tpl->setVariable('PANEL_DATE', ilDatePresentation::formatPeriod(
117 new ilDate($a_app['dstart'], IL_CAL_UNIX),
118 new ilDate($a_app['dend'], IL_CAL_UNIX)
119 ));
120 } else {
121 $this->tpl->setVariable('PANEL_DATE', ilDatePresentation::formatPeriod(
122 new ilDateTime($a_app['dstart'], IL_CAL_UNIX),
123 new ilDateTime($a_app['dend'], IL_CAL_UNIX)
124 ));
125 }
126 if ($a_app['event']->getLocation()) {
127 $this->tpl->setVariable('PANEL_TXT_WHERE', $this->lng->txt('cal_where'));
128 $this->tpl->setVariable('PANEL_WHERE', ilUtil::makeClickable($a_app['event']->getLocation()), true);
129 }
130 if ($a_app['event']->getDescription()) {
131 $this->tpl->setVariable('PANEL_TXT_DESC', $this->lng->txt('description'));
132 $this->tpl->setVariable('PANEL_DESC', ilUtil::makeClickable(nl2br($a_app['event']->getDescription())));
133 }
134
135 if ($a_app['event']->isMilestone() && $a_app['event']->getCompletion() > 0) {
136 $this->tpl->setVariable('PANEL_TXT_COMPL', $this->lng->txt('cal_task_completion'));
137 $this->tpl->setVariable('PANEL_COMPL', $a_app['event']->getCompletion() . " %");
138 }
139
140 if ($a_app['event']->isMilestone()) {
141 // users responsible
142 $users = $a_app['event']->readResponsibleUsers();
143 $delim = "";
144 foreach ($users as $r) {
145 $value.= $delim . $r["lastname"] . ", " . $r["firstname"] . " [" . $r["login"] . "]";
146 $delim = "<br />";
147 }
148 if (count($users) > 0) {
149 $this->tpl->setVariable('PANEL_TXT_RESP', $this->lng->txt('cal_responsible'));
150 $this->tpl->setVariable('PANEL_RESP', $value);
151 }
152 }
153
154 include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
155 $cat_id = ilCalendarCategoryAssignments::_lookupCategory($a_app['event']->getEntryId());
156 $cat_info = ilCalendarCategories::_getInstance()->getCategoryInfo($cat_id);
157 $entry_obj_id = isset($cat_info['subitem_obj_ids'][$cat_id]) ?
158 $cat_info['subitem_obj_ids'][$cat_id] :
159 $cat_info['obj_id'];
160
161 $this->tpl->setVariable('PANEL_TXT_CAL_TYPE', $this->lng->txt('cal_cal_type'));
162 switch ($cat_info['type']) {
164 $this->tpl->setVariable('PANEL_CAL_TYPE', $this->lng->txt('cal_type_system'));
165 break;
166
168 $this->tpl->setVariable('PANEL_CAL_TYPE', $this->lng->txt('cal_type_personal'));
169 break;
170
172 $type = ilObject::_lookupType($cat_info['obj_id']);
173 $this->tpl->setVariable('PANEL_CAL_TYPE', $this->lng->txt('cal_type_' . $type));
174
175 // Course group appointment registration
176 if ($this->settings->isCGRegistrationEnabled() and $type == 'crs' or $type == 'grp') {
177 if (!$a_app['event']->isAutoGenerated()) {
178 include_once './Services/Calendar/classes/class.ilCalendarRegistration.php';
179 $reg = new ilCalendarRegistration($a_app['event']->getEntryId());
180
181 if ($reg->isRegistered($ilUser->getId(), new ilDateTime($a_app['dstart'], IL_CAL_UNIX), new ilDateTime($a_app['dend'], IL_CAL_UNIX))) {
182 $this->tpl->setCurrentBlock('panel_cancel_book_link');
183 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'seed', $this->getSeed()->get(IL_CAL_DATE));
184 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $a_app['event']->getEntryId());
185 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'dstart', $a_app['dstart']);
186 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'dend', $a_app['dend']);
187
188 $this->tpl->setVariable('TXT_PANEL_CANCELBOOK', $this->lng->txt('cal_reg_unregister'));
189 $this->tpl->setVariable('PANEL_CANCELBOOK_HREF', $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'confirmUnregister'));
190 $this->tpl->parseCurrentBlock();
191 } else {
192 $this->tpl->setCurrentBlock('panel_book_link');
193 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'seed', $this->getSeed()->get(IL_CAL_DATE));
194 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $a_app['event']->getEntryId());
195 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'dstart', $a_app['dstart']);
196 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'dend', $a_app['dend']);
197 $this->tpl->setVariable('TXT_PANEL_BOOK', $this->lng->txt('cal_reg_register'));
198 $this->tpl->setVariable('PANEL_BOOK_HREF', $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'confirmRegister'));
199 $this->tpl->parseCurrentBlock();
200 }
201
202 include_once './Services/Link/classes/class.ilLink.php';
203 $registrations = array();
204 foreach ($reg->getRegisteredUsers(new ilDateTime($a_app['dstart'], IL_CAL_UNIX), new ilDateTime($a_app['dend'], IL_CAL_UNIX)) as $usr_data) {
205 $usr_id = $usr_data['usr_id'];
206 $this->ctrl->setParameterByClass('ilconsultationhoursgui', 'user', $usr_id);
207 $registrations[] = '<a href="' . $this->ctrl->getLinkTargetByClass('ilconsultationhoursgui', 'showprofile') . '">' . ilObjUser::_lookupFullname($usr_id);
208 $this->ctrl->setParameterByClass('ilconsultationhoursgui', 'user', '');
209 }
210 if (count($registrations)) {
211 $this->tpl->setCurrentBlock('panel_current_booking');
212 $this->tpl->setVariable('PANEL_TXT_CURRENT_BOOKING', $this->lng->txt('cal_reg_registered_users'));
213 $this->tpl->setVariable('PANEL_CURRENT_BOOKING', implode('<br />', $registrations));
214 $this->tpl->parseCurrentBlock();
215 }
216 }
217 }
218 break;
219
221 $this->tpl->setVariable('PANEL_CAL_TYPE', $this->lng->txt('cal_ch_ch'));
222
223 include_once 'Services/Booking/classes/class.ilBookingEntry.php';
224 $entry = new ilBookingEntry($a_app['event']->getContextId());
225
226 $is_owner = $entry->isOwner();
227 $user_entry = ($cat_info['obj_id'] == $ilUser->getId());
228
229 if ($user_entry && !$is_owner) {
230 // find source calendar entry in owner calendar
231 include_once 'Services/Calendar/classes/ConsultationHours/class.ilConsultationHourAppointments.php';
232 $apps = ilConsultationHourAppointments::getAppointmentIds($entry->getObjId(), $a_app['event']->getContextId(), $a_app['event']->getStart());
233 $ref_event = $apps[0];
234 } else {
235 $ref_event = $a_app['event']->getEntryId();
236 }
237
238 $this->tpl->setCurrentBlock('panel_booking_owner');
239 $this->tpl->setVariable('PANEL_TXT_BOOKING_OWNER', $this->lng->txt('cal_ch_booking_owner'));
240 $this->tpl->setVariable('PANEL_BOOKING_OWNER', ilObjUser::_lookupFullname($entry->getObjId()));
241 $this->tpl->parseCurrentBlock();
242
243 $this->tpl->setCurrentBlock('panel_max_booking');
244 $this->tpl->setVariable('PANEL_TXT_MAX_BOOKING', $this->lng->txt('cal_ch_num_bookings'));
245 $this->tpl->setVariable('PANEL_MAX_BOOKING', $entry->getNumberOfBookings());
246 $this->tpl->parseCurrentBlock();
247
248 if (!$is_owner) {
249 if ($entry->hasBooked($ref_event)) {
250 if (ilDateTime::_after($a_app['event']->getStart(), new ilDateTime(time(), IL_CAL_UNIX))) {
251 $this->tpl->setCurrentBlock('panel_cancel_book_link');
252 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $ref_event);
253 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'seed', $this->getSeed()->get(IL_CAL_DATE));
254 $this->tpl->setVariable('TXT_PANEL_CANCELBOOK', $this->lng->txt('cal_ch_cancel_booking'));
255 $this->tpl->setVariable('PANEL_CANCELBOOK_HREF', $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'cancelBooking'));
256 $this->tpl->parseCurrentBlock();
257 }
258 }
259 #else if(!$entry->isBookedOut($ref_event))
260 elseif ($entry->isAppointmentBookableForUser($ref_event, $GLOBALS['ilUser']->getId())) {
261 $this->tpl->setCurrentBlock('panel_book_link');
262 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $ref_event);
263 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'seed', $this->getSeed()->get(IL_CAL_DATE));
264 $this->tpl->setVariable('TXT_PANEL_BOOK', $this->lng->txt('cal_ch_book'));
265 $this->tpl->setVariable('PANEL_BOOK_HREF', $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'book'));
266 $this->tpl->parseCurrentBlock();
267 }
268
269 $this->tpl->setCurrentBlock('panel_current_booking');
270 $this->tpl->setVariable('PANEL_TXT_CURRENT_BOOKING', $this->lng->txt('cal_ch_current_bookings'));
271 $this->tpl->setVariable('PANEL_CURRENT_BOOKING', $entry->getCurrentNumberOfBookings($ref_event));
272 $this->tpl->parseCurrentBlock();
273 } else {
274 $obj_ids = $entry->getTargetObjIds();
275 foreach ($obj_ids as $obj_id) {
277 $refs = ilObject::_getAllReferences($obj_id);
278 include_once './Services/Link/classes/class.ilLink.php';
279 $this->tpl->setCurrentBlock('panel_booking_target_row');
280 $this->tpl->setVariable('PANEL_BOOKING_TARGET_TITLE', $title);
281 $this->tpl->setVariable('PANEL_BOOKING_TARGET', ilLink::_getLink(end($refs)));
282 $this->tpl->parseCurrentBlock();
283 }
284 if ($obj_ids) {
285 $this->tpl->setCurrentBlock('panel_booking_target');
286 $this->tpl->setVariable('PANEL_TXT_BOOKING_TARGET', $this->lng->txt('cal_ch_target_object'));
287 $this->tpl->parseCurrentBlock();
288 }
289
290 $link_users = true;
292 $link_users = false;
293 }
294
295 include_once './Services/Link/classes/class.ilLink.php';
296 $bookings = array();
297 $this->ctrl->setParameterByClass('ilconsultationhoursgui', 'panel', 1);
298 foreach ($entry->getCurrentBookings($a_app['event']->getEntryId()) as $user_id) {
299 if ($link_users) {
300 $this->ctrl->setParameterByClass('ilconsultationhoursgui', 'user', $user_id);
301 $bookings[] = '<a href="' . $this->ctrl->getLinkTargetByClass('ilconsultationhoursgui', 'showprofile') . '">' .
302 ilObjUser::_lookupFullname($user_id) . '</a>';
303 $this->ctrl->setParameterByClass('ilconsultationhoursgui', 'user', '');
304 } else {
305 $bookings[] = ilObjUser::_lookupFullname($user_id);
306 }
307 }
308 $this->ctrl->setParameterByClass('ilconsultationhoursgui', 'panel', '');
309 $this->tpl->setCurrentBlock('panel_current_booking');
310 $this->tpl->setVariable('PANEL_TXT_CURRENT_BOOKING', $this->lng->txt('cal_ch_current_bookings'));
311 $this->tpl->setVariable('PANEL_CURRENT_BOOKING', implode('<br />', $bookings));
312 $this->tpl->parseCurrentBlock();
313 }
314 break;
315
317 $this->tpl->setVariable('PANEL_CAL_TYPE', $this->lng->txt('cal_ch_booking'));
318
319 $this->tpl->setCurrentBlock('panel_cancel_book_link');
320 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $a_app['event']->getEntryId());
321 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'seed', $this->getSeed()->get(IL_CAL_DATE));
322 $this->tpl->setVariable('TXT_PANEL_CANCELBOOK', $this->lng->txt('cal_ch_cancel_booking'));
323 $this->tpl->setVariable('PANEL_CANCELBOOK_HREF', $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'cancelBooking'));
324 $this->tpl->parseCurrentBlock();
325 break;
326 }
327
328 $this->tpl->setVariable('PANEL_TXT_CAL_NAME', $this->lng->txt('cal_calendar_name'));
329 $this->tpl->setVariable('PANEL_CAL_NAME', $cat_info['title']);
330
331
332 if ($cat_info['editable'] and !$a_app['event']->isAutoGenerated()) {
333 $this->tpl->setCurrentBlock('panel_edit_link');
334 $this->tpl->setVariable('TXT_PANEL_EDIT', $this->lng->txt('edit'));
335
336 $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
337 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'seed', $this->getSeed()->get(IL_CAL_DATE));
338 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $a_app['event']->getEntryId());
339 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'dt', $a_app['dstart']);
340 $this->tpl->setVariable('PANEL_EDIT_HREF', $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'askEdit'));
341
342 $this->tpl->setCurrentBlock('panel_delete_link');
343 $this->tpl->setVariable('TXT_PANEL_DELETE', $this->lng->txt('delete'));
344
345 $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
346 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'seed', $this->getSeed()->get(IL_CAL_DATE));
347 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $a_app['event']->getEntryId());
348 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'dt', $a_app['dstart']);
349 $this->tpl->setVariable('PANEL_DELETE_HREF', $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'askdelete'));
350 $this->tpl->parseCurrentBlock();
351 }
352 include_once('./Services/Calendar/classes/class.ilCalendarCategory.php');
353 if ($cat_info['type'] == ilCalendarCategory::TYPE_OBJ) {
354 $refs = ilObject::_getAllReferences($entry_obj_id);
355 $type = ilObject::_lookupType($entry_obj_id);
356 $title = ilObject::_lookupTitle($entry_obj_id) ?
357 ilObject::_lookupTitle($entry_obj_id) :
358 $lng->txt('obj_' . $type);
359
360 include_once('./Services/Link/classes/class.ilLink.php');
361 $href = ilLink::_getStaticLink(current($refs), ilObject::_lookupType($entry_obj_id));
362 $parent = $tree->getParentId(current($refs));
363 $parent_title = ilObject::_lookupTitle(ilObject::_lookupObjId($parent));
364 $this->tpl->setVariable('PANEL_TXT_LINK', $this->lng->txt('ext_link'));
365 $this->tpl->setVariable('PANEL_LINK_HREF', $href);
366 $this->tpl->setVariable('PANEL_LINK_NAME', $title);
367 $this->tpl->setVariable('PANEL_PARENT', $parent_title);
368 }
369
370 return $this->tpl->get();
371 }
372}
$users
Definition: authpage.php:44
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_DATE
const IL_CAL_UNIX
Booking definition.
GUI class for YUI appointment panels.
static _getInstance(ilDate $seed)
get singleton instance
static _getInstance($a_usr_id=0)
get singleton instance
static _lookupCategory($a_cal_id)
Lookup category id.
registration for calendar appointments
static _getInstance()
get singleton instance
static getAppointmentIds($a_user_id, $a_context_id=null, $a_start=null, $a_type=null, $a_check_owner=true)
Get all appointment ids.
static formatPeriod(ilDateTime $start, ilDateTime $end, $a_skip_starting_day=false)
Format a period of two date Shows: 14.
@classDescription Date and time handling
static _after(ilDateTime $start, ilDateTime $end, $a_compare_field='', $a_tz='')
compare two dates and check start is after end This method does not consider tz offsets.
Class for single dates.
static _lookupFullname($a_user_id)
Lookup Full Name.
static _lookupObjId($a_id)
static _lookupTitle($a_id)
lookup object title
static _getAllReferences($a_id)
get all reference ids of object
static _lookupType($a_id, $a_reference=false)
lookup object type
special template class to simplify handling of ITX/PEAR
static makeClickable($a_text, $detectGotoLinks=false)
makeClickable In Texten enthaltene URLs und Mail-Adressen klickbar machen
$counter
$r
Definition: example_031.php:79
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
global $ilCtrl
Definition: ilias.php:18
static getDescription()
Definition: Php.php:51
$type
settings()
Definition: settings.php:2
$ilUser
Definition: imgupload.php:18