From c396d49c3a004937f35d93b917a274640f760043 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Thu, 19 Jul 2012 16:29:36 +0200 Subject: [PATCH 1/2] Minor fixing query --- main/inc/lib/usermanager.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/inc/lib/usermanager.lib.php b/main/inc/lib/usermanager.lib.php index 86535eb0f3..117026425b 100644 --- a/main/inc/lib/usermanager.lib.php +++ b/main/inc/lib/usermanager.lib.php @@ -2872,7 +2872,7 @@ class UserManager { $table_user = Database::get_main_table(TABLE_MAIN_USER); $table_admin = Database::get_main_table(TABLE_MAIN_ADMIN); - $sql = "SELECT user_id, username, firstname, lastname, email from $table_user as u, $table_admin as a WHERE u.user_id=a.user_id"; + $sql = "SELECT u.user_id, username, firstname, lastname, email from $table_user as u INNER JOIN $table_admin as a ON (u.user_id=a.user_id) "; $result = Database::query($sql); $return = array(); if (Database::num_rows($result)> 0) { From 10183efeedc549a5d66504da726534ccbba7ee02 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Thu, 19 Jul 2012 16:54:47 +0200 Subject: [PATCH 2/2] Some minor fixes in the message and notification, should implement #5178 --- main/auth/inscription.php | 54 ++++++++++++------------------- main/inc/lib/message.lib.php | 16 +++++---- main/inc/lib/notification.lib.php | 38 +++++++++++----------- main/inc/lib/usermanager.lib.php | 15 +++++++-- 4 files changed, 62 insertions(+), 61 deletions(-) diff --git a/main/auth/inscription.php b/main/auth/inscription.php index 17616a61c8..d8bfcffb6f 100644 --- a/main/auth/inscription.php +++ b/main/auth/inscription.php @@ -366,43 +366,29 @@ if ($form->validate()) { $sql = "UPDATE ".$TABLE_USER." SET active='0' WHERE user_id='".$user_id."'"; Database::query($sql); - $table_main_admin = Database::get_main_table(TABLE_MAIN_ADMIN); - - if ($_configuration['multiple_access_urls']) { - $access_url_id = api_get_current_access_url_id(); - $tbl_url_rel_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); - $sql_get_id_admin = "SELECT admin.user_id FROM ".$tbl_url_rel_user." as url, ".$table_main_admin." as admin WHERE access_url_id='".$access_url_id."' AND admin.user_id=url.user_id"; + // 2. Send mail to all platform admin + + $emailsubject = get_lang('ApprovalForNewAccount',null,$values['language']).': '.$values['username']; + $emailbody = get_lang('ApprovalForNewAccount',null,$values['language'])."\n"; + $emailbody .= get_lang('UserName',null,$values['language']).': '.$values['username']."\n"; + + if (api_is_western_name_order()) { + $emailbody .= get_lang('FirstName',null,$values['language']).': '.$values['firstname']."\n"; + $emailbody .= get_lang('LastName',null,$values['language']).': '.$values['lastname']."\n"; } else { - $sql_get_id_admin = "SELECT * FROM ".$table_main_admin; + $emailbody .= get_lang('LastName',null,$values['language']).': '.$values['lastname']."\n"; + $emailbody .= get_lang('FirstName',null,$values['language']).': '.$values['firstname']."\n"; } - $result = Database::query($sql_get_id_admin); - while ($row = Database::fetch_array($result)) { - - $sql_admin_list = "SELECT * FROM ".$TABLE_USER." WHERE user_id='".$row['user_id']."'"; - $result_list = Database::query($sql_admin_list); - $admin_list = Database::fetch_array($result_list); - $emailto = $admin_list['email']; - - // 2. send mail to the platform admin - $emailsubject = get_lang('ApprovalForNewAccount',null,$values['language']).': '.$values['username']; - $emailbody = get_lang('ApprovalForNewAccount',null,$values['language'])."\n"; - $emailbody .= get_lang('UserName',null,$values['language']).': '.$values['username']."\n"; - - if (api_is_western_name_order()) { - $emailbody .= get_lang('FirstName',null,$values['language']).': '.$values['firstname']."\n"; - $emailbody .= get_lang('LastName',null,$values['language']).': '.$values['lastname']."\n"; - } else { - $emailbody .= get_lang('LastName',null,$values['language']).': '.$values['lastname']."\n"; - $emailbody .= get_lang('FirstName',null,$values['language']).': '.$values['firstname']."\n"; - } - $emailbody .= get_lang('Email',null,$values['language']).': '.$values['email']."\n"; - $emailbody .= get_lang('Status',null,$values['language']).': '.$values['status']."\n\n"; - $emailbody .= get_lang('ManageUser',null,$values['language']).': '.api_get_path(WEB_CODE_PATH).'admin/user_edit.php?user_id='.$user_id; - - $sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS); - $email_admin = api_get_setting('emailAdministrator'); - @api_mail('', $emailto, $emailsubject, $emailbody, $sender_name, $email_admin); + $emailbody .= get_lang('Email',null,$values['language']).': '.$values['email']."\n"; + $emailbody .= get_lang('Status',null,$values['language']).': '.$values['status']."\n\n"; + $url_edit = Display::url(api_get_path(WEB_CODE_PATH).'admin/user_edit.php?user_id='.$user_id, api_get_path(WEB_CODE_PATH).'admin/user_edit.php?user_id='.$user_id); + $emailbody .= get_lang('ManageUser',null,$values['language']).": $url_edit"; + + $admins = UserManager::get_all_administrators(); + foreach ($admins as $admin_info) { + MessageManager::send_message($admin_info['user_id'], $emailsubject, $emailbody, null, null, null, null, null, null, $user_id); } + // 3. exit the page unset($user_id); diff --git a/main/inc/lib/message.lib.php b/main/inc/lib/message.lib.php index 4e59abf7ec..a9331c0547 100644 --- a/main/inc/lib/message.lib.php +++ b/main/inc/lib/message.lib.php @@ -198,7 +198,8 @@ class MessageManager } return $message_list; } - + + /** * Sends a message to a user/group * @@ -210,17 +211,21 @@ class MessageManager * @param int group id (optional) * @param int parent id (optional) * @param int message id for updating the message (optional) - * @param bool sent an email or not (@todo) + * @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) { + 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); $parent_id = intval($parent_id); $edit_message_id = intval($edit_message_id); - $topic_id = intval($topic_id); - $user_sender_id = api_get_user_id(); + $topic_id = intval($topic_id); + if (empty($sender_id)) { + $user_sender_id = api_get_user_id(); + } else { + $user_sender_id = intval($sender_id); + } $total_filesize = 0; if (is_array($file_attachments)) { @@ -245,7 +250,6 @@ class MessageManager if (!empty($receiver_user_id) || !empty($group_id)) { // message for user friend - $clean_subject = Database::escape_string($subject); $clean_content = Database::escape_string($content); diff --git a/main/inc/lib/notification.lib.php b/main/inc/lib/notification.lib.php index cffc6d9483..ad9dad2095 100644 --- a/main/inc/lib/notification.lib.php +++ b/main/inc/lib/notification.lib.php @@ -13,23 +13,23 @@ //default values //mail_notify_message ("At once", "Daily", "No") -define('NOTIFY_MESSAGE_AT_ONCE', '1'); -define('NOTIFY_MESSAGE_DAILY', '8'); -define('NOTIFY_MESSAGE_WEEKLY', '12'); -define('NOTIFY_MESSAGE_NO', '0'); +define('NOTIFY_MESSAGE_AT_ONCE', '1'); +define('NOTIFY_MESSAGE_DAILY', '8'); +define('NOTIFY_MESSAGE_WEEKLY', '12'); +define('NOTIFY_MESSAGE_NO', '0'); //mail_notify_invitation ("At once", "Daily", "No") -define('NOTIFY_INVITATION_AT_ONCE', '1'); -define('NOTIFY_INVITATION_DAILY', '8'); -define('NOTIFY_INVITATION_WEEKLY', '12'); -define('NOTIFY_INVITATION_NO', '0'); +define('NOTIFY_INVITATION_AT_ONCE', '1'); +define('NOTIFY_INVITATION_DAILY', '8'); +define('NOTIFY_INVITATION_WEEKLY', '12'); +define('NOTIFY_INVITATION_NO', '0'); // mail_notify_group_message ("At once", "Daily", "No") -define('NOTIFY_GROUP_AT_ONCE', '1'); -define('NOTIFY_GROUP_DAILY', '8'); -define('NOTIFY_GROUP_WEEKLY', '12'); -define('NOTIFY_GROUP_NO', '0'); +define('NOTIFY_GROUP_AT_ONCE', '1'); +define('NOTIFY_GROUP_DAILY', '8'); +define('NOTIFY_GROUP_WEEKLY', '12'); +define('NOTIFY_GROUP_NO', '0'); define('NOTIFICATION_TYPE_MESSAGE', 1); define('NOTIFICATION_TYPE_INVITATION', 2); @@ -63,7 +63,7 @@ class Notification extends Model { 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) { + foreach ($notifications as $item_to_send) { //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); @@ -80,7 +80,7 @@ class Notification extends Model { /** * Save message notification * @param array message type NOTIFICATION_TYPE_MESSAGE, NOTIFICATION_TYPE_INVITATION, NOTIFICATION_TYPE_GROUP - * @param array user list of ids + * @param array recipients: user list of ids * @param string title * @param string content of the message * @param array result of api_get_user_info() or GroupPortalManager:get_group_data() @@ -106,16 +106,18 @@ class Notification extends Model { } if (!empty($user_list)) { - foreach($user_list as $user_id) { + foreach ($user_list as $user_id) { $extra_data = UserManager::get_extra_user_data($user_id); - $params = array(); + $params = array(); if ($avoid_my_self) { if ($user_id == api_get_user_id()) { continue; } } - $user_setting = $extra_data[$setting_to_check]; + $user_info = api_get_user_info($user_id); + $user_setting = $extra_data[$setting_to_check]; + switch ($user_setting) { //No notifications case NOTIFY_MESSAGE_NO: @@ -140,7 +142,7 @@ class Notification extends Model { $params['send_freq'] = $user_setting; $this->save($params); break; - } + } } } } diff --git a/main/inc/lib/usermanager.lib.php b/main/inc/lib/usermanager.lib.php index 117026425b..d7031f0b00 100644 --- a/main/inc/lib/usermanager.lib.php +++ b/main/inc/lib/usermanager.lib.php @@ -2870,9 +2870,18 @@ class UserManager { */ public function get_all_administrators() { $table_user = Database::get_main_table(TABLE_MAIN_USER); - $table_admin = Database::get_main_table(TABLE_MAIN_ADMIN); - - $sql = "SELECT u.user_id, username, firstname, lastname, email from $table_user as u INNER JOIN $table_admin as a ON (u.user_id=a.user_id) "; + $table_admin = Database::get_main_table(TABLE_MAIN_ADMIN); + $tbl_url_rel_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); + $access_url_id = api_get_current_access_url_id(); + if (api_get_multiple_access_url()) { + $access_url_id = api_get_current_access_url_id(); + $sql = "SELECT admin.user_id, username, firstname, lastname, email FROM $tbl_url_rel_user as url INNER JOIN $table_admin as admin + ON (admin.user_id=url.user_id) INNER JOIN $table_user u ON (u.user_id=admin.user_id) + WHERE access_url_id ='".$access_url_id."'"; + } else { + $sql = "SELECT admin.user_id, username, firstname, lastname, email FROM $table_admin as admin + INNER JOIN $table_user u ON (u.user_id=admin.user_id)"; + } $result = Database::query($sql); $return = array(); if (Database::num_rows($result)> 0) {