/**
  * Book an appointment. All checks (assignment possible, max booking) must be done before
  * @param type $a_usr_id
  * @param type $a_app_id
  * @return bool
  */
 public static function bookAppointment($a_usr_id, $a_app_id)
 {
     global $lng;
     // Create new default consultation hour calendar
     include_once './Services/Language/classes/class.ilLanguageFactory.php';
     $cal_lang = ilLanguageFactory::_getLanguage($lng->getDefaultLanguage());
     $cal_lang->loadLanguageModule('dateplaner');
     include_once './Services/Calendar/classes/class.ilCalendarUtil.php';
     include_once './Services/Calendar/classes/class.ilCalendarCategory.php';
     $ch = ilCalendarUtil::initDefaultCalendarByType(ilCalendarCategory::TYPE_CH, $a_usr_id, $cal_lang->txt('cal_ch_personal_ch'), true);
     // duplicate appointment
     include_once './Services/Calendar/classes/class.ilCalendarEntry.php';
     $app = new ilCalendarEntry($a_app_id);
     $personal_app = clone $app;
     $personal_app->save();
     // assign appointment to category
     include_once './Services/Calendar/classes/class.ilCalendarCategoryAssignments.php';
     $assignment = new ilCalendarCategoryAssignments($personal_app->getEntryId());
     $assignment->addAssignment($ch->getCategoryID());
     // book appointment
     include_once './Services/Booking/classes/class.ilBookingEntry.php';
     $booking = new ilBookingEntry($app->getContextId());
     $booking->book($app->getEntryId(), $a_usr_id);
     return true;
 }
 /**
  * Book consultation appointment, was confirmed
  */
 public function bookconfirmed()
 {
     global $ilUser;
     $entry = (int) $_POST['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());
     $booking->book($entry->getEntryId());
     // create user calendar/appointment
     include_once './Services/Calendar/classes/class.ilCalendarCategory.php';
     include_once './Services/Calendar/classes/class.ilCalendarUtil.php';
     include_once './Services/Calendar/classes/class.ilCalendarCategoryAssignments.php';
     $user_entry = clone $entry;
     $user_entry->save();
     $def_cat = ilCalendarUtil::initDefaultCalendarByType(ilCalendarCategory::TYPE_CH, $ilUser->getId(), $this->lng->txt('cal_ch_personal_ch'), true);
     $assign = new ilCalendarCategoryAssignments($user_entry->getEntryId());
     $assign->addAssignment($def_cat->getCategoryID());
     ilUtil::sendSuccess($this->lng->txt('cal_booking_confirmed'), true);
     $this->ctrl->returnToParent($this);
 }