/** * 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(); }
OCP\JSON::error(array('message' => 'empty')); exit; } $calendars = OC_Calendar_Calendar::allCalendars(OCP\USER::getUser()); foreach ($calendars as $cal) { if ($cal['userid'] != OCP\User::getUser()) { continue; } if ($cal['displayname'] == $_POST['name'] && $cal['id'] != $_POST['id']) { OCP\JSON::error(array('message' => 'namenotavailable')); exit; } } $calendarid = $_POST['id']; try { OC_Calendar_Calendar::editCalendar($calendarid, strip_tags($_POST['name']), null, null, null, $_POST['color']); OC_Calendar_Calendar::setCalendarActive($calendarid, $_POST['active']); } catch (Exception $e) { OCP\JSON::error(array('message' => $e->getMessage())); exit; } $calendar = OC_Calendar_Calendar::find($calendarid); $tmpl = new OCP\Template('calendar', 'part.choosecalendar.rowfields'); $tmpl->assign('calendar', $calendar); $shared = false; if ($calendar['userid'] != OCP\User::getUser()) { $sharedCalendar = OCP\Share::getItemSharedWithBySource('calendar', $calendarid); if ($sharedCalendar && $sharedCalendar['permissions'] & OCP\Share::PERMISSION_UPDATE) { $shared = true; } }
/** * @NoAdminRequired */ public function setListName() { $listId = (int) $this->params('listID'); $listName = $this->params('name'); $response = new JSONResponse(); if (trim($listName) == '') { // 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'] == $listName && $cal['id'] != $listId) { // OCP\JSON::error(array('message'=>'namenotavailable')); exit; } } $color = '#CCCCCC'; \OC_Calendar_Calendar::editCalendar($listId, strip_tags($listName), null, null, null, $color); $result = array('data' => array()); $response->setData($result); return $response; }
/** * Updates a calendars properties * * The properties array uses the propertyName in clark-notation as key, * and the array value for the property value. In the case a property * should be deleted, the property value will be null. * * This method must be atomic. If one property cannot be changed, the * entire operation must fail. * * If the operation was successful, true can be returned. * If the operation failed, false can be returned. * * Deletion of a non-existant property is always succesful. * * Lastly, it is optional to return detailed information about any * failures. In this case an array should be returned with the following * structure: * * array( * 403 => array( * '{DAV:}displayname' => null, * ), * 424 => array( * '{DAV:}owner' => null, * ) * ) * * In this example it was forbidden to update {DAV:}displayname. * (403 Forbidden), which in turn also caused {DAV:}owner to fail * (424 Failed Dependency) because the request needs to be atomic. * * @param string $calendarId * @param PropPatch $propPatch * @return bool|array */ public function updateCalendar($calendarId, PropPatch $propPatch) { $newValues = array(); $result = array(200 => array(), 403 => array(), 424 => array()); $hasError = false; $properties = $propPatch->getRemainingMutations(); foreach ($properties as $propertyName => $propertyValue) { // We don't know about this property. if (!isset($this->propertyMap[$propertyName])) { $hasError = true; $result[403][$propertyName] = null; unset($properties[$propertyName]); continue; } $fieldName = $this->propertyMap[$propertyName]; $newValues[$fieldName] = $propertyValue; } // If there were any errors we need to fail the request if ($hasError) { // Properties has the remaining properties foreach ($properties as $propertyName => $propertyValue) { $result[424][$propertyName] = null; } // Removing unused statuscodes for cleanliness foreach ($result as $status => $properties) { if (is_array($properties) && count($properties) === 0) { unset($result[$status]); } } return $result; } // Success if (!isset($newValues['displayname'])) { $newValues['displayname'] = null; } if (!isset($newValues['timezone'])) { $newValues['timezone'] = null; } if (!isset($newValues['calendarorder'])) { $newValues['calendarorder'] = null; } if (!isset($newValues['calendarcolor'])) { $newValues['calendarcolor'] = null; } if (!is_null($newValues['calendarcolor']) && strlen($newValues['calendarcolor']) == 9) { $newValues['calendarcolor'] = substr($newValues['calendarcolor'], 0, 7); } OC_Calendar_Calendar::editCalendar($calendarId, $newValues['displayname'], null, $newValues['timezone'], $newValues['calendarorder'], $newValues['calendarcolor']); return 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. */ require_once '../../../lib/base.php'; $l10n = new OC_L10N('calendar'); // Check if we are a user OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('calendar'); $calendarid = $_POST['id']; OC_Calendar_Calendar::editCalendar($calendarid, $_POST['name'], null, null, null, $_POST['color']); OC_Calendar_Calendar::setCalendarActive($calendarid, $_POST['active']); $calendar = OC_Calendar_Calendar::findCalendar($calendarid); $tmpl = new OC_Template('calendar', 'part.choosecalendar.rowfields'); $tmpl->assign('calendar', $calendar); OC_JSON::success(array('data' => $tmpl->fetchPage()));