? 162176-25.patch
Index: inactive_user.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/inactive_user/inactive_user.install,v
retrieving revision 1.2
diff -u -p -r1.2 inactive_user.install
--- inactive_user.install	29 May 2009 17:47:52 -0000	1.2
+++ inactive_user.install	11 Aug 2009 21:07:43 -0000
@@ -26,6 +26,27 @@ function inactive_user_schema() {
           '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,10 @@ function inactive_user_schema() {
  */
 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_admin_email');
   variable_del('inactive_user_auto_block');
   variable_del('inactive_user_auto_block_warn');
@@ -108,3 +133,20 @@ function inactive_user_uninstall() {
   }
   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_1() {
+  $ret = array();
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      $ret[] = update_sql("ALTER TABLE {inactive_users} 
+         ADD never_returned INT( 1 ) UNSIGNED NOT NULL DEFAULT '0' AFTER uid,
+         ADD notified_never_return_user INT( 1 ) UNSIGNED NOT NULL DEFAULT '0' AFTER never_returned,
+         ADD notified_never_return_admin INT( 1 ) UNSIGNED NOT NULL DEFAULT '0' AFTER notified_never_return_user;");
+      return $ret;
+    break;
+  }
+}
Index: inactive_user.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/inactive_user/inactive_user.module,v
retrieving revision 1.9
diff -u -p -r1.9 inactive_user.module
--- inactive_user.module	11 Jun 2009 19:27:33 -0000	1.9
+++ inactive_user.module	11 Aug 2009 21:07:44 -0000
@@ -51,7 +51,9 @@ function inactive_user_menu() {
 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 @@ function inactive_user_custom_settings()
     '#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']['never_logged_in_user_auto_delete'] = array(
+      '#type' => 'select',
+      '#title' => t('Delete users that have never returned, and the account is older than'),
+      '#default_value' => variable_get('never_logged_in_user_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',
@@ -249,6 +294,41 @@ function inactive_user_cron() {
       }
     }
 
+     // 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);
@@ -397,7 +477,21 @@ function inactive_user_cron() {
         unset($user_list);
       }
     }
-  }
+
+   	 // automatically delete never logged in users
+    if ($delete_time = variable_get('never_logged_in_user_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($subject, $
  */
 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;
