/**
  *@PublicPage
  * @NoCSRFRequired
  * 
  */
 public function exportEvents()
 {
     $token = $this->params('t');
     $calid = null;
     $eventid = null;
     if (isset($token)) {
         $linkItem = \OCP\Share::getShareByToken($token, false);
         if (is_array($linkItem) && isset($linkItem['uid_owner'])) {
             $rootLinkItem = \OCP\Share::resolveReShare($linkItem);
             if (isset($rootLinkItem['uid_owner'])) {
                 \OCP\JSON::checkUserExists($rootLinkItem['uid_owner']);
                 if ($linkItem['item_type'] === CalendarApp::SHARECALENDAR) {
                     $sPrefix = CalendarApp::SHARECALENDARPREFIX;
                 }
                 if ($linkItem['item_type'] === CalendarApp::SHAREEVENT) {
                     $sPrefix = CalendarApp::SHAREEVENTPREFIX;
                 }
                 if ($linkItem['item_type'] === CalendarApp::SHARETODO) {
                     $sPrefix = CalendarApp::SHARETODOPREFIX;
                 }
                 $itemSource = CalendarApp::validateItemSource($linkItem['item_source'], $sPrefix);
                 if ($linkItem['item_type'] === CalendarApp::SHARECALENDAR) {
                     $calid = $itemSource;
                 }
                 if ($linkItem['item_type'] === CalendarApp::SHAREEVENT || $linkItem['item_type'] === CalendarApp::SHARETODO) {
                     $eventid = $itemSource;
                 }
             }
         }
     } else {
         if (\OCP\User::isLoggedIn()) {
             $calid = $this->params('calid');
             $eventid = $this->params('eventid');
         }
     }
     if (!is_null($calid)) {
         $calendar = CalendarApp::getCalendar($calid, true);
         if (!$calendar) {
             $params = ['status' => 'error'];
             $response = new JSONResponse($params);
             return $response;
         }
         $name = str_replace(' ', '_', $calendar['displayname']) . '.ics';
         $calendarEvents = Export::export($calid, Export::CALENDAR);
         $response = new DataDownloadResponse($calendarEvents, $name, 'text/calendar');
         return $response;
     }
     if (!is_null($eventid)) {
         $data = CalendarApp::getEventObject($eventid, false);
         if (!$data) {
             $params = ['status' => 'error'];
             $response = new JSONResponse($params);
             return $response;
         }
         $name = str_replace(' ', '_', $data['summary']) . '.ics';
         $singleEvent = Export::export($eventid, Export::EVENT);
         $response = new DataDownloadResponse($singleEvent, $name, 'text/calendar');
         return $response;
     }
 }
Example #2
0
 public function __construct()
 {
     $timeNow = time();
     //test
     $checkOffset = new \DateTime(date('d.m.Y', $timeNow), new \DateTimeZone(self::$tz));
     $calcSumWin = $checkOffset->getOffset();
     $this->nowTime = strtotime(date('d.m.Y H:i', $timeNow)) + $calcSumWin;
     if (\OC::$server->getSession()->get('public_link_token')) {
         $linkItem = \OCP\Share::getShareByToken(\OC::$server->getSession()->get('public_link_token', false));
         if (is_array($linkItem) && isset($linkItem['uid_owner'])) {
             if ($linkItem['item_type'] === App::SHARECALENDAR) {
                 $sPrefix = App::SHARECALENDARPREFIX;
             }
             if ($linkItem['item_type'] === App::SHAREEVENT) {
                 $sPrefix = App::SHAREEVENTPREFIX;
             }
             if ($linkItem['item_type'] === App::SHARETODO) {
                 $sPrefix = App::SHARETODOPREFIX;
             }
             $itemSource = App::validateItemSource($linkItem['item_source'], $sPrefix);
             $rootLinkItem = Calendar::find($itemSource);
             $this->aCalendars[] = $rootLinkItem;
         }
     } else {
         if (\OCP\User::isLoggedIn()) {
             $this->aCalendars = Calendar::allCalendars(\OCP\User::getUser());
             $this->checkAlarm();
         }
     }
 }
Example #3
0
 public function formatItems($items, $format, $parameters = null)
 {
     $vtodos = array();
     if ($format === self::FORMAT_TODO) {
         $user_timezone = CalendarApp::getTimezone();
         foreach ($items as $item) {
             $item['item_source'] = CalendarApp::validateItemSource($item['item_source'], CalendarApp::SHARETODOPREFIX);
             if (!TasksApp::checkSharedTodo($item['item_source'])) {
                 $event = TasksApp::getEventObject($item['item_source']);
                 $vcalendar = VObject::parse($event['calendardata']);
                 $vtodo = $vcalendar->VTODO;
                 $accessclass = $vtodo->getAsString('CLASS');
                 if ($accessclass == '' || $accessclass == 'PUBLIC') {
                     $permissions['permissions'] = $item['permissions'];
                     $permissions['calendarcolor'] = '#cccccc';
                     $permissions['isOnlySharedTodo'] = true;
                     $permissions['calendarowner'] = Object::getowner($item['item_source']);
                     $permissions['displayname'] = $item['uid_owner'];
                     //\OCP\Util::writeLog('calendar','Cal Owner :'.$permissions['calendarowner'].$vtodo -> getAsString('SUMMARY') ,\OCP\Util::DEBUG);
                     $permissions['iscompleted'] = false;
                     if ($vtodo->COMPLETED) {
                         $permissions['iscompleted'] = true;
                         $vtodos['done'][] = TasksApp::arrayForJSON($item['item_source'], $vtodo, $user_timezone, $permissions, $event);
                     } else {
                         $vtodos['open'][] = TasksApp::arrayForJSON($item['item_source'], $vtodo, $user_timezone, $permissions, $event);
                     }
                 }
             }
             //$vtodos[] = $vtodo;
         }
     }
     return $vtodos;
 }
Example #4
0
 /**
  * @brief Returns all  shared events where user is owner
  * 
  * @return array
  */
 public static function getTodoSharees()
 {
     $SQL = 'SELECT item_source, item_type FROM `*PREFIX*share` WHERE `uid_owner` = ? AND `item_type` = ?';
     $stmt = \OCP\DB::prepare($SQL);
     $result = $stmt->execute(array(\OCP\User::getUser(), CalendarApp::SHARETODO));
     $aSharees = '';
     while ($row = $result->fetchRow()) {
         $itemSource = CalendarApp::validateItemSource($row['item_source'], CalendarApp::SHARETODOPREFIX);
         $aSharees[$itemSource] = 1;
     }
     if (is_array($aSharees)) {
         return $aSharees;
     } else {
         return false;
     }
 }
Example #5
0
 public function formatItems($items, $format, $parameters = null)
 {
     $events = array();
     if ($format == self::FORMAT_EVENT) {
         foreach ($items as $item) {
             $item['item_source'] = App::validateItemSource($item['item_source'], App::SHAREEVENTPREFIX);
             if (!Object::checkSharedEvent($item['item_source'])) {
                 $event = Object::find($item['item_source']);
                 $event['summary'] = $item['item_target'];
                 $event['item_source'] = (int) $item['item_source'];
                 $event['privat'] = false;
                 $event['shared'] = false;
                 $event['isalarm'] = $event['isalarm'];
                 $event['permissions'] = $item['permissions'];
                 //$event['userid'] = $event['userid'];
                 $event['orgevent'] = false;
                 $events[] = $event;
             }
         }
     }
     return $events;
 }
 private function getPublicEvent($itemSource, $shareOwner, $token)
 {
     $itemSource = CalendarApp::validateItemSource($itemSource, CalendarApp::SHAREEVENTPREFIX);
     $data = CalendarApp::getEventObject($itemSource, false, false);
     $object = VObject::parse($data['calendardata']);
     $vevent = $object->VEVENT;
     $object = Object::cleanByAccessClass($itemSource, $object);
     $accessclass = $vevent->getAsString('CLASS');
     if ($accessclass == 'PRIVATE') {
         header('HTTP/1.0 404 Not Found');
         $response = new TemplateResponse('core', '404', '', 'guest');
         return $response;
     }
     $permissions = CalendarApp::getPermissions($itemSource, CalendarApp::EVENT, $accessclass);
     $dtstart = $vevent->DTSTART;
     $dtend = Object::getDTEndFromVEvent($vevent);
     $dtstartType = $vevent->DTSTART->getValueType();
     if ($dtstartType == 'DATE') {
         $startdate = $dtstart->getDateTime()->format('d-m-Y');
         $starttime = '';
         $enddate = $dtend->getDateTime()->modify('-1 day')->format('d-m-Y');
         $endtime = '';
         $choosenDate = $choosenDate + 3600 * 24;
         $allday = true;
     }
     if ($dtstartType == 'DATE-TIME') {
         $startdate = $dtstart->getDateTime()->format('d-m-Y');
         $starttime = $dtstart->getDateTime()->format('H:i');
         $enddate = $dtend->getDateTime()->format('d-m-Y');
         $endtime = $dtend->getDateTime()->format('H:i');
         $allday = false;
     }
     $summary = strtr($vevent->getAsString('SUMMARY'), array('\\,' => ',', '\\;' => ';'));
     $location = strtr($vevent->getAsString('LOCATION'), array('\\,' => ',', '\\;' => ';'));
     $categories = $vevent->getAsArray('CATEGORIES');
     $description = strtr($vevent->getAsString('DESCRIPTION'), array('\\,' => ',', '\\;' => ';'));
     $link = strtr($vevent->getAsString('URL'), array('\\,' => ',', '\\;' => ';'));
     $last_modified = $vevent->__get('LAST-MODIFIED');
     if ($last_modified) {
         $lastmodified = $last_modified->getDateTime()->format('U');
     } else {
         $lastmodified = 0;
     }
     $repeatInfo = array();
     $repeat['repeat'] = '';
     if ($data['repeating'] == 1) {
         $rrule = explode(';', $vevent->getAsString('RRULE'));
         $rrulearr = array();
         $repeat['repeat_rules'] = '';
         foreach ($rrule as $rule) {
             list($attr, $val) = explode('=', $rule);
             if ($attr != 'COUNT' && $attr !== 'UNTIL') {
                 if ($repeat['repeat_rules'] === '') {
                     $repeat['repeat_rules'] = $attr . '=' . $val;
                 } else {
                     $repeat['repeat_rules'] .= ';' . $attr . '=' . $val;
                 }
             }
             if ($attr === 'COUNT' || $attr !== 'UNTIL') {
                 $rrulearr[$attr] = $val;
             }
         }
         if (array_key_exists('COUNT', $rrulearr)) {
             $repeat['end'] = 'count';
             $repeat['count'] = $rrulearr['COUNT'];
         } elseif (array_key_exists('UNTIL', $rrulearr)) {
             $repeat['end'] = 'date';
             $endbydate_day = substr($rrulearr['UNTIL'], 6, 2);
             $endbydate_month = substr($rrulearr['UNTIL'], 4, 2);
             $endbydate_year = substr($rrulearr['UNTIL'], 0, 4);
             $repeat['date'] = $endbydate_day . '-' . $endbydate_month . '-' . $endbydate_year;
         } else {
             $repeat['end'] = 'never';
         }
         $repeat_end_options = CalendarApp::getEndOptions();
         if ($repeat['end'] === 'count') {
             $repeatInfo['end'] = $this->l10n->t('after') . ' ' . $repeat['count'] . ' ' . $this->l10n->t('Events');
         }
         if ($repeat['end'] === 'date') {
             $repeatInfo['end'] = $repeat['date'];
         }
         if ($repeat['end'] === 'never') {
             $repeatInfo['end'] = $repeat_end_options[$repeat['end']];
         }
     } else {
         $repeat['repeat'] = 'doesnotrepeat';
     }
     $calendar_options[0]['id'] = $data['calendarid'];
     $access_class_options = CalendarApp::getAccessClassOptions();
     $aOExdate = '';
     if ($vevent->EXDATE) {
         $timezone = CalendarApp::getTimezone();
         foreach ($vevent->EXDATE as $param) {
             $param = new \DateTime($param);
             $aOExdate[$param->format('U')] = $param->format('d-m-Y');
         }
     }
     $timezone = \OC::$server->getSession()->get('public_link_timezone');
     $sCat = '';
     if (is_array($categories) && count($categories) > 0) {
         $sCat = $categories;
     }
     $params = ['eventid' => $itemSource, 'appname' => $this->appName, 'permissions' => $permissions, 'lastmodified' => $lastmodified, 'exDate' => $aOExdate, 'sharingToken' => $token, 'token' => $token, 'calendar_options' => $calendar_options, 'access_class_options' => $access_class_options, 'title' => $summary, 'accessclass' => $accessclass, 'location' => $location, 'calendar' => $data['calendarid'], 'timezone' => $timezone, 'uidOwner' => $shareOwner, 'displayName' => \OCP\User::getDisplayName($shareOwner), 'allday' => $allday, 'startdate' => $startdate, 'starttime' => $starttime, 'enddate' => $enddate, 'endtime' => $endtime, 'description' => $description, 'link' => $link, 'repeat_rules' => isset($repeat['repeat_rules']) ? $repeat['repeat_rules'] : '', 'repeat' => $repeat['repeat'], 'repeatInfo' => $repeat['repeat'] != 'doesnotrepeat' ? $repeatInfo : '', 'categories' => $sCat];
     $response = new TemplateResponse($this->appName, 'publicevent', $params, 'base');
     return $response;
 }
Example #7
0
    /**
     * @brief Returns all  shared calendar where user is owner
     * 
     * @return array
     * FIXME search for function on OCP\Share
     */
    public static function getCalendarSharees()
    {
        $SQL = 'SELECT `item_source`, `share_with`, `share_type` ,`permissions`, `item_type` FROM `*PREFIX*share` 
		WHERE `uid_owner` = ? AND `item_type` = ? 
		ORDER BY `item_source` ASC
		';
        $stmt = \OCP\DB::prepare($SQL);
        $result = $stmt->execute(array(\OCP\User::getUser(), App::SHARECALENDAR));
        $aSharees = '';
        while ($row = $result->fetchRow()) {
            $shareWith = '';
            $itemSource = App::validateItemSource($row['item_source'], App::SHARECALENDARPREFIX);
            if ($row['share_with'] && $row['share_type'] != 3) {
                $shareWith = ': ' . $row['share_with'];
            }
            if ($row['share_with'] && $row['share_type'] == 3) {
                $shareWith = ': password protected ';
            }
            $shareDescr = self::shareTypeDescription($row['share_type']) . ' ' . $shareWith . ' (' . Calendar::permissionReader($row['permissions']) . ")<br>";
            //$aSharees[][$itemSource]=array('myShare'=>1,'shareTypeDescr'=>$shareDescr);
            $aSharees[] = ['itemSource' => $itemSource, 'descr' => $shareDescr];
        }
        if (is_array($aSharees)) {
            $aReturn = [];
            $oldId = '';
            foreach ($aSharees as $shareInfo) {
                if ($shareInfo['itemSource'] != $oldId) {
                    $aReturn[$shareInfo['itemSource']] = $shareInfo['descr'];
                } else {
                    $aReturn[$shareInfo['itemSource']] .= $shareInfo['descr'];
                }
                $oldId = $shareInfo['itemSource'];
            }
            return $aReturn;
        } else {
            return false;
        }
    }
Example #8
0
 /**
  *@PublicPage
  * @NoCSRFRequired
  * @UseSession
  */
 public function index($token)
 {
     if ($token) {
         $linkItem = Share::getShareByToken($token, false);
         if (is_array($linkItem) && isset($linkItem['uid_owner'])) {
             $type = $linkItem['item_type'];
             $itemSource = CalendarApp::validateItemSource($linkItem['item_source'], CalendarApp::SHARETODOPREFIX);
             $shareOwner = $linkItem['uid_owner'];
             $calendarName = $linkItem['item_target'];
             $rootLinkItem = \OCP\Share::resolveReShare($linkItem);
             // stupid copy and paste job
             if (isset($linkItem['share_with'])) {
                 // Authenticate share_with
                 $password = $this->params('password');
                 if (isset($password)) {
                     if ($linkItem['share_type'] === \OCP\Share::SHARE_TYPE_LINK) {
                         // Check Password
                         $newHash = '';
                         if (\OC::$server->getHasher()->verify($password, $linkItem['share_with'], $newHash)) {
                             $this->session->set('public_link_authenticated', $linkItem['id']);
                             if (!empty($newHash)) {
                             }
                         } else {
                             \OCP\Util::addStyle('files_sharing', 'authenticate');
                             $params = array('wrongpw' => true);
                             return new TemplateResponse('files_sharing', 'authenticate', $params, 'guest');
                         }
                     } else {
                         \OCP\Util::writeLog('share', 'Unknown share type ' . $linkItem['share_type'] . ' for share id ' . $linkItem['id'], \OCP\Util::ERROR);
                         return false;
                     }
                 } else {
                     // Check if item id is set in session
                     if (!$this->session->exists('public_link_authenticated') || $this->session->get('public_link_authenticated') !== $linkItem['id']) {
                         // Prompt for password
                         \OCP\Util::addStyle('files_sharing', 'authenticate');
                         $params = array();
                         return new TemplateResponse('files_sharing', 'authenticate', $params, 'guest');
                     }
                 }
             }
             \OCP\Util::addStyle(CalendarApp::$appname, '3rdparty/fontello/css/animation');
             \OCP\Util::addStyle(CalendarApp::$appname, '3rdparty/fontello/css/fontello');
             \OCP\Util::addStyle($this->appName, 'style');
             \OCP\Util::addStyle($this->appName, 'share');
             \OCP\Util::addScript($this->appName, 'share');
             $data = TasksApp::getEventObject($itemSource, false, false);
             $l = \OC::$server->getL10N($this->appName);
             $object = VObject::parse($data['calendardata']);
             $vTodo = $object->VTODO;
             $id = $data['id'];
             $object = Object::cleanByAccessClass($id, $object);
             $accessclass = $vTodo->getAsString('CLASS');
             $permissions = TasksApp::getPermissions($id, TasksApp::TODO, $accessclass);
             if ($accessclass === 'PRIVATE') {
                 header('HTTP/1.0 404 Not Found');
                 $response = new TemplateResponse('core', '404', '', 'guest');
                 return $response;
             }
             $categories = $vTodo->getAsArray('CATEGORIES');
             $summary = strtr($vTodo->getAsString('SUMMARY'), array('\\,' => ',', '\\;' => ';'));
             $location = strtr($vTodo->getAsString('LOCATION'), array('\\,' => ',', '\\;' => ';'));
             $description = strtr($vTodo->getAsString('DESCRIPTION'), array('\\,' => ',', '\\;' => ';'));
             $priorityOptionsArray = TasksApp::getPriorityOptionsFilterd();
             //$priorityOptions=$priorityOptionsArray[(string)$vTodo->priority];
             $priorityOptions = 0;
             $link = strtr($vTodo->getAsString('URL'), array('\\,' => ',', '\\;' => ';'));
             $TaskDate = '';
             $TaskTime = '';
             if ($vTodo->DUE) {
                 $dateDueType = $vTodo->DUE->getValueType();
                 if ($dateDueType == 'DATE') {
                     $TaskDate = $vTodo->DUE->getDateTime()->format('d.m.Y');
                     $TaskTime = '';
                 }
                 if ($dateDueType == 'DATE-TIME') {
                     $TaskDate = $vTodo->DUE->getDateTime()->format('d.m.Y');
                     $TaskTime = $vTodo->DUE->getDateTime()->format('H:i');
                 }
             }
             $TaskStartTime = '';
             $TaskStartDate = '';
             if ($vTodo->DTSTART) {
                 $dateStartType = $vTodo->DTSTART->getValueType();
                 if ($dateStartType === 'DATE') {
                     $TaskStartDate = $vTodo->DTSTART->getDateTime()->format('d.m.Y');
                     $TaskStartTime = '';
                 }
                 if ($dateStartType === 'DATE-TIME') {
                     $TaskStartDate = $vTodo->DTSTART->getDateTime()->format('d.m.Y');
                     $TaskStartTime = $vTodo->DTSTART->getDateTime()->format('H:i');
                 }
             }
             //PERCENT-COMPLETE
             $cptlStatus = (string) $this->l10n->t('needs action');
             $percentComplete = 0;
             if ($vTodo->{'PERCENT-COMPLETE'}) {
                 $percentComplete = $vTodo->{'PERCENT-COMPLETE'};
                 //$cptlStatus = (string)$this->l10n->t('in procress');
                 if ($percentComplete === '0') {
                     $cptlStatus = (string) $this->l10n->t('needs action');
                 }
                 if ($percentComplete > '0' && $percentComplete < '100') {
                     $cptlStatus = (string) $this->l10n->t('in procress');
                 }
             }
             if ($vTodo->{'COMPLETED'}) {
                 $cptlStatus = (string) $this->l10n->t('completed');
             }
             $timezone = \OC::$server->getSession()->get('public_link_timezone');
             $sCat = '';
             if (is_array($categories) && count($categories) > 0) {
                 $sCat = $categories;
             }
             $params = ['eventid' => $itemSource, 'permissions' => $permissions, 'priorityOptions' => $priorityOptions, 'percentComplete' => $percentComplete, 'cptlStatus' => $cptlStatus, 'TaskDate' => isset($TaskDate) ? $TaskDate : '', 'TaskTime' => isset($TaskTime) ? $TaskTime : '', 'TaskStartDate' => isset($TaskStartDate) ? $TaskStartDate : '', 'TaskStartTime' => isset($TaskStartTime) ? $TaskStartTime : '', 'title' => $summary, 'accessclass' => $accessclass, 'location' => $location, 'categories' => $sCat, 'calendar' => $data['calendarid'], 'aCalendar' => CalendarApp::getCalendar($data['calendarid'], false, false), 'calAppName' => CalendarApp::$appname, 'description' => $description, 'repeat_rules' => '', 'link' => $link, 'timezone' => $timezone, 'uidOwner' => $shareOwner, 'displayName' => \OCP\User::getDisplayName($shareOwner), 'sharingToken' => $token, 'token' => $token];
             $response = new TemplateResponse($this->appName, 'publicevent', $params, 'base');
             return $response;
         }
         //end isset
     }
     //end token
     $tmpl = new \OCP\Template('', '404', 'guest');
     $tmpl->printPage();
 }
Example #9
0
 /**
  * @brief Converts the shared item sources back into the item in the specified format
  * @param array Shared items
  * @param int Format
  * @return ?
  *
  * The items array is a 3-dimensional array with the item_source as the first key and the share id as the second key to an array with the share info.
  * The key/value pairs included in the share info depend on the function originally called:
  * If called by getItem(s)Shared: id, item_type, item, item_source, share_type, share_with, permissions, stime, file_source
  * If called by getItem(s)SharedWith: id, item_type, item, item_source, item_target, share_type, share_with, permissions, stime, file_source, file_target
  * This function allows the backend to control the output of shared items with custom formats.
  * It is only called through calls to the public getItem(s)Shared(With) functions.
  */
 public function formatItems($items, $format, $parameters = null)
 {
     $calendars = array();
     if ($format == self::FORMAT_CALENDAR) {
         foreach ($items as $item) {
             $item['item_source'] = App::validateItemSource($item['item_source'], App::SHARECALENDARPREFIX);
             $calendar = App::getCalendar($item['item_source'], false);
             if (!$calendar) {
                 continue;
             }
             // TODO: really check $parameters['permissions'] == 'rw'/'r'
             if ($parameters['permissions'] == 'rw') {
                 continue;
                 // TODO
             }
             $calendar['displayname'] = $item['item_target'];
             $calendar['permissions'] = $item['permissions'];
             $calendar['calendarid'] = $calendar['id'];
             $calendar['owner'] = $calendar['userid'];
             $calendar['active'] = (int) $calendar['active'];
             $calendars[] = $calendar;
         }
     }
     return $calendars;
 }