/**
  * 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);
 }
 /**
  * ask delete appointments
  *
  * @access protected
  * @return
  */
 protected function askDeleteAppointments()
 {
     global $tpl;
     if (!count($_POST['appointments'])) {
         ilUtil::sendFailure($this->lng->txt('select_one'));
         $this->details();
         return true;
     }
     include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
     $confirmation_gui = new ilConfirmationGUI();
     $this->ctrl->setParameter($this, 'category_id', (int) $_GET['category_id']);
     $confirmation_gui->setFormAction($this->ctrl->getFormAction($this));
     $confirmation_gui->setHeaderText($this->lng->txt('cal_del_app_sure'));
     $confirmation_gui->setConfirm($this->lng->txt('delete'), 'deleteAppointments');
     $confirmation_gui->setCancel($this->lng->txt('cancel'), 'details');
     include_once './Services/Calendar/classes/class.ilCalendarEntry.php';
     foreach ($_POST['appointments'] as $app_id) {
         $app = new ilCalendarEntry($app_id);
         $confirmation_gui->addItem('appointments[]', (int) $app_id, $app->getTitle());
     }
     $tpl->setContent($confirmation_gui->getHTML());
 }
 /**
  * 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;
 }
 /**
  * 
  * @return 
  */
 public function send()
 {
     global $rbacreview, $lng;
     switch ($this->getType()) {
         case self::TYPE_USER:
             $rcp = array_pop($this->getRecipients());
             $this->initLanguage($rcp);
             $this->getLanguage()->loadLanguageModule('dateplaner');
             $this->initMail();
             $this->setSubject(sprintf($this->getLanguageText('cal_mail_notification_subject'), $this->getAppointment()->getTitle()));
             $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
             $this->appendBody("\n\n");
             $this->appendBody($this->getLanguageText('cal_mail_notification_body'));
             $this->appendBody("\n\n");
             $this->appendAppointmentDetails();
             $this->appendBody("\n\n");
             $this->getMail()->appendInstallationSignature(true);
             $this->addAttachment();
             $this->sendMail($this->getRecipients(), array('system'), true);
             break;
         case self::TYPE_USER_ANONYMOUS:
             $rcp = array_pop($this->getRecipients());
             $this->setLanguage(ilLanguageFactory::_getLanguage($lng->getDefaultLanguage()));
             $this->getLanguage()->loadLanguageModule('dateplaner');
             $this->getLanguage()->loadLanguageModule('mail');
             $this->initMail();
             $this->setSubject(sprintf($this->getLanguageText('cal_mail_notification_subject'), $this->getAppointment()->getTitle()));
             $this->setBody(ilMail::getSalutation(0, $this->getLanguage()));
             $this->appendBody("\n\n");
             $this->appendBody($this->getLanguageText('cal_mail_notification_body'));
             $this->appendBody("\n\n");
             $this->appendAppointmentDetails();
             $this->appendBody("\n\n");
             $this->getMail()->appendInstallationSignature(true);
             $this->addAttachment();
             $this->sendMail($this->getRecipients(), array('email'), false);
             break;
         case self::TYPE_GRP_NEW_NOTIFICATION:
             $this->setLanguage(ilLanguageFactory::_getLanguage($lng->getDefaultLanguage()));
             $this->getLanguage()->loadLanguageModule('grp');
             $this->getLanguage()->loadLanguageModule('dateplaner');
             $this->initMail();
             $this->setSubject(sprintf($this->getLanguageText('cal_grp_new_notification_sub'), $this->getObjectTitle(true)));
             $this->setBody($this->getLanguageText('grp_notification_salutation'));
             $this->appendBody("\n\n");
             $this->appendBody(sprintf($this->getLanguageText('cal_grp_new_notification_body'), $this->getObjectTitle(true)));
             $this->appendBody("\n\n");
             $this->appendBody($this->getLanguageText('grp_mail_permanent_link'));
             $this->appendBody("\n\n");
             $this->appendAppointmentDetails();
             $this->appendBody("\n\n");
             $this->appendBody($this->createPermanentLink());
             $this->getMail()->appendInstallationSignature(true);
             $this->addAttachment();
             $this->sendMail(array('#il_grp_admin_' . $this->getRefId(), '#il_grp_member_' . $this->getRefId()), array('system'), false);
             break;
         case self::TYPE_GRP_NOTIFICATION:
             $this->setLanguage(ilLanguageFactory::_getLanguage($lng->getDefaultLanguage()));
             $this->getLanguage()->loadLanguageModule('grp');
             $this->getLanguage()->loadLanguageModule('dateplaner');
             $this->initMail();
             $this->setSubject(sprintf($this->getLanguageText('cal_grp_notification_sub'), $this->getObjectTitle(true)));
             $this->setBody($this->getLanguageText('grp_notification_salutation'));
             $this->appendBody("\n\n");
             $this->appendBody(sprintf($this->getLanguageText('cal_grp_notification_body'), $this->getObjectTitle(true)));
             $this->appendBody("\n\n");
             $this->appendAppointmentDetails();
             $this->appendBody("\n\n");
             $this->appendBody($this->getLanguageText('grp_mail_permanent_link'));
             $this->appendBody("\n\n");
             $this->appendBody($this->createPermanentLink());
             $this->getMail()->appendInstallationSignature(true);
             $this->addAttachment();
             $this->sendMail(array('#il_grp_admin_' . $this->getRefId(), '#il_grp_member_' . $this->getRefId()), array('system'), false);
             break;
         case self::TYPE_CRS_NEW_NOTIFICATION:
             $this->setLanguage(ilLanguageFactory::_getLanguage($lng->getDefaultLanguage()));
             $this->getLanguage()->loadLanguageModule('crs');
             $this->getLanguage()->loadLanguageModule('dateplaner');
             $this->initMail();
             $this->setSubject(sprintf($this->getLanguageText('cal_crs_new_notification_sub'), $this->getObjectTitle(true)));
             $this->setBody($this->getLanguageText('crs_notification_salutation'));
             $this->appendBody("\n\n");
             $this->appendBody(sprintf($this->getLanguageText('cal_crs_new_notification_body'), $this->getObjectTitle(true)));
             $this->appendBody("\n\n");
             $this->appendBody($this->getLanguageText('crs_mail_permanent_link'));
             $this->appendBody("\n\n");
             $this->appendAppointmentDetails();
             $this->appendBody("\n\n");
             $this->appendBody($this->createPermanentLink());
             $this->getMail()->appendInstallationSignature(true);
             $this->addAttachment();
             $this->sendMail(array('#il_crs_admin_' . $this->getRefId(), '#il_crs_tutor_' . $this->getRefId(), '#il_crs_member_' . $this->getRefId()), array('system'), false);
             break;
         case self::TYPE_CRS_NOTIFICATION:
             $this->setLanguage(ilLanguageFactory::_getLanguage($lng->getDefaultLanguage()));
             $this->getLanguage()->loadLanguageModule('crs');
             $this->getLanguage()->loadLanguageModule('dateplaner');
             $this->initMail();
             $this->setSubject(sprintf($this->getLanguageText('cal_crs_notification_sub'), $this->getObjectTitle(true)));
             $this->setBody($this->getLanguageText('crs_notification_salutation'));
             $this->appendBody("\n\n");
             $this->appendBody(sprintf($this->getLanguageText('cal_crs_notification_body'), $this->getObjectTitle(true)));
             $this->appendBody("\n\n");
             $this->appendAppointmentDetails();
             $this->appendBody("\n\n");
             $this->appendBody($this->getLanguageText('crs_mail_permanent_link'));
             $this->appendBody("\n\n");
             $this->appendBody($this->createPermanentLink());
             $this->getMail()->appendInstallationSignature(true);
             $this->addAttachment();
             $this->sendMail(array('#il_crs_admin_' . $this->getRefId(), '#il_crs_tutor_' . $this->getRefId(), '#il_crs_member_' . $this->getRefId()), array('system'), false);
             break;
         case self::TYPE_BOOKING_CONFIRMATION:
             $user_id = array_pop($this->getRecipients());
             include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
             include_once 'Services/Booking/classes/class.ilBookingEntry.php';
             $entry = new ilCalendarEntry($this->getAppointmentId());
             $booking = new ilBookingEntry($entry->getContextId());
             $this->initLanguage($user_id);
             $this->getLanguage()->loadLanguageModule('dateplaner');
             $this->initMail();
             $this->setSubject(sprintf($this->getLanguageText('cal_booking_confirmation_subject'), $entry->getTitle()));
             $this->setBody(ilMail::getSalutation($user_id, $this->getLanguage()));
             $this->appendBody("\n\n");
             $this->appendBody(sprintf($this->getLanguageText('cal_booking_confirmation_body'), ilObjUser::_lookupFullname($booking->getObjId())));
             $this->appendBody("\n\n");
             $this->appendAppointmentDetails($booking);
             /*
             				$this->appendBody("\n\n");
             				$this->appendBody($this->getLanguageText('cal_booking_confirmation_link'));
             				$this->appendBody("\n\n");
             				$this->appendBody($this->createPermanentLink());
             */
             $this->getMail()->appendInstallationSignature(true);
             $this->sendMail(array($user_id), array('system'), true);
             $this->appendBody("\n\n");
             $this->appendBody($this->getLanguageText('cal_booking_confirmation_user') . "\n");
             $this->appendBody(ilObjUser::_lookupFullname($user_id));
             $this->sendMail(array($booking->getObjId()), array('system'), true);
             break;
         case self::TYPE_BOOKING_CANCELLATION:
             $user_id = array_pop($this->getRecipients());
             include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
             include_once 'Services/Booking/classes/class.ilBookingEntry.php';
             $entry = new ilCalendarEntry($this->getAppointmentId());
             $booking = new ilBookingEntry($entry->getContextId());
             $user_id = array_pop($this->getRecipients());
             $this->initLanguage($user_id);
             $this->getLanguage()->loadLanguageModule('dateplaner');
             $this->initMail();
             $this->setSubject(sprintf($this->getLanguageText('cal_booking_cancellation_subject'), $entry->getTitle()));
             $this->setBody(ilMail::getSalutation($user_id, $this->getLanguage()));
             $this->appendBody("\n\n");
             $this->appendBody(sprintf($this->getLanguageText('cal_booking_cancellation_body'), ilObjUser::_lookupFullname($booking->getObjId())));
             $this->appendBody("\n\n");
             $this->appendAppointmentDetails($booking);
             $this->getMail()->appendInstallationSignature(true);
             $this->sendMail(array($user_id), array('system'), true);
             $this->appendBody("\n\n");
             $this->appendBody($this->getLanguageText('cal_booking_cancellation_user') . "\n");
             $this->appendBody(ilObjUser::_lookupFullname($user_id));
             $this->sendMail(array($booking->getObjId()), array('system'), true);
             break;
     }
     $this->deleteAttachments();
 }
 /**
  * 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());
 }
 /**
  * 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());
 }