Index: advuser.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/advuser/advuser.module,v retrieving revision 1.13.2.8 diff -u -r1.13.2.8 advuser.module --- advuser.module 2 May 2008 19:32:59 -0000 1.13.2.8 +++ advuser.module 21 May 2008 18:56:01 -0000 @@ -59,6 +59,9 @@ return $items; } +/** + * Primary advuser management callback. + */ function advuser_admin($callback_arg = '') { $op = isset($_POST['op']) ? $_POST['op'] : $callback_arg; @@ -69,7 +72,10 @@ } elseif ($_POST['accounts'] && $_POST['operation'] == 'email') { $output = drupal_get_form('advuser_multiple_email_confirm'); - } + } + elseif ($_POST['accounts'] && $_POST['operation'] == 'passreset') { + $output = drupal_get_form('advuser_newpass_confirm'); + } else { $output = drupal_get_form('advuser_filter_form'); $output .= drupal_get_form('advuser_admin_account'); @@ -273,23 +279,7 @@ } function advuser_multiple_delete_confirm() { - $edit = $_POST; - - $form['accounts'] = array( - '#prefix' => '', - '#tree' => TRUE - ); - // array_filter returns only elements with TRUE values - foreach (array_filter($edit['accounts']) as $uid => $value) { - $user = db_result(db_query('SELECT name FROM {users} WHERE uid = %d', $uid)); - $form['accounts'][$uid] = array( - '#type' => 'hidden', - '#value' => $uid, - '#prefix' => '
  • ', - '#suffix' => check_plain($user) ."
  • \n" - ); - } + $form = advuser_account_form(); $form['operation'] = array('#type' => 'hidden', '#value' => 'delete'); return confirm_form( @@ -312,21 +302,16 @@ } /** - * Email functionality + * Generates a form stub account managment pages. */ -function advuser_advuser_operations() { - $operations = array( - 'email' => array( - 'label' => t('Email selected users') - ) - ); - return $operations; -} - -function advuser_multiple_email_confirm() { +function advuser_account_form() { $edit = $_POST; - $form['accounts'] = array('#prefix' => '', '#tree' => TRUE); + $form['accounts'] = array( + '#prefix' => '', + '#tree' => TRUE, + ); // array_filter returns only elements with TRUE values foreach (array_filter($edit['accounts']) as $uid => $value) { $user = db_result(db_query('SELECT name FROM {users} WHERE uid = %d', $uid)); @@ -337,6 +322,27 @@ '#suffix' => check_plain($user) ."\n" ); } + return $form; +} + +/** + * Email functionality + */ +function advuser_advuser_operations() { + $operations = array( + 'email' => array( + 'label' => t('Email selected users'), + ), + 'passreset' => array( + 'label' => t('Reset password and notify'), + ), + ); + return $operations; +} + +function advuser_multiple_email_confirm() { + $form = advuser_account_form(); + $form['operation'] = array( '#type' => 'hidden', '#value' => 'email' @@ -388,6 +394,64 @@ } /** + * Email user(s) with new password functionality. + */ +function advuser_newpass_confirm() { + $form = advuser_account_form(); + + $form['operation'] = array( + '#type' => 'hidden', + '#value' => 'email' + ); + $form['variables'] = array( + '#type' => 'markup', + '#prefix' => '
    ', + '#value' => "

    ". ADVUSER_SUBSTITUTION_TEXT . "

    " .t("%new_password contains a contains a password reset url"). "

    ", + '#suffix' => '
    ' + ); + $form['mailsubject'] = array( + '#type' => 'textfield', + '#title' => t('Subject'), + '#required' => TRUE, + '#default_value' => variable_get('advuser_newpass_mailsubject', 'Your %site password has been reset'), + ); + $form['mailbody'] = array( + '#type' => 'textarea', + '#title' => t('Mail body'), + '#required' => TRUE, + '#default_value' => variable_get('advuser_newpass_mailbody', 'Your password for %site has been reset. Click here to login %new_password'), + ); + $form['operation'] = array('#type' => 'hidden', '#value' => 'passreset'); + + return confirm_form( + $form, + t('Are you sure you want to reset these users passwords?'), + 'admin/user/user/advuser', t('This action cannot be undone.'), + t('Send new passwords'), + t('Cancel') + ); +} + +/** + * Password reset and notify submit handler + */ +function advuser_newpass_confirm_submit($form_id, $form_values) { + if ($form_values['confirm']) { + foreach (array_filter($form_values['accounts']) as $uid) { + $from = variable_get("site_mail", ini_get("sendmail_from")); + $account = user_load(array('uid' => $uid)); + $variables = _advuser_get_variables($account); + // Reset password only as we send the email. + $variables['%new_password'] = user_pass_reset_url($account); + $mail_subject = strtr($form_values['mailsubject'], $variables); + $mail_body = strtr($form_values['mailbody'], $variables); + drupal_mail('advance-user-newpass', $account->mail, $mail_subject, $mail_body, $from); + } + drupal_set_message(t('The users have been sent a "reset password" link.')); + } +} + +/** * advuser settings page */ function advuser_settings() { @@ -448,6 +512,27 @@ '#description' => t('The mail that is going to be sent to the selected roles when a user modifies their account. You may insert substitution variables within this item.'), '#default_value' => variable_get('advuser_modify_mail', NULL), ); + + // New password notifications. + $form['advuser_newpass'] = array( + '#type' => 'fieldset', + '#title' => t('Mail notifications for resetting user passwords.'), + '#description' => t("An extra token %new_password which contains a contains a password reset url is available in the body of this email"), + '#collapsible' => FALSE, + '#collapsed' => FALSE, + ); + $form['advuser_newpass']['advuser_newpass_mailsubject'] = array( + '#type' => 'textfield', + '#title' => t('Subject'), + '#required' => TRUE, + '#default_value' => variable_get('advuser_newpass_mailsubject', 'Your %site password has been reset'), + ); + $form['advuser_newpass']['advuser_newpass_mailbody'] = array( + '#type' => 'textarea', + '#title' => t('Mail body'), + '#required' => TRUE, + '#default_value' => variable_get('advuser_newpass_mailbody', 'Your password for %site has been reset. Click here to login %new_password'), + ); //Maximum rows in dataset to display $form['advuser_mail']['advuser_listno'] = array(