/** * @NoAdminRequired */ public function addList() { $listName = $this->params('name'); $userId = $this->api->getUserId(); if (trim($listName) == '') { // OCP\JSON::error(array('message'=>'empty')); exit; } $calendars = \OC_Calendar_Calendar::allCalendars($userId, true); foreach ($calendars as $cal) { if ($cal['displayname'] == $listName) { // OCP\JSON::error(array('message'=>'namenotavailable')); exit; } } $color = '#CCCCCC'; $calendarId = \OC_Calendar_Calendar::addCalendar($userId, strip_tags($listName), 'VEVENT,VTODO,VJOURNAL', null, 0, $color); \OC_Calendar_Calendar::setCalendarActive($calendarId, 1); $list = \OC_Calendar_Calendar::find($calendarId); $list['tmpID'] = $this->params('tmpID'); $result = array('data' => array('list' => $list)); $response = new JSONResponse(); $response->setData($result); return $response; }
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()); }
/** * add a list * * @param $name * @param $tmpID * @return array * @throws \Exception */ public function add($name, $tmpID) { if (trim($name) == '') { // OCP\JSON::error(array('message'=>'empty')); exit; } $calendars = \OC_Calendar_Calendar::allCalendars($this->userId, true); foreach ($calendars as $cal) { if ($cal['displayname'] == $name) { // OCP\JSON::error(array('message'=>'namenotavailable')); exit; } } $color = '#CCCCCC'; $calendarId = \OC_Calendar_Calendar::addCalendar($this->userId, strip_tags($name), 'VEVENT,VTODO,VJOURNAL', null, 0, $color); \OC_Calendar_Calendar::setCalendarActive($calendarId, 1); $list = \OC_Calendar_Calendar::find($calendarId); $list['tmpID'] = $tmpID; return $list; }
<?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 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; }
/** * 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)))); }
OCP\JSON::error(array('error' => 'notvalid')); exit; } $newcal = false; if ($_POST['method'] == 'new') { $calendars = OC_Calendar_Calendar::allCalendars(OCP\User::getUser()); foreach ($calendars as $calendar) { if ($calendar['displayname'] == $_POST['calname']) { $id = $calendar['id']; $newcal = false; break; } $newcal = true; } if ($newcal) { $id = OC_Calendar_Calendar::addCalendar(OCP\USER::getUser(), strip_tags($_POST['calname']), 'VEVENT,VTODO,VJOURNAL', null, 0, strip_tags($_POST['calcolor'])); 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) {
<?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. */ 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"); }
<?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. */ // 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)));
OC_JSON::checkLoggedIn(); OC_Util::checkAppEnabled('calendar'); if ($_GET["import"] == "existing") { $calid = $_GET["calid"]; $calendar = OC_Calendar_Calendar::findCalendar($calid); if ($calendar['userid'] != OC_User::getUser()) { OC_JSON::error(); exit; } if ($_GET["path"] != "") { $filename = $_GET["path"] . "/" . $_GET["file"]; } else { $filename = "/" . $_GET["file"]; } } else { $id = OC_Calendar_Calendar::addCalendar(OC_User::getUser(), $_POST['calname']); OC_Calendar_Calendar::setCalendarActive($id, 1); $calid = $id; if ($_POST["path"] != "") { $filename = $_POST["path"] . "/" . $_POST["file"]; } else { $filename = "/" . $_POST["file"]; } } $vcalendar = OC_Filesystem::file_get_contents($filename); $vcalendar = explode("BEGIN:VEVENT", $vcalendar); for ($i = 1; $i < count($vcalendar); $i++) { $vcalendar[$i] = "BEGIN:VEVENT" . $vcalendar[$i]; } for ($i = 1; $i < count($vcalendar) - 1; $i++) { $vcalendar[$i] = $vcalendar[$i] . "END:VCALENDAR";
/** * @brief Creates default calendar for a user * @param paramters parameters from postCreateUser-Hook * @return array */ public static function createUser($parameters) { OC_Calendar_Calendar::addCalendar($parameters['uid'], 'Default calendar'); return true; }