Index: user_register_notify.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/user_register_notify/user_register_notify.module,v retrieving revision 1.1.2.12 diff -u -r1.1.2.12 user_register_notify.module --- user_register_notify.module 13 Aug 2008 20:12:45 -0000 1.1.2.12 +++ user_register_notify.module 5 Dec 2008 16:33:01 -0000 @@ -40,6 +40,18 @@ '#description' => t('If you leave this blank, the site email address, %mailto, will be used.', array('%mailto' => variable_get('site_mail', ini_get('sendmail_from')))), '#default_value' => variable_get('user_register_notify_mailto', variable_get('site_mail', ini_get('sendmail_from'))), ); + $form['roles'] = array( + '#type' => 'fieldset', + '#title' => t('Roles'), + '#description' => t('All users with permissions roles will also receive a notification email when selected.'), + '#collapsible' => TRUE, + '#collapsed' => TRUE + ); + $user_roles = user_roles(TRUE); + $form['roles']['user_register_notify_roles'] = array( + '#type' => 'checkboxes', + '#options' => $user_roles + ); $form['user_register_notify_subject'] = array( '#type' => 'textfield', '#title' => t('Email Subject'), @@ -65,11 +77,18 @@ '#title' => t('Page Sort order'), '#default_value' => variable_get('user_register_notify_alert', 'create'), '#description' => t('When to send an Email'), - '#required' => false, + '#required' => FALSE ); return system_settings_form($form); } +function user_register_notify_settings_validate($form_id, $form_values) { + foreach ($form_values['user_register_notify_roles'] as $key => $value) { + if (!is_numeric($key)) { + form_set_error('user_register_notify_roles', t('Invalid role identifier submitted.')); + } + } +} function user_register_notify_setup_email(&$edit, &$account) { // Notify administrator of new user only if this is not first user and @@ -117,9 +136,21 @@ '!profile' => check_plain($profile_data), ); $subject = t(variable_get('user_register_notify_subject', USER_REGISTER_NOTIFY_SUBJECT), $variables); - $body = t(variable_get('user_register_notify_body',USER_REGISTER_NOTIFY_BODY), $variables); + $body = t(variable_get('user_register_notify_body', USER_REGISTER_NOTIFY_BODY), $variables); $from = variable_get('site_mail', ini_get('sendmail_from')); $to = variable_get('user_register_notify_mailto', $from); + + $roles = implode(',', variable_get('user_register_roles', array())); + if (!empty($roles)) { + $result = db_query("SELECT mail FROM {users} AS u INNER JOIN {users_roles} AS r ON u.uid = r.uid WHERE r.rid IN($roles)"); + $emails = array(); + while ($mail = db_fetch_object($result)) { + $emails[] = $mail->mail; + } + if (!empty($emails)) { + $to = $to .' '. implode(' ', $emails); + } + } drupal_mail('user-register-notify-admin', $to, $subject, $body, $from, array('Reply-To' => $to)); drupal_set_message(check_plain($account_data)); }