Testing swiftmail

skala
Julio Montoya 12 years ago
parent 1df17c8abd
commit c945e31be1
  1. 38
      main/inc/global.inc.php
  2. 201
      main/inc/lib/mail.lib.inc.php
  3. 216
      main/inc/lib/main_api.lib.php
  4. 9
      main/inc/lib/message.lib.php
  5. 146
      main/inc/lib/notification.lib.php
  6. 4
      main/messages/new_message.php

@ -211,41 +211,16 @@ $app->register(new Silex\Provider\DoctrineServiceProvider(), array(
)
));
$app->register(new Silex\Provider\SwiftmailerServiceProvider());
$app->register(new DoctrineOrmServiceProvider, array(
"orm.proxies_dir" => $app['db.orm.proxies_dir'],
"orm.em.options" => array(
"mappings" => array(
// Using actual filesystem paths
/*array(
"type" => "annotation",
"namespace" => "Foo\Entities",
"path" => __DIR__."/src/Foo/Entities",
),*/
/*array(
"type" => "xml",
"namespace" => "Bat\Entities",
"path" => __DIR__."/src/Bat/Resources/mappings",
),*/
array(
"type" => "annotation",
"namespace" => "Entity",
"path" => api_get_path(INCLUDE_PATH).'Entity',
)
// Using PSR-0 namespaceish embedded resources
// (requires registering a PSR-0 Resource Locator
// Service Provider)
/*array(
"type" => "annotations",
"namespace" => "Baz\Entities",
"resources_namespace" => "Baz\Entities",
),
array(
"type" => "xml",
"namespace" => "Bar\Entities",
"resources_namespace" => "Bar\Resources\mappings",
),*/
),
),
));
@ -358,7 +333,7 @@ $app['default_layout'] = 'layout_1_col.tpl';
require_once $lib_path.'database.constants.inc.php';
//@todo use swift mail
require_once $lib_path.'mail.lib.inc.php';
//require_once $lib_path.'mail.lib.inc.php';
require_once $lib_path.'fileManage.lib.php';
require_once $lib_path.'text.lib.php';
@ -492,7 +467,16 @@ if (file_exists($mail_conf)) {
require_once $mail_conf;
}
// ===== "who is logged in?" module section =====
$app->register(new Silex\Provider\SwiftmailerServiceProvider(), array(
'swiftmailer.options' => array(
'host' => $platform_email['SMTP_HOST'],
'port' => $platform_email['SMTP_PORT'],
'username' => $platform_email['SMTP_USER'],
'password' => $platform_email['SMTP_PASS'],
'encryption' => null,
'auth_mode' => null
),
));
// check and modify the date of user in the track.e.online table
if (!$x = strpos($_SERVER['PHP_SELF'], 'whoisonline.php')) {

@ -14,204 +14,3 @@ require_once api_get_path(LIBRARY_PATH).'phpmailer/class.phpmailer.php';
// It should actually be revised for using the complete RFC3696 description:
// http://tools.ietf.org/html/rfc3696#section-3
//$regexp_rfc3696 = "^[0-9a-z_\.+-]+@(([0-9]{1,3}\.){3}[0-9]{1,3}|([0-9a-z][0-9a-z-]*[0-9a-z]\.)+[a-z]{2,3})$"; // Deprecated, 13-OCT-2010.
/**
* Sends email using the phpmailer class
* Sender name and email can be specified, if not specified
* name and email of the platform admin are used
*
* @author Bert Vanderkimpen ICT&O UGent
*
* @param recipient_name name of recipient
* @param recipient_email email of recipient
* @param message email body
* @param subject email subject
* @return returns true if mail was sent
* @see class.phpmailer.php
* @deprecated use api_mail_html()
*/
function api_mail($recipient_name, $recipient_email, $subject, $message, $sender_name = '', $sender_email = '', $extra_headers = '') {
api_mail_html($recipient_name, $recipient_email, $subject, $message, $sender_name, $sender_email, $extra_headers);
}
/**
* Sends an HTML email using the phpmailer class (and multipart/alternative to downgrade gracefully)
* Sender name and email can be specified, if not specified
* name and email of the platform admin are used
*
* @author Bert Vanderkimpen ICT&O UGent
* @author Yannick Warnier <yannick.warnier@beeznest.com>
*
* @param string name of recipient
* @param string email of recipient
* @param string email subject
* @param string email body
* @param string sender name
* @param string sender e-mail
* @param array extra headers in form $headers = array($name => $value) to allow parsing
* @param array data file (path and filename)
* @param array data to attach a file (optional)
* @param bool True for attaching a embedded file inside content html (optional)
* @return returns true if mail was sent
* @see class.phpmailer.php
*/
function api_mail_html($recipient_name, $recipient_email, $subject, $message, $sender_name = '', $sender_email = '', $extra_headers = null, $data_file = array(), $embedded_image = false) {
global $platform_email;
$mail = new PHPMailer();
$mail->Mailer = $platform_email['SMTP_MAILER'];
$mail->Host = $platform_email['SMTP_HOST'];
$mail->Port = $platform_email['SMTP_PORT'];
$mail->CharSet = $platform_email['SMTP_CHARSET'];
$mail->WordWrap = 200; // Stay far below SMTP protocol 980 chars limit.
if ($platform_email['SMTP_AUTH']) {
$mail->SMTPAuth = 1;
$mail->Username = $platform_email['SMTP_USER'];
$mail->Password = $platform_email['SMTP_PASS'];
}
$mail->Priority = 3; // 5 = low, 1 = high
$mail->AddCustomHeader('Errors-To: '.$platform_email['SMTP_FROM_EMAIL']);
$mail->SMTPKeepAlive = true;
if (($sender_email != '') && ($sender_name != '')) {
$mail->AddReplyTo($sender_email, $sender_name);
}
if (isset($extra_headers['reply_to'])) {
$mail->AddReplyTo($extra_headers['reply_to']['mail'], $extra_headers['reply_to']['name']);
}
// Attachments
// $mail->AddAttachment($path);
// $mail->AddAttachment($path, $filename);
if ($sender_email != '') {
$mail->From = $sender_email;
$mail->Sender = $sender_email;
//$mail->ConfirmReadingTo = $sender_email; // Disposition-Notification
} else {
$mail->From = $platform_email['SMTP_FROM_EMAIL'];
$mail->Sender = $platform_email['SMTP_FROM_EMAIL'];
//$mail->ConfirmReadingTo = $platform_email['SMTP_FROM_EMAIL']; // Disposition-Notification
}
if ($sender_name != '') {
$mail->FromName = $sender_name;
} else {
$mail->FromName = $platform_email['SMTP_FROM_NAME'];
}
$mail->Subject = $subject;
$mail->AltBody = strip_tags(str_replace('<br />',"\n", api_html_entity_decode($message)));
// Send embedded image.
if ($embedded_image) {
// Get all images html inside content.
preg_match_all("/<img\s+.*?src=[\"\']?([^\"\' >]*)[\"\']?[^>]*>/i", $message, $m);
// Prepare new tag images.
$new_images_html = array();
$i = 1;
if (!empty($m[1])) {
foreach ($m[1] as $image_path) {
$real_path = realpath($image_path);
$filename = basename($image_path);
$image_cid = $filename.'_'.$i;
$encoding = 'base64';
$image_type = mime_content_type($real_path);
$mail->AddEmbeddedImage($real_path, $image_cid, $filename, $encoding, $image_type);
$new_images_html[] = '<img src="cid:'.$image_cid.'" />';
$i++;
}
}
// Replace origin image for new embedded image html.
$x = 0;
if (!empty($m[0])) {
foreach ($m[0] as $orig_img) {
$message = str_replace($orig_img, $new_images_html[$x], $message);
$x++;
}
}
}
$message = str_replace(array("\n\r", "\n", "\r"), '<br />', $message);
$mail->Body = '<html><head></head><body>'.$message.'</body></html>';
// Attachment ...
if (!empty($data_file)) {
$mail->AddAttachment($data_file['path'], $data_file['filename']);
}
// Only valid addresses are accepted.
if (is_array($recipient_email)) {
foreach ($recipient_email as $dest) {
if (api_valid_email($dest)) {
$mail->AddAddress($dest, $recipient_name);
//$mail->AddAddress($dest, ($i > 1 ? '' : $recipient_name));
}
}
} else {
if (api_valid_email($recipient_email)) {
$mail->AddAddress($recipient_email, $recipient_name);
} else {
return 0;
}
}
if (is_array($extra_headers) && count($extra_headers) > 0) {
foreach ($extra_headers as $key => $value) {
switch (strtolower($key)) {
case 'reply-to':
//the value here is the result of api_get_user_info()
$sender_email = $value['email'];
$sender_name = $value['complete_name'];
$mail->AddReplyTo($sender_email, $sender_name);
break;
case 'encoding':
case 'content-transfer-encoding':
$mail->Encoding = $value;
break;
case 'charset':
$mail->Charset = $value;
break;
case 'contenttype':
case 'content-type':
$mail->ContentType = $value;
break;
default:
$mail->AddCustomHeader($key.':'.$value);
break;
}
}
} else {
if (!empty($extra_headers)) {
$mail->AddCustomHeader($extra_headers);
}
}
// WordWrap the html body (phpMailer only fixes AltBody) FS#2988
$mail->Body = $mail->WrapText($mail->Body, $mail->WordWrap);
// Send the mail message.
if (!$mail->Send()) {
//echo 'ERROR: mail not sent to '.$recipient_name.' ('.$recipient_email.') because of '.$mail->ErrorInfo.'<br />';
error_log('ERROR: mail not sent to '.$recipient_name.' ('.$recipient_email.') because of '.$mail->ErrorInfo.'<br />');
return 0;
}
// Clear all the addresses.
$mail->ClearAddresses();
/*
$body = $message;
$message = \Swift_Message::newInstance()
->setSubject('[YourSite] Feedback')
->setFrom(array($sender_email , $sender_name))
->setTo(array($recipient_email => $recipient_name))
->setBody($body);
global $app;
$app['mailer']->send($message);*/
return 1;
}

@ -6567,4 +6567,220 @@ function api_set_settings_and_plugins() {
function api_set_setting_last_update() {
//Saving latest refresh
api_set_setting('settings_latest_update', api_get_utc_datetime());
}
/**
* Sends email using the phpmailer class
* Sender name and email can be specified, if not specified
* name and email of the platform admin are used
*
* @author Bert Vanderkimpen ICT&O UGent
*
* @param recipient_name name of recipient
* @param recipient_email email of recipient
* @param message email body
* @param subject email subject
* @return returns true if mail was sent
* @see class.phpmailer.php
* @deprecated use api_mail_html()
*/
function api_mail($recipient_name, $recipient_email, $subject, $message, $sender_name = '', $sender_email = '', $extra_headers = '') {
api_mail_html($recipient_name, $recipient_email, $subject, $message, $sender_name, $sender_email, $extra_headers);
}
/**
* Sends an HTML email using the phpmailer class (and multipart/alternative to downgrade gracefully)
* Sender name and email can be specified, if not specified
* name and email of the platform admin are used
*
* @author Bert Vanderkimpen ICT&O UGent
* @author Yannick Warnier <yannick.warnier@beeznest.com>
*
* @param string name of recipient
* @param string email of recipient
* @param string email subject
* @param string email body
* @param string sender name
* @param string sender e-mail
* @param array extra headers in form $headers = array($name => $value) to allow parsing
* @param array data file (path and filename)
* @param array data to attach a file (optional)
* @param bool True for attaching a embedded file inside content html (optional)
* @return returns true if mail was sent
* @see class.phpmailer.php
*/
function api_mail_html($recipient_name, $recipient_email, $subject, $body, $sender_name = '', $sender_email = '', $extra_headers = null, $data_file = array(), $embedded_image = false) {
global $app;
if (($sender_email != '') && ($sender_name != '')) {
//$mail->AddReplyTo($sender_email, $sender_name);
}
$reply_to_mail = null;
$reply_to_name = null;
if (isset($extra_headers['reply_to'])) {
$reply_to_mail = $extra_headers['reply_to']['mail'];
$reply_to_name = $extra_headers['reply_to']['name'];
}
$message = \Swift_Message::newInstance()
->setSubject($subject)
->setFrom(array($sender_email => $sender_name))
->setTo(array($recipient_email => $recipient_name))
->setReplyTo(array($reply_to_mail => $reply_to_name))
->setBody($body);
$status = $app['mailer']->send($message);
return $status;
$mail = new PHPMailer();
$mail->Mailer = $platform_email['SMTP_MAILER'];
$mail->Host = $platform_email['SMTP_HOST'];
$mail->Port = $platform_email['SMTP_PORT'];
$mail->CharSet = $platform_email['SMTP_CHARSET'];
$mail->WordWrap = 200; // Stay far below SMTP protocol 980 chars limit.
if ($platform_email['SMTP_AUTH']) {
$mail->SMTPAuth = 1;
$mail->Username = $platform_email['SMTP_USER'];
$mail->Password = $platform_email['SMTP_PASS'];
}
$mail->Priority = 3; // 5 = low, 1 = high
$mail->AddCustomHeader('Errors-To: '.$platform_email['SMTP_FROM_EMAIL']);
$mail->SMTPKeepAlive = true;
if (($sender_email != '') && ($sender_name != '')) {
$mail->AddReplyTo($sender_email, $sender_name);
}
if (isset($extra_headers['reply_to'])) {
$mail->AddReplyTo($extra_headers['reply_to']['mail'], $extra_headers['reply_to']['name']);
}
// Attachments
// $mail->AddAttachment($path);
// $mail->AddAttachment($path, $filename);
if ($sender_email != '') {
$mail->From = $sender_email;
$mail->Sender = $sender_email;
//$mail->ConfirmReadingTo = $sender_email; // Disposition-Notification
} else {
$mail->From = $platform_email['SMTP_FROM_EMAIL'];
$mail->Sender = $platform_email['SMTP_FROM_EMAIL'];
//$mail->ConfirmReadingTo = $platform_email['SMTP_FROM_EMAIL']; // Disposition-Notification
}
if ($sender_name != '') {
$mail->FromName = $sender_name;
} else {
$mail->FromName = $platform_email['SMTP_FROM_NAME'];
}
$mail->Subject = $subject;
$mail->AltBody = strip_tags(str_replace('<br />',"\n", api_html_entity_decode($message)));
// Send embedded image.
if ($embedded_image) {
// Get all images html inside content.
preg_match_all("/<img\s+.*?src=[\"\']?([^\"\' >]*)[\"\']?[^>]*>/i", $message, $m);
// Prepare new tag images.
$new_images_html = array();
$i = 1;
if (!empty($m[1])) {
foreach ($m[1] as $image_path) {
$real_path = realpath($image_path);
$filename = basename($image_path);
$image_cid = $filename.'_'.$i;
$encoding = 'base64';
$image_type = mime_content_type($real_path);
$mail->AddEmbeddedImage($real_path, $image_cid, $filename, $encoding, $image_type);
$new_images_html[] = '<img src="cid:'.$image_cid.'" />';
$i++;
}
}
// Replace origin image for new embedded image html.
$x = 0;
if (!empty($m[0])) {
foreach ($m[0] as $orig_img) {
$message = str_replace($orig_img, $new_images_html[$x], $message);
$x++;
}
}
}
$message = str_replace(array("\n\r", "\n", "\r"), '<br />', $message);
$mail->Body = '<html><head></head><body>'.$message.'</body></html>';
// Attachment ...
if (!empty($data_file)) {
$mail->AddAttachment($data_file['path'], $data_file['filename']);
}
// Only valid addresses are accepted.
if (is_array($recipient_email)) {
foreach ($recipient_email as $dest) {
if (api_valid_email($dest)) {
$mail->AddAddress($dest, $recipient_name);
//$mail->AddAddress($dest, ($i > 1 ? '' : $recipient_name));
}
}
} else {
if (api_valid_email($recipient_email)) {
$mail->AddAddress($recipient_email, $recipient_name);
} else {
return 0;
}
}
if (is_array($extra_headers) && count($extra_headers) > 0) {
foreach ($extra_headers as $key => $value) {
switch (strtolower($key)) {
case 'reply-to':
//the value here is the result of api_get_user_info()
$sender_email = $value['email'];
$sender_name = $value['complete_name'];
$mail->AddReplyTo($sender_email, $sender_name);
break;
case 'encoding':
case 'content-transfer-encoding':
$mail->Encoding = $value;
break;
case 'charset':
$mail->Charset = $value;
break;
case 'contenttype':
case 'content-type':
$mail->ContentType = $value;
break;
default:
$mail->AddCustomHeader($key.':'.$value);
break;
}
}
} else {
if (!empty($extra_headers)) {
$mail->AddCustomHeader($extra_headers);
}
}
// WordWrap the html body (phpMailer only fixes AltBody) FS#2988
$mail->Body = $mail->WrapText($mail->Body, $mail->WordWrap);
// Send the mail message.
if (!$mail->Send()) {
//echo 'ERROR: mail not sent to '.$recipient_name.' ('.$recipient_email.') because of '.$mail->ErrorInfo.'<br />';
error_log('ERROR: mail not sent to '.$recipient_name.' ('.$recipient_email.') because of '.$mail->ErrorInfo.'<br />');
return 0;
}
// Clear all the addresses.
$mail->ClearAddresses();
return 1;
}

@ -160,9 +160,6 @@ class MessageManager
$edit_message_id = intval($edit_message_id);
$topic_id = intval($topic_id);
//Capturing the original sender id
$original_sender_id = $user_sender_id;
//Saving the user id for the chamilo inbox, if the sender is null we asume that the current user is the one that sent the message
if (empty($sender_id)) {
$user_sender_id = api_get_user_id();
@ -245,10 +242,9 @@ class MessageManager
if (empty($group_id)) {
$sender_info = array();
if (!empty($original_sender_id)) {
$sender_info = api_get_user_info($original_sender_id);
if (!empty($user_sender_id)) {
$sender_info = api_get_user_info($user_sender_id);
}
$notification->save_notification(NOTIFICATION_TYPE_MESSAGE, array($receiver_user_id), $subject, $content, $sender_info);
} else {
$group_info = GroupPortalManager::get_group_data($group_id);
@ -265,6 +261,7 @@ class MessageManager
$new_user_list[] = $user_data['user_id'];
}
$group_info = array('group_info' => $group_info, 'user_info' => $sender_info);
$notification->save_notification(NOTIFICATION_TYPE_GROUP, $new_user_list, $subject, $content, $group_info);
}
return $inbox_last_id;

@ -39,80 +39,80 @@ define('NOTIFICATION_TYPE_GROUP', 3);
* @package chamilo.library
*/
class Notification extends Model {
var $table;
var $columns = array('id', 'dest_user_id', 'sender_id', 'dest_mail', 'title', 'content', 'send_freq', 'created_at', 'sent_at');
var $max_content_length = 254; //Max lenght of the notification.content field
var $debug = false;
/* message, invitation, group messages */
var $type;
var $type;
var $sender_name;
var $sender_email;
var $extra_headers = array();
var $send_email_as_user = false; //False, chamilo will sent an email as the user (not recommended)
public function __construct() {
$this->table = Database::get_main_table(TABLE_NOTIFICATION);
$this->sender_email = api_get_setting('noreply_email_address');
$this->sender_name = api_get_setting('siteName');
// If no-reply email doesn't exist use the admin email
if (empty($this->sender_email)) {
if (empty($this->sender_email)) {
$this->sender_email = api_get_setting('emailAdministrator');
$this->sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS);
}
}
$this->sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS);
}
}
/**
* Send the notifications
* @param int notification frecuency
*/
* @param int notification frecuency
*/
public function send($frec = NOTIFY_MESSAGE_DAILY) {
$notifications = $this->find('all', array('where'=> array('sent_at IS NULL AND send_freq = ?' => $frec)));
$notifications = $this->find('all', array('where'=> array('sent_at IS NULL AND send_freq = ?' => $frec)));
if (!empty($notifications)) {
foreach ($notifications as $item_to_send) {
$this->set_sender_info($item_to_send['sender_id']);
//Sending email
api_mail_html($item_to_send['dest_mail'],
$item_to_send['dest_mail'],
Security::filter_terms($item_to_send['title']),
Security::filter_terms($item_to_send['content']),
$this->sender_name,
$this->sender_email,
api_mail_html($item_to_send['dest_mail'],
$item_to_send['dest_mail'],
Security::filter_terms($item_to_send['title']),
Security::filter_terms($item_to_send['content']),
$this->sender_name,
$this->sender_email,
$this->extra_headers
);
if ($this->debug) { error_log('Sending message to: '.$item_to_send['dest_mail']); }
//Updating
$item_to_send['sent_at'] = api_get_utc_datetime();
$this->update($item_to_send);
if ($this->debug) { error_log('Updating record : '.print_r($item_to_send,1)); }
}
}
}
}
/**
* Sets the sender info in order to add the reply-to
*/
function set_sender_info($user_id) {
if (!empty($user_id)) {
$sender_user_info = api_get_user_info($user_id);
if ($this->send_email_as_user) {
$sender_user_info = api_get_user_info($user_id);
if ($this->send_email_as_user) {
$this->sender_email = $sender_user_info['email'];
$this->sender_name = $sender_user_info['complete_name'];
$this->sender_name = $sender_user_info['complete_name'];
} else {
$this->extra_headers = array('reply-to' => $sender_user_info);
}
}
}
/**
* Save message notification
* @param array message type NOTIFICATION_TYPE_MESSAGE, NOTIFICATION_TYPE_INVITATION, NOTIFICATION_TYPE_GROUP
@ -124,16 +124,16 @@ class Notification extends Model {
public function save_notification($type, $user_list, $title, $content, $sender_info = array()) {
$this->type = intval($type);
$content = $this->format_content($content, $sender_info);
$sender_id = 0;
if (!empty($sender_info) && isset($sender_info['user_id'])) {
$sender_id = $sender_info['user_id'];
$this->set_sender_info($sender_id);
}
}
$setting_to_check = '';
$avoid_my_self = false;
switch ($this->type) {
case NOTIFICATION_TYPE_MESSAGE;
$setting_to_check = 'mail_notify_message';
@ -146,103 +146,103 @@ class Notification extends Model {
$avoid_my_self = true;
break;
}
if (!empty($user_list)) {
foreach ($user_list as $user_id) {
$extra_data = UserManager::get_extra_user_data($user_id);
$params = array();
$extra_data = UserManager::get_extra_user_data($user_id);
$params = array();
if ($avoid_my_self) {
if ($user_id == api_get_user_id()) {
continue;
}
}
}
$user_info = api_get_user_info($user_id);
$user_setting = $extra_data[$setting_to_check];
switch ($user_setting) {
//No notifications
//No notifications
case NOTIFY_MESSAGE_NO:
case NOTIFY_INVITATION_NO:
case NOTIFY_GROUP_NO:
break;
//Send notification right now!
case NOTIFY_MESSAGE_AT_ONCE:
case NOTIFY_INVITATION_AT_ONCE:
case NOTIFY_GROUP_AT_ONCE:
case NOTIFY_INVITATION_AT_ONCE:
case NOTIFY_GROUP_AT_ONCE:
if (!empty($user_info['mail'])) {
$name = api_get_person_name($user_info['firstname'], $user_info['lastname']);
$name = api_get_person_name($user_info['firstname'], $user_info['lastname']);
api_mail_html($name, $user_info['mail'], Security::filter_terms($title), Security::filter_terms($content), $this->sender_name, $this->sender_email, $this->extra_headers);
}
$params['sent_at'] = api_get_utc_datetime();
//Saving the notification to be sent some day
default:
//Saving the notification to be sent some day
default:
$params['dest_user_id'] = $user_id;
$params['dest_mail'] = $user_info['mail'];
$params['title'] = $title;
$params['content'] = cut($content, $this->max_content_length);
$params['send_freq'] = $user_setting;
$params['send_freq'] = $user_setting;
$params['sender_id'] = $sender_id;
$this->save($params);
break;
}
}
}
}
}
}
/**
* Formats the content in order to add the welcome message, the notification preference, etc
* @param string the content
* @param array result of api_get_user_info() or GroupPortalManager:get_group_data()
* */
public function format_content($content, $sender_info) {
$new_message_text = $link_to_new_message = '';
$new_message_text = $link_to_new_message = '';
switch ($this->type) {
case NOTIFICATION_TYPE_MESSAGE:
case NOTIFICATION_TYPE_MESSAGE:
if (!empty($sender_info)) {
$sender_name = api_get_person_name($sender_info['firstname'], $sender_info['lastname'], null, PERSON_NAME_EMAIL_ADDRESS);
$new_message_text = sprintf(get_lang('YouHaveANewMessageFromX'), $sender_name);
$sender_name = api_get_person_name($sender_info['firstname'], $sender_info['lastname'], null, PERSON_NAME_EMAIL_ADDRESS);
$new_message_text = sprintf(get_lang('YouHaveANewMessageFromX'), $sender_name);
}
$link_to_new_message = Display::url(get_lang('SeeMessage'), api_get_path(WEB_CODE_PATH).'messages/inbox.php');
break;
case NOTIFICATION_TYPE_INVITATION:
if (!empty($sender_info)) {
$sender_name = api_get_person_name($sender_info['firstname'], $sender_info['lastname'], null, PERSON_NAME_EMAIL_ADDRESS);
//$sender_mail = $sender_info['email'] ;
$new_message_text = sprintf(get_lang('YouHaveANewInvitationFromX'), $sender_name);
}
$link_to_new_message = Display::url(get_lang('SeeInvitation'), api_get_path(WEB_CODE_PATH).'social/invitations.php');
//$sender_mail = $sender_info['email'] ;
$new_message_text = sprintf(get_lang('YouHaveANewInvitationFromX'), $sender_name);
}
$link_to_new_message = Display::url(get_lang('SeeInvitation'), api_get_path(WEB_CODE_PATH).'social/invitations.php');
break;
case NOTIFICATION_TYPE_GROUP:
$topic_page = intval($_REQUEST['topics_page_nr']);
if (!empty($sender_info)) {
$sender_name = $sender_info['group_info']['name'];
$new_message_text = sprintf(get_lang('YouHaveReceivedANewMessageInTheGroupX'), $sender_name);
if (!empty($sender_info)) {
$sender_name = $sender_info['group_info']['name'];
$new_message_text = sprintf(get_lang('YouHaveReceivedANewMessageInTheGroupX'), $sender_name);
$sender_name = api_get_person_name($sender_info['user_info']['firstname'], $sender_info['user_info']['lastname'], null, PERSON_NAME_EMAIL_ADDRESS);
$sender_name = Display::url($sender_name , api_get_path(WEB_CODE_PATH).'social/profile.php?'.$sender_info['user_info']['user_id']);
$new_message_text .= '<br />'.get_lang('User').': '.$sender_name;
}
$group_url = api_get_path(WEB_CODE_PATH).'social/group_topics.php?id='.$sender_info['group_info']['id'].'&topic_id='.$sender_info['group_info']['topic_id'].'&msg_id='.$sender_info['group_info']['msg_id'].'&topics_page_nr='.$topic_page;
}
$group_url = api_get_path(WEB_CODE_PATH).'social/group_topics.php?id='.$sender_info['group_info']['id'].'&topic_id='.$sender_info['group_info']['topic_id'].'&msg_id='.$sender_info['group_info']['msg_id'].'&topics_page_nr='.$topic_page;
$link_to_new_message = Display::url(get_lang('SeeMessage'), $group_url);
break;
}
}
$preference_url = api_get_path(WEB_CODE_PATH).'auth/profile.php';
// You have received a new message text
if (!empty($new_message_text)) {
$content = $new_message_text.'<br /><hr><br />'.$content;
}
}
// See message with link text
if (!empty($link_to_new_message)) {
$content = $content.'<br /><br />'.$link_to_new_message;
}
// You have received this message because you are subscribed text
$content = $content.'<br /><hr><i>'.
sprintf(get_lang('YouHaveReceivedThisNotificationBecauseYouAreSubscribedOrInvolvedInItToChangeYourNotificationPreferencesPleaseClickHereX'), Display::url($preference_url, $preference_url)).'</i>';
return $content;
return $content;
}
}

@ -227,12 +227,12 @@ function manage_form($default, $select_from_user_list = null, $sent_to = null) {
$file_comments = $_POST['legend'];
$title = $default['title'];
$content = $default['content'];
$group_id = $default['group_id'];
$group_id = isset($default['group_id']) ? $default['group_id'] : null;
$parent_id = $default['parent_id'];
if (is_array($user_list) && count($user_list)> 0) {
//all is well, send the message
foreach ($user_list as $user) {
$res = MessageManager::send_message($user, $title, $content, $_FILES, $file_comments, $group_id, $parent_id);
$res = MessageManager::send_message($user, $title, $content, $_FILES, $file_comments, $group_id, $parent_id, null, null, api_get_user_id());
if ($res) {
if (is_string($res)) {
$html .= Display::return_message($res, 'error');

Loading…
Cancel
Save