skala
Julio Montoya 12 years ago
parent 3fa0ec3ba7
commit 65bd5e7890
  1. 6
      main/inc/lib/mail.lib.inc.php
  2. 19
      main/inc/lib/message.lib.php
  3. 67
      main/inc/lib/notification.lib.php
  4. 1
      main/install/db_main.sql
  5. 36
      main/install/migrate-db-1.9.0-1.10.0-pre.sql

@ -163,6 +163,12 @@ function api_mail_html($recipient_name, $recipient_email, $subject, $message, $s
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;

@ -207,7 +207,7 @@ class MessageManager
* @param int sender id (optional) the default value is the current user_id
* @return bool
*/
public static function send_message($receiver_user_id, $subject, $content, $file_attachments = array(), $file_comments = array(), $group_id = 0, $parent_id = 0, $edit_message_id = 0, $topic_id = 0, $sender_id = null) {
public static function send_message($receiver_user_id, $subject, $content, $file_attachments = array(), $file_comments = array(), $group_id = 0, $parent_id = 0, $edit_message_id = 0, $topic_id = 0, $sender_id = null) {
$table_message = Database::get_main_table(TABLE_MESSAGE);
$group_id = intval($group_id);
$receiver_user_id = intval($receiver_user_id);
@ -215,6 +215,10 @@ 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();
} else {
@ -292,9 +296,14 @@ class MessageManager
//Load user settings
$notification = new Notification();
$sender_info = api_get_user_info($user_sender_id);
if (empty($group_id)) {
if (empty($group_id)) {
$sender_info = array();
if (!empty($original_sender_id)) {
$sender_info = api_get_user_info($original_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);
@ -310,7 +319,7 @@ class MessageManager
foreach($user_list as $user_data) {
$new_user_list[] = $user_data['user_id'];
}
$group_info = array('group_info'=>$group_info, 'user_info' => $sender_info);
$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;

@ -41,26 +41,30 @@ define('NOTIFICATION_TYPE_GROUP', 3);
class Notification extends Model {
var $table;
var $columns = array('id','dest_user_id','dest_mail','title','content','send_freq','created_at','sent_at');
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 $admin_name;
var $admin_email;
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->admin_email = api_get_setting('noreply_email_address');
$this->admin_name = api_get_setting('siteName');
$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->admin_email)) {
$this->admin_email = api_get_setting('emailAdministrator');
$this->admin_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS);
}
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);
}
}
/**
@ -68,19 +72,21 @@ class Notification extends Model {
* @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->admin_name,
$this->admin_email
$this->sender_name,
$this->sender_email,
$this->extra_headers
);
if ($this->debug) { error_log('Sending message to: '.$item_to_send['dest_mail']); }
@ -92,6 +98,21 @@ class Notification extends Model {
}
}
/**
* 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) {
$this->sender_email = $sender_user_info['email'];
$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
@ -103,11 +124,17 @@ 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) {
switch ($this->type) {
case NOTIFICATION_TYPE_MESSAGE;
$setting_to_check = 'mail_notify_message';
break;
@ -145,7 +172,7 @@ class Notification extends Model {
case NOTIFY_GROUP_AT_ONCE:
if (!empty($user_info['mail'])) {
$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->admin_name, $this->admin_email);
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
@ -154,7 +181,8 @@ class Notification extends Model {
$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;
}
@ -170,11 +198,10 @@ class Notification extends Model {
public function format_content($content, $sender_info) {
$new_message_text = $link_to_new_message = '';
switch($this->type) {
switch ($this->type) {
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);
//$sender_mail = $sender_info['email'] ;
$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');
@ -214,7 +241,7 @@ class Notification extends Model {
}
// You have received this message because you are subscribed text
$content = $content.'<br /><hr><i>'.
$content = $content.'<br /><hr><i>'.
sprintf(get_lang('YouHaveReceivedThisNotificationBecauseYouAreSubscribedOrInvolvedInItToChangeYourNotificationPreferencesPleaseClickHereX'), Display::url($preference_url, $preference_url)).'</i>';
return $content;
}

@ -2826,6 +2826,7 @@ CREATE TABLE IF NOT EXISTS notification (
dest_user_id INT NOT NULL,
dest_mail CHAR(255),
title CHAR(255),
sender_id INT NOT NULL DEFAULT 0,
content CHAR(255),
send_freq SMALLINT DEFAULT 1,
created_at DATETIME NOT NULL,

@ -1,14 +1,16 @@
-- This script updates the databases structure before migrating the data from
-- version 1.9.0 (or version 1.9.2, 1.9.4) to version 1.10.0
-- it is intended as a standalone script, however, this has not been finished
-- yet, and it should still be parsed by a PHP script.
-- version 1.9.0 (or version 1.9.2) to version 1.10.0
-- it is intended as a standalone script, however, because of the multiple
-- databases related difficulties, it should be parsed by a PHP script in
-- order to connect to and update the right databases.
-- There is one line per query, allowing the PHP function file() to read
-- all lines separately into an array. The xxMAINxx-type markers used to be
-- there to tell the PHP script which database we're talking about, but since
-- 1.9.0, everything should be residing in the same, unique xxMAINxx section.
-- all lines separately into an array. The xxMAINxx-type markers are there
-- to tell the PHP script which database we're talking about.
-- By always using the keyword "TABLE" in the queries, we should be able
-- to retrieve and modify the table name from the PHP script if needed, which
-- will allow us to deal with the unique-database-type installations
--
-- This first part is for the main database
-- xxMAINxx
@ -16,5 +18,25 @@
ALTER TABLE track_e_online ADD INDEX idx_trackonline_uat (login_user_id, access_url_id, login_date);
-- Do not move this query
UPDATE settings_current SET selected_value = '1.10.0.19436' WHERE variable = 'chamilo_database_version';
-- Main changes
-- Courses changes c_XXX
ALTER TABLE c_lp_item ADD INDEX idx_c_lp_item_cid_lp_id (c_id, lp_id);
ALTER TABLE c_lp_item_view ADD INDEX idx_c_lp_item_view_cid_lp_view_id_lp_item_id(c_id, lp_view_id, lp_item_id);
ALTER TABLE c_tool_intro MODIFY COLUMN intro_text MEDIUMTEXT NOT NULL;
ALTER TABLE notification ADD COLUMN sender_id INT NOT NULL DEFAULT 0;
-- Normal tables
UPDATE settings_current SET selected_value = '1.10.xx' WHERE variable = 'chamilo_database_version';
-- xxSTATSxx
-- All stats DB changes will be added in the "main zone"
-- xxUSERxx
-- All user DB changes will be added in the "main zone"
-- xxCOURSExx
-- All course DB changes will be added in the "main zone"
Loading…
Cancel
Save