Index: inactive_user.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/inactive_user/inactive_user.install,v
retrieving revision 1.2
diff -u -r1.2 inactive_user.install
--- inactive_user.install	29 May 2009 17:47:52 -0000	1.2
+++ inactive_user.install	19 Aug 2009 20:09:16 -0000
@@ -26,6 +26,27 @@
           'unsigned' => TRUE,
           'not null' => TRUE,
           'default' => 0),
+        'never_returned' => array(
+          'description' => t('never_returned.'),
+          'type' => 'int',
+          'size' => 'tiny',
+          'unsigned' => TRUE,
+          'not null' => TRUE,
+          'default' => 0),
+        'notified_never_return_user' => array(
+          'description' => t('never_returned user notifier.'),
+          'type' => 'int',
+          'size' => 'tiny',
+          'unsigned' => TRUE,
+          'not null' => TRUE,
+          'default' => 0),
+        'notified_never_return_admin' => array(
+          'description' => t('never_returned admin notifier.'),
+          'type' => 'int',
+          'size' => 'tiny',
+          'unsigned' => TRUE,
+          'not null' => TRUE,
+          'default' => 0),
         'notified_admin' => array(
           'description' => t('Admin notifier.'),
           'type' => 'int',
@@ -84,6 +105,11 @@
  */
 function inactive_user_uninstall() {
   drupal_uninstall_schema('inactive_user');
+  variable_del('inactive_user_never_returned_grace_period');
+  variable_del('inactive_user_never_returned_notify_admin');
+  variable_del('inactive_user_never_returned_user_notify');
+  variable_del('inactive_user_never_returned_user_notify_text');
+  variable_del('inactive_user_never_logged_in_auto_delete');
   variable_del('inactive_user_admin_email');
   variable_del('inactive_user_auto_block');
   variable_del('inactive_user_auto_block_warn');
@@ -108,3 +134,42 @@
   }
   drupal_set_message(t('Inactive user has been uninstalled.'));
 }
+
+/**
+ * Add fields never_returned, notified_never_return_user, notified_never_return_admin 
+ * to manage users who never used their accounts
+ */
+function inactive_user_update_6000() {
+  $ret = array();
+  db_add_field($ret, 'inactive_users', 'never_returned', 
+    array(
+      'description' => t('never_returned.'),
+      'type' => 'int',
+      'size' => 'tiny',
+      'unsigned' => TRUE,
+      'not null' => TRUE,
+      'default' => 0
+    )
+  );
+  db_add_field($ret, 'inactive_users', 'notified_never_return_user', 
+    array(
+      'description' => t('never_returned user notifier.'),
+      'type' => 'int',
+      'size' => 'tiny',
+      'unsigned' => TRUE,
+      'not null' => TRUE,
+      'default' => 0
+    )
+  );
+  db_add_field($ret, 'inactive_users', 'notified_never_return_admin', 
+    array(
+      'description' => t('never_returned admin notifier.'),
+      'type' => 'int',
+      'size' => 'tiny',
+      'unsigned' => TRUE,
+      'not null' => TRUE,
+      'default' => 0
+    )
+  );
+  return $ret;
+}
Index: inactive_user.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/inactive_user/inactive_user.module,v
retrieving revision 1.9
diff -u -r1.9 inactive_user.module
--- inactive_user.module	11 Jun 2009 19:27:33 -0000	1.9
+++ inactive_user.module	19 Aug 2009 20:06:33 -0000
@@ -51,7 +51,9 @@
 function inactive_user_custom_settings() {
   $period = array(0 => 'disabled') + drupal_map_assoc(array(604800, 1209600, 1814400, 2419200, 2592000, 7776000, 15552000, 23328000, 31536000, 47088000, 63072000), '_format_interval');
   $warn_period = array(0 => 'disabled') + drupal_map_assoc(array(86400, 172800, 259200, 604800, 1209600, 1814400, 2592000), '_format_interval');
-  $mail_variables = ' %username, %useremail, %lastaccess, %period, %sitename, %siteurl';
+  $mail_variables = ' %username, %useremail, %lastaccess, %period, @sitename, %siteurl';
+  $grace_period = $period;	//for never-returned users
+  unset ( $grace_period[0] );		// assures that users newer than 1 week will never be notified
 
   // set administrator e-mail
   $form['inactive_user_admin_email_fieldset'] = array(
@@ -68,7 +70,50 @@
     '#maxlength' => 256,
     '#required' => TRUE,
   );
-
+  
+  // notification of never-returned user
+    $form['inactive_user_never_returned_notification'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Never-returned user notification'),
+      '#collapsible' => TRUE,
+      '#collapsed' => FALSE,
+    );
+    $form['inactive_user_never_returned_notification']['inactive_user_never_returned_notify_admin'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Notify administrator when a user has never logged in.'),
+      '#default_value' => variable_get('inactive_user_never_returned_notify_admin', 0),
+      '#description' => t('Generate an email to notify the site administrator that a user account has never been used after registration.  Requires crontab.'),
+    );
+    $form['inactive_user_never_returned_notification']['inactive_user_never_returned_user_notify'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Notify users when they have never logged in.'),
+      '#default_value' => variable_get('inactive_user_never_returned_user_notify', 0),
+      '#description' => t('Generate an email to notify users when they have never used their account after registration.  Requires crontab.'),
+    );
+    $form['inactive_user_never_returned_notification']['inactive_user_never_returned_grace_period'] = array(
+      '#type' => 'select',
+      '#title' => t('Don\'t notify about users newer than'),
+      '#default_value' => variable_get('inactive_user_never_returned_grace_period', 604800),
+      '#options' => $grace_period,
+      '#description' => t('Allows notification of users whose accounts have been created before the set time. Defaults to one week. Setting this period to zero is not allowed, to avoid notification of newly created users. Requires crontab.'),
+    );
+    $form['inactive_user_never_returned_notification']['inactive_user_never_returned_user_notify_text'] = array(
+      '#type' => 'textarea',
+      '#title' => t('Body of user notification e-mail'),
+      '#default_value' => variable_get('inactive_user_never_returned_user_notify_text', _inactive_user_mail_text('never_returned_notify_text')),
+      '#cols' => 70,
+      '#rows' => 10,
+      '#description' => t('Customize the body of the notification e-mail sent to the user.') . ' ' . t('Available variables are:') . $mail_variables,
+      '#required' => TRUE,
+    );
+    $form['inactive_user_never_returned_notification']['inactive_user_never_logged_in_auto_delete'] = array(
+      '#type' => 'select',
+      '#title' => t('Delete users that have never returned, and the account is older than'),
+      '#default_value' => variable_get('inactive_user_never_logged_in_auto_delete', 0),
+      '#options' => $period,
+      '#description' => t('Automatically delete user accounts that have never logged in, and account was created longer than the specified time.  Warning, user accounts are permanently deleted, with no ability to undo the action!  Requires crontab.'),
+    );
+  
   // inactive user notification
   $form['inactive_user_notification'] = array(
     '#type' => 'fieldset',
@@ -237,7 +282,7 @@
     unset($user_list);
 
     // reset notifications if recent user activity
-    $users = db_fetch_object(db_query('SELECT uid FROM {inactive_users} WHERE uid <> 1'));
+    $users = db_fetch_object(db_query('SELECT uid FROM {inactive_users} WHERE uid > 1'));
     if ($users) {
       foreach ($users as $uid) {
         $u = db_fetch_object(db_query('SELECT access, name FROM {users} WHERE uid = %d', $uid));
@@ -249,9 +294,44 @@
       }
     }
 
+     // notify administrator of never-returned user accounts (doesn't send e-mails for a week after registration)
+    if ( variable_get('inactive_user_never_returned_notify_admin', 0) && $grace_time = variable_get('inactive_user_never_returned_grace_period', 604800) ) {
+      $result = db_query('SELECT uid, name, mail, access, login, created FROM {users} WHERE ( access = 0 or login = 0 ) && NOT (uid=1) and created < %d ORDER BY uid ASC', time() - $grace_time);
+      while ($user = db_fetch_object($result)) {
+        if ($user->uid && !db_fetch_object(db_query('SELECT uid FROM {inactive_users} WHERE uid = %d AND notified_never_return_admin = 1 and never_returned = 1', $user->uid)) ) {
+          
+          db_query('UPDATE {inactive_users} SET notified_never_return_admin = 1, never_returned = 1 WHERE uid = %d', $user->uid);
+          if (!db_affected_rows()) {
+            // must create a new row
+            @db_query('INSERT INTO {inactive_users} (uid, notified_never_return_admin, never_returned) VALUES(%d, 1, 1)', $user->uid);
+          }
+          $user_list .= "$user->uid $user->name ($user->mail)\n";
+        }
+      }
+      if ($user_list) {
+        _inactive_user_mail(t('[@sitename] Never-returned users', array('@sitename' => variable_get('site_name', 'drupal'))), _inactive_user_mail_text('never_returned_notify_admin_text'), $notify_time, NULL, $user_list);
+        unset($user_list);
+      }
+    }
+ 
+    // notify users that their account has never been used (doesn't send e-mails for a week after registration)
+    if ( variable_get('inactive_user_never_returned_user_notify', 0) && $grace_time = variable_get('inactive_user_never_returned_grace_period', 604800) ) {
+      $result = db_query('SELECT uid, name, mail, access, login, created FROM {users} WHERE ( access = 0 or login = 0 ) AND status != 0 AND NOT (uid=1)  and created < %d', time() - $grace_time);
+      while ($user = db_fetch_object($result)) {
+        if ($user->uid && !db_fetch_object(db_query('SELECT uid FROM {inactive_users} WHERE notified_never_return_user = 1 and never_returned = 1 AND uid = %d', $user->uid)) ) {
+          db_query('UPDATE {inactive_users} SET notified_never_return_user = 1, never_returned = 1 WHERE uid = %d', $user->uid);
+          if (!db_affected_rows()) {
+            @db_query('INSERT INTO {inactive_users} (uid, notified_never_return_user, never_returned) VALUES(%d, 1, 1)', $user->uid);
+          }
+          _inactive_user_mail(t('[@sitename] Never-used account', array('@sitename' => variable_get('site_name', 'drupal'))), variable_get('inactive_user_never_returned_user_notify_text', _inactive_user_mail_text('never_returned_notify_text')), $notify_time, $user, NULL);
+          watchdog('user', t('user %user notified of never-used account', array('%user' => $user->name)), WATCHDOG_NOTICE, l(t('edit user'), "admin/user/edit/$uid"));
+        }
+      }
+    }
+
     // notify administrator of inactive user accounts
     if ($notify_time = variable_get('inactive_user_notify_admin', 0)) {
-      $result = db_query('SELECT uid, name, mail, access, created FROM {users} WHERE ((access <> 0 AND login <> 0 AND access < (%d - %d)) OR (login = 0 AND created < (%d - %d))) AND uid <> 1', time(), $notify_time, time(), $notify_time);
+      $result = db_query('SELECT uid, name, mail, access, created FROM {users} WHERE ((access <> 0 AND login <> 0 AND access < (%d - %d)) OR (login = 0 AND created < (%d - %d))) AND uid > 1', time(), $notify_time, time(), $notify_time);
       while ($user = db_fetch_object($result)) {
         if ($user->uid && !db_fetch_object(db_query('SELECT uid FROM {inactive_users} WHERE uid = %d AND notified_admin = 1', $user->uid)) && ($user->created < (time() - $notify_time))) {
           db_query('UPDATE {inactive_users} SET notified_admin = 1 WHERE uid = %d', $user->uid);
@@ -270,7 +350,7 @@
 
     // notify users that their account has been inactive
     if ($notify_time = variable_get('inactive_user_notify', 0)) {
-      $result = db_query('SELECT * FROM {users} WHERE ((access <> 0 AND login <> 0 AND access < (%d - %d)) OR (login = 0 AND created < (%d - %d))) AND status <> 0 AND uid <> 1', time(), $notify_time, time(), $notify_time);
+      $result = db_query('SELECT * FROM {users} WHERE ((access <> 0 AND login <> 0 AND access < (%d - %d)) OR (login = 0 AND created < (%d - %d))) AND status <> 0 AND uid > 1', time(), $notify_time, time(), $notify_time);
       while ($user = db_fetch_object($result)) {
         if ($user->uid && !db_fetch_object(db_query('SELECT uid FROM {inactive_users} WHERE notified_user = 1 AND uid = %d', $user->uid)) && ($user->created < (time() - $notify_time))) {
           db_query('UPDATE {inactive_users} SET notified_user = 1 WHERE uid = %d', $user->uid);
@@ -286,7 +366,7 @@
     // warn users when they are about to be blocked
     if (($warn_time = variable_get('inactive_user_auto_block_warn', 0)) &&
         ($block_time = variable_get('inactive_user_auto_block', 0))) {
-      $result = db_query('SELECT * FROM {users} WHERE ((access <> 0 AND login <> 0 AND access < (%d - %d - %d)) OR (login = 0 AND created < (%d - %d - %d))) AND status <> 0 AND uid <> 1', time(), $warn_time, $block_time, time(), $warn_time, $block_time);
+      $result = db_query('SELECT * FROM {users} WHERE ((access <> 0 AND login <> 0 AND access < (%d - %d - %d)) OR (login = 0 AND created < (%d - %d - %d))) AND status <> 0 AND uid > 1', time(), $warn_time, $block_time, time(), $warn_time, $block_time);
       while ($user = db_fetch_object($result)) {
         if ($user->uid && !db_fetch_object(db_query('SELECT uid FROM {inactive_users} WHERE uid = %d AND warned_user_block_timestamp > 0', $user->uid)) && ($user->created < (time() - $warn_time - $block_time))) {
           db_query('UPDATE {inactive_users} SET warned_user_block_timestamp = %d WHERE uid = %d', time() + $warn_time, $user->uid);
@@ -301,7 +381,7 @@
 
     // automatically block users
     if ($block_time = variable_get('inactive_user_auto_block', 0)) {
-      $result = db_query('SELECT * FROM {users} WHERE ((access <> 0 AND login <> 0 AND access < (%d - %d)) OR (login = 0 AND created < (%d - %d))) AND status <> 0 AND uid <> 1', time(), $block_time, time(), $block_time);
+      $result = db_query('SELECT * FROM {users} WHERE ((access <> 0 AND login <> 0 AND access < (%d - %d)) OR (login = 0 AND created < (%d - %d))) AND status <> 0 AND uid > 1', time(), $block_time, time(), $block_time);
       while ($user = db_fetch_object($result)) {
         // don't block user yet if we sent a warning and it hasn't expired
         if ($user->uid && db_fetch_object(db_query('SELECT uid FROM {inactive_users} WHERE uid = %d AND warned_user_block_timestamp < %d', $user->uid, time())) && ($user->created < (time() - $block_time))) {
@@ -340,7 +420,7 @@
     // warn users when they are about to be deleted
     if (($warn_time = variable_get('inactive_user_auto_delete_warn', 0)) &&
         ($delete_time = variable_get('inactive_user_auto_delete', 0))) {
-      $result = db_query('SELECT * FROM {users} WHERE ((access <> 0 AND login <> 0 AND access < (%d - %d - %d)) OR (login = 0 AND created < (%d - %d - %d))) AND uid <> 1', time(), $warn_time, $delete_time, time(), $warn_time, $delete_time);
+      $result = db_query('SELECT * FROM {users} WHERE ((access <> 0 AND login <> 0 AND access < (%d - %d - %d)) OR (login = 0 AND created < (%d - %d - %d))) AND uid > 1', time(), $warn_time, $delete_time, time(), $warn_time, $delete_time);
       while ($user = db_fetch_object($result)) {
         if ($user->uid && !db_fetch_object(db_query('SELECT uid FROM {inactive_users} WHERE uid = %d AND warned_user_delete_timestamp > 0', $user->uid)) && ($user->created < (time() - $warn_time - $delete_time))) {
           if (variable_get('inactive_user_preserve_content', 1) && _inactive_user_with_content($user->uid)) {
@@ -363,9 +443,9 @@
 
     // automatically delete users
     if ($delete_time = variable_get('inactive_user_auto_delete', 0)) {
-      $result = db_query('SELECT * FROM {users} WHERE ((access <> 0 AND login <> 0 AND access < (%d - %d)) OR (login = 0 AND created < (%d - %d))) AND uid <> 1', time(), $delete_time, time(), $delete_time);
+      $result = db_query('SELECT * FROM {users} WHERE ((access <> 0 AND login <> 0 AND access < (%d - %d)) OR (login = 0 AND created < (%d - %d))) AND uid > 1', time(), $delete_time, time(), $delete_time);
       while ($user = db_fetch_object($result)) {
-        if ($user->uid && ((variable_get('inactive_user_auto_delete_warn', 0) && db_fetch_object(db_query('SELECT uid FROM {inactive_users} WHERE uid = %d AND warned_user_delete_timestamp < %d AND protected <> 1', $user->uid, time()))) || (!variable_get('inactive_user_auto_delete_warn', 0))) && ($user->created < (time() - $delete_time))) {
+        if ($user->uid && ((variable_get('inactive_user_auto_delete_warn', 0) && db_fetch_object(db_query('SELECT uid FROM {inactive_users} WHERE uid = %d AND warned_user_delete_timestamp < %d AND protected > 1', $user->uid, time()))) || (!variable_get('inactive_user_auto_delete_warn', 0))) && ($user->created < (time() - $delete_time))) {
           if (variable_get('inactive_user_preserve_content', 1) && _inactive_user_with_content($user->uid)) {
             // this is a protected user, mark as such
             db_query('UPDATE {inactive_users} SET protected = 1 WHERE uid = %d', $user->uid);
@@ -397,7 +477,21 @@
         unset($user_list);
       }
     }
-  }
+
+   	 // automatically delete never logged in users
+    if ($delete_time = variable_get('inactive_user_never_logged_in_auto_delete', 0)) {
+      $result = db_query('SELECT * FROM {users} WHERE access = 0 AND ((%d - created ) > %d) AND NOT (uid=1)', time(), $delete_time);
+      while ($user = db_fetch_object($result)) 
+      	{
+            // delete the user
+            $array = (array) $user;
+            db_query("DELETE FROM {users} WHERE uid = %d", $user->uid);
+            db_query("DELETE FROM {authmap} WHERE uid = %d", $user->uid);
+            module_invoke_all('user', 'delete', $array, $user);
+            watchdog('user', t('user %user deleted due to never having logged int', array('%user' => $user->name)));
+        }
+    }
+  } 
 }
 
 /**
@@ -485,6 +579,12 @@
  */
 function _inactive_user_mail_text($message) {
   switch ($message) {
+    case 'never_returned_notify_text':
+      return t("Hello %username,\n\n  We haven't seen you at @sitename since you first registered. Please come back and activate your account soon at %siteurl.\n\nSincerely,\n  @sitename team");
+      break;
+    case 'never_returned_notify_admin_text':
+      return t("Hello,\n\n  This automatic notification is to inform you that the following users have never been seen on @sitename since they first registered:\n\n%userlist");
+      break;
     case 'notify_text':
       return t("Hello %username,\n\n  We haven't seen you at %sitename since %lastaccess, and we miss you!  Please come back and visit us soon at %siteurl.\n\nSincerely,\n  %sitename team");
       break;

