From d62c08e3b6828c6f4a227f97e664528d1759eb67 Mon Sep 17 00:00:00 2001 From: David Hicks Date: Fri, 12 Jun 2009 21:27:39 +1000 Subject: [PATCH] Notify user if an admin updates their account This fixes bug #4772 - a request for this new feature. When managing user accounts, administrators now have a checkbox (checked by default) which allows them to send notifications of account changes to the current/new email address of the user. This is particularly useful for informing users that the username of their account has been updated. Previously, an email or other method of notification had to be manually sent to the user to inform them of the need to use a new username when logging in. --- config_defaults_inc.php | 9 +++-- docbook/adminguide/en/configuration.sgml | 10 ++++-- lang/strings_english.txt | 5 +++ manage_user_edit_page.php | 4 +++ manage_user_update.php | 43 ++++++++++++++++++++++++ 5 files changed, 65 insertions(+), 6 deletions(-) diff --git a/config_defaults_inc.php b/config_defaults_inc.php index 2244b0f38b..709bcfa7b0 100644 --- a/config_defaults_inc.php +++ b/config_defaults_inc.php @@ -377,9 +377,12 @@ $g_return_path_email = 'admin@example.com'; /** - * allow email notification - * note that if this is disabled, sign-up and password reset messages will - * not be sent. + * Allow email notification. + * Set to ON to enable email notifications, OFF to disable them. Note that + * disabling email notifications has no effect on emails generated as part + * of the user signup process. When set to OFF, the password reset feature + * is disabled. Additionally, notifications of administrators updating + * accounts are not sent to users. * @global int $g_enable_email_notification */ $g_enable_email_notification = ON; diff --git a/docbook/adminguide/en/configuration.sgml b/docbook/adminguide/en/configuration.sgml index 003dfec6ed..6d62de1e31 100644 --- a/docbook/adminguide/en/configuration.sgml +++ b/docbook/adminguide/en/configuration.sgml @@ -286,9 +286,13 @@ $g_enable_email_notification - Set to ON to enable e-mail notifications, OFF to disable - them. Default is ON. Note that disabling email notifications has no effect on - emails generated as part of the user signup process. + Set to ON to enable email notifications, OFF to + disable them. Default is ON. Note that disabling + email notifications has no effect on emails generated + as part of the user signup process. When set to OFF, + the password reset feature is disabled. Additionally, + notifications of administrators updating accounts are + not sent to users. diff --git a/lang/strings_english.txt b/lang/strings_english.txt index a4b0be3f93..73e23ee059 100644 --- a/lang/strings_english.txt +++ b/lang/strings_english.txt @@ -976,6 +976,9 @@ $s_account_deleted_msg = 'Account deleted...'; # manage_user_delete_page.php $s_delete_account_sure_msg = 'Are you sure you wish to delete this account?'; +# manage_user_edit_page.php +$s_notify_user = 'Notify User'; + # manage_user_prune.php $s_accounts_pruned_msg = 'All accounts that have never logged in and are older than 1 week have been removed'; $s_prune_accounts_button = 'Prune'; @@ -999,6 +1002,8 @@ $s_account_reset_msg2 = 'Account password has been set to blank...'; # manage_user_update.php $s_manage_user_protected_msg = 'Account protected. Access level and enabled protected. Otherwise, account has been updated...'; $s_manage_user_updated_msg = 'Account successfully updated...'; +$s_email_user_updated_subject = 'Account updated'; +$s_email_user_updated_msg = 'Your account has been updated by an administrator. A list of these changes is provided below. You can update your account details and preferences at any time by visiting the following URL:'; # menu_inc.php $s_main_link = 'Main'; diff --git a/manage_user_edit_page.php b/manage_user_edit_page.php index 0105aeb718..e149429d36 100644 --- a/manage_user_edit_page.php +++ b/manage_user_edit_page.php @@ -130,6 +130,10 @@ + + + diff --git a/manage_user_update.php b/manage_user_update.php index b68c07cb07..cc26704c79 100644 --- a/manage_user_update.php +++ b/manage_user_update.php @@ -40,6 +40,12 @@ $f_access_level = gpc_get_int( 'access_level' ); $f_user_id = gpc_get_int( 'user_id' ); + if ( config_get( 'enable_email_notification' ) == ON ) { + $f_send_email_notification = gpc_get_bool( 'send_email_notification' ); + } else { + $f_send_email_notification = 0; + } + user_ensure_exists( $f_user_id ); $f_email = trim( $f_email ); @@ -47,6 +53,12 @@ $t_old_username = user_get_field( $f_user_id, 'username' ); + if ( $f_send_email_notification ) { + $t_old_realname = user_get_field( $f_user_id, 'realname' ); + $t_old_email = user_get_email( $f_user_id ); + $t_old_access_level = user_get_field( $f_user_id, 'access_level' ); + } + # check that the username is unique if ( 0 != strcasecmp( $t_old_username, $f_username ) && false == user_is_name_unique( $f_username ) ) { @@ -109,6 +121,37 @@ } $result = db_query_bound( $query, $query_params ); + + if ( $f_send_email_notification ) { + lang_push( user_pref_get_language( $f_user_id ) ); + $t_changes = ""; + if ( strcmp( $f_username, $t_old_username ) ) { + $t_changes .= lang_get( 'username' ) . ': ' . $t_old_username . ' => ' . $f_username . "\n"; + } + if ( strcmp( $t_realname, $t_old_realname ) ) { + $t_changes .= lang_get( 'realname' ) . ': ' . $t_old_realname . ' => ' . $t_realname . "\n"; + } + if ( strcmp( $f_email, $t_old_email ) ) { + $t_changes .= lang_get( 'email' ) . ': ' . $t_old_email . ' => ' . $f_email . "\n"; + } + if ( strcmp( $f_access_level, $t_old_access_level ) ) { + $t_old_access_string = get_enum_element( 'access_levels', $t_old_access_level ); + $t_new_access_string = get_enum_element( 'access_levels', $f_access_level ); + $t_changes .= lang_get( 'access_level' ) . ': ' . $t_old_access_string . ' => ' . $t_new_access_string . "\n\n"; + } + if ( !empty( $t_changes ) ) { + $t_subject = '[' . config_get( 'window_title' ) . '] ' . lang_get( 'email_user_updated_subject' ); + $t_updated_msg = lang_get( 'email_user_updated_msg' ); + $t_message = $t_updated_msg . "\n\n" . config_get( 'path' ) . 'account_page.php' . "\n\n" . $t_changes; + email_store( $f_email, $t_subject, $t_message ); + log_event( LOG_EMAIL, sprintf( 'Account update notification sent to ' . $f_username . ' (' . $f_email . ')' ) ); + if ( config_get( 'email_send_using_cronjob' ) == OFF ) { + email_send_all(); + } + } + lang_pop(); + } + $t_redirect_url = 'manage_user_edit_page.php?user_id=' . $c_user_id; form_security_purge('manage_user_update');