/**
  * Cancel a booking
  * @param type $a_usr_id
  * @param type $a_app_id
  * @return bool
  */
 public static function cancelBooking($a_usr_id, $a_app_id, $a_send_notification = true)
 {
     // Delete personal copy of appointment
     include_once './Services/Calendar/classes/class.ilCalendarEntry.php';
     $app = new ilCalendarEntry($a_app_id);
     include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourAppointments.php';
     $user_apps = ilConsultationHourAppointments::getAppointmentIds($a_usr_id, $app->getContextId(), $app->getStart(), ilCalendarCategory::TYPE_CH, false);
     foreach ($user_apps as $uapp_id) {
         $uapp = new ilCalendarEntry($uapp_id);
         $uapp->delete();
         include_once './Services/Calendar/classes/class.ilCalendarCategoryAssignments.php';
         ilCalendarCategoryAssignments::_deleteByAppointmentId($uapp_id);
         break;
     }
     // Delete booking entries
     // Send notification
     $booking = new ilBookingEntry($app->getContextId());
     if ($a_send_notification) {
         $booking->cancelBooking($a_app_id, $a_usr_id);
     } else {
         $booking->deleteBooking($a_app_id, $a_usr_id);
     }
     return true;
 }
 /**
  * confirm delete for multiple entries
  */
 public function confirmDelete()
 {
     global $tpl;
     if (!isset($_REQUEST['apps'])) {
         ilUtil::sendFailure($this->lng->txt('select_one'));
         return $this->appointmentList();
     }
     include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
     $this->ctrl->saveParameter($this, array('seed', 'app_id', 'dt'));
     $confirm = new ilConfirmationGUI();
     $confirm->setFormAction($this->ctrl->getFormAction($this));
     $confirm->setHeaderText($this->lng->txt('cal_delete_app_sure'));
     $confirm->setCancel($this->lng->txt('cancel'), 'cancel');
     include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
     $bookings_available = array();
     foreach ((array) $_REQUEST['apps'] as $entry_id) {
         $entry = new ilCalendarEntry($entry_id);
         $confirm->addItem('apps[]', $entry_id, ilDatePresentation::formatDate($entry->getStart()) . ', ' . $entry->getTitle());
         include_once './Services/Booking/classes/class.ilBookingEntry.php';
         if (ilBookingEntry::lookupBookingsForAppointment($entry_id)) {
             $bookings_available[] = ilDatePresentation::formatDate($entry->getStart()) . ', ' . $entry->getTitle();
         }
     }
     if ($bookings_available) {
         ilUtil::sendInfo($this->lng->txt('cal_ch_delete_app_booking_info') . '<br />' . implode('<br />', $bookings_available));
     }
     $confirm->setConfirm($this->lng->txt('delete'), 'delete');
     $confirm->setCancel($this->lng->txt('cancel'), 'appointmentList');
     $tpl->setContent($confirm->getHTML());
 }
 /**
  * Parse Groups
  * @param array $groups
  */
 public function parse(array $appointments)
 {
     global $ilCtrl;
     $rows = array();
     $counter = 0;
     foreach ($appointments as $app) {
         include_once './Services/Calendar/classes/class.ilCalendarEntry.php';
         $cal_entry = new ilCalendarEntry($app);
         include_once './Services/Booking/classes/class.ilBookingEntry.php';
         foreach (ilBookingEntry::lookupBookingsForAppointment($app) as $user_id) {
             include_once './Services/User/classes/class.ilUserUtil.php';
             $rows[$counter]['name'] = ilUserUtil::getNamePresentation($user_id, true, true, $ilCtrl->getLinkTarget($this->getParentObject(), $this->getParentCmd()), true, true);
             $message = ilBookingEntry::lookupBookingMessage($app, $user_id);
             if (strlen(trim($message))) {
                 $rows[$counter]['comment'] = '"' . $message . '"';
             }
             $rows[$counter]['title'] = $cal_entry->getTitle();
             $rows[$counter]['start'] = $cal_entry->getStart()->get(IL_CAL_UNIX);
             $rows[$counter]['start_str'] = ilDatePresentation::formatDate($cal_entry->getStart());
             $rows[$counter]['id'] = $app . '_' . $user_id;
             ++$counter;
         }
     }
     $this->setData($rows);
 }
 /**
  * Confirmation screen for booking of consultation appointment
  */
 public function book()
 {
     global $ilUser, $tpl;
     $entry = (int) $_GET['app_id'];
     $user = (int) $_GET['bkid'];
     $this->ctrl->saveParameter($this, 'app_id');
     include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
     include_once 'Services/Booking/classes/class.ilBookingEntry.php';
     $entry = new ilCalendarEntry($entry);
     $form = $this->initFormConfirmBooking();
     $form->getItemByPostVar('date')->setValue(ilDatePresentation::formatPeriod($entry->getStart(), $entry->getEnd()));
     $form->getItemByPostVar('title')->setValue($entry->getTitle() . " (" . ilObjUser::_lookupFullname($user) . ')');
     $tpl->setContent($form->getHTML());
     return true;
 }
 /**
  * Exclusion date to ical format
  * @return 
  */
 public function toICal()
 {
     $entry = new ilCalendarEntry($this->getEntryId());
     $start = $entry->getStart();
     if ($entry->isFullday()) {
         return 'EXDATE;VALUE=DATE:' . $this->getDate()->get(IL_CAL_FKT_DATE, 'Ymd');
     } else {
         return 'EXDATE:' . $this->getDate()->get(IL_CAL_FKT_DATE, 'Ymd') . 'T' . $start->get(IL_CAL_FKT_DATE, 'his');
     }
 }
 /**
  * confirm delete for multiple entries
  */
 public function confirmDelete()
 {
     global $tpl;
     if (!isset($_POST['apps'])) {
         ilUtil::sendFailure($this->lng->txt('select_one'));
         return $this->appointmentList();
     }
     include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
     $this->ctrl->saveParameter($this, array('seed', 'app_id', 'dt'));
     $confirm = new ilConfirmationGUI();
     $confirm->setFormAction($this->ctrl->getFormAction($this));
     $confirm->setHeaderText($this->lng->txt('cal_delete_app_sure'));
     $confirm->setCancel($this->lng->txt('cancel'), 'cancel');
     include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
     foreach ($_POST['apps'] as $entry_id) {
         $entry = new ilCalendarEntry($entry_id);
         $confirm->addItem('apps[]', $entry_id, ilDatePresentation::formatDate($entry->getStart()) . ', ' . $entry->getTitle());
     }
     $confirm->setConfirm($this->lng->txt('delete'), 'delete');
     $confirm->setCancel($this->lng->txt('cancel'), 'appointmentList');
     $tpl->setContent($confirm->getHTML());
 }
 /**
  * get current number of bookings
  * @param	int		$a_entry_id
  * @param	bool	$a_check_current_user
  * @return	bool
  */
 public function isBookedOut($a_entry_id, $a_check_current_user = false)
 {
     global $ilUser;
     if ($this->getNumberOfBookings() == $this->getCurrentNumberOfBookings($a_entry_id)) {
         // check against current user
         if ($a_check_current_user) {
             if ($this->hasBooked($a_entry_id)) {
                 return false;
             }
             if ($ilUser->getId() == $this->getObjId()) {
                 return false;
             }
         }
         return true;
     }
     $deadline = $this->getDeadlineHours();
     if ($deadline) {
         include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
         $entry = new ilCalendarEntry($a_entry_id);
         if (time() + $deadline * 60 * 60 > $entry->getStart()->get(IL_CAL_UNIX)) {
             return true;
         }
     }
     return false;
 }
 /**
  * set appointments
  *
  * @access public
  * @return
  */
 public function setAppointments($a_apps)
 {
     include_once './Services/Calendar/classes/class.ilCalendarEntry.php';
     include_once './Services/Calendar/classes/class.ilCalendarRecurrences.php';
     include_once './Services/Calendar/classes/class.ilCalendarCategory.php';
     $cat = new ilCalendarCategory($this->cat_id);
     foreach ($a_apps as $cal_entry_id) {
         $entry = new ilCalendarEntry($cal_entry_id);
         $rec = ilCalendarRecurrences::_getFirstRecurrence($entry->getEntryId());
         // booking
         if ($cat->getType() == ilCalendarCategory::TYPE_CH) {
             include_once 'Services/Booking/classes/class.ilBookingEntry.php';
             $book = new ilBookingEntry($entry->getContextId());
             if ($book) {
                 $title = $entry->getTitle();
                 if ($book->isOwner()) {
                     $max = (int) $book->getNumberOfBookings();
                     $current = (int) $book->getCurrentNumberOfBookings($entry->getEntryId());
                     if ($max > 1) {
                         $title .= ' (' . $current . '/' . $max . ')';
                     } else {
                         if ($current == $max) {
                             $title .= ' (' . $this->lng->txt('cal_booked_out') . ')';
                         } else {
                             $title .= ' (' . $this->lng->txt('cal_book_free') . ')';
                         }
                     }
                 } else {
                     if ($book->hasBooked($entry->getEntryId())) {
                         $title .= ' (' . $this->lng->txt('cal_date_booked') . ')';
                     }
                 }
             }
         } else {
             $title = $entry->getPresentationTitle();
         }
         $tmp_arr['id'] = $entry->getEntryId();
         $tmp_arr['title'] = $title;
         $tmp_arr['description'] = $entry->getDescription();
         $tmp_arr['fullday'] = $entry->isFullday();
         $tmp_arr['begin'] = $entry->getStart()->get(IL_CAL_UNIX);
         $tmp_arr['end'] = $entry->getEnd()->get(IL_CAL_UNIX);
         $tmp_arr['dt_sort'] = $entry->getStart()->get(IL_CAL_UNIX);
         $tmp_arr['dt'] = ilDatePresentation::formatPeriod($entry->getStart(), $entry->getEnd());
         #$tmp_arr['duration'] = ($dur = $tmp_arr['end'] - $tmp_arr['begin']) ? $dur : 60 * 60 * 24;
         $tmp_arr['duration'] = $tmp_arr['end'] - $tmp_arr['begin'];
         if ($tmp_arr['fullday']) {
             $tmp_arr['duration'] += 60 * 60 * 24;
         }
         if (!$tmp_arr['fullday'] and $tmp_arr['end'] == $tmp_arr['begin']) {
             $tmp_arr['duration'] = '';
         }
         $tmp_arr['frequence'] = $rec->getFrequenceType();
         $tmp_arr['deletable'] = (!$entry->isAutoGenerated() and $this->is_editable);
         $appointments[] = $tmp_arr;
     }
     $this->setData($appointments ? $appointments : array());
 }
 /**
  * Confirmation screen for booking of consultation appointment
  */
 public function book()
 {
     global $ilUser, $tpl;
     $entry = (int) $_GET['app_id'];
     $user = (int) $_GET['bkid'];
     include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
     include_once 'Services/Booking/classes/class.ilBookingEntry.php';
     $entry = new ilCalendarEntry($entry);
     $booking = new ilBookingEntry($entry->getContextId());
     $user_settings = ilCalendarUserSettings::_getInstanceByUserId($ilUser->getId());
     $timezone = $ilUser->getTimeZone();
     switch ($user_settings->getTimeFormat()) {
         case ilCalendarSettings::TIME_FORMAT_24:
             $title = $entry->getStart()->get(IL_CAL_FKT_DATE, 'H:i', $timezone);
             $title .= "-" . $entry->getEnd()->get(IL_CAL_FKT_DATE, 'H:i', $timezone);
             break;
         case ilCalendarSettings::TIME_FORMAT_12:
             $title = $entry->getStart()->get(IL_CAL_FKT_DATE, 'h:ia', $timezone);
             $title .= "-" . $entry->getEnd()->get(IL_CAL_FKT_DATE, 'h:ia', $timezone);
             break;
     }
     $title .= ' ' . $entry->getTitle() . " (" . ilObjUser::_lookupFullname($user) . ')';
     include_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
     $conf = new ilConfirmationGUI();
     $conf->setFormAction($this->ctrl->getFormAction($this));
     $conf->setHeaderText($this->lng->txt('cal_confirm_booking_info'));
     $conf->setConfirm($this->lng->txt('cal_confirm_booking'), 'bookconfirmed');
     $conf->setCancel($this->lng->txt('cancel'), 'cancel');
     $conf->addItem('app_id', $entry->getEntryId(), $title);
     $tpl->setContent($conf->getHTML());
 }
Esempio n. 10
0
 /**
  * cancel calendar booking for user
  * @param	int	$a_entry_id
  * @param	int	$a_user_id
  */
 public function cancelBooking($a_entry_id, $a_user_id = false)
 {
     global $ilUser, $ilDB;
     if (!$a_user_id) {
         $a_user_id = $ilUser->getId();
     }
     // @todo do not send mails about past consultation hours
     $entry = new ilCalendarEntry($a_entry_id);
     $past = ilDateTime::_before($entry->getStart(), new ilDateTime(time(), IL_CAL_UNIX));
     if ($this->hasBooked($a_entry_id, $a_user_id) && !$past) {
         include_once 'Services/Calendar/classes/class.ilCalendarMailNotification.php';
         $mail = new ilCalendarMailNotification();
         $mail->setAppointmentId($a_entry_id);
         $mail->setRecipients(array($a_user_id));
         $mail->setType(ilCalendarMailNotification::TYPE_BOOKING_CANCELLATION);
         $mail->send();
     }
     $this->deleteBooking($a_entry_id, $a_user_id);
     return true;
 }