ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 {
58 {
59 $this->user_id = $user_id;
60 }
61 else
62 {
63 $user_id = false;
64 }
65 }
66 if(!$user_id)
67 {
68 $this->user_id = $ilUser->getId();
69 }
70
71 $this->ctrl = $ilCtrl;
72 $this->lng = $lng;
73 $this->tpl = $tpl;
74 }
75
80 public function executeCommand()
81 {
82 global $ilUser, $ilCtrl, $tpl, $ilHelp, $ilTabs;
83
84 $ilHelp->setScreenIdComponent("cal");
85
86 switch($this->ctrl->getNextClass())
87 {
88 case "ilpublicuserprofilegui":
89 include_once('./Services/User/classes/class.ilPublicUserProfileGUI.php');
90 #22168 don't send the current user if no GET user_id
91 //$profile = new ilPublicUserProfileGUI($this->user_id);
92 $profile = new ilPublicUserProfileGUI();
93 $profile->setBackUrl($this->getProfileBackUrl());
94 $ret = $ilCtrl->forwardCommand($profile);
95 $tpl->setContent($ret);
96 break;
97
98 case 'ilrepositorysearchgui':
99
100 include_once('./Services/Search/classes/class.ilRepositorySearchGUI.php');
101 $rep_search = new ilRepositorySearchGUI();
102
103 if(isset($_REQUEST['assignM']))
104 {
105 $rep_search->setCallback(
106 $this,
107 'assignUsersToAppointments',
108 array()
109 );
110 $ilCtrl->setParameter($this,'assignM',1);
111 $ilCtrl->setReturn($this,'appointmentList');
112 $ilTabs->activateSubTab('cal_ch_app_list');
113 }
114 elseif(isset($_REQUEST['grp_id']))
115 {
116 $rep_search->setCallback(
117 $this,
118 'assignUsersToGroup',
119 array()
120 );
121 $ilCtrl->saveParameter($this,'grp_id');
122 $ilCtrl->setReturn($this,'groupList');
123 $ilTabs->activateSubTab('cal_ch_app_grp');
124 }
125 elseif(isset($_REQUEST['apps']))
126 {
127 $rep_search->setCallback(
128 $this,
129 'assignUsersToAppointment',
130 array()
131 );
132 $ilCtrl->saveParameter($this,'apps');
133 $ilCtrl->setReturn($this,'appointmentList');
134 $ilTabs->activateSubTab('cal_ch_app_list');
135 }
136 $ilCtrl->forwardCommand($rep_search);
137 break;
138
139 default:
140 $tpl->setTitle($this->lng->txt("cal_ch_form_header")); // #12220
141
142 $this->setTabs();
143 if($ilUser->getId() != $this->user_id)
144 {
145 $ilCtrl->setParameter($this, 'user_id', $this->user_id);
146 }
147
148 $cmd = $this->ctrl->getCmd('appointmentList');
149 $this->$cmd();
150 }
151 }
152
157 public function getUserId()
158 {
159 return $this->user_id;
160 }
161
165 protected function searchUsersForAppointments()
166 {
167 global $ilCtrl, $ilTabs;
168
169 $_SESSION['ch_apps'] = $_REQUEST['apps'];
170
171 if(!count($_SESSION['ch_apps']))
172 {
173 ilUtil::sendFailure($this->lng->txt('select_one'),true);
174 $GLOBALS['ilCtrl']->redirect($this,'appointmentList');
175 }
176 $_REQUEST['assignM'] = 1;
177 $ilCtrl->setCmdClass('ilrepositorysearchgui');
178 $ilCtrl->setcmd('');
179 $this->executeCommand();
180 }
181
186 protected function sendInfoAboutUnassignedUsers($unassigned)
187 {
188 if(!$unassigned)
189 {
190 return true;
191 }
192 $users = array();
193 foreach($unassigned as $user_id)
194 {
195 include_once './Services/User/classes/class.ilObjUser.php';
197 }
198 ilUtil::sendInfo($this->lng->txt('cal_ch_user_assignment_failed_info').'<br />'.implode('<br />', $users),true);
199 return true;
200 }
201
206 public function assignUsersToAppointments(array $users)
207 {
208 global $ilCtrl;
209
210 $unassigned_users = array();
211 foreach($_SESSION['ch_apps'] as $app)
212 {
213 $unassigned_users = array_unique(array_merge($unassigned_users,$this->assignUsersToAppointment($users,$app,false)));
214 }
215
216 $this->sendInfoAboutUnassignedUsers($unassigned_users);
217 $ilCtrl->redirect($this,'appointmentList');
218 }
219
220
226 public function assignUsersToAppointment(array $users, $a_app = 0, $a_redirect = true)
227 {
228 global $ilCtrl;
229
230 if($a_app)
231 {
232 $app = $a_app;
233 }
234 else
235 {
236 $app = $_REQUEST['apps'];
237 }
238
239 include_once './Services/Booking/classes/class.ilBookingEntry.php';
241
242 $assigned_users = array();
243 foreach($users as $user)
244 {
245 if($booking->getCurrentNumberOfBookings($app) >= $booking->getNumberOfBookings())
246 {
247 break;
248 }
249 if(!ilBookingEntry::lookupBookingsOfUser((array) $app, $user))
250 {
251 include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourUtils.php';
253 $assigned_users[] = $user;
254 }
255 }
256
257 $unassigned_users = array_diff($users, $assigned_users);
258
259 if($a_redirect)
260 {
261 $this->sendInfoAboutUnassignedUsers($unassigned_users);
262 $ilCtrl->redirect($this,'appointmentList');
263 }
264 else
265 {
266 return $unassigned_users;
267 }
268
269 }
270
276 public function assignUsersToGroup(array $usr_ids)
277 {
278 global $ilCtrl;
279
280 $group_id = (int) $_REQUEST['grp_id'];
281
282 $tomorrow = new ilDateTime(time(),IL_CAL_UNIX);
283 $tomorrow->increment(IL_CAL_DAY,1);
284
285 // Get all future consultation hours
286 include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourAppointments.php';
287 include_once './Services/Booking/classes/class.ilBookingEntry.php';
289 $this->user_id,
290 $group_id,
291 $tomorrow
292 );
293 $users = $usr_ids;
294 $assigned_users = array();
295 foreach($apps as $app)
296 {
298 foreach($users as $user)
299 {
300 if($booking->getCurrentNumberOfBookings($app) >= $booking->getNumberOfBookings())
301 {
302 break;
303 }
304 if(!ilBookingEntry::lookupBookingsOfUser($apps, $user))
305 {
306 include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourUtils.php';
308 $assigned_users[] = $user;
309 }
310 }
311 }
312
313 $this->sendInfoAboutUnassignedUsers(array_diff($users, $assigned_users));
314 $ilCtrl->redirect($this,'bookingList');
315 }
316
317
322 protected function groupList()
323 {
324 global $ilToolbar, $ilTabs, $tpl;
325
326 $ilToolbar->setFormAction($this->ctrl->getFormAction($this));
327 $ilToolbar->addButton($this->lng->txt('cal_ch_add_grp'),$this->ctrl->getLinkTarget($this,'addGroup'));
328
329 $this->setSubTabs();
330 $ilTabs->activateSubTab('cal_ch_app_grp');
331
332 include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourGroupTableGUI.php';
333 include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourGroups.php';
334 $gtbl = new ilConsultationHourGroupTableGUI($this,'groupList',$this->getUserId());
336
337 $tpl->setContent($gtbl->getHTML());
338 }
339
345 protected function addGroup(ilPropertyFormGUI $form = null)
346 {
347 global $ilTabs, $tpl;
348
349 $this->setSubTabs();
350 $ilTabs->activateSubTab('cal_ch_app_grp');
351
352 if($form == null)
353 {
354 $form = $this->initGroupForm();
355 }
356 $tpl->setContent($form->getHTML());
357 }
358
362 protected function saveGroup()
363 {
364 $form = $this->initGroupForm();
365 if($form->checkInput())
366 {
367 include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourGroup.php';
368 $group = new ilConsultationHourGroup();
369 $group->setTitle($form->getInput('title'));
370 $group->setMaxAssignments($form->getInput('multiple'));
371 $group->setUserId($this->getUserId());
372 $group->save();
373
374 ilUtil::sendSuccess($GLOBALS['lng']->txt('settings_saved'),true);
375 $GLOBALS['ilCtrl']->redirect($this,'groupList');
376 }
377
378 ilUtil::sendFailure($GLOBALS['lng']->txt('err_check_input'),true);
379 $this->addGroup($form);
380 }
381
387 protected function editGroup(ilPropertyFormGUI $form = null)
388 {
389 global $ilCtrl, $tpl, $ilTabs;
390
391 $ilCtrl->setParameter($this,'grp_id',(int) $_REQUEST['grp_id']);
392 $this->setSubTabs();
393 $ilTabs->activateSubTab('cal_ch_app_grp');
394
395 if($form == null)
396 {
397 $form = $this->initGroupForm((int) $_REQUEST['grp_id']);
398 }
399 $tpl->setContent($form->getHTML());
400 }
401
408 protected function updateGroup()
409 {
410 global $ilCtrl, $tpl, $ilTabs;
411
412 $ilCtrl->setParameter($this,'grp_id',(int) $_REQUEST['grp_id']);
413
414 $form = $this->initGroupForm((int) $_REQUEST['grp_id']);
415 if($form->checkInput())
416 {
417 include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourGroup.php';
418 $group = new ilConsultationHourGroup((int) $_REQUEST['grp_id']);
419 $group->setTitle($form->getInput('title'));
420 $group->setMaxAssignments($form->getInput('multiple'));
421 $group->setUserId($this->getUserId());
422 $group->update();
423
424 ilUtil::sendSuccess($GLOBALS['lng']->txt('settings_saved'),true);
425 $GLOBALS['ilCtrl']->redirect($this,'groupList');
426 }
427
428 ilUtil::sendFailure($GLOBALS['lng']->txt('err_check_input'),true);
429 $this->editGroup($form);
430 }
431
437 protected function confirmDeleteGroup()
438 {
439 global $ilCtrl, $ilTabs, $tpl;
440
441 $ilCtrl->setParameter($this,'grp_id',(int) $_REQUEST['grp_id']);
442 $groups = array((int) $_REQUEST['grp_id']);
443
444 $this->setSubTabs();
445 $ilTabs->activateSubTab('cal_ch_app_grp');
446
447
448 include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
449 $confirm = new ilConfirmationGUI();
450 $confirm->setFormAction($ilCtrl->getFormAction($this));
451 $confirm->setHeaderText($GLOBALS['lng']->txt('cal_ch_grp_delete_sure'));
452 $confirm->setConfirm($GLOBALS['lng']->txt('delete'), 'deleteGroup');
453 $confirm->setCancel($GLOBALS['lng']->txt('cancel'), 'groupList');
454
455 foreach($groups as $grp_id)
456 {
457 include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourGroup.php';
458 $group = new ilConsultationHourGroup($grp_id);
459
460 $confirm->addItem('groups[]', $grp_id, $group->getTitle());
461 }
462 $tpl->setContent($confirm->getHTML());
463 }
464
468 protected function deleteGroup()
469 {
470 global $ilCtrl;
471
472 foreach((array) $_REQUEST['groups'] as $grp_id)
473 {
474 include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourGroup.php';
475 $group = new ilConsultationHourGroup($grp_id);
476 $group->delete();
477 }
478 ilUtil::sendSuccess($GLOBALS['lng']->txt('cal_ch_grp_deleted'));
479 $ilCtrl->redirect($this,'groupList');
480 }
481
485 protected function initGroupForm($a_group_id = 0)
486 {
487 include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourGroup.php';
488 $group = new ilConsultationHourGroup($a_group_id);
489
490 include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
491 $form = new ilPropertyFormGUI();
492 $form->setFormAction($GLOBALS['ilCtrl']->getFormAction($this));
493
494 if($a_group_id)
495 {
496 $form->setTitle($GLOBALS['lng']->txt('cal_ch_grp_update_tbl'));
497 $form->addCommandButton('updateGroup', $GLOBALS['lng']->txt('save'));
498 $form->addCommandButton('groupList', $GLOBALS['lng']->txt('cancel'));
499 }
500 else
501 {
502 $form->setTitle($GLOBALS['lng']->txt('cal_ch_grp_add_tbl'));
503 $form->addCommandButton('saveGroup', $GLOBALS['lng']->txt('save'));
504 $form->addCommandButton('appointmentList', $GLOBALS['lng']->txt('cancel'));
505 }
506
507 $title = new ilTextInputGUI($GLOBALS['lng']->txt('title'),'title');
508 $title->setMaxLength(128);
509 $title->setSize(40);
510 $title->setRequired(true);
511 $title->setValue($group->getTitle());
512 $form->addItem($title);
513
514 $multiple = new ilNumberInputGUI($GLOBALS['lng']->txt('cal_ch_grp_multiple'),'multiple');
515 $multiple->setRequired(true);
516 $multiple->setMinValue(1);
517 $multiple->setSize(1);
518 $multiple->setMaxLength(2);
519 $multiple->setInfo($GLOBALS['lng']->txt('cal_ch_grp_multiple_info'));
520 $multiple->setValue($group->getMaxAssignments());
521 $form->addItem($multiple);
522
523 return $form;
524 }
525
529 protected function bookingList()
530 {
531 global $ilToolbar, $ilTabs, $tpl;
532
533 $this->setSubTabs();
534 $ilTabs->activateSubTab('cal_ch_app_bookings');
535
536 include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourBookingTableGUI.php';
537 $btable = new ilConsultationHourBookingTableGUI($this,'bookingList',$this->getUserId());
539 $tpl->setContent($btable->getHTML());
540 }
541
545 protected function confirmDeleteBooking()
546 {
547 $this->confirmRejectBooking(false);
548 }
549
553 protected function confirmRejectBooking($a_send_notification = true)
554 {
555 global $ilTabs, $tpl;
556
557 $this->setSubTabs();
558 $ilTabs->activateSubTab('cal_ch_app_bookings');
559
560 include_once('./Services/Utilities/classes/class.ilConfirmationGUI.php');
561
562 $confirm = new ilConfirmationGUI();
563 $confirm->setFormAction($this->ctrl->getFormAction($this));
564
565 if($a_send_notification)
566 {
567 ilUtil::sendInfo($this->lng->txt('cal_ch_cancel_booking_info'));
568 $confirm->setHeaderText($this->lng->txt('cal_ch_cancel_booking_sure'));
569 $confirm->setConfirm($this->lng->txt('cal_ch_reject_booking'), 'rejectBooking');
570 }
571 else
572 {
573 ilUtil::sendInfo($this->lng->txt('cal_ch_delete_booking_info'));
574 $confirm->setHeaderText($this->lng->txt('cal_ch_delete_booking_sure'));
575 $confirm->setConfirm($this->lng->txt('cal_ch_delete_booking'), 'deleteBooking');
576 }
577
578 $confirm->setCancel($this->lng->txt('cancel'),'bookingList');
579
580 include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
581 foreach((array) $_REQUEST['bookuser'] as $bookuser)
582 {
583 $ids = explode('_',$bookuser);
584
585 include_once './Services/Calendar/classes/class.ilCalendarEntry.php';
586 include_once './Services/User/classes/class.ilUserUtil.php';
587 $entry = new ilCalendarEntry($ids[0]);
588 $confirm->addItem(
589 'bookuser[]',
590 $bookuser,
592 $ids[1],
593 true,
594 false,
595 '',
596 true,
597 true
598 ).', '.ilDatePresentation::formatDate($entry->getStart())
599 );
600 }
601 $tpl->setContent($confirm->getHTML());
602 }
603
607 protected function deleteBooking()
608 {
609 $this->rejectBooking(false);
610 }
611
616 protected function rejectBooking($a_send_notification = true)
617 {
618 global $ilCtrl;
619
620 foreach((array) $_REQUEST['bookuser'] as $bookuser)
621 {
622 $ids = explode('_',$bookuser);
623
624 include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourUtils.php';
625 ilConsultationHourUtils::cancelBooking($ids[1],$ids[0],$a_send_notification);
626 }
627 if($a_send_notification)
628 {
629 ilUtil::sendSuccess($this->lng->txt('cal_ch_canceled_bookings'),true);
630 }
631 else
632 {
633 ilUtil::sendSuccess($this->lng->txt('cal_ch_deleted_bookings'),true);
634 }
635 $ilCtrl->redirect($this,'bookingList');
636 }
637
643 protected function appointmentList()
644 {
645 global $ilToolbar, $ilHelp, $ilTabs;
646
647 $ilHelp->setScreenId("consultation_hours");
648
649 $ilToolbar->setFormAction($this->ctrl->getFormAction($this));
650 $ilToolbar->addButton($this->lng->txt('cal_ch_add_sequence'),$this->ctrl->getLinkTarget($this,'createSequence'));
651
652 $this->setSubTabs();
653 $ilTabs->activateSubTab('cal_ch_app_list');
654
655 include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHoursTableGUI.php';
656 $tbl = new ilConsultationHoursTableGUI($this,'appointmentList',$this->getUserId());
657 $tbl->parse();
658 $this->tpl->setContent($tbl->getHTML());
659 }
660
665 protected function createSequence()
666 {
667 $this->initFormSequence(self::MODE_CREATE);
668
669 $this->booking = new ilBookingEntry();
670 $this->form->getItemByPostVar('bo')->setValue($this->booking->getNumberOfBookings());
671 $this->form->getItemByPostVar('ap')->setValue(1);
672 $this->form->getItemByPostVar('du')->setMinutes(15);
673 $this->form->getItemByPostVar('st')->setDate(
674 new ilDateTime(mktime(8,0,0,date('n',time()),date('d',time()),date('Y',time())),IL_CAL_UNIX));
675
676 $this->tpl->setContent($this->form->getHTML());
677 }
678
684 protected function initFormSequence($a_mode)
685 {
686 include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
687
688 include_once('./Services/YUI/classes/class.ilYuiUtil.php');
690
691 $this->form = new ilPropertyFormGUI();
692 $this->form->setFormAction($this->ctrl->getFormAction($this));
693
694 switch($a_mode)
695 {
697 $this->form->setTitle($this->lng->txt('cal_ch_add_sequence'));
698 $this->form->addCommandButton('saveSequence', $this->lng->txt('save'));
699 $this->form->addCommandButton('appointmentList', $this->lng->txt('cancel'));
700 break;
701
702 /*
703 case self::MODE_UPDATE:
704 $this->form->setTitle($this->lng->txt('cal_ch_edit_sequence'));
705 $this->form->addCommandButton('updateSequence', $this->lng->txt('save'));
706 $this->form->addCommandButton('appointmentList', $this->lng->txt('cancel'));
707 break;
708 */
709
710 case self::MODE_MULTI:
711 $this->form->setTitle($this->lng->txt('cal_ch_multi_edit_sequence'));
712 $this->form->addCommandButton('updateMulti', $this->lng->txt('save'));
713 $this->form->addCommandButton('appointmentList', $this->lng->txt('cancel'));
714 break;
715 }
716
717 // in case of existing groups show a selection
718 include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourGroups.php';
720 {
721 $group = new ilSelectInputGUI($this->lng->txt('cal_ch_grp_selection'),'grp');
722 $group->setOptions($options);
723 $group->setRequired(false);
724 $this->form->addItem($group);
725 }
726
727 // Title
728 $ti = new ilTextInputGUI($this->lng->txt('title'),'ti');
729 $ti->setSize(32);
730 $ti->setMaxLength(128);
731 $ti->setRequired(true);
732 $this->form->addItem($ti);
733
734 if($a_mode != self::MODE_MULTI)
735 {
736 // Start
737 include_once './Services/Form/classes/class.ilDateTimeInputGUI.php';
738 $dur = new ilDateTimeInputGUI($this->lng->txt('cal_start'),'st');
739 $dur->setShowTime(true);
740 $dur->setRequired(true);
741 $this->form->addItem($dur);
742
743 // Duration
744 $du = new ilDurationInputGUI($this->lng->txt('cal_ch_duration'),'du');
745 $du->setShowMinutes(true);
746 $du->setShowHours(true);
747 $this->form->addItem($du);
748
749 // Number of appointments
750 $nu = new ilNumberInputGUI($this->lng->txt('cal_ch_num_appointments'),'ap');
751 $nu->setInfo($this->lng->txt('cal_ch_num_appointments_info'));
752 $nu->setSize(2);
753 $nu->setMaxLength(2);
754 $nu->setRequired(true);
755 $nu->setMinValue(1);
756 $this->form->addItem($nu);
757
758 // Recurrence
759 include_once('./Services/Calendar/classes/Form/class.ilRecurrenceInputGUI.php');
760 $rec = new ilRecurrenceInputGUI($this->lng->txt('cal_recurrences'),'frequence');
761 $rec->setEnabledSubForms(
762 array(
766 )
767 );
768 $this->form->addItem($rec);
769 }
770
771 // Number of bookings
772 $nu = new ilNumberInputGUI($this->lng->txt('cal_ch_num_bookings'),'bo');
773 $nu->setSize(2);
774 $nu->setMaxLength(2);
775 $nu->setMinValue(1);
776 $nu->setRequired(true);
777 $this->form->addItem($nu);
778
779 // Deadline
780 $dead = new ilDurationInputGUI($this->lng->txt('cal_ch_deadline'),'dead');
781 $dead->setInfo($this->lng->txt('cal_ch_deadline_info'));
782 $dead->setShowMinutes(false);
783 $dead->setShowHours(true);
784 $dead->setShowDays(true);
785 $this->form->addItem($dead);
786
787 // Location
788 $lo = new ilTextInputGUI($this->lng->txt('cal_where'),'lo');
789 $lo->setSize(32);
790 $lo->setMaxLength(128);
791 $this->form->addItem($lo);
792
793 // Description
794 $de = new ilTextAreaInputGUI($this->lng->txt('description'),'de');
795 $de->setRows(10);
796 $de->setCols(60);
797 $this->form->addItem($de);
798
799 // Target Object
800 $tgt = new ilTextInputGUI($this->lng->txt('cal_ch_target_object'),'tgt');
801 $tgt->setInfo($this->lng->txt('cal_ch_target_object_info'));
802 $tgt->setSize(16);
803 $tgt->setMaxLength(128);
804 $this->form->addItem($tgt);
805 }
806
811 protected function saveSequence()
812 {
813 global $ilObjDataCache;
814
815 $this->initFormSequence(self::MODE_CREATE);
816
817 if($this->form->checkInput())
818 {
819 $this->form->setValuesByPost();
820
821 $booking = new ilBookingEntry();
822 $booking->setObjId($this->getUserId());
823 $booking->setNumberOfBookings($this->form->getInput('bo'));
824
825 $deadline = $this->form->getInput('dead');
826 $deadline = $deadline['dd'] * 24 + $deadline['hh'];
827 $booking->setDeadlineHours($deadline);
828
829 // consultation hour group
830 include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourGroups.php';
832 {
833 $booking->setBookingGroup((int) $this->form->getInput('grp'));
834 }
835
836 $tgt = explode(',',$this->form->getInput('tgt'));
837 $obj_ids = array();
838 foreach((array) $tgt as $ref_id)
839 {
840 if(!trim($ref_id))
841 {
842 continue;
843 }
844 $obj_id = $ilObjDataCache->lookupObjId($ref_id);
845 $type = ilObject::_lookupType($obj_id);
846 $valid_types = array('crs','grp');
847 if(!$obj_id or !in_array($type, $valid_types))
848 {
849 ilUtil::sendFailure($this->lng->txt('cal_ch_unknown_repository_object'));
850 $this->tpl->setContent($this->form->getHTML());
851 return;
852 }
853
854 $obj_ids[] = $obj_id;
855 }
856 $booking->setTargetObjIds($obj_ids);
857
858 $booking->save();
860
861 ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
862 $this->ctrl->redirect($this,'appointmentList');
863 }
864 else
865 {
866 $this->form->setValuesByPost();
867 $this->tpl->setContent($this->form->getHTML());
868 }
869 }
870
877 {
878 include_once './Services/Calendar/classes/class.ilDateList.php';
879 $concurrent_dates = new ilDateList(ilDateList::TYPE_DATETIME);
880 $start = clone $this->form->getItemByPostVar('st')->getDate();
881 for($i = 0; $i < $this->form->getItemByPostVar('ap')->getValue(); $i++)
882 {
883 $concurrent_dates->add(clone $start);
884
885 $start->increment(ilDateTime::MINUTE,$this->form->getItemByPostVar('du')->getMinutes());
886 $start->increment(ilDateTime::HOUR,$this->form->getItemByPostVar('du')->getHours());
887 #$start = new ilDateTime(,IL_CAL_UNIX);
888 }
889
890 include_once './Services/Calendar/classes/class.ilCalendarUtil.php';
891 $def_cat = ilCalendarUtil::initDefaultCalendarByType(ilCalendarCategory::TYPE_CH,$this->getUserId(),$this->lng->txt('cal_ch_personal_ch'),true);
892
893 // Add calendar appointment for each
894 include_once './Services/Calendar/classes/class.ilCalendarCategoryAssignments.php';
895 include_once './Services/Calendar/classes/class.ilCalendarEntry.php';
896 include_once './Services/Calendar/classes/class.ilCalendarRecurrenceCalculator.php';
897 include_once './Services/Booking/classes/class.ilBookingPeriod.php';
898
899 $num_appointments = 0;
900 foreach($concurrent_dates as $dt)
901 {
902 if($num_appointments >= self::MAX_APPOINTMENTS_PER_SEQUENCE)
903 {
904 break;
905 }
906
907 $end = clone $dt;
908 $end->increment(ilDateTime::MINUTE,$this->form->getItemByPostVar('du')->getMinutes());
909 $end->increment(ilDateTime::HOUR,$this->form->getItemByPostVar('du')->getHours());
910
912 new ilBookingPeriod($dt,$end),
913 $this->form->getItemByPostVar('frequence')->getRecurrence()
914 );
915
916 // Calculate with one year limit
917 $limit = clone $dt;
918 $limit->increment(ilDateTime::YEAR,1);
919
920 $date_list = $calc->calculateDateList($dt,$limit);
921
922 $num = 0;
923 foreach($date_list as $app_start)
924 {
925 $app_end = clone $app_start;
926 $app_end->increment(ilDateTime::MINUTE,$this->form->getItemByPostVar('du')->getMinutes());
927 $app_end->increment(ilDateTime::HOUR,$this->form->getItemByPostVar('du')->getHours());
928
929
930 $entry = new ilCalendarEntry();
931 $entry->setContextId($booking->getId());
932 $entry->setTitle($this->form->getInput('ti'));
933 $entry->setSubtitle("#consultationhour#"); // dynamic, see ilCalendarEntry
934 $entry->setDescription($this->form->getInput('de'));
935 $entry->setLocation($this->form->getInput('lo'));
936 $entry->setStart($app_start);
937 $entry->setEnd($app_end);
938
939 $entry->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
940 $entry->save();
941
942 $cat_assign = new ilCalendarCategoryAssignments($entry->getEntryId());
943 $cat_assign->addAssignment($def_cat->getCategoryID());
944
945 $num_appointments++;
946 }
947 }
948 }
949
954 protected function setTabs()
955 {
956 global $ilTabs, $ilUser, $ilCtrl;
957
958 $ilCtrl->setParameter($this, 'user_id', '');
959 $ilTabs->addTab('consultation_hours_'.$ilUser->getId(), $this->lng->txt('cal_ch_ch'), $this->ctrl->getLinkTarget($this,'appointmentList'));
960
962 {
963 $ilCtrl->setParameter($this, 'user_id', $user_id);
964 $ilTabs->addTab('consultation_hours_'.$user_id, $this->lng->txt('cal_ch_ch').': '.$login, $this->ctrl->getLinkTarget($this,'appointmentList'));
965 }
966 $ilCtrl->setParameter($this, 'user_id', '');
967
968 $ilTabs->addTab('ch_settings', $this->lng->txt('settings'), $this->ctrl->getLinkTarget($this,'settings'));
969
970 $ilTabs->activateTab('consultation_hours_'.$this->getUserId());
971 }
972
978 protected function setSubTabs()
979 {
980 global $ilTabs, $ilCtrl;
981
982 $ilCtrl->setParameter($this,'user_id',$this->getUserId());
983 $ilTabs->addSubTab('cal_ch_app_list',$this->lng->txt('cal_ch_app_list'),$ilCtrl->getLinkTarget($this,'appointmentList'));
984 $ilTabs->addSubTab('cal_ch_app_grp',$this->lng->txt('cal_ch_app_grp'),$ilCtrl->getLinkTarget($this,'groupList'));
985 $ilTabs->addSubTab('cal_ch_app_bookings',$this->lng->txt('cal_ch_app_bookings'),$ilCtrl->getLinkTarget($this,'bookingList'));
986 }
987
991 public function edit()
992 {
993 global $ilTabs;
994
995 if(!isset($_REQUEST['apps']))
996 {
997 ilUtil::sendFailure($this->lng->txt('select_one'));
998 return $this->appointmentList();
999 }
1000
1001 $this->initFormSequence(self::MODE_MULTI);
1002
1003 if($_REQUEST['apps'] && !is_array($_REQUEST['apps']))
1004 {
1005 $_REQUEST['apps'] = explode(';', $_REQUEST['apps']);
1006 }
1007
1008 $hidden = new ilHiddenInputGUI('apps');
1009 $hidden->setValue(implode(';', $_REQUEST['apps']));
1010 $this->form->addItem($hidden);
1011
1012 include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
1013 $first = $_REQUEST['apps'];
1014 $first = array_shift($_REQUEST['apps']);
1015 $entry = new ilCalendarEntry($first);
1016
1017 $this->form->getItemByPostVar('ti')->setValue($entry->getTitle());
1018 $this->form->getItemByPostVar('lo')->setValue($entry->getLocation());
1019 $this->form->getItemByPostVar('de')->setValue($entry->getDescription());
1020
1021 include_once 'Services/Booking/classes/class.ilBookingEntry.php';
1022 $booking = new ilBookingEntry($entry->getContextId());
1023
1024 $this->form->getItemByPostVar('bo')->setValue($booking->getNumberOfBookings());
1025
1026 $ref_ids = array();
1027 foreach($booking->getTargetObjIds() as $obj_id)
1028 {
1029 $refs = ilObject::_getAllReferences($obj_id);
1030 $ref_ids[] = end($refs);
1031 }
1032 $this->form->getItemByPostVar('tgt')->setValue(implode(',',$ref_ids));
1033
1034 $deadline = $booking->getDeadlineHours();
1035 $this->form->getItemByPostVar('dead')->setDays(floor($deadline/24));
1036 $this->form->getItemByPostVar('dead')->setHours($deadline%24);
1037
1038 if($booking->getBookingGroup())
1039 {
1040 $this->form->getItemByPostVar('grp')->setValue($booking->getBookingGroup());
1041 }
1042
1043 $this->tpl->setContent($this->form->getHTML());
1044 }
1045
1050 protected function updateMulti()
1051 {
1052 global $ilObjDataCache;
1053
1054 $this->initFormSequence(self::MODE_MULTI);
1055
1056 if($this->form->checkInput())
1057 {
1058 $this->form->setValuesByPost();
1059 $apps = explode(';', $_POST['apps']);
1060
1061 include_once 'Services/Booking/classes/class.ilBookingEntry.php';
1062 include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
1063
1064 // do collision-check if max bookings were reduced
1065 // no collision check
1066 $first = $apps;
1067 $first = array_shift($first);
1069 #if($this->form->getInput('bo') < $entry->getNumberOfBookings())
1070 #{
1071 # $this->edit();
1072 # return;
1073 #}
1074
1075 // create new context
1076 $booking = new ilBookingEntry();
1077
1078 $booking->setObjId($this->getUserId());
1079 $booking->setNumberOfBookings($this->form->getInput('bo'));
1080
1081 $deadline = $this->form->getInput('dead');
1082 $deadline = $deadline['dd']*24+$deadline['hh'];
1083 $booking->setDeadlineHours($deadline);
1084
1085 $tgt = explode(',',$this->form->getInput('tgt'));
1086 $obj_ids = array();
1087 foreach((array) $tgt as $ref_id)
1088 {
1089 if(!trim($ref_id))
1090 {
1091 continue;
1092 }
1093 $obj_id = $ilObjDataCache->lookupObjId($ref_id);
1094 $type = ilObject::_lookupType($obj_id);
1095 $valid_types = array('crs','grp');
1096 if(!$obj_id or !in_array($type, $valid_types))
1097 {
1098 ilUtil::sendFailure($this->lng->txt('cal_ch_unknown_repository_object'));
1099 $this->edit();
1100 return;
1101 }
1102 $obj_ids[] = $obj_id;
1103 }
1104 $booking->setTargetObjIds($obj_ids);
1105
1106 include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourGroups.php';
1108 {
1109 $booking->setBookingGroup($this->form->getInput('grp'));
1110 }
1111 $booking->save();
1112
1113
1114 // update entries
1115 $title = $this->form->getInput('ti');
1116 $location = $this->form->getInput('lo');
1117 $description = $this->form->getInput('de');
1118
1119 foreach($apps as $item_id)
1120 {
1121 $entry = new ilCalendarEntry($item_id);
1122 $entry->setContextId($booking->getId());
1123 $entry->setTitle($title);
1124 $entry->setLocation($location);
1125 $entry->setDescription($description);
1126 $entry->update();
1127 }
1128
1130
1131 ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
1132 $this->ctrl->redirect($this,'appointmentList');
1133 }
1134 $this->tpl->setContent($this->form->getHTML());
1135 }
1136
1140 public function confirmDelete()
1141 {
1142 global $tpl;
1143
1144 if(!isset($_REQUEST['apps']))
1145 {
1146 ilUtil::sendFailure($this->lng->txt('select_one'));
1147 return $this->appointmentList();
1148 }
1149
1150 include_once('./Services/Utilities/classes/class.ilConfirmationGUI.php');
1151
1152
1153 $this->ctrl->saveParameter($this,array('seed','app_id','dt'));
1154
1155 $confirm = new ilConfirmationGUI();
1156 $confirm->setFormAction($this->ctrl->getFormAction($this));
1157 $confirm->setHeaderText($this->lng->txt('cal_delete_app_sure'));
1158 $confirm->setCancel($this->lng->txt('cancel'),'cancel');
1159
1160 include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
1161
1162 $bookings_available = array();
1163 foreach((array) $_REQUEST['apps'] as $entry_id)
1164 {
1165 $entry = new ilCalendarEntry($entry_id);
1166 $confirm->addItem('apps[]', $entry_id, ilDatePresentation::formatDate($entry->getStart()).', '.$entry->getTitle());
1167
1168 include_once './Services/Booking/classes/class.ilBookingEntry.php';
1170 {
1171 $bookings_available[] = ilDatePresentation::formatDate($entry->getStart()).', '.$entry->getTitle();
1172 }
1173 }
1174
1175 if($bookings_available)
1176 {
1177 ilUtil::sendInfo($this->lng->txt('cal_ch_delete_app_booking_info').'<br />'.implode('<br />',$bookings_available));
1178 }
1179
1180 $confirm->setConfirm($this->lng->txt('delete'),'delete');
1181 $confirm->setCancel($this->lng->txt('cancel'),'appointmentList');
1182
1183 $tpl->setContent($confirm->getHTML());
1184 }
1185
1189 public function delete()
1190 {
1191 if(!isset($_POST['apps']))
1192 {
1193 ilUtil::sendFailure($this->lng->txt('select_one'));
1194 return $this->appointmentList();
1195 }
1196
1197 include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
1198 include_once 'Services/Calendar/classes/class.ilCalendarCategoryAssignments.php';
1199 foreach($_POST['apps'] as $entry_id)
1200 {
1201 // cancel booking for users
1203 if($booking)
1204 {
1205 foreach($booking->getCurrentBookings($entry_id) as $user_id)
1206 {
1207 include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourUtils.php';
1209 }
1210 }
1211 // remove calendar entries
1212 include_once './Services/Calendar/classes/class.ilCalendarEntry.php';
1213 $entry = new ilCalendarEntry($entry_id);
1214 $entry->delete();
1215
1217 }
1218
1220
1221 ilUtil::sendSuccess($this->lng->txt('cal_deleted_app'), true);
1222 $this->ctrl->redirect($this, 'appointmentList');
1223 }
1224
1228 public function showProfile()
1229 {
1230 global $tpl, $ilTabs, $ilCtrl;
1231
1232 $ilTabs->clearTargets();
1233
1234 $user_id = (int)$_GET['user'];
1235
1236 include_once 'Services/User/classes/class.ilPublicUserProfileGUI.php';
1237 $profile = new ilPublicUserProfileGUI($user_id);
1238 $profile->setBackUrl($this->getProfileBackUrl());
1239 $tpl->setContent($ilCtrl->getHTML($profile));
1240 }
1241
1247 protected function getProfileBackUrl()
1248 {
1249 // from repository
1250 if(isset($_REQUEST["ref_id"]))
1251 {
1252 $url = $this->ctrl->getLinkTargetByClass('ilCalendarMonthGUI');
1253 }
1254 // from panel
1255 else if(isset($_GET['panel']))
1256 {
1257 $url = $this->ctrl->getLinkTargetByClass('ilCalendarPresentationGUI');
1258 }
1259 // from appointments
1260 else
1261 {
1262 $url = $this->ctrl->getLinkTarget($this, 'appointmentList');
1263 }
1264 return $url;
1265 }
1266
1270 public function settings()
1271 {
1272 global $tpl, $ilTabs, $ilHelp;
1273
1274 $ilHelp->setScreenId("consultation_hours_settings");
1275 $ilTabs->activateTab('ch_settings');
1276
1277 $form = $this->initSettingsForm();
1278 $tpl->setContent($form->getHTML());
1279 }
1280
1285 protected function initSettingsForm()
1286 {
1287 global $ilDB, $ilUser;
1288
1289 include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
1290
1291 $form = new ilPropertyFormGUI();
1292 $form->setFormAction($this->ctrl->getFormAction($this));
1293
1294 $mng = new ilTextInputGUI($this->lng->txt('cal_ch_manager'), 'mng');
1295 $mng->setInfo($this->lng->txt('cal_ch_manager_info'));
1296 $form->addItem($mng);
1297
1298 $mng->setValue(ilConsultationHourAppointments::getManager(true));
1299
1300 $form->setTitle($this->lng->txt('settings'));
1301 $form->addCommandButton('updateSettings', $this->lng->txt('save'));
1302 // $form->addCommandButton('appointmentList', $this->lng->txt('cancel'));
1303 return $form;
1304 }
1305
1309 public function updateSettings()
1310 {
1311 global $ilDB, $ilCtrl, $ilUser, $tpl, $ilTabs;
1312
1313 $form = $this->initSettingsForm();
1314 if($form->checkInput())
1315 {
1316 $mng = $form->getInput('mng');
1318 {
1319 ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
1320 $ilCtrl->redirect($this, 'settings');
1321 }
1322 else
1323 {
1324 $ilTabs->activateTab('ch_settings');
1325
1326 ilUtil::sendFailure($this->lng->txt('cal_ch_unknown_user'));
1327 $field = $form->getItemByPostVar('mng');
1328 $field->setValue($mng);
1329 $tpl->setContent($form->getHTML());
1330 return;
1331 }
1332 }
1333 }
1334}
1335?>
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
global $tpl
Definition: ilias.php:8
$location
Definition: buildRTE.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 getAppointmentIdsByGroup($a_user_id, $a_ch_group_id, ilDateTime $start=null)
Get appointment ids by consultation hour group.
static getManager($a_as_name=false)
Get consultation hour manager for current 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 getAppointmentIds($a_user_id, $a_context_id=NULL, $a_start=NULL, $a_type=NULL, $a_check_owner=true)
Get all appointment ids.
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 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)
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.
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)
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)
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.
$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
$ret
Definition: parser.php:6
global $lng
Definition: privfeed.php:17
$cmd
Definition: sahs_server.php:35
$ref_id
Definition: sahs_server.php:39
$url
Definition: shib_logout.php:72
global $ilDB
if(!is_array($argv)) $options
$ilUser
Definition: imgupload.php:18