Ejemplo n.º 1
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;
 }
Ejemplo n.º 2
0
 /**
  * @NoAdminRequired
  */
 public function setCompletedTask()
 {
     $id = $this->params('id');
     $checked = $this->params('checked');
     $vcalendar = CalendarApp::getVCalendar($id);
     $vtodo = $vcalendar->VTODO;
     TasksApp::setComplete($vtodo, $checked ? 100 : 0, null);
     Object::edit($id, $vcalendar->serialize());
     $user_timezone = CalendarApp::getTimezone();
     $aTask = TasksApp::getEventObject($id, true, true);
     $aCalendar = CalendarCalendar::find($aTask['calendarid']);
     $task_info[] = TasksApp::arrayForJSON($id, $vtodo, $user_timezone, $aCalendar, $aTask);
     $subTaskIds = '';
     if ($aTask['relatedto'] === '') {
         $subTaskIds = TasksApp::getSubTasks($aTask['eventuid']);
         if ($subTaskIds !== '') {
             $tempIds = explode(',', $subTaskIds);
             foreach ($tempIds as $subIds) {
                 $vcalendar = TasksApp::getVCalendar($subIds, true, true);
                 $vtodo = $vcalendar->VTODO;
                 TasksApp::setComplete($vtodo, $checked ? 100 : 0, null);
                 TasksApp::edit($subIds, $vcalendar->serialize());
                 $task_info[] = TasksApp::arrayForJSON($subIds, $vtodo, $user_timezone, $aCalendar, $aTask);
             }
         }
     }
     $params = ['status' => 'success', 'data' => $task_info];
     $response = new JSONResponse($params);
     return $response;
 }
 /**
  * @NoAdminRequired
  * @NoCSRFRequired
  */
 public function index()
 {
     $calendars = CalendarCalendar::allCalendars($this->userId);
     $allcached = true;
     foreach ($calendars as $calendar) {
         if (!$this->repeatController->isCalendarCached($calendar['id'])) {
             $allcached = 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 = ['appname' => $this->appName, 'timezone' => $this->configInfo->getUserValue($this->userId, $this->appName, 'timezone', ''), 'timezones' => \DateTimeZone::listIdentifiers(), 'calendars' => $calendars, 'mySharedCalendars' => Object::getCalendarSharees(), 'isShareApiActive' => \OC::$server->getAppConfig()->getValue('core', 'shareapi_enabled', 'yes'), 'timeformat' => $this->configInfo->getUserValue($this->userId, $this->appName, 'timeformat', '24'), 'dateformat' => $this->configInfo->getUserValue($this->userId, $this->appName, 'dateformat', 'd-m-Y'), 'timezonedetection' => $this->configInfo->getUserValue($this->userId, $this->appName, 'timezonedetection'), 'firstday' => $this->configInfo->getUserValue($this->userId, $this->appName, 'firstday', 'mo'), 'allCalendarCached' => $allcached, 'userConfig' => $userConfig];
     $response = new TemplateResponse($this->appName, 'settings', $params, '');
     return $response;
 }
Ejemplo n.º 4
0
 /**
  * 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));
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 6
0
 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;
 }
Ejemplo n.º 7
0
 /**
  * @brief Remove all properties which should not be exported for the AccessClass Confidential
  * @param string $id Event ID
  * @param VObject_VObject $vobject Sabre VObject
  * @return object
  */
 public static function cleanByAccessClass($id, $vobject)
 {
     // Do not clean your own calendar
     if (Object::getowner($id) === \OCP\USER::getUser()) {
         return $vobject;
     }
     if (isset($vobject->VEVENT)) {
         $velement = $vobject->VEVENT;
     } elseif (isset($vobject->VJOURNAL)) {
         $velement = $vobject->VJOURNAL;
     } elseif (isset($vobject->VTODO)) {
         $velement = $vobject->VTODO;
     }
     if (isset($velement->CLASS) && $velement->CLASS->getValue() == 'CONFIDENTIAL') {
         foreach ($velement->children as &$property) {
             switch ($property->name) {
                 case 'CREATED':
                 case 'DTSTART':
                 case 'RRULE':
                 case 'DURATION':
                 case 'DTEND':
                 case 'CLASS':
                 case 'UID':
                     break;
                 case 'SUMMARY':
                     $property->setValue(App::$l10n->t('Busy'));
                     break;
                 default:
                     $velement->__unset($property->name);
                     unset($property);
                     break;
             }
         }
     }
     return $vobject;
 }
Ejemplo n.º 8
0
 /**
  * 
  * @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;
 }
Ejemplo n.º 9
0
 /**
  * @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);
     }
 }
Ejemplo n.º 10
0
 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;
 }
Ejemplo n.º 11
0
 /**
  * Deletes an existing calendar object.
  *
  * @param string $calendarId
  * @param string $objectUri
  * @return void
  */
 public function deleteCalendarObject($calendarId, $objectUri)
 {
     $calendar = CalendarCalendar::find($calendarId);
     $bAccess = true;
     if ($calendar['userid'] !== \OCP\User::getUser()) {
         $sharedCalendar = \OCP\Share::getItemSharedWithBySource(CalendarApp::SHARECALENDAR, CalendarApp::SHARECALENDARPREFIX . $calendarId);
         if (!$sharedCalendar || !($sharedCalendar['permissions'] & \OCP\PERMISSION_UPDATE)) {
             $bAccess = false;
             \OCP\Util::writeLog('calendarplus', 'CALDAV -> DELETE Permission denied! Calendar ' . $calendar['displayname'], \OCP\Util::DEBUG);
         }
     }
     if ($bAccess === true) {
         Object::deleteFromDAVData($calendarId, $objectUri);
     }
 }
Ejemplo n.º 12
0
 /**
  * @NoAdminRequired
  */
 public function deleteTask()
 {
     $id = $this->params('id');
     $task = CalendarApp::getEventObject($id);
     //Search for Sub Tasks
     $subTaskIds = '';
     if ($task['relatedto'] === '') {
         $subTaskIds = TasksApp::getSubTasks($task['eventuid']);
         if ($subTaskIds !== '') {
             $tempIds = explode(',', $subTaskIds);
             foreach ($tempIds as $subIds) {
                 Object::delete($subIds);
             }
         }
     }
     Object::delete($id);
     $params = ['id' => $id];
     $response = new JSONResponse();
     $response->setData($params);
     return $response;
 }
Ejemplo n.º 13
0
 /**
  * @brief analyses the parameter for calendar parameter and returns the objects
  * @param (string) $calendarid - calendarid
  * @param (int) $start - unixtimestamp of start
  * @param (int) $end - unixtimestamp of end
  * @return (array) $events
  */
 public static function getrequestedEvents($calendarid, $start, $end)
 {
     $events = array();
     if ($calendarid === 'shared_events') {
         $checkStart = $start->format('U');
         $singleevents = \OCP\Share::getItemsSharedWith(self::SHAREEVENT, ShareEvent::FORMAT_EVENT);
         foreach ($singleevents as $singleevent) {
             $startCheck_dt = new \DateTime($singleevent['startdate'], new \DateTimeZone('UTC'));
             $checkStartSE = $startCheck_dt->format('U');
             if ($checkStartSE > $checkStart) {
                 $singleevent['summary'] .= ' (' . (string) self::$l10n->t('by') . ' ' . Object::getowner($singleevent['id']) . ')';
                 $events[] = $singleevent;
             }
         }
     } else {
         if (is_numeric($calendarid)) {
             $calendar = self::getCalendar($calendarid);
             \OCP\Response::enableCaching(0);
             \OCP\Response::setETagHeader($calendar['ctag']);
             $events = Object::allInPeriod($calendarid, $start, $end);
         } else {
             \OCP\Util::emitHook('OCA\\CalendarPlus', 'getEvents', array('calendar_id' => $calendarid, 'events' => &$events));
         }
     }
     return $events;
 }
Ejemplo n.º 14
0
 /**
  * @NoAdminRequired
  * 
  * @brief checks if a whole calendar is already cached
  * @param integer $id 
  * @return bool
  */
 public function isCalendarCached($id)
 {
     $aCachedevents = $this->getCalendar($id);
     $cachedevents = 0;
     if ($aCachedevents !== null) {
         $cachedevents = count($aCachedevents);
     }
     $repeatingevents = 0;
     $allevents = Object::all($id);
     foreach ($allevents as $event) {
         if ((int) $event['repeating'] === 1) {
             $repeatingevents++;
         }
     }
     if ($cachedevents < $repeatingevents) {
         return false;
     } else {
         return true;
     }
 }
Ejemplo n.º 15
0
 /**
  * @brief returns informations about an event
  * @param int $id - id of the event
  * @param bool $security - check access rights or not
  * @param bool $shared - check if the user got access via sharing
  * @return mixed - bool / array
  */
 public static function getEventObject($id, $security = true, $shared = false)
 {
     $event = Object::find($id);
     if ($shared === true || $security === true) {
         //$permissions = self::getPermissions($id, self::TODO);
         //\OCP\Util::writeLog(self::$appname, __METHOD__.' id: '.$id.', permissions: '.$permissions, \OCP\Util::DEBUG);
         if (self::getPermissions($id, self::TODO)) {
             return $event;
         }
     } else {
         return $event;
     }
     return false;
 }
Ejemplo n.º 16
0
 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);
     }
 }
Ejemplo n.º 17
0
 /**
  * @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;
 }
Ejemplo n.º 18
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();
 }