From 8fbc881a5f11a3dd415e52d0791dc483becde21a Mon Sep 17 00:00:00 2001 From: visithaWB Date: Tue, 16 Apr 2013 01:27:33 +0530 Subject: [PATCH 01/17] Send Mail button is added when event is sharing --- templates/part.share.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/templates/part.share.php b/templates/part.share.php index d161f237..1659cecb 100644 --- a/templates/part.share.php +++ b/templates/part.share.php @@ -1,6 +1,10 @@ ' . OC_Util::sanitizeHTML($l->t('Nobody')) . ''); } ?> +
+" onclick="Calendar.Util.sendmail('','','','','');"> +
+
t('Shared via calendar')); ?>
-t('NOTE: Actions on events shared via calendar will affect the entire calendar sharing.')); ?> \ No newline at end of file +t('NOTE: Actions on events shared via calendar will affect the entire calendar sharing.')); ?> From 86722a452d486d769ed2d2ec0f9fcb89da649bcc Mon Sep 17 00:00:00 2001 From: visithaWB Date: Tue, 16 Apr 2013 01:33:37 +0530 Subject: [PATCH 02/17] added new function sendmail to get event data and send them to sendmail.php ajax file --- js/calendar.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/js/calendar.js b/js/calendar.js index 5559eca0..340fdd69 100644 --- a/js/calendar.js +++ b/js/calendar.js @@ -8,6 +8,25 @@ Calendar={ Util:{ + sendmail: function(eventId, location, description, dtstart, dtend){ + $.post( + OC.filePath('calendar','ajax/event','sendmail.php'), + { + eventId:eventId, + location:location, + description:description, + dtstart:dtstart, + dtend:dtend + }, + function(result){ + if(result.status!='success'){ + OC.dialogs.alert(result.data.message, 'Error sending mail'); + } else { + UserList.add(username, result.data.groups, null, 'default', true); + } + } + ); + }, dateTimeToTimestamp:function(dateString, timeString){ dateTuple = dateString.split('-'); timeTuple = timeString.split(':'); From d8ef58ca8a4fb6b7e745dca53b9d14f671771b5a Mon Sep 17 00:00:00 2001 From: visithaWB Date: Tue, 16 Apr 2013 01:37:14 +0530 Subject: [PATCH 03/17] this is new ajax file created to send event data to back end for the email creation --- ajax/event/sendmail.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 ajax/event/sendmail.php diff --git a/ajax/event/sendmail.php b/ajax/event/sendmail.php new file mode 100644 index 00000000..5b6f7871 --- /dev/null +++ b/ajax/event/sendmail.php @@ -0,0 +1,29 @@ + + * 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(); + +$id = $_POST['id']; +$eventId = $_POST['eventId']; +$location = $_POST['location']; +$description = $_POST['description']; +$dtstart = $_POST['dtstart']; +$dtend = $_POST['dtend']; + +try { + //OC_Calendar_Object::sendMail(); + OC_Calendar_App::sendEmails($eventId, $location, $description, $dtstart, $dtend); +} catch(Exception $e) { + OCP\JSON::error(array('data' => array('message'=>$e->getMessage()))); + exit; +} + +OCP\JSON::success(); From 0efff2d24329e8a3ab1bca24c3092a0bf1594341 Mon Sep 17 00:00:00 2001 From: visithaWB Date: Tue, 16 Apr 2013 01:41:11 +0530 Subject: [PATCH 04/17] File bit changed --- ajax/event/sendmail.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ajax/event/sendmail.php b/ajax/event/sendmail.php index 5b6f7871..c6c0a0b1 100644 --- a/ajax/event/sendmail.php +++ b/ajax/event/sendmail.php @@ -1,6 +1,6 @@ + * Copyright (c) 2013 Visitha Baddegama * This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. @@ -19,7 +19,6 @@ $dtstart = $_POST['dtstart']; $dtend = $_POST['dtend']; try { - //OC_Calendar_Object::sendMail(); OC_Calendar_App::sendEmails($eventId, $location, $description, $dtstart, $dtend); } catch(Exception $e) { OCP\JSON::error(array('data' => array('message'=>$e->getMessage()))); From a4e3830a9602804a9a36464e13fd9a7496a7c023 Mon Sep 17 00:00:00 2001 From: visithaWB Date: Tue, 16 Apr 2013 01:43:52 +0530 Subject: [PATCH 05/17] added new function sendEmails to create HTML email and send it --- lib/app.php | 972 +++++++++++++++++++++++++++------------------------- 1 file changed, 513 insertions(+), 459 deletions(-) diff --git a/lib/app.php b/lib/app.php index aaab0fd6..e601c72b 100644 --- a/lib/app.php +++ b/lib/app.php @@ -1,4 +1,5 @@ * Copyright (c) 2012 Georg Ehrke @@ -10,496 +11,549 @@ */ OC_Calendar_App::$l10n = new OC_L10N('calendar'); OC_Calendar_App::$tz = OC_Calendar_App::getTimezone(); -class OC_Calendar_App{ - const CALENDAR = 'calendar'; - const EVENT = 'event'; - /** - * @brief language object for calendar app - */ - public static $l10n; - /** - * @brief categories of the user - */ - protected static $categories = null; +class OC_Calendar_App { - /** - * @brief timezone of the user - */ - public static $tz; + const CALENDAR = 'calendar'; + const EVENT = 'event'; - /** - * @brief returns informations about a calendar - * @param int $id - id of the calendar - * @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 getCalendar($id, $security = true, $shared = false) { - if(! is_numeric($id)) { - return false; - } + /** + * @brief language object for calendar app + */ + public static $l10n; - $calendar = OC_Calendar_Calendar::find($id); - // FIXME: Correct arguments to just check for permissions - if($security === true && $shared === false) { - if(OCP\User::getUser() === $calendar['userid']){ - return $calendar; - }else{ - return false; - } - } - if($security === true && $shared === true) { - if(OCP\Share::getItemSharedWithBySource('calendar', $id)) { - return $calendar; - } - } - return $calendar; - } + /** + * @brief categories of the user + */ + protected static $categories = null; - /** - * @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 = OC_Calendar_Object::find($id); - if($shared === true || $security === true) { - $permissions = self::getPermissions($id, self::EVENT); - OCP\Util::writeLog('contacts', __METHOD__.' id: '.$id.', permissions: '.$permissions, OCP\Util::DEBUG); - if(self::getPermissions($id, self::EVENT)) { - return $event; - } - } else { - return $event; - } + /** + * @brief timezone of the user + */ + public static $tz; - return false; - } + /** + * @brief Check if the password is correct + * @param $uid The username + * @param $password The password + * @returns string + * + * Check if the password is correct without logging in the user + * returns the user id or false + */ + public static function sendEmails($eventid, $location, $description, $dtstart, $dtend) { - /** - * @brief returns the parsed calendar data - * @param int $id - id of the event - * @param bool $security - check access rights or not - * @return mixed - bool / object - */ - public static function getVCalendar($id, $security = true, $shared = false) { - $event_object = self::getEventObject($id, $security, $shared); - if($event_object === false) { - return false; - } - $vobject = OC_VObject::parse($event_object['calendardata']); - if(is_null($vobject)) { - return false; - } - return $vobject; - } + $user = OC_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) { + $eventShareesNames[] = $sharee['share_with']; + } + } + foreach ($eventShareesNames as $name) { + $result = OC_Calendar_Calendar::getUsersEmails($name); + $emails[] = $result; + } + foreach ($emails as $email) { + $to = "visithauom@gmail.com"; + $from = "visithauom@gmail.com"; + $subject = "Testing mail"; + $headers = "MIME-Version: 1.0\r\n"; - /** - * @brief checks if an event was edited and dies if it was - * @param (object) $vevent - vevent object of the event - * @param (int) $lastmodified - time of last modification as unix timestamp - * @return (bool) - */ - public static function isNotModified($vevent, $lastmodified) { - $last_modified = $vevent->__get('LAST-MODIFIED'); - if($last_modified && $lastmodified != $last_modified->getDateTime()->format('U')) { - OCP\JSON::error(array('modified'=>true)); - exit; - } - return true; - } + $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; - /** - * @brief returns the default categories of ownCloud - * @return (array) $categories - */ - public static function getDefaultCategories() { - return array( - (string)self::$l10n->t('Birthday'), - (string)self::$l10n->t('Business'), - (string)self::$l10n->t('Call'), - (string)self::$l10n->t('Clients'), - (string)self::$l10n->t('Deliverer'), - (string)self::$l10n->t('Holidays'), - (string)self::$l10n->t('Ideas'), - (string)self::$l10n->t('Journey'), - (string)self::$l10n->t('Jubilee'), - (string)self::$l10n->t('Meeting'), - (string)self::$l10n->t('Other'), - (string)self::$l10n->t('Personal'), - (string)self::$l10n->t('Projects'), - (string)self::$l10n->t('Questions'), - (string)self::$l10n->t('Work'), - ); - } + $headers .= "From:" . $from; - /** - * @brief returns the vcategories object of the user - * @return (object) $vcategories - */ - public static function getVCategories() { - if (is_null(self::$categories)) { - if(OC_VCategories::isEmpty('event')) { - self::scanCategories(); - } - self::$categories = new OC_VCategories('event', - null, - self::getDefaultCategories()); - } - return self::$categories; - } + $message = ''; +//$message .= 'Website Change Request'; + $message .= ''; + $message .= ""; + $message .= ""; + $message .= ""; + $message .= "
" . $user . " has shared with you an event
Location: " . $location . "
Description: " . $description . "
"; + $message .= ""; - /** - * @brief returns the categories of the vcategories object - * @return (array) $categories - */ - public static function getCategoryOptions() { - $categories = self::getVCategories()->categories(); - return $categories; - } + OC_Mail::send($email, "User", "Calendar Event Shared..!", $message, "visithauom@gmail.com", $user, $html = 1, $altbody = '', $ccaddress = '', $ccname = '', $bcc = ''); + } + } - /** - * scan events for categories. - * @param $events VEVENTs to scan. null to check all events for the current user. - */ - public static function scanCategories($events = null) { - if (is_null($events)) { - $calendars = OC_Calendar_Calendar::allCalendars(OCP\USER::getUser()); - if(count($calendars) > 0) { - $events = array(); - foreach($calendars as $calendar) { - if($calendar['userid'] === OCP\User::getUser()) { - $calendar_events = OC_Calendar_Object::all($calendar['id']); - $events = $events + $calendar_events; - } - } - } - } - if(is_array($events) && count($events) > 0) { - $vcategories = new OC_VCategories('event'); - $vcategories->delete($vcategories->categories()); - foreach($events as $event) { - $vobject = OC_VObject::parse($event['calendardata']); - if(!is_null($vobject)) { - $object = null; - if (isset($calendar->VEVENT)) { - $object = $calendar->VEVENT; - } else - if (isset($calendar->VTODO)) { - $object = $calendar->VTODO; - } else - if (isset($calendar->VJOURNAL)) { - $object = $calendar->VJOURNAL; - } - if ($object) { - $vcategories->loadFromVObject($event['id'], $vobject, true); - } - } - } - } - } + /** + * @brief returns informations about a calendar + * @param int $id - id of the calendar + * @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 getCalendar($id, $security = true, $shared = false) { + if (!is_numeric($id)) { + return false; + } - /** - * check VEvent for new categories. - * @see OC_VCategories::loadFromVObject - */ - public static function loadCategoriesFromVCalendar($id, OC_VObject $calendar) { - $object = null; - if (isset($calendar->VEVENT)) { - $object = $calendar->VEVENT; - } else - if (isset($calendar->VTODO)) { - $object = $calendar->VTODO; - } else - if (isset($calendar->VJOURNAL)) { - $object = $calendar->VJOURNAL; - } - if ($object) { - self::getVCategories()->loadFromVObject($id, $object, true); - } - } + $calendar = OC_Calendar_Calendar::find($id); + // FIXME: Correct arguments to just check for permissions + if ($security === true && $shared === false) { + if (OCP\User::getUser() === $calendar['userid']) { + return $calendar; + } else { + return false; + } + } + if ($security === true && $shared === true) { + if (OCP\Share::getItemSharedWithBySource('calendar', $id)) { + return $calendar; + } + } + return $calendar; + } - /** - * @brief returns the options for the access class of an event - * @return array - valid inputs for the access class of an event - */ - public static function getAccessClassOptions() { - return OC_Calendar_Object::getAccessClassOptions(self::$l10n); - } + /** + * @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 = OC_Calendar_Object::find($id); + if ($shared === true || $security === true) { + $permissions = self::getPermissions($id, self::EVENT); + OCP\Util::writeLog('contacts', __METHOD__ . ' id: ' . $id . ', permissions: ' . $permissions, OCP\Util::DEBUG); + if (self::getPermissions($id, self::EVENT)) { + return $event; + } + } else { + return $event; + } - /** - * @brief returns the options for the repeat rule of an repeating event - * @return array - valid inputs for the repeat rule of an repeating event - */ - public static function getRepeatOptions() { - return OC_Calendar_Object::getRepeatOptions(self::$l10n); - } + return false; + } - /** - * @brief returns the options for the end of an repeating event - * @return array - valid inputs for the end of an repeating events - */ - public static function getEndOptions() { - return OC_Calendar_Object::getEndOptions(self::$l10n); - } + /** + * @brief returns the parsed calendar data + * @param int $id - id of the event + * @param bool $security - check access rights or not + * @return mixed - bool / object + */ + public static function getVCalendar($id, $security = true, $shared = false) { + $event_object = self::getEventObject($id, $security, $shared); + if ($event_object === false) { + return false; + } + $vobject = OC_VObject::parse($event_object['calendardata']); + if (is_null($vobject)) { + return false; + } + return $vobject; + } - /** - * @brief returns the options for an monthly repeating event - * @return array - valid inputs for monthly repeating events - */ - public static function getMonthOptions() { - return OC_Calendar_Object::getMonthOptions(self::$l10n); - } + /** + * @brief checks if an event was edited and dies if it was + * @param (object) $vevent - vevent object of the event + * @param (int) $lastmodified - time of last modification as unix timestamp + * @return (bool) + */ + public static function isNotModified($vevent, $lastmodified) { + $last_modified = $vevent->__get('LAST-MODIFIED'); + if ($last_modified && $lastmodified != $last_modified->getDateTime()->format('U')) { + OCP\JSON::error(array('modified' => true)); + exit; + } + return true; + } - /** - * @brief returns the options for an weekly repeating event - * @return array - valid inputs for weekly repeating events - */ - public static function getWeeklyOptions() { - return OC_Calendar_Object::getWeeklyOptions(self::$l10n); - } + /** + * @brief returns the default categories of ownCloud + * @return (array) $categories + */ + public static function getDefaultCategories() { + return array( + (string) self::$l10n->t('Birthday'), + (string) self::$l10n->t('Business'), + (string) self::$l10n->t('Call'), + (string) self::$l10n->t('Clients'), + (string) self::$l10n->t('Deliverer'), + (string) self::$l10n->t('Holidays'), + (string) self::$l10n->t('Ideas'), + (string) self::$l10n->t('Journey'), + (string) self::$l10n->t('Jubilee'), + (string) self::$l10n->t('Meeting'), + (string) self::$l10n->t('Other'), + (string) self::$l10n->t('Personal'), + (string) self::$l10n->t('Projects'), + (string) self::$l10n->t('Questions'), + (string) self::$l10n->t('Work'), + ); + } - /** - * @brief returns the options for an yearly repeating event - * @return array - valid inputs for yearly repeating events - */ - public static function getYearOptions() { - return OC_Calendar_Object::getYearOptions(self::$l10n); - } + /** + * @brief returns the vcategories object of the user + * @return (object) $vcategories + */ + public static function getVCategories() { + if (is_null(self::$categories)) { + if (OC_VCategories::isEmpty('event')) { + self::scanCategories(); + } + self::$categories = new OC_VCategories('event', + null, + self::getDefaultCategories()); + } + return self::$categories; + } - /** - * @brief returns the options for an yearly repeating event which occurs on specific days of the year - * @return array - valid inputs for yearly repeating events - */ - public static function getByYearDayOptions() { - return OC_Calendar_Object::getByYearDayOptions(); - } + /** + * @brief returns the categories of the vcategories object + * @return (array) $categories + */ + public static function getCategoryOptions() { + $categories = self::getVCategories()->categories(); + return $categories; + } - /** - * @brief returns the options for an yearly repeating event which occurs on specific month of the year - * @return array - valid inputs for yearly repeating events - */ - public static function getByMonthOptions() { - return OC_Calendar_Object::getByMonthOptions(self::$l10n); - } + /** + * scan events for categories. + * @param $events VEVENTs to scan. null to check all events for the current user. + */ + public static function scanCategories($events = null) { + if (is_null($events)) { + $calendars = OC_Calendar_Calendar::allCalendars(OCP\USER::getUser()); + if (count($calendars) > 0) { + $events = array(); + foreach ($calendars as $calendar) { + if ($calendar['userid'] === OCP\User::getUser()) { + $calendar_events = OC_Calendar_Object::all($calendar['id']); + $events = $events + $calendar_events; + } + } + } + } + if (is_array($events) && count($events) > 0) { + $vcategories = new OC_VCategories('event'); + $vcategories->delete($vcategories->categories()); + foreach ($events as $event) { + $vobject = OC_VObject::parse($event['calendardata']); + if (!is_null($vobject)) { + $object = null; + if (isset($calendar->VEVENT)) { + $object = $calendar->VEVENT; + } else + if (isset($calendar->VTODO)) { + $object = $calendar->VTODO; + } else + if (isset($calendar->VJOURNAL)) { + $object = $calendar->VJOURNAL; + } + if ($object) { + $vcategories->loadFromVObject($event['id'], $vobject, true); + } + } + } + } + } - /** - * @brief returns the options for an yearly repeating event which occurs on specific week numbers of the year - * @return array - valid inputs for yearly repeating events - */ - public static function getByWeekNoOptions() { - return OC_Calendar_Object::getByWeekNoOptions(); - } + /** + * check VEvent for new categories. + * @see OC_VCategories::loadFromVObject + */ + public static function loadCategoriesFromVCalendar($id, OC_VObject $calendar) { + $object = null; + if (isset($calendar->VEVENT)) { + $object = $calendar->VEVENT; + } else + if (isset($calendar->VTODO)) { + $object = $calendar->VTODO; + } else + if (isset($calendar->VJOURNAL)) { + $object = $calendar->VJOURNAL; + } + if ($object) { + self::getVCategories()->loadFromVObject($id, $object, true); + } + } - /** - * @brief returns the options for an yearly or monthly repeating event which occurs on specific days of the month - * @return array - valid inputs for yearly or monthly repeating events - */ - public static function getByMonthDayOptions() { - return OC_Calendar_Object::getByMonthDayOptions(); - } + /** + * @brief returns the options for the access class of an event + * @return array - valid inputs for the access class of an event + */ + public static function getAccessClassOptions() { + return OC_Calendar_Object::getAccessClassOptions(self::$l10n); + } - /** - * @brief returns the options for an monthly repeating event which occurs on specific weeks of the month - * @return array - valid inputs for monthly repeating events - */ - public static function getWeekofMonth() { - return OC_Calendar_Object::getWeekofMonth(self::$l10n); - } + /** + * @brief returns the options for the repeat rule of an repeating event + * @return array - valid inputs for the repeat rule of an repeating event + */ + public static function getRepeatOptions() { + return OC_Calendar_Object::getRepeatOptions(self::$l10n); + } - /** - * @return (string) $timezone as set by user or the default timezone - */ - public static function getTimezone() { - return OCP\Config::getUserValue(OCP\User::getUser(), - 'calendar', - 'timezone', - date_default_timezone_get()); - } + /** + * @brief returns the options for the end of an repeating event + * @return array - valid inputs for the end of an repeating events + */ + public static function getEndOptions() { + return OC_Calendar_Object::getEndOptions(self::$l10n); + } - /** - * @brief Get the permissions for a calendar / an event - * @param (int) $id - id of the calendar / event - * @param (string) $type - type of the id (calendar/event) - * @return (int) $permissions - CRUDS permissions - * @param (string) $accessclass - access class (rfc5545, section 3.8.1.3) - * @see OCP\Share - */ - public static function getPermissions($id, $type, $accessclass = '') { - $permissions_all = OCP\PERMISSION_ALL; + /** + * @brief returns the options for an monthly repeating event + * @return array - valid inputs for monthly repeating events + */ + public static function getMonthOptions() { + return OC_Calendar_Object::getMonthOptions(self::$l10n); + } - if($type == self::CALENDAR) { - $calendar = self::getCalendar($id, false, false); - if($calendar['userid'] == OCP\USER::getUser()) { - return $permissions_all; - } else { - $sharedCalendar = OCP\Share::getItemSharedWithBySource('calendar', $id); - if ($sharedCalendar) { - return $sharedCalendar['permissions']; - } - } - } - elseif($type == self::EVENT) { - if(OC_Calendar_Object::getowner($id) == OCP\USER::getUser()) { - return $permissions_all; - } else { - $object = OC_Calendar_Object::find($id); - $sharedCalendar = OCP\Share::getItemSharedWithBySource('calendar', $object['calendarid']); - $sharedEvent = OCP\Share::getItemSharedWithBySource('event', $id); - $calendar_permissions = 0; - $event_permissions = 0; - if ($sharedCalendar) { - $calendar_permissions = $sharedCalendar['permissions']; - } - if ($sharedEvent) { - $event_permissions = $sharedEvent['permissions']; - } - if ($accessclass === 'PRIVATE') { - return 0; - } elseif ($accessclass === 'CONFIDENTIAL') { - return OCP\PERMISSION_READ; - } else { - return max($calendar_permissions, $event_permissions); - } - } - } - return 0; - } + /** + * @brief returns the options for an weekly repeating event + * @return array - valid inputs for weekly repeating events + */ + public static function getWeeklyOptions() { + return OC_Calendar_Object::getWeeklyOptions(self::$l10n); + } - /* - * @brief Get the permissions for an access class - * @param (string) $accessclass - access class (rfc5545, section 3.8.1.3) - * @return (int) $permissions - CRUDS permissions - * @see OCP\Share - */ - public static function getAccessClassPermissions($accessclass = '') { + /** + * @brief returns the options for an yearly repeating event + * @return array - valid inputs for yearly repeating events + */ + public static function getYearOptions() { + return OC_Calendar_Object::getYearOptions(self::$l10n); + } - switch($accessclass) { - case 'CONFIDENTIAL': - return OCP\PERMISSION_READ; - case 'PUBLIC': - case '': - return (OCP\PERMISSION_READ | OCP\PERMISSION_UPDATE | OCP\PERMISSION_DELETE); - default: - return 0; - } - } + /** + * @brief returns the options for an yearly repeating event which occurs on specific days of the year + * @return array - valid inputs for yearly repeating events + */ + public static function getByYearDayOptions() { + return OC_Calendar_Object::getByYearDayOptions(); + } - /** - * @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') { - $singleevents = OCP\Share::getItemsSharedWith('event', OC_Share_Backend_Event::FORMAT_EVENT); - foreach($singleevents as $singleevent) { - $singleevent['summary'] .= ' (' . self::$l10n->t('by') . ' ' . OC_Calendar_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 = OC_Calendar_Object::allInPeriod($calendarid, $start, $end, $calendar['userid'] !== OCP\User::getUser()); - } else { - OCP\Util::emitHook('OC_Calendar', 'getEvents', array('calendar_id' => $calendarid, 'events' => &$events)); - } - } - return $events; - } + /** + * @brief returns the options for an yearly repeating event which occurs on specific month of the year + * @return array - valid inputs for yearly repeating events + */ + public static function getByMonthOptions() { + return OC_Calendar_Object::getByMonthOptions(self::$l10n); + } - /** - * @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) { - \OCP\Util::writeLog('calendar', __METHOD__.' event: '.print_r($event['summary'], true), \OCP\Util::DEBUG); - 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"; - } - $object = OC_VObject::parse($event['calendardata']); - if(!$object) { - \OCP\Util::writeLog('calendar', __METHOD__.' Error parsing event: '.print_r($event, true), \OCP\Util::DEBUG); - return array(); - } + /** + * @brief returns the options for an yearly repeating event which occurs on specific week numbers of the year + * @return array - valid inputs for yearly repeating events + */ + public static function getByWeekNoOptions() { + return OC_Calendar_Object::getByWeekNoOptions(); + } - $output = array(); + /** + * @brief returns the options for an yearly or monthly repeating event which occurs on specific days of the month + * @return array - valid inputs for yearly or monthly repeating events + */ + public static function getByMonthDayOptions() { + return OC_Calendar_Object::getByMonthDayOptions(); + } + + /** + * @brief returns the options for an monthly repeating event which occurs on specific weeks of the month + * @return array - valid inputs for monthly repeating events + */ + public static function getWeekofMonth() { + return OC_Calendar_Object::getWeekofMonth(self::$l10n); + } + + /** + * @return (string) $timezone as set by user or the default timezone + */ + public static function getTimezone() { + return OCP\Config::getUserValue(OCP\User::getUser(), 'calendar', 'timezone', date_default_timezone_get()); + } + + /** + * @brief Get the permissions for a calendar / an event + * @param (int) $id - id of the calendar / event + * @param (string) $type - type of the id (calendar/event) + * @return (int) $permissions - CRUDS permissions + * @param (string) $accessclass - access class (rfc5545, section 3.8.1.3) + * @see OCP\Share + */ + public static function getPermissions($id, $type, $accessclass = '') { + $permissions_all = OCP\PERMISSION_ALL; + + if ($type == self::CALENDAR) { + $calendar = self::getCalendar($id, false, false); + if ($calendar['userid'] == OCP\USER::getUser()) { + return $permissions_all; + } else { + $sharedCalendar = OCP\Share::getItemSharedWithBySource('calendar', $id); + if ($sharedCalendar) { + return $sharedCalendar['permissions']; + } + } + } elseif ($type == self::EVENT) { + if (OC_Calendar_Object::getowner($id) == OCP\USER::getUser()) { + return $permissions_all; + } else { + $object = OC_Calendar_Object::find($id); + $sharedCalendar = OCP\Share::getItemSharedWithBySource('calendar', $object['calendarid']); + $sharedEvent = OCP\Share::getItemSharedWithBySource('event', $id); + $calendar_permissions = 0; + $event_permissions = 0; + if ($sharedCalendar) { + $calendar_permissions = $sharedCalendar['permissions']; + } + if ($sharedEvent) { + $event_permissions = $sharedEvent['permissions']; + } + if ($accessclass === 'PRIVATE') { + return 0; + } elseif ($accessclass === 'CONFIDENTIAL') { + return OCP\PERMISSION_READ; + } else { + return max($calendar_permissions, $event_permissions); + } + } + } + return 0; + } + + /* + * @brief Get the permissions for an access class + * @param (string) $accessclass - access class (rfc5545, section 3.8.1.3) + * @return (int) $permissions - CRUDS permissions + * @see OCP\Share + */ + + public static function getAccessClassPermissions($accessclass = '') { + + switch ($accessclass) { + case 'CONFIDENTIAL': + return OCP\PERMISSION_READ; + case 'PUBLIC': + case '': + return (OCP\PERMISSION_READ | OCP\PERMISSION_UPDATE | OCP\PERMISSION_DELETE); + default: + return 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') { + $singleevents = OCP\Share::getItemsSharedWith('event', OC_Share_Backend_Event::FORMAT_EVENT); + foreach ($singleevents as $singleevent) { + $singleevent['summary'] .= ' (' . self::$l10n->t('by') . ' ' . OC_Calendar_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 = OC_Calendar_Object::allInPeriod($calendarid, $start, $end, $calendar['userid'] !== OCP\User::getUser()); + } else { + OCP\Util::emitHook('OC_Calendar', 'getEvents', array('calendar_id' => $calendarid, 'events' => &$events)); + } + } + return $events; + } + + /** + * @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) { + \OCP\Util::writeLog('calendar', __METHOD__ . ' event: ' . print_r($event['summary'], true), \OCP\Util::DEBUG); + 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"; + } + $object = OC_VObject::parse($event['calendardata']); + if (!$object) { + \OCP\Util::writeLog('calendar', __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('calendar', __METHOD__ . ' Object contains not event: ' . print_r($event, true), \OCP\Util::DEBUG); + return $output; + } + $id = $event['id']; + if (OC_Calendar_Object::getowner($id) !== OCP\USER::getUser()) { + // do not show events with private or unknown access class + if (isset($vevent->CLASS) + && ($vevent->CLASS->value === 'CONFIDENTIAL' + || $vevent->CLASS->value === 'PRIVATE' + || $vevent->CLASS->value === '')) { + return $output; + } + $object = OC_Calendar_Object::cleanByAccessClass($id, $object); + } + $allday = ($vevent->DTSTART->getDateType() == Sabre\VObject\Property\DateTime::DATE) ? true : false; + $last_modified = @$vevent->__get('LAST-MODIFIED'); + $lastmodified = ($last_modified) ? $last_modified->getDateTime()->format('U') : 0; + $staticoutput = array('id' => (int) $event['id'], + 'title' => (!is_null($vevent->SUMMARY) && $vevent->SUMMARY->value != '') ? $vevent->SUMMARY->value : self::$l10n->t('unnamed'), + 'description' => isset($vevent->DESCRIPTION) ? $vevent->DESCRIPTION->value : '', + 'lastmodified' => $lastmodified, + 'allDay' => $allday); + if (OC_Calendar_Object::isrepeating($id) && OC_Calendar_Repeat::is_cached_inperiod($event['id'], $start, $end)) { + $cachedinperiod = OC_Calendar_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'); + } 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'); + } + $output[] = array_merge($staticoutput, $dynamicoutput); + } + } else { + if (OC_Calendar_Object::isrepeating($id) || $event['repeating'] == 1) { + $object->expand($start, $end); + } + foreach ($object->getComponents() as $singleevent) { + if (!($singleevent instanceof Sabre\VObject\Component\VEvent)) { + continue; + } + $dynamicoutput = OC_Calendar_Object::generateStartEndDate($singleevent->DTSTART, OC_Calendar_Object::getDTEndFromVEvent($singleevent), $allday, self::$tz); + $output[] = array_merge($staticoutput, $dynamicoutput); + } + } + \OCP\Util::writeLog('calendar', __METHOD__ . ' event: ' . print_r($event['summary'], true) . ' done', \OCP\Util::DEBUG); + return $output; + } - if($object->name === 'VEVENT') { - $vevent = $object; - } elseif(isset($object->VEVENT)) { - $vevent = $object->VEVENT; - } else { - \OCP\Util::writeLog('calendar', __METHOD__.' Object contains not event: '.print_r($event, true), \OCP\Util::DEBUG); - return $output; - } - $id = $event['id']; - if(OC_Calendar_Object::getowner($id) !== OCP\USER::getUser()) { - // do not show events with private or unknown access class - if (isset($vevent->CLASS) - && ($vevent->CLASS->value === 'CONFIDENTIAL' - || $vevent->CLASS->value === 'PRIVATE' - || $vevent->CLASS->value === '')) - { - return $output; - } - $object = OC_Calendar_Object::cleanByAccessClass($id, $object); - } - $allday = ($vevent->DTSTART->getDateType() == Sabre\VObject\Property\DateTime::DATE)?true:false; - $last_modified = @$vevent->__get('LAST-MODIFIED'); - $lastmodified = ($last_modified)?$last_modified->getDateTime()->format('U'):0; - $staticoutput = array('id'=>(int)$event['id'], - 'title' => (!is_null($vevent->SUMMARY) && $vevent->SUMMARY->value != '')? $vevent->SUMMARY->value: self::$l10n->t('unnamed'), - 'description' => isset($vevent->DESCRIPTION)?$vevent->DESCRIPTION->value:'', - 'lastmodified'=>$lastmodified, - 'allDay'=>$allday); - if(OC_Calendar_Object::isrepeating($id) && OC_Calendar_Repeat::is_cached_inperiod($event['id'], $start, $end)) { - $cachedinperiod = OC_Calendar_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'); - }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'); - } - $output[] = array_merge($staticoutput, $dynamicoutput); - } - }else{ - if(OC_Calendar_Object::isrepeating($id) || $event['repeating'] == 1) { - $object->expand($start, $end); - } - foreach($object->getComponents() as $singleevent) { - if(!($singleevent instanceof Sabre\VObject\Component\VEvent)) { - continue; - } - $dynamicoutput = OC_Calendar_Object::generateStartEndDate($singleevent->DTSTART, OC_Calendar_Object::getDTEndFromVEvent($singleevent), $allday, self::$tz); - $output[] = array_merge($staticoutput, $dynamicoutput); - } - } - \OCP\Util::writeLog('calendar', __METHOD__.' event: '.print_r($event['summary'], true) . ' done', \OCP\Util::DEBUG); - return $output; - } } From ad98fdcaa83897940b1e2ef1dc9f8609a50b3973 Mon Sep 17 00:00:00 2001 From: visithaWB Date: Tue, 16 Apr 2013 01:47:42 +0530 Subject: [PATCH 06/17] Added new function sendEmails to create HTML emails and send them --- lib/app.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/app.php b/lib/app.php index e601c72b..6c40f021 100644 --- a/lib/app.php +++ b/lib/app.php @@ -33,13 +33,13 @@ class OC_Calendar_App { public static $tz; /** - * @brief Check if the password is correct - * @param $uid The username - * @param $password The password - * @returns string + * @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 * - * Check if the password is correct without logging in the user - * returns the user id or false */ public static function sendEmails($eventid, $location, $description, $dtstart, $dtend) { From 0e37ca49e04526b377874497f72905d72dfaa5f2 Mon Sep 17 00:00:00 2001 From: visithaWB Date: Tue, 16 Apr 2013 02:10:51 +0530 Subject: [PATCH 07/17] method to return email address of selected user --- lib/calendar.php | 660 ++++++++++++++++++++++++----------------------- 1 file changed, 343 insertions(+), 317 deletions(-) diff --git a/lib/calendar.php b/lib/calendar.php index 266b7d07..dd74b9e6 100644 --- a/lib/calendar.php +++ b/lib/calendar.php @@ -1,4 +1,5 @@ * This file is licensed under the Affero General Public License version 3 or @@ -28,358 +29,383 @@ /** * This class manages our calendars */ -class OC_Calendar_Calendar{ - /** - * @brief Returns the list of calendars for a specific user. - * @param string $uid User ID - * @param boolean $active Only return calendars with this $active state, default(=false) is don't care - * @return array - */ - public static function allCalendars($uid, $active=false) { - $values = array($uid); - $active_where = ''; - if (!is_null($active) && $active) { - $active_where = ' AND `active` = ?'; - $values[] = (int)$active; - } - $stmt = OCP\DB::prepare( 'SELECT * FROM `*PREFIX*calendar_calendars` WHERE `userid` = ?' . $active_where ); - $result = $stmt->execute($values); +class OC_Calendar_Calendar { - $calendars = array(); - while( $row = $result->fetchRow()) { - $row['permissions'] = OCP\PERMISSION_CREATE - | OCP\PERMISSION_READ | OCP\PERMISSION_UPDATE - | OCP\PERMISSION_DELETE | OCP\PERMISSION_SHARE; - $calendars[] = $row; - } - $calendars = array_merge($calendars, OCP\Share::getItemsSharedWith('calendar', OC_Share_Backend_Calendar::FORMAT_CALENDAR)); + /** + * @brief Get the email address of user + * @returns the email address of user + * + * This method returns the email address of selected user. + */ + public function getUsersEmails($names) { + $emails = array(); + $query = OC_DB::prepare('SELECT `email` FROM `*PREFIX*users` WHERE LOWER(`uid`) = LOWER(?)'); + $result = $query->execute(array($names)); + $row = $result->fetchRow(); + $emails[] = $row['email']; - return $calendars; - } + return $row['email']; + } - /** - * @brief Returns the list of calendars for a principal (DAV term of user) - * @param string $principaluri - * @return array - */ - public static function allCalendarsWherePrincipalURIIs($principaluri) { - $uid = self::extractUserID($principaluri); - return self::allCalendars($uid); - } + /** + * @brief Returns the list of calendars for a specific user. + * @param string $uid User ID + * @param boolean $active Only return calendars with this $active state, default(=false) is don't care + * @return array + */ + public static function allCalendars($uid, $active = false) { + $values = array($uid); + $active_where = ''; + if (!is_null($active) && $active) { + $active_where = ' AND `active` = ?'; + $values[] = (int) $active; + } + $stmt = OCP\DB::prepare('SELECT * FROM `*PREFIX*calendar_calendars` WHERE `userid` = ?' . $active_where); + $result = $stmt->execute($values); - /** - * @brief Gets the data of one calendar - * @param integer $id - * @return associative array - */ - public static function find($id) { - $stmt = OCP\DB::prepare( 'SELECT * FROM `*PREFIX*calendar_calendars` WHERE `id` = ?' ); - $result = $stmt->execute(array($id)); + $calendars = array(); + while ($row = $result->fetchRow()) { + $row['permissions'] = OCP\PERMISSION_CREATE + | OCP\PERMISSION_READ | OCP\PERMISSION_UPDATE + | OCP\PERMISSION_DELETE | OCP\PERMISSION_SHARE; + $calendars[] = $row; + } + $calendars = array_merge($calendars, OCP\Share::getItemsSharedWith('calendar', OC_Share_Backend_Calendar::FORMAT_CALENDAR)); - $row = $result->fetchRow(); - if($row['userid'] != OCP\USER::getUser() && !OC_Group::inGroup(OCP\User::getUser(), 'admin')) { - $sharedCalendar = OCP\Share::getItemSharedWithBySource('calendar', $id); - if (!$sharedCalendar || !($sharedCalendar['permissions'] & OCP\PERMISSION_READ)) { - return $row; // I have to return the row so e.g. OC_Calendar_Object::getowner() works. - } - $row['permissions'] = $sharedCalendar['permissions']; - } else { - $row['permissions'] = OCP\PERMISSION_ALL; - } - return $row; - } + return $calendars; + } - /** - * @brief 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 Default: null, format: '#RRGGBB(AA)' - * @return insertid - */ - public static function addCalendar($userid,$name,$components='VEVENT,VTODO,VJOURNAL',$timezone=null,$order=0,$color=null) { - $all = self::allCalendars($userid); - $uris = array(); - foreach($all as $i) { - $uris[] = $i['uri']; - } + /** + * @brief Returns the list of calendars for a principal (DAV term of user) + * @param string $principaluri + * @return array + */ + public static function allCalendarsWherePrincipalURIIs($principaluri) { + $uid = self::extractUserID($principaluri); + return self::allCalendars($uid); + } - $uri = self::createURI($name, $uris ); + /** + * @brief Gets the data of one calendar + * @param integer $id + * @return associative array + */ + public static function find($id) { + $stmt = OCP\DB::prepare('SELECT * FROM `*PREFIX*calendar_calendars` WHERE `id` = ?'); + $result = $stmt->execute(array($id)); - $stmt = OCP\DB::prepare( 'INSERT INTO `*PREFIX*calendar_calendars` (`userid`,`displayname`,`uri`,`ctag`,`calendarorder`,`calendarcolor`,`timezone`,`components`) VALUES(?,?,?,?,?,?,?,?)' ); - $result = $stmt->execute(array($userid,$name,$uri,1,$order,$color,$timezone,$components)); + $row = $result->fetchRow(); + if ($row['userid'] != OCP\USER::getUser() && !OC_Group::inGroup(OCP\User::getUser(), 'admin')) { + $sharedCalendar = OCP\Share::getItemSharedWithBySource('calendar', $id); + if (!$sharedCalendar || !($sharedCalendar['permissions'] & OCP\PERMISSION_READ)) { + return $row; // I have to return the row so e.g. OC_Calendar_Object::getowner() works. + } + $row['permissions'] = $sharedCalendar['permissions']; + } else { + $row['permissions'] = OCP\PERMISSION_ALL; + } + return $row; + } - $insertid = OCP\DB::insertid('*PREFIX*calendar_calendars'); - OCP\Util::emitHook('OC_Calendar', 'addCalendar', $insertid); + /** + * @brief 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 Default: null, format: '#RRGGBB(AA)' + * @return insertid + */ + public static function addCalendar($userid, $name, $components = 'VEVENT,VTODO,VJOURNAL', $timezone = null, $order = 0, $color = null) { + $all = self::allCalendars($userid); + $uris = array(); + foreach ($all as $i) { + $uris[] = $i['uri']; + } - return $insertid; - } + $uri = self::createURI($name, $uris); - /** - * @brief Creates default calendars - * @param string $userid - * @return boolean - */ - public static function addDefaultCalendars($userid = null) { - if(is_null($userid)) { - $userid = OCP\USER::getUser(); - } - - $id = self::addCalendar($userid,'Default calendar'); + $stmt = OCP\DB::prepare('INSERT INTO `*PREFIX*calendar_calendars` (`userid`,`displayname`,`uri`,`ctag`,`calendarorder`,`calendarcolor`,`timezone`,`components`) VALUES(?,?,?,?,?,?,?,?)'); + $result = $stmt->execute(array($userid, $name, $uri, 1, $order, $color, $timezone, $components)); - return true; - } + $insertid = OCP\DB::insertid('*PREFIX*calendar_calendars'); + OCP\Util::emitHook('OC_Calendar', 'addCalendar', $insertid); - /** - * @brief Creates a new calendar from the data sabredav provides - * @param string $principaluri - * @param string $uri - * @param string $name - * @param string $components - * @param string $timezone - * @param integer $order - * @param string $color format: '#RRGGBB(AA)' - * @return insertid - */ - public static function addCalendarFromDAVData($principaluri,$uri,$name,$components,$timezone,$order,$color) { - $userid = self::extractUserID($principaluri); + return $insertid; + } - $stmt = OCP\DB::prepare( 'INSERT INTO `*PREFIX*calendar_calendars` (`userid`,`displayname`,`uri`,`ctag`,`calendarorder`,`calendarcolor`,`timezone`,`components`) VALUES(?,?,?,?,?,?,?,?)' ); - $result = $stmt->execute(array($userid,$name,$uri,1,$order,$color,$timezone,$components)); + /** + * @brief Creates default calendars + * @param string $userid + * @return boolean + */ + public static function addDefaultCalendars($userid = null) { + if (is_null($userid)) { + $userid = OCP\USER::getUser(); + } - $insertid = OCP\DB::insertid('*PREFIX*calendar_calendars'); - OCP\Util::emitHook('OC_Calendar', 'addCalendar', $insertid); + $id = self::addCalendar($userid, 'Default calendar'); - return $insertid; - } + return true; + } - /** - * @brief Edits a calendar - * @param integer $id - * @param string $name Default: null - * @param string $components Default: null - * @param string $timezone Default: null - * @param integer $order Default: null - * @param string $color Default: null, format: '#RRGGBB(AA)' - * @return boolean - * - * Values not null will be set - */ - public static function editCalendar($id,$name=null,$components=null,$timezone=null,$order=null,$color=null) { - // Need these ones for checking uri - $calendar = self::find($id); - if ($calendar['userid'] != OCP\User::getUser() && !OC_Group::inGroup(OCP\User::getUser(), 'admin')) { - $sharedCalendar = OCP\Share::getItemSharedWithBySource('calendar', $id); - if (!$sharedCalendar || !($sharedCalendar['permissions'] & OCP\PERMISSION_UPDATE)) { - throw new Exception( - OC_Calendar_App::$l10n->t( - 'You do not have the permissions to update this calendar.' - ) - ); - } - } + /** + * @brief Creates a new calendar from the data sabredav provides + * @param string $principaluri + * @param string $uri + * @param string $name + * @param string $components + * @param string $timezone + * @param integer $order + * @param string $color format: '#RRGGBB(AA)' + * @return insertid + */ + public static function addCalendarFromDAVData($principaluri, $uri, $name, $components, $timezone, $order, $color) { + $userid = self::extractUserID($principaluri); - // Keep old stuff - if(is_null($name)) $name = $calendar['displayname']; - if(is_null($components)) $components = $calendar['components']; - if(is_null($timezone)) $timezone = $calendar['timezone']; - if(is_null($order)) $order = $calendar['calendarorder']; - if(is_null($color)) $color = $calendar['calendarcolor']; + $stmt = OCP\DB::prepare('INSERT INTO `*PREFIX*calendar_calendars` (`userid`,`displayname`,`uri`,`ctag`,`calendarorder`,`calendarcolor`,`timezone`,`components`) VALUES(?,?,?,?,?,?,?,?)'); + $result = $stmt->execute(array($userid, $name, $uri, 1, $order, $color, $timezone, $components)); - $stmt = OCP\DB::prepare( 'UPDATE `*PREFIX*calendar_calendars` SET `displayname`=?,`calendarorder`=?,`calendarcolor`=?,`timezone`=?,`components`=?,`ctag`=`ctag`+1 WHERE `id`=?' ); - $result = $stmt->execute(array($name,$order,$color,$timezone,$components,$id)); + $insertid = OCP\DB::insertid('*PREFIX*calendar_calendars'); + OCP\Util::emitHook('OC_Calendar', 'addCalendar', $insertid); - OCP\Util::emitHook('OC_Calendar', 'editCalendar', $id); - return true; - } + return $insertid; + } - /** - * @brief Sets a calendar (in)active - * @param integer $id - * @param boolean $active - * @return boolean - */ - public static function setCalendarActive($id,$active) { - $calendar = self::find($id); - if ($calendar['userid'] != OCP\User::getUser()) { - $sharedCalendar = OCP\Share::getItemSharedWithBySource('calendar', $id); - if (!$sharedCalendar || !($sharedCalendar['permissions'] & OCP\PERMISSION_UPDATE)) { - throw new Exception( - OC_Calendar_App::$l10n->t( - 'You do not have the permissions to update this calendar.' - ) - ); - } - } - $stmt = OCP\DB::prepare( 'UPDATE `*PREFIX*calendar_calendars` SET `active` = ? WHERE `id` = ?' ); - $stmt->execute(array((int)$active, $id)); + /** + * @brief Edits a calendar + * @param integer $id + * @param string $name Default: null + * @param string $components Default: null + * @param string $timezone Default: null + * @param integer $order Default: null + * @param string $color Default: null, format: '#RRGGBB(AA)' + * @return boolean + * + * Values not null will be set + */ + public static function editCalendar($id, $name = null, $components = null, $timezone = null, $order = null, $color = null) { + // Need these ones for checking uri + $calendar = self::find($id); + if ($calendar['userid'] != OCP\User::getUser() && !OC_Group::inGroup(OCP\User::getUser(), 'admin')) { + $sharedCalendar = OCP\Share::getItemSharedWithBySource('calendar', $id); + if (!$sharedCalendar || !($sharedCalendar['permissions'] & OCP\PERMISSION_UPDATE)) { + throw new Exception( + OC_Calendar_App::$l10n->t( + 'You do not have the permissions to update this calendar.' + ) + ); + } + } - return true; - } + // Keep old stuff + if (is_null($name)) + $name = $calendar['displayname']; + if (is_null($components)) + $components = $calendar['components']; + if (is_null($timezone)) + $timezone = $calendar['timezone']; + if (is_null($order)) + $order = $calendar['calendarorder']; + if (is_null($color)) + $color = $calendar['calendarcolor']; - /** - * @brief Updates ctag for calendar - * @param integer $id - * @return boolean - */ - public static function touchCalendar($id) { - $stmt = OCP\DB::prepare( 'UPDATE `*PREFIX*calendar_calendars` SET `ctag` = `ctag` + 1 WHERE `id` = ?' ); - $stmt->execute(array($id)); + $stmt = OCP\DB::prepare('UPDATE `*PREFIX*calendar_calendars` SET `displayname`=?,`calendarorder`=?,`calendarcolor`=?,`timezone`=?,`components`=?,`ctag`=`ctag`+1 WHERE `id`=?'); + $result = $stmt->execute(array($name, $order, $color, $timezone, $components, $id)); - return true; - } + OCP\Util::emitHook('OC_Calendar', 'editCalendar', $id); + return true; + } - /** - * @brief removes a calendar - * @param integer $id - * @return boolean - */ - public static function deleteCalendar($id) { - $calendar = self::find($id); - if ($calendar['userid'] != OCP\User::getUser() && !OC_Group::inGroup(OCP\User::getUser(), 'admin')) { - $sharedCalendar = OCP\Share::getItemSharedWithBySource('calendar', $id); - if (!$sharedCalendar || !($sharedCalendar['permissions'] & OCP\PERMISSION_DELETE)) { - throw new Exception( - OC_Calendar_App::$l10n->t( - 'You do not have the permissions to delete this calendar.' - ) - ); - } - } - $stmt = OCP\DB::prepare( 'DELETE FROM `*PREFIX*calendar_calendars` WHERE `id` = ?' ); - $stmt->execute(array($id)); + /** + * @brief Sets a calendar (in)active + * @param integer $id + * @param boolean $active + * @return boolean + */ + public static function setCalendarActive($id, $active) { + $calendar = self::find($id); + if ($calendar['userid'] != OCP\User::getUser()) { + $sharedCalendar = OCP\Share::getItemSharedWithBySource('calendar', $id); + if (!$sharedCalendar || !($sharedCalendar['permissions'] & OCP\PERMISSION_UPDATE)) { + throw new Exception( + OC_Calendar_App::$l10n->t( + 'You do not have the permissions to update this calendar.' + ) + ); + } + } + $stmt = OCP\DB::prepare('UPDATE `*PREFIX*calendar_calendars` SET `active` = ? WHERE `id` = ?'); + $stmt->execute(array((int) $active, $id)); - $stmt = OCP\DB::prepare( 'DELETE FROM `*PREFIX*calendar_objects` WHERE `calendarid` = ?' ); - $stmt->execute(array($id)); + return true; + } - OCP\Share::unshareAll('calendar', $id); + /** + * @brief Updates ctag for calendar + * @param integer $id + * @return boolean + */ + public static function touchCalendar($id) { + $stmt = OCP\DB::prepare('UPDATE `*PREFIX*calendar_calendars` SET `ctag` = `ctag` + 1 WHERE `id` = ?'); + $stmt->execute(array($id)); - OCP\Util::emitHook('OC_Calendar', 'deleteCalendar', $id); - if(OCP\USER::isLoggedIn() and count(self::allCalendars(OCP\USER::getUser())) == 0) { - self::addDefaultCalendars(OCP\USER::getUser()); - } + return true; + } - return true; - } + /** + * @brief removes a calendar + * @param integer $id + * @return boolean + */ + public static function deleteCalendar($id) { + $calendar = self::find($id); + if ($calendar['userid'] != OCP\User::getUser() && !OC_Group::inGroup(OCP\User::getUser(), 'admin')) { + $sharedCalendar = OCP\Share::getItemSharedWithBySource('calendar', $id); + if (!$sharedCalendar || !($sharedCalendar['permissions'] & OCP\PERMISSION_DELETE)) { + throw new Exception( + OC_Calendar_App::$l10n->t( + 'You do not have the permissions to delete this calendar.' + ) + ); + } + } + $stmt = OCP\DB::prepare('DELETE FROM `*PREFIX*calendar_calendars` WHERE `id` = ?'); + $stmt->execute(array($id)); - /** - * @brief merges two calendars - * @param integer $id1 - * @param integer $id2 - * @return boolean - */ - public static function mergeCalendar($id1, $id2) { - $calendar = self::find($id1); - if ($calendar['userid'] != OCP\User::getUser() && !OC_Group::inGroup(OCP\User::getUser(), 'admin')) { - $sharedCalendar = OCP\Share::getItemSharedWithBySource('calendar', $id1); - if (!$sharedCalendar || !($sharedCalendar['permissions'] & OCP\PERMISSION_UPDATE)) { - throw new Exception( - OC_Calendar_App::$l10n->t( - 'You do not have the permissions to add to this calendar.' - ) - ); - } - } - $stmt = OCP\DB::prepare('UPDATE `*PREFIX*calendar_objects` SET `calendarid` = ? WHERE `calendarid` = ?'); - $stmt->execute(array($id1, $id2)); - self::touchCalendar($id1); - self::deleteCalendar($id2); - } + $stmt = OCP\DB::prepare('DELETE FROM `*PREFIX*calendar_objects` WHERE `calendarid` = ?'); + $stmt->execute(array($id)); - /** - * @brief Creates a URI for Calendar - * @param string $name name of the calendar - * @param array $existing existing calendar URIs - * @return string uri - */ - public static function createURI($name,$existing) { - $strip=array(' ','/','?','&');//these may break sync clients - $name=str_replace($strip,'',$name); - $name = strtolower($name); + OCP\Share::unshareAll('calendar', $id); - $newname = $name; - $i = 1; - while(in_array($newname,$existing)) { - $newname = $name.$i; - $i = $i + 1; - } - return $newname; - } + OCP\Util::emitHook('OC_Calendar', 'deleteCalendar', $id); + if (OCP\USER::isLoggedIn() and count(self::allCalendars(OCP\USER::getUser())) == 0) { + self::addDefaultCalendars(OCP\USER::getUser()); + } - /** - * @brief gets the userid from a principal path - * @return string - */ - public static function extractUserID($principaluri) { - list($prefix,$userid) = Sabre_DAV_URLUtil::splitPath($principaluri); - return $userid; - } + return true; + } - /** - * @brief returns the possible color for calendars - * @return array - */ - public static function getCalendarColorOptions() { - return array( - '#ff0000', // "Red" - '#b3dc6c', // "Green" - '#ffff00', // "Yellow" - '#808000', // "Olive" - '#ffa500', // "Orange" - '#ff7f50', // "Coral" - '#ee82ee', // "Violet" - '#9fc6e7', // "light blue" - ); - } + /** + * @brief merges two calendars + * @param integer $id1 + * @param integer $id2 + * @return boolean + */ + public static function mergeCalendar($id1, $id2) { + $calendar = self::find($id1); + if ($calendar['userid'] != OCP\User::getUser() && !OC_Group::inGroup(OCP\User::getUser(), 'admin')) { + $sharedCalendar = OCP\Share::getItemSharedWithBySource('calendar', $id1); + if (!$sharedCalendar || !($sharedCalendar['permissions'] & OCP\PERMISSION_UPDATE)) { + throw new Exception( + OC_Calendar_App::$l10n->t( + 'You do not have the permissions to add to this calendar.' + ) + ); + } + } + $stmt = OCP\DB::prepare('UPDATE `*PREFIX*calendar_objects` SET `calendarid` = ? WHERE `calendarid` = ?'); + $stmt->execute(array($id1, $id2)); + self::touchCalendar($id1); + self::deleteCalendar($id2); + } - /** - * @brief generates the Event Source Info for our JS - * @param array $calendar calendar data - * @return array - */ - public static function getEventSourceInfo($calendar) { - return array( - 'url' => OCP\Util::linkTo('calendar', 'ajax/events.php').'?calendar_id='.$calendar['id'], - 'backgroundColor' => $calendar['calendarcolor'], - 'borderColor' => '#888', - 'textColor' => self::generateTextColor($calendar['calendarcolor']), - 'cache' => true, - ); - } + /** + * @brief Creates a URI for Calendar + * @param string $name name of the calendar + * @param array $existing existing calendar URIs + * @return string uri + */ + public static function createURI($name, $existing) { + $strip = array(' ', '/', '?', '&'); //these may break sync clients + $name = str_replace($strip, '', $name); + $name = strtolower($name); - /* - * @brief checks if a calendar name is available for a user - * @param string $calendarname - * @param string $userid - * @return boolean - */ - public static function isCalendarNameavailable($calendarname, $userid) { - $calendars = self::allCalendars($userid); - foreach($calendars as $calendar) { - if($calendar['displayname'] == $calendarname) { - return false; - } - } - return true; - } + $newname = $name; + $i = 1; + while (in_array($newname, $existing)) { + $newname = $name . $i; + $i = $i + 1; + } + return $newname; + } + + /** + * @brief gets the userid from a principal path + * @return string + */ + public static function extractUserID($principaluri) { + list($prefix, $userid) = Sabre_DAV_URLUtil::splitPath($principaluri); + return $userid; + } + + /** + * @brief returns the possible color for calendars + * @return array + */ + public static function getCalendarColorOptions() { + return array( + '#ff0000', // "Red" + '#b3dc6c', // "Green" + '#ffff00', // "Yellow" + '#808000', // "Olive" + '#ffa500', // "Orange" + '#ff7f50', // "Coral" + '#ee82ee', // "Violet" + '#9fc6e7', // "light blue" + ); + } + + /** + * @brief generates the Event Source Info for our JS + * @param array $calendar calendar data + * @return array + */ + public static function getEventSourceInfo($calendar) { + return array( + 'url' => OCP\Util::linkTo('calendar', 'ajax/events.php') . '?calendar_id=' . $calendar['id'], + 'backgroundColor' => $calendar['calendarcolor'], + 'borderColor' => '#888', + 'textColor' => self::generateTextColor($calendar['calendarcolor']), + 'cache' => true, + ); + } + + /* + * @brief checks if a calendar name is available for a user + * @param string $calendarname + * @param string $userid + * @return boolean + */ + + public static function isCalendarNameavailable($calendarname, $userid) { + $calendars = self::allCalendars($userid); + foreach ($calendars as $calendar) { + if ($calendar['displayname'] == $calendarname) { + return false; + } + } + return true; + } + + /* + * @brief generates the text color for the calendar + * @param string $calendarcolor rgb calendar color code in hex format (with or without the leading #) + * (this function doesn't pay attention on the alpha value of rgba color codes) + * @return boolean + */ + + public static function generateTextColor($calendarcolor) { + if (substr_count($calendarcolor, '#') == 1) { + $calendarcolor = substr($calendarcolor, 1); + } + $red = hexdec(substr($calendarcolor, 0, 2)); + $green = hexdec(substr($calendarcolor, 2, 2)); + $blue = hexdec(substr($calendarcolor, 4, 2)); + //recommendation by W3C + $computation = ((($red * 299) + ($green * 587) + ($blue * 114)) / 1000); + return ($computation > 130) ? '#000000' : '#FAFAFA'; + } - /* - * @brief generates the text color for the calendar - * @param string $calendarcolor rgb calendar color code in hex format (with or without the leading #) - * (this function doesn't pay attention on the alpha value of rgba color codes) - * @return boolean - */ - public static function generateTextColor($calendarcolor) { - if(substr_count($calendarcolor, '#') == 1) { - $calendarcolor = substr($calendarcolor,1); - } - $red = hexdec(substr($calendarcolor,0,2)); - $green = hexdec(substr($calendarcolor,2,2)); - $blue = hexdec(substr($calendarcolor,4,2)); - //recommendation by W3C - $computation = ((($red * 299) + ($green * 587) + ($blue * 114)) / 1000); - return ($computation > 130)?'#000000':'#FAFAFA'; - } } From b3db1be93cd1d7c1b1dd1c5a6f8a222cbedb2f26 Mon Sep 17 00:00:00 2001 From: visithaWB Date: Tue, 16 Apr 2013 14:34:46 +0530 Subject: [PATCH 08/17] sendEmail function is modified to allow send emails to multiple users --- lib/app.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/app.php b/lib/app.php index 6c40f021..e4eb120d 100644 --- a/lib/app.php +++ b/lib/app.php @@ -62,15 +62,14 @@ class OC_Calendar_App { $result = OC_Calendar_Calendar::getUsersEmails($name); $emails[] = $result; } + $useremail = OC_Calendar_Calendar::getUsersEmails($user); foreach ($emails as $email) { - $to = "visithauom@gmail.com"; - $from = "visithauom@gmail.com"; - $subject = "Testing mail"; + $subject = "Calendar Event Shared..!!"; $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; - $headers .= "From:" . $from; + $headers .= "From:" . $useremail; $message = ''; //$message .= 'Website Change Request'; @@ -81,7 +80,7 @@ class OC_Calendar_App { $message .= ""; $message .= ""; - OC_Mail::send($email, "User", "Calendar Event Shared..!", $message, "visithauom@gmail.com", $user, $html = 1, $altbody = '', $ccaddress = '', $ccname = '', $bcc = ''); + OC_Mail::send($email, "User", $subject, $message, $useremail, $user, $html = 1, $altbody = '', $ccaddress = '', $ccname = '', $bcc = ''); } } From d9a7844bb62d3f12b5a239b1c79c8020519bd057 Mon Sep 17 00:00:00 2001 From: visithaWB Date: Thu, 18 Apr 2013 12:51:07 +0530 Subject: [PATCH 09/17] new branch is created --- calendar.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/calendar.php b/calendar.php index 2c0bee9d..caff0d08 100644 --- a/calendar.php +++ b/calendar.php @@ -7,6 +7,7 @@ */ $l10n = OC_L10N::get('calendar'); OCP\JSON::checkLoggedIn(); +OCP\JSON::checkLogged(); OCP\JSON::checkAppEnabled('calendar'); $tmpl = new OCP\Template('calendar', 'part.choosecalendar'); -$tmpl->printpage(); \ No newline at end of file +$tmpl->printpage(); From 1f91551adccaf58090a3f9a90bc29047604deaaf Mon Sep 17 00:00:00 2001 From: visithaWB Date: Thu, 18 Apr 2013 13:24:43 +0530 Subject: [PATCH 10/17] File is replaced by original file --- lib/app.php | 52 ---------------------------------------------------- 1 file changed, 52 deletions(-) diff --git a/lib/app.php b/lib/app.php index e4eb120d..88b9ec8a 100644 --- a/lib/app.php +++ b/lib/app.php @@ -32,58 +32,6 @@ class OC_Calendar_App { */ public static $tz; - /** - * @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, $location, $description, $dtstart, $dtend) { - - $user = OC_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) { - $eventShareesNames[] = $sharee['share_with']; - } - } - foreach ($eventShareesNames as $name) { - $result = OC_Calendar_Calendar::getUsersEmails($name); - $emails[] = $result; - } - $useremail = OC_Calendar_Calendar::getUsersEmails($user); - foreach ($emails as $email) { - $subject = "Calendar Event Shared..!!"; - $headers = "MIME-Version: 1.0\r\n"; - - $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; - - $headers .= "From:" . $useremail; - - $message = ''; -//$message .= 'Website Change Request'; - $message .= ''; - $message .= ""; - $message .= ""; - $message .= ""; - $message .= "
" . $user . " has shared with you an event
Location: " . $location . "
Description: " . $description . "
"; - $message .= ""; - - OC_Mail::send($email, "User", $subject, $message, $useremail, $user, $html = 1, $altbody = '', $ccaddress = '', $ccname = '', $bcc = ''); - } - } - /** * @brief returns informations about a calendar * @param int $id - id of the calendar From 4c26692344393f33b956c69c92fafdf5ed30248e Mon Sep 17 00:00:00 2001 From: visithaWB Date: Thu, 18 Apr 2013 13:31:19 +0530 Subject: [PATCH 11/17] Replaced by Orginal file --- lib/app.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/app.php b/lib/app.php index 88b9ec8a..1b36ab1f 100644 --- a/lib/app.php +++ b/lib/app.php @@ -11,7 +11,6 @@ */ OC_Calendar_App::$l10n = new OC_L10N('calendar'); OC_Calendar_App::$tz = OC_Calendar_App::getTimezone(); - class OC_Calendar_App { const CALENDAR = 'calendar'; From e7e5e9c1817745c06bf7b135c8c5390db57995f5 Mon Sep 17 00:00:00 2001 From: visithaWB Date: Thu, 18 Apr 2013 13:36:27 +0530 Subject: [PATCH 12/17] Replaced by Original file --- lib/app.php | 918 ++++++++++++++++++++++++++-------------------------- 1 file changed, 459 insertions(+), 459 deletions(-) diff --git a/lib/app.php b/lib/app.php index 1b36ab1f..aaab0fd6 100644 --- a/lib/app.php +++ b/lib/app.php @@ -1,5 +1,4 @@ * Copyright (c) 2012 Georg Ehrke @@ -11,495 +10,496 @@ */ OC_Calendar_App::$l10n = new OC_L10N('calendar'); OC_Calendar_App::$tz = OC_Calendar_App::getTimezone(); -class OC_Calendar_App { +class OC_Calendar_App{ + const CALENDAR = 'calendar'; + const EVENT = 'event'; + /** + * @brief language object for calendar app + */ + public static $l10n; - const CALENDAR = 'calendar'; - const EVENT = 'event'; + /** + * @brief categories of the user + */ + protected static $categories = null; - /** - * @brief language object for calendar app - */ - public static $l10n; + /** + * @brief timezone of the user + */ + public static $tz; - /** - * @brief categories of the user - */ - protected static $categories = null; + /** + * @brief returns informations about a calendar + * @param int $id - id of the calendar + * @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 getCalendar($id, $security = true, $shared = false) { + if(! is_numeric($id)) { + return false; + } - /** - * @brief timezone of the user - */ - public static $tz; + $calendar = OC_Calendar_Calendar::find($id); + // FIXME: Correct arguments to just check for permissions + if($security === true && $shared === false) { + if(OCP\User::getUser() === $calendar['userid']){ + return $calendar; + }else{ + return false; + } + } + if($security === true && $shared === true) { + if(OCP\Share::getItemSharedWithBySource('calendar', $id)) { + return $calendar; + } + } + return $calendar; + } - /** - * @brief returns informations about a calendar - * @param int $id - id of the calendar - * @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 getCalendar($id, $security = true, $shared = false) { - if (!is_numeric($id)) { - return false; - } + /** + * @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 = OC_Calendar_Object::find($id); + if($shared === true || $security === true) { + $permissions = self::getPermissions($id, self::EVENT); + OCP\Util::writeLog('contacts', __METHOD__.' id: '.$id.', permissions: '.$permissions, OCP\Util::DEBUG); + if(self::getPermissions($id, self::EVENT)) { + return $event; + } + } else { + return $event; + } - $calendar = OC_Calendar_Calendar::find($id); - // FIXME: Correct arguments to just check for permissions - if ($security === true && $shared === false) { - if (OCP\User::getUser() === $calendar['userid']) { - return $calendar; - } else { - return false; - } - } - if ($security === true && $shared === true) { - if (OCP\Share::getItemSharedWithBySource('calendar', $id)) { - return $calendar; - } - } - return $calendar; - } + return false; + } - /** - * @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 = OC_Calendar_Object::find($id); - if ($shared === true || $security === true) { - $permissions = self::getPermissions($id, self::EVENT); - OCP\Util::writeLog('contacts', __METHOD__ . ' id: ' . $id . ', permissions: ' . $permissions, OCP\Util::DEBUG); - if (self::getPermissions($id, self::EVENT)) { - return $event; - } - } else { - return $event; - } + /** + * @brief returns the parsed calendar data + * @param int $id - id of the event + * @param bool $security - check access rights or not + * @return mixed - bool / object + */ + public static function getVCalendar($id, $security = true, $shared = false) { + $event_object = self::getEventObject($id, $security, $shared); + if($event_object === false) { + return false; + } + $vobject = OC_VObject::parse($event_object['calendardata']); + if(is_null($vobject)) { + return false; + } + return $vobject; + } - return false; - } + /** + * @brief checks if an event was edited and dies if it was + * @param (object) $vevent - vevent object of the event + * @param (int) $lastmodified - time of last modification as unix timestamp + * @return (bool) + */ + public static function isNotModified($vevent, $lastmodified) { + $last_modified = $vevent->__get('LAST-MODIFIED'); + if($last_modified && $lastmodified != $last_modified->getDateTime()->format('U')) { + OCP\JSON::error(array('modified'=>true)); + exit; + } + return true; + } - /** - * @brief returns the parsed calendar data - * @param int $id - id of the event - * @param bool $security - check access rights or not - * @return mixed - bool / object - */ - public static function getVCalendar($id, $security = true, $shared = false) { - $event_object = self::getEventObject($id, $security, $shared); - if ($event_object === false) { - return false; - } - $vobject = OC_VObject::parse($event_object['calendardata']); - if (is_null($vobject)) { - return false; - } - return $vobject; - } + /** + * @brief returns the default categories of ownCloud + * @return (array) $categories + */ + public static function getDefaultCategories() { + return array( + (string)self::$l10n->t('Birthday'), + (string)self::$l10n->t('Business'), + (string)self::$l10n->t('Call'), + (string)self::$l10n->t('Clients'), + (string)self::$l10n->t('Deliverer'), + (string)self::$l10n->t('Holidays'), + (string)self::$l10n->t('Ideas'), + (string)self::$l10n->t('Journey'), + (string)self::$l10n->t('Jubilee'), + (string)self::$l10n->t('Meeting'), + (string)self::$l10n->t('Other'), + (string)self::$l10n->t('Personal'), + (string)self::$l10n->t('Projects'), + (string)self::$l10n->t('Questions'), + (string)self::$l10n->t('Work'), + ); + } - /** - * @brief checks if an event was edited and dies if it was - * @param (object) $vevent - vevent object of the event - * @param (int) $lastmodified - time of last modification as unix timestamp - * @return (bool) - */ - public static function isNotModified($vevent, $lastmodified) { - $last_modified = $vevent->__get('LAST-MODIFIED'); - if ($last_modified && $lastmodified != $last_modified->getDateTime()->format('U')) { - OCP\JSON::error(array('modified' => true)); - exit; - } - return true; - } + /** + * @brief returns the vcategories object of the user + * @return (object) $vcategories + */ + public static function getVCategories() { + if (is_null(self::$categories)) { + if(OC_VCategories::isEmpty('event')) { + self::scanCategories(); + } + self::$categories = new OC_VCategories('event', + null, + self::getDefaultCategories()); + } + return self::$categories; + } - /** - * @brief returns the default categories of ownCloud - * @return (array) $categories - */ - public static function getDefaultCategories() { - return array( - (string) self::$l10n->t('Birthday'), - (string) self::$l10n->t('Business'), - (string) self::$l10n->t('Call'), - (string) self::$l10n->t('Clients'), - (string) self::$l10n->t('Deliverer'), - (string) self::$l10n->t('Holidays'), - (string) self::$l10n->t('Ideas'), - (string) self::$l10n->t('Journey'), - (string) self::$l10n->t('Jubilee'), - (string) self::$l10n->t('Meeting'), - (string) self::$l10n->t('Other'), - (string) self::$l10n->t('Personal'), - (string) self::$l10n->t('Projects'), - (string) self::$l10n->t('Questions'), - (string) self::$l10n->t('Work'), - ); - } + /** + * @brief returns the categories of the vcategories object + * @return (array) $categories + */ + public static function getCategoryOptions() { + $categories = self::getVCategories()->categories(); + return $categories; + } - /** - * @brief returns the vcategories object of the user - * @return (object) $vcategories - */ - public static function getVCategories() { - if (is_null(self::$categories)) { - if (OC_VCategories::isEmpty('event')) { - self::scanCategories(); - } - self::$categories = new OC_VCategories('event', - null, - self::getDefaultCategories()); - } - return self::$categories; - } + /** + * scan events for categories. + * @param $events VEVENTs to scan. null to check all events for the current user. + */ + public static function scanCategories($events = null) { + if (is_null($events)) { + $calendars = OC_Calendar_Calendar::allCalendars(OCP\USER::getUser()); + if(count($calendars) > 0) { + $events = array(); + foreach($calendars as $calendar) { + if($calendar['userid'] === OCP\User::getUser()) { + $calendar_events = OC_Calendar_Object::all($calendar['id']); + $events = $events + $calendar_events; + } + } + } + } + if(is_array($events) && count($events) > 0) { + $vcategories = new OC_VCategories('event'); + $vcategories->delete($vcategories->categories()); + foreach($events as $event) { + $vobject = OC_VObject::parse($event['calendardata']); + if(!is_null($vobject)) { + $object = null; + if (isset($calendar->VEVENT)) { + $object = $calendar->VEVENT; + } else + if (isset($calendar->VTODO)) { + $object = $calendar->VTODO; + } else + if (isset($calendar->VJOURNAL)) { + $object = $calendar->VJOURNAL; + } + if ($object) { + $vcategories->loadFromVObject($event['id'], $vobject, true); + } + } + } + } + } - /** - * @brief returns the categories of the vcategories object - * @return (array) $categories - */ - public static function getCategoryOptions() { - $categories = self::getVCategories()->categories(); - return $categories; - } + /** + * check VEvent for new categories. + * @see OC_VCategories::loadFromVObject + */ + public static function loadCategoriesFromVCalendar($id, OC_VObject $calendar) { + $object = null; + if (isset($calendar->VEVENT)) { + $object = $calendar->VEVENT; + } else + if (isset($calendar->VTODO)) { + $object = $calendar->VTODO; + } else + if (isset($calendar->VJOURNAL)) { + $object = $calendar->VJOURNAL; + } + if ($object) { + self::getVCategories()->loadFromVObject($id, $object, true); + } + } - /** - * scan events for categories. - * @param $events VEVENTs to scan. null to check all events for the current user. - */ - public static function scanCategories($events = null) { - if (is_null($events)) { - $calendars = OC_Calendar_Calendar::allCalendars(OCP\USER::getUser()); - if (count($calendars) > 0) { - $events = array(); - foreach ($calendars as $calendar) { - if ($calendar['userid'] === OCP\User::getUser()) { - $calendar_events = OC_Calendar_Object::all($calendar['id']); - $events = $events + $calendar_events; - } - } - } - } - if (is_array($events) && count($events) > 0) { - $vcategories = new OC_VCategories('event'); - $vcategories->delete($vcategories->categories()); - foreach ($events as $event) { - $vobject = OC_VObject::parse($event['calendardata']); - if (!is_null($vobject)) { - $object = null; - if (isset($calendar->VEVENT)) { - $object = $calendar->VEVENT; - } else - if (isset($calendar->VTODO)) { - $object = $calendar->VTODO; - } else - if (isset($calendar->VJOURNAL)) { - $object = $calendar->VJOURNAL; - } - if ($object) { - $vcategories->loadFromVObject($event['id'], $vobject, true); - } - } - } - } - } + /** + * @brief returns the options for the access class of an event + * @return array - valid inputs for the access class of an event + */ + public static function getAccessClassOptions() { + return OC_Calendar_Object::getAccessClassOptions(self::$l10n); + } - /** - * check VEvent for new categories. - * @see OC_VCategories::loadFromVObject - */ - public static function loadCategoriesFromVCalendar($id, OC_VObject $calendar) { - $object = null; - if (isset($calendar->VEVENT)) { - $object = $calendar->VEVENT; - } else - if (isset($calendar->VTODO)) { - $object = $calendar->VTODO; - } else - if (isset($calendar->VJOURNAL)) { - $object = $calendar->VJOURNAL; - } - if ($object) { - self::getVCategories()->loadFromVObject($id, $object, true); - } - } + /** + * @brief returns the options for the repeat rule of an repeating event + * @return array - valid inputs for the repeat rule of an repeating event + */ + public static function getRepeatOptions() { + return OC_Calendar_Object::getRepeatOptions(self::$l10n); + } - /** - * @brief returns the options for the access class of an event - * @return array - valid inputs for the access class of an event - */ - public static function getAccessClassOptions() { - return OC_Calendar_Object::getAccessClassOptions(self::$l10n); - } + /** + * @brief returns the options for the end of an repeating event + * @return array - valid inputs for the end of an repeating events + */ + public static function getEndOptions() { + return OC_Calendar_Object::getEndOptions(self::$l10n); + } - /** - * @brief returns the options for the repeat rule of an repeating event - * @return array - valid inputs for the repeat rule of an repeating event - */ - public static function getRepeatOptions() { - return OC_Calendar_Object::getRepeatOptions(self::$l10n); - } + /** + * @brief returns the options for an monthly repeating event + * @return array - valid inputs for monthly repeating events + */ + public static function getMonthOptions() { + return OC_Calendar_Object::getMonthOptions(self::$l10n); + } - /** - * @brief returns the options for the end of an repeating event - * @return array - valid inputs for the end of an repeating events - */ - public static function getEndOptions() { - return OC_Calendar_Object::getEndOptions(self::$l10n); - } + /** + * @brief returns the options for an weekly repeating event + * @return array - valid inputs for weekly repeating events + */ + public static function getWeeklyOptions() { + return OC_Calendar_Object::getWeeklyOptions(self::$l10n); + } - /** - * @brief returns the options for an monthly repeating event - * @return array - valid inputs for monthly repeating events - */ - public static function getMonthOptions() { - return OC_Calendar_Object::getMonthOptions(self::$l10n); - } + /** + * @brief returns the options for an yearly repeating event + * @return array - valid inputs for yearly repeating events + */ + public static function getYearOptions() { + return OC_Calendar_Object::getYearOptions(self::$l10n); + } - /** - * @brief returns the options for an weekly repeating event - * @return array - valid inputs for weekly repeating events - */ - public static function getWeeklyOptions() { - return OC_Calendar_Object::getWeeklyOptions(self::$l10n); - } + /** + * @brief returns the options for an yearly repeating event which occurs on specific days of the year + * @return array - valid inputs for yearly repeating events + */ + public static function getByYearDayOptions() { + return OC_Calendar_Object::getByYearDayOptions(); + } - /** - * @brief returns the options for an yearly repeating event - * @return array - valid inputs for yearly repeating events - */ - public static function getYearOptions() { - return OC_Calendar_Object::getYearOptions(self::$l10n); - } + /** + * @brief returns the options for an yearly repeating event which occurs on specific month of the year + * @return array - valid inputs for yearly repeating events + */ + public static function getByMonthOptions() { + return OC_Calendar_Object::getByMonthOptions(self::$l10n); + } - /** - * @brief returns the options for an yearly repeating event which occurs on specific days of the year - * @return array - valid inputs for yearly repeating events - */ - public static function getByYearDayOptions() { - return OC_Calendar_Object::getByYearDayOptions(); - } + /** + * @brief returns the options for an yearly repeating event which occurs on specific week numbers of the year + * @return array - valid inputs for yearly repeating events + */ + public static function getByWeekNoOptions() { + return OC_Calendar_Object::getByWeekNoOptions(); + } - /** - * @brief returns the options for an yearly repeating event which occurs on specific month of the year - * @return array - valid inputs for yearly repeating events - */ - public static function getByMonthOptions() { - return OC_Calendar_Object::getByMonthOptions(self::$l10n); - } + /** + * @brief returns the options for an yearly or monthly repeating event which occurs on specific days of the month + * @return array - valid inputs for yearly or monthly repeating events + */ + public static function getByMonthDayOptions() { + return OC_Calendar_Object::getByMonthDayOptions(); + } - /** - * @brief returns the options for an yearly repeating event which occurs on specific week numbers of the year - * @return array - valid inputs for yearly repeating events - */ - public static function getByWeekNoOptions() { - return OC_Calendar_Object::getByWeekNoOptions(); - } + /** + * @brief returns the options for an monthly repeating event which occurs on specific weeks of the month + * @return array - valid inputs for monthly repeating events + */ + public static function getWeekofMonth() { + return OC_Calendar_Object::getWeekofMonth(self::$l10n); + } - /** - * @brief returns the options for an yearly or monthly repeating event which occurs on specific days of the month - * @return array - valid inputs for yearly or monthly repeating events - */ - public static function getByMonthDayOptions() { - return OC_Calendar_Object::getByMonthDayOptions(); - } + /** + * @return (string) $timezone as set by user or the default timezone + */ + public static function getTimezone() { + return OCP\Config::getUserValue(OCP\User::getUser(), + 'calendar', + 'timezone', + date_default_timezone_get()); + } - /** - * @brief returns the options for an monthly repeating event which occurs on specific weeks of the month - * @return array - valid inputs for monthly repeating events - */ - public static function getWeekofMonth() { - return OC_Calendar_Object::getWeekofMonth(self::$l10n); - } + /** + * @brief Get the permissions for a calendar / an event + * @param (int) $id - id of the calendar / event + * @param (string) $type - type of the id (calendar/event) + * @return (int) $permissions - CRUDS permissions + * @param (string) $accessclass - access class (rfc5545, section 3.8.1.3) + * @see OCP\Share + */ + public static function getPermissions($id, $type, $accessclass = '') { + $permissions_all = OCP\PERMISSION_ALL; - /** - * @return (string) $timezone as set by user or the default timezone - */ - public static function getTimezone() { - return OCP\Config::getUserValue(OCP\User::getUser(), 'calendar', 'timezone', date_default_timezone_get()); - } + if($type == self::CALENDAR) { + $calendar = self::getCalendar($id, false, false); + if($calendar['userid'] == OCP\USER::getUser()) { + return $permissions_all; + } else { + $sharedCalendar = OCP\Share::getItemSharedWithBySource('calendar', $id); + if ($sharedCalendar) { + return $sharedCalendar['permissions']; + } + } + } + elseif($type == self::EVENT) { + if(OC_Calendar_Object::getowner($id) == OCP\USER::getUser()) { + return $permissions_all; + } else { + $object = OC_Calendar_Object::find($id); + $sharedCalendar = OCP\Share::getItemSharedWithBySource('calendar', $object['calendarid']); + $sharedEvent = OCP\Share::getItemSharedWithBySource('event', $id); + $calendar_permissions = 0; + $event_permissions = 0; + if ($sharedCalendar) { + $calendar_permissions = $sharedCalendar['permissions']; + } + if ($sharedEvent) { + $event_permissions = $sharedEvent['permissions']; + } + if ($accessclass === 'PRIVATE') { + return 0; + } elseif ($accessclass === 'CONFIDENTIAL') { + return OCP\PERMISSION_READ; + } else { + return max($calendar_permissions, $event_permissions); + } + } + } + return 0; + } - /** - * @brief Get the permissions for a calendar / an event - * @param (int) $id - id of the calendar / event - * @param (string) $type - type of the id (calendar/event) - * @return (int) $permissions - CRUDS permissions - * @param (string) $accessclass - access class (rfc5545, section 3.8.1.3) - * @see OCP\Share - */ - public static function getPermissions($id, $type, $accessclass = '') { - $permissions_all = OCP\PERMISSION_ALL; + /* + * @brief Get the permissions for an access class + * @param (string) $accessclass - access class (rfc5545, section 3.8.1.3) + * @return (int) $permissions - CRUDS permissions + * @see OCP\Share + */ + public static function getAccessClassPermissions($accessclass = '') { - if ($type == self::CALENDAR) { - $calendar = self::getCalendar($id, false, false); - if ($calendar['userid'] == OCP\USER::getUser()) { - return $permissions_all; - } else { - $sharedCalendar = OCP\Share::getItemSharedWithBySource('calendar', $id); - if ($sharedCalendar) { - return $sharedCalendar['permissions']; - } - } - } elseif ($type == self::EVENT) { - if (OC_Calendar_Object::getowner($id) == OCP\USER::getUser()) { - return $permissions_all; - } else { - $object = OC_Calendar_Object::find($id); - $sharedCalendar = OCP\Share::getItemSharedWithBySource('calendar', $object['calendarid']); - $sharedEvent = OCP\Share::getItemSharedWithBySource('event', $id); - $calendar_permissions = 0; - $event_permissions = 0; - if ($sharedCalendar) { - $calendar_permissions = $sharedCalendar['permissions']; - } - if ($sharedEvent) { - $event_permissions = $sharedEvent['permissions']; - } - if ($accessclass === 'PRIVATE') { - return 0; - } elseif ($accessclass === 'CONFIDENTIAL') { - return OCP\PERMISSION_READ; - } else { - return max($calendar_permissions, $event_permissions); - } - } - } - return 0; - } + switch($accessclass) { + case 'CONFIDENTIAL': + return OCP\PERMISSION_READ; + case 'PUBLIC': + case '': + return (OCP\PERMISSION_READ | OCP\PERMISSION_UPDATE | OCP\PERMISSION_DELETE); + default: + return 0; + } + } - /* - * @brief Get the permissions for an access class - * @param (string) $accessclass - access class (rfc5545, section 3.8.1.3) - * @return (int) $permissions - CRUDS permissions - * @see OCP\Share - */ + /** + * @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') { + $singleevents = OCP\Share::getItemsSharedWith('event', OC_Share_Backend_Event::FORMAT_EVENT); + foreach($singleevents as $singleevent) { + $singleevent['summary'] .= ' (' . self::$l10n->t('by') . ' ' . OC_Calendar_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 = OC_Calendar_Object::allInPeriod($calendarid, $start, $end, $calendar['userid'] !== OCP\User::getUser()); + } else { + OCP\Util::emitHook('OC_Calendar', 'getEvents', array('calendar_id' => $calendarid, 'events' => &$events)); + } + } + return $events; + } - public static function getAccessClassPermissions($accessclass = '') { + /** + * @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) { + \OCP\Util::writeLog('calendar', __METHOD__.' event: '.print_r($event['summary'], true), \OCP\Util::DEBUG); + 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"; + } + $object = OC_VObject::parse($event['calendardata']); + if(!$object) { + \OCP\Util::writeLog('calendar', __METHOD__.' Error parsing event: '.print_r($event, true), \OCP\Util::DEBUG); + return array(); + } - switch ($accessclass) { - case 'CONFIDENTIAL': - return OCP\PERMISSION_READ; - case 'PUBLIC': - case '': - return (OCP\PERMISSION_READ | OCP\PERMISSION_UPDATE | OCP\PERMISSION_DELETE); - default: - return 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') { - $singleevents = OCP\Share::getItemsSharedWith('event', OC_Share_Backend_Event::FORMAT_EVENT); - foreach ($singleevents as $singleevent) { - $singleevent['summary'] .= ' (' . self::$l10n->t('by') . ' ' . OC_Calendar_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 = OC_Calendar_Object::allInPeriod($calendarid, $start, $end, $calendar['userid'] !== OCP\User::getUser()); - } else { - OCP\Util::emitHook('OC_Calendar', 'getEvents', array('calendar_id' => $calendarid, 'events' => &$events)); - } - } - return $events; - } - - /** - * @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) { - \OCP\Util::writeLog('calendar', __METHOD__ . ' event: ' . print_r($event['summary'], true), \OCP\Util::DEBUG); - 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"; - } - $object = OC_VObject::parse($event['calendardata']); - if (!$object) { - \OCP\Util::writeLog('calendar', __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('calendar', __METHOD__ . ' Object contains not event: ' . print_r($event, true), \OCP\Util::DEBUG); - return $output; - } - $id = $event['id']; - if (OC_Calendar_Object::getowner($id) !== OCP\USER::getUser()) { - // do not show events with private or unknown access class - if (isset($vevent->CLASS) - && ($vevent->CLASS->value === 'CONFIDENTIAL' - || $vevent->CLASS->value === 'PRIVATE' - || $vevent->CLASS->value === '')) { - return $output; - } - $object = OC_Calendar_Object::cleanByAccessClass($id, $object); - } - $allday = ($vevent->DTSTART->getDateType() == Sabre\VObject\Property\DateTime::DATE) ? true : false; - $last_modified = @$vevent->__get('LAST-MODIFIED'); - $lastmodified = ($last_modified) ? $last_modified->getDateTime()->format('U') : 0; - $staticoutput = array('id' => (int) $event['id'], - 'title' => (!is_null($vevent->SUMMARY) && $vevent->SUMMARY->value != '') ? $vevent->SUMMARY->value : self::$l10n->t('unnamed'), - 'description' => isset($vevent->DESCRIPTION) ? $vevent->DESCRIPTION->value : '', - 'lastmodified' => $lastmodified, - 'allDay' => $allday); - if (OC_Calendar_Object::isrepeating($id) && OC_Calendar_Repeat::is_cached_inperiod($event['id'], $start, $end)) { - $cachedinperiod = OC_Calendar_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'); - } 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'); - } - $output[] = array_merge($staticoutput, $dynamicoutput); - } - } else { - if (OC_Calendar_Object::isrepeating($id) || $event['repeating'] == 1) { - $object->expand($start, $end); - } - foreach ($object->getComponents() as $singleevent) { - if (!($singleevent instanceof Sabre\VObject\Component\VEvent)) { - continue; - } - $dynamicoutput = OC_Calendar_Object::generateStartEndDate($singleevent->DTSTART, OC_Calendar_Object::getDTEndFromVEvent($singleevent), $allday, self::$tz); - $output[] = array_merge($staticoutput, $dynamicoutput); - } - } - \OCP\Util::writeLog('calendar', __METHOD__ . ' event: ' . print_r($event['summary'], true) . ' done', \OCP\Util::DEBUG); - return $output; - } + $output = array(); + if($object->name === 'VEVENT') { + $vevent = $object; + } elseif(isset($object->VEVENT)) { + $vevent = $object->VEVENT; + } else { + \OCP\Util::writeLog('calendar', __METHOD__.' Object contains not event: '.print_r($event, true), \OCP\Util::DEBUG); + return $output; + } + $id = $event['id']; + if(OC_Calendar_Object::getowner($id) !== OCP\USER::getUser()) { + // do not show events with private or unknown access class + if (isset($vevent->CLASS) + && ($vevent->CLASS->value === 'CONFIDENTIAL' + || $vevent->CLASS->value === 'PRIVATE' + || $vevent->CLASS->value === '')) + { + return $output; + } + $object = OC_Calendar_Object::cleanByAccessClass($id, $object); + } + $allday = ($vevent->DTSTART->getDateType() == Sabre\VObject\Property\DateTime::DATE)?true:false; + $last_modified = @$vevent->__get('LAST-MODIFIED'); + $lastmodified = ($last_modified)?$last_modified->getDateTime()->format('U'):0; + $staticoutput = array('id'=>(int)$event['id'], + 'title' => (!is_null($vevent->SUMMARY) && $vevent->SUMMARY->value != '')? $vevent->SUMMARY->value: self::$l10n->t('unnamed'), + 'description' => isset($vevent->DESCRIPTION)?$vevent->DESCRIPTION->value:'', + 'lastmodified'=>$lastmodified, + 'allDay'=>$allday); + if(OC_Calendar_Object::isrepeating($id) && OC_Calendar_Repeat::is_cached_inperiod($event['id'], $start, $end)) { + $cachedinperiod = OC_Calendar_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'); + }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'); + } + $output[] = array_merge($staticoutput, $dynamicoutput); + } + }else{ + if(OC_Calendar_Object::isrepeating($id) || $event['repeating'] == 1) { + $object->expand($start, $end); + } + foreach($object->getComponents() as $singleevent) { + if(!($singleevent instanceof Sabre\VObject\Component\VEvent)) { + continue; + } + $dynamicoutput = OC_Calendar_Object::generateStartEndDate($singleevent->DTSTART, OC_Calendar_Object::getDTEndFromVEvent($singleevent), $allday, self::$tz); + $output[] = array_merge($staticoutput, $dynamicoutput); + } + } + \OCP\Util::writeLog('calendar', __METHOD__.' event: '.print_r($event['summary'], true) . ' done', \OCP\Util::DEBUG); + return $output; + } } From 418dc41878fe7e00dd0bf3d8a8bf436d08e47948 Mon Sep 17 00:00:00 2001 From: visithaWB Date: Thu, 18 Apr 2013 13:43:29 +0530 Subject: [PATCH 13/17] sendEmails function is added again --- lib/app.php | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/lib/app.php b/lib/app.php index aaab0fd6..8b665c4c 100644 --- a/lib/app.php +++ b/lib/app.php @@ -502,4 +502,56 @@ class OC_Calendar_App{ \OCP\Util::writeLog('calendar', __METHOD__.' event: '.print_r($event['summary'], true) . ' done', \OCP\Util::DEBUG); return $output; } + + /** + * @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, $location, $description, $dtstart, $dtend) { + + $user = OC_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) { + $eventShareesNames[] = $sharee['share_with']; + } + } + foreach ($eventShareesNames as $name) { + $result = OC_Calendar_Calendar::getUsersEmails($name); + $emails[] = $result; + } + $useremail = OC_Calendar_Calendar::getUsersEmails($user); + foreach ($emails as $email) { + $subject = "Calendar Event Shared..!!"; + $headers = "MIME-Version: 1.0\r\n"; + + $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; + + $headers .= "From:" . $useremail; + + $message = ''; + //$message .= 'Website Change Request'; + $message .= ''; + $message .= ""; + $message .= ""; + $message .= ""; + $message .= "
" . $user . " has shared with you an event
Location: " . $location . "
Description: " . $description . "
"; + $message .= ""; + + OC_Mail::send($email, "User", $subject, $message, $useremail, $user, $html = 1, $altbody = '', $ccaddress = '', $ccname = '', $bcc = ''); + } + } } From e9c367c3a0aa49d8ee7b0fe3249c5f509791ce28 Mon Sep 17 00:00:00 2001 From: visithaWB Date: Thu, 18 Apr 2013 13:47:02 +0530 Subject: [PATCH 14/17] Replaced by Original Calendar.php file --- lib/calendar.php | 662 +++++++++++++++++++++++------------------------ 1 file changed, 318 insertions(+), 344 deletions(-) diff --git a/lib/calendar.php b/lib/calendar.php index dd74b9e6..16615984 100644 --- a/lib/calendar.php +++ b/lib/calendar.php @@ -1,5 +1,4 @@ * This file is licensed under the Affero General Public License version 3 or @@ -29,383 +28,358 @@ /** * This class manages our calendars */ -class OC_Calendar_Calendar { +class OC_Calendar_Calendar{ + /** + * @brief Returns the list of calendars for a specific user. + * @param string $uid User ID + * @param boolean $active Only return calendars with this $active state, default(=false) is don't care + * @return array + */ + public static function allCalendars($uid, $active=false) { + $values = array($uid); + $active_where = ''; + if (!is_null($active) && $active) { + $active_where = ' AND `active` = ?'; + $values[] = (int)$active; + } + $stmt = OCP\DB::prepare( 'SELECT * FROM `*PREFIX*calendar_calendars` WHERE `userid` = ?' . $active_where ); + $result = $stmt->execute($values); - /** - * @brief Get the email address of user - * @returns the email address of user - * - * This method returns the email address of selected user. - */ - public function getUsersEmails($names) { - $emails = array(); - $query = OC_DB::prepare('SELECT `email` FROM `*PREFIX*users` WHERE LOWER(`uid`) = LOWER(?)'); - $result = $query->execute(array($names)); - $row = $result->fetchRow(); - $emails[] = $row['email']; + $calendars = array(); + while( $row = $result->fetchRow()) { + $row['permissions'] = OCP\PERMISSION_CREATE + | OCP\PERMISSION_READ | OCP\PERMISSION_UPDATE + | OCP\PERMISSION_DELETE | OCP\PERMISSION_SHARE; + $calendars[] = $row; + } + $calendars = array_merge($calendars, OCP\Share::getItemsSharedWith('calendar', OC_Share_Backend_Calendar::FORMAT_CALENDAR)); - return $row['email']; - } + return $calendars; + } - /** - * @brief Returns the list of calendars for a specific user. - * @param string $uid User ID - * @param boolean $active Only return calendars with this $active state, default(=false) is don't care - * @return array - */ - public static function allCalendars($uid, $active = false) { - $values = array($uid); - $active_where = ''; - if (!is_null($active) && $active) { - $active_where = ' AND `active` = ?'; - $values[] = (int) $active; - } - $stmt = OCP\DB::prepare('SELECT * FROM `*PREFIX*calendar_calendars` WHERE `userid` = ?' . $active_where); - $result = $stmt->execute($values); + /** + * @brief Returns the list of calendars for a principal (DAV term of user) + * @param string $principaluri + * @return array + */ + public static function allCalendarsWherePrincipalURIIs($principaluri) { + $uid = self::extractUserID($principaluri); + return self::allCalendars($uid); + } - $calendars = array(); - while ($row = $result->fetchRow()) { - $row['permissions'] = OCP\PERMISSION_CREATE - | OCP\PERMISSION_READ | OCP\PERMISSION_UPDATE - | OCP\PERMISSION_DELETE | OCP\PERMISSION_SHARE; - $calendars[] = $row; - } - $calendars = array_merge($calendars, OCP\Share::getItemsSharedWith('calendar', OC_Share_Backend_Calendar::FORMAT_CALENDAR)); + /** + * @brief Gets the data of one calendar + * @param integer $id + * @return associative array + */ + public static function find($id) { + $stmt = OCP\DB::prepare( 'SELECT * FROM `*PREFIX*calendar_calendars` WHERE `id` = ?' ); + $result = $stmt->execute(array($id)); - return $calendars; - } + $row = $result->fetchRow(); + if($row['userid'] != OCP\USER::getUser() && !OC_Group::inGroup(OCP\User::getUser(), 'admin')) { + $sharedCalendar = OCP\Share::getItemSharedWithBySource('calendar', $id); + if (!$sharedCalendar || !($sharedCalendar['permissions'] & OCP\PERMISSION_READ)) { + return $row; // I have to return the row so e.g. OC_Calendar_Object::getowner() works. + } + $row['permissions'] = $sharedCalendar['permissions']; + } else { + $row['permissions'] = OCP\PERMISSION_ALL; + } + return $row; + } - /** - * @brief Returns the list of calendars for a principal (DAV term of user) - * @param string $principaluri - * @return array - */ - public static function allCalendarsWherePrincipalURIIs($principaluri) { - $uid = self::extractUserID($principaluri); - return self::allCalendars($uid); - } + /** + * @brief 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 Default: null, format: '#RRGGBB(AA)' + * @return insertid + */ + public static function addCalendar($userid,$name,$components='VEVENT,VTODO,VJOURNAL',$timezone=null,$order=0,$color=null) { + $all = self::allCalendars($userid); + $uris = array(); + foreach($all as $i) { + $uris[] = $i['uri']; + } - /** - * @brief Gets the data of one calendar - * @param integer $id - * @return associative array - */ - public static function find($id) { - $stmt = OCP\DB::prepare('SELECT * FROM `*PREFIX*calendar_calendars` WHERE `id` = ?'); - $result = $stmt->execute(array($id)); + $uri = self::createURI($name, $uris ); - $row = $result->fetchRow(); - if ($row['userid'] != OCP\USER::getUser() && !OC_Group::inGroup(OCP\User::getUser(), 'admin')) { - $sharedCalendar = OCP\Share::getItemSharedWithBySource('calendar', $id); - if (!$sharedCalendar || !($sharedCalendar['permissions'] & OCP\PERMISSION_READ)) { - return $row; // I have to return the row so e.g. OC_Calendar_Object::getowner() works. - } - $row['permissions'] = $sharedCalendar['permissions']; - } else { - $row['permissions'] = OCP\PERMISSION_ALL; - } - return $row; - } + $stmt = OCP\DB::prepare( 'INSERT INTO `*PREFIX*calendar_calendars` (`userid`,`displayname`,`uri`,`ctag`,`calendarorder`,`calendarcolor`,`timezone`,`components`) VALUES(?,?,?,?,?,?,?,?)' ); + $result = $stmt->execute(array($userid,$name,$uri,1,$order,$color,$timezone,$components)); - /** - * @brief 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 Default: null, format: '#RRGGBB(AA)' - * @return insertid - */ - public static function addCalendar($userid, $name, $components = 'VEVENT,VTODO,VJOURNAL', $timezone = null, $order = 0, $color = null) { - $all = self::allCalendars($userid); - $uris = array(); - foreach ($all as $i) { - $uris[] = $i['uri']; - } + $insertid = OCP\DB::insertid('*PREFIX*calendar_calendars'); + OCP\Util::emitHook('OC_Calendar', 'addCalendar', $insertid); - $uri = self::createURI($name, $uris); + return $insertid; + } - $stmt = OCP\DB::prepare('INSERT INTO `*PREFIX*calendar_calendars` (`userid`,`displayname`,`uri`,`ctag`,`calendarorder`,`calendarcolor`,`timezone`,`components`) VALUES(?,?,?,?,?,?,?,?)'); - $result = $stmt->execute(array($userid, $name, $uri, 1, $order, $color, $timezone, $components)); + /** + * @brief Creates default calendars + * @param string $userid + * @return boolean + */ + public static function addDefaultCalendars($userid = null) { + if(is_null($userid)) { + $userid = OCP\USER::getUser(); + } + + $id = self::addCalendar($userid,'Default calendar'); - $insertid = OCP\DB::insertid('*PREFIX*calendar_calendars'); - OCP\Util::emitHook('OC_Calendar', 'addCalendar', $insertid); + return true; + } - return $insertid; - } + /** + * @brief Creates a new calendar from the data sabredav provides + * @param string $principaluri + * @param string $uri + * @param string $name + * @param string $components + * @param string $timezone + * @param integer $order + * @param string $color format: '#RRGGBB(AA)' + * @return insertid + */ + public static function addCalendarFromDAVData($principaluri,$uri,$name,$components,$timezone,$order,$color) { + $userid = self::extractUserID($principaluri); - /** - * @brief Creates default calendars - * @param string $userid - * @return boolean - */ - public static function addDefaultCalendars($userid = null) { - if (is_null($userid)) { - $userid = OCP\USER::getUser(); - } + $stmt = OCP\DB::prepare( 'INSERT INTO `*PREFIX*calendar_calendars` (`userid`,`displayname`,`uri`,`ctag`,`calendarorder`,`calendarcolor`,`timezone`,`components`) VALUES(?,?,?,?,?,?,?,?)' ); + $result = $stmt->execute(array($userid,$name,$uri,1,$order,$color,$timezone,$components)); - $id = self::addCalendar($userid, 'Default calendar'); + $insertid = OCP\DB::insertid('*PREFIX*calendar_calendars'); + OCP\Util::emitHook('OC_Calendar', 'addCalendar', $insertid); - return true; - } + return $insertid; + } - /** - * @brief Creates a new calendar from the data sabredav provides - * @param string $principaluri - * @param string $uri - * @param string $name - * @param string $components - * @param string $timezone - * @param integer $order - * @param string $color format: '#RRGGBB(AA)' - * @return insertid - */ - public static function addCalendarFromDAVData($principaluri, $uri, $name, $components, $timezone, $order, $color) { - $userid = self::extractUserID($principaluri); + /** + * @brief Edits a calendar + * @param integer $id + * @param string $name Default: null + * @param string $components Default: null + * @param string $timezone Default: null + * @param integer $order Default: null + * @param string $color Default: null, format: '#RRGGBB(AA)' + * @return boolean + * + * Values not null will be set + */ + public static function editCalendar($id,$name=null,$components=null,$timezone=null,$order=null,$color=null) { + // Need these ones for checking uri + $calendar = self::find($id); + if ($calendar['userid'] != OCP\User::getUser() && !OC_Group::inGroup(OCP\User::getUser(), 'admin')) { + $sharedCalendar = OCP\Share::getItemSharedWithBySource('calendar', $id); + if (!$sharedCalendar || !($sharedCalendar['permissions'] & OCP\PERMISSION_UPDATE)) { + throw new Exception( + OC_Calendar_App::$l10n->t( + 'You do not have the permissions to update this calendar.' + ) + ); + } + } - $stmt = OCP\DB::prepare('INSERT INTO `*PREFIX*calendar_calendars` (`userid`,`displayname`,`uri`,`ctag`,`calendarorder`,`calendarcolor`,`timezone`,`components`) VALUES(?,?,?,?,?,?,?,?)'); - $result = $stmt->execute(array($userid, $name, $uri, 1, $order, $color, $timezone, $components)); + // Keep old stuff + if(is_null($name)) $name = $calendar['displayname']; + if(is_null($components)) $components = $calendar['components']; + if(is_null($timezone)) $timezone = $calendar['timezone']; + if(is_null($order)) $order = $calendar['calendarorder']; + if(is_null($color)) $color = $calendar['calendarcolor']; - $insertid = OCP\DB::insertid('*PREFIX*calendar_calendars'); - OCP\Util::emitHook('OC_Calendar', 'addCalendar', $insertid); + $stmt = OCP\DB::prepare( 'UPDATE `*PREFIX*calendar_calendars` SET `displayname`=?,`calendarorder`=?,`calendarcolor`=?,`timezone`=?,`components`=?,`ctag`=`ctag`+1 WHERE `id`=?' ); + $result = $stmt->execute(array($name,$order,$color,$timezone,$components,$id)); - return $insertid; - } + OCP\Util::emitHook('OC_Calendar', 'editCalendar', $id); + return true; + } - /** - * @brief Edits a calendar - * @param integer $id - * @param string $name Default: null - * @param string $components Default: null - * @param string $timezone Default: null - * @param integer $order Default: null - * @param string $color Default: null, format: '#RRGGBB(AA)' - * @return boolean - * - * Values not null will be set - */ - public static function editCalendar($id, $name = null, $components = null, $timezone = null, $order = null, $color = null) { - // Need these ones for checking uri - $calendar = self::find($id); - if ($calendar['userid'] != OCP\User::getUser() && !OC_Group::inGroup(OCP\User::getUser(), 'admin')) { - $sharedCalendar = OCP\Share::getItemSharedWithBySource('calendar', $id); - if (!$sharedCalendar || !($sharedCalendar['permissions'] & OCP\PERMISSION_UPDATE)) { - throw new Exception( - OC_Calendar_App::$l10n->t( - 'You do not have the permissions to update this calendar.' - ) - ); - } - } + /** + * @brief Sets a calendar (in)active + * @param integer $id + * @param boolean $active + * @return boolean + */ + public static function setCalendarActive($id,$active) { + $calendar = self::find($id); + if ($calendar['userid'] != OCP\User::getUser()) { + $sharedCalendar = OCP\Share::getItemSharedWithBySource('calendar', $id); + if (!$sharedCalendar || !($sharedCalendar['permissions'] & OCP\PERMISSION_UPDATE)) { + throw new Exception( + OC_Calendar_App::$l10n->t( + 'You do not have the permissions to update this calendar.' + ) + ); + } + } + $stmt = OCP\DB::prepare( 'UPDATE `*PREFIX*calendar_calendars` SET `active` = ? WHERE `id` = ?' ); + $stmt->execute(array((int)$active, $id)); - // Keep old stuff - if (is_null($name)) - $name = $calendar['displayname']; - if (is_null($components)) - $components = $calendar['components']; - if (is_null($timezone)) - $timezone = $calendar['timezone']; - if (is_null($order)) - $order = $calendar['calendarorder']; - if (is_null($color)) - $color = $calendar['calendarcolor']; + return true; + } - $stmt = OCP\DB::prepare('UPDATE `*PREFIX*calendar_calendars` SET `displayname`=?,`calendarorder`=?,`calendarcolor`=?,`timezone`=?,`components`=?,`ctag`=`ctag`+1 WHERE `id`=?'); - $result = $stmt->execute(array($name, $order, $color, $timezone, $components, $id)); + /** + * @brief Updates ctag for calendar + * @param integer $id + * @return boolean + */ + public static function touchCalendar($id) { + $stmt = OCP\DB::prepare( 'UPDATE `*PREFIX*calendar_calendars` SET `ctag` = `ctag` + 1 WHERE `id` = ?' ); + $stmt->execute(array($id)); - OCP\Util::emitHook('OC_Calendar', 'editCalendar', $id); - return true; - } + return true; + } - /** - * @brief Sets a calendar (in)active - * @param integer $id - * @param boolean $active - * @return boolean - */ - public static function setCalendarActive($id, $active) { - $calendar = self::find($id); - if ($calendar['userid'] != OCP\User::getUser()) { - $sharedCalendar = OCP\Share::getItemSharedWithBySource('calendar', $id); - if (!$sharedCalendar || !($sharedCalendar['permissions'] & OCP\PERMISSION_UPDATE)) { - throw new Exception( - OC_Calendar_App::$l10n->t( - 'You do not have the permissions to update this calendar.' - ) - ); - } - } - $stmt = OCP\DB::prepare('UPDATE `*PREFIX*calendar_calendars` SET `active` = ? WHERE `id` = ?'); - $stmt->execute(array((int) $active, $id)); + /** + * @brief removes a calendar + * @param integer $id + * @return boolean + */ + public static function deleteCalendar($id) { + $calendar = self::find($id); + if ($calendar['userid'] != OCP\User::getUser() && !OC_Group::inGroup(OCP\User::getUser(), 'admin')) { + $sharedCalendar = OCP\Share::getItemSharedWithBySource('calendar', $id); + if (!$sharedCalendar || !($sharedCalendar['permissions'] & OCP\PERMISSION_DELETE)) { + throw new Exception( + OC_Calendar_App::$l10n->t( + 'You do not have the permissions to delete this calendar.' + ) + ); + } + } + $stmt = OCP\DB::prepare( 'DELETE FROM `*PREFIX*calendar_calendars` WHERE `id` = ?' ); + $stmt->execute(array($id)); - return true; - } + $stmt = OCP\DB::prepare( 'DELETE FROM `*PREFIX*calendar_objects` WHERE `calendarid` = ?' ); + $stmt->execute(array($id)); - /** - * @brief Updates ctag for calendar - * @param integer $id - * @return boolean - */ - public static function touchCalendar($id) { - $stmt = OCP\DB::prepare('UPDATE `*PREFIX*calendar_calendars` SET `ctag` = `ctag` + 1 WHERE `id` = ?'); - $stmt->execute(array($id)); + OCP\Share::unshareAll('calendar', $id); - return true; - } + OCP\Util::emitHook('OC_Calendar', 'deleteCalendar', $id); + if(OCP\USER::isLoggedIn() and count(self::allCalendars(OCP\USER::getUser())) == 0) { + self::addDefaultCalendars(OCP\USER::getUser()); + } - /** - * @brief removes a calendar - * @param integer $id - * @return boolean - */ - public static function deleteCalendar($id) { - $calendar = self::find($id); - if ($calendar['userid'] != OCP\User::getUser() && !OC_Group::inGroup(OCP\User::getUser(), 'admin')) { - $sharedCalendar = OCP\Share::getItemSharedWithBySource('calendar', $id); - if (!$sharedCalendar || !($sharedCalendar['permissions'] & OCP\PERMISSION_DELETE)) { - throw new Exception( - OC_Calendar_App::$l10n->t( - 'You do not have the permissions to delete this calendar.' - ) - ); - } - } - $stmt = OCP\DB::prepare('DELETE FROM `*PREFIX*calendar_calendars` WHERE `id` = ?'); - $stmt->execute(array($id)); + return true; + } - $stmt = OCP\DB::prepare('DELETE FROM `*PREFIX*calendar_objects` WHERE `calendarid` = ?'); - $stmt->execute(array($id)); + /** + * @brief merges two calendars + * @param integer $id1 + * @param integer $id2 + * @return boolean + */ + public static function mergeCalendar($id1, $id2) { + $calendar = self::find($id1); + if ($calendar['userid'] != OCP\User::getUser() && !OC_Group::inGroup(OCP\User::getUser(), 'admin')) { + $sharedCalendar = OCP\Share::getItemSharedWithBySource('calendar', $id1); + if (!$sharedCalendar || !($sharedCalendar['permissions'] & OCP\PERMISSION_UPDATE)) { + throw new Exception( + OC_Calendar_App::$l10n->t( + 'You do not have the permissions to add to this calendar.' + ) + ); + } + } + $stmt = OCP\DB::prepare('UPDATE `*PREFIX*calendar_objects` SET `calendarid` = ? WHERE `calendarid` = ?'); + $stmt->execute(array($id1, $id2)); + self::touchCalendar($id1); + self::deleteCalendar($id2); + } - OCP\Share::unshareAll('calendar', $id); + /** + * @brief Creates a URI for Calendar + * @param string $name name of the calendar + * @param array $existing existing calendar URIs + * @return string uri + */ + public static function createURI($name,$existing) { + $strip=array(' ','/','?','&');//these may break sync clients + $name=str_replace($strip,'',$name); + $name = strtolower($name); - OCP\Util::emitHook('OC_Calendar', 'deleteCalendar', $id); - if (OCP\USER::isLoggedIn() and count(self::allCalendars(OCP\USER::getUser())) == 0) { - self::addDefaultCalendars(OCP\USER::getUser()); - } + $newname = $name; + $i = 1; + while(in_array($newname,$existing)) { + $newname = $name.$i; + $i = $i + 1; + } + return $newname; + } - return true; - } + /** + * @brief gets the userid from a principal path + * @return string + */ + public static function extractUserID($principaluri) { + list($prefix,$userid) = Sabre_DAV_URLUtil::splitPath($principaluri); + return $userid; + } - /** - * @brief merges two calendars - * @param integer $id1 - * @param integer $id2 - * @return boolean - */ - public static function mergeCalendar($id1, $id2) { - $calendar = self::find($id1); - if ($calendar['userid'] != OCP\User::getUser() && !OC_Group::inGroup(OCP\User::getUser(), 'admin')) { - $sharedCalendar = OCP\Share::getItemSharedWithBySource('calendar', $id1); - if (!$sharedCalendar || !($sharedCalendar['permissions'] & OCP\PERMISSION_UPDATE)) { - throw new Exception( - OC_Calendar_App::$l10n->t( - 'You do not have the permissions to add to this calendar.' - ) - ); - } - } - $stmt = OCP\DB::prepare('UPDATE `*PREFIX*calendar_objects` SET `calendarid` = ? WHERE `calendarid` = ?'); - $stmt->execute(array($id1, $id2)); - self::touchCalendar($id1); - self::deleteCalendar($id2); - } + /** + * @brief returns the possible color for calendars + * @return array + */ + public static function getCalendarColorOptions() { + return array( + '#ff0000', // "Red" + '#b3dc6c', // "Green" + '#ffff00', // "Yellow" + '#808000', // "Olive" + '#ffa500', // "Orange" + '#ff7f50', // "Coral" + '#ee82ee', // "Violet" + '#9fc6e7', // "light blue" + ); + } - /** - * @brief Creates a URI for Calendar - * @param string $name name of the calendar - * @param array $existing existing calendar URIs - * @return string uri - */ - public static function createURI($name, $existing) { - $strip = array(' ', '/', '?', '&'); //these may break sync clients - $name = str_replace($strip, '', $name); - $name = strtolower($name); + /** + * @brief generates the Event Source Info for our JS + * @param array $calendar calendar data + * @return array + */ + public static function getEventSourceInfo($calendar) { + return array( + 'url' => OCP\Util::linkTo('calendar', 'ajax/events.php').'?calendar_id='.$calendar['id'], + 'backgroundColor' => $calendar['calendarcolor'], + 'borderColor' => '#888', + 'textColor' => self::generateTextColor($calendar['calendarcolor']), + 'cache' => true, + ); + } - $newname = $name; - $i = 1; - while (in_array($newname, $existing)) { - $newname = $name . $i; - $i = $i + 1; - } - return $newname; - } + /* + * @brief checks if a calendar name is available for a user + * @param string $calendarname + * @param string $userid + * @return boolean + */ + public static function isCalendarNameavailable($calendarname, $userid) { + $calendars = self::allCalendars($userid); + foreach($calendars as $calendar) { + if($calendar['displayname'] == $calendarname) { + return false; + } + } + return true; + } - /** - * @brief gets the userid from a principal path - * @return string - */ - public static function extractUserID($principaluri) { - list($prefix, $userid) = Sabre_DAV_URLUtil::splitPath($principaluri); - return $userid; - } - - /** - * @brief returns the possible color for calendars - * @return array - */ - public static function getCalendarColorOptions() { - return array( - '#ff0000', // "Red" - '#b3dc6c', // "Green" - '#ffff00', // "Yellow" - '#808000', // "Olive" - '#ffa500', // "Orange" - '#ff7f50', // "Coral" - '#ee82ee', // "Violet" - '#9fc6e7', // "light blue" - ); - } - - /** - * @brief generates the Event Source Info for our JS - * @param array $calendar calendar data - * @return array - */ - public static function getEventSourceInfo($calendar) { - return array( - 'url' => OCP\Util::linkTo('calendar', 'ajax/events.php') . '?calendar_id=' . $calendar['id'], - 'backgroundColor' => $calendar['calendarcolor'], - 'borderColor' => '#888', - 'textColor' => self::generateTextColor($calendar['calendarcolor']), - 'cache' => true, - ); - } - - /* - * @brief checks if a calendar name is available for a user - * @param string $calendarname - * @param string $userid - * @return boolean - */ - - public static function isCalendarNameavailable($calendarname, $userid) { - $calendars = self::allCalendars($userid); - foreach ($calendars as $calendar) { - if ($calendar['displayname'] == $calendarname) { - return false; - } - } - return true; - } - - /* - * @brief generates the text color for the calendar - * @param string $calendarcolor rgb calendar color code in hex format (with or without the leading #) - * (this function doesn't pay attention on the alpha value of rgba color codes) - * @return boolean - */ - - public static function generateTextColor($calendarcolor) { - if (substr_count($calendarcolor, '#') == 1) { - $calendarcolor = substr($calendarcolor, 1); - } - $red = hexdec(substr($calendarcolor, 0, 2)); - $green = hexdec(substr($calendarcolor, 2, 2)); - $blue = hexdec(substr($calendarcolor, 4, 2)); - //recommendation by W3C - $computation = ((($red * 299) + ($green * 587) + ($blue * 114)) / 1000); - return ($computation > 130) ? '#000000' : '#FAFAFA'; - } - -} + /* + * @brief generates the text color for the calendar + * @param string $calendarcolor rgb calendar color code in hex format (with or without the leading #) + * (this function doesn't pay attention on the alpha value of rgba color codes) + * @return boolean + */ + public static function generateTextColor($calendarcolor) { + if(substr_count($calendarcolor, '#') == 1) { + $calendarcolor = substr($calendarcolor,1); + } + $red = hexdec(substr($calendarcolor,0,2)); + $green = hexdec(substr($calendarcolor,2,2)); + $blue = hexdec(substr($calendarcolor,4,2)); + //recommendation by W3C + $computation = ((($red * 299) + ($green * 587) + ($blue * 114)) / 1000); + return ($computation > 130)?'#000000':'#FAFAFA'; + } +} \ No newline at end of file From 5b144f767c9e1409290e68c65c5569d3e443ab1c Mon Sep 17 00:00:00 2001 From: visithaWB Date: Thu, 18 Apr 2013 13:51:54 +0530 Subject: [PATCH 15/17] getUsersEmails function is added again --- lib/calendar.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/calendar.php b/lib/calendar.php index 16615984..1b40b8eb 100644 --- a/lib/calendar.php +++ b/lib/calendar.php @@ -382,4 +382,20 @@ class OC_Calendar_Calendar{ $computation = ((($red * 299) + ($green * 587) + ($blue * 114)) / 1000); return ($computation > 130)?'#000000':'#FAFAFA'; } -} \ No newline at end of file + + /** + * @brief Get the email address of a user + * @returns the email address of the user + * + * This method returns the email address of selected user. + */ + public function getUsersEmails($names) { + $emails = array(); + $query = OC_DB::prepare('SELECT `email` FROM `*PREFIX*users` WHERE LOWER(`uid`) = LOWER(?)'); + $result = $query->execute(array($names)); + $row = $result->fetchRow(); + $emails[] = $row['email']; + + return $row['email']; + } +} From be8c75b043fae9d8a9b18679c16a48fc15e0e97e Mon Sep 17 00:00:00 2001 From: visithaWB Date: Thu, 18 Apr 2013 13:54:40 +0530 Subject: [PATCH 16/17] Replaced by Original file --- calendar.php | 1 - 1 file changed, 1 deletion(-) diff --git a/calendar.php b/calendar.php index caff0d08..0be2566f 100644 --- a/calendar.php +++ b/calendar.php @@ -7,7 +7,6 @@ */ $l10n = OC_L10N::get('calendar'); OCP\JSON::checkLoggedIn(); -OCP\JSON::checkLogged(); OCP\JSON::checkAppEnabled('calendar'); $tmpl = new OCP\Template('calendar', 'part.choosecalendar'); $tmpl->printpage(); From 3ae0cc0a295eda214d86994a4c874994c876fe1e Mon Sep 17 00:00:00 2001 From: visithaWB Date: Wed, 1 May 2013 16:50:52 +0530 Subject: [PATCH 17/17] HTML code is improved --- lib/app.php | 26 ++++++++++++-------------- lib/calendar.php | 0 2 files changed, 12 insertions(+), 14 deletions(-) mode change 100644 => 100755 lib/app.php mode change 100644 => 100755 lib/calendar.php diff --git a/lib/app.php b/lib/app.php old mode 100644 new mode 100755 index 8b665c4c..b3868051 --- a/lib/app.php +++ b/lib/app.php @@ -514,7 +514,7 @@ class OC_Calendar_App{ */ public static function sendEmails($eventid, $location, $description, $dtstart, $dtend) { - $user = OC_User::getUser(); + $user = \OCP\User::getUser(); $eventsharees = array(); $eventShareesNames = array(); $emails = array(); @@ -535,21 +535,19 @@ class OC_Calendar_App{ } $useremail = OC_Calendar_Calendar::getUsersEmails($user); foreach ($emails as $email) { - $subject = "Calendar Event Shared..!!"; - $headers = "MIME-Version: 1.0\r\n"; + $subject = 'Calendar Event Shared'; + + $headers = 'MIME-Version: 1.0\r\n'; + $headers .= 'Content-Type: text/html; charset=utf-8\r\n'; + $headers .= 'From:' . $useremail; - $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; - - $headers .= "From:" . $useremail; - - $message = ''; - //$message .= 'Website Change Request'; + $message = ''; $message .= ''; - $message .= ""; - $message .= ""; - $message .= ""; - $message .= "
" . $user . " has shared with you an event
Location: " . $location . "
Description: " . $description . "
"; - $message .= ""; + $message .= "" . $user . ' has shared with you an event'; + $message .= 'Location: ' . $location . ''; + $message .= 'Description: ' . $description . ''; + $message .= ''; + $message .= ''; OC_Mail::send($email, "User", $subject, $message, $useremail, $user, $html = 1, $altbody = '', $ccaddress = '', $ccname = '', $bcc = ''); } diff --git a/lib/calendar.php b/lib/calendar.php old mode 100644 new mode 100755