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; }
/** * Returns a list of ACE's for this node. * * Each ACE has the following properties: * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are * currently the only supported privileges * * 'principal', a url to the principal who owns the node * * 'protected' (optional), indicating that this ACE is not allowed to * be updated. * * @return array */ public function getACL() { $readprincipal = $this->getOwner(); $writeprincipal = $this->getOwner(); $uid = CalendarCalendar::extractUserID($this->getOwner()); if ($uid != \OCP\USER::getUser()) { $object = VObject::parse($this->objectData['calendardata']); $sharedCalendar = \OCP\Share::getItemSharedWithBySource(CalendarApp::SHARECALENDAR, CalendarApp::SHARECALENDARPREFIX . $this->calendarInfo['id']); $sharedAccessClassPermissions = Object::getAccessClassPermissions($object); if ($sharedCalendar && $sharedCalendar['permissions'] & \OCP\PERMISSION_READ && $sharedAccessClassPermissions & \OCP\PERMISSION_READ) { $readprincipal = 'principals/' . \OCP\USER::getUser(); } if ($sharedCalendar && $sharedCalendar['permissions'] & \OCP\PERMISSION_UPDATE && $sharedAccessClassPermissions & \OCP\PERMISSION_UPDATE) { $writeprincipal = 'principals/' . \OCP\USER::getUser(); } else { $writeprincipal = ''; } } return array(array('privilege' => '{DAV:}read', 'principal' => $readprincipal, 'protected' => true), array('privilege' => '{DAV:}write', 'principal' => $writeprincipal, 'protected' => true), array('privilege' => '{DAV:}read', 'principal' => $readprincipal . '/calendar-proxy-write', 'protected' => true), array('privilege' => '{DAV:}write', 'principal' => $writeprincipal . '/calendar-proxy-write', 'protected' => true), array('privilege' => '{DAV:}read', 'principal' => $readprincipal . '/calendar-proxy-read', 'protected' => true)); }
/** * @NoAdminRequired */ public function touchCalendar() { $id = (int) $this->params('eventid'); $data = CalendarApp::getEventObject($id, false, false); $vcalendar = VObject::parse($data['calendardata']); $vevent = $vcalendar->VEVENT; $vevent->setDateTime('LAST-MODIFIED', 'now'); $vevent->setDateTime('DTSTAMP', 'now'); Object::edit($id, $vcalendar->serialize()); $params = ['status' => 'success']; $response = new JSONResponse($params); return $response; }
public function parseAlarm($aEvents) { $factor = 60; foreach ($aEvents as $event) { $startalarmtime = 0; $vMode = ''; $object = VObject::parse($event['calendardata']); if (isset($object->VEVENT)) { $vevent = $object->VEVENT; $dtstart = $vevent->DTSTART; $vMode = 'event'; } if (isset($object->VTODO)) { $vevent = $object->VTODO; $dtstart = $vevent->DUE; $vMode = 'todo'; } if ($event['startdate'] !== '' && ($vMode == 'event' || $vMode == 'todo')) { $starttimeTmp = new \DateTime($event['startdate'], new \DateTimeZone('UTC')); $starttimeTmp->setTimezone(new \DateTimeZone(self::$tz)); $starttime = $starttimeTmp->format('d.m.Y H:i'); } else { $starttime = $dtstart->getDateTime()->format('d.m.Y H:i'); } $startTimeShow = $starttime; $starttime = strtotime($starttime); if ($vevent->VALARM) { $valarm = $vevent->VALARM; $triggerTime = $valarm->getAsString('TRIGGER'); if (stristr($triggerTime, 'PT')) { $triggerAlarm = self::parseTrigger($triggerTime); $startalarmtime = $starttime + $triggerAlarm; } else { $triggerDate = $valarm->TRIGGER; if ($triggerDate->getValueType() !== 'DURATION' && $valarm->getAsString('ACTION') === 'DISPLAY') { $triggerAlarm = $triggerDate->getDateTime()->format('d.m.Y H:i'); $startalarmtime = strtotime($triggerAlarm); } } $triggerAction = $valarm->getAsString('ACTION'); } // $checktime=$startalarmtime-$this->nowTime; if ($this->nowTime == $startalarmtime) { $userid = Object::getowner($event['id']); $link = ''; $icon = ''; if ($vMode === 'event') { $link = \OC::$server->getURLGenerator()->linkToRoute(App::$appname . '.page.index') . '#' . urlencode($event['id']); $icon = 'calendar'; } if ($vMode === 'todo') { $link = \OC::$server->getURLGenerator()->linkToRoute('tasksplus.page.index') . '#' . urlencode($event['id']); $icon = 'tasks'; } $this->activeAlarms[$event['id']] = array('id' => $event['id'], 'userid' => $userid, 'icon' => $icon, 'link' => $link, 'action' => $triggerAction, 'summary' => $event['summary'], 'startdate' => $startTimeShow); } //\OCP\Util::writeLog('calendar', 'AlarmCheck Active:' . $event['summary'] . ' -> ' . date('d.m.Y H:i', $startalarmtime) . ' : ' . date('d.m.Y H:i', $this -> nowTime), \OCP\Util::DEBUG); } }
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; }
/** * @brief deletes an object * @param integer $id id of object * @return boolean */ public static function delete($id) { $oldobject = self::find($id); $calid = self::getCalendarid($id); $calendar = Calendar::find($calid); $oldvobject = VObject::parse($oldobject['calendardata']); if ($calendar['userid'] != \OCP\User::getUser()) { $shareMode = self::checkShareMode($calid); if ($shareMode) { $sharedCalendar = \OCP\Share::getItemSharedWithBySource(App::SHARECALENDAR, App::SHARECALENDARPREFIX . $calid); //calid, not objectid !!!! 1111 one one one eleven } else { $sharedCalendar = \OCP\Share::getItemSharedWithBySource(App::SHAREEVENT, App::SHAREEVENTPREFIX . $id); } $sharedAccessClassPermissions = Object::getAccessClassPermissions($oldvobject); if (!$sharedCalendar || !($sharedCalendar['permissions'] & \OCP\PERMISSION_DELETE) || !($sharedAccessClassPermissions & \OCP\PERMISSION_DELETE)) { throw new \Exception(App::$l10n->t('You do not have the permissions to delete this event.')); } } $stmt = \OCP\DB::prepare('DELETE FROM `' . App::CldObjectTable . '` WHERE `id` = ?'); $stmt->execute(array($id)); //DELETE SHARED ONLY EVENT if (\OCP\Share::unshareAll(App::SHAREEVENT, App::SHAREEVENTPREFIX . $id)) { //if($delId=Object::checkSharedEvent($id)){ $stmt = \OCP\DB::prepare('DELETE FROM `' . App::CldObjectTable . '` WHERE `org_objid` = ?'); $stmt->execute(array($id)); //} } Calendar::touchCalendar($oldobject['calendarid']); $app = new Application(); $c = $app->getContainer(); $repeatController = $c->query('RepeatController'); $repeatController->cleanEvent($id); //\OCP\Util::emitHook('\OCA\CalendarPlus', 'deleteEvent', $id); $params = array('mode' => 'deleted', 'link' => '', 'trans_type' => App::$l10n->t($oldobject['objecttype']), 'summary' => $oldobject['summary'], 'cal_user' => $calendar['userid'], 'cal_displayname' => $calendar['displayname']); ActivityData::logEventActivity($params); //App::getVCategories()->purgeObject($id); return true; }
/** * * @param string $query * @return \OCP\Search\Result */ function search($query) { $today = date('Y-m-d', time()); $allowedCommands = array('#ra' => 1, '#dt' => 1); $calendars = Calendar::allCalendars(\OCP\USER::getUser(), true); $activeCalendars = ''; $config = \OC::$server->getConfig(); foreach ($calendars as $calendar) { $isAktiv = $calendar['active']; if ($config->getUserValue(\OCP\USER::getUser(), CalendarApp::$appname, 'calendar_' . $calendar['id']) != '') { $isAktiv = $config->getUserValue(\OCP\USER::getUser(), CalendarApp::$appname, 'calendar_' . $calendar['id']); } if (!array_key_exists('active', $calendar)) { $isAktiv = 1; } if ($isAktiv == 1 && (int) $calendar['issubscribe'] === 0) { $activeCalendars[] = $calendar; } } if (count($activeCalendars) == 0 || !\OCP\App::isEnabled(CalendarApp::$appname)) { //return false; } $results = array(); $searchquery = array(); if (substr_count($query, ' ') > 0) { $searchquery = explode(' ', $query); } else { $searchquery[] = $query; } $user_timezone = CalendarApp::getTimezone(); $l = \OC::$server->getL10N(TasksApp::$appname); $isDate = false; if (strlen($query) >= 5 && self::validateDate($query)) { $isDate = true; //\OCP\Util::writeLog('calendar','VALID DATE FOUND', \OCP\Util::DEBUG); } //foreach($calendars as $calendar) { $objects = TasksApp::all($activeCalendars); foreach ($objects as $object) { if ($object['objecttype'] != 'VTODO') { continue; } $searchAdvanced = false; if ($isDate == true && strlen($query) >= 5) { $tempQuery = strtotime($query); $checkDate = date('Y-m-d', $tempQuery); if (substr_count($object['startdate'], $checkDate) > 0 || substr_count($object['enddate'], $checkDate) > 0) { $searchAdvanced = true; } } if (array_key_exists($query, $allowedCommands) && $allowedCommands[$query]) { if ($query == '#dt') { $search = $object['startdate']; if (substr_count($search, $today) > 0) { $searchAdvanced = true; } } if ($query == '#ra') { if ($object['isalarm'] == 1) { $searchAdvanced = true; } } } if (substr_count(strtolower($object['summary']), strtolower($query)) > 0 || $searchAdvanced == true) { $calendardata = VObject::parse($object['calendardata']); $vtodo = $calendardata->VTODO; if (Object::getowner($object['id']) !== \OCP\USER::getUser()) { if (isset($vtodo->CLASS) && $vtodo->CLASS->getValue() === 'CONFIDENTIAL') { continue; } if (isset($vtodo->CLASS) && ($vtodo->CLASS->getValue() === 'PRIVATE' || $vtodo->CLASS->getValue() === '')) { continue; } } if ($vtodo->DUE) { $dtstart = $vtodo->DUE; $start_dt = $dtstart->getDateTime(); $start_dt->setTimezone(new \DateTimeZone($user_timezone)); if ($dtstart->getValueType() == 'DATE') { $info = $l->t('Date') . ': ' . $start_dt->format('d.m.Y'); } else { $info = $l->t('Date') . ': ' . $start_dt->format('d.m.y H:i'); } } if ($vtodo->DTSTART) { $dtstart1 = $vtodo->DTSTART; $start_dt = $dtstart1->getDateTime(); $start_dt->setTimezone(new \DateTimeZone($user_timezone)); if ($dtstart1->getValueType() == 'DATE') { $info = $l->t('Date') . ': ' . $start_dt->format('d.m.Y'); } else { $info = $l->t('Date') . ': ' . $start_dt->format('d.m.y H:i'); } } $link = \OC::$server->getURLGenerator()->linkToRoute(TasksApp::$appname . '.page.index') . '#' . urlencode($object['id']); $returnData['id'] = $object['id']; $returnData['description'] = $object['summary'] . ' ' . $info; $returnData['link'] = $link; $results[] = new Result($returnData); } } //} return $results; }
/** * @brief generates the output for an event which will be readable for our js * @param (mixed) $event - event object / array * @param (int) $start - DateTime object of start * @param (int) $end - DateTime object of end * @return (array) $output - readable output */ public static function generateEventOutput(array $event, $start, $end, $list = false) { if (!isset($event['calendardata']) && !isset($event['vevent'])) { return false; } if (!isset($event['calendardata']) && isset($event['vevent'])) { $event['calendardata'] = "BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:ownCloud's Internal iCal System\n" . $event['vevent']->serialize() . "END:VCALENDAR"; } try { $object = VObject::parse($event['calendardata']); if (!$object) { \OCP\Util::writeLog(self::$appname, __METHOD__ . ' Error parsing event: ' . print_r($event, true), \OCP\Util::DEBUG); return array(); } $output = array(); if ($object->name === 'VEVENT') { $vevent = $object; } elseif (isset($object->VEVENT)) { $vevent = $object->VEVENT; } else { \OCP\Util::writeLog(self::$appname, __METHOD__ . ' Object contains not event: ' . print_r($event, true), \OCP\Util::DEBUG); return $output; } $id = $event['id']; $SUMMARY = !is_null($vevent->SUMMARY) && $vevent->SUMMARY->getValue() != '' ? strtr($vevent->SUMMARY->getValue(), array('\\,' => ',', '\\;' => ';')) : (string) self::$l10n->t('unnamed'); if ($event['summary'] != '') { $SUMMARY = $event['summary']; } if (Object::getowner($id) !== \OCP\USER::getUser()) { // do not show events with private or unknown access class // \OCP\Util::writeLog('calendar','Sharee ID: ->'.$event['calendarid'].':'.$event['summary'], \OCP\Util::DEBUG); if (isset($vevent->CLASS) && $vevent->CLASS->getValue() === 'CONFIDENTIAL') { $SUMMARY = (string) self::$l10n->t('Busy'); } if (isset($vevent->CLASS) && ($vevent->CLASS->getValue() === 'PRIVATE' || $vevent->CLASS->getValue() === '')) { return $output; } $object = Object::cleanByAccessClass($id, $object); } $event['orgevent'] = ''; if (array_key_exists('org_objid', $event) && $event['org_objid'] > 0) { $event['orgevent'] = array('calendarcolor' => '#000'); } $event['isalarm'] = false; if (isset($vevent->VALARM)) { $event['isalarm'] = true; } $event['privat'] = false; if (isset($vevent->CLASS) && $vevent->CLASS->getValue() === 'PRIVATE') { $event['privat'] = 'private'; } if (isset($vevent->CLASS) && $vevent->CLASS->getValue() === 'CONFIDENTIAL') { $event['privat'] = 'confidential'; } $allday = $vevent->DTSTART->getValueType() == 'DATE' ? true : false; $last_modified = @$vevent->__get('LAST-MODIFIED'); $calid = ''; if (array_key_exists('calendarid', $event)) { $calid = $event['calendarid']; } /* $eventPerm = ''; if (array_key_exists('permissions', $event)) { $eventPerm = Calendar::permissionReader($event['permissions']); } $location = (!is_null($vevent -> LOCATION) && $vevent -> LOCATION -> getValue() != '') ? $vevent -> getAsString('LOCATION') : ''; */ $bDay = false; if (array_key_exists('bday', $event)) { $bDay = $event['bday']; } $isEventShared = false; if (isset($event['shared']) && $event['shared'] === 1) { $isEventShared = $event['shared']; } $lastmodified = $last_modified ? $last_modified->getDateTime()->format('U') : 0; $staticoutput = array('id' => (int) $event['id'], 'title' => $SUMMARY, 'lastmodified' => $lastmodified, 'categories' => $vevent->getAsArray('CATEGORIES'), 'calendarid' => (int) $calid, 'bday' => $bDay, 'shared' => $isEventShared, 'privat' => $event['privat'], 'isrepeating' => false, 'isalarm' => $event['isalarm'], 'orgevent' => $event['orgevent'], 'allDay' => $allday); if (Object::isrepeating($id) && Repeat::is_cached_inperiod($event['id'], $start, $end)) { $cachedinperiod = Repeat::get_inperiod($id, $start, $end); foreach ($cachedinperiod as $cachedevent) { $dynamicoutput = array(); if ($allday) { $start_dt = new \DateTime($cachedevent['startdate'], new \DateTimeZone('UTC')); $end_dt = new \DateTime($cachedevent['enddate'], new \DateTimeZone('UTC')); $dynamicoutput['start'] = $start_dt->format('Y-m-d'); $dynamicoutput['end'] = $end_dt->format('Y-m-d'); $dynamicoutput['startlist'] = $start_dt->format('Y/m/d'); $dynamicoutput['endlist'] = $end_dt->format('Y/m/d'); } else { $start_dt = new \DateTime($cachedevent['startdate'], new \DateTimeZone('UTC')); $end_dt = new \DateTime($cachedevent['enddate'], new \DateTimeZone('UTC')); $start_dt->setTimezone(new \DateTimeZone(self::$tz)); $end_dt->setTimezone(new \DateTimeZone(self::$tz)); $dynamicoutput['start'] = $start_dt->format('Y-m-d H:i:s'); $dynamicoutput['end'] = $end_dt->format('Y-m-d H:i:s'); $dynamicoutput['startlist'] = $start_dt->format('Y/m/d H:i:s'); $dynamicoutput['endlist'] = $end_dt->format('Y/m/d H:i:s'); } $dynamicoutput['isrepeating'] = true; $output[] = array_merge($staticoutput, $dynamicoutput); } } else { if (Object::isrepeating($id) || $event['repeating'] == 1) { $object->expand($start, $end); } foreach ($object->getComponents() as $singleevent) { if (!$singleevent instanceof \Sabre\VObject\Component\VEvent) { continue; } $dynamicoutput = Object::generateStartEndDate($singleevent->DTSTART, Object::getDTEndFromVEvent($singleevent), $allday, self::$tz); $output[] = array_merge($staticoutput, $dynamicoutput); } } return $output; } catch (\Exception $e) { $uid = 'unknown'; if (isset($event['uri'])) { $uid = $event['uri']; } \OCP\Util::writeLog(self::$appname, 'Event (' . $uid . ') contains invalid data!', \OCP\Util::WARN); } }
public function generateTasksToCalendarOutput() { $this->aTasksOutput = \OCP\Share::getItemsSharedWith(CalendarApp::SHARETODO, Vtodo::FORMAT_TODO); foreach ($this->aTasks as $task) { if ($task['objecttype'] != 'VTODO') { continue; } if (is_null($task['summary'])) { continue; } $object = VObject::parse($task['calendardata']); $vtodo = $object->VTODO; $isCompleted = $vtodo->COMPLETED; try { if ($this->sMode != '' && $this->sMode != 'alltasksdone') { //if($isCompleted){ //$this->aTasksOutput['done'][] = App::arrayForJSON($task['id'], $vtodo, $this->dUserTimeZone,$this->aCalendar[$task['calendarid']],$task); //}else{ $this->aTasksOutput['open'][] = App::arrayForJSON($task['id'], $vtodo, $this->dUserTimeZone, $this->aCalendar[$task['calendarid']], $task); //} } elseif ($this->sMode != '' && $this->sMode == 'alltasksdone') { if ($isCompleted) { //$dateCompleted=$isCompleted->getDateTime() -> format('d.m.Y'); $this->aTasksOutput['done'][] = App::arrayForJSON($task['id'], $vtodo, $this->dUserTimeZone, $this->aCalendar[$task['calendarid']], $task); } } else { //if($isCompleted){ //$this->aTasksOutput['done'][] = App::arrayForJSON($task['id'], $vtodo, $this->dUserTimeZone,$this->aCalendar[$task['calendarid']],$task); //}else{ $this->aTasksOutput['open'][] = App::arrayForJSON($task['id'], $vtodo, $this->dUserTimeZone, $this->aCalendar[$task['calendarid']], $task); //} } } catch (\Exception $e) { \OCP\Util::writeLog(App::$appname, $e->getMessage(), \OCP\Util::ERROR); } } }
private function getVobjectData($id, $choosenDate, $data) { $result = []; if (!$data) { return false; } $sDateFormat = $this->configInfo->getUserValue($this->userId, $this->appName, 'dateformat', 'd-m-Y'); $object = VObject::parse($data['calendardata']); $vevent = $object->VEVENT; $object = Object::cleanByAccessClass($id, $object); $result['accessclass'] = $vevent->getAsString('CLASS'); $result['permissions'] = CalendarApp::getPermissions($id, CalendarApp::EVENT, $result['accessclass']); $dtstart = $vevent->DTSTART; $result['dtstart'] = $dtstart; $dtend = Object::getDTEndFromVEvent($vevent); $dateStartType = (string) $vevent->DTSTART->getValueType(); if ($dateStartType === 'DATE') { $result['startdate'] = $dtstart->getDateTime()->format($sDateFormat); $result['starttime'] = ''; $result['enddate'] = $dtend->getDateTime()->modify('-1 day')->format($sDateFormat); $result['endtime'] = ''; $result['choosenDate'] = $choosenDate + 3600 * 24; $result['allday'] = true; } if ($dateStartType === 'DATE-TIME') { $tz = CalendarApp::getTimezone(); $start_dt = new \DateTime($data['startdate'], new \DateTimeZone('UTC')); $end_dt = new \DateTime($data['enddate'], new \DateTimeZone('UTC')); $start_dt->setTimezone(new \DateTimeZone($tz)); $end_dt->setTimezone(new \DateTimeZone($tz)); $result['startdate'] = $start_dt->format($sDateFormat); $result['starttime'] = $start_dt->format('H:i'); $result['enddate'] = $end_dt->format($sDateFormat); $result['endtime'] = $end_dt->format('H:i'); $result['allday'] = false; $result['choosenDate'] = $choosenDate; } $result['summary'] = strtr($vevent->getAsString('SUMMARY'), array('\\,' => ',', '\\;' => ';')); $result['location'] = strtr($vevent->getAsString('LOCATION'), array('\\,' => ',', '\\;' => ';')); $result['categories'] = $vevent->getAsString('CATEGORIES'); $result['description'] = strtr($vevent->getAsString('DESCRIPTION'), array('\\,' => ',', '\\;' => ';')); $result['link'] = strtr($vevent->getAsString('URL'), array('\\,' => ',', '\\;' => ';')); $last_modified = $vevent->__get('LAST-MODIFIED'); if ($last_modified) { $result['lastmodified'] = $last_modified->getDateTime()->format('U'); } else { $result['lastmodified'] = 0; } $result['addSingleDeleteButton'] = false; if ((int) $data['repeating'] === 1) { $result['addSingleDeleteButton'] = true; $rrule = explode(';', $vevent->getAsString('RRULE')); $result['rrule'] = $this->parseRrules($rrule); } else { $result['rrule']['repeat'] = 'doesnotrepeat'; } //NEW Reminder $result['reminder_options'] = CalendarApp::getReminderOptions(); $result['alarm'] = $this->parseValarm($vevent, $result['reminder_options']); return $result; }
/** *@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(); }
/** * @NoAdminRequired */ public function editTask() { //relatedto,hiddenfield, read_worker,$_POST,mytaskcal, mytaskmode $id = $this->params('tid'); $hiddenPostField = $this->params('hiddenfield'); $myTaskCal = $this->params('mytaskcal'); $myTaskMode = $this->params('mytaskmode'); $data = TasksApp::getEventObject($id, false, false); $object = VObject::parse($data['calendardata']); $calId = Object::getCalendarid($id); $orgId = $data['org_objid']; //Search for Main Task $mainTaskId = ''; if ($data['relatedto'] !== '') { $mainTaskId = TasksApp::getEventIdbyUID($data['relatedto']); } //Search for Sub Tasks $subTaskIds = ''; if ($data['relatedto'] === '') { $subTaskIds = TasksApp::getSubTasks($data['eventuid']); } if (isset($hiddenPostField) && $hiddenPostField === 'edititTask' && $id > 0) { $cid = $this->params('read_worker'); $postRequestAll = $this->getParams(); TasksApp::updateVCalendarFromRequest($postRequestAll, $object); TasksApp::edit($id, $object->serialize(), $orgId); if ($mainTaskId === '') { $mainTaskId = $id; } if ($calId !== intval($cid)) { Object::moveToCalendar($id, intval($cid)); if ($subTaskIds !== '') { $tempIds = explode(',', $subTaskIds); foreach ($tempIds as $subIds) { Object::moveToCalendar($subIds, intval($cid)); } } } $vcalendar1 = TasksApp::getVCalendar($id, true, true); $vtodo = $vcalendar1->VTODO; $aTask = TasksApp::getEventObject($id, true, true); $aCalendar = CalendarCalendar::find($aTask['calendarid']); $user_timezone = CalendarApp::getTimezone(); $task_info = TasksApp::arrayForJSON($id, $vtodo, $user_timezone, $aCalendar, $aTask); $task_info['olduid'] = $data['eventuid']; $task_info['oldcalendarid'] = $data['calendarid']; $response = new JSONResponse(); $response->setData($task_info); return $response; } $vtodo = $object->VTODO; $object = Object::cleanByAccessClass($id, $object); $accessclass = $vtodo->getAsString('CLASS'); if (empty($accessclass)) { $accessclass = 'PUBLIC'; } $permissions = TasksApp::getPermissions($id, TasksApp::TODO, $accessclass); $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'); } } $TaskStartDate = ''; $TaskStartTime = ''; 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'); } } $priority = $vtodo->getAsString('PRIORITY'); $calendarsArrayTmp = CalendarCalendar::allCalendars($this->userId, true); //Filter Importent Values $calendar_options = array(); $checkArray = array(); $checkShareArray = array(); $bShareCalId = ''; foreach ($calendarsArrayTmp as $calendar) { $isAktiv = $calendar['active']; if ($this->configInfo->getUserValue($this->userId, CalendarApp::$appname, 'calendar_' . $calendar['id']) != '') { $isAktiv = $this->configInfo->getUserValue($this->userId, CalendarApp::$appname, 'calendar_' . $calendar['id']); } if (!array_key_exists('active', $calendar)) { $isAktiv = 1; } if ((int) $isAktiv === 1 && $calendar['userid'] !== $this->userId || $mainTaskId !== '') { $sharedCalendar = \OCP\Share::getItemSharedWithBySource(CalendarApp::SHARECALENDAR, CalendarApp::SHARECALENDARPREFIX . $calendar['id']); if ($sharedCalendar && $sharedCalendar['permissions'] & \OCP\PERMISSION_UPDATE && $mainTaskId === '') { array_push($calendar_options, $calendar); $checkShareArray[$calendar['id']] = $sharedCalendar['permissions']; } } if ($isAktiv === 1 && $calendar['userid'] === $this->userId) { array_push($calendar_options, $calendar); $checkShareArray[$calendar['id']] = \OCP\PERMISSION_ALL; } } if (!array_key_exists($calId, $checkShareArray)) { $bShareCalId = 'hide'; } $priorityOptionsArray = TasksApp::getPriorityOptionsFilterd(); $priorityOptions = TasksApp::generateSelectFieldArray('priority', (string) $vtodo->priority, $priorityOptionsArray, false); $access_class_options = CalendarApp::getAccessClassOptions(); //NEW Reminder $reminder_options = CalendarApp::getReminderOptions(); $reminder_advanced_options = CalendarApp::getAdvancedReminderOptions(); $reminder_time_options = CalendarApp::getReminderTimeOptions(); //reminder $vtodosharees = array(); $sharedwithByVtodo = \OCP\Share::getItemShared(CalendarApp::SHARETODO, CalendarApp::SHARETODOPREFIX . $id); if (is_array($sharedwithByVtodo)) { foreach ($sharedwithByVtodo as $share) { if ($share['share_type'] == \OCP\Share::SHARE_TYPE_USER || $share['share_type'] == \OCP\Share::SHARE_TYPE_GROUP) { $vtodosharees[] = $share; } } } $percentCompleted = '0'; if ($vtodo->{'PERCENT-COMPLETE'}) { $percentCompleted = $vtodo->getAsString('PERCENT-COMPLETE'); } $aAlarm = $this->setAlarmTask($vtodo, $reminder_options); $params = ['id' => $id, 'calId' => $calId, 'orgId' => $orgId, 'permissions' => $permissions, 'priorityOptions' => $priorityOptions, 'access_class_options' => $access_class_options, 'calendar_options' => $calendar_options, 'calendar' => $calId, 'mymode' => $myTaskMode, 'mycal' => $myTaskCal, 'bShareCalId' => $bShareCalId, 'subtaskids' => $subTaskIds, 'cal_permissions' => $checkShareArray, 'accessclass' => $accessclass, 'reminder_options' => $reminder_options, 'reminder_rules' => array_key_exists('triggerRequest', $aAlarm) ? $aAlarm['triggerRequest'] : '', 'reminder' => $aAlarm['action'], 'reminder_time_options' => $reminder_time_options, 'reminder_advanced_options' => $reminder_advanced_options, 'reminder_advanced' => 'DISPLAY', 'remindertimeselect' => array_key_exists('reminder_time_select', $aAlarm) ? $aAlarm['reminder_time_select'] : '', 'remindertimeinput' => array_key_exists('reminder_time_input', $aAlarm) ? $aAlarm['reminder_time_input'] : '', 'reminderemailinput' => array_key_exists('email', $aAlarm) ? $aAlarm['email'] : '', 'reminderdate' => array_key_exists('reminderdate', $aAlarm) ? $aAlarm['reminderdate'] : '', 'remindertime' => array_key_exists('remindertime', $aAlarm) ? $aAlarm['remindertime'] : '', 'link' => $link, 'priority' => $priority, 'TaskDate' => $TaskDate, 'TaskTime' => $TaskTime, 'TaskStartDate' => $TaskStartDate, 'TaskStartTime' => $TaskStartTime, 'vtodosharees' => $vtodosharees, 'percentCompleted' => $percentCompleted, 'sharetodo' => CalendarApp::SHARETODO, 'sharetodoprefix' => CalendarApp::SHARETODOPREFIX, 'vtodo' => $vtodo]; $response = new TemplateResponse($this->appName, 'event.edit', $params, ''); return $response; }
/** * scan events for categories. * @param $events VEVENTs to scan. null to check all events for the current user. */ public static function scanCategories($events = null) { if (is_null($events)) { $calendars = CalendarCalendar::allCalendars(\OCP\USER::getUser()); if (count($calendars) > 0) { $events = array(); foreach ($calendars as $calendar) { if ($calendar['userid'] === \OCP\User::getUser()) { $calendar_events = Object::all($calendar['id']); $events = $events + $calendar_events; } } } } if (is_array($events) && count($events) > 0) { $vcategories = \OC::$server->getTagManager()->load('event'); $getName = function ($tag) { return $tag['name']; }; $tags = array_map($getName, $vcategories->getTags()); $vcategories->delete($tags); foreach ($events as $event) { $vobject = VObject::parse($event['calendardata']); if (!is_null($vobject)) { $object = null; if (isset($calendar->VEVENT)) { $object = $calendar->VEVENT; } else { if (isset($calendar->VTODO)) { $object = $calendar->VTODO; } else { if (isset($calendar->VJOURNAL)) { $object = $calendar->VJOURNAL; } } } if ($object && isset($object->CATEGORIES)) { $vcategories->addMultiple($object->CATEGORIES->getParts(), true, $event['id']); } } } } }
/** * @NoAdminRequired * * @brief generates the cache the first time * @param integer $id * @return bool true */ public function generateEventCache($id) { $event = Object::find($id); if ((int) $event['repeating'] === 0) { return false; } $calendarId = Object::getCalendarid($id); $object = VObject::parse($event['calendardata']); $start = new \DateTime('01-01-' . date('Y') . ' 00:00:00', new \DateTimeZone('UTC')); $start->modify('-2 years'); $end = new \DateTime('31-12-' . date('Y') . ' 23:59:59', new \DateTimeZone('UTC')); $end->modify('+2 years'); $object->expand($start, $end); foreach ($object->getComponents() as $vevent) { if (!$vevent instanceof \Sabre\VObject\Component) { continue; } $startenddate = Object::generateStartEndDate($vevent->DTSTART, Object::getDTEndFromVEvent($vevent), !$vevent->DTSTART->hasTime(), 'UTC'); $this->repeatDB->insertEvent($id, $calendarId, $startenddate['start'], $startenddate['end']); } return true; }
/** * @brief returns the parsed calendar data * @param int $id - id of the event * @param bool $security - check access rights or not * @return mixed - bool / object */ public static function getVCalendar($id, $security = true, $shared = false) { $event_object = self::getEventObject($id, $security, $shared); if ($event_object === false) { return false; } $vobject = VObject::parse($event_object['calendardata']); if (is_null($vobject)) { return false; } return $vobject; }
/** * Returns information from a single calendar object, based on it's object * uri. * * The returned array must have the same keys as getCalendarObjects. The * 'calendardata' object is required here though, while it's not required * for getCalendarObjects. * * @param string $calendarId * @param string $objectUri * @return array */ public function getCalendarObject($calendarId, $objectUri) { $data = Object::findWhereDAVDataIs($calendarId, $objectUri); if (is_array($data)) { $data = $this->OCAddETag($data); $object = VObject::parse($data['calendardata']); if (!$object) { return false; } $object = Object::cleanByAccessClass($data['id'], $object); $data['calendardata'] = $object->serialize(); //$data = $this->OCAddETag($data); return $data; } else { return false; } }