ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilConsultationHoursGUI.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.ilCalendarRecurrence.php';
25include_once './Services/Booking/classes/class.ilBookingEntry.php';
26include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourAppointments.php';
27
35{
36 const MODE_CREATE = 1;
37 const MODE_UPDATE = 2;
38 const MODE_MULTI = 3;
39
41
42 protected $user_id;
43 protected $ctrl;
44
45 protected $booking = null;
46
50 public function __construct()
51 {
52 global $lng, $ilCtrl, $tpl, $ilUser;
53
54 $user_id = (int) $_GET['user_id'];
55 if ($user_id) {
56 if (in_array($user_id, array_keys(ilConsultationHourAppointments::getManagedUsers()))) {
57 $this->user_id = $user_id;
58 } else {
59 $user_id = false;
60 }
61 }
62 if (!$user_id) {
63 $this->user_id = $ilUser->getId();
64 }
65
66 $this->ctrl = $ilCtrl;
67 $this->lng = $lng;
68 $this->tpl = $tpl;
69 }
70
75 public function executeCommand()
76 {
77 global $ilUser, $ilCtrl, $tpl, $ilHelp, $ilTabs;
78
79 $ilHelp->setScreenIdComponent("cal");
80
81 switch ($this->ctrl->getNextClass()) {
82 case "ilpublicuserprofilegui":
83 include_once('./Services/User/classes/class.ilPublicUserProfileGUI.php');
84 #22168 don't send the current user if no GET user_id
85 //$profile = new ilPublicUserProfileGUI($this->user_id);
86 $profile = new ilPublicUserProfileGUI();
87 $profile->setBackUrl($this->getProfileBackUrl());
88 $ret = $ilCtrl->forwardCommand($profile);
89 $tpl->setContent($ret);
90 break;
91
92 case 'ilrepositorysearchgui':
93
94 include_once('./Services/Search/classes/class.ilRepositorySearchGUI.php');
95 $rep_search = new ilRepositorySearchGUI();
96
97 if (isset($_REQUEST['assignM'])) {
98 $rep_search->setCallback(
99 $this,
100 'assignUsersToAppointments',
101 array()
102 );
103 $ilCtrl->setParameter($this, 'assignM', 1);
104 $ilCtrl->setReturn($this, 'appointmentList');
105 $ilTabs->activateSubTab('cal_ch_app_list');
106 } elseif (isset($_REQUEST['grp_id'])) {
107 $rep_search->setCallback(
108 $this,
109 'assignUsersToGroup',
110 array()
111 );
112 $ilCtrl->saveParameter($this, 'grp_id');
113 $ilCtrl->setReturn($this, 'groupList');
114 $ilTabs->activateSubTab('cal_ch_app_grp');
115 } elseif (isset($_REQUEST['apps'])) {
116 $rep_search->setCallback(
117 $this,
118 'assignUsersToAppointment',
119 array()
120 );
121 $ilCtrl->saveParameter($this, 'apps');
122 $ilCtrl->setReturn($this, 'appointmentList');
123 $ilTabs->activateSubTab('cal_ch_app_list');
124 }
125 $ilCtrl->forwardCommand($rep_search);
126 break;
127
128 default:
129 $tpl->setTitle($this->lng->txt("cal_ch_form_header")); // #12220
130
131 $this->setTabs();
132 if ($ilUser->getId() != $this->user_id) {
133 $ilCtrl->setParameter($this, 'user_id', $this->user_id);
134 }
135
136 $cmd = $this->ctrl->getCmd('appointmentList');
137 $this->$cmd();
138 }
139 }
140
145 public function getUserId()
146 {
147 return $this->user_id;
148 }
149
153 protected function searchUsersForAppointments()
154 {
155 global $ilCtrl, $ilTabs;
156
157 $_SESSION['ch_apps'] = $_REQUEST['apps'];
158
159 if (!count($_SESSION['ch_apps'])) {
160 ilUtil::sendFailure($this->lng->txt('select_one'), true);
161 $GLOBALS['ilCtrl']->redirect($this, 'appointmentList');
162 }
163 $_REQUEST['assignM'] = 1;
164 $ilCtrl->setCmdClass('ilrepositorysearchgui');
165 $ilCtrl->setcmd('');
166 $this->executeCommand();
167 }
168
173 protected function sendInfoAboutUnassignedUsers($unassigned)
174 {
175 if (!$unassigned) {
176 return true;
177 }
178 $users = array();
179 foreach ($unassigned as $user_id) {
180 include_once './Services/User/classes/class.ilObjUser.php';
182 }
183 ilUtil::sendInfo($this->lng->txt('cal_ch_user_assignment_failed_info') . '<br />' . implode('<br />', $users), true);
184 return true;
185 }
186
191 public function assignUsersToAppointments(array $users)
192 {
193 global $ilCtrl;
194
195 $unassigned_users = array();
196 foreach ($_SESSION['ch_apps'] as $app) {
197 $unassigned_users = array_unique(array_merge($unassigned_users, $this->assignUsersToAppointment($users, $app, false)));
198 }
199
200 $this->sendInfoAboutUnassignedUsers($unassigned_users);
201 $ilCtrl->redirect($this, 'appointmentList');
202 }
203
204
210 public function assignUsersToAppointment(array $users, $a_app = 0, $a_redirect = true)
211 {
212 global $ilCtrl;
213
214 if ($a_app) {
215 $app = $a_app;
216 } else {
217 $app = $_REQUEST['apps'];
218 }
219
220 if (!count($users)) {
221 ilUtil::sendFailure($GLOBALS['DIC']->language()->txt('select_one'), true);
222 return false;
223 }
224
225
226 include_once './Services/Booking/classes/class.ilBookingEntry.php';
228
229 $assigned_users = array();
230 foreach ($users as $user) {
231 if ($booking->getCurrentNumberOfBookings($app) >= $booking->getNumberOfBookings()) {
232 break;
233 }
234 if (!ilBookingEntry::lookupBookingsOfUser((array) $app, $user)) {
235 include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourUtils.php';
237 $assigned_users[] = $user;
238 }
239 }
240
241 $unassigned_users = array_diff($users, $assigned_users);
242
243 if ($a_redirect) {
244 $this->sendInfoAboutUnassignedUsers($unassigned_users);
245 $ilCtrl->redirect($this, 'appointmentList');
246 } else {
247 return $unassigned_users;
248 }
249 }
250
256 public function assignUsersToGroup(array $usr_ids)
257 {
258 global $ilCtrl;
259
260 $group_id = (int) $_REQUEST['grp_id'];
261
262 $tomorrow = new ilDateTime(time(), IL_CAL_UNIX);
263 $tomorrow->increment(IL_CAL_DAY, 1);
264
265 // Get all future consultation hours
266 include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourAppointments.php';
267 include_once './Services/Booking/classes/class.ilBookingEntry.php';
269 $this->user_id,
270 $group_id,
271 $tomorrow
272 );
273 $users = $usr_ids;
274 $assigned_users = array();
275 foreach ($apps as $app) {
277 foreach ($users as $user) {
278 if ($booking->getCurrentNumberOfBookings($app) >= $booking->getNumberOfBookings()) {
279 break;
280 }
281 if (!ilBookingEntry::lookupBookingsOfUser($apps, $user)) {
282 include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourUtils.php';
284 $assigned_users[] = $user;
285 }
286 }
287 }
288
289 $this->sendInfoAboutUnassignedUsers(array_diff($users, $assigned_users));
290 $ilCtrl->redirect($this, 'bookingList');
291 }
292
293
298 protected function groupList()
299 {
300 global $ilToolbar, $ilTabs, $tpl;
301
302 $ilToolbar->setFormAction($this->ctrl->getFormAction($this));
303 $ilToolbar->addButton($this->lng->txt('cal_ch_add_grp'), $this->ctrl->getLinkTarget($this, 'addGroup'));
304
305 $this->setSubTabs();
306 $ilTabs->activateSubTab('cal_ch_app_grp');
307
308 include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourGroupTableGUI.php';
309 include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourGroups.php';
310 $gtbl = new ilConsultationHourGroupTableGUI($this, 'groupList', $this->getUserId());
312
313 $tpl->setContent($gtbl->getHTML());
314 }
315
321 protected function addGroup(ilPropertyFormGUI $form = null)
322 {
323 global $ilTabs, $tpl;
324
325 $this->setSubTabs();
326 $ilTabs->activateSubTab('cal_ch_app_grp');
327
328 if ($form == null) {
329 $form = $this->initGroupForm();
330 }
331 $tpl->setContent($form->getHTML());
332 }
333
337 protected function saveGroup()
338 {
339 $form = $this->initGroupForm();
340 if ($form->checkInput()) {
341 include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourGroup.php';
342 $group = new ilConsultationHourGroup();
343 $group->setTitle($form->getInput('title'));
344 $group->setMaxAssignments($form->getInput('multiple'));
345 $group->setUserId($this->getUserId());
346 $group->save();
347
348 ilUtil::sendSuccess($GLOBALS['lng']->txt('settings_saved'), true);
349 $GLOBALS['ilCtrl']->redirect($this, 'groupList');
350 }
351
352 ilUtil::sendFailure($GLOBALS['lng']->txt('err_check_input'), true);
353 $this->addGroup($form);
354 }
355
361 protected function editGroup(ilPropertyFormGUI $form = null)
362 {
363 global $ilCtrl, $tpl, $ilTabs;
364
365 $ilCtrl->setParameter($this, 'grp_id', (int) $_REQUEST['grp_id']);
366 $this->setSubTabs();
367 $ilTabs->activateSubTab('cal_ch_app_grp');
368
369 if ($form == null) {
370 $form = $this->initGroupForm((int) $_REQUEST['grp_id']);
371 }
372 $tpl->setContent($form->getHTML());
373 }
374
381 protected function updateGroup()
382 {
383 global $ilCtrl, $tpl, $ilTabs;
384
385 $ilCtrl->setParameter($this, 'grp_id', (int) $_REQUEST['grp_id']);
386
387 $form = $this->initGroupForm((int) $_REQUEST['grp_id']);
388 if ($form->checkInput()) {
389 include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourGroup.php';
390 $group = new ilConsultationHourGroup((int) $_REQUEST['grp_id']);
391 $group->setTitle($form->getInput('title'));
392 $group->setMaxAssignments($form->getInput('multiple'));
393 $group->setUserId($this->getUserId());
394 $group->update();
395
396 ilUtil::sendSuccess($GLOBALS['lng']->txt('settings_saved'), true);
397 $GLOBALS['ilCtrl']->redirect($this, 'groupList');
398 }
399
400 ilUtil::sendFailure($GLOBALS['lng']->txt('err_check_input'), true);
401 $this->editGroup($form);
402 }
403
409 protected function confirmDeleteGroup()
410 {
411 global $ilCtrl, $ilTabs, $tpl;
412
413 $ilCtrl->setParameter($this, 'grp_id', (int) $_REQUEST['grp_id']);
414 $groups = array((int) $_REQUEST['grp_id']);
415
416 $this->setSubTabs();
417 $ilTabs->activateSubTab('cal_ch_app_grp');
418
419
420 include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
421 $confirm = new ilConfirmationGUI();
422 $confirm->setFormAction($ilCtrl->getFormAction($this));
423 $confirm->setHeaderText($GLOBALS['lng']->txt('cal_ch_grp_delete_sure'));
424 $confirm->setConfirm($GLOBALS['lng']->txt('delete'), 'deleteGroup');
425 $confirm->setCancel($GLOBALS['lng']->txt('cancel'), 'groupList');
426
427 foreach ($groups as $grp_id) {
428 include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourGroup.php';
429 $group = new ilConsultationHourGroup($grp_id);
430
431 $confirm->addItem('groups[]', $grp_id, $group->getTitle());
432 }
433 $tpl->setContent($confirm->getHTML());
434 }
435
439 protected function deleteGroup()
440 {
441 global $ilCtrl;
442
443 foreach ((array) $_REQUEST['groups'] as $grp_id) {
444 include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourGroup.php';
445 $group = new ilConsultationHourGroup($grp_id);
446 $group->delete();
447 }
448 ilUtil::sendSuccess($GLOBALS['lng']->txt('cal_ch_grp_deleted'));
449 $ilCtrl->redirect($this, 'groupList');
450 }
451
455 protected function initGroupForm($a_group_id = 0)
456 {
457 include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourGroup.php';
458 $group = new ilConsultationHourGroup($a_group_id);
459
460 include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
461 $form = new ilPropertyFormGUI();
462 $form->setFormAction($GLOBALS['ilCtrl']->getFormAction($this));
463
464 if ($a_group_id) {
465 $form->setTitle($GLOBALS['lng']->txt('cal_ch_grp_update_tbl'));
466 $form->addCommandButton('updateGroup', $GLOBALS['lng']->txt('save'));
467 $form->addCommandButton('groupList', $GLOBALS['lng']->txt('cancel'));
468 } else {
469 $form->setTitle($GLOBALS['lng']->txt('cal_ch_grp_add_tbl'));
470 $form->addCommandButton('saveGroup', $GLOBALS['lng']->txt('save'));
471 $form->addCommandButton('appointmentList', $GLOBALS['lng']->txt('cancel'));
472 }
473
474 $title = new ilTextInputGUI($GLOBALS['lng']->txt('title'), 'title');
475 $title->setMaxLength(128);
476 $title->setSize(40);
477 $title->setRequired(true);
478 $title->setValue($group->getTitle());
479 $form->addItem($title);
480
481 $multiple = new ilNumberInputGUI($GLOBALS['lng']->txt('cal_ch_grp_multiple'), 'multiple');
482 $multiple->setRequired(true);
483 $multiple->setMinValue(1);
484 $multiple->setSize(1);
485 $multiple->setMaxLength(2);
486 $multiple->setInfo($GLOBALS['lng']->txt('cal_ch_grp_multiple_info'));
487 $multiple->setValue($group->getMaxAssignments());
488 $form->addItem($multiple);
489
490 return $form;
491 }
492
496 protected function bookingList()
497 {
498 global $ilToolbar, $ilTabs, $tpl;
499
500 $this->setSubTabs();
501 $ilTabs->activateSubTab('cal_ch_app_bookings');
502
503 include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourBookingTableGUI.php';
504 $btable = new ilConsultationHourBookingTableGUI($this, 'bookingList', $this->getUserId());
506 $tpl->setContent($btable->getHTML());
507 }
508
512 protected function confirmDeleteBooking()
513 {
514 $this->confirmRejectBooking(false);
515 }
516
520 protected function confirmRejectBooking($a_send_notification = true)
521 {
522 global $ilTabs, $tpl;
523
524 $this->setSubTabs();
525 $ilTabs->activateSubTab('cal_ch_app_bookings');
526
527 include_once('./Services/Utilities/classes/class.ilConfirmationGUI.php');
528
529 $confirm = new ilConfirmationGUI();
530 $confirm->setFormAction($this->ctrl->getFormAction($this));
531
532 if ($a_send_notification) {
533 ilUtil::sendInfo($this->lng->txt('cal_ch_cancel_booking_info'));
534 $confirm->setHeaderText($this->lng->txt('cal_ch_cancel_booking_sure'));
535 $confirm->setConfirm($this->lng->txt('cal_ch_reject_booking'), 'rejectBooking');
536 } else {
537 ilUtil::sendInfo($this->lng->txt('cal_ch_delete_booking_info'));
538 $confirm->setHeaderText($this->lng->txt('cal_ch_delete_booking_sure'));
539 $confirm->setConfirm($this->lng->txt('cal_ch_delete_booking'), 'deleteBooking');
540 }
541
542 $confirm->setCancel($this->lng->txt('cancel'), 'bookingList');
543
544 include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
545 foreach ((array) $_REQUEST['bookuser'] as $bookuser) {
546 $ids = explode('_', $bookuser);
547
548 include_once './Services/Calendar/classes/class.ilCalendarEntry.php';
549 include_once './Services/User/classes/class.ilUserUtil.php';
550 $entry = new ilCalendarEntry($ids[0]);
551 $confirm->addItem(
552 'bookuser[]',
553 $bookuser,
555 $ids[1],
556 true,
557 false,
558 '',
559 true,
560 true
561 ) . ', ' . ilDatePresentation::formatDate($entry->getStart())
562 );
563 }
564 $tpl->setContent($confirm->getHTML());
565 }
566
570 protected function deleteBooking()
571 {
572 $this->rejectBooking(false);
573 }
574
579 protected function rejectBooking($a_send_notification = true)
580 {
581 global $ilCtrl;
582
583 foreach ((array) $_REQUEST['bookuser'] as $bookuser) {
584 $ids = explode('_', $bookuser);
585
586 include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourUtils.php';
587 ilConsultationHourUtils::cancelBooking($ids[1], $ids[0], $a_send_notification);
588 }
589 if ($a_send_notification) {
590 ilUtil::sendSuccess($this->lng->txt('cal_ch_canceled_bookings'), true);
591 } else {
592 ilUtil::sendSuccess($this->lng->txt('cal_ch_deleted_bookings'), true);
593 }
594 $ilCtrl->redirect($this, 'bookingList');
595 }
596
602 protected function appointmentList()
603 {
604 global $ilToolbar, $ilHelp, $ilTabs;
605
606 $ilHelp->setScreenId("consultation_hours");
607
608 $ilToolbar->setFormAction($this->ctrl->getFormAction($this));
609 $ilToolbar->addButton($this->lng->txt('cal_ch_add_sequence'), $this->ctrl->getLinkTarget($this, 'createSequence'));
610
611 $this->setSubTabs();
612 $ilTabs->activateSubTab('cal_ch_app_list');
613
614 include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHoursTableGUI.php';
615 $tbl = new ilConsultationHoursTableGUI($this, 'appointmentList', $this->getUserId());
616 $tbl->parse();
617 $this->tpl->setContent($tbl->getHTML());
618 }
619
624 protected function createSequence()
625 {
626 $this->initFormSequence(self::MODE_CREATE);
627
628 $this->booking = new ilBookingEntry();
629 $this->form->getItemByPostVar('bo')->setValue($this->booking->getNumberOfBookings());
630 $this->form->getItemByPostVar('ap')->setValue(1);
631 $this->form->getItemByPostVar('du')->setMinutes(15);
632 $this->form->getItemByPostVar('st')->setDate(
633 new ilDateTime(mktime(8, 0, 0, date('n', time()), date('d', time()), date('Y', time())), IL_CAL_UNIX)
634 );
635
636 $this->tpl->setContent($this->form->getHTML());
637 }
638
644 protected function initFormSequence($a_mode)
645 {
646 include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
647
648 include_once('./Services/YUI/classes/class.ilYuiUtil.php');
650
651 $this->form = new ilPropertyFormGUI();
652 $this->form->setFormAction($this->ctrl->getFormAction($this));
653
654 switch ($a_mode) {
656 $this->form->setTitle($this->lng->txt('cal_ch_add_sequence'));
657 $this->form->addCommandButton('saveSequence', $this->lng->txt('save'));
658 $this->form->addCommandButton('appointmentList', $this->lng->txt('cancel'));
659 break;
660
661 /*
662 case self::MODE_UPDATE:
663 $this->form->setTitle($this->lng->txt('cal_ch_edit_sequence'));
664 $this->form->addCommandButton('updateSequence', $this->lng->txt('save'));
665 $this->form->addCommandButton('appointmentList', $this->lng->txt('cancel'));
666 break;
667 */
668
669 case self::MODE_MULTI:
670 $this->form->setTitle($this->lng->txt('cal_ch_multi_edit_sequence'));
671 $this->form->addCommandButton('updateMulti', $this->lng->txt('save'));
672 $this->form->addCommandButton('appointmentList', $this->lng->txt('cancel'));
673 break;
674 }
675
676 // in case of existing groups show a selection
677 include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourGroups.php';
679 $group = new ilSelectInputGUI($this->lng->txt('cal_ch_grp_selection'), 'grp');
680 $group->setOptions($options);
681 $group->setRequired(false);
682 $this->form->addItem($group);
683 }
684
685 // Title
686 $ti = new ilTextInputGUI($this->lng->txt('title'), 'ti');
687 $ti->setSize(32);
688 $ti->setMaxLength(128);
689 $ti->setRequired(true);
690 $this->form->addItem($ti);
691
692 if ($a_mode != self::MODE_MULTI) {
693 // Start
694 include_once './Services/Form/classes/class.ilDateTimeInputGUI.php';
695 $dur = new ilDateTimeInputGUI($this->lng->txt('cal_start'), 'st');
696 $dur->setShowTime(true);
697 $dur->setRequired(true);
698 $this->form->addItem($dur);
699
700 // Duration
701 $du = new ilDurationInputGUI($this->lng->txt('cal_ch_duration'), 'du');
702 $du->setShowMinutes(true);
703 $du->setShowHours(true);
704 $this->form->addItem($du);
705
706 // Number of appointments
707 $nu = new ilNumberInputGUI($this->lng->txt('cal_ch_num_appointments'), 'ap');
708 $nu->setInfo($this->lng->txt('cal_ch_num_appointments_info'));
709 $nu->setSize(2);
710 $nu->setMaxLength(2);
711 $nu->setRequired(true);
712 $nu->setMinValue(1);
713 $this->form->addItem($nu);
714
715 // Recurrence
716 include_once('./Services/Calendar/classes/Form/class.ilRecurrenceInputGUI.php');
717 $rec = new ilRecurrenceInputGUI($this->lng->txt('cal_recurrences'), 'frequence');
718 $rec->setEnabledSubForms(
719 array(
723 )
724 );
725 $this->form->addItem($rec);
726 }
727
728 // Number of bookings
729 $nu = new ilNumberInputGUI($this->lng->txt('cal_ch_num_bookings'), 'bo');
730 $nu->setSize(2);
731 $nu->setMaxLength(2);
732 $nu->setMinValue(1);
733 $nu->setRequired(true);
734 $this->form->addItem($nu);
735
736 // Deadline
737 $dead = new ilDurationInputGUI($this->lng->txt('cal_ch_deadline'), 'dead');
738 $dead->setInfo($this->lng->txt('cal_ch_deadline_info'));
739 $dead->setShowMinutes(false);
740 $dead->setShowHours(true);
741 $dead->setShowDays(true);
742 $this->form->addItem($dead);
743
744 // Location
745 $lo = new ilTextInputGUI($this->lng->txt('cal_where'), 'lo');
746 $lo->setSize(32);
747 $lo->setMaxLength(128);
748 $this->form->addItem($lo);
749
750 // Description
751 $de = new ilTextAreaInputGUI($this->lng->txt('description'), 'de');
752 $de->setRows(10);
753 $de->setCols(60);
754 $this->form->addItem($de);
755
756 // Target Object
757 $tgt = new ilTextInputGUI($this->lng->txt('cal_ch_target_object'), 'tgt');
758 $tgt->setInfo($this->lng->txt('cal_ch_target_object_info'));
759 $tgt->setSize(16);
760 $tgt->setMaxLength(128);
761 $this->form->addItem($tgt);
762 }
763
768 protected function saveSequence()
769 {
770 global $ilObjDataCache;
771
772 $this->initFormSequence(self::MODE_CREATE);
773
774 if ($this->form->checkInput()) {
775 $this->form->setValuesByPost();
776
777 $booking = new ilBookingEntry();
778 $booking->setObjId($this->getUserId());
779 $booking->setNumberOfBookings($this->form->getInput('bo'));
780
781 $deadline = $this->form->getInput('dead');
782 $deadline = $deadline['dd'] * 24 + $deadline['hh'];
783 $booking->setDeadlineHours($deadline);
784
785 // consultation hour group
786 include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourGroups.php';
788 $booking->setBookingGroup((int) $this->form->getInput('grp'));
789 }
790
791 $tgt = explode(',', $this->form->getInput('tgt'));
792 $obj_ids = array();
793 foreach ((array) $tgt as $ref_id) {
794 if (!trim($ref_id)) {
795 continue;
796 }
797 $obj_id = $ilObjDataCache->lookupObjId($ref_id);
798 $type = ilObject::_lookupType($obj_id);
799 $valid_types = array('crs','grp');
800 if (!$obj_id or !in_array($type, $valid_types)) {
801 ilUtil::sendFailure($this->lng->txt('cal_ch_unknown_repository_object'));
802 $this->tpl->setContent($this->form->getHTML());
803 return;
804 }
805
806 $obj_ids[] = $obj_id;
807 }
808 $booking->setTargetObjIds($obj_ids);
809
810 $booking->save();
812
813 ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
814 $this->ctrl->redirect($this, 'appointmentList');
815 } else {
816 $this->form->setValuesByPost();
817 $this->tpl->setContent($this->form->getHTML());
818 }
819 }
820
827 {
828 include_once './Services/Calendar/classes/class.ilDateList.php';
829 $concurrent_dates = new ilDateList(ilDateList::TYPE_DATETIME);
830 $start = clone $this->form->getItemByPostVar('st')->getDate();
831 for ($i = 0; $i < $this->form->getItemByPostVar('ap')->getValue(); $i++) {
832 $concurrent_dates->add(clone $start);
833
834 $start->increment(ilDateTime::MINUTE, $this->form->getItemByPostVar('du')->getMinutes());
835 $start->increment(ilDateTime::HOUR, $this->form->getItemByPostVar('du')->getHours());
836 #$start = new ilDateTime(,IL_CAL_UNIX);
837 }
838
839 include_once './Services/Calendar/classes/class.ilCalendarUtil.php';
840 $def_cat = ilCalendarUtil::initDefaultCalendarByType(ilCalendarCategory::TYPE_CH, $this->getUserId(), $this->lng->txt('cal_ch_personal_ch'), true);
841
842 // Add calendar appointment for each
843 include_once './Services/Calendar/classes/class.ilCalendarCategoryAssignments.php';
844 include_once './Services/Calendar/classes/class.ilCalendarEntry.php';
845 include_once './Services/Calendar/classes/class.ilCalendarRecurrenceCalculator.php';
846 include_once './Services/Booking/classes/class.ilBookingPeriod.php';
847
848 $num_appointments = 0;
849 foreach ($concurrent_dates as $dt) {
850 if ($num_appointments >= self::MAX_APPOINTMENTS_PER_SEQUENCE) {
851 break;
852 }
853
854 $end = clone $dt;
855 $end->increment(ilDateTime::MINUTE, $this->form->getItemByPostVar('du')->getMinutes());
856 $end->increment(ilDateTime::HOUR, $this->form->getItemByPostVar('du')->getHours());
857
859 new ilBookingPeriod($dt, $end),
860 $this->form->getItemByPostVar('frequence')->getRecurrence()
861 );
862
863 // Calculate with one year limit
864 $limit = clone $dt;
865 $limit->increment(ilDateTime::YEAR, 1);
866
867 $date_list = $calc->calculateDateList($dt, $limit);
868
869 $num = 0;
870 foreach ($date_list as $app_start) {
871 $app_end = clone $app_start;
872 $app_end->increment(ilDateTime::MINUTE, $this->form->getItemByPostVar('du')->getMinutes());
873 $app_end->increment(ilDateTime::HOUR, $this->form->getItemByPostVar('du')->getHours());
874
875
876 $entry = new ilCalendarEntry();
877 $entry->setContextId($booking->getId());
878 $entry->setTitle($this->form->getInput('ti'));
879 $entry->setSubtitle("#consultationhour#"); // dynamic, see ilCalendarEntry
880 $entry->setDescription($this->form->getInput('de'));
881 $entry->setLocation($this->form->getInput('lo'));
882 $entry->setStart($app_start);
883 $entry->setEnd($app_end);
884
885 $entry->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
886 $entry->save();
887
888 $cat_assign = new ilCalendarCategoryAssignments($entry->getEntryId());
889 $cat_assign->addAssignment($def_cat->getCategoryID());
890
891 $num_appointments++;
892 }
893 }
894 }
895
900 protected function setTabs()
901 {
902 global $ilTabs, $ilUser, $ilCtrl;
903
904 $ilCtrl->setParameter($this, 'user_id', '');
905 $ilTabs->addTab('consultation_hours_' . $ilUser->getId(), $this->lng->txt('cal_ch_ch'), $this->ctrl->getLinkTarget($this, 'appointmentList'));
906
908 $ilCtrl->setParameter($this, 'user_id', $user_id);
909 $ilTabs->addTab('consultation_hours_' . $user_id, $this->lng->txt('cal_ch_ch') . ': ' . $login, $this->ctrl->getLinkTarget($this, 'appointmentList'));
910 }
911 $ilCtrl->setParameter($this, 'user_id', '');
912
913 $ilTabs->addTab('ch_settings', $this->lng->txt('settings'), $this->ctrl->getLinkTarget($this, 'settings'));
914
915 $ilTabs->activateTab('consultation_hours_' . $this->getUserId());
916 }
917
923 protected function setSubTabs()
924 {
925 global $ilTabs, $ilCtrl;
926
927 $ilCtrl->setParameter($this, 'user_id', $this->getUserId());
928 $ilTabs->addSubTab('cal_ch_app_list', $this->lng->txt('cal_ch_app_list'), $ilCtrl->getLinkTarget($this, 'appointmentList'));
929 $ilTabs->addSubTab('cal_ch_app_grp', $this->lng->txt('cal_ch_app_grp'), $ilCtrl->getLinkTarget($this, 'groupList'));
930 $ilTabs->addSubTab('cal_ch_app_bookings', $this->lng->txt('cal_ch_app_bookings'), $ilCtrl->getLinkTarget($this, 'bookingList'));
931 }
932
936 public function edit()
937 {
938 global $ilTabs;
939
940 if (!isset($_REQUEST['apps'])) {
941 ilUtil::sendFailure($this->lng->txt('select_one'));
942 return $this->appointmentList();
943 }
944
945 $this->initFormSequence(self::MODE_MULTI);
946
947 if ($_REQUEST['apps'] && !is_array($_REQUEST['apps'])) {
948 $_REQUEST['apps'] = explode(';', $_REQUEST['apps']);
949 }
950
951 $hidden = new ilHiddenInputGUI('apps');
952 $hidden->setValue(implode(';', $_REQUEST['apps']));
953 $this->form->addItem($hidden);
954
955 include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
956 $first = $_REQUEST['apps'];
957 $first = array_shift($_REQUEST['apps']);
958 $entry = new ilCalendarEntry($first);
959
960 $this->form->getItemByPostVar('ti')->setValue($entry->getTitle());
961 $this->form->getItemByPostVar('lo')->setValue($entry->getLocation());
962 $this->form->getItemByPostVar('de')->setValue($entry->getDescription());
963
964 include_once 'Services/Booking/classes/class.ilBookingEntry.php';
965 $booking = new ilBookingEntry($entry->getContextId());
966
967 $this->form->getItemByPostVar('bo')->setValue($booking->getNumberOfBookings());
968
969 $ref_ids = array();
970 foreach ($booking->getTargetObjIds() as $obj_id) {
971 $refs = ilObject::_getAllReferences($obj_id);
972 $ref_ids[] = end($refs);
973 }
974 $this->form->getItemByPostVar('tgt')->setValue(implode(',', $ref_ids));
975
976 $deadline = $booking->getDeadlineHours();
977 $this->form->getItemByPostVar('dead')->setDays(floor($deadline/24));
978 $this->form->getItemByPostVar('dead')->setHours($deadline%24);
979
980 if ($booking->getBookingGroup()) {
981 $this->form->getItemByPostVar('grp')->setValue($booking->getBookingGroup());
982 }
983
984 $this->tpl->setContent($this->form->getHTML());
985 }
986
991 protected function createNewBookingEntry(\ilPropertyFormGUI $validate_form)
992 {
993 global $DIC;
994
995 $obj_cache = $DIC['ilObjDataCache'];
996
997 $booking = new \ilBookingEntry();
998 $booking->setObjId($this->user_id);
999 $booking->setNumberOfBookings((int) $this->form->getInput('bo'));
1000
1001 $deadline = $this->form->getInput('dead');
1002 $deadline = $deadline['dd'] * 24 + $deadline['hh'];
1003 $booking->setDeadlineHours($deadline);
1004
1005 $tgt = explode(',', (string) $this->form->getInput('tgt'));
1006 $obj_ids = [];
1007 foreach ((array) $tgt as $ref_id) {
1008 if (!trim($ref_id)) {
1009 continue;
1010 }
1011 $obj_id = $obj_cache->lookupObjId($ref_id);
1012 $type = ilObject::_lookupType($obj_id);
1013 $valid_types = ['crs', 'grp'];
1014 if (!$obj_id or !in_array($type, $valid_types)) {
1015 ilUtil::sendFailure($this->lng->txt('cal_ch_unknown_repository_object'));
1016 return null;
1017 }
1018 $obj_ids[] = $obj_id;
1019 }
1020 $booking->setTargetObjIds($obj_ids);
1021
1023 $booking->setBookingGroup($this->form->getInput('grp'));
1024 }
1025 $booking->save();
1026 return $booking;
1027 }
1028
1034 {
1035 foreach ($appointments as $appointment_id) {
1036
1037 $booking_appointment = new \ilCalendarEntry($appointment_id);
1038 $booking_start = $booking_appointment->getStart();
1039 $booking_end = $booking_appointment->getEnd();
1040
1041 $deprecatedBooking = \ilBookingEntry::getInstanceByCalendarEntryId($appointment_id);
1042 if (!$deprecatedBooking instanceof \ilBookingEntry) {
1043 // @todo error handling
1044 continue;
1045 }
1046
1048 $deprecatedBooking,
1049 $booking_start,
1050 $booking_end
1051 );
1052 foreach ($relevant_appointments as $relevant_appointment_id) {
1053
1054 $entry = new \ilCalendarEntry($relevant_appointment_id);
1055 $entry->setContextId($booking->getId());
1056 $entry->setTitle($form->getInput('ti'));
1057 $entry->setLocation($form->getInput('lo'));
1058 $entry->setDescription($form->getInput('de'));
1059 $entry->update();
1060 }
1061 }
1062 }
1063
1068 protected function updateMulti()
1069 {
1070 global $DIC;
1071
1072 $ilObjDataCache = $DIC['ilObjDataCache'];
1073
1074 $this->initFormSequence(self::MODE_MULTI);
1075
1076 if ($this->form->checkInput()) {
1077
1078 $this->form->setValuesByPost();
1079 $apps = explode(';', (string) $_POST['apps']);
1080
1081 // create new booking
1082 $booking = $this->createNewBookingEntry($this->form);
1083 if (!$booking instanceof \ilBookingEntry) {
1084 $this->edit();
1085 return false;
1086 }
1087 $this->rewriteBookingIdsForAppointments($booking, $apps, $this->form);
1089
1090 ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
1091 $this->ctrl->redirect($this, 'appointmentList');
1092 }
1093 $this->tpl->setContent($this->form->getHTML());
1094 }
1095
1096
1097
1101 public function confirmDelete()
1102 {
1103 global $tpl;
1104
1105 if (!isset($_REQUEST['apps'])) {
1106 ilUtil::sendFailure($this->lng->txt('select_one'));
1107 return $this->appointmentList();
1108 }
1109
1110 include_once('./Services/Utilities/classes/class.ilConfirmationGUI.php');
1111
1112
1113 $this->ctrl->saveParameter($this, array('seed','app_id','dt'));
1114
1115 $confirm = new ilConfirmationGUI();
1116 $confirm->setFormAction($this->ctrl->getFormAction($this));
1117 $confirm->setHeaderText($this->lng->txt('cal_delete_app_sure'));
1118 $confirm->setCancel($this->lng->txt('cancel'), 'cancel');
1119
1120 include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
1121
1122 $bookings_available = array();
1123 foreach ((array) $_REQUEST['apps'] as $entry_id) {
1124 $entry = new ilCalendarEntry($entry_id);
1125 $confirm->addItem('apps[]', $entry_id, ilDatePresentation::formatDate($entry->getStart()) . ', ' . $entry->getTitle());
1126
1127 include_once './Services/Booking/classes/class.ilBookingEntry.php';
1129 $bookings_available[] = ilDatePresentation::formatDate($entry->getStart()) . ', ' . $entry->getTitle();
1130 }
1131 }
1132
1133 if ($bookings_available) {
1134 ilUtil::sendInfo($this->lng->txt('cal_ch_delete_app_booking_info') . '<br />' . implode('<br />', $bookings_available));
1135 }
1136
1137 $confirm->setConfirm($this->lng->txt('delete'), 'delete');
1138 $confirm->setCancel($this->lng->txt('cancel'), 'appointmentList');
1139
1140 $tpl->setContent($confirm->getHTML());
1141 }
1142
1146 public function delete()
1147 {
1148 if (!isset($_POST['apps'])) {
1149 ilUtil::sendFailure($this->lng->txt('select_one'));
1150 return $this->appointmentList();
1151 }
1152
1153 include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
1154 include_once 'Services/Calendar/classes/class.ilCalendarCategoryAssignments.php';
1155 foreach ($_POST['apps'] as $entry_id) {
1156 // cancel booking for users
1158 if ($booking) {
1159 foreach ($booking->getCurrentBookings($entry_id) as $user_id) {
1160 include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourUtils.php';
1162 }
1163 }
1164 // remove calendar entries
1165 include_once './Services/Calendar/classes/class.ilCalendarEntry.php';
1166 $entry = new ilCalendarEntry($entry_id);
1167 $entry->delete();
1168
1170 }
1171
1173
1174 ilUtil::sendSuccess($this->lng->txt('cal_deleted_app'), true);
1175 $this->ctrl->redirect($this, 'appointmentList');
1176 }
1177
1181 public function showProfile()
1182 {
1183 global $tpl, $ilTabs, $ilCtrl;
1184
1185 $ilTabs->clearTargets();
1186
1187 $user_id = (int) $_GET['user'];
1188
1189 include_once 'Services/User/classes/class.ilPublicUserProfileGUI.php';
1190 $profile = new ilPublicUserProfileGUI($user_id);
1191 $profile->setBackUrl($this->getProfileBackUrl());
1192 $tpl->setContent($ilCtrl->getHTML($profile));
1193 }
1194
1200 protected function getProfileBackUrl()
1201 {
1202 // from repository
1203 if (isset($_REQUEST["ref_id"])) {
1204 $url = $this->ctrl->getLinkTargetByClass('ilCalendarMonthGUI');
1205 }
1206 // from panel
1207 elseif (isset($_GET['panel'])) {
1208 $url = $this->ctrl->getLinkTargetByClass('ilCalendarPresentationGUI');
1209 }
1210 // from appointments
1211 else {
1212 $url = $this->ctrl->getLinkTarget($this, 'appointmentList');
1213 }
1214 return $url;
1215 }
1216
1220 public function settings()
1221 {
1222 global $tpl, $ilTabs, $ilHelp;
1223
1224 $ilHelp->setScreenId("consultation_hours_settings");
1225 $ilTabs->activateTab('ch_settings');
1226
1227 $form = $this->initSettingsForm();
1228 $tpl->setContent($form->getHTML());
1229 }
1230
1235 protected function initSettingsForm()
1236 {
1237 global $ilDB, $ilUser;
1238
1239 include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
1240
1241 $form = new ilPropertyFormGUI();
1242 $form->setFormAction($this->ctrl->getFormAction($this));
1243
1244 $mng = new ilTextInputGUI($this->lng->txt('cal_ch_manager'), 'mng');
1245 $mng->setInfo($this->lng->txt('cal_ch_manager_info'));
1246 $form->addItem($mng);
1247
1248 $mng->setValue(ilConsultationHourAppointments::getManager(true));
1249
1250 $form->setTitle($this->lng->txt('settings'));
1251 $form->addCommandButton('updateSettings', $this->lng->txt('save'));
1252 // $form->addCommandButton('appointmentList', $this->lng->txt('cancel'));
1253 return $form;
1254 }
1255
1259 public function updateSettings()
1260 {
1261 global $ilDB, $ilCtrl, $ilUser, $tpl, $ilTabs;
1262
1263 $form = $this->initSettingsForm();
1264 if ($form->checkInput()) {
1265 $mng = $form->getInput('mng');
1267 ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
1268 $ilCtrl->redirect($this, 'settings');
1269 } else {
1270 $ilTabs->activateTab('ch_settings');
1271
1272 ilUtil::sendFailure($this->lng->txt('cal_ch_unknown_user'));
1273 $field = $form->getItemByPostVar('mng');
1274 $field->setValue($mng);
1275 $tpl->setContent($form->getHTML());
1276 return;
1277 }
1278 }
1279 }
1280}
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
$tpl
Definition: ilias.php:10
if(!isset( $_REQUEST[ 'ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
$users
Definition: authpage.php:44
$_GET["client_id"]
$_POST["username"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_TRANSLATION_SYSTEM
const IL_CAL_FREQ_MONTHLY
const IL_CAL_FREQ_WEEKLY
const IL_CAL_UNIX
const IL_CAL_DAY
Booking definition.
static lookupBookingsOfUser($a_app_ids, $a_usr_id, ilDateTime $start=null)
Lookup bookings if user.
static getInstanceByCalendarEntryId($a_id)
Get instance by calendar entry.
static removeObsoleteEntries()
Remove unused booking entries.
static lookupBookingsForAppointment($a_app_id)
Lookup booked users for appointment @global type $ilDB.
Booking period Used for calculation of recurring events.
static _deleteByAppointmentId($a_app_id)
Delete appointment assignment.
Model for a calendar entry.
Calculates an ilDateList for a given calendar entry and recurrence rule.
static initDefaultCalendarByType($a_type_id, $a_usr_id, $a_title, $a_create=false)
Init the default calendar for given type and user.
Confirmation screen class.
static getAppointmentIds($a_user_id, $a_context_id=null, $a_start=null, $a_type=null, $a_check_owner=true)
Get all appointment ids.
static getAppointmentIdsByGroup($a_user_id, $a_ch_group_id, ilDateTime $start=null)
Get appointment ids by consultation hour group.
static getManager($a_as_name=false, $a_full_name=false, $a_user_id=null)
Get consultation hour manager for current user or specific user.
static getManagedUsers()
Get all managed consultation hours users for current users.
static setManager($a_user_name)
Set consultation hour manager for current user.
static getGroupsOfUser($a_user_id)
Get a all groups of an user.
static getCountGroupsOfUser($a_user_id)
Get number of consultation hour groups @global type $ilDB.
static getGroupSelectOptions($a_user_id)
Get group selection options.
static findCalendarAppointmentsForBooking(\ilBookingEntry $booking, \ilDateTime $start, \ilDateTime $end)
static cancelBooking($a_usr_id, $a_app_id, $a_send_notification=true)
Cancel a booking.
static bookAppointment($a_usr_id, $a_app_id)
Book an appointment.
Consultation hours editor.
editGroup(ilPropertyFormGUI $form=null)
Edit group @global type $ilCtrl.
confirmDelete()
confirm delete for multiple entries
updateGroup()
Update group @global type $ilCtrl @global type $tpl @global type $ilTabs.
rejectBooking($a_send_notification=true)
rewriteBookingIdsForAppointments(\ilBookingEntry $booking, $appointments, \ilPropertyFormGUI $form)
appointmentList()
Show settings of consultation hours.
groupList()
Show consultation hour group @global type $ilToolbar.
edit()
Edit multiple sequence items.
confirmRejectBooking($a_send_notification=true)
Show delete booking confirmation.
addGroup(ilPropertyFormGUI $form=null)
Show add group form @global type $ilToolbar @global type $ilTabs.
showProfile()
show public profile of given user
sendInfoAboutUnassignedUsers($unassigned)
Send info message about unassigned users.
searchUsersForAppointments()
start searching for users
assignUsersToAppointments(array $users)
Assign users to multiple appointments.
bookingList()
Show list of bookings.
updateMulti()
Update multiple sequence items.
confirmDeleteBooking()
Show delete booking confirmation.
assignUsersToAppointment(array $users, $a_app=0, $a_redirect=true)
Assign users to an appointment.
initGroupForm($a_group_id=0)
Init new/update group form.
setSubTabs()
Set sub tabs @global type $ilTabs @global type $ilCtrl.
createNewBookingEntry(\ilPropertyFormGUI $validate_form)
createAppointments(ilBookingEntry $booking)
Create calendar appointments.
confirmDeleteGroup()
Confirm delete @global type $ilCtrl @global type $ilTabs.
getProfileBackUrl()
Build context-sensitive profile back url.
Consultation hours administration.
List of dates.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false)
Format a date @access public.
This class represents a date/time property in a property form.
@classDescription Date and time handling
This class represents a duration (typical hh:mm:ss) property in a property form.
This class represents a hidden form property in a property form.
This class represents a number property in a property form.
static _lookupFullname($a_user_id)
Lookup Full Name.
static _getAllReferences($a_id)
get all reference ids of object
static _lookupType($a_id, $a_reference=false)
lookup object type
This class represents a property form user interface.
GUI class for public user profile presentation.
This class represents an input GUI for recurring events/appointments (course events or calendar appoi...
This class represents a selection list property in a property form.
This class represents a text area property in a property form.
This class represents a text property in a property form.
static getNamePresentation( $a_user_id, $a_user_image=false, $a_profile_link=false, $a_profile_back_link="", $a_force_first_lastname=false, $a_omit_login=false, $a_sortable=true, $a_return_data_array=false, $a_ctrl_path="ilpublicuserprofilegui")
Default behaviour is:
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
static initDomEvent()
Init YUI DomEvent.
$i
Definition: disco.tpl.php:19
$tbl
Definition: example_048.php:81
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
const IL_CAL_FREQ_DAILY
Model of calendar entry recurrcences.
global $ilCtrl
Definition: ilias.php:18
$end
Definition: saml1-acs.php:18
$ret
Definition: parser.php:6
global $lng
Definition: privfeed.php:17
$type
$url
if(isset($_POST['submit'])) $form
global $DIC
Definition: saml.php:7
global $ilDB
$ilUser
Definition: imgupload.php:18