diff --git a/ajax/event/sendmail.php b/ajax/event/sendmail.php new file mode 100644 index 00000000..c6c0a0b1 --- /dev/null +++ b/ajax/event/sendmail.php @@ -0,0 +1,28 @@ + + * 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_App::sendEmails($eventId, $location, $description, $dtstart, $dtend); +} catch(Exception $e) { + OCP\JSON::error(array('data' => array('message'=>$e->getMessage()))); + exit; +} + +OCP\JSON::success(); diff --git a/calendar.php b/calendar.php index 9832a56b..a7bd0472 100644 --- a/calendar.php +++ b/calendar.php @@ -9,4 +9,4 @@ $l10n = OCP\Util::getL10N('calendar'); OCP\JSON::checkLoggedIn(); OCP\JSON::checkAppEnabled('calendar'); $tmpl = new OCP\Template('calendar', 'part.choosecalendar'); -$tmpl->printpage(); \ No newline at end of file +$tmpl->printpage(); diff --git a/js/calendar.js b/js/calendar.js index c68c0cb4..e2c516b4 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(':'); diff --git a/lib/app.php b/lib/app.php old mode 100644 new mode 100755 index 660f6f0c..0782e25e --- a/lib/app.php +++ b/lib/app.php @@ -511,4 +511,54 @@ class OC_Calendar_App{ \OCP\Util::writeLog('calendar', 'Event (' . $uid . ') contains invalid data!',\OCP\Util::WARN); } } + + /** + * @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 = \OCP\User::getUser(); + $eventsharees = array(); + $eventShareesNames = array(); + $emails = array(); + $sharedwithByEvent = OCP\Share::getItemShared('event', $eventid); + if (is_array($sharedwithByEvent)) { + foreach ($sharedwithByEvent as $share) { + if ($share['share_type'] == OCP\Share::SHARE_TYPE_USER || $share['share_type'] == OCP\Share::SHARE_TYPE_GROUP) { + $eventsharees[] = $share; + } + } + foreach ($eventsharees as $sharee) { + $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=utf-8\r\n'; + $headers .= 'From:' . $useremail; + + $message = '
'; + $message .= '" . $user . ' has shared with you an event | |
Location: | ' . $location . ' |
Description: | ' . $description . ' |