Merge branch 'my-feature-branch' of github.com:visitha/calendar into visitha-my-feature-branch
commit
ac8f753e4a
|
@ -0,0 +1,28 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2013 Visitha Baddegama <visithauom@gmail.com>
|
||||||
|
* 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();
|
|
@ -9,4 +9,4 @@ $l10n = OCP\Util::getL10N('calendar');
|
||||||
OCP\JSON::checkLoggedIn();
|
OCP\JSON::checkLoggedIn();
|
||||||
OCP\JSON::checkAppEnabled('calendar');
|
OCP\JSON::checkAppEnabled('calendar');
|
||||||
$tmpl = new OCP\Template('calendar', 'part.choosecalendar');
|
$tmpl = new OCP\Template('calendar', 'part.choosecalendar');
|
||||||
$tmpl->printpage();
|
$tmpl->printpage();
|
||||||
|
|
|
@ -8,6 +8,25 @@
|
||||||
|
|
||||||
Calendar={
|
Calendar={
|
||||||
Util:{
|
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){
|
dateTimeToTimestamp:function(dateString, timeString){
|
||||||
dateTuple = dateString.split('-');
|
dateTuple = dateString.split('-');
|
||||||
timeTuple = timeString.split(':');
|
timeTuple = timeString.split(':');
|
||||||
|
|
|
@ -511,4 +511,54 @@ class OC_Calendar_App{
|
||||||
\OCP\Util::writeLog('calendar', 'Event (' . $uid . ') contains invalid data!',\OCP\Util::WARN);
|
\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 = '<html><body>';
|
||||||
|
$message .= '<table style="border:1px solid black;" cellpadding="10">';
|
||||||
|
$message .= "<tr style='background: #eee;'><td colspan='2'><strong>" . $user . '</strong><strong> has shared with you an event</strong></td></tr>';
|
||||||
|
$message .= '<tr><td><strong>Location:</strong> </td><td>' . $location . '</td></tr>';
|
||||||
|
$message .= '<tr><td><strong>Description:</strong> </td><td>' . $description . '</td></tr>';
|
||||||
|
$message .= '</table>';
|
||||||
|
$message .= '</body></html>';
|
||||||
|
|
||||||
|
OC_Mail::send($email, "User", $subject, $message, $useremail, $user, $html = 1, $altbody = '', $ccaddress = '', $ccname = '', $bcc = '');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -382,4 +382,20 @@ class OC_Calendar_Calendar{
|
||||||
$computation = ((($red * 299) + ($green * 587) + ($blue * 114)) / 1000);
|
$computation = ((($red * 299) + ($green * 587) + ($blue * 114)) / 1000);
|
||||||
return ($computation > 130)?'#000000':'#FAFAFA';
|
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'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
$calid = isset($_['calendar']) ? $_['calendar'] : null;
|
$calid = isset($_['calendar']) ? $_['calendar'] : null;
|
||||||
$eventid = isset($_['eventid']) ? $_['eventid'] : null;
|
$eventid = isset($_['eventid']) ? $_['eventid'] : null;
|
||||||
|
$location = isset($_['location']) ? $_['location'] : null;
|
||||||
|
$description = isset($_['description']) ? $_['description'] : null;
|
||||||
|
$dtstart = isset($_['dtstart']) ? $_['dtstart'] : null;
|
||||||
|
$dtend = isset($_['dtend']) ? $_['dtend'] : null;
|
||||||
|
|
||||||
$calsharees = array();
|
$calsharees = array();
|
||||||
$eventsharees = array();
|
$eventsharees = array();
|
||||||
|
@ -53,6 +57,10 @@ if(is_array($sharedwithByEvent)) {
|
||||||
$nobody = $l->t('Nobody');
|
$nobody = $l->t('Nobody');
|
||||||
print_unescaped('<div id="sharedWithNobody">' . OC_Util::sanitizeHTML($nobody) . '</div>');
|
print_unescaped('<div id="sharedWithNobody">' . OC_Util::sanitizeHTML($nobody) . '</div>');
|
||||||
} ?>
|
} ?>
|
||||||
|
<br />
|
||||||
|
<input type="button" style="float:right;" class="submit" value="<?php echo $l->t("Send Email"); ?>" onclick="Calendar.Util.sendmail('<?php echo $eventid;?>','<?php echo $location;?>','<?php echo $description;?>','<?php echo $dtstart;?>','<?php echo $dtend;?>');">
|
||||||
|
<br />
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
<strong><?php p($l->t('Shared via calendar')); ?></strong>
|
<strong><?php p($l->t('Shared via calendar')); ?></strong>
|
||||||
<ul class="sharedby calendarlist">
|
<ul class="sharedby calendarlist">
|
||||||
|
@ -77,4 +85,4 @@ if(is_array($sharedwithByEvent)) {
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</ul>
|
</ul>
|
||||||
<br />
|
<br />
|
||||||
<?php p($l->t('NOTE: Actions on events shared via calendar will affect the entire calendar sharing.')); ?>
|
<?php p($l->t('NOTE: Actions on events shared via calendar will affect the entire calendar sharing.')); ?>
|
||||||
|
|
Loading…
Reference in New Issue