|
@@ -33,21 +33,25 @@ define('NOTIFY_GROUP_NO', '0');
|
|
|
class Notification extends Model {
|
|
|
|
|
|
var $table;
|
|
|
- var $columns = array('id','dest_user_id','dest_mail','title','content','send_freq','created_at','sent_at');
|
|
|
- var $max_content_length = 254;
|
|
|
- var $debug = true;
|
|
|
+ var $columns = array('id','dest_user_id','dest_mail','title','content','send_freq','created_at','sent_at');
|
|
|
+ var $max_content_length = 254;
|
|
|
+ var $debug = true;
|
|
|
+
|
|
|
+ var $admin_name;
|
|
|
+ var $admin_email;
|
|
|
|
|
|
public function __construct() {
|
|
|
- $this->table = Database::get_main_table(TABLE_NOTIFICATION);
|
|
|
+ $this->table = Database::get_main_table(TABLE_NOTIFICATION);
|
|
|
+ $this->admin_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS);
|
|
|
+ $this->admin_email = api_get_setting('emailAdministrator');
|
|
|
}
|
|
|
|
|
|
public function send($frec = NOTIFY_MESSAGE_DAILY) {
|
|
|
$notifications = $this->find('all',array('where'=>array('sent_at IS NULL AND send_freq = ?'=>$frec)));
|
|
|
if (!empty($notifications)) {
|
|
|
foreach($notifications as $item_to_send) {
|
|
|
-
|
|
|
-
|
|
|
- api_mail_html($item_to_send['dest_mail'], $item_to_send['dest_mail'], $item_to_send['title'], $item_to_send['content']);
|
|
|
+
|
|
|
+ api_mail_html($item_to_send['dest_mail'], $item_to_send['dest_mail'], $item_to_send['title'], $item_to_send['content'], $this->admin_name, $this->admin_email);
|
|
|
if ($this->debug) { error_log('Sending message to: '.$item_to_send['dest_mail']); }
|
|
|
|
|
|
$item_to_send['sent_at'] = api_get_utc_datetime();
|
|
@@ -62,9 +66,17 @@ class Notification extends Model {
|
|
|
* @param array user list of ids
|
|
|
* @param string title
|
|
|
* @param string content of the message
|
|
|
+ * @param array sender info (return of the api_get_user_info() function )
|
|
|
*
|
|
|
*/
|
|
|
- public function save_message_notifications($user_list, $title, $content) {
|
|
|
+ public function save_message_notifications($user_list, $title, $content, $sender_info = array()) {
|
|
|
+ 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'] ;
|
|
|
+ $content = sprintf(get_lang('YouHaveANewMessageFromX'), $sender_name).'<br />'.$content;
|
|
|
+ }
|
|
|
+ $content = $content.'<br />'.Display::url(get_lang('SeeMessage'), api_get_path(WEB_CODE_PATH).'messages/inbox.php');
|
|
|
+
|
|
|
if (!empty($user_list)) {
|
|
|
foreach($user_list as $user_id) {
|
|
|
$extra_data = UserManager::get_extra_user_data($user_id);
|
|
@@ -76,11 +88,10 @@ class Notification extends Model {
|
|
|
$user_info = api_get_user_info($user_id);
|
|
|
if (!empty($user_info['mail'])) {
|
|
|
$name = api_get_person_name($user_info['firstname'], $user_info['lastname']);
|
|
|
- api_mail_html($name, $user_info['mail'], $title, $content);
|
|
|
+ api_mail_html($name, $user_info['mail'], $title, $content, $this->admin_name, $this->admin_email);
|
|
|
}
|
|
|
$params['sent_at'] = api_get_utc_datetime();
|
|
|
- default:
|
|
|
- $extra_data = UserManager::get_extra_user_data($user_id);
|
|
|
+ default:
|
|
|
$user_info = api_get_user_info($user_id);
|
|
|
$params['dest_user_id'] = $user_id;
|
|
|
$params['dest_mail'] = $user_info['mail'];
|
|
@@ -101,8 +112,16 @@ class Notification extends Model {
|
|
|
* @param string content of the message
|
|
|
*
|
|
|
*/
|
|
|
- public function save_invitation_notifications($user_list, $title, $content) {
|
|
|
- if (!empty($user_list)) {
|
|
|
+ public function save_invitation_notifications($user_list, $title, $content, $sender_info = array()) {
|
|
|
+ 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'] ;
|
|
|
+ $content = sprintf(get_lang('YouHaveANewInvitationFromX'), $sender_name).'<br />'.$content;
|
|
|
+ }
|
|
|
+
|
|
|
+ $content = $content.'<br />'.Display::url(get_lang('SeeInvitation'), api_get_path(WEB_CODE_PATH).'social/invitations.php');
|
|
|
+
|
|
|
+ if (!empty($user_list)) {
|
|
|
foreach($user_list as $user_id) {
|
|
|
$extra_data = UserManager::get_extra_user_data($user_id);
|
|
|
$params = array();
|
|
@@ -113,11 +132,10 @@ class Notification extends Model {
|
|
|
$user_info = api_get_user_info($user_id);
|
|
|
if (!empty($user_info['mail'])) {
|
|
|
$name = api_get_person_name($user_info['firstname'], $user_info['lastname']);
|
|
|
- api_mail_html($name, $user_info['mail'], $title, $content);
|
|
|
+ api_mail_html($name, $user_info['mail'], $title, $content, $this->admin_name, $this->admin_email);
|
|
|
}
|
|
|
$params['sent_at'] = api_get_utc_datetime();
|
|
|
- default:
|
|
|
- $extra_data = UserManager::get_extra_user_data($user_id);
|
|
|
+ default:
|
|
|
$user_info = api_get_user_info($user_id);
|
|
|
$params['dest_user_id'] = $user_id;
|
|
|
$params['dest_mail'] = $user_info['mail'];
|
|
@@ -139,7 +157,12 @@ class Notification extends Model {
|
|
|
* @param string content of the message
|
|
|
*
|
|
|
*/
|
|
|
- public function save_group_notifications($user_list, $title, $content) {
|
|
|
+ public function save_group_notifications($user_list, $title, $content, $sender_info = array()) {
|
|
|
+ if (!empty($sender_info)) {
|
|
|
+ $sender_name = $sender_info['name'];
|
|
|
+ $content = sprintf(get_lang('YouHaveReceivedANewMessageInTheGroupX'), $sender_name).'<br />'.$content;
|
|
|
+ $content = $content.'<br />'.Display::url(get_lang('SeeMessage'), api_get_path(WEB_CODE_PATH).'social/groups.php?id='.$sender_info['id']);
|
|
|
+ }
|
|
|
if (!empty($user_list)) {
|
|
|
foreach($user_list as $user_id) {
|
|
|
|
|
@@ -155,11 +178,10 @@ class Notification extends Model {
|
|
|
$user_info = api_get_user_info($user_id);
|
|
|
if (!empty($user_info['mail'])) {
|
|
|
$name = api_get_person_name($user_info['firstname'], $user_info['lastname']);
|
|
|
- api_mail_html($name, $user_info['mail'], $title, $content);
|
|
|
+ api_mail_html($name, $user_info['mail'], $title, $content, $this->admin_name, $this->admin_email);
|
|
|
}
|
|
|
$params['sent_at'] = api_get_utc_datetime();
|
|
|
- default:
|
|
|
- $extra_data = UserManager::get_extra_user_data($user_id);
|
|
|
+ default:
|
|
|
$user_info = api_get_user_info($user_id);
|
|
|
$params['dest_user_id'] = $user_id;
|
|
|
$params['dest_mail'] = $user_info['mail'];
|