function testBasic() { $uid = uniqid(); $this->assertEquals(OC_Calendar_Calendar::allCalendars($uid), array()); OC_User::setUserId($uid); $calId1 = OC_Calendar_Calendar::addCalendar($uid, 'test'); $all = OC_Calendar_Calendar::allCalendars($uid); $this->assertEquals(count($all), 1); $this->assertEquals($all[0]['id'], $calId1); $this->assertEquals($all[0]['displayname'], 'test'); $this->assertEquals($all[0]['uri'], 'test'); $this->assertEquals($uid, $all[0]['userid']); $calId2 = OC_Calendar_Calendar::addCalendar($uid, 'test'); $this->assertNotEquals($calId1, $calId2); $all = OC_Calendar_Calendar::allCalendars($uid); $this->assertEquals(count($all), 2); $this->assertEquals($all[1]['id'], $calId2); $this->assertEquals($all[1]['displayname'], 'test'); $this->assertEquals($all[1]['uri'], 'test1'); //$cal1=OC_Calendar_Calendar::find($calId1); //$this->assertEquals($cal1,$all[0]); OC_Calendar_Calendar::deleteCalendar($calId1); OC_Calendar_Calendar::deleteCalendar($calId2); $this->assertEquals(OC_Calendar_Calendar::allCalendars($uid), array()); }
function import() { switch ($this->appinfo->version) { default: // All versions of the app have had the same db structure, so all can use the same import function $query = $this->content->prepare('SELECT * FROM `calendar_calendars` WHERE `userid` = ?'); $results = $query->execute(array($this->olduid)); $idmap = array(); while ($row = $results->fetchRow()) { // Import each calendar $calendarquery = OCP\DB::prepare('INSERT INTO `*PREFIX*calendar_calendars` (`userid`,`displayname`,`uri`,`ctag`,`calendarorder`,`calendarcolor`,`timezone`,`components`) VALUES(?,?,?,?,?,?,?,?)'); $calendarquery->execute(array($this->uid, $row['displayname'], $row['uri'], $row['ctag'], $row['calendarorder'], $row['calendarcolor'], $row['timezone'], $row['components'])); // Map the id $idmap[$row['id']] = OCP\DB::insertid('*PREFIX*calendar_calendars'); // Make the calendar active OC_Calendar_Calendar::setCalendarActive($idmap[$row['id']], true); } // Now tags foreach ($idmap as $oldid => $newid) { $query = $this->content->prepare('SELECT * FROM `calendar_objects` WHERE `calendarid` = ?'); $results = $query->execute(array($oldid)); while ($row = $results->fetchRow()) { // Import the objects $objectquery = OCP\DB::prepare('INSERT INTO `*PREFIX*calendar_objects` (`calendarid`,`objecttype`,`startdate`,`enddate`,`repeating`,`summary`,`calendardata`,`uri`,`lastmodified`) VALUES(?,?,?,?,?,?,?,?,?)'); $objectquery->execute(array($newid, $row['objecttype'], $row['startdate'], $row['enddate'], $row['repeating'], $row['summary'], $row['calendardata'], $row['uri'], $row['lastmodified'])); } } // All done! break; } return true; }
/** * @NoAdminRequired */ public function getTasks() { $calendars = \OC_Calendar_Calendar::allCalendars($this->userId, true); $user_timezone = \OC_Calendar_App::getTimezone(); $tasks = array(); foreach ($calendars as $calendar) { $calendar_tasks = \OC_Calendar_Object::all($calendar['id']); foreach ($calendar_tasks as $task) { if ($task['objecttype'] != 'VTODO') { continue; } if (is_null($task['summary'])) { continue; } $vtodo = Helper::parseVTODO($task['calendardata']); try { $task_data = Helper::arrayForJSON($task['id'], $vtodo, $user_timezone); $task_data['calendarid'] = $calendar['id']; $task_data['calendarcolor'] = $calendar['calendarcolor']; $tasks[] = $task_data; } catch (\Exception $e) { \OCP\Util::writeLog('tasks', $e->getMessage(), \OCP\Util::ERROR); } } } $result = array('data' => array('tasks' => $tasks)); $response = new JSONResponse(); $response->setData($result); return $response; }
/** * Search for query in calendar events * * @param string $query * @return array list of \OCA\Calendar\Search\Event */ function search($query) { $calendars = \OC_Calendar_Calendar::allCalendars(\OCP\USER::getUser(), true); // check if the calenar is enabled if (count($calendars) == 0 || !\OCP\App::isEnabled('calendar')) { return array(); } $results = array(); foreach ($calendars as $calendar) { $objects = \OC_Calendar_Object::all($calendar['id']); $date = strtotime($query); // search all calendar objects, one by one foreach ($objects as $object) { // skip non-events if ($object['objecttype'] != 'VEVENT') { continue; } // check the event summary string if (stripos($object['summary'], $query) !== false) { $results[] = new \OCA\Calendar\Search\Event($object); continue; } // check if the event is happening on a queried date $range = $this->getDateRange($object); if ($date && $this->fallsWithin($date, $range)) { $results[] = new \OCA\Calendar\Search\Event($object); continue; } } } return $results; }
/** * @brief Deletes all calendars of a certain user * @param paramters parameters from postDeleteUser-Hook * @return array */ public static function deleteUser($parameters) { $calendars = OC_Calendar_Calendar::allCalendars($parameters['uid']); foreach ($calendars as $calendar) { OC_Calendar_Calendar::deleteCalendar($calendar['id']); } return true; }
private function getCalendars() { $calendars = array(); foreach (OC_Calendar_Calendar::allCalendars($this->user, true) as $cal) { $calendars[$cal['id']] = $cal['displayname']; } return $calendars; }
/** * @brief exports a calendar and convert all times to UTC * @param integer $id id of the calendar * @return string */ private static function calendar($id) { $events = OC_Calendar_Object::all($id); $calendar = OC_Calendar_Calendar::find($id); $return = "BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:ownCloud Calendar " . OCP\App::getAppVersion('calendar') . "\nX-WR-CALNAME:" . $calendar['displayname'] . "\n"; foreach ($events as $event) { $return .= self::generateEvent($event); } $return .= "END:VCALENDAR"; return $return; }
/** * @brief Get a unique name of the item for the specified user * @param string Item * @param string|false User the item is being shared with * @param array|null List of similar item names already existing as shared items * @return string Target name * * This function needs to verify that the user does not already have an item with this name. * If it does generate a new name e.g. name_# */ public function generateTarget($itemSource, $shareWith, $exclude = null) { $calendar = OC_Calendar_App::getCalendar($itemSource); $user_calendars = array(); foreach (OC_Calendar_Calendar::allCalendars($shareWith) as $user_calendar) { $user_calendars[] = $user_calendar['displayname']; } $name = $calendar['userid'] . "'s " . $calendar['displayname']; $suffix = ''; while (in_array($name . $suffix, $user_calendars)) { $suffix++; } return $name . $suffix; }
/** * Search for query in tasks * * @param string $query * @return array list of \OCA\Tasks\Controller\Task */ function search($query) { $calendars = \OC_Calendar_Calendar::allCalendars(\OC::$server->getUserSession()->getUser()->getUID(), true); $user_timezone = \OC_Calendar_App::getTimezone(); // check if the calenar is enabled if (count($calendars) == 0 || !\OCP\App::isEnabled('tasks')) { return array(); } $results = array(); foreach ($calendars as $calendar) { // $calendar_entries = \OC_Calendar_Object::all($calendar['id']); $objects = \OC_Calendar_Object::all($calendar['id']); // $date = strtotime($query); // // search all calendar objects, one by one foreach ($objects as $object) { // skip non-todos if ($object['objecttype'] != 'VTODO') { continue; } if (!($vtodo = Helper::parseVTODO($object))) { continue; } $id = $object['id']; $calendarId = $object['calendarid']; // check these properties $properties = array('SUMMARY', 'DESCRIPTION', 'LOCATION', 'CATEGORIES'); foreach ($properties as $property) { $string = $vtodo->{$property}; if (stripos($string, $query) !== false) { // $results[] = new \OCA\Tasks\Controller\Task($id,$calendarId,$vtodo,$property,$query,$user_timezone); $results[] = Helper::arrayForJSON($id, $vtodo, $user_timezone, $calendarId); continue 2; } } $comments = $vtodo->COMMENT; if ($comments) { foreach ($comments as $com) { if (stripos($com->getValue(), $query) !== false) { // $results[] = new \OCA\Tasks\Controller\Task($id,$calendarId,$vtodo,'COMMENTS',$query,$user_timezone); $results[] = Helper::arrayForJSON($id, $vtodo, $user_timezone, $calendarId); continue 2; } } } } } usort($results, array($this, 'sort_completed')); return $results; }
function search($query) { $calendars = OC_Calendar_Calendar::allCalendars(OCP\USER::getUser(), true); if (count($calendars) == 0 || !OCP\App::isEnabled('calendar')) { //return false; } $results = array(); $searchquery = array(); if (substr_count($query, ' ') > 0) { $searchquery = explode(' ', $query); } else { $searchquery[] = $query; } $user_timezone = OC_Calendar_App::getTimezone(); $l = new OC_l10n('calendar'); foreach ($calendars as $calendar) { $objects = OC_Calendar_Object::all($calendar['id']); foreach ($objects as $object) { if ($object['objecttype'] != 'VEVENT') { continue; } if (substr_count(strtolower($object['summary']), strtolower($query)) > 0) { $calendardata = OC_VObject::parse($object['calendardata']); $vevent = $calendardata->VEVENT; $dtstart = $vevent->DTSTART; $dtend = OC_Calendar_Object::getDTEndFromVEvent($vevent); $start_dt = $dtstart->getDateTime(); $start_dt->setTimezone(new DateTimeZone($user_timezone)); $end_dt = $dtend->getDateTime(); $end_dt->setTimezone(new DateTimeZone($user_timezone)); if ($dtstart->getDateType() == Sabre\VObject\Property\DateTime::DATE) { $end_dt->modify('-1 sec'); if ($start_dt->format('d.m.Y') != $end_dt->format('d.m.Y')) { $info = $l->t('Date') . ': ' . $start_dt->format('d.m.Y') . ' - ' . $end_dt->format('d.m.Y'); } else { $info = $l->t('Date') . ': ' . $start_dt->format('d.m.Y'); } } else { $info = $l->t('Date') . ': ' . $start_dt->format('d.m.y H:i') . ' - ' . $end_dt->format('d.m.y H:i'); } $link = OCP\Util::linkTo('calendar', 'index.php') . '?showevent=' . urlencode($object['id']); $results[] = new OC_Search_Result($object['summary'], $info, $link, (string) $l->t('Cal.')); //$name,$text,$link,$type } } } return $results; }
/** * 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 = OC_Calendar_Calendar::extractUserID($this->getOwner()); if ($uid != OCP\USER::getUser()) { $sharedCalendar = OCP\Share::getItemSharedWithBySource('calendar', $this->calendarInfo['id']); if ($sharedCalendar && $sharedCalendar['permissions'] & OCP\PERMISSION_READ) { $readprincipal = 'principals/' . OCP\USER::getUser(); } if ($sharedCalendar && $sharedCalendar['permissions'] & OCP\PERMISSION_UPDATE) { $writeprincipal = 'principals/' . OCP\USER::getUser(); } } 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), array('privilege' => '{' . Sabre_CalDAV_Plugin::NS_CALDAV . '}read-free-busy', 'principal' => '{DAV:}authenticated', 'protected' => true)); }
/** * 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 = OC_Calendar_Calendar::extractUserID($this->getOwner()); if ($uid != OCP\USER::getUser()) { $object = OC_VObject::parse($this->objectData['calendardata']); $sharedCalendar = OCP\Share::getItemSharedWithBySource('calendar', $this->calendarInfo['id']); $sharedAccessClassPermissions = OC_Calendar_App::getAccessClassPermissions($object->VEVENT->CLASS->value); 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(); } } 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)); }
/** * 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 = OC_Calendar_Calendar::extractUserID($this->getOwner()); if ($uid != OCP\USER::getUser()) { if ($uid === 'contact_birthdays') { $readprincipal = 'principals/' . OCP\User::getUser(); } else { $object = \Sabre\VObject\Reader::read($this->objectData['calendardata']); $sharedCalendar = OCP\Share::getItemSharedWithBySource('calendar', $this->calendarInfo['id']); $sharedAccessClassPermissions = OC_Calendar_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(); } } } 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)); }
<?php /** * Copyright (c) 2011 Bart Visscher <*****@*****.**> * This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. */ $tmpl = new OCP\Template('calendar', 'settings'); $timezone = OCP\Config::getUserValue(OCP\USER::getUser(), 'calendar', 'timezone', ''); $tmpl->assign('timezone', $timezone); $tmpl->assign('timezones', DateTimeZone::listIdentifiers()); $tmpl->assign('calendars', OC_Calendar_Calendar::allCalendars(OCP\USER::getUser()), false); OCP\Util::addscript('calendar', 'settings'); $tmpl->printPage();
/** * @brief returns the owner of an object * @param integer $id * @return string */ public static function getowner($id) { if ($id == 0) { return null; } $event = self::find($id); $cal = OC_Calendar_Calendar::find($event['calendarid']); if ($cal === false || is_array($cal) === false) { return null; } if (array_key_exists('userid', $cal)) { return $cal['userid']; } else { return null; } }
public function createCalendarName() { $calendars = OC_Calendar_Calendar::allCalendars($this->userid); $calendarname = $guessedcalendarname = !is_null($this->guessCalendarName()) ? $this->guessCalendarName() : OC_Calendar_App::$l10n->t('New Calendar'); $i = 1; while (!OC_Calendar_Calendar::isCalendarNameavailable($calendarname, $this->userid)) { $calendarname = $guessedcalendarname . ' (' . $i . ')'; $i++; } return $calendarname; }
<?php /** * Copyright (c) 2011 Georg Ehrke <ownclouddev at georgswebsite dot de> * This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. */ require_once '../../lib/base.php'; OC_Util::checkLoggedIn(); OC_Util::checkAppEnabled('calendar'); // Create default calendar ... $calendars = OC_Calendar_Calendar::allCalendars(OC_User::getUser()); if (count($calendars) == 0) { OC_Calendar_Calendar::addCalendar(OC_User::getUser(), 'default', 'Default calendar'); $calendars = OC_Calendar_Calendar::allCalendars(OC_User::getUser()); } OC_UTIL::addScript('calendar', 'calendar'); OC_UTIL::addStyle('calendar', 'style'); OC_UTIL::addScript('', 'jquery.multiselect'); OC_UTIL::addStyle('', 'jquery.multiselect'); OC_APP::setActiveNavigationEntry('calendar_index'); $output = new OC_TEMPLATE('calendar', 'calendar', 'user'); $output->printPage();
/** * @brief use to create HTML emails and send them * @param $eventid The event id * @param $location The location * @param $description The description * @param $dtstart The start date * @param $dtend The end date * */ public static function sendEmails($eventid, $summary, $location, $description, $dtstart, $dtend) { $user = \OCP\User::getUser(); $eventsharees = array(); $eventShareesNames = array(); $emails = array(); $sharedwithByEvent = \OCP\Share::getItemShared('event', $eventid); if (is_array($sharedwithByEvent)) { foreach ($sharedwithByEvent as $share) { if ($share['share_type'] === \OCP\Share::SHARE_TYPE_USER || $share['share_type'] === \OCP\Share::SHARE_TYPE_GROUP) { $eventsharees[] = $share; } } foreach ($eventsharees as $sharee) { $shwth = $sharee['share_with']; if ($sharee['share_type'] == \OCP\Share::SHARE_TYPE_GROUP) { foreach (OC_Group::usersInGroup($shwth) as $u) { if (!in_array($u, $eventShareesNames)) { $eventShareesNames[] = $u; } } } else { if (!in_array($shwth, $eventShareesNames)) { $eventShareesNames[] = $shwth; } } } } foreach ($eventShareesNames as $name) { $result = OC_Calendar_Calendar::getUsersEmails($name); $emails[] = $result; } $adminmail = \OCP\Util::getDefaultEmailAddress('no-reply'); foreach ($emails as $email) { if ($email === null) { continue; } $subject = 'Calendar Event Shared'; $message = '<html><body>'; $message .= '<table style="border:1px solid black;" cellpadding="10">'; $message .= "<tr style='background: #eee;'><td colspan='2'><strong>" . $user . '</strong><strong> has shared with you an event</strong></td></tr>'; $message .= '<tr><td><strong>Summary:</strong> </td><td>' . \OCP\Util::sanitizeHTML($summary) . '</td></tr>'; $message .= '<tr><td><strong>Location:</strong> </td><td>' . \OCP\Util::sanitizeHTML($location) . '</td></tr>'; $message .= '<tr><td><strong>Description:</strong> </td><td>' . \OCP\Util::sanitizeHTML($description) . '</td></tr>'; $message .= '</table>'; $message .= '</body></html>'; OCP\Util::sendMail($email, \OCP\User::getDisplayName(), $subject, $message, $adminmail, $user, $html = 1); } }
/** * @brief Creates a new project * @param Project title * @param Description of the project * @param Member who created the project * @param Deadline of the project * @param List of members working in the project and their roles * @return int|boolean (Post ID of the post specifying the project creation|false) */ public static function createProject($title, $desc, $creator, $deadline, $details = NULL) { $post_id = NULL; try { \OCP\DB::beginTransaction(); $calendar_id = OC_Calendar_Calendar::addCalendar(\OC_User::getUser(), $title, 'VEVENT,VTODO,VJOURNAL', null, 0, '#3a87ad'); $query = \OCP\DB::prepare('INSERT INTO `*PREFIX*collaboration_project`(`title`, `description`, `starting_date`, `ending_date`, `last_updated`, `calendar_id`) VALUES(?, ?, CURRENT_TIMESTAMP, ?, CURRENT_TIMESTAMP, ?)'); $query->execute(array($title, $desc, OC_Collaboration_Time::convertUITimeToDBTime($deadline . ' 23:59:59'), $calendar_id)); $pid = OCP\DB::insertid('*PREFIX*collaboration_project'); $add_member = \OCP\DB::prepare('INSERT INTO `*PREFIX*collaboration_works_on`(`pid`, `member`, `role`) VALUES(?, ?, ?)'); $add_member->execute(array($pid, $creator, 'Creator')); $cnt = count($details); if ($cnt != 0 && isset($details[0]['member'])) { foreach ($details as $detail) { $member = strtolower($detail['member']); if (!OC_User::userExists($member)) { OC_User::createUser($member, $member); } $add_member->execute(array($pid, $member, $detail['role'])); OC_Preferences::setValue($member, 'settings', 'email', $detail['email']); OC_Preferences::setValue($member, 'collaboration', 'mobile', $detail['mobile']); } } $post_id = OC_Collaboration_Post::createPost('Project Created', 'Project \'' . $title . '\' has been created with deadline ' . OC_Collaboration_Time::convertToFullDate($deadline) . '.', $creator, $pid, 'Project Creation', array(), true); \OCP\DB::commit(); } catch (\Exception $e) { OC_Log::write('collaboration', __METHOD__ . ', Exception: ' . $e->getMessage(), OCP\Util::DEBUG); return false; } return $post_id; }
/** * set name of list by id * * @param $id * @param $name * @return array * @throws \Exception */ public function setName($id, $name) { if (trim($name) == '') { // OCP\JSON::error(array('message'=>'empty')); exit; } $calendars = \OC_Calendar_Calendar::allCalendars($this->userId, true); foreach ($calendars as $cal) { if ($cal['userid'] != $this->userId) { continue; } if ($cal['displayname'] == $name && $cal['id'] != $id) { // OCP\JSON::error(array('message'=>'namenotavailable')); exit; } } $color = '#CCCCCC'; \OC_Calendar_Calendar::editCalendar($id, strip_tags($name), null, null, null, $color); return array(); }
/** * Copyright (c) 2012 Georg Ehrke <*****@*****.**> * This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. */ $data = $_POST['data']; $data = explode(',', $data); $data = end($data); $data = base64_decode($data); OCP\JSON::checkLoggedIn(); OCP\App::checkAppEnabled('calendar'); $import = new OC_Calendar_Import($data); $import->setUserID(OCP\User::getUser()); $import->setTimeZone(OC_Calendar_App::$tz); $import->disableProgressCache(); if (!$import->isValid()) { OCP\JSON::error(); exit; } $newcalendarname = strip_tags($import->createCalendarName()); $newid = OC_Calendar_Calendar::addCalendar(OCP\User::getUser(), $newcalendarname, 'VEVENT,VTODO,VJOURNAL', null, 0, $import->createCalendarColor()); $import->setCalendarID($newid); $import->import(); $count = $import->getCount(); if ($count == 0) { OC_Calendar_Calendar::deleteCalendar($newid); OCP\JSON::error(array('message' => OC_Calendar_App::$l10n->t('The file contained either no events or all events are already saved in your calendar.'))); } else { OCP\JSON::success(array('message' => $count . ' ' . OC_Calendar_App::$l10n->t('events has been saved in the new calendar') . ' ' . $newcalendarname, 'eventSource' => OC_Calendar_Calendar::getEventSourceInfo(OC_Calendar_Calendar::find($newid)))); }
* Copyright (c) 2011 Georg Ehrke <ownclouddev at georgswebsite dot de> * This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. */ OCP\User::checkLoggedIn(); OCP\App::checkAppEnabled('calendar'); // Create default calendar ... $calendars = OC_Calendar_Calendar::allCalendars(OCP\USER::getUser(), 1); if (count($calendars) == 0) { OC_Calendar_Calendar::addCalendar(OCP\USER::getUser(), 'Default calendar'); $calendars = OC_Calendar_Calendar::allCalendars(OCP\USER::getUser(), 1); } $eventSources = array(); foreach ($calendars as $calendar) { $eventSources[] = OC_Calendar_Calendar::getEventSourceInfo($calendar); } $eventSources[] = array('url' => '?app=calendar&getfile=ajax/events.php?calendar_id=shared_rw', 'backgroundColor' => '#1D2D44', 'borderColor' => '#888', 'textColor' => 'white', 'editable' => 'true'); $eventSources[] = array('url' => '?app=calendar&getfile=ajax/events.php?calendar_id=shared_r', 'backgroundColor' => '#1D2D44', 'borderColor' => '#888', 'textColor' => 'white', 'editable' => 'false'); OCP\Util::emitHook('OC_Calendar', 'getSources', array('sources' => &$eventSources)); $categories = OC_Calendar_App::getCategoryOptions(); //Fix currentview for fullcalendar if (OCP\Config::getUserValue(OCP\USER::getUser(), 'calendar', 'currentview', 'month') == "oneweekview") { OCP\Config::setUserValue(OCP\USER::getUser(), "calendar", "currentview", "agendaWeek"); } if (OCP\Config::getUserValue(OCP\USER::getUser(), 'calendar', 'currentview', 'month') == "onemonthview") { OCP\Config::setUserValue(OCP\USER::getUser(), "calendar", "currentview", "month"); } if (OCP\Config::getUserValue(OCP\USER::getUser(), 'calendar', 'currentview', 'month') == "listview") { OCP\Config::setUserValue(OCP\USER::getUser(), "calendar", "currentview", "list"); }
OC_Calendar_Calendar::setCalendarActive($id, 1); } } else { $calendar = OC_Calendar_App::getCalendar($_POST['id']); if ($calendar['userid'] != OCP\USER::getUser()) { OCP\JSON::error(array('error' => 'missingcalendarrights')); exit; } $id = $_POST['id']; $import->setOverwrite($_POST['overwrite']); } $import->setCalendarID($id); try { $import->import(); } catch (Exception $e) { OCP\JSON::error(array('message' => OC_Calendar_App::$l10n->t('Import failed'), 'debug' => $e->getMessage())); //write some log } $count = $import->getCount(); if ($count == 0) { if ($newcal) { OC_Calendar_Calendar::deleteCalendar($id); } OCP\JSON::error(array('message' => OC_Calendar_App::$l10n->t('The file contained either no events or all events are already saved in your calendar.'))); } else { if ($newcal) { OCP\JSON::success(array('message' => $count . ' ' . OC_Calendar_App::$l10n->t('events has been saved in the new calendar') . ' ' . strip_tags($_POST['calname']))); } else { OCP\JSON::success(array('message' => $count . ' ' . OC_Calendar_App::$l10n->t('events has been saved in your calendar'))); } }
<?php //Prerendering for iCalendar file $file = \OC\Files\Filesystem::file_get_contents($_['path'] . '/' . $_['filename']); if (!$file) { OCP\JSON::error(array('error' => '404')); } $import = new OC_Calendar_Import($file); $import->setUserID(OCP\User::getUser()); $newcalendarname = OCP\Util::sanitizeHTML($import->createCalendarName()); $guessedcalendarname = OCP\Util::sanitizeHTML($import->guessCalendarName()); $calendarcolor = OCP\Util::sanitizeHTML($import->createCalendarColor()); //loading calendars for select box $calendar_options = OC_Calendar_Calendar::allCalendars(OCP\USER::getUser()); $calendar_options[] = array('id' => 'newcal', 'displayname' => $l->t('create a new calendar')); $defaultcolors = OC_Calendar_Calendar::getCalendarColorOptions(); ?> <div id="calendar_import_dialog" title="<?php p($l->t("Import a calendar file")); ?> "> <div id="calendar_import_form"> <form> <input type="hidden" id="calendar_import_filename" value="<?php p($_['filename']); ?> "> <input type="hidden" id="calendar_import_path" value="<?php p($_['path']); ?> ">
/** * Copyright (c) 2011 Bart Visscher <*****@*****.**> * This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. */ // Check if we are a user OCP\JSON::checkLoggedIn(); OCP\JSON::checkAppEnabled('calendar'); OCP\JSON::callCheck(); if (trim($_POST['name']) == '') { OCP\JSON::error(array('message' => 'empty')); exit; } $calendars = OC_Calendar_Calendar::allCalendars(OCP\USER::getUser()); foreach ($calendars as $cal) { if ($cal['displayname'] == $_POST['name']) { OCP\JSON::error(array('message' => 'namenotavailable')); exit; } } $userid = OCP\USER::getUser(); $calendarid = OC_Calendar_Calendar::addCalendar($userid, strip_tags($_POST['name']), 'VEVENT,VTODO,VJOURNAL', null, 0, $_POST['color']); OC_Calendar_Calendar::setCalendarActive($calendarid, 1); $calendar = OC_Calendar_Calendar::find($calendarid); $tmpl = new OCP\Template('calendar', 'part.choosecalendar.rowfields'); $tmpl->assign('calendar', $calendar); $tmpl->assign('shared', false); OCP\JSON::success(array('page' => $tmpl->fetchPage(), 'eventSource' => OC_Calendar_Calendar::getEventSourceInfo($calendar)));
<?php /** * Copyright (c) 2012 Georg Ehrke <ownclouddev at georgswebsite dot de> * This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. */ OCP\JSON::checkLoggedIn(); OCP\JSON::checkAppEnabled('calendar'); OCP\JSON::callCheck(); $errarr = OC_Calendar_Object::validateRequest($_POST); if ($errarr) { //show validate errors OCP\JSON::error($errarr); exit; } else { $cal = $_POST['calendar']; $calendar = OC_Calendar_Calendar::find($cal); if ($calendar['userid'] != OCP\USER::getUser()) { $l = OC_L10N::get('core'); OC_JSON::error(array('data' => array('message' => $l->t('Authentication error')))); exit; } $vcalendar = OC_Calendar_Object::createVCalendarFromRequest($_POST); $result = OC_Calendar_Object::add($cal, $vcalendar->serialize()); OCP\JSON::success(); }
<?php // Init owncloud OCP\JSON::checkLoggedIn(); OCP\JSON::checkAppEnabled('tasks'); OCP\JSON::callCheck(); $calendars = OC_Calendar_Calendar::allCalendars(OCP\User::getUser(), true); $category_options = OC_Calendar_App::getCategoryOptions(); $percent_options = range(0, 100, 10); $priority_options = OC_Task_App::getPriorityOptions(); $tmpl = new OCP\Template('tasks', 'part.addtaskform'); $tmpl->assign('calendars', $calendars); $tmpl->assign('category_options', $category_options); $tmpl->assign('percent_options', $percent_options); $tmpl->assign('priority_options', $priority_options); $tmpl->assign('details', new OC_VObject('VTODO')); $tmpl->assign('categories', ''); $page = $tmpl->fetchPage(); OCP\JSON::success(array('data' => array('page' => $page)));
<?php /** * Copyright (c) 2011 Bart Visscher <*****@*****.**> * This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. */ OCP\JSON::checkLoggedIn(); OCP\JSON::checkAppEnabled('calendar'); $calendarcolor_options = OC_Calendar_Calendar::getCalendarColorOptions(); $calendar = OC_Calendar_App::getCalendar($_POST['calendarid']); $tmpl = new OCP\Template("calendar", "part.editcalendar"); $tmpl->assign('new', false); $tmpl->assign('calendarcolor_options', $calendarcolor_options); $tmpl->assign('calendar', $calendar); $tmpl->printPage();
" id="onemonthview_radio"/> <input type="button" value="<?php p($l->t('Today')); ?> " id="datecontrol_today"/> </form> </li> <li> <a id="newCalendar"><?php p($l->t('New Calendar')); ?> </a> </li> <?php $option_calendars = OC_Calendar_Calendar::allCalendars(OCP\USER::getUser()); for ($i = 0; $i < count($option_calendars); $i++) { print_unescaped("<li data-id='" . OC_Util::sanitizeHTML($option_calendars[$i]['id']) . "'>"); $tmpl = new OCP\Template('calendar', 'part.choosecalendar.rowfields'); $tmpl->assign('calendar', $option_calendars[$i]); if ($option_calendars[$i]['userid'] != OCP\User::getUser()) { $sharedCalendar = OCP\Share::getItemSharedWithBySource('calendar', $option_calendars[$i]['id']); $shared = true; } else { $shared = false; } $tmpl->assign('shared', $shared); $tmpl->printpage(); print_unescaped("</li>"); } ?>
/** * @brief returns the owner of an object * @param integer $id * @return string */ public static function getowner($id) { $event = self::find($id); $cal = OC_Calendar_Calendar::find($event['calendarid']); return $cal['userid']; }