/**
  * Update multiple sequence items
  * @return
  */
 protected function updateMulti()
 {
     global $ilObjDataCache;
     $this->initFormSequence(self::MODE_MULTI);
     if ($this->form->checkInput()) {
         $this->form->setValuesByPost();
         $apps = explode(';', $_POST['apps']);
         include_once 'Services/Booking/classes/class.ilBookingEntry.php';
         include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
         // do collision-check if max bookings were reduced
         // no collision check
         $first = $apps;
         $first = array_shift($first);
         $entry = ilBookingEntry::getInstanceByCalendarEntryId($first);
         #if($this->form->getInput('bo') < $entry->getNumberOfBookings())
         #{
         #   $this->edit();
         #   return;
         #}
         // create new context
         $booking = new ilBookingEntry();
         $booking->setObjId($this->getUserId());
         $booking->setNumberOfBookings($this->form->getInput('bo'));
         $deadline = $this->form->getInput('dead');
         $deadline = $deadline['dd'] * 24 + $deadline['hh'];
         $booking->setDeadlineHours($deadline);
         $tgt = explode(',', $this->form->getInput('tgt'));
         $obj_ids = array();
         foreach ((array) $tgt as $ref_id) {
             if (!trim($ref_id)) {
                 continue;
             }
             $obj_id = $ilObjDataCache->lookupObjId($ref_id);
             $type = ilObject::_lookupType($obj_id);
             $valid_types = array('crs', 'grp');
             if (!$obj_id or !in_array($type, $valid_types)) {
                 ilUtil::sendFailure($this->lng->txt('cal_ch_unknown_repository_object'));
                 $this->edit();
                 return;
             }
             $obj_ids[] = $obj_id;
         }
         $booking->setTargetObjIds($obj_ids);
         include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourGroups.php';
         if (ilConsultationHourGroups::getCountGroupsOfUser($this->getUserId())) {
             $booking->setBookingGroup($this->form->getInput('grp'));
         }
         $booking->save();
         // update entries
         $title = $this->form->getInput('ti');
         $location = $this->form->getInput('lo');
         $description = $this->form->getInput('de');
         foreach ($apps as $item_id) {
             $entry = new ilCalendarEntry($item_id);
             $entry->setContextId($booking->getId());
             $entry->setTitle($title);
             $entry->setLocation($location);
             $entry->setDescription($description);
             $entry->update();
         }
         ilBookingEntry::removeObsoleteEntries();
         ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
         $this->ctrl->redirect($this, 'appointmentList');
     }
     $this->tpl->setContent($this->form->getHTML());
 }
 /**
  * Book object for date
  * 
  * @param int $a_object_id
  * @param int $a_from timestamp
  * @param int $a_to timestamp
  */
 function processBooking($a_object_id, $a_from = null, $a_to = null)
 {
     global $ilUser;
     include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
     $reservation = new ilBookingReservation();
     $reservation->setObjectId($a_object_id);
     $reservation->setUserId($ilUser->getID());
     $reservation->setFrom($a_from);
     $reservation->setTo($a_to);
     $reservation->save();
     if ($a_from) {
         $this->lng->loadLanguageModule('dateplaner');
         include_once 'Services/Calendar/classes/class.ilCalendarUtil.php';
         include_once 'Services/Calendar/classes/class.ilCalendarCategory.php';
         $def_cat = ilCalendarUtil::initDefaultCalendarByType(ilCalendarCategory::TYPE_BOOK, $ilUser->getId(), $this->lng->txt('cal_ch_personal_book'), true);
         include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
         $object = new ilBookingObject($a_object_id);
         include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
         $entry = new ilCalendarEntry();
         $entry->setStart(new ilDateTime($a_from, IL_CAL_UNIX));
         $entry->setEnd(new ilDateTime($a_to, IL_CAL_UNIX));
         $entry->setTitle($this->lng->txt('book_cal_entry') . ' ' . $object->getTitle());
         $entry->setContextId($reservation->getId());
         $entry->save();
         include_once 'Services/Calendar/classes/class.ilCalendarCategoryAssignments.php';
         $assignment = new ilCalendarCategoryAssignments($entry->getEntryId());
         $assignment->addAssignment($def_cat->getCategoryId());
     }
 }
 /**
  * Update multiple sequence items
  * @return
  */
 protected function updateMulti()
 {
     global $ilObjDataCache;
     $this->initFormSequence(self::MODE_MULTI);
     if ($this->form->checkInput()) {
         $this->form->setValuesByPost();
         $apps = explode(';', $_POST['apps']);
         include_once 'Services/Booking/classes/class.ilBookingEntry.php';
         include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
         // do collision-check if max bookings were reduced
         $first = $apps;
         $first = array_shift($first);
         $entry = ilBookingEntry::getInstanceByCalendarEntryId($first);
         if ($this->form->getInput('bo') < $entry->getNumberOfBookings()) {
             $this->edit();
             return;
         }
         // create new context
         $booking = new ilBookingEntry();
         $booking->setObjId($this->getUserId());
         $booking->setNumberOfBookings($this->form->getInput('bo'));
         $deadline = $this->form->getInput('dead');
         $deadline = $deadline['dd'] * 24 + $deadline['hh'];
         $booking->setDeadlineHours($deadline);
         $tgt = $this->form->getInput('tgt');
         if ($tgt) {
             // if value was not changed, we already have an object id
             if ($tgt != $entry->getTargetObjId()) {
                 $obj_id = $ilObjDataCache->lookupObjId($tgt);
                 if (!$obj_id) {
                     ilUtil::sendFailure($this->lng->txt('cal_ch_unknown_repository_object'), true);
                     $this->edit();
                     return;
                 }
                 $booking->setTargetObjId($obj_id);
             } else {
                 $booking->setTargetObjId($tgt);
             }
         }
         $booking->save();
         // update entries
         $title = $this->form->getInput('ti');
         $location = $this->form->getInput('lo');
         $description = $this->form->getInput('de');
         foreach ($apps as $item_id) {
             $entry = new ilCalendarEntry($item_id);
             $entry->setContextId($booking->getId());
             $entry->setTitle($title);
             $entry->setLocation($location);
             $entry->setDescription($description);
             $entry->update();
         }
         ilBookingEntry::removeObsoleteEntries();
         ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
         $this->ctrl->redirect($this, 'appointmentList');
     }
     $this->tpl->setContent($this->form->getHTML());
 }
 /**
  * Create appointments
  *
  * @access public
  * @param
  * @return
  * @static
  */
 public static function createAppointments($a_obj, $a_appointments)
 {
     global $ilLog;
     include_once './Services/Calendar/classes/class.ilCalendarEntry.php';
     include_once './Services/Calendar/classes/class.ilCalendarCategoryAssignments.php';
     include_once './Services/Calendar/classes/class.ilCalendarCategories.php';
     if (!($cat_id = ilCalendarCategories::_lookupCategoryIdByObjId($a_obj->getId()))) {
         $ilLog->write(__METHOD__ . ': Cannot find calendar category for obj_id ' . $a_obj->getId());
         $cat_id = self::createCategory($a_obj);
     }
     foreach ($a_appointments as $app_templ) {
         $app = new ilCalendarEntry();
         $app->setContextId($app_templ->getContextId());
         $app->setTitle($app_templ->getTitle());
         $app->setSubtitle($app_templ->getSubtitle());
         $app->setDescription($app_templ->getDescription());
         $app->setFurtherInformations($app_templ->getInformation());
         $app->setLocation($app_templ->getLocation());
         $app->setStart($app_templ->getStart());
         $app->setEnd($app_templ->getEnd());
         $app->setFullday($app_templ->isFullday());
         $app->setAutoGenerated(true);
         $app->setTranslationType($app_templ->getTranslationType());
         $app->save();
         $ass = new ilCalendarCategoryAssignments($app->getEntryId());
         $ass->addAssignment($cat_id);
     }
 }
 /**
  * Book object for date
  * 
  * @param int $a_object_id
  * @param int $a_from timestamp
  * @param int $a_to timestamp
  * @param int $a_group_id 
  * @return int
  */
 function processBooking($a_object_id, $a_from = null, $a_to = null, $a_group_id = null)
 {
     global $ilUser, $ilAccess;
     // #11995
     if (!$ilAccess->checkAccess('read', '', $this->object->getRefId())) {
         $this->ilias->raiseError($this->lng->txt("msg_no_perm_read"), $this->ilias->error_obj->MESSAGE);
     }
     include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
     $reservation = new ilBookingReservation();
     $reservation->setObjectId($a_object_id);
     $reservation->setUserId($ilUser->getID());
     $reservation->setFrom($a_from);
     $reservation->setTo($a_to);
     $reservation->setGroupId($a_group_id);
     $reservation->save();
     if ($a_from) {
         $this->lng->loadLanguageModule('dateplaner');
         include_once 'Services/Calendar/classes/class.ilCalendarUtil.php';
         include_once 'Services/Calendar/classes/class.ilCalendarCategory.php';
         $def_cat = ilCalendarUtil::initDefaultCalendarByType(ilCalendarCategory::TYPE_BOOK, $ilUser->getId(), $this->lng->txt('cal_ch_personal_book'), true);
         include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
         $object = new ilBookingObject($a_object_id);
         include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
         $entry = new ilCalendarEntry();
         $entry->setStart(new ilDateTime($a_from, IL_CAL_UNIX));
         $entry->setEnd(new ilDateTime($a_to, IL_CAL_UNIX));
         $entry->setTitle($this->lng->txt('book_cal_entry') . ' ' . $object->getTitle());
         $entry->setContextId($reservation->getId());
         $entry->save();
         include_once 'Services/Calendar/classes/class.ilCalendarCategoryAssignments.php';
         $assignment = new ilCalendarCategoryAssignments($entry->getEntryId());
         $assignment->addAssignment($def_cat->getCategoryId());
     }
     return $reservation->getId();
 }
 /**
  * Import record
  *
  * @param
  * @return
  */
 function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
 {
     switch ($a_entity) {
         case "calendar":
             // please note: we currently only support private user calendars to
             // be imported
             if ($a_rec["Type"] == 1) {
                 $usr_id = $a_mapping->getMapping("Services/User", "usr", $a_rec["ObjId"]);
                 if ($usr_id > 0 && ilObject::_lookupType($usr_id) == "usr") {
                     include_once './Services/Calendar/classes/class.ilCalendarCategory.php';
                     $category = new ilCalendarCategory(0);
                     $category->setTitle($a_rec["Title"]);
                     $category->setColor($a_rec["Color"]);
                     $category->setType(ilCalendarCategory::TYPE_USR);
                     $category->setObjId($usr_id);
                     $category->add();
                     $a_mapping->addMapping("Services/Calendar", "calendar", $a_rec["CatId"], $category->getCategoryID());
                 }
             }
             break;
         case "cal_entry":
             // please note: we currently only support private user calendars to
             // be imported
             if ((int) $a_rec["ContextId"] == 0) {
                 include_once './Services/Calendar/classes/class.ilCalendarEntry.php';
                 $entry = new ilCalendarEntry(0);
                 $entry->setTitle($a_rec["Title"]);
                 $entry->setSubtitle($a_rec["Subtitle"]);
                 $entry->setDescription($a_rec["Description"]);
                 $entry->setLocation($a_rec["Location"]);
                 $entry->setFullday($a_rec["Fullday"]);
                 if ($a_rec["Starta"] != "") {
                     $entry->setStart(new ilDateTime($a_rec["Starta"], IL_CAL_DATETIME, 'UTC'));
                 }
                 if ($a_rec["Enda"] != "") {
                     $entry->setEnd(new ilDateTime($a_rec["Enda"], IL_CAL_DATETIME, 'UTC'));
                 }
                 $entry->setFurtherInformations($a_rec["Informations"]);
                 $entry->setAutoGenerated($a_rec["AutoGenerated"]);
                 $entry->setContextId($a_rec["ContextId"]);
                 $entry->setMilestone($a_rec["Milestone"]);
                 $entry->setCompletion($a_rec["Completion"]);
                 $entry->setTranslationType($a_rec["TranslationType"]);
                 $entry->enableNotification($a_rec["Notification"]);
                 $entry->save();
                 $a_mapping->addMapping("Services/Calendar", "cal_entry", $a_rec["Id"], $entry->getEntryId());
             }
             break;
         case "cal_assignment":
             $cat_id = $a_mapping->getMapping("Services/Calendar", "calendar", $a_rec["CatId"]);
             $entry_id = $a_mapping->getMapping("Services/Calendar", "cal_entry", $a_rec["EntryId"]);
             if ($cat_id > 0 && $entry_id > 0) {
                 include_once './Services/Calendar/classes/class.ilCalendarCategoryAssignments.php';
                 $ass = new ilCalendarCategoryAssignments($entry_id);
                 $ass->addAssignment($cat_id);
             }
             break;
         case "recurrence_rule":
             $entry_id = $a_mapping->getMapping("Services/Calendar", "cal_entry", $a_rec["EntryId"]);
             if ($entry_id > 0) {
                 include_once './Services/Calendar/classes/class.ilCalendarRecurrence.php';
                 $rec = new ilCalendarRecurrence();
                 $rec->setEntryId($entry_id);
                 $rec->setRecurrence($a_rec["CalRecurrence"]);
                 $rec->setFrequenceType($a_rec["FreqType"]);
                 if ($a_rec["FreqUntilDate"] != "") {
                     $rec->setFrequenceUntilDate(new ilDateTime($a_rec["FreqUntilDate"], IL_CAL_DATETIME));
                 }
                 $rec->setFrequenceUntilCount($a_rec["FreqUntilCount"]);
                 $rec->setInterval($a_rec["Interval"]);
                 $rec->setBYDAY($a_rec["Byday"]);
                 $rec->setBYWEEKNO($a_rec["Byweekno"]);
                 $rec->setBYMONTH($a_rec["Bymonth"]);
                 $rec->setBYMONTHDAY($a_rec["Bymonthday"]);
                 $rec->setBYYEARDAY($a_rec["Byyearday"]);
                 $rec->setBYSETPOS($a_rec["Bysetpos"]);
                 $rec->setWeekstart($a_rec["Weekstart"]);
                 $rec->save();
                 $a_mapping->addMapping("Services/Calendar", "recurrence_rule", $a_rec["RuleId"], $rec->getRecurrenceId());
             }
             break;
     }
 }