/** * Creates a new calendar * @param string $userid * @param string $name * @param string $components Default: "VEVENT,VTODO,VJOURNAL" * @param string $timezone Default: null * @param integer $order Default: 1 * @param string $color * @return insertid || null */ public function add($userid, $name, $components = 'VEVENT,VTODO,VJOURNAL', $timezone = null, $order = 0, $color = "#C2F9FC", $issubscribe = 0, $externuri = '', $lastmodified = 0) { $all = $this->allCalendars(); $uris = array(); foreach ($all as $i) { $uris[] = $i['uri']; } if ($lastmodified === 0) { $lastmodified = time(); } $uri = $this->createURI($name, $uris); $insertid = $this->calendarDB->add($name, $uri, $order, $color, $timezone, $components, $issubscribe, $externuri, $lastmodified); if ($insertid !== null) { \OCP\Util::emitHook('\\OCA\\CalendarPlus', 'addCalendar', $insertid); $link = \OC::$server->getURLGenerator()->linkToRoute($this->appName . '.page.index'); $params = array('mode' => 'created', 'link' => $link, 'trans_type' => '', 'summary' => $name, 'cal_user' => $userid, 'cal_displayname' => $name); ActivityData::logEventActivity($params, false, true); return $insertid; } else { return null; } }
/** * @brief deletes an object with the data provided by \Sabredav * @param integer $cid calendar id * @param string $uri the uri of the object * @return boolean */ public static function deleteFromDAVData($cid, $uri) { $oldobject = self::findWhereDAVDataIs($cid, $uri); $calendar = Calendar::find($cid); if ($calendar['userid'] != \OCP\User::getUser()) { $sharedCalendar = \OCP\Share::getItemSharedWithBySource(App::SHARECALENDAR, App::SHARECALENDARPREFIX . $cid); if (!$sharedCalendar || !($sharedCalendar['permissions'] & \OCP\PERMISSION_DELETE)) { throw new VObject_DAV_Exception_Forbidden(App::$l10n->t('You do not have the permissions to delete this event.')); } } $stmt = \OCP\DB::prepare('DELETE FROM `' . App::CldObjectTable . '` WHERE `calendarid`= ? AND `uri`=?'); $stmt->execute(array($cid, $uri)); Calendar::touchCalendar($cid); $app = new Application(); $c = $app->getContainer(); $repeatController = $c->query('RepeatController'); $repeatController->cleanEvent($oldobject['id']); //\OCP\Util::emitHook('\OCA\CalendarPlus', 'deleteEvent', $oldobject['id']); $params = array('mode' => 'deleted', 'link' => '', 'trans_type' => App::$l10n->t($oldobject['objecttype']), 'summary' => $oldobject['summary'], 'cal_user' => $calendar['userid'], 'cal_displayname' => $calendar['displayname']); ActivityData::logEventActivity($params, true); return true; }
/** * removes a calendar * @param integer $id * @param boolean $bLogActivity * @return associative array */ public function delete($id, $bLogActivity = true) { $calendar = $this->find($id); //\OCP\Util::writeLog('DAV', 'DEL ID-> '.$id, \OCP\Util::DEBUG); $group = \OC::$server->getGroupManager()->get('admin'); $this->setUserId(\OCP\User::getUser()); if ($calendar['userid'] !== $this->userId && !$group->inGroup($this->userId)) { $sharedCalendar = $this->shareConnector->getItemSharedWithBySourceCalendar($id); if (!$sharedCalendar || !($sharedCalendar['permissions'] & $this->shareConnector->getDeleteAccess())) { throw new \Sabre\DAV\Exception\Forbidden('You do not have the permissions to delete this calendar.'); } } $calendarDB = new CalendarDAO($this->db, $this->userId); $bDeleteCalendar = $calendarDB->delete($id); if ($bDeleteCalendar === true) { \OCP\Util::emitHook('\\OCA\\CalendarPlus', 'deleteCalendar', $id); $this->deleteObjects($id); $this->shareConnector->unshareAllCalendar($id); $app = new Application(); $c = $app->getContainer(); $repeatController = $c->query('RepeatController'); $repeatController->cleanCalendar($id); $calendars = $this->all(false, false); if (\OCP\USER::isLoggedIn() && count($calendars) === 0 || count($calendars) === 1 && $calendars[0]['id'] === 'birthday_' . $this->userId) { //self::addDefaultCalendars($user); } if ($bLogActivity === true) { $link = \OC::$server->getURLGenerator()->linkToRoute('calendarplus.page.index'); $params = array('mode' => 'deleted', 'link' => $link, 'trans_type' => '', 'summary' => $calendar['displayname'], 'cal_user' => $this->userId, 'cal_displayname' => $calendar['displayname']); ActivityData::logEventActivity($params, false, true); } return $bDeleteCalendar; } else { return $bDeleteCalendar; } }
/** * @brief removes a calendar * @param integer $id * @return boolean */ public static function deleteCalendar($id) { $calendar = self::find($id); //\OCP\Util::writeLog('DAV', 'DEL ID-> '.$id, \OCP\Util::DEBUG); $group = \OC::$server->getGroupManager()->get('admin'); $user = \OCP\User::getUser(); if ($calendar['userid'] != $user && !$group->inGroup($user)) { $sharedCalendar = \OCP\Share::getItemSharedWithBySource(App::SHARECALENDAR, App::SHARECALENDARPREFIX . $id); if (!$sharedCalendar || !($sharedCalendar['permissions'] & \OCP\PERMISSION_DELETE)) { throw new \Exception(App::$l10n->t('You do not have the permissions to delete this calendar.')); } } $stmt = \OCP\DB::prepare('DELETE FROM `' . App::CldCalendarTable . '` WHERE `id` = ?'); $stmt->execute(array($id)); $stmt = \OCP\DB::prepare('DELETE FROM `' . App::CldObjectTable . '` WHERE `calendarid` = ?'); $stmt->execute(array($id)); \OCP\Share::unshareAll(App::SHARECALENDAR, App::SHARECALENDARPREFIX . $id); \OCP\Util::emitHook('\\OCA\\CalendarPlus', 'deleteCalendar', $id); $calendars = self::allCalendars(\OCP\USER::getUser(), false, false); if (\OCP\USER::isLoggedIn() && count($calendars) === 0 || count($calendars) == 1 && $calendars[0]['id'] == 'birthday_' . \OCP\USER::getUser()) { self::addDefaultCalendars(\OCP\USER::getUser()); } $link = \OC::$server->getURLGenerator()->linkToRoute(App::$appname . '.page.index'); $params = array('mode' => 'deleted', 'link' => $link, 'trans_type' => '', 'summary' => $calendar['displayname'], 'cal_user' => $user, 'cal_displayname' => $calendar['displayname']); ActivityData::logEventActivity($params, false, true); return true; }
/** * @brief removes a calendar * @param integer $id * @return boolean */ public static function deleteCalendar($id) { $calendar = self::find($id); //\OCP\Util::writeLog('DAV', 'DEL ID-> '.$id, \OCP\Util::DEBUG); $group = \OC::$server->getGroupManager()->get('admin'); $user = \OCP\User::getUser(); if ($calendar['userid'] != $user && !$group->inGroup(\OC::$server->getUserSession()->getUser())) { $sharedCalendar = \OCP\Share::getItemSharedWithBySource(App::SHARECALENDAR, App::SHARECALENDARPREFIX . $id); if (!$sharedCalendar || !($sharedCalendar['permissions'] & \OCP\PERMISSION_DELETE)) { throw new \Exception(App::$l10n->t('You do not have the permissions to delete this calendar.')); } } $dbObject = \OC::$server->getDb(); $calendarDB = new CalendarDAO($dbObject, $user); $bDeleteCalendar = $calendarDB->delete($id); if ($bDeleteCalendar === true) { $stmt = \OCP\DB::prepare('DELETE FROM `' . App::CldObjectTable . '` WHERE `calendarid` = ?'); $stmt->execute(array($id)); \OCP\Share::unshareAll(App::SHARECALENDAR, App::SHARECALENDARPREFIX . $id); //\OCP\Util::emitHook('\OCA\CalendarPlus', 'deleteCalendar', $id); $app = new Application(); $c = $app->getContainer(); $repeatController = $c->query('RepeatController'); $repeatController->cleanCalendar($id); $link = \OC::$server->getURLGenerator()->linkToRoute(App::$appname . '.page.index'); $params = array('mode' => 'deleted', 'link' => $link, 'trans_type' => '', 'summary' => $calendar['displayname'], 'cal_user' => $user, 'cal_displayname' => $calendar['displayname']); ActivityData::logEventActivity($params, false, true); return $bDeleteCalendar; } else { return $bDeleteCalendar; } }
/** * @brief edits an object * @param integer $id id of object * @param string $data object * @return boolean */ public static function edit($id, $data, $orgid = 0) { $oldobject = Object::find($id); $calid = Object::getCalendarid($id); $calendar = Calendar::find($calid); $oldvobject = VObject::parse($oldobject['calendardata']); if ($calendar['userid'] !== \OCP\User::getUser()) { $shareMode = Object::checkShareMode($calid); if ($shareMode) { $sharedCalendar = \OCP\Share::getItemSharedWithBySource(CalendarApp::SHARECALENDAR, CalendarApp::SHARECALENDARPREFIX . $calid); //calid, not objectid !!!! 1111 one one one eleven } else { $sharedCalendar = \OCP\Share::getItemSharedWithBySource(CalendarApp::SHARETODO, CalendarApp::SHARETODOPREFIX . $id); } $sharedAccessClassPermissions = Object::getAccessClassPermissions($oldvobject); if (!$sharedCalendar || !($sharedCalendar['permissions'] & \OCP\PERMISSION_UPDATE) || !($sharedAccessClassPermissions & \OCP\PERMISSION_UPDATE)) { throw new \Exception(CalendarApp::$l10n->t('You do not have the permissions to edit this todo. Fehler' . $sharedCalendar . $id)); } } $object = VObject::parse($data); CalendarApp::loadCategoriesFromVCalendar($id, $object); list($type, $startdate, $enddate, $summary, $repeating, $uid, $isAlarm, $relatedTo) = Object::extractData($object); //check Share if ($orgid > 0) { $stmtShareUpdate = \OCP\DB::prepare("UPDATE `*PREFIX*share` SET `item_target`= ? WHERE `item_source` = ? AND `item_type` = ? "); $stmtShareUpdate->execute(array($summary, CalendarApp::SHARETODOPREFIX . $orgid, CalendarApp::SHARETODO)); $stmt = \OCP\DB::prepare('UPDATE `' . CalendarApp::CldObjectTable . '` SET `objecttype`=?,`startdate`=?,`enddate`=?,`repeating`=?,`summary`=?,`calendardata`=?,`lastmodified`= ? ,`isalarm`= ? ,`eventuid`= ?,`relatedto`= ? WHERE `id` = ?'); $stmt->execute(array($type, $startdate, $enddate, $repeating, $summary, $data, time(), $isAlarm, $uid, $relatedTo, $orgid)); } $stmtShare = \OCP\DB::prepare("SELECT COUNT(*) AS COUNTSHARE FROM `*PREFIX*share` WHERE `item_source` = ? AND `item_type`= ? "); $result = $stmtShare->execute(array(CalendarApp::SHARETODOPREFIX . $id, CalendarApp::SHARETODO)); $row = $result->fetchRow(); if ($row['COUNTSHARE'] >= 1) { $stmtShareUpdate = \OCP\DB::prepare("UPDATE `*PREFIX*share` SET `item_target`= ? WHERE `item_source` = ? AND `item_type` = ? "); $stmtShareUpdate->execute(array($summary, CalendarApp::SHARETODOPREFIX . $id, CalendarApp::SHARETODO)); $stmt = \OCP\DB::prepare('UPDATE `' . CalendarApp::CldObjectTable . '` SET `objecttype`=?,`startdate`=?,`enddate`=?,`repeating`=?,`summary`=?,`calendardata`=?,`lastmodified`= ?,`isalarm`= ? WHERE `org_objid` = ?'); $stmt->execute(array($type, $startdate, $enddate, $repeating, $summary, $data, time(), $isAlarm, $id)); } $stmt = \OCP\DB::prepare('UPDATE `' . CalendarApp::CldObjectTable . '` SET `objecttype`=?,`startdate`=?,`enddate`=?,`repeating`=?,`summary`=?,`calendardata`=?,`lastmodified`= ? ,`isalarm`= ?,`eventuid`= ?,`relatedto`= ? WHERE `id` = ?'); $stmt->execute(array($type, $startdate, $enddate, $repeating, $summary, $data, time(), $isAlarm, $uid, $relatedTo, $id)); Calendar::touchCalendar($oldobject['calendarid']); //\OCP\Util::emitHook('OC_Calendar', 'editTodo', $id); /****Activity New ***/ $link = \OC::$server->getURLGenerator()->linkToRoute(self::$appname . '.page.index') . '#' . urlencode($id); $params = array('mode' => 'edited', 'link' => $link, 'trans_type' => App::$l10n->t($type), 'summary' => $summary, 'cal_user' => $calendar['userid'], 'cal_displayname' => $calendar['displayname']); ActivityData::logEventActivity($params); /**END***/ return true; }