? diff.patch
Index: force_password_change.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/force_password_change/force_password_change.install,v
retrieving revision 1.3.4.1
diff -u -p -r1.3.4.1 force_password_change.install
--- force_password_change.install	29 Jun 2010 08:38:41 -0000	1.3.4.1
+++ force_password_change.install	5 Aug 2010 21:43:30 -0000
@@ -5,355 +5,293 @@
 /**
  * Implementation of hook_install()
  */
-function force_password_change_install()
-{
-	// Install the module schema
-	drupal_install_schema('force_password_change');
-	
-	// Create a row each user in the {force_password_change_users} table
-	$query1 = 'INSERT INTO {force_password_change_users} (uid) VALUES ';
-	$query2 = '';
-	$arguments = array();
-	$uids = db_query('SELECT uid FROM {users} WHERE uid > 0');
-	while($uid = db_fetch_array($uids))
-	{
-		if(strlen($query2))
-		{
-			$query2 .= ', ';
-		}
-		$query2 .= '(%d)';
-		$arguments[] = $uid['uid'];
-	}
-	db_query($query1 . $query2, $arguments);
-	
-	// Create a row for each role in the {force_password_change_roles} table
-	$query1 = 'INSERT INTO {force_password_change_roles} (rid) VALUES ';
-	$query2 = '';
-	$arguments = array();
-	$rids = db_query('SELECT rid FROM {role} WHERE rid > 1');
-	while($rid = db_fetch_array($rids))
-	{
-		if(strlen($query2))
-		{
-			$query2 .= ', ';
-		}
-		$query2 .= '(%d)';
-		$arguments[] = $rid['rid'];
-	}
-	db_query($query1 . $query2, $arguments);
-	
-	// Create a new column in the users table to indicate a required forced password change
-	// This is added here rather than in the {force_password_change_users} table so that the value is loaded
-	// during the bootstrap process
-	$ret = array();
-	db_add_field
-	(
-		$ret,
-		'users',
-		'force_password_change',
-		array
-		(
-			'type' => 'int',
-			'length' => 1,
-			'default' => 0,
-		),
-		array
-		(
-			'indexes' => array
-			(
-				'user_force_password' => array('uid', 'force_password_change'),
-			),
-		)
-	);
-	
-	// Set a variable indicating the module installation date. This is used in hook_user() to compare the users signup date with the module installation date
-	// to see if they were required to change their password upon first time login. Users who signed up before this variable was set will of course not have
-	// bee required to change their password upon first time login.
-	variable_set('force_password_change_installation_date', time());
-	return $ret;
+function force_password_change_install() {
+  // Install the module schema
+  drupal_install_schema('force_password_change');
+  
+  // Create a row each user in the {force_password_change_users} table
+  $query1 = 'INSERT INTO {force_password_change_users} (uid) VALUES ';
+  $query2 = '';
+  $arguments = array();
+  $uids = db_query('SELECT uid FROM {users} WHERE uid > 0');
+  while($uid = db_fetch_array($uids)) {
+    if (strlen($query2)) {
+      $query2 .= ', ';
+    }
+    $query2 .= '(%d)';
+    $arguments[] = $uid['uid'];
+  }
+  db_query($query1 . $query2, $arguments);
+  
+  // Create a row for each role in the {force_password_change_roles} table
+  $query1 = 'INSERT INTO {force_password_change_roles} (rid) VALUES ';
+  $query2 = '';
+  $arguments = array();
+  $rids = db_query('SELECT rid FROM {role} WHERE rid > 1');
+  while($rid = db_fetch_array($rids)) {
+    if (strlen($query2)) {
+      $query2 .= ', ';
+    }
+    $query2 .= '(%d)';
+    $arguments[] = $rid['rid'];
+  }
+  db_query($query1 . $query2, $arguments);
+  
+  // Create a new column in the users table to indicate a required forced password change
+  // This is added here rather than in the {force_password_change_users} table so that the value is loaded
+  // during the bootstrap process
+  $ret = array();
+  db_add_field(
+    $ret,
+    'users',
+    'force_password_change',
+    array(
+      'type' => 'int',
+      'length' => 1,
+      'default' => 0,
+    ),
+    array(
+      'indexes' => array(
+        'user_force_password' => array('uid', 'force_password_change'),
+      ),
+    )
+  );
+  
+  // Set a variable indicating the module installation date. This is used in hook_user() to compare the users signup date with the module installation date
+  // to see if they were required to change their password upon first time login. Users who signed up before this variable was set will of course not have
+  // bee required to change their password upon first time login.
+  variable_set('force_password_change_installation_date', time());
+  return $ret;
 }
 
 /**
  * Implementation of hook_uninstall()
  */
-function force_password_change_uninstall()
-{
-	variable_del('force_password_change_installation_date');
-	$ret = array();
-	db_drop_index
-	(
-		$ret,
-		'users',
-		'user_force_password'
-	);
-	db_drop_field
-	(
-		$ret,
-		'users',
-		'force_password_change'
-	);
-	drupal_uninstall_schema('force_password_change');
-	return $ret;
+function force_password_change_uninstall() {
+  variable_del('force_password_change_installation_date');
+  $ret = array();
+  db_drop_index($ret, 'users', 'user_force_password');
+  db_drop_field($ret, 'users', 'force_password_change');
+  drupal_uninstall_schema('force_password_change');
+  return $ret;
 }
 
 /**
  * Implementation of hook_schema()
  */
-function force_password_change_schema()
-{
-	$schema['force_password_change_users'] = array
-	(
-		'description' => t('Holds password change data for users'),
-		'fields' => array
-		(
-			'uid' => array
-			(
-				'description' => t('The UID from the {users} table'),
-				'type' => 'int',
-				'unsigned' => TRUE,
-				'not null' => TRUE,
-			),
-			'last_password_change' => array
-			(
-				'description' => t('A UNIX timestamp referring to the date that the user last changed their password'),
-				'type' => 'int',
-				'unsigned' => TRUE,
-				'length' => 10,
-				'default' => NULL,
-			),
-			'last_force' => array
-			(
-				'description' => t('A UNIX timestamp referring to the last date on which the user was forced to change their password'),
-				'type' => 'int',
-				'unsigned' => TRUE,
-				'length' => 10,
-				'default' => NULL,
-			),
-		),
-		'primary key' => array('uid'),
-	);
-	$schema['force_password_change_roles'] = array
-	(
-		'description' => t('Holds the time of the last forced password change by role'),
-		'fields' => array
-		(
-			'rid' => array
-			(
-				'description' => t('The RID from the {role} table'),
-				'type' => 'int',
-				'unsigned' => TRUE,
-				'not null' => TRUE,
-			),
-			'last_force' => array
-			(
-				'description' => t('A UNIX timestamp referring to the last date on which users in the role were forced to change their password'),
-				'type' => 'int',
-				'unsigned' => TRUE,
-				'length' => 10,
-			),
-		),
-		'primary key' => array('rid'),
-	);
-	$schema['force_password_change_expiry'] = array
-	(
-		'description' => t('Holds information related to the expiry of passwords by role'),
-		'fields' => array
-		(
-			'rid' => array
-			(
-				'description' => t('The RID from the {role} table'),
-				'type' => 'int',
-				'unsigned' => TRUE,
-				'default' => NULL,
-			),
-			'expiry' => array
-			(
-				'description' => t('The number of seconds after which a user will be forced to reset their password'),
-				'type' => 'int',
-				'unsigned' => TRUE,
-				'default' => 0,
-			),
-			'weight' => array
-			(
-				'description' => t('Allows for priorities to be applied to password expirations'),
-				'type' => 'int',
-				'default' => 0,
-			),
-		),
-		'primary key' => array('rid'),
-	);
-	return $schema;
+function force_password_change_schema() {
+  $schema['force_password_change_users'] = array(
+    'description' => t('Holds password change data for users'),
+    'fields' => array(
+      'uid' => array(
+        'description' => t('The UID from the {users} table'),
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+      ),
+      'last_password_change' => array(
+        'description' => t('A UNIX timestamp referring to the date that the user last changed their password'),
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'length' => 10,
+        'default' => NULL,
+      ),
+      'last_force' => array(
+        'description' => t('A UNIX timestamp referring to the last date on which the user was forced to change their password'),
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'length' => 10,
+        'default' => NULL,
+      ),
+    ),
+    'primary key' => array('uid'),
+  );
+  $schema['force_password_change_roles'] = array(
+    'description' => t('Holds the time of the last forced password change by role'),
+    'fields' => array(
+      'rid' => array(
+        'description' => t('The RID from the {role} table'),
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+      ),
+      'last_force' => array(
+        'description' => t('A UNIX timestamp referring to the last date on which users in the role were forced to change their password'),
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'length' => 10,
+      ),
+    ),
+    'primary key' => array('rid'),
+  );
+  $schema['force_password_change_expiry'] = array(
+    'description' => t('Holds information related to the expiry of passwords by role'),
+    'fields' => array(
+      'rid' => array(
+        'description' => t('The RID from the {role} table'),
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'default' => NULL,
+      ),
+      'expiry' => array(
+        'description' => t('The number of seconds after which a user will be forced to reset their password'),
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'default' => 0,
+      ),
+      'weight' => array(
+        'description' => t('Allows for priorities to be applied to password expirations'),
+        'type' => 'int',
+        'default' => 0,
+      ),
+    ),
+    'primary key' => array('rid'),
+  );
+  return $schema;
 }
 
 /**
  * Implementation of hook_schema_alter()
  */
-function force_password_change_schema_alter(&$schema)
-{
-	$schema['users']['fields']['force_password_change'] = array
-	(
-		'type' => 'int',
-		'length' => 1,
-		'default' => 0,
-	);
-	$schema['users']['indexes']['user_force_password'] = array('uid', 'force_password_change');
+function force_password_change_schema_alter(&$schema) {
+  $schema['users']['fields']['force_password_change'] = array(
+    'type' => 'int',
+    'length' => 1,
+    'default' => 0,
+  );
+  $schema['users']['indexes']['user_force_password'] = array('uid', 'force_password_change');
 }
 
 /**
  * Implementation of hook_update_N()
  */
-function force_password_change_update_6200()
-{
-	// Set a variable indicating the module installation date. This is used in hook_user() to compare the users signup date with the module installation date
-	// to see if they were required to change their password upon first time login. Users who signed up before this variable was set will of course not have
-	// bee required to change their password upon first time login.
-	variable_set('force_password_change_installation_date', time());
+function force_password_change_update_6200() {
+  // Set a variable indicating the module installation date. This is used in hook_user() to compare the users signup date with the module installation date
+  // to see if they were required to change their password upon first time login. Users who signed up before this variable was set will of course not have
+  // bee required to change their password upon first time login.
+  variable_set('force_password_change_installation_date', time());
 
-	$ret = array();
-	db_create_table
-	(
-		$ret,
-		'force_password_change_users',
-		array
-		(
-			'description' => t('Holds password change data for users'),
-			'fields' => array
-			(
-				'uid' => array
-				(
-					'description' => t('The UID from the {users} table'),
-					'type' => 'int',
-					'unsigned' => TRUE,
-					'not null' => TRUE,
-				),
-				'last_password_change' => array
-				(
-					'description' => t('A UNIX timestamp referring to the date that the user last changed their password'),
-					'type' => 'int',
-					'unsigned' => TRUE,
-					'length' => 10,
-				),
-				'last_force' => array
-				(
-					'description' => t('A UNIX timestamp referring to the last date on which the user was forced to change their password'),
-					'type' => 'int',
-					'unsigned' => TRUE,
-					'length' => 10,
-				),
-			),
-			'primary_key' => array('uid'),
-		)
-	);
-	db_create_table
-	(
-		$ret,
-		'force_password_change_roles',
-		array
-		(
-			'description' => t('Holds the time of the last forced password change by role'),
-			'fields' => array
-			(
-				'rid' => array
-				(
-					'description' => t('The RID from the {role} table'),
-					'type' => 'int',
-					'unsigned' => TRUE,
-					'not null' => TRUE,
-				),
-				'last_force' => array
-				(
-					'description' => t('A UNIX timestamp referring to the last date on which users in the role were forced to change their password'),
-					'type' => 'int',
-					'unsigned' => TRUE,
-					'length' => 10,
-				),
-			),
-			'primary key' => array('rid'),
-		)
-	);
-	
-	return $ret;
+  $ret = array();
+  db_create_table(
+    $ret,
+    'force_password_change_users',
+    array(
+      'description' => t('Holds password change data for users'),
+      'fields' => array(
+        'uid' => array(
+          'description' => t('The UID from the {users} table'),
+          'type' => 'int',
+          'unsigned' => TRUE,
+          'not null' => TRUE,
+        ),
+        'last_password_change' => array(
+          'description' => t('A UNIX timestamp referring to the date that the user last changed their password'),
+          'type' => 'int',
+          'unsigned' => TRUE,
+          'length' => 10,
+        ),
+        'last_force' => array(
+          'description' => t('A UNIX timestamp referring to the last date on which the user was forced to change their password'),
+          'type' => 'int',
+          'unsigned' => TRUE,
+          'length' => 10,
+        ),
+      ),
+      'primary_key' => array('uid'),
+    )
+  );
+  db_create_table(
+    $ret,
+    'force_password_change_roles',
+    array(
+      'description' => t('Holds the time of the last forced password change by role'),
+      'fields' => array(
+        'rid' => array(
+          'description' => t('The RID from the {role} table'),
+          'type' => 'int',
+          'unsigned' => TRUE,
+          'not null' => TRUE,
+        ),
+        'last_force' => array(
+          'description' => t('A UNIX timestamp referring to the last date on which users in the role were forced to change their password'),
+          'type' => 'int',
+          'unsigned' => TRUE,
+          'length' => 10,
+        ),
+      ),
+      'primary key' => array('rid'),
+    )
+  );
+  
+  return $ret;
 }
 
 /**
  * Implementation of hook_update_N()
  */
-function force_password_change_update_6201()
-{
-	// Create a row each user in the {force_password_change_users} table
-	$query1 = 'INSERT INTO {force_password_change_users} (uid) VALUES ';
-	$query2 = '';
-	$arguments = array();
-	$uids = db_query('SELECT uid FROM {users} WHERE uid > 0');
-	while($uid = db_fetch_array($uids))
-	{
-		if(strlen($query2))
-		{
-			$query2 .= ', ';
-		}
-		$query2 .= '(%d)';
-		$arguments[] = $uid['uid'];
-	}
-	db_query($query1 . $query2, $arguments);
-	
-	// Create a row for each role in the {force_password_change_roles} table
-	$query1 = 'INSERT INTO {force_password_change_roles} (rid) VALUES ';
-	$query2 = '';
-	$arguments = array();
-	$rids = db_query('SELECT rid FROM {role} WHERE rid > 1');
-	while($rid = db_fetch_array($rids))
-	{
-		if(strlen($query2))
-		{
-			$query2 .= ', ';
-		}
-		$query2 .= '(%d)';
-		$arguments[] = $rid['rid'];
-	}
-	db_query($query1 . $query2, $arguments);
-	
-	return array();
+function force_password_change_update_6201() {
+  // Create a row each user in the {force_password_change_users} table
+  $query1 = 'INSERT INTO {force_password_change_users} (uid) VALUES ';
+  $query2 = '';
+  $arguments = array();
+  $uids = db_query('SELECT uid FROM {users} WHERE uid > 0');
+  while($uid = db_fetch_array($uids)) {
+    if (strlen($query2)) {
+      $query2 .= ', ';
+    }
+    $query2 .= '(%d)';
+    $arguments[] = $uid['uid'];
+  }
+  db_query($query1 . $query2, $arguments);
+  
+  // Create a row for each role in the {force_password_change_roles} table
+  $query1 = 'INSERT INTO {force_password_change_roles} (rid) VALUES ';
+  $query2 = '';
+  $arguments = array();
+  $rids = db_query('SELECT rid FROM {role} WHERE rid > 1');
+  while($rid = db_fetch_array($rids)) {
+    if (strlen($query2)) {
+      $query2 .= ', ';
+    }
+    $query2 .= '(%d)';
+    $arguments[] = $rid['rid'];
+  }
+  db_query($query1 . $query2, $arguments);
+  
+  return array();
 }
 
 /**
  * Implementation of hook_update_N()
  */
-function force_password_change_update_6300()
-{
-	$ret = array();
-	db_create_table
-	(
-		$ret,
-		'force_password_change_expiry',
-		array
-		(
-			'description' => t('Holds information related to the expiry of passwords by role'),
-			'fields' => array
-			(
-				'rid' => array
-				(
-					'description' => t('The RID from the {role} table'),
-					'type' => 'int',
-					'unsigned' => TRUE,
-					'default' => NULL,
-				),
-				'expiry' => array
-				(
-					'description' => t('The number of seconds after which a user will be forced to reset their password'),
-					'type' => 'int',
-					'unsigned' => TRUE,
-					'default' => 0,
-				),
-				'weight' => array
-				(
-					'description' => t('Allows for priorities to be applied to password expirations'),
-					'type' => 'int',
-					'default' => 0,
-				),
-			),
-			'primary key' => array('rid'),
-		)
-	);
-	return $ret;
+function force_password_change_update_6300() {
+  $ret = array();
+  db_create_table(
+    $ret,
+    'force_password_change_expiry',
+    array(
+      'description' => t('Holds information related to the expiry of passwords by role'),
+      'fields' => array(
+        'rid' => array(
+          'description' => t('The RID from the {role} table'),
+          'type' => 'int',
+          'unsigned' => TRUE,
+          'default' => NULL,
+        ),
+        'expiry' => array(
+          'description' => t('The number of seconds after which a user will be forced to reset their password'),
+          'type' => 'int',
+          'unsigned' => TRUE,
+          'default' => 0,
+        ),
+        'weight' => array(
+          'description' => t('Allows for priorities to be applied to password expirations'),
+          'type' => 'int',
+          'default' => 0,
+        ),
+      ),
+      'primary key' => array('rid'),
+    )
+  );
+  return $ret;
 }
-
Index: force_password_change.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/force_password_change/force_password_change.module,v
retrieving revision 1.6.2.1.2.1
diff -u -p -r1.6.2.1.2.1 force_password_change.module
--- force_password_change.module	29 Jun 2010 08:38:41 -0000	1.6.2.1.2.1
+++ force_password_change.module	5 Aug 2010 21:43:31 -0000
@@ -5,365 +5,264 @@
 /**
  * Implementation of hook_perm()
  */
-function force_password_change_perm()
-{
-	return array
-	(
-		'Administer force password change',
-	);
+function force_password_change_perm() {
+  return array('Administer force password change');
 }
 
 /**
  * Implementation of hook_menu()
  */
-function force_password_change_menu()
-{
-	$menu['admin/user/force_password_change'] = array
-	(
-		'title' => 'Force password change',
-		'page callback' => 'drupal_get_form',
-		'page arguments' => array('force_password_change_settings'),
-		'access arguments' => array('Administer force password change'),
-		'file' => 'force_password_change_pages.inc',
-	);
-	$menu['force_password_change/list/%'] = array
-	(
-		'title' => 'dummy title. Does not need translation',
-		'page callback' => 'force_password_change_list',
-		'page arguments' => array(2),
-		'access arguments' => array('Administer force password change'),
-		'file' => 'force_password_change_pages.inc',
-		'type' => MENU_CALLBACK,
-	);
-	return $menu;
+function force_password_change_menu() {
+  $menu['admin/user/force_password_change'] = array(
+    'title' => 'Force password change',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('force_password_change_settings'),
+    'access arguments' => array('Administer force password change'),
+    'file' => 'force_password_change_pages.inc',
+  );
+  $menu['force_password_change/list/%'] = array(
+    'title' => 'dummy title. Does not need translation',
+    'page callback' => 'force_password_change_list',
+    'page arguments' => array(2),
+    'access arguments' => array('Administer force password change'),
+    'file' => 'force_password_change_pages.inc',
+    'type' => MENU_CALLBACK,
+  );
+  return $menu;
 }
 
 /**
  * Implementation of hook_init()
  */
-function force_password_change_init()
-{
-	global $user;
-	$change_password_url = preg_replace('/!uid/', $user->uid, variable_get('change_password_url', 'user/!uid/edit'));
-	if($_GET['q'] != $change_password_url && $_GET['q'] != drupal_get_path_alias('logout'))
-	{
-		if($user->force_password_change)
-		{
-			drupal_set_message(t('An administrator has required that you change your password. Please change your password to proceed.'), 'error', FALSE);
-			drupal_goto($change_password_url, 'destination=' . $_GET['q']);
-		}
-		else
-		{
-			$expiry_data = db_result
-			(
-				db_query_range
-				(
-					'SELECT fpce.expiry ' .
-					'FROM {force_password_change_expiry} AS fpce ' .
-					'LEFT JOIN {users_roles} AS ur ' .
-					'ON ur.rid = fpce.rid ' .
-					'WHERE ur.uid = %d OR fpce.rid = 2 ' .
-					'ORDER BY fpce.weight ',
-					$user->uid,
-					0,
-					1
-				)
-			);
-			if($expiry_data)
-			{
-				$pass_change_data = db_fetch_array
-				(
-					db_query
-					(
-						'SELECT fpcu.last_password_change, u.created ' .
-						'FROM {force_password_change_users} AS fpcu ' .
-						'JOIN {users} AS u ' .
-						'ON u.uid = %d ',
-						$user->uid
-					)
-				);
-				if(($pass_change_data['last_password_change'] != '' && (time() - $expiry_data) > $pass_change_data['last_password_change']) || ($pass_change_data['last_password_change'] == '' && (time() - $expiry_data) > $pass_change_data['created']))
-				{
-					$expires = $expiry_data;
-					$year = 60 * 60 * 24 * 365;
-					if($expires % $year === 0)
-					{
-						$time_period = $expires / $year;
-						$time_period = ($time_period > 1) ? $time_period . ' ' . t('years') : t('year');
-					}
-					else
-					{
-						$week = 60 * 60 * 24 * 7;
-						if($expires % $week === 0)
-						{
-							$time_period = $expires / $week;
-							$time_period = ($time_period > 1) ? $time_period . ' ' . t('weeks') : t('week');
-						}
-						else
-						{
-							$day = 60 * 60 * 24;
-							if($expires % $day === 0)
-							{
-								$time_period = $expires / $day;
-								$time_period = ($time_period > 1) ? $time_period . ' ' . t('days') : t('day');
-							}
-							else
-							{
-								$hour = 60 * 60;
-								if($expires % $hour === 0)
-								{
-									$time_period = $expires / $hour;
-									$time_period = ($time_period > 1) ? $time_period . ' ' . t('hours') : t('hour');
-								}
-							}
-						}
-					}
-					drupal_set_message(t('This site requires that you change your password every !time_period. Please change your password to proceed.', array('!time_period' => $time_period)));
-					drupal_goto($change_password_url, 'destination=' . $_GET['q']);
-				}
-			}
-		}
-	}
+function force_password_change_init() {
+  global $user;
+  $change_password_url = preg_replace('/!uid/', $user->uid, variable_get('change_password_url', 'user/!uid/edit'));
+  if ($_GET['q'] != $change_password_url && $_GET['q'] != drupal_get_path_alias('logout')) {
+    if ($user->force_password_change) {
+      drupal_set_message(t('An administrator has required that you change your password. Please change your password to proceed.'), 'error', FALSE);
+      drupal_goto($change_password_url, 'destination=' . $_GET['q']);
+    }
+    else {
+      $expiry_data = db_result(db_query_range('SELECT fpce.expiry FROM {force_password_change_expiry} AS fpce LEFT JOIN {users_roles} AS ur ON ur.rid = fpce.rid WHERE ur.uid = %d OR fpce.rid = 2 ORDER BY fpce.weight', $user->uid, 0, 1));
+      if ($expiry_data) {
+        $pass_change_data = db_fetch_array(db_query('SELECT fpcu.last_password_change, u.created FROM {force_password_change_users} AS fpcu JOIN {users} AS u ON u.uid = %d', $user->uid));
+        if (($pass_change_data['last_password_change'] != '' && (time() - $expiry_data) > $pass_change_data['last_password_change']) || ($pass_change_data['last_password_change'] == '' && (time() - $expiry_data) > $pass_change_data['created'])) {
+          $expires = $expiry_data;
+          $year = 60 * 60 * 24 * 365;
+          if ($expires % $year === 0) {
+            $time_period = $expires / $year;
+            $time_period = ($time_period > 1) ? $time_period . ' ' . t('years') : t('year');
+          }
+          else {
+            $week = 60 * 60 * 24 * 7;
+            if ($expires % $week === 0) {
+              $time_period = $expires / $week;
+              $time_period = ($time_period > 1) ? $time_period . ' ' . t('weeks') : t('week');
+            }
+            else {
+              $day = 60 * 60 * 24;
+              if ($expires % $day === 0) {
+                $time_period = $expires / $day;
+                $time_period = ($time_period > 1) ? $time_period . ' ' . t('days') : t('day');
+              }
+              else {
+                $hour = 60 * 60;
+                if ($expires % $hour === 0) {
+                  $time_period = $expires / $hour;
+                  $time_period = ($time_period > 1) ? $time_period . ' ' . t('hours') : t('hour');
+                }
+              }
+            }
+          }
+          drupal_set_message(t('This site requires that you change your password every !time_period. Please change your password to proceed.', array('!time_period' => $time_period)));
+          drupal_goto($change_password_url, 'destination=' . $_GET['q']);
+        }
+      }
+    }
+  }
 }
 
 /**
  * Implementation of hook_user()
  */
-function force_password_change_user($op, &$edit, &$account, $category = NULL)
-{
-	global $user;
-	switch($op)
-	{
-		case 'validate':
-			if($account->force_password_change && $account->uid == $user->uid)
-			{
-				if($edit['pass'] == '')
-				{
-					form_set_error('password', t('You must choose a new password'));
-				}
-			}
-			if(md5($edit['pass']) == $account->pass)
-			{
-				form_set_error('pass', t('You cannot use your current password. Please choose a different password.'));
-			}
-			break;
-		case 'register':
-			$form = array();
-			if(!variable_get('first_time_login_password_change', FALSE))
-			{
-				$form['force_password_change'] = array
-				(
-					'#type' => 'checkbox',
-					'#title' => t('Force password change on first-time login'),
-					'#description' => t('If this box is checked, the user will be forced to change their password on their first login.'),
-				);
-			}
-			return $form;
-			break;
-		case 'update':
-			if($edit['pass'] != $account->pass)
-			{
-				db_query
-				(
-					'UPDATE {force_password_change_users} SET last_password_change = %d WHERE uid = %d',
-					time(),
-					$account->uid
-				);
-			}
-			if($account->force_password_change && $user->uid == $account->uid && isset($edit['pending_force_password_change']))
-			{
-				db_query
-				(
-					'UPDATE {users} SET force_password_change = 0 WHERE uid = %d',
-					$account->uid
-				);
-				$forced_uids = variable_get('force_password_change_first_time_uids', array());
-				if(count($forced_uids))
-				{
-					unset($forced_uids[$account->uid]);
-					variable_set('force_password_change_first_time_uids', $forced_uids);
-				}
-			}
-			if($edit['force_password_change'])
-			{
-				db_query
-				(
-					'UPDATE {users} SET force_password_change = 1 WHERE uid = %d',
-					$account->uid
-				);
-				db_query
-				(
-					'UPDATE {force_password_change_users} SET last_force = %d WHERE uid = %d',
-					time(),
-					$account->uid
-				);
-				unset($edit['force_password_change']);
-			}
-			break;
-		case 'insert':
-			db_query('INSERT INTO {force_password_change_users} (uid) VALUES (%d)', $account->uid);
-			if(variable_get('first_time_login_password_change', 0))
-			{
-				db_query('UPDATE {users} SET force_password_change = 1 WHERE uid = %d', $account->uid);
-			}
-			elseif($edit['force_password_change'])
-			{
-				db_query('UPDATE {users} SET force_password_change = 1 WHERE uid = %d', $account->uid);
-				$forced_uids = variable_get('force_password_change_first_time_uids', array());
-				$forced_uids[$account->uid] = $account->uid;
-				variable_set('force_password_change_first_time_uids', $forced_uids);
-			}
-			unset($edit['force_password_change']);
-			break;
-		case 'delete':
-			db_query('DELETE FROM {force_password_change_users} WHERE uid = %d', $account->uid);
-			break;
-	}
+function force_password_change_user($op, &$edit, &$account, $category = NULL) {
+  global $user;
+  switch($op) {
+    case 'validate':
+      if ($account->force_password_change && $account->uid == $user->uid) {
+        if ($edit['pass'] == '') {
+          form_set_error('password', t('You must choose a new password'));
+        }
+      }
+      if (md5($edit['pass']) == $account->pass) {
+        form_set_error('pass', t('You cannot use your current password. Please choose a different password.'));
+      }
+      break;
+    case 'register':
+      $form = array();
+      if (!variable_get('first_time_login_password_change', FALSE)) {
+        $form['force_password_change'] = array(
+          '#type' => 'checkbox',
+          '#title' => t('Force password change on first-time login'),
+          '#description' => t('If this box is checked, the user will be forced to change their password on their first login.'),
+        );
+      }
+      return $form;
+      break;
+    case 'update':
+      if ($edit['pass'] != $account->pass) {
+        db_query('UPDATE {force_password_change_users} SET last_password_change = %d WHERE uid = %d', time(), $account->uid);
+      }
+      if ($account->force_password_change && $user->uid == $account->uid && isset($edit['pending_force_password_change'])) {
+        db_query('UPDATE {users} SET force_password_change = 0 WHERE uid = %d', $account->uid);
+        $forced_uids = variable_get('force_password_change_first_time_uids', array());
+        if (count($forced_uids)) {
+          unset($forced_uids[$account->uid]);
+          variable_set('force_password_change_first_time_uids', $forced_uids);
+        }
+      }
+      if ($edit['force_password_change']) {
+        db_query('UPDATE {users} SET force_password_change = 1 WHERE uid = %d', $account->uid);
+        db_query('UPDATE {force_password_change_users} SET last_force = %d WHERE uid = %d', time(), $account->uid);
+        unset($edit['force_password_change']);
+      }
+      break;
+    case 'insert':
+      db_query('INSERT INTO {force_password_change_users} (uid) VALUES (%d)', $account->uid);
+      if (variable_get('first_time_login_password_change', 0)) {
+        db_query('UPDATE {users} SET force_password_change = 1 WHERE uid = %d', $account->uid);
+      }
+      elseif ($edit['force_password_change']) {
+        db_query('UPDATE {users} SET force_password_change = 1 WHERE uid = %d', $account->uid);
+        $forced_uids = variable_get('force_password_change_first_time_uids', array());
+        $forced_uids[$account->uid] = $account->uid;
+        variable_set('force_password_change_first_time_uids', $forced_uids);
+      }
+      unset($edit['force_password_change']);
+      break;
+    case 'delete':
+      db_query('DELETE FROM {force_password_change_users} WHERE uid = %d', $account->uid);
+      break;
+  }
 }
 
 /**
  * Implementation of hook_form_alter()
  */
-function force_password_change_form_alter(&$form, &$form_state, $form_id)
-{
-	if($form_id == 'user_admin_new_role')
-	{
-		$form['#submit'][] = 'force_password_change_add_role';
-		$form['#theme'][] = 'force_password_change_new_role_form';
-	}
-	elseif($form_id == 'user_admin_role')
-	{
-		$form['force_password_change'] = array
-		(
-			'#type' => 'checkbox',
-			'#title' => t('Force users in this role to change their password'),
-			'#description' => t('Users who are not signed in will be required to change their password immediately upon sign in. Users who are currently signed in will be required to change their password upon their next page click, but after changing their password will be redirected back to the page they were attempting to access.') . '<br />' . t('Note: When you return to this page, this box will be unchecked. This is because this setting is a trigger, not a persistant state.'),
-			'#weight' => -1,
-		);
-		$form['name']['#weight'] = -2;
-		$form['#submit'][] = 'force_password_change_administer_role';
-	}
-	elseif($form_id == 'user_profile_form')
-	{
-		global $user;
-		if(user_access('Administer force password change', $user))
-		{
-			$form['account']['name']['#weight'] = -2;
-			$form['account']['mail']['#weight'] = -1;
-			$form['account']['password']['#weight'] = -1;
-			$form['account']['password']['pass'] = $form['account']['pass'];
-			unset($form['account']['pass']);
-			
-			if($user->uid != $form['_account']['#value']->uid)
-			{
-				$form['account']['password']['force_password_change'] = array
-				(
-					'#type' => 'checkbox',
-					'#title' => t('Force this user to change their password'),
-					'#description' => t('If this box is checked, the user will be forced to change their password. If the user is signed in, they will be forced to change their password on their next page load. If they are not signed in, they will be forced to change their password the next time they log in.') . '<br />' . t('Note: This box will be unchecked each time the page is loaded, as it is a trigger, not a persistent state.'),
-				);
-			}
-			
-			$force_password_data = db_fetch_array(db_query('SELECT last_password_change, last_force FROM {force_password_change_users} WHERE uid = %d', $form['_account']['#value']->uid));
-			$password_stats = '<p><strong>' . t('Password Stats:') . '</strong></p>';
-			$password_stats .= '<ul>';
-			$password_stats .= '<li>' . t('User has a pending forced password change:') . ' ';
-			$password_stats .= ($form['_account']['#value']->force_password_change) ? t('Yes') : t('No') . '</li>';
-			$password_stats .= '<li>' . t("User was last forced to change their password on:") . ' ';
-			if($force_password_data['last_force'] != '')
-			{
-				$last_force = format_date($force_password_data['last_force'], 'small');
-			}
-			elseif(variable_get('first_time_login_password_change', FALSE) && $form['_account']['#value']->created > variable_get('force_password_change_installation_date', 0))
-			{
-				$last_force = t('Their first login');
-			}
-			else
-			{
-				$forced_uids = variable_get('force_password_change_first_time_uids', array());
-				if(count($forced_uids) && isset($forced_uids[$form['_account']['#value']->uid]))
-				{
-					$last_force = t('Their first login');
-				}
-				elseif($force_password_data['last_password_change'] != '')
-				{
-					$last_force = t('Their first login');
-				}
-				else
-				{
-					$last_force = t('Never');
-				}
-			}
-			$password_stats .=  $last_force . '</li>';
-			$password_stats .= '<li>' . t('User last changed their password on:') . ' ';
-			$password_stats .= ($force_password_data['last_password_change'] != '') ? format_date($force_password_data['last_password_change'], 'small') : t('Never');
-			$password_stats .= '</li>';
-			$password_stats .= '</ul>';
-			$form['account']['password']['password_stats'] = array
-			(
-				'#value' => $password_stats,
-			);
-		}
-		$form['pending_force_password_change'] = array
-		(
-			'#type' => 'value',
-			'#value' => $form['_account']['#value']->force_password_change
-	   );
-	}
-	if($form_id == 'user_register')
-	{
-		$form['account']['name']['#weight'] = -2;
-		$form['account']['mail']['#weight'] = -1;
-		$form['account']['password']['#weight'] = -1;
-		$form['account']['password']['pass'] = $form['account']['pass'];
-		$form['account']['password']['force_password_change'] = $form['force_password_change'];
-		unset($form['account']['pass']);
-		unset($form['force_password_change']);
-	}
+function force_password_change_form_alter(&$form, &$form_state, $form_id) {
+  if ($form_id == 'user_admin_new_role') {
+    $form['#submit'][] = 'force_password_change_add_role';
+    $form['#theme'][] = 'force_password_change_new_role_form';
+  }
+  elseif ($form_id == 'user_admin_role') {
+    $form['force_password_change'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Force users in this role to change their password'),
+      '#description' => t('Users who are not signed in will be required to change their password immediately upon sign in. Users who are currently signed in will be required to change their password upon their next page click, but after changing their password will be redirected back to the page they were attempting to access.') . '<br />' . t('Note: When you return to this page, this box will be unchecked. This is because this setting is a trigger, not a persistant state.'),
+      '#weight' => -1,
+    );
+    $form['name']['#weight'] = -2;
+    $form['#submit'][] = 'force_password_change_administer_role';
+  }
+  elseif ($form_id == 'user_profile_form') {
+    global $user;
+    if (user_access('Administer force password change', $user)) {
+      $form['account']['name']['#weight'] = -2;
+      $form['account']['mail']['#weight'] = -1;
+      $form['account']['password']['#weight'] = -1;
+      $form['account']['password']['pass'] = $form['account']['pass'];
+      unset($form['account']['pass']);
+      
+      if ($user->uid != $form['_account']['#value']->uid) {
+        $form['account']['password']['force_password_change'] = array(
+          '#type' => 'checkbox',
+          '#title' => t('Force this user to change their password'),
+          '#description' => t('If this box is checked, the user will be forced to change their password. If the user is signed in, they will be forced to change their password on their next page load. If they are not signed in, they will be forced to change their password the next time they log in.') . '<br />' . t('Note: This box will be unchecked each time the page is loaded, as it is a trigger, not a persistent state.'),
+        );
+      }
+      
+      $force_password_data = db_fetch_array(db_query('SELECT last_password_change, last_force FROM {force_password_change_users} WHERE uid = %d', $form['_account']['#value']->uid));
+      $password_stats = '<p><strong>' . t('Password Stats:') . '</strong></p>';
+      $password_stats .= '<ul>';
+      $password_stats .= '<li>' . t('User has a pending forced password change:') . ' ';
+      $password_stats .= ($form['_account']['#value']->force_password_change) ? t('Yes') : t('No') . '</li>';
+      $password_stats .= '<li>' . t("User was last forced to change their password on:") . ' ';
+      if ($force_password_data['last_force'] != '') {
+        $last_force = format_date($force_password_data['last_force'], 'small');
+      }
+      elseif (variable_get('first_time_login_password_change', FALSE) && $form['_account']['#value']->created > variable_get('force_password_change_installation_date', 0)) {
+        $last_force = t('Their first login');
+      }
+      else {
+        $forced_uids = variable_get('force_password_change_first_time_uids', array());
+        if (count($forced_uids) && isset($forced_uids[$form['_account']['#value']->uid])) {
+          $last_force = t('Their first login');
+        }
+        elseif ($force_password_data['last_password_change'] != '') {
+          $last_force = t('Their first login');
+        }
+        else {
+          $last_force = t('Never');
+        }
+      }
+      $password_stats .=  $last_force . '</li>';
+      $password_stats .= '<li>' . t('User last changed their password on:') . ' ';
+      $password_stats .= ($force_password_data['last_password_change'] != '') ? format_date($force_password_data['last_password_change'], 'small') : t('Never');
+      $password_stats .= '</li>';
+      $password_stats .= '</ul>';
+      $form['account']['password']['password_stats'] = array(
+        '#value' => $password_stats,
+      );
+    }
+    $form['pending_force_password_change'] = array(
+      '#type' => 'value',
+      '#value' => $form['_account']['#value']->force_password_change
+     );
+  }
+  if ($form_id == 'user_register') {
+    $form['account']['name']['#weight'] = -2;
+    $form['account']['mail']['#weight'] = -1;
+    $form['account']['password']['#weight'] = -1;
+    $form['account']['password']['pass'] = $form['account']['pass'];
+    $form['account']['password']['force_password_change'] = $form['force_password_change'];
+    unset($form['account']['pass']);
+    unset($form['force_password_change']);
+  }
 }
 
 /**
  * Implementation of hook_theme()
  */
-function force_password_change_theme()
-{
-	return array
-	(
-		'force_password_change_new_role_form' => array
-		(
-			'arguments' => array
-			(
-				'form' => NULL,
-			),
-			'file' => 'force_password_change_pages.inc',
-		),
-		'force_password_change_settings' => array
-		(
-			'arguments' => array
-			(
-				'form' => NULL,
-			),
-			'file' => 'force_password_change_pages.inc',
-		),
-		'force_password_change_expiry' => array
-		(
-			'arguments' => array
-			(
-				'form' => NULL,
-			),
-			'file' => 'force_password_change_pages.inc',
-		),
-	);
+function force_password_change_theme() {
+  return array(
+    'force_password_change_new_role_form' => array(
+      'arguments' => array(
+        'form' => NULL,
+      ),
+      'file' => 'force_password_change_pages.inc',
+    ),
+    'force_password_change_settings' => array(
+      'arguments' => array(
+        'form' => NULL,
+      ),
+      'file' => 'force_password_change_pages.inc',
+    ),
+    'force_password_change_expiry' => array(
+      'arguments' => array(
+        'form' => NULL,
+      ),
+      'file' => 'force_password_change_pages.inc',
+    ),
+  );
 }
 
 /**
  * This function is called after a new role has been added to the system.
  * It creates a new row in the {force_password_change_roles} table for the role that has been created
  */
-function force_password_change_add_role($form, &$form_state)
-{
-	$rid = db_result(db_query('SELECT rid FROM {role} WHERE name = "%s"', $form_state['values']['name']));
-	db_query('INSERT INTO {force_password_change_roles} (rid) VALUES (%d)', $rid);
+function force_password_change_add_role($form, &$form_state) {
+  $rid = db_result(db_query('SELECT rid FROM {role} WHERE name = "%s"', $form_state['values']['name']));
+  db_query('INSERT INTO {force_password_change_roles} (rid) VALUES (%d)', $rid);
 }
 
 /**
@@ -372,54 +271,22 @@ function force_password_change_add_role(
  * Or
  * 2) Forces the users in that role to chage their password if the applicable checkbox is checked.
  */
-function force_password_change_administer_role($form, &$form_state)
-{
-	if($form_state['values']['op'] == $form_state['values']['delete'])
-	{
-		db_query('DELETE FROM {force_password_change_roles} WHERE rid = %d', $form_state['values']['rid']);
-	}
-	elseif($form_state['values']['op'] == $form_state['values']['submit'] && $form_state['values']['force_password_change'])
-	{
-		$uids = array();
-		$db_uids = db_query
-		(
-			'SELECT uid ' .
-			'FROM {users_roles} ' .
-			'WHERE rid = %d',
-			$form_state['values']['rid']
-		);
-		while($uid = db_fetch_array($db_uids))
-		{
-			$uids[] = $uid['uid'];
-		}
-		$uid_list = implode(', ', $uids);
-		if(strlen($uid_list))
-		{
-			db_query
-			(
-				'UPDATE {users} ' .
-				'SET force_password_change = 1 ' .
-				'WHERE uid IN (%s)',
-				$uid_list
-			);
-			db_query
-			(
-				'UPDATE {force_password_change_users} ' .
-				'SET last_force = %d ' .
-				'WHERE uid IN (%s)',
-				time(),
-				$uid_list
-			);
-		}
-		db_query
-		(
-			'UPDATE {force_password_change_roles} ' .
-			'SET last_force = %d ' .
-			'WHERE rid = %d ',
-			time(),
-			$form_state['values']['rid']
-		);
-		drupal_set_message(t('Users in this role will be required to immediately change their password'));
-	}
+function force_password_change_administer_role($form, &$form_state) {
+  if ($form_state['values']['op'] == $form_state['values']['delete']) {
+    db_query('DELETE FROM {force_password_change_roles} WHERE rid = %d', $form_state['values']['rid']);
+  }
+  elseif ($form_state['values']['op'] == $form_state['values']['submit'] && $form_state['values']['force_password_change']) {
+    $uids = array();
+    $db_uids = db_query('SELECT uid FROM {users_roles} WHERE rid = %d', $form_state['values']['rid']);
+    while($uid = db_fetch_array($db_uids)) {
+      $uids[] = $uid['uid'];
+    }
+    $uid_list = implode(', ', $uids);
+    if (strlen($uid_list)) {
+      db_query('UPDATE {users} SET force_password_change = 1 WHERE uid IN (%s)', $uid_list);
+      db_query('UPDATE {force_password_change_users} SET last_force = %d WHERE uid IN (%s)', time(), $uid_list);
+    }
+    db_query('UPDATE {force_password_change_roles} SET last_force = %d WHERE rid = %d', time(), $form_state['values']['rid']);
+    drupal_set_message(t('Users in this role will be required to immediately change their password'));
+  }
 }
-
Index: force_password_change_pages.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/force_password_change/force_password_change_pages.inc,v
retrieving revision 1.1.4.1
diff -u -p -r1.1.4.1 force_password_change_pages.inc
--- force_password_change_pages.inc	29 Jun 2010 08:38:41 -0000	1.1.4.1
+++ force_password_change_pages.inc	5 Aug 2010 21:43:31 -0000
@@ -5,644 +5,461 @@
 /**
  * This function creates the settings page. It is a callback function for drupal_get_form()
  */
-function force_password_change_settings($form_state)
-{
-	$form['first_time_login_password_change'] = array
-	(
-		'#type' => 'checkbox',
-		'#title' => t('Force password change on first-time login'),
-		'#default_value' => variable_get('first_time_login_password_change', 0),
-	);
-	$all_roles = user_roles(TRUE);
-	foreach($all_roles as $rid => $role)
-	{
-		if($rid > 2)
-		{
-			$user_count = db_result(db_query('SELECT COUNT(uid) FROM {users_roles} WHERE rid = %d', $rid));
-			$pending_count = db_result
-			(
-				db_query
-				(
-					'SELECT COUNT(u.uid) ' .
-					'FROM {users} AS u ' .
-					'JOIN {users_roles} AS ur ' .
-					'ON ur.uid = u.uid ' .
-					'WHERE u.force_password_change = 1 AND u.uid > 0 AND ur.rid = %d',
-					$rid
-				)
-			);
-		}
-		elseif($rid == 2)
-		{
-			$user_count = db_result(db_query('SELECT COUNT(uid) FROM {users} WHERE uid > 0'));
-			$pending_count = db_result(db_query('SELECT COUNT(uid) FROM {users} WHERE force_password_change = 1 AND uid > 0'));
-		}
-		$roles[$rid] = $role;
-		$stats[$rid] = array
-		(
-			'user_count' => $user_count,
-			'pending_count' => $pending_count
-		);
-	}
-	$form['roles'] = array
-	(
-		'#type' => 'checkboxes',
-		'#options' => $roles,
-		'#title' => t('Force users in the following roles to change their password'),
-		'#description' => t('Users who are not signed in will be required to change their password immediately upon sign in. Users who are currently signed in will be required to change their password upon their next page click, but after changing their password will be redirected back to the page they were attempting to access.') . '<br />' . t('Note: When you return to this page, no roles will be selected. This is because this setting is a trigger, not a persistant state.'),
-	);
-	$expiry_data = db_query('SELECT rid, expiry, weight from {force_password_change_expiry} ORDER BY weight ASC, rid ASC');
-	$expiry = array();
-	while($data = db_fetch_array($expiry_data))
-	{
-		$expiry[$data['rid']] = array
-		(
-			'expiry' => $data['expiry'],
-			'weight' => $data['weight'],
-		);
-	}
-	$form['expiry_data'] = array
-	(
-		'#type' => 'value',
-		'#value' => $expiry,
-	);
-	$form['expiry'] = array
-	(
-		'#type' => 'fieldset',
-		'#title' => t('Password Expiry'),
-		'#collapsible' => TRUE,
-	);
-	$form['expiry']['header'] = array
-	(
-		'#value' => '<p>' . t('Select the amount of time after which you would like users in a role to be automatically forced to change their password. Any users who do not change their password in this amount of time will be forced to change their password on their next login/page load. If you do not wish passwords to expire for a certain role, leave/set the value for that role to zero.') . '</p>',
-	);
-	$form['expiry']['table'] = array
-	(
-		'#tree' => TRUE,
-		'#theme' => 'force_password_change_expiry',
-	);
-	$time_period = array
-	(
-		'hours',
-		'days',
-		'weeks',
-		'years',
-	);
-	$heaviest_weight = 0;
-	if(count($expiry))
-	{
-		foreach($expiry as $rid => $data)
-		{
-			$form['expiry']['table'][$rid]['role'] = array
-			(
-				'#value' => $roles[$rid],
-			);
-			if($data['expiry'] != '' && $data['expiry'])
-			{
-				$expires = $data['expiry'];
-				$year = 60 * 60 * 24 * 365;
-				if($expires % $year === 0)
-				{
-					$time_period_default = 3;
-					$time_quantity_default = $expires / $year;
-				}
-				else
-				{
-					$week = 60 * 60 * 24 * 7;
-					if($expires % $week === 0)
-					{
-						$time_period_default = 2;
-						$time_quantity_default = $expires / $week;
-					}
-					else
-					{
-						$day = 60 * 60 * 24;
-						if($expires % $day === 0)
-						{
-							$time_period_default = 1;
-							$time_quantity_default = $expires / $day;
-						}
-						else
-						{
-							$hour = 60 * 60;
-							$time_period_default = 0;
-							if($expires % $hour === 0)
-							{
-								$time_quantity_default = $expires / $hour;
-							}
-							else
-							{
-								$time_quantity_default = 0;
-							}
-						}
-					}
-				}
-			}
-			else
-			{
-				$time_period_default = 0;
-				$time_quantity_default = 0;
-			}
-			$form['expiry']['table'][$rid]['time_quantity'] = array
-			(
-				'#type' => 'textfield',
-				'#default_value' => $time_quantity_default,
-			);
-			$form['expiry']['table'][$rid]['time_period'] = array
-			(
-				'#type' => 'select',
-				'#options' => $time_period,
-				'#default_value' => $time_period_default,
-			);
-			$form['expiry']['table'][$rid]['weight'] = array
-			(
-				'#type' => 'weight',
-				'#delta' => count($roles),
-				'#default_value' => ($data['weight'] != '') ? $data['weight'] : 0,
-			);
-			$heaviest_weight = ($data['weight'] != '') ? $data['weight'] : 0;
-		}
-	}
-	foreach($roles as $rid => $r)
-	{
-		if(!isset($form['expiry']['table'][$rid]))
-		{
-			$heaviest_weight++;
-			$form['expiry']['table'][$rid]['role'] = array
-			(
-				'#value' => $r,
-			);
-			$form['expiry']['table'][$rid]['time_quantity'] = array
-			(
-				'#type' => 'textfield',
-				'#default_value' => 0,
-			);
-			$form['expiry']['table'][$rid]['time_period'] = array
-			(
-				'#type' => 'select',
-				'#options' => $time_period,
-			);
-			$form['expiry']['table'][$rid]['weight'] = array
-			(
-				'#type' => 'weight',
-				'#delta' => count($roles),
-				'#default_value' => $heaviest_weight,
-			);
-		}
-	}
-	$form['expiry']['footer'] = array
-	(
-		'#value' => '<p>' . t('Drag and drop the rows to set the priority for password expiry. The roles with the highest priority should be placed at the top of the list. If a user is a member of more than one role, then the time after which their password expires will be determined by whichever of their roles has the highest priority. Any other roles will be ignored. On this note, placing the authenticated user role above any other role will effectively nullify the expiry date for those roles, since all members are authenticated users.') . '</p>',
-	);
-	$form['stats'] = array
-	(
-		'#type' => 'value',
-		'#value' => $stats,
-	);
-	$form['change_password_url'] = array
-	(
-		'#type' => 'textfield',
-		'#title' => t('Path to password change URL'),
-		'#description' => t('Only change this if you have implemented a module that changes the user password URL from user/[UID]/edit to something else. Use !uid in place of the user id') . '<br />' . t('WARNING: if you set this URL to an invalid URL, you could break your site, so backup your files first, and double check the path before setting it.'),
-		'#default_value' => variable_get('change_password_url', 'user/!uid/edit'),
-	);
+function force_password_change_settings($form_state) {
+  $form['first_time_login_password_change'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Force password change on first-time login'),
+    '#default_value' => variable_get('first_time_login_password_change', 0),
+  );
+  $all_roles = user_roles(TRUE);
+  foreach($all_roles as $rid => $role) {
+    if ($rid > 2) {
+      $user_count = db_result(db_query('SELECT COUNT(uid) FROM {users_roles} WHERE rid = %d', $rid));
+      $pending_count = db_result(db_query('SELECT COUNT(u.uid) FROM {users} AS u JOIN {users_roles} AS ur ON ur.uid = u.uid WHERE u.force_password_change = 1 AND u.uid > 0 AND ur.rid = %d', $rid));
+    }
+    elseif ($rid == 2) {
+      $user_count = db_result(db_query('SELECT COUNT(uid) FROM {users} WHERE uid > 0'));
+      $pending_count = db_result(db_query('SELECT COUNT(uid) FROM {users} WHERE force_password_change = 1 AND uid > 0'));
+    }
+    $roles[$rid] = $role;
+    $stats[$rid] = array(
+      'user_count' => $user_count,
+      'pending_count' => $pending_count
+    );
+  }
+  $form['roles'] = array(
+    '#type' => 'checkboxes',
+    '#options' => $roles,
+    '#title' => t('Force users in the following roles to change their password'),
+    '#description' => t('Users who are not signed in will be required to change their password immediately upon sign in. Users who are currently signed in will be required to change their password upon their next page click, but after changing their password will be redirected back to the page they were attempting to access.') . '<br />' . t('Note: When you return to this page, no roles will be selected. This is because this setting is a trigger, not a persistant state.'),
+  );
+  $expiry_data = db_query('SELECT rid, expiry, weight from {force_password_change_expiry} ORDER BY weight ASC, rid ASC');
+  $expiry = array();
+  while($data = db_fetch_array($expiry_data)) {
+    $expiry[$data['rid']] = array(
+      'expiry' => $data['expiry'],
+      'weight' => $data['weight'],
+    );
+  }
+  $form['expiry_data'] = array(
+    '#type' => 'value',
+    '#value' => $expiry,
+  );
+  $form['expiry'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Password Expiry'),
+    '#collapsible' => TRUE,
+  );
+  $form['expiry']['header'] = array(
+    '#value' => '<p>' . t('Select the amount of time after which you would like users in a role to be automatically forced to change their password. Any users who do not change their password in this amount of time will be forced to change their password on their next login/page load. If you do not wish passwords to expire for a certain role, leave/set the value for that role to zero.') . '</p>',
+  );
+  $form['expiry']['table'] = array(
+    '#tree' => TRUE,
+    '#theme' => 'force_password_change_expiry',
+  );
+  $time_period = array(
+    'hours',
+    'days',
+    'weeks',
+    'years',
+  );
+  $heaviest_weight = 0;
+  if (count($expiry)) {
+    foreach($expiry as $rid => $data) {
+      $form['expiry']['table'][$rid]['role'] = array(
+        '#value' => $roles[$rid],
+      );
+      if ($data['expiry'] != '' && $data['expiry']) {
+        $expires = $data['expiry'];
+        $year = 60 * 60 * 24 * 365;
+        if ($expires % $year === 0) {
+          $time_period_default = 3;
+          $time_quantity_default = $expires / $year;
+        }
+        else {
+          $week = 60 * 60 * 24 * 7;
+          if ($expires % $week === 0) {
+            $time_period_default = 2;
+            $time_quantity_default = $expires / $week;
+          }
+          else {
+            $day = 60 * 60 * 24;
+            if ($expires % $day === 0) {
+              $time_period_default = 1;
+              $time_quantity_default = $expires / $day;
+            }
+            else {
+              $hour = 60 * 60;
+              $time_period_default = 0;
+              if ($expires % $hour === 0) {
+                $time_quantity_default = $expires / $hour;
+              }
+              else {
+                $time_quantity_default = 0;
+              }
+            }
+          }
+        }
+      }
+      else {
+        $time_period_default = 0;
+        $time_quantity_default = 0;
+      }
+      $form['expiry']['table'][$rid]['time_quantity'] = array(
+        '#type' => 'textfield',
+        '#default_value' => $time_quantity_default,
+      );
+      $form['expiry']['table'][$rid]['time_period'] = array(
+        '#type' => 'select',
+        '#options' => $time_period,
+        '#default_value' => $time_period_default,
+      );
+      $form['expiry']['table'][$rid]['weight'] = array(
+        '#type' => 'weight',
+        '#delta' => count($roles),
+        '#default_value' => ($data['weight'] != '') ? $data['weight'] : 0,
+      );
+      $heaviest_weight = ($data['weight'] != '') ? $data['weight'] : 0;
+    }
+  }
+  foreach($roles as $rid => $r) {
+    if (!isset($form['expiry']['table'][$rid])) {
+      $heaviest_weight++;
+      $form['expiry']['table'][$rid]['role'] = array(
+        '#value' => $r,
+      );
+      $form['expiry']['table'][$rid]['time_quantity'] = array(
+        '#type' => 'textfield',
+        '#default_value' => 0,
+      );
+      $form['expiry']['table'][$rid]['time_period'] = array(
+        '#type' => 'select',
+        '#options' => $time_period,
+      );
+      $form['expiry']['table'][$rid]['weight'] = array(
+        '#type' => 'weight',
+        '#delta' => count($roles),
+        '#default_value' => $heaviest_weight,
+      );
+    }
+  }
+  $form['expiry']['footer'] = array(
+    '#value' => '<p>' . t('Drag and drop the rows to set the priority for password expiry. The roles with the highest priority should be placed at the top of the list. If a user is a member of more than one role, then the time after which their password expires will be determined by whichever of their roles has the highest priority. Any other roles will be ignored. On this note, placing the authenticated user role above any other role will effectively nullify the expiry date for those roles, since all members are authenticated users.') . '</p>',
+  );
+  $form['stats'] = array(
+    '#type' => 'value',
+    '#value' => $stats,
+  );
+  $form['change_password_url'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Path to password change URL'),
+    '#description' => t('Only change this if you have implemented a module that changes the user password URL from user/[UID]/edit to something else. Use !uid in place of the user id') . '<br />' . t('WARNING: if you set this URL to an invalid URL, you could break your site, so backup your files first, and double check the path before setting it.'),
+    '#default_value' => variable_get('change_password_url', 'user/!uid/edit'),
+  );
 
-	$form['submit'] = array
-	(
-		'#type' => 'submit',
-		'#value' => t('Submit'),
-	);
-	return $form;
+  $form['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Submit'),
+  );
+  return $form;
 }
 
 /**
  * Submit function for the settings form
  */
-function force_password_change_settings_submit($form, &$form_state)
-{
-	$selected_roles = array();
-	variable_set('change_password_url', $form_state['values']['change_password_url']);
-	variable_set('first_time_login_password_change', $form_state['values']['first_time_login_password_change']);
-	foreach($form_state['values']['roles'] as $role)
-	{
-		if($role > 2)
-		{
-			$uids = array();
-			$db_uids = db_query
-			(
-				'SELECT uid ' .
-				'FROM {users_roles} ' .
-				'WHERE rid = %d',
-				$role
-			);
-			while($uid = db_fetch_array($db_uids))
-			{
-				$uids[] = $uid['uid'];
-			}
-			$uid_list = implode(', ', $uids);
-			if(strlen($uid_list))
-			{
-				db_query
-				(
-					'UPDATE {users} ' .
-					'SET force_password_change = 1 ' .
-					'WHERE uid IN (%s)',
-					$uid_list
-				);
-				db_query
-				(
-					'UPDATE {force_password_change_users} ' .
-					'SET last_force = %d ' .
-					'WHERE uid IN (%s)',
-					time(),
-					$uid_list
-				);
-			}
-			$selected_roles[] = $role;
-		}
-		elseif($role == 2)
-		{
-			db_query
-			(
-				'UPDATE {users} ' .
-				'SET force_password_change = 1 '
-			);
-			db_query
-			(
-				'UPDATE {force_password_change_users} ' .
-				'SET last_force = %d ',
-				time()
-			);
-			$selected_roles[] = $role;
-		}
-	}
-	if(count($selected_roles))
-	{
-		db_query
-		(
-			'UPDATE {force_password_change_roles} ' .
-			'SET last_force = %d ' .
-			'WHERE rid IN (%s) ',
-			time(),
-			implode(', ', $selected_roles)
-		);
-		$roles = user_roles(TRUE);
-		$list = '<ul>';
-		foreach($selected_roles as $sr)
-		{
-			$list .= '<li>' . $roles[$sr] . '</li>';
-		}
-		$list .= '</ul>';
-		drupal_set_message(t('Users in the following roles will be required to immediately change their password: !list', array('!list' => $list)), 'status');
-	}
-	
-	$delete_expiries = array();
-	$add_query = 'INSERT INTO {force_password_change_expiry} (rid, expiry, weight) VALUES ';
-	$add_query2 = '';
-	$arguments = array();
-	foreach($form_state['values']['table'] as $rid => $expiry)
-	{
-		$multiplier = array(60 * 60, 60 * 60 * 24, 60 * 60 * 24 * 7, 60 * 60 * 24 * 365);
-		$time_period = $expiry['time_quantity'] * $multiplier[$expiry['time_period']];
-		if(isset($form_state['values']['expiry_data'][$rid])) // update
-		{
-			db_query('UPDATE {force_password_change_expiry} SET expiry = %d, weight = %d WHERE rid = %d', $time_period, $expiry['weight'], $rid);
-		}
-		else // create
-		{
-			if(strlen($add_query2))
-			{
-				$add_query2 .= ',';
-			}
-			$add_query2 .= '(%d, %d, %d)';
-			$arguments[] = $rid;
-			$arguments[] = $time_period;
-			$arguments[] = $expiry['weight'];
-		}
-	}
-	if(count($delete_expiries))
-	{
-		db_query('DELETE FROM {force_password_change_expiry} WHERE rid IN (%s)', implode(',', $delete_expiries));
-	}
-	if(strlen($add_query2))
-	{
-		db_query($add_query . $add_query2, $arguments);
-	}
+function force_password_change_settings_submit($form, &$form_state) {
+  $selected_roles = array();
+  variable_set('change_password_url', $form_state['values']['change_password_url']);
+  variable_set('first_time_login_password_change', $form_state['values']['first_time_login_password_change']);
+  foreach($form_state['values']['roles'] as $role) {
+    if ($role > 2) {
+      $uids = array();
+      $db_uids = db_query('SELECT uid FROM {users_roles} WHERE rid = %d', $role);
+      while($uid = db_fetch_array($db_uids)) {
+        $uids[] = $uid['uid'];
+      }
+      $uid_list = implode(', ', $uids);
+      if (strlen($uid_list)) {
+        db_query('UPDATE {users} SET force_password_change = 1 WHERE uid IN (%s)', $uid_list);
+        db_query('UPDATE {force_password_change_users} SET last_force = %d WHERE uid IN (%s)', time(), $uid_list);
+      }
+      $selected_roles[] = $role;
+    }
+    elseif ($role == 2) {
+      db_query('UPDATE {users} SET force_password_change = 1');
+      db_query('UPDATE {force_password_change_users} SET last_force = %d', time());
+      $selected_roles[] = $role;
+    }
+  }
+  if (count($selected_roles)) {
+    db_query('UPDATE {force_password_change_roles} SET last_force = %d WHERE rid IN (%s)', time(), implode(', ', $selected_roles));
+    $roles = user_roles(TRUE);
+    $list = '<ul>';
+    foreach($selected_roles as $sr) {
+      $list .= '<li>' . $roles[$sr] . '</li>';
+    }
+    $list .= '</ul>';
+    drupal_set_message(t('Users in the following roles will be required to immediately change their password: !list', array('!list' => $list)), 'status');
+  }
+  
+  $delete_expiries = array();
+  $add_query = 'INSERT INTO {force_password_change_expiry} (rid, expiry, weight) VALUES ';
+  $add_query2 = '';
+  $arguments = array();
+  foreach($form_state['values']['table'] as $rid => $expiry) {
+    $multiplier = array(60 * 60, 60 * 60 * 24, 60 * 60 * 24 * 7, 60 * 60 * 24 * 365);
+    $time_period = $expiry['time_quantity'] * $multiplier[$expiry['time_period']];
+    if (isset($form_state['values']['expiry_data'][$rid])) // update {
+      db_query('UPDATE {force_password_change_expiry} SET expiry = %d, weight = %d WHERE rid = %d', $time_period, $expiry['weight'], $rid);
+    }
+    else { // create
+      if (strlen($add_query2)) {
+        $add_query2 .= ',';
+      }
+      $add_query2 .= '(%d, %d, %d)';
+      $arguments[] = $rid;
+      $arguments[] = $time_period;
+      $arguments[] = $expiry['weight'];
+    }
+  }
+  if (count($delete_expiries)) {
+    db_query('DELETE FROM {force_password_change_expiry} WHERE rid IN (%s)', implode(',', $delete_expiries));
+  }
+  if (strlen($add_query2)) {
+    db_query($add_query . $add_query2, $arguments);
+  }
 }
 
 /**
  * Details page for a particular role, as it relates to the Force Password Change module
  */
-function force_password_change_list($rid)
-{
-	$roles = user_roles(TRUE);
-	if($rid < 2 || !$rid)
-	{
-		drupal_set_title(t("Error: role doesn't exist"));
-		return t("Error: role doesn't exist.");
-	}
-	drupal_set_title(t('Force Password Change Details for !role', array('!role' => $roles[$rid])));
-	$output = '<p><strong>' . t('Last forced password change for this role:') . '</strong> ';
-	$last_change = db_result(db_query('SELECT last_force FROM {force_password_change_roles} WHERE rid = %d', $rid));
-	$output .= ($last_change != '') ? format_date($last_change, 'small') : t('Never');
-	$output .= '</p>';
-	$pending_header = array
-	(
-		array('data' => t('Username'), 'field' => 'u.name', 'sort' => 'asc'),
-		array('data' => t('Last Forced Password Change'), 'field' => 'fpcu.last_force'),
-		array('data' => t('Last Password Change'), 'field' => 'fpcu.last_password_change'),
-	);
-	
-	$pending_query = 'SELECT u.uid, u.name, u.created, fpcu.last_force, fpcu.last_password_change ' .
-						'FROM {users} AS u ' .
-						'JOIN {force_password_change_users} AS fpcu ' .
-						'ON fpcu.uid = u.uid ';
-	if($rid > 2)
-	{
-		$pending_query .= 'JOIN {users_roles} AS ur ' .
-							'ON ur.uid = u.uid ';
-	}
-	$pending_query .= 'WHERE u.force_password_change = 1 ';
-	if($rid > 2)
-	{
-		$pending_query .= ' AND ur.rid = ' . $rid . ' ';
-	}
-	$pending_query .= tablesort_sql($pending_header);
-	$pending_user_data = pager_query
-	(
-		$pending_query,
-		100,
-		0
-	);
-	
-	$rows = array();
-	$force_password_change_installation_date = variable_get('force_password_change_installation_date', 0);
-	$forced_uids = variable_get('force_password_change_first_time_uids', array());
-	while($pending_user = db_fetch_array($pending_user_data))
-	{
-		$row = array();
-		$row[] = l($pending_user['name'], 'user/' . $pending_user['uid']);
-		if($pending_user['last_force'] != '')
-		{
-			$last_force = format_date($pending_user['last_force'], 'small');
-		}
-		elseif(variable_get('first_time_login_password_change', FALSE) && $pending_user['created'] > $force_password_change_installation_date)
-		{
-			$last_force = t('Their first login');
-		}
-		else
-		{
-			if(count($forced_uids) && isset($forced_uids[$pending_user['uid']]))
-			{
-				$last_force = t('Their first login');
-			}
-			elseif($pending_user['last_password_change'] != '')
-			{
-				$last_force = t('Their first login');
-			}
-			else
-			{
-				$last_force = t('Never');
-			}
-		}
-		$row[] = $last_force;
-		$row[] = ($pending_user['last_password_change'] != '') ? format_date($pending_user['last_password_change'], 'small') : t('Never');
-		$rows[] = $row;
-	}
-	if(!count($rows))
-	{
-		$row = array();
-		$row[] = array('data' => t('No users found'), 'colspan' => 3);
-		$rows[] = $row;
-	}
-	$output .= '<h3>' . t('Users with a pending password change') . '</h3>' . theme('table', $pending_header, $rows) . theme('pager', array(), 100, 0);
+function force_password_change_list($rid) {
+  $roles = user_roles(TRUE);
+  if ($rid < 2 || !$rid) {
+    drupal_set_title(t("Error: role doesn't exist"));
+    return t("Error: role doesn't exist.");
+  }
+  drupal_set_title(t('Force Password Change Details for !role', array('!role' => $roles[$rid])));
+  $output = '<p><strong>' . t('Last forced password change for this role:') . '</strong> ';
+  $last_change = db_result(db_query('SELECT last_force FROM {force_password_change_roles} WHERE rid = %d', $rid));
+  $output .= ($last_change != '') ? format_date($last_change, 'small') : t('Never');
+  $output .= '</p>';
+  $pending_header = array(
+    array('data' => t('Username'), 'field' => 'u.name', 'sort' => 'asc'),
+    array('data' => t('Last Forced Password Change'), 'field' => 'fpcu.last_force'),
+    array('data' => t('Last Password Change'), 'field' => 'fpcu.last_password_change'),
+  );
+  
+  $pending_query = 'SELECT u.uid, u.name, u.created, fpcu.last_force, fpcu.last_password_change FROM {users} AS u JOIN {force_password_change_users} AS fpcu ON fpcu.uid = u.uid ';
+  if ($rid > 2) {
+    $pending_query .= 'JOIN {users_roles} AS ur ON ur.uid = u.uid ';
+  }
+  $pending_query .= 'WHERE u.force_password_change = 1 ';
+  if ($rid > 2) {
+    $pending_query .= ' AND ur.rid = ' . $rid . ' ';
+  }
+  $pending_query .= tablesort_sql($pending_header);
+  $pending_user_data = pager_query($pending_query, 100, 0);
+  
+  $rows = array();
+  $force_password_change_installation_date = variable_get('force_password_change_installation_date', 0);
+  $forced_uids = variable_get('force_password_change_first_time_uids', array());
+  while($pending_user = db_fetch_array($pending_user_data)) {
+    $row = array();
+    $row[] = l($pending_user['name'], 'user/' . $pending_user['uid']);
+    if ($pending_user['last_force'] != '') {
+      $last_force = format_date($pending_user['last_force'], 'small');
+    }
+    elseif (variable_get('first_time_login_password_change', FALSE) && $pending_user['created'] > $force_password_change_installation_date) {
+      $last_force = t('Their first login');
+    }
+    else {
+      if (count($forced_uids) && isset($forced_uids[$pending_user['uid']])) {
+        $last_force = t('Their first login');
+      }
+      elseif ($pending_user['last_password_change'] != '') {
+        $last_force = t('Their first login');
+      }
+      else {
+        $last_force = t('Never');
+      }
+    }
+    $row[] = $last_force;
+    $row[] = ($pending_user['last_password_change'] != '') ? format_date($pending_user['last_password_change'], 'small') : t('Never');
+    $rows[] = $row;
+  }
+  if (!count($rows)) {
+    $row = array();
+    $row[] = array('data' => t('No users found'), 'colspan' => 3);
+    $rows[] = $row;
+  }
+  $output .= '<h3>' . t('Users with a pending password change') . '</h3>' . theme('table', $pending_header, $rows) . theme('pager', array(), 100, 0);
 
-	$nonpending_header = array
-	(
-		array('data' => t('Username'), 'field' => 'u.name', 'sort' => 'asc'),
-		array('data' => t('Last Forced Password Change'), 'field' => 'fpcu.last_force'),
-		array('data' => t('Last Password Change'), 'field' => 'fpcu.last_password_change'),
-	);
-	$nonpending_query = 'SELECT u.uid, u.name, u.created, fpcu.last_force, fpcu.last_password_change ' .
-						'FROM {users} AS u ' .
-						'JOIN {force_password_change_users} AS fpcu ' .
-						'ON fpcu.uid = u.uid ';
-	if($rid > 2)
-	{
-		$nonpending_query .= 'JOIN {users_roles} AS ur ' .
-							'ON ur.uid = u.uid ';
-	}
-	$nonpending_query .= 'WHERE u.force_password_change = 0 ';
-	if($rid > 2)
-	{
-		$nonpending_query .= ' AND ur.rid = ' . $rid . ' ';
-	}
-	$nonpending_query .= tablesort_sql($nonpending_header);
-	$nonpending_user_data = pager_query
-	(
-		$nonpending_query,
-		100,
-		1
-	);
-	$rows = array();
-	while($nonpending_user = db_fetch_array($nonpending_user_data))
-	{
-		$row = array();
-		$row[] = l($nonpending_user['name'], 'user/' . $nonpending_user['uid']);
-		if($nonpending_user['last_force'] != '')
-		{
-			$last_force = format_date($nonpending_user['last_force'], 'small');
-		}
-		elseif(variable_get('first_time_login_password_change', FALSE) && $nonpending_user['created'] > $force_password_change_installation_date)
-		{
-			$last_force = t('Their first login');
-		}
-		else
-		{
-			if(count($forced_uids) && isset($forced_uids[$nonpending_user['uid']]))
-			{
-				$last_force = t('Their first login');
-			}
-			elseif($nonpending_user['last_password_change'] != '')
-			{
-				$last_force = t('Their first login');
-			}
-			else
-			{
-				$last_force = t('Never');
-			}
-		}
-		$row[] = $last_force;
-		$row[] = ($nonpending_user['last_password_change'] != '') ? format_date($nonpending_user['last_password_change'], 'small') : t('Never');
-		$rows[] = $row;
-	}
-	if(!count($rows))
-	{
-		$row = array();
-		$row[] = array('data' => t('No users found'), 'colspan' => 3);
-		$rows[] = $row;
-	}
-	$output .= '<h3>' . t('Users without a pending password change') . '</h3>' . theme('table', $nonpending_header, $rows) . theme('pager', array(), 100, 1);
-	
-	$output .= drupal_get_form('force_password_change_single_role', $rid);
-	
-	if($_GET['return'] == 'settings')
-	{
-		$output .= '<p>' . l(t('Back to settings page'), 'admin/user/force_password_change') . '</p>';
-	}
-	elseif($_GET['return'] == 'roles')
-	{
-		$output .= '<p>' . l(t('Back to roles page'), 'admin/user/roles') . '</p>';
-	}
-	
-	return $output;
+  $nonpending_header = array(
+    array('data' => t('Username'), 'field' => 'u.name', 'sort' => 'asc'),
+    array('data' => t('Last Forced Password Change'), 'field' => 'fpcu.last_force'),
+    array('data' => t('Last Password Change'), 'field' => 'fpcu.last_password_change'),
+  );
+  $nonpending_query = 'SELECT u.uid, u.name, u.created, fpcu.last_force, fpcu.last_password_change FROM {users} AS u JOIN {force_password_change_users} AS fpcu ON fpcu.uid = u.uid ';
+  if ($rid > 2) {
+    $nonpending_query .= 'JOIN {users_roles} AS ur ON ur.uid = u.uid ';
+  }
+  $nonpending_query .= 'WHERE u.force_password_change = 0 ';
+  if ($rid > 2) {
+    $nonpending_query .= ' AND ur.rid = ' . $rid . ' ';
+  }
+  $nonpending_query .= tablesort_sql($nonpending_header);
+  $nonpending_user_data = pager_query(
+    $nonpending_query,
+    100,
+    1
+  );
+  $rows = array();
+  while($nonpending_user = db_fetch_array($nonpending_user_data)) {
+    $row = array();
+    $row[] = l($nonpending_user['name'], 'user/' . $nonpending_user['uid']);
+    if ($nonpending_user['last_force'] != '') {
+      $last_force = format_date($nonpending_user['last_force'], 'small');
+    }
+    elseif (variable_get('first_time_login_password_change', FALSE) && $nonpending_user['created'] > $force_password_change_installation_date) {
+      $last_force = t('Their first login');
+    }
+    else {
+      if (count($forced_uids) && isset($forced_uids[$nonpending_user['uid']])) {
+        $last_force = t('Their first login');
+      }
+      elseif ($nonpending_user['last_password_change'] != '') {
+        $last_force = t('Their first login');
+      }
+      else {
+        $last_force = t('Never');
+      }
+    }
+    $row[] = $last_force;
+    $row[] = ($nonpending_user['last_password_change'] != '') ? format_date($nonpending_user['last_password_change'], 'small') : t('Never');
+    $rows[] = $row;
+  }
+  if (!count($rows)) {
+    $row = array();
+    $row[] = array('data' => t('No users found'), 'colspan' => 3);
+    $rows[] = $row;
+  }
+  $output .= '<h3>' . t('Users without a pending password change') . '</h3>' . theme('table', $nonpending_header, $rows) . theme('pager', array(), 100, 1);
+  
+  $output .= drupal_get_form('force_password_change_single_role', $rid);
+  
+  if ($_GET['return'] == 'settings') {
+    $output .= '<p>' . l(t('Back to settings page'), 'admin/user/force_password_change') . '</p>';
+  }
+  elseif ($_GET['return'] == 'roles') {
+    $output .= '<p>' . l(t('Back to roles page'), 'admin/user/roles') . '</p>';
+  }
+  
+  return $output;
 }
 
 /**
  * Form to force a password change on a single role. Used on the details page
  */
-function force_password_change_single_role($form_state, $rid)
-{
-	$form['force_password_change'] = array
-	(
-		'#type' => 'checkbox',
-		'#title' => t('Force users in this role to change their password'),
-		'#description' => t('Users who are not signed in will be required to change their password immediately upon sign in. Users who are currently signed in will be required to change their password upon their next page click, but after changing their password will be redirected back to the page they were attempting to access.') . '<br />' . t('Note: When you return to this page, this box will be unchecked. This is because this setting is a trigger, not a persistant state.'),
-		'#weight' => -1,
-	);
-	$form['rid'] = array
-	(
-		'#type' => 'value',
-		'#value' => $rid,
-	);
-	$form['submit'] = array
-	(
-		'#type' => 'submit',
-		'#value' => t('Force Password Change'),
-	);
-	return $form;
+function force_password_change_single_role($form_state, $rid) {
+  $form['force_password_change'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Force users in this role to change their password'),
+    '#description' => t('Users who are not signed in will be required to change their password immediately upon sign in. Users who are currently signed in will be required to change their password upon their next page click, but after changing their password will be redirected back to the page they were attempting to access.') . '<br />' . t('Note: When you return to this page, this box will be unchecked. This is because this setting is a trigger, not a persistant state.'),
+    '#weight' => -1,
+  );
+  $form['rid'] = array(
+    '#type' => 'value',
+    '#value' => $rid,
+  );
+  $form['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Force Password Change'),
+  );
+  return $form;
 }
 
 /**
  * Submission function for the form that forces a password change on a single role
 
  */
-function force_password_change_single_role_submit($form, &$form_state)
-{
-	$uids = array();
-	$db_uids = db_query
-	(
-		'SELECT uid ' .
-		'FROM {users_roles} ' .
-		'WHERE rid = %d',
-		$form_state['values']['rid']
-	);
-	while($uid = db_fetch_array($db_uids))
-	{
-		$uids[] = $uid['uid'];
-	}
-	$uid_list = implode(', ', $uids);
-	if(strlen($uid_list))
-	{
-		db_query
-		(
-			'UPDATE {users} ' .
-			'SET force_password_change = 1 ' .
-			'WHERE uid IN (%s)',
-			$uid_list
-		);
-		db_query
-		(
-			'UPDATE {force_password_change_users} ' .
-			'SET last_force = %d ' .
-			'WHERE uid IN (%s)',
-			time(),
-			$uid_list
-		);
-	}
-	db_query
-	(
-		'UPDATE {force_password_change_roles} ' .
-		'SET last_force = %d ' .
-		'WHERE rid = %d ',
-		time(),
-		$form_state['values']['rid']
-	);
-	drupal_set_message(t('Users in this role will be required to immediately change their password'));	
+function force_password_change_single_role_submit($form, &$form_state) {
+  $uids = array();
+  $db_uids = db_query('SELECT uid FROM {users_roles} WHERE rid = %d', $form_state['values']['rid']);
+  while($uid = db_fetch_array($db_uids)) {
+    $uids[] = $uid['uid'];
+  }
+  $uid_list = implode(', ', $uids);
+  if (strlen($uid_list)) {
+    db_query('UPDATE {users} SET force_password_change = 1 WHERE uid IN (%s)', $uid_list);
+    db_query('UPDATE {force_password_change_users} SET last_force = %d WHERE uid IN (%s)', time(), $uid_list);
+  }
+  db_query('UPDATE {force_password_change_roles} SET last_force = %d WHERE rid = %d', time(), $form_state['values']['rid']);
+  drupal_set_message(t('Users in this role will be required to immediately change their password'));  
 }
 
 /**
  * Theme function that effectively rebuilds the add new role form (Administer -> User management -> Roles)
  * This function adds a link from each role the force password change details page for that role
  */
-function theme_force_password_change_new_role_form($form)
-{
-	$header = array(t('Name'), array('data' => t('Operations'), 'colspan' => 3));
-	foreach (user_roles() as $rid => $name)
-	{
-		$edit_permissions = l(t('edit permissions'), 'admin/user/permissions/'. $rid);
-		if (!in_array($rid, array(DRUPAL_ANONYMOUS_RID, DRUPAL_AUTHENTICATED_RID)))
-		{
-			$rows[] = array($name, l(t('edit role'), 'admin/user/roles/edit/'. $rid), $edit_permissions, l(t('Force Password Change'), 'force_password_change/list/' . $rid, array('query' => 'return=roles')));
-		}
-		else
-		{
-			if($rid == DRUPAL_AUTHENTICATED_RID)
-			{
-				$rows[] = array($name, t('locked'), $edit_permissions, l(t('Force Password Change'), 'force_password_change/list/' . $rid, array('query' => 'return=roles')));
-			}
-			else
-			{
-				$rows[] = array($name, t('locked'), $edit_permissions, '---');
-			}
-		}
-	}
-	$rows[] = array(drupal_render($form['name']), array('data' => drupal_render($form['submit']), 'colspan' => 3));
-	
-	$output = drupal_render($form);
-	$output .= theme('table', $header, $rows);
-	
-	return $output;
+function theme_force_password_change_new_role_form($form) {
+  $header = array(t('Name'), array('data' => t('Operations'), 'colspan' => 3));
+  foreach (user_roles() as $rid => $name) {
+    $edit_permissions = l(t('edit permissions'), 'admin/user/permissions/'. $rid);
+    if (!in_array($rid, array(DRUPAL_ANONYMOUS_RID, DRUPAL_AUTHENTICATED_RID))) {
+      $rows[] = array($name, l(t('edit role'), 'admin/user/roles/edit/'. $rid), $edit_permissions, l(t('Force Password Change'), 'force_password_change/list/' . $rid, array('query' => 'return=roles')));
+    }
+    else {
+      if ($rid == DRUPAL_AUTHENTICATED_RID) {
+        $rows[] = array($name, t('locked'), $edit_permissions, l(t('Force Password Change'), 'force_password_change/list/' . $rid, array('query' => 'return=roles')));
+      }
+      else {
+        $rows[] = array($name, t('locked'), $edit_permissions, '---');
+      }
+    }
+  }
+  $rows[] = array(drupal_render($form['name']), array('data' => drupal_render($form['submit']), 'colspan' => 3));
+  
+  $output = drupal_render($form);
+  $output .= theme('table', $header, $rows);
+  
+  return $output;
 }
 
 /**
  * Theme function for the settings page. This is used to place the stats for a role beside the checkbox, without having to 
  * include the stats in the label
  */
-function theme_force_password_change_settings($form)
-{
-	$path = drupal_get_path('module', 'force_password_change');
-	drupal_add_css($path . '/css/force_password_change_settings.css', 'module', 'all', FALSE);
-	$output = drupal_render($form['first_time_login_password_change']);
-	$temp_output .= '<div id="force_password_roles">';
-	foreach(element_children($form['roles']) as $rid)
-	{
-		$temp_output .= drupal_render($form['roles'][$rid]);
-		$temp_output .= '<p>(' . t('Users in role: !user_count | Users with pending forced password change: !pending_count | !details', array('!user_count' => $form['stats']['#value'][$rid]['user_count'], '!pending_count' => $form['stats']['#value'][$rid]['pending_count'], '!details' => l(t('Details'), 'force_password_change/list/' . $rid, array('query' => 'return=settings')))) . ')</p>';
-	}
-	$temp_output .= '</div>';
-	$output .= drupal_render($form['roles']) . $temp_output;
-	return $output . drupal_render($form);
+function theme_force_password_change_settings($form) {
+  $path = drupal_get_path('module', 'force_password_change');
+  drupal_add_css($path . '/css/force_password_change_settings.css', 'module', 'all', FALSE);
+  $output = drupal_render($form['first_time_login_password_change']);
+  $temp_output .= '<div id="force_password_roles">';
+  foreach(element_children($form['roles']) as $rid) {
+    $temp_output .= drupal_render($form['roles'][$rid]);
+    $temp_output .= '<p>(' . t('Users in role: !user_count | Users with pending forced password change: !pending_count | !details', array('!user_count' => $form['stats']['#value'][$rid]['user_count'], '!pending_count' => $form['stats']['#value'][$rid]['pending_count'], '!details' => l(t('Details'), 'force_password_change/list/' . $rid, array('query' => 'return=settings')))) . ')</p>';
+  }
+  $temp_output .= '</div>';
+  $output .= drupal_render($form['roles']) . $temp_output;
+  return $output . drupal_render($form);
 }
 
 /**
  * Theme function for password expiry on the settings page. This is used add the tabledrag for the expiry data
  */
-function theme_force_password_change_expiry($form)
-{
-	drupal_add_tabledrag('password_expiry_table', 'order', 'sibling', 'weight-group');
-	$header = array(t('Role'), t('Expire password after:'), t('Weight'));
-	$rows = array();
-	foreach(element_children($form) as $key)
-	{
-		$element = &$form[$key];
-		$element['weight']['#attributes']['class'] = 'weight-group';
-		$row = array();
-		$row[] = drupal_render($element['role']);
-		$row[] = drupal_render($element['time_quantity']) . drupal_render($element['time_period']);
-		$row[] = drupal_render($element['weight']);
-		$rows[] = array('data' => $row, 'class' => 'draggable');
-	}
-	$output = theme('table', $header, $rows, array('id' => 'password_expiry_table'));
-	return $output . drupal_render($form);
-}
\ No newline at end of file
+function theme_force_password_change_expiry($form) {
+  drupal_add_tabledrag('password_expiry_table', 'order', 'sibling', 'weight-group');
+  $header = array(t('Role'), t('Expire password after:'), t('Weight'));
+  $rows = array();
+  foreach(element_children($form) as $key) {
+    $element = &$form[$key];
+    $element['weight']['#attributes']['class'] = 'weight-group';
+    $row = array();
+    $row[] = drupal_render($element['role']);
+    $row[] = drupal_render($element['time_quantity']) . drupal_render($element['time_period']);
+    $row[] = drupal_render($element['weight']);
+    $rows[] = array('data' => $row, 'class' => 'draggable');
+  }
+  $output = theme('table', $header, $rows, array('id' => 'password_expiry_table'));
+  return $output . drupal_render($form);
+}
