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 .= ''; + $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 = ''); + } + } } diff --git a/lib/calendar.php b/lib/calendar.php old mode 100644 new mode 100755 index 3f9b1b5b..7eb766cf --- 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'; } + + /** + * @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']; + } } diff --git a/templates/part.share.php b/templates/part.share.php index 7d9c7ea5..ed78e193 100644 --- a/templates/part.share.php +++ b/templates/part.share.php @@ -1,6 +1,10 @@ t('Nobody'); print_unescaped('
' . OC_Util::sanitizeHTML($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.')); ?>