/**
  * Get participants and responsible users
  */
 function getParticipantsAndResponsibles()
 {
     $participants = array();
     if ($this->app_id > 0) {
         include_once "./Services/Calendar/classes/class.ilCalendarEntry.php";
         $app = new ilCalendarEntry($this->app_id);
         $resp_users = $app->readResponsibleUsers();
         foreach ($resp_users as $v) {
             $n = ilObjUser::_lookupName($v["user_id"]);
             $participants[$v["user_id"]] = array_merge($n, array("type" => "non-member"));
             $this->resp_users[] = $v["user_id"];
         }
     }
     include_once './Modules/Group/classes/class.ilGroupParticipants.php';
     $part = ilGroupParticipants::_getInstanceByObjId($this->grp_id);
     $admins = $part->getAdmins();
     $members = $part->getMembers();
     foreach ($members as $v) {
         $n = ilObjUser::_lookupName($v);
         $participants[$v] = array_merge($n, array("type" => "member"));
     }
     foreach ($admins as $v) {
         $n = ilObjUser::_lookupName($v);
         $participants[$v] = array_merge($n, array("type" => "admin"));
     }
     $this->setData($participants);
 }
 public function isValidEvent(ilCalendarEntry $a_event)
 {
     global $ilUser;
     $booking = new ilBookingEntry($a_event->getContextId());
     // portfolio embedded: filter by consultation hour groups?
     if (!is_array($this->group_ids) || in_array($booking->getBookingGroup(), $this->group_ids)) {
         // do not filter against course/group in portfolio
         if ($this->cats->getMode() == ilCalendarCategories::MODE_PORTFOLIO_CONSULTATION) {
             $booking->setTargetObjIds(null);
         }
         if (($this->user_id == $ilUser->getId() || !$booking->isBookedOut($a_event->getEntryId(), true)) && $booking->isTargetObjectVisible($this->cats->getTargetRefId())) {
             return true;
         }
     }
     return false;
 }
 /**
  * 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;
 }
 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();
 }
 public function insertBookingAppointment($a_insertedId, $a_booking_values, $a_from = NULL, $a_to = NULL)
 {
     //create appointment first
     if ($a_from == NULL || $a_to == NULL) {
         $a_from = $a_booking_values['from']['date'] . " " . $a_booking_values['from']['time'];
         $a_to = $a_booking_values['to']['date'] . " " . $a_booking_values['to']['time'];
     }
     $time_start = new ilDateTime($a_from, 1);
     $time_end = new ilDateTime($a_to, 1);
     $title = $a_booking_values['subject'];
     $room_name = $this->ilRoomSharingDatabase->getRoomName($a_booking_values['room']);
     $cal_cat_id = $a_booking_values['cal_id'];
     //use original ilCalendarEntry and let ILIAS do the work
     $app = new ilCalendarEntry();
     $app->setStart($time_start);
     $app->setEnd($time_end);
     $app->setFullday(false);
     $app->setTitle($title);
     $app->setDescription($a_booking_values['comment']);
     $app->setAutoGenerated(true);
     $app->enableNotification(false);
     $app->setLocation($room_name);
     $app->validate();
     $app->save();
     $ass = new ilCalendarCategoryAssignments($app->getEntryId());
     $ass->addAssignment($cal_cat_id);
     //update bookings-table afterwards
     $this->ilDB->manipulate('UPDATE ' . dbc::BOOKINGS_TABLE . ' SET calendar_entry_id = ' . $this->ilDB->quote($app->getEntryId(), 'integer') . ' WHERE id = ' . $this->ilDB->quote($a_insertedId, 'integer') . ' AND pool_id =' . $this->ilDB->quote($this->pool_id, 'integer'));
 }
 /**
  * write a new event
  *
  * @access protected
  */
 protected function writeEvent()
 {
     $entry = new ilCalendarEntry();
     // Search for summary
     foreach ($this->getContainer()->getItemsByName('SUMMARY', false) as $item) {
         if (is_a($item, 'ilICalProperty')) {
             $entry->setTitle($this->purgeString($item->getValue()));
             break;
         }
     }
     // Search description
     foreach ($this->getContainer()->getItemsByName('DESCRIPTION', false) as $item) {
         if (is_a($item, 'ilICalProperty')) {
             $entry->setDescription($this->purgeString($item->getValue()));
             break;
         }
     }
     // Search location
     foreach ($this->getContainer()->getItemsByName('LOCATION', false) as $item) {
         if (is_a($item, 'ilICalProperty')) {
             $entry->setLocation($this->purgeString($item->getValue()));
             break;
         }
     }
     foreach ($this->getContainer()->getItemsByName('DTSTART') as $start) {
         $fullday = false;
         foreach ($start->getItemsByName('VALUE') as $type) {
             if ($type->getValue() == 'DATE') {
                 $fullday = true;
             }
         }
         $start_tz = $this->default_timezone;
         foreach ($start->getItemsByName('TZID') as $param) {
             $start_tz = $this->getTZ($param->getValue());
         }
         if ($fullday) {
             $start = new ilDate($start->getValue(), IL_CAL_DATE);
         } else {
             $start = new ilDateTime($start->getValue(), IL_CAL_DATETIME, $start_tz->getIdentifier());
         }
         $entry->setStart($start);
         $entry->setFullday($fullday);
     }
     foreach ($this->getContainer()->getItemsByName('DTEND') as $end) {
         $fullday = false;
         foreach ($end->getItemsByName('VALUE') as $type) {
             if ($type->getValue() == 'DATE') {
                 $fullday = true;
             }
         }
         $end_tz = $this->default_timezone;
         foreach ($end->getItemsByName('TZID') as $param) {
             $end_tz = $this->getTZ($param->getValue());
         }
         if ($fullday) {
             $end = new ilDate($end->getValue(), IL_CAL_DATE);
             $end->increment(IL_CAL_DAY, -1);
         } else {
             $end = new ilDateTime($end->getValue(), IL_CAL_DATETIME, $end_tz->getIdentifier());
         }
         $entry->setEnd($end);
         $entry->setFullday($fullday);
     }
     // save calendar event
     if ($this->category->getLocationType() == ilCalendarCategory::LTYPE_REMOTE) {
         $entry->setAutoGenerated(true);
     }
     $entry->save();
     include_once './Services/Calendar/classes/class.ilCalendarCategoryAssignments.php';
     $ass = new ilCalendarCategoryAssignments($entry->getEntryId());
     $ass->addAssignment($this->category->getCategoryID());
     // Recurrences
     foreach ($this->getContainer()->getItemsByName('RRULE') as $recurrence) {
         #var_dump("<pre>",$recurrence,"</pre>");
         include_once './Services/Calendar/classes/class.ilCalendarRecurrence.php';
         $rec = new ilCalendarRecurrence();
         $rec->setEntryId($entry->getEntryId());
         foreach ($recurrence->getItemsByName('FREQ') as $freq) {
             switch ($freq->getValue()) {
                 case 'DAILY':
                 case 'WEEKLY':
                 case 'MONTHLY':
                 case 'YEARLY':
                     $rec->setFrequenceType((string) $freq->getValue());
                     break;
                 default:
                     $this->log->write(__METHOD__ . ': Cannot handle recurring event of type: ' . $freq->getValue());
                     break 3;
             }
         }
         foreach ($recurrence->getItemsByName('COUNT') as $value) {
             $rec->setFrequenceUntilCount((string) $value->getValue());
             break;
         }
         foreach ($recurrence->getItemsByName('UNTIL') as $until) {
             $rec->setFrequenceUntilDate(new ilDate($until->getValue(), IL_CAL_DATE));
             break;
         }
         foreach ($recurrence->getItemsByName('INTERVAL') as $value) {
             $rec->setInterval((string) $value->getValue());
             break;
         }
         foreach ($recurrence->getItemsByName('BYDAY') as $value) {
             $rec->setBYDAY((string) $value->getValue());
             break;
         }
         foreach ($recurrence->getItemsByName('BYWEEKNO') as $value) {
             $rec->setBYWEEKNO((string) $value->getValue());
             break;
         }
         foreach ($recurrence->getItemsByName('BYMONTH') as $value) {
             $rec->setBYMONTH((string) $value->getValue());
             break;
         }
         foreach ($recurrence->getItemsByName('BYMONTHDAY') as $value) {
             $rec->setBYMONTHDAY((string) $value->getValue());
             break;
         }
         foreach ($recurrence->getItemsByName('BYYEARDAY') as $value) {
             $rec->setBYYEARDAY((string) $value->getValue());
             break;
         }
         foreach ($recurrence->getItemsByName('BYSETPOS') as $value) {
             $rec->setBYSETPOS((string) $value->getValue());
             break;
         }
         foreach ($recurrence->getItemsByName('WKST') as $value) {
             $rec->setWeekstart((string) $value->getValue());
             break;
         }
         $rec->save();
     }
 }
 /**
  * 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;
 }
 /**
  * Build url from calendar entry
  * @param ilCalendarEntry $entry
  * @return string
  */
 protected function buildAppointmentUrl(ilCalendarEntry $entry)
 {
     $cat = ilCalendarCategory::getInstanceByCategoryId(current((array) ilCalendarCategoryAssignments::_lookupCategories($entry->getEntryId())));
     if ($cat->getType() != ilCalendarCategory::TYPE_OBJ) {
         $this->writer->addLine('URL;VALUE=URI:' . ILIAS_HTTP_PATH);
     } else {
         $refs = ilObject::_getAllReferences($cat->getObjId());
         include_once './Services/Link/classes/class.ilLink.php';
         $this->writer->addLine('URL;VALUE=URI:' . ilLink::_getLink(current((array) $refs)));
     }
 }
 /**
  * Generate Calendar Entries
  *
  * @param
  * @return
  */
 function generateCalendarEntries($a_num_per_course = 10)
 {
     include_once "./Services/Calendar/classes/class.ilDateTime.php";
     include_once "./Services/Calendar/classes/class.ilCalendarEntry.php";
     include_once "./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php";
     include_once "./Services/Calendar/classes/class.ilCalendarCategories.php";
     $this->log("Creating Calendar Entries");
     $crs_ref_ids = ilUtil::_getObjectsByOperations("crs", "read", 0, $limit = 1000000);
     $cnt = 1;
     foreach ($crs_ref_ids as $rid) {
         $obj_id = ilObject::_lookupObjId($rid);
         $cat_id = ilCalendarCategories::_lookupCategoryIdByObjId($obj_id);
         $start = new ilDate(time(), IL_CAL_UNIX);
         $end = new ilDate(time(), IL_CAL_UNIX);
         $end->increment(IL_CAL_HOUR, 2);
         for ($i = 1; $i <= $a_num_per_course; $i++) {
             $this->log("Event " . $cnt);
             $entry = new ilCalendarEntry();
             $entry->setStart($start);
             //ilDateTiem
             $entry->setEnd($end);
             //ilDateTiem
             $entry->setFullday(false);
             //ilDateTiem
             $entry->setTitle("Event " . $cnt);
             //ilDateTiem
             $entry->save();
             $id = $entry->getEntryId();
             $ass = new ilCalendarCategoryAssignments($id);
             $ass->addAssignment($cat_id);
             $start->increment(IL_CAL_DAY, 1);
             $end->increment(IL_CAL_DAY, 1);
             //echo "-$cat_id-";
             //echo "+".ilDatePresentation::formatDate($start)."+";
             $cnt++;
         }
     }
 }
 /**
  * Import ical in calendar
  * @param ilCalendarCategory $cat 
  */
 protected function importIcal(ilCalendarCategory $cat)
 {
     // Delete old appointments
     include_once './Services/Calendar/classes/class.ilCalendarCategoryAssignments.php';
     foreach (ilCalendarCategoryAssignments::_getAssignedAppointments(array($cat->getCategoryID())) as $app_id) {
         include_once './Services/Calendar/classes/class.ilCalendarEntry.php';
         ilCalendarEntry::_delete($app_id);
     }
     ilCalendarCategoryAssignments::_deleteByCategoryId($cat->getCategoryID());
     // Import new appointments
     include_once './Services/Calendar/classes/iCal/class.ilICalParser.php';
     $parser = new ilICalParser($this->ical, ilICalParser::INPUT_STRING);
     $parser->setCategoryId($cat->getCategoryID());
     $parser->parse();
 }
 /**
  * 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());
 }
 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();
 }
 /**
  * Delete automatic generated appointments
  * 
  * @access public
  * @param int obj_id
  * @param array context ids
  * @static
  */
 public static function deleteAppointments($a_obj_id, array $a_context_ids = null)
 {
     include_once './Services/Calendar/classes/class.ilCalendarCategoryAssignments.php';
     include_once './Services/Calendar/classes/class.ilCalendarEntry.php';
     foreach (ilCalendarCategoryAssignments::_getAutoGeneratedAppointmentsByObjId($a_obj_id) as $app_id) {
         // delete only selected entries
         if (is_array($a_context_ids)) {
             $entry = new ilCalendarEntry($app_id);
             if (!in_array($entry->getContextId(), $a_context_ids)) {
                 continue;
             }
         }
         ilCalendarCategoryAssignments::_deleteByAppointmentId($app_id);
         ilCalendarEntry::_delete($app_id);
     }
 }
 /**
  * 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;
     }
 }
 public function isValidEvent(ilCalendarEntry $a_event)
 {
     return !$this->hidden_cat->isAppointmentVisible($a_event->getEntryId());
 }
 /**
  * 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');
     }
 }
 /**
  * Read events (will be moved to another class, since only active and/or visible calendars are shown)
  *
  * @access protected
  */
 public function getEvents()
 {
     global $ilDB;
     include_once './Services/Calendar/classes/class.ilCalendarCategories.php';
     $cats = ilCalendarCategories::_getInstance($this->user->getId())->getCategories($this->enabledSubitemCalendars());
     if (!$this->filter_bookings) {
         $cats = $this->hidden_cat->filterHidden($cats, ilCalendarCategories::_getInstance($this->user->getId())->getCategoriesInfo());
     }
     if (!count($cats)) {
         return array();
     }
     // TODO: optimize
     $query = "SELECT ce.cal_id cal_id FROM cal_entries ce LEFT JOIN cal_recurrence_rules crr ON ce.cal_id = crr.cal_id " . "JOIN cal_cat_assignments ca ON ca.cal_id = ce.cal_id ";
     if ($this->type != self::TYPE_INBOX) {
         $query .= "WHERE ((starta <= " . $this->db->quote($this->end->get(IL_CAL_DATETIME, '', 'UTC'), 'timestamp') . " " . "AND enda >= " . $this->db->quote($this->start->get(IL_CAL_DATETIME, '', 'UTC'), 'timestamp') . ") " . "OR (starta <= " . $this->db->quote($this->end->get(IL_CAL_DATETIME, '', 'UTC'), 'timestamp') . " " . "AND NOT rule_id IS NULL)) ";
     } else {
         $date = new ilDateTime(mktime(0, 0, 0), IL_CAL_UNIX);
         $query .= "WHERE starta >= " . $this->db->quote($date->get(IL_CAL_DATETIME, '', 'UTC'), 'timestamp');
     }
     $query .= "AND " . $ilDB->in('ca.cat_id', $cats, false, 'integer') . " " . "ORDER BY starta";
     $res = $this->db->query($query);
     $events = array();
     include_once 'Services/Booking/classes/class.ilBookingEntry.php';
     while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) {
         if (!$this->hidden_cat->isAppointmentVisible($row->cal_id) || $this->filter_bookings) {
             $event = new ilCalendarEntry($row->cal_id);
             if (!$this->filter_bookings) {
                 $events[] = $event;
             } else {
                 $booking = new ilBookingEntry($event->getContextId());
                 if (!$booking->isBookedOut($row->cal_id, true)) {
                     $events[] = $event;
                 }
             }
         }
     }
     return $events;
 }
 /**
  * 
  * @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();
 }
 /**
  * Delete automatic generated appointments
  * 
  * @access public
  * @param int obj_id
  * @static
  */
 public static function deleteAppointments($a_obj_id)
 {
     include_once './Services/Calendar/classes/class.ilCalendarCategoryAssignments.php';
     include_once './Services/Calendar/classes/class.ilCalendarEntry.php';
     foreach (ilCalendarCategoryAssignments::_getAutoGeneratedAppointmentsByObjId($a_obj_id) as $app_id) {
         ilCalendarCategoryAssignments::_deleteByAppointmentId($app_id);
         ilCalendarEntry::_delete($app_id);
     }
 }
 /**
  * Get category object of given calendar entry
  * @param ilCalendarEntry $entry
  * @return ilCalendarCategory
  */
 protected function calendarEntryToCategory(ilCalendarEntry $entry)
 {
     include_once 'Services/Calendar/classes/class.ilCalendarCategoryAssignments.php';
     include_once 'Services/Calendar/classes/class.ilCalendarCategory.php';
     $assignment = new ilCalendarCategoryAssignments($entry->getEntryId());
     $assignment = $assignment->getFirstAssignment();
     return new ilCalendarCategory($assignment);
 }
 /**
  * delete
  *
  * @access public
  * @return
  */
 public function delete()
 {
     global $ilDB;
     $query = "DELETE FROM cal_categories " . "WHERE cat_id = " . $this->db->quote($this->cat_id, 'integer') . " ";
     $res = $ilDB->manipulate($query);
     include_once './Services/Calendar/classes/class.ilCalendarHidden.php';
     ilCalendarHidden::_deleteCategories($this->cat_id);
     include_once './Services/Calendar/classes/class.ilCalendarCategoryAssignments.php';
     foreach (ilCalendarCategoryAssignments::_getAssignedAppointments(array($this->cat_id)) as $app_id) {
         include_once './Services/Calendar/classes/class.ilCalendarEntry.php';
         ilCalendarEntry::_delete($app_id);
     }
     ilCalendarCategoryAssignments::_deleteByCategoryId($this->cat_id);
 }
 /**
  * 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);
 }
 /**
  * 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;
 }
 /**
  * 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');
 }
 /**
  * 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;
 }