/**
  * @NoAdminRequired
  *
  * @param string $calendarid
  * @param integer $active
  */
 public function setActiveCalendar($calendarid, $active)
 {
     $calendar = CalendarApp::getCalendar((int) $calendarid, true, true);
     CalendarCalendar::setCalendarActive($calendarid, (int) $active);
     $isAktiv = $active;
     if ($this->configInfo->getUserValue($this->userId, $this->appName, 'calendar_' . $calendarid) !== '') {
         $isAktiv = $this->configInfo->getUserValue($this->userId, $this->appName, 'calendar_' . $calendarid);
     }
     $eventSource = CalendarCalendar::getEventSourceInfo($calendar);
     $params = ['status' => 'success', 'active' => $isAktiv, 'eventSource' => $eventSource];
     $response = new JSONResponse($params);
     return $response;
 }
 /**
  * @NoAdminRequired
  */
 public function setActiveCalendar()
 {
     $calendarid = $this->params('calendarid');
     $pActive = intval($this->params('active'));
     $calendar = false;
     if ($calendarid !== 'birthday_' . $this->userId) {
         $calendar = CalendarApp::getCalendar((int) $calendarid, true, true);
     }
     if (!$calendar && $calendarid !== 'birthday_' . $this->userId) {
         $params = ['status' => 'error', 'message' => 'permission denied'];
         $response = new JSONResponse($params);
         return $response;
     }
     CalendarCalendar::setCalendarActive($calendarid, (int) $pActive);
     $isAktiv = $pActive;
     if ($this->configInfo->getUserValue($this->userId, $this->appName, 'calendar_' . $calendarid) !== '') {
         $isAktiv = $this->configInfo->getUserValue($this->userId, $this->appName, 'calendar_' . $calendarid);
     }
     $eventSource = '';
     if ($calendarid !== 'birthday_' . $this->userId) {
         $eventSource = CalendarCalendar::getEventSourceInfo($calendar);
     } else {
         \OCP\Util::emitHook('OC_Calendar', 'getSources', array('all' => false, 'sources' => &$eventSource));
     }
     $params = ['status' => 'success', 'active' => $isAktiv, 'eventSource' => $eventSource];
     $response = new JSONResponse($params);
     return $response;
 }
 /**
  * @PublicPage
  * @NoCSRFRequired
  */
 public function getGuestSettingsCalendar()
 {
     $token = $this->params('t');
     if (isset($token)) {
         $linkItem = \OCP\Share::getShareByToken($token, false);
         if (is_array($linkItem) && isset($linkItem['uid_owner'])) {
             // seems to be a valid share
             if ($linkItem['item_type'] === CalendarApp::SHARECALENDAR) {
                 $sPrefix = CalendarApp::SHARECALENDARPREFIX;
             }
             if ($linkItem['item_type'] === CalendarApp::SHAREEVENT) {
                 $sPrefix = CalendarApp::SHAREEVENTPREFIX;
             }
             $itemSource = CalendarApp::validateItemSource($linkItem['item_source'], $sPrefix);
             $shareOwner = $linkItem['uid_owner'];
             $rootLinkItem = \OCP\Share::resolveReShare($linkItem);
             if (isset($rootLinkItem['uid_owner'])) {
                 \OCP\JSON::checkUserExists($rootLinkItem['uid_owner']);
                 $calendar = CalendarCalendar::find($itemSource);
                 if (!array_key_exists('active', $calendar)) {
                     $calendar['active'] = 1;
                 }
                 if ($calendar['active'] == 1) {
                     $eventSources[] = CalendarCalendar::getEventSourceInfo($calendar, true);
                     $eventSources[0]['url'] = \OC::$server->getURLGenerator()->linkToRoute($this->appName . '.public.getEventsPublic') . '?t=' . $token;
                     $calendarInfo[$calendar['id']] = array('bgcolor' => $calendar['calendarcolor'], 'color' => CalendarCalendar::generateTextColor($calendar['calendarcolor']));
                     $myRefreshChecker[$calendar['id']] = $calendar['ctag'];
                 }
             }
         }
         $defaultView = 'month';
         if ($this->session->get('public_currentView') != '') {
             $defaultView = (string) $this->session->get('public_currentView');
         }
         $params = ['status' => 'success', 'defaultView' => $defaultView, 'agendatime' => 'HH:mm { - HH:mm}', 'defaulttime' => 'HH:mm', 'firstDay' => '1', 'calendarId' => $calendar['id'], 'eventSources' => $eventSources, 'calendarcolors' => $calendarInfo, 'myRefreshChecker' => $myRefreshChecker];
         $response = new JSONResponse($params);
         return $response;
     }
 }
示例#4
0
 /**
  * @NoAdminRequired
  */
 public function importEventsPerDrop()
 {
     $pCalid = $this->params('calid');
     $pAddCal = $this->params('addCal');
     $pAddCalCol = $this->params('addCalCol');
     $data = $this->params('data');
     $data = explode(',', $data);
     $data = end($data);
     $data = base64_decode($data);
     $import = new Import($data);
     $import->setUserID($this->userId);
     $import->setTimeZone(CalendarApp::$tz);
     $import->disableProgressCache();
     if (!$import->isValid()) {
         $params = ['status' => 'error', 'error' => 'notvalid'];
         $response = new JSONResponse($params);
         return $response;
     }
     if ($pCalid == 'newCal' && $pAddCal != '') {
         $calendars = CalendarCalendar::allCalendars($this->userId);
         foreach ($calendars as $calendar) {
             if ($calendar['displayname'] == $pAddCal) {
                 $id = $calendar['id'];
                 $newcal = false;
                 break;
             }
             $newcal = true;
         }
         if ($newcal) {
             $id = CalendarCalendar::addCalendar($this->userId, strip_tags($pAddCal), 'VEVENT,VTODO,VJOURNAL', null, 0, strip_tags($pAddCalCol));
             CalendarCalendar::setCalendarActive($id, 1);
         }
     } else {
         $id = $pCalid;
         $calendar = CalendarApp::getCalendar($id);
         if ($calendar['userid'] != $this->userId) {
             $params = ['status' => 'error', 'error' => 'missingcalendarrights'];
             $response = new JSONResponse($params);
             return $response;
         }
     }
     $import->setOverwrite(false);
     $import->setCalendarID($id);
     $import->import();
     $count = $import->getCount();
     if ($count == 0) {
         CalendarCalendar::deleteCalendar($id);
         $params = ['status' => 'error', 'message' => $this->l10n->t('The file contained either no events or all events are already saved in your calendar.')];
         $response = new JSONResponse($params);
         return $response;
     } else {
         $newcalendarname = strip_tags($pAddCal);
         if ($pAddCal != '') {
             $params = ['status' => 'success', 'message' => $count . ' ' . $this->l10n->t('events has been saved in the new calendar') . ' ' . $newcalendarname, 'eventSource' => CalendarCalendar::getEventSourceInfo(CalendarCalendar::find($id))];
             $response = new JSONResponse($params);
             return $response;
         } else {
             $params = ['status' => 'success', 'message' => $count . ' ' . $this->l10n->t('events has been saved in the calendar') . ' ' . $calendar['displayname'], 'eventSource' => ''];
             $response = new JSONResponse($params);
             return $response;
         }
     }
 }
 /**
  * @NoAdminRequired
  */
 public function getUserSettingsCalendar()
 {
     $firstDayConfig = $this->configInfo->getUserValue($this->userId, $this->appName, 'firstday', 'mo');
     $firstDay = $this->prepareFirstDay($firstDayConfig);
     $agendaTime = 'hh:mm tt { - hh:mm tt}';
     $defaultTime = 'hh:mm tt';
     $timeFormat = $this->configInfo->getUserValue($this->userId, $this->appName, 'timeformat', '24');
     if ($timeFormat === '24') {
         $agendaTime = 'HH:mm { - HH:mm}';
         $defaultTime = 'HH:mm { - HH:mm}';
     }
     $dateFormat = $this->configInfo->getUserValue($this->userId, $this->appName, 'dateformat', 'd-m-Y');
     $checkCat = CalendarApp::loadTags();
     $checkCatTagsList = '';
     $checkCatCategory = '';
     foreach ($checkCat['categories'] as $category) {
         $checkCatCategory[] = $category;
     }
     foreach ($checkCat['tagslist'] as $tag) {
         $checkCatTagsList[$tag['name']] = array('id' => $tag['id'], 'name' => $tag['name'], 'color' => $tag['color'], 'bgcolor' => $tag['bgcolor']);
     }
     $eventSources = [];
     $calendars = CalendarCalendar::allCalendars($this->userId);
     $calendarInfo = [];
     $myCalendars = [];
     $myRefreshChecker = [];
     foreach ($calendars as $calendar) {
         $isAktiv = (int) $calendar['active'];
         if ($this->configInfo->getUserValue($this->userId, $this->appName, 'calendar_' . $calendar['id']) !== '') {
             $isAktiv = (int) $this->configInfo->getUserValue($this->userId, $this->appName, 'calendar_' . $calendar['id']);
         }
         if (!array_key_exists('active', $calendar)) {
             $isAktiv = 1;
         }
         if ($this->userId !== $calendar['userid']) {
             $calendar['uri'] = $calendar['uri'] . '_shared_by_' . $calendar['userid'];
         }
         $addClass = '';
         if (isset($calendar['className'])) {
             $addClass = $calendar['className'];
         }
         $bgColor = '';
         $textColor = '';
         if (isset($calendar['calendarcolor'])) {
             $bgColor = $calendar['calendarcolor'];
             /*DEFAULT*/
             $textColorDefault = CalendarCalendar::generateTextColor($bgColor);
             $textColor = $bgColor;
         }
         if (isset($calendar['textColor'])) {
             /*DEFAULT*/
             $textColorDefault = $calendar['textColor'];
             $textColor = $bgColor;
         }
         $calendarInfo[$calendar['id']] = ['bgcolor' => $bgColor, 'color' => $textColorDefault, 'colorDefault' => $textColorDefault, 'name' => $calendar['displayname'], 'externuri' => $calendar['externuri'], 'uri' => $calendar['uri'], 'className' => $addClass];
         if ((int) $isAktiv === 1) {
             $eventSources[] = CalendarCalendar::getEventSourceInfo($calendar);
             $myCalendars[$calendar['id']] = ['id' => $calendar['id'], 'name' => $calendar['displayname'], 'uri' => $calendar['uri'], 'issubscribe' => (int) $calendar['issubscribe'], 'permissions' => (int) $calendar['permissions']];
             $myRefreshChecker[$calendar['id']] = $calendar['ctag'];
         }
     }
     $events_baseURL = \OC::$server->getURLGenerator()->linkToRoute($this->appName . '.event.getEvents');
     $eventSources[] = array('url' => $events_baseURL . '?calendar_id=shared_events', 'className' => 'shared-events', 'editable' => 'false');
     if ($this->configInfo->getUserValue($this->userId, $this->appName, 'userconfig')) {
         $userConfig = json_decode($this->configInfo->getUserValue($this->userId, $this->appName, 'userconfig'));
     } else {
         //Guest Config Public Page
         $userConfig = '{"agendaDay":"true","agendaThreeDays":"false","agendaWorkWeek":"false","agendaWeek":"true","month":"true","year":"false","list":"false"}';
         $userConfig = json_decode($userConfig);
     }
     $leftNavAktiv = $this->configInfo->getUserValue($this->userId, $this->appName, 'calendarnav');
     $rightNavAktiv = $this->configInfo->getUserValue($this->userId, $this->appName, 'tasknav');
     $taskAppActive = \OC::$server->getAppManager()->isEnabledForUser('tasksplus');
     $params = ['status' => 'success', 'defaultView' => $this->configInfo->getUserValue($this->userId, $this->appName, 'currentview', 'month'), 'agendatime' => $agendaTime, 'defaulttime' => $defaultTime, 'dateformat' => $dateFormat, 'timeformat' => $timeFormat, 'firstDay' => $firstDay, 'firstDayString' => $firstDayConfig, 'categories' => $checkCatCategory, 'tags' => $checkCatTagsList, 'eventSources' => $eventSources, 'calendarcolors' => $calendarInfo, 'mycalendars' => $myCalendars, 'myRefreshChecker' => $myRefreshChecker, 'choosenCalendar' => $this->configInfo->getUserValue($this->userId, $this->appName, 'choosencalendar'), 'userConfig' => $userConfig, 'sharetypeevent' => CalendarApp::SHAREEVENT, 'sharetypecalendar' => CalendarApp::SHARECALENDAR, 'leftnavAktiv' => $leftNavAktiv, 'rightnavAktiv' => $rightNavAktiv, 'taskAppActive' => $taskAppActive];
     $response = new JSONResponse($params);
     return $response;
 }
 /**
  * @NoAdminRequired
  */
 public function getUserSettingsCalendar()
 {
     $firstDayConfig = $this->configInfo->getUserValue($this->userId, $this->appName, 'firstday', 'mo');
     $firstDay = $this->prepareFirstDay($firstDayConfig);
     $agendaTime = 'hh:mm tt { - hh:mm tt}';
     $defaultTime = 'hh:mm tt';
     if ($this->configInfo->getUserValue($this->userId, $this->appName, 'timeformat', '24') === '24') {
         $agendaTime = 'HH:mm { - HH:mm}';
         $defaultTime = 'HH:mm';
     }
     $checkCat = CalendarApp::loadTags();
     $checkCatTagsList = '';
     $checkCatCategory = '';
     foreach ($checkCat['categories'] as $category) {
         $checkCatCategory[] = $category;
     }
     foreach ($checkCat['tagslist'] as $tag) {
         $checkCatTagsList[$tag['name']] = array('name' => $tag['name'], 'color' => $tag['color'], 'bgcolor' => $tag['bgcolor']);
     }
     $eventSources = [];
     $calendars = CalendarCalendar::allCalendars($this->userId);
     $calendarInfo = [];
     $myCalendars = [];
     $myRefreshChecker = [];
     foreach ($calendars as $calendar) {
         $isAktiv = $calendar['active'];
         if ($this->configInfo->getUserValue($this->userId, $this->appName, 'calendar_' . $calendar['id']) !== '') {
             $isAktiv = (int) $this->configInfo->getUserValue($this->userId, $this->appName, 'calendar_' . $calendar['id']);
         }
         if (!array_key_exists('active', $calendar)) {
             $isAktiv = 1;
         }
         if ((int) $isAktiv === 1) {
             $eventSources[] = CalendarCalendar::getEventSourceInfo($calendar);
             $calendarInfo[$calendar['id']] = ['bgcolor' => $calendar['calendarcolor'], 'color' => CalendarCalendar::generateTextColor($calendar['calendarcolor'])];
             $myCalendars[$calendar['id']] = ['id' => $calendar['id'], 'name' => $calendar['displayname'], 'issubscribe' => (int) $calendar['issubscribe'], 'permissions' => (int) $calendar['permissions']];
             $myRefreshChecker[$calendar['id']] = $calendar['ctag'];
         }
     }
     $events_baseURL = \OC::$server->getURLGenerator()->linkToRoute($this->appName . '.event.getEvents');
     $eventSources[] = array('url' => $events_baseURL . '?calendar_id=shared_events', 'backgroundColor' => '#1D2D44', 'borderColor' => '#888', 'textColor' => 'white', 'editable' => 'false');
     if ($this->configInfo->getUserValue($this->userId, $this->appName, 'userconfig')) {
         $userConfig = json_decode($this->configInfo->getUserValue($this->userId, $this->appName, 'userconfig'));
     } else {
         //Guest Config Public Page
         $userConfig = '{"agendaDay":"true","agendaThreeDays":"false","agendaWorkWeek":"false","agendaWeek":"true","month":"true","year":"false","list":"false"}';
         $userConfig = json_decode($userConfig);
     }
     $params = ['status' => 'success', 'defaultView' => $this->configInfo->getUserValue($this->userId, $this->appName, 'currentview', 'month'), 'agendatime' => $agendaTime, 'defaulttime' => $defaultTime, 'firstDay' => $firstDay, 'categories' => $checkCatCategory, 'tags' => $checkCatTagsList, 'eventSources' => $eventSources, 'calendarcolors' => $calendarInfo, 'mycalendars' => $myCalendars, 'myRefreshChecker' => $myRefreshChecker, 'choosenCalendar' => $this->configInfo->getUserValue($this->userId, $this->appName, 'choosencalendar'), 'userConfig' => $userConfig, 'sharetypeevent' => CalendarApp::SHAREEVENT, 'sharetypecalendar' => CalendarApp::SHARECALENDAR];
     $response = new JSONResponse($params);
     return $response;
 }