/**
  * Read private calendars
  *
  * @access protected
  * @return
  */
 protected function readPrivateCalendars()
 {
     global $ilUser;
     global $ilDB;
     // First read private calendars of user
     $query = "SELECT cat_id FROM cal_categories " . "WHERE type = " . $this->db->quote(ilCalendarCategory::TYPE_USR, 'integer') . " " . "AND obj_id = " . $this->db->quote($ilUser->getId(), 'integer') . " ";
     $res = $this->db->query($query);
     while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) {
         $cat_ids[] = $row->cat_id;
     }
     // Read shared calendars
     include_once './Services/Calendar/classes/class.ilCalendarSharedStatus.php';
     $accepted_ids = ilCalendarSharedStatus::getAcceptedCalendars($ilUser->getId());
     if (!($cat_ids = array_merge((array) $cat_ids, $accepted_ids))) {
         return true;
     }
     // user categories
     $query = "SELECT * FROM cal_categories " . "WHERE type = " . $this->db->quote(ilCalendarCategory::TYPE_USR, 'integer') . " " . "AND " . $ilDB->in('cat_id', $cat_ids, false, 'integer') . " " . "ORDER BY title ";
     $res = $this->db->query($query);
     while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) {
         $this->categories[] = $row->cat_id;
         $this->categories_info[$row->cat_id]['obj_id'] = $row->obj_id;
         $this->categories_info[$row->cat_id]['cat_id'] = $row->cat_id;
         $this->categories_info[$row->cat_id]['title'] = $row->title;
         $this->categories_info[$row->cat_id]['color'] = $row->color;
         $this->categories_info[$row->cat_id]['type'] = $row->type;
         include_once './Services/Calendar/classes/class.ilCalendarShared.php';
         if (in_array($row->cat_id, $accepted_ids)) {
             $shared = new ilCalendarShared($row->cat_id);
             if ($shared->isEditableForUser($ilUser->getId())) {
                 $this->categories_info[$row->cat_id]['editable'] = true;
             } else {
                 $this->categories_info[$row->cat_id]['editable'] = false;
             }
         } else {
             $this->categories_info[$row->cat_id]['editable'] = true;
         }
         $this->categories_info[$row->cat_id]['accepted'] = in_array($row->cat_id, $accepted_ids);
         $this->categories_info[$row->cat_id]['remote'] = $row->loc_type == ilCalendarCategory::LTYPE_REMOTE;
     }
 }
 /**
  * read permissions
  *
  * @access private
  * @param
  * @return
  */
 private function readPermissions()
 {
     global $ilUser, $rbacsystem, $ilAccess;
     $this->editable = false;
     $this->visible = false;
     $this->importable = false;
     include_once './Services/Calendar/classes/class.ilCalendarShared.php';
     $shared = ilCalendarShared::getSharedCalendarsForUser($ilUser->getId());
     $cat = new ilCalendarCategory((int) $_GET['category_id']);
     switch ($cat->getType()) {
         case ilCalendarCategory::TYPE_USR:
             if ($cat->getObjId() == $ilUser->getId()) {
                 $this->visible = true;
                 $this->editable = true;
                 $this->importable = true;
             } elseif (isset($shared[$cat->getCategoryID()])) {
                 $this->visible = true;
             }
             break;
         case ilCalendarCategory::TYPE_GLOBAL:
             $this->importable = $this->editable = $rbacsystem->checkAccess('edit_event', ilCalendarSettings::_getInstance()->getCalendarSettingsId());
             $this->visible = true;
             break;
         case ilCalendarCategory::TYPE_OBJ:
             $this->editable = false;
             $refs = ilObject::_getAllReferences($cat->getObjId());
             foreach ($refs as $ref) {
                 if ($ilAccess->checkAccess('read', '', $ref)) {
                     $this->visible = true;
                 }
                 if ($ilAccess->checkAccess('edit_event', '', $ref)) {
                     $this->importable = true;
                 }
             }
             break;
         case ilCalendarCategory::TYPE_BOOK:
         case ilCalendarCategory::TYPE_CH:
             $this->editable = $ilUser->getId() == $cat->getCategoryID();
             $this->visible = true;
             $this->importable = false;
             break;
     }
 }
 /**
  * accept shared calendar
  *
  * @access protected
  * @return
  */
 protected function declineShared()
 {
     global $ilUser;
     if (!$_POST['cal_ids'] or !is_array($_POST['cal_ids'])) {
         ilUtil::sendFailure($this->lng->txt('select_one'));
         $this->inbox();
         return false;
     }
     include_once './Services/Calendar/classes/class.ilCalendarSharedStatus.php';
     $status = new ilCalendarSharedStatus($ilUser->getId());
     include_once './Services/Calendar/classes/class.ilCalendarShared.php';
     foreach ($_POST['cal_ids'] as $calendar_id) {
         if (!ilCalendarShared::isSharedWithUser($ilUser->getId(), $calendar_id)) {
             ilUtil::sendFailure($this->lng->txt('permission_denied'));
             $this->inbox();
             return false;
         }
         $status->decline($calendar_id);
     }
     ilUtil::sendSuccess($this->lng->txt('settings_saved'));
     $this->inbox();
     return true;
 }