Skip to content

Commit

Permalink
Merge branch 'manage-user-email-notify'
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhicks committed Jun 20, 2009
2 parents 20c5900 + d62c08e commit 63e4dbc
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 6 deletions.
9 changes: 6 additions & 3 deletions config_defaults_inc.php
Expand Up @@ -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;
Expand Down
10 changes: 7 additions & 3 deletions docbook/adminguide/en/configuration.sgml
Expand Up @@ -286,9 +286,13 @@
<varlistentry>
<term>$g_enable_email_notification</term>
<listitem>
<para>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.
<para>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.
</para>
</listitem>
</varlistentry>
Expand Down
5 changes: 5 additions & 0 deletions lang/strings_english.txt
Expand Up @@ -984,6 +984,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';
Expand All @@ -1007,6 +1010,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';
Expand Down
4 changes: 4 additions & 0 deletions manage_user_edit_page.php
Expand Up @@ -130,6 +130,10 @@
<!-- Submit Button -->
<tr>
<td colspan="2" class="center">
<?php if ( config_get( 'enable_email_notification' ) == ON ) {
echo lang_get( 'notify_user' ); ?>
<input type="checkbox" name="send_email_notification" checked />
<?php } ?>
<input type="submit" class="button" value="<?php echo lang_get( 'update_user_button' ) ?>" />
</td>
</tr>
Expand Down
43 changes: 43 additions & 0 deletions manage_user_update.php
Expand Up @@ -40,13 +40,25 @@
$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 );
$f_username = trim( $f_username );

$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 ) ) {
Expand Down Expand Up @@ -111,6 +123,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');
Expand Down

0 comments on commit 63e4dbc

Please sign in to comment.