Index: advuser.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/advuser/advuser.module,v
retrieving revision 1.13.2.2
diff -u -p -r1.13.2.2 advuser.module
--- advuser.module	14 Mar 2008 18:47:08 -0000	1.13.2.2
+++ advuser.module	18 Mar 2008 20:48:00 -0000
@@ -11,14 +11,32 @@
 /**
  * @constants
  */
-define('ADVUSER_DEFAULT_NEW_MAIL', "User email: %user_email\n\nIf you want to check and edit the account go to %uri.\n\nInvestigate User:\nYahoo search  %user_email: %yahoo_user \nGoogle search %user_email: %google_user\n\n--\n%site");
-define('ADVUSER_DEFAULT_MODIFY_MAIL', ADVUSER_DEFAULT_NEW_MAIL); // "User email: %user_email\n\nIf you want to check and edit the account go to %uri.\n\nYahoo search %user_email: %yahoo_user \nGoogle search %user_email: %google_user\n\n--\n%site");
+define('ADVUSER_DEFAULT_NEW_MAIL', 
+"User email: %user_email
+
+If you want to check and edit the account go to %uri.
+
+Investigate User:
+Yahoo search  %user_email: %yahoo_user 
+Google search %user_email: %google_user
+
+--
+%site");
+
+define('ADVUSER_DEFAULT_MODIFY_MAIL', ADVUSER_DEFAULT_NEW_MAIL);
+
 define('ADVUSER_DEFAULT_NEW_ROLES', NULL);
+
 define('ADVUSER_DEFAULT_NEW_SUBJECT', 'A new user (%username) has just registered on %site.');
+
 define('ADVUSER_DEFAULT_MODIFY_SUBJECT', 'A user (%username) has just modified their account on %site.');
+
 define('ADVUSER_DEFAULT_NEW_NOTIFY', 1);
+
 define('ADVUSER_DEFAULT_MODIFY_NOTIFY', 1);
+
 define('ADVUSER_DEFAULT_LISTNO', 200);
+
 define('ADVUSER_DEFAULT_PROFILE_FIELDS', NULL);
 
 /**
@@ -46,16 +64,17 @@ function advuser_menu($may_cache) {
       'callback' => 'drupal_get_form',
       'callback arguments' => array('advuser_settings'),
       'access' =>  $admin_access,
-      'type' => MENU_NORMAL_ITEM
+      'type' => MENU_NORMAL_ITEM,
     );
 
     $items[] = array(
-      'path' => 'admin/user/advuser', 
-      'title' => t('Advanced management'),
+      'path' => 'admin/user/user/advuser', 
+      'title' => t('Advanced'),
       'description' => t('List, add, edit and email users.'),
       'callback' => 'advuser_admin', 
       'callback arguments' => array('list'), 
-      'access' => $access_access
+      'access' => $access_access,
+      'type' => MENU_LOCAL_TASK,
     );
   }
   return $items;
@@ -68,9 +87,11 @@ function advuser_admin($callback_arg = '
     default: {
       if ($_POST['accounts'] && $_POST['operation'] == 'delete') {
         $output = drupal_get_form('advuser_multiple_delete_confirm');
-      } else if ($_POST['accounts'] && $_POST['operation'] == 'email') {
+      } 
+      elseif ($_POST['accounts'] && $_POST['operation'] == 'email') {
         $output = drupal_get_form('advuser_multiple_email_confirm');
-      } else {
+      } 
+      else {
         $output = drupal_get_form('advuser_filter_form');
         $output .= drupal_get_form('advuser_admin_account');
       }
@@ -270,18 +291,30 @@ function advuser_admin_account_validate(
 function advuser_multiple_delete_confirm() {
   $edit = $_POST;
 
-  $form['accounts'] = array('#prefix' => '<ul>', '#suffix' => '</ul>', '#tree' => TRUE);
+  $form['accounts'] = array(
+    '#prefix' => '<ul>', 
+    '#suffix' => '</ul>', 
+    '#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' => '<li>', '#suffix' => check_plain($user) ."</li>\n");
+    $form['accounts'][$uid] = array(
+      '#type' => 'hidden', 
+      '#value' => $uid, 
+      '#prefix' => '<li>', 
+      '#suffix' => check_plain($user) ."</li>\n"
+    );
   }
   $form['operation'] = array('#type' => 'hidden', '#value' => 'delete');
 
-  return confirm_form($form,
-                      t('Are you sure you want to delete these users?'),
-                      'admin/user/advuser', t('This action cannot be undone.'),
-                      t('Delete all'), t('Cancel'));
+  return confirm_form(
+    $form,
+    t('Are you sure you want to delete these users?'),
+    'admin/user/user/advuser', t('This action cannot be undone.'),
+    t('Delete all'), 
+    t('Cancel')
+  );
 }
 
 function advuser_multiple_delete_confirm_submit($form_id, $form_values) {
@@ -291,7 +324,7 @@ function advuser_multiple_delete_confirm
     }
     drupal_set_message(t('The users have been deleted.'));
   }
-  return 'admin/user/advuser';
+  return 'admin/user/user/advuser';
 }
 
 /**
@@ -313,50 +346,61 @@ function advuser_multiple_email_confirm(
   // 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' => '<li>', '#suffix' => check_plain($user) ."</li>\n");
+    $form['accounts'][$uid] = array(
+      '#type' => 'hidden', 
+      '#value' => $uid, 
+      '#prefix' => '<li>', 
+      '#suffix' => check_plain($user) ."</li>\n"
+    );
   }
-  $form['operation'] = array('#type' => 'hidden', '#value' => 'email');
+  $form['operation'] = array(
+    '#type' => 'hidden', 
+    '#value' => 'email'
+  );
 
   $form['variables'] = array(
-      '#type' => 'markup', 
-      '#value' => '<div class="advuser-inset-panel"><strong>Substitution variables</strong> available in subject and email body<br/><em> %username, %site, %uri, %user_email, %google_user (search google for user email), %yahoo_user (search yahoo for user email)</em></div>'
-    );
+    '#type' => 'markup', 
+    '#prefix' => '<div class="advuser-inset-panel">',
+    '#value' => '<strong>Substitution variables</strong> available in subject and email body<br/><em> %username, %site, %uri, %user_email, %google_user (search google for user email), %yahoo_user (search yahoo for user email)</em>',
+    '#suffix' => '</div>' 
+  );
 
   $form['mailsubject'] = array(
-      '#type' => 'textfield',
-      '#title' => t('Subject'),
-      '#required' => TRUE,
-    );
+    '#type' => 'textfield',
+    '#title' => t('Subject'),
+    '#required' => TRUE,
+  );
+
   $form['mailbody'] = array(
-      '#type' => 'textarea', 
-      '#title' => t('Mail body'),
-      '#required' => TRUE,
-    );
+    '#type' => 'textarea', 
+    '#title' => t('Mail body'),
+    '#required' => TRUE,
+  );
 
-  return confirm_form($form,
-                      t('Are you sure you want to email these users?'),
-                      'admin/user/advuser', t('This action cannot be undone.'),
-                      t('Email'), t('Cancel'));
+  return confirm_form(
+    $form,
+    t('Are you sure you want to email these users?'),
+    'admin/user/user/advuser',
+    t('This action cannot be undone.'),
+    t('Email'),
+    t('Cancel')
+  );
 }
 
 function advuser_multiple_email_confirm_submit($form_id, $form_values) {
   if ($form_values['confirm']) {
     foreach ($form_values['accounts'] as $uid => $value) {
       $account = user_load(array('uid' => $uid));
-      if ( module_exists('lightcrm') ) {
-        _lightcrm_comment_add($uid, $edit['mailsubject'], $edit['mailbody']);
-      } else {
-        $from = variable_get("site_mail", ini_get("sendmail_from")); // http://drupal.org/node/77689
-        // these are invariant for all sent emails
-        $variables = _advuser_get_variables($account);
-        $form_values['mailsubject'] = strtr($form_values['mailsubject'], $variables);
-        $form_values['mailbody'] = strtr($form_values['mailbody'], $variables);
-        drupal_mail('advance-user-mail', $account->mail, $form_values['mailsubject'], $form_values['mailbody'], $from);
-      }
+      $from = variable_get("site_mail", ini_get("sendmail_from"));
+      // these are invariant for all sent emails
+      $variables = _advuser_get_variables($account);
+      $form_values['mailsubject'] = strtr($form_values['mailsubject'], $variables);
+      $form_values['mailbody'] = strtr($form_values['mailbody'], $variables);
+      drupal_mail('advance-user-mail', $account->mail, $form_values['mailsubject'], $form_values['mailbody'], $from);
     }
     drupal_set_message(t('The users have been mailed.'));
   }
-  return 'admin/user/advuser';
+  return 'admin/user/user/advuser';
 }
 
 /**
@@ -365,56 +409,59 @@ function advuser_multiple_email_confirm_
 function advuser_settings() {
 
   $form['advuser_mail'] = array(
-      '#type' => 'fieldset',
-      '#title' => t('Mail notifications on user account activity.'),
-      '#collapsible' => FALSE,
-      '#collapsed' => FALSE,
-    );
+    '#type' => 'fieldset',
+    '#title' => t('Mail notifications on user account activity.'),
+    '#collapsible' => FALSE,
+    '#collapsed' => FALSE,
+  );
 
   $form['advuser_mail']['variables'] = array(
-      '#type' => 'markup', 
-      '#value' => '<div class="advuser-inset-panel"><strong>Substitution variables</strong> available in subject and email body<br/><em> %username, %site, %uri, %user_email, %google_user (search google for user email), %yahoo_user (search yahoo for user email)</em></div>'
-    );
+    '#type' => 'markup', 
+    '#value' => '<div class="advuser-inset-panel"><strong>Substitution variables</strong> available in subject and email body<br/><em> %username, %site, %uri, %user_email, %google_user (search google for user email), %yahoo_user (search yahoo for user email)</em></div>'
+  );
 
   //New User Notification
   $form['advuser_mail']['advuser_new_notify'] = array(
-      '#type' => 'checkbox',
-      '#title' => t('Send notifications on new user registration'),
-      '#description' => t('Notify selected roles when new users register.'),
-      '#default_value' => variable_get('advuser_new_notify', ADVUSER_DEFAULT_NEW_NOTIFY),
-    );
+    '#type' => 'checkbox',
+    '#title' => t('Send notifications on new user registration'),
+    '#description' => t('Notify selected roles when new users register.'),
+    '#default_value' => variable_get('advuser_new_notify', ADVUSER_DEFAULT_NEW_NOTIFY),
+  );
+
   $form['advuser_mail']['advuser_new_subject'] = array(
-      '#type' => 'textfield',
-      '#title' => t('Mail subject'),
-      '#description' => t('The subject of the mail that is going to be sent to the user.  You may insert substitution variables within this item.'),
-      '#default_value' => variable_get('advuser_new_subject', ADVUSER_DEFAULT_NEW_SUBJECT),
-    );
+    '#type' => 'textfield',
+    '#title' => t('Mail subject'),
+    '#description' => t('The subject of the mail that is going to be sent to the user.  You may insert substitution variables within this item.'),
+    '#default_value' => variable_get('advuser_new_subject', ADVUSER_DEFAULT_NEW_SUBJECT),
+  );
+
   $form['advuser_mail']['advuser_new_mail'] = array(
-      '#type' => 'textarea',
-      '#title' => t('Mail body'),
-      '#description' => t('The mail that is going to be sent to the selected roles.  You may insert substitution variables within this item.'),
-      '#default_value' => variable_get('advuser_new_mail', ADVUSER_DEFAULT_NEW_MAIL),
-    );
+    '#type' => 'textarea',
+    '#title' => t('Mail body'),
+    '#description' => t('The mail that is going to be sent to the selected roles.  You may insert substitution variables within this item.'),
+    '#default_value' => variable_get('advuser_new_mail', ADVUSER_DEFAULT_NEW_MAIL),
+  );
 
    //User change notification
    $form['advuser_mail']['advuser_modify_notify'] = array(
-      '#type' => 'checkbox',
-      '#title' => t('Send notifications on user profile updates'),
-      '#description' => t('Notify selected roles when users update their profiles.'),
-      '#default_value' => variable_get('advuser_modify_notify', ADVUSER_DEFAULT_MODIFY_NOTIFY),
-    );
+    '#type' => 'checkbox',
+    '#title' => t('Send notifications on user profile updates'),
+    '#description' => t('Notify selected roles when users update their profiles.'),
+    '#default_value' => variable_get('advuser_modify_notify', ADVUSER_DEFAULT_MODIFY_NOTIFY),
+  );
+
   $form['advuser_mail']['advuser_modify_subject'] = array(
-      '#type' => 'textfield',
-      '#title' => t('Mail subject'),
-      '#description' => t('The subject of the mail that is going to be sent when a user modifies their profiles.  You may insert substitution variables within this item.'),
-      '#default_value' => variable_get('advuser_modify_subject', ADVUSER_DEFAULT_MODIFY_SUBJECT),
-    );
+    '#type' => 'textfield',
+    '#title' => t('Mail subject'),
+    '#description' => t('The subject of the mail that is going to be sent when a user modifies their profiles.  You may insert substitution variables within this item.'),
+    '#default_value' => variable_get('advuser_modify_subject', ADVUSER_DEFAULT_MODIFY_SUBJECT),
+  );
   $form['advuser_mail']['advuser_modify_mail'] = array(
-      '#type' => 'textarea',
-      '#title' => t('Mail body'),
-      '#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', ADVUSER_DEFAULT_MODIFY_MAIL),
-    );
+    '#type' => 'textarea',
+    '#title' => t('Mail body'),
+    '#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', ADVUSER_DEFAULT_MODIFY_MAIL),
+  );
         
     //Maximum rows in dataset to display
     $form['advuser_mail']['advuser_listno'] = array(
@@ -436,12 +483,12 @@ function advuser_settings() {
     }
   }
   $form['advuser_mailonnew']['advuser_new_roles'] = array(
-      '#type' => 'checkboxes',
-      '#title' => t('Notification Roles'),
-      '#description' => t('Roles that receive email notifications.'),
-      '#options' => $roles,
-      '#default_value' => $values,
-    );
+    '#type' => 'checkboxes',
+    '#title' => t('Notification Roles'),
+    '#description' => t('Roles that receive email notifications.'),
+    '#options' => $roles,
+    '#default_value' => $values,
+  );
 
   if ($sel_roles_count == 0) {
     $form['advuser_mailonnew']['no_roles_sel_warning'] = array(
@@ -510,25 +557,36 @@ function _advuser_get_variables(&$user) 
  * in roles.  
  */
 function _advuser_get_roles_query_fragment($roles) {
-  // TODO: this needs to be cleaned up.
   if (is_array($roles) ) {
+    $c = NULL;
     foreach ((array)$roles as $role_k => $role_v) {
       if ( $role_v > 0 ) {
         if ( $role_v == DRUPAL_AUTHENTICATED_RID ) {
-          $role_where = ' OR 1';
+          $role_where .= $c . '1';
         }
          else {
-          $role_where = ' OR ur.rid = '. $role_v;
+          $role_where .= $c . $role_v;
         }
+        $c = ', ';
       }
     }
   }
+  if (!empty($role_where)) {
+    $role_where = 'ur.rid IN ('.$role_where.')';
+  }
   return $role_where;
 }
 
+/**
+ * @private
+ * Return a list of users to send notification of user changes.
+ *
+ * @param string $role      // The specified role to send mail to.
+ * @return resource         // The result of the db_query.
+ */
 function _advuser_dbquery_users_to_notify($roles) {
   $role_where = _advuser_get_roles_query_fragment($roles);
-  return db_query('SELECT u.mail, u.name FROM {users} u LEFT JOIN {users_roles} ur on u.uid = ur.uid WHERE 0 '. $role_where );
+  return db_query('SELECT u.mail, u.name FROM {users} u LEFT JOIN {users_roles} ur on u.uid = ur.uid '. (empty($role_where) ? NULL : 'WHERE '. $role_where) );
 }
 
 
Index: advuser_filters.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/advuser/Attic/advuser_filters.inc,v
retrieving revision 1.1.2.3
diff -u -p -r1.1.2.3 advuser_filters.inc
--- advuser_filters.inc	17 Mar 2008 22:06:21 -0000	1.1.2.3
+++ advuser_filters.inc	18 Mar 2008 20:48:00 -0000
@@ -426,7 +426,7 @@ function advuser_build_filter_query() {
 function advuser_filter_form_submit($form_id, $form_values) {
   $op = $form_values['op'];
   $filters = advuser_filters();
-  $ret = 'admin/user/advuser';
+  $ret = 'admin/user/user/advuser';
 
   switch ($op) {
     case t('Filter'):
