/**
  * 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;
 }
 /**
  * delete multiple entries
  */
 public function delete()
 {
     if (!isset($_POST['apps'])) {
         ilUtil::sendFailure($this->lng->txt('select_one'));
         return $this->appointmentList();
     }
     include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
     include_once 'Services/Calendar/classes/class.ilCalendarCategoryAssignments.php';
     foreach ($_POST['apps'] as $entry_id) {
         // cancel booking for users
         $booking = ilBookingEntry::getInstanceByCalendarEntryId($entry_id);
         if ($booking) {
             foreach ($booking->getCurrentBookings($entry_id) as $user_id) {
                 include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourUtils.php';
                 ilConsultationHourUtils::cancelBooking($user_id, $entry_id, false);
             }
         }
         // remove calendar entries
         include_once './Services/Calendar/classes/class.ilCalendarEntry.php';
         $entry = new ilCalendarEntry($entry_id);
         $entry->delete();
         ilCalendarCategoryAssignments::_deleteByAppointmentId($entry_id);
     }
     ilBookingEntry::removeObsoleteEntries();
     ilUtil::sendSuccess($this->lng->txt('cal_deleted_app'), true);
     $this->ctrl->redirect($this, 'appointmentList');
 }
 /**
  * delete appointments
  *
  * @access protected
  * @return
  */
 protected function deleteAppointments()
 {
     if (!count($_POST['appointments'])) {
         ilUtil::sendFailure($this->lng->txt('select_one'));
         $this->details();
         return true;
     }
     include_once './Services/Calendar/classes/class.ilCalendarEntry.php';
     foreach ($_POST['appointments'] as $app_id) {
         $app = new ilCalendarEntry($app_id);
         $app->delete();
         include_once './Services/Calendar/classes/class.ilCalendarCategoryAssignments.php';
         ilCalendarCategoryAssignments::_deleteByAppointmentId($app_id);
     }
     ilUtil::sendSuccess($this->lng->txt('settings_saved'));
     $this->details();
     return true;
 }
 /**
  * Cancel consultation appointment or ressource booking, was confirmed
  * This will delete the calendar entry
  */
 public function cancelConfirmed()
 {
     global $ilUser;
     $entry = (int) $_POST['app_id'];
     $user = (int) $_GET['bkid'];
     include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
     $entry = new ilCalendarEntry($entry);
     $category = $this->calendarEntryToCategory($entry);
     if ($category->getType() == ilCalendarCategory::TYPE_CH) {
         // find cloned calendar entry in user calendar
         include_once 'Services/Calendar/classes/ConsultationHours/class.ilConsultationHourAppointments.php';
         $GLOBALS['ilLog']->dump($entry->getStart());
         $apps = ilConsultationHourAppointments::getAppointmentIds($ilUser->getId(), $entry->getContextId(), $entry->getStart(), ilCalendarCategory::TYPE_CH, false);
         $GLOBALS['ilLog']->dump($apps);
         // Fix for wrong, old entries
         foreach ((array) $apps as $own_app) {
             $ref_entry = new ilCalendarEntry($own_app);
             $ref_entry->delete();
         }
         include_once 'Services/Booking/classes/class.ilBookingEntry.php';
         $booking = new ilBookingEntry($entry->getContextId());
         $booking->cancelBooking($entry->getEntryId());
         // do NOT delete original entry
     } else {
         if ($category->getType() == ilCalendarCategory::TYPE_BOOK) {
             include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
             $booking = new ilBookingReservation($entry->getContextId());
             $booking->setStatus(ilBookingReservation::STATUS_CANCELLED);
             $booking->update();
             $entry->delete();
         }
     }
     ilUtil::sendSuccess($this->lng->txt('cal_cancel_booking_confirmed'), true);
     $this->ctrl->returnToParent($this);
 }
 function rsvCancelObject()
 {
     global $ilAccess, $ilUser;
     $this->tabs_gui->setTabActive('log');
     $id = (int) $_GET['reservation_id'];
     include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
     $obj = new ilBookingReservation($id);
     if (!$ilAccess->checkAccess("write", "", $this->ref_id) && $obj->getUserId() != $ilUser->getId()) {
         ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
         $this->ctrl->redirect($this, 'log');
     }
     $obj->setStatus(ilBookingReservation::STATUS_CANCELLED);
     $obj->update();
     if ($this->object->getScheduleType() != ilObjBookingPool::TYPE_NO_SCHEDULE) {
         // remove user calendar entry (#11086)
         $cal_entry_id = $obj->getCalendarEntry();
         if ($cal_entry_id) {
             include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
             $entry = new ilCalendarEntry($cal_entry_id);
             $entry->delete();
         }
     }
     ilUtil::sendSuccess($this->lng->txt('settings_saved'));
     $this->logObject();
 }
 function rsvCancelObject()
 {
     global $ilAccess, $ilUser, $tpl, $lng, $ilCtrl;
     $ids = $_POST["rsv_id"];
     // parse aggregation form
     if ($_POST["rsv_aggr"]) {
         $form = $this->rsvConfirmCancelAggregationForm($_POST["rsv_aggr"]);
         if (!$form->checkInput()) {
             $this->tabs_gui->clearTargets();
             $this->tabs_gui->setBackTarget($lng->txt("back"), $ilCtrl->getLinkTarget($this, "log"));
             return $tpl->setContent($form->getHTML());
         }
         $ids = array();
         foreach ($_POST["rsv_aggr"] as $idx => $aggr_ids) {
             $max = (int) $_POST["rsv_id_" . $idx];
             if ($max) {
                 if (!is_array($aggr_ids)) {
                     $ids[] = $aggr_ids;
                 } else {
                     $aggr_ids = array_slice($aggr_ids, 0, $max);
                     $ids = array_merge($ids, $aggr_ids);
                 }
             }
         }
     }
     if ($ids) {
         include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
         foreach ($ids as $id) {
             $obj = new ilBookingReservation($id);
             if (!$ilAccess->checkAccess("write", "", $this->ref_id) && $obj->getUserId() != $ilUser->getId()) {
                 ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
                 $this->ctrl->redirect($this, 'log');
             }
             $obj->setStatus(ilBookingReservation::STATUS_CANCELLED);
             $obj->update();
             if ($this->object->getScheduleType() != ilObjBookingPool::TYPE_NO_SCHEDULE) {
                 // remove user calendar entry (#11086)
                 $cal_entry_id = $obj->getCalendarEntry();
                 if ($cal_entry_id) {
                     include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
                     $entry = new ilCalendarEntry($cal_entry_id);
                     $entry->delete();
                 }
             }
         }
     }
     ilUtil::sendSuccess($this->lng->txt('settings_saved'));
     $this->logObject();
 }