? userpoint.patch
Index: userpoints.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/userpoints/userpoints.module,v
retrieving revision 1.67.2.57
diff -u -p -r1.67.2.57 userpoints.module
--- userpoints.module	30 Apr 2010 15:55:09 -0000	1.67.2.57
+++ userpoints.module	10 May 2010 17:07:15 -0000
@@ -5,7 +5,7 @@
 
 define('USERPOINTS_PERM_VIEW',           'view userpoints');
 define('USERPOINTS_PERM_VIEW_OWN',       'view own userpoints');
-//The permission(PERM_USE) was removed from use as per #158490 it'll remain 
+//The permission(PERM_USE) was removed from use as per #158490 it'll remain
 //out until code exists to use the permission (jredding 12/26/2007)
 define('USERPOINTS_PERM_USE',            'use userpoints');
 define('USERPOINTS_PERM_ADMIN',          'administer userpoints');
@@ -46,7 +46,7 @@ define('USERPOINTS_TRANSACTION_TIMESTAMP
  */
 function userpoints_translation() {
   static $trans;
-  
+
   if (!isset($trans)) {
     $trans = array(
       '!Points' => variable_get(USERPOINTS_TRANS_UCPOINTS, 'Points'),
@@ -56,7 +56,7 @@ function userpoints_translation() {
       '!Uncategorized'  => variable_get(USERPOINTS_TRANS_UNCAT, 'Uncategorized'),
       );
   }
-  return $trans;  
+  return $trans;
 }
 
 /*
@@ -136,7 +136,7 @@ function userpoints_menu() {
     'access arguments' => array(USERPOINTS_PERM_ADMIN),
     'type'             => MENU_CALLBACK
   );
-  
+
   $items['admin/user/userpoints/approve'] = array(
     'title'            => 'Approve Userpoints',
     'page callback'    => 'userpoints_admin_approve',
@@ -149,7 +149,7 @@ function userpoints_menu() {
     'access arguments' => array(USERPOINTS_PERM_ADMIN),
     'type'             => MENU_CALLBACK
   );
-  
+
   $items['userpoints'] = array(
     'title'            => 'Users by !points',
     'title arguments'  => userpoints_translation(),
@@ -157,7 +157,7 @@ function userpoints_menu() {
     'access arguments' => array(USERPOINTS_PERM_VIEW),
     'type'             => MENU_NORMAL_ITEM,
   );
-  
+
   $items['myuserpoints'] = array(
     'title'           => 'My !points',
     'title arguments' => userpoints_translation(),
@@ -178,9 +178,9 @@ function userpoints_access_my_points() {
   if ($user->uid === 1 || user_access('USERPOINTS_PERM_ADMIN')) {
     return TRUE;
   }
-  return ( _userpoints_user_exists($user->uid) && 
-					((user_access(USERPOINTS_PERM_VIEW) && user_is_logged_in()) || user_access(USERPOINTS_PERM_VIEW_OWN)) 
-				 );
+  return ( _userpoints_user_exists($user->uid) &&
+          ((user_access(USERPOINTS_PERM_VIEW) && user_is_logged_in()) || user_access(USERPOINTS_PERM_VIEW_OWN))
+         );
 }
 
 /**
@@ -204,8 +204,8 @@ function userpoints_theme() {
         )
       ),
     'userpoints_list_users_header' => array(
-	    'arguments' => array()
-	   ),
+      'arguments' => array()
+     ),
     'userpoints_list_users_row' => array(
       'arguments' => array(
         'row' => NULL,
@@ -257,7 +257,7 @@ function userpoints_admin_settings() {
     '#collapsed' => TRUE,
     '#title' => t('Points branding'),
   );
-  
+
   $form[$group][USERPOINTS_TRANS_UCPOINTS] = array(
   '#type' => 'textfield',
   '#title' => t('Word to use in the interface for the upper case plural word !Points', userpoints_translation()),
@@ -265,7 +265,7 @@ function userpoints_admin_settings() {
   '#size' => 20,
   '#maxlength' => 20,
   );
-  
+
   $form[$group][USERPOINTS_TRANS_LCPOINTS] = array(
   '#type' => 'textfield',
   '#title' => t('Word to use in the interface for the lower case plural word !points', userpoints_translation()),
@@ -331,7 +331,7 @@ function userpoints_admin_settings() {
   );
 
   /**
-   * If the expiration date is earlier than today 
+   * If the expiration date is earlier than today
    * new points will last forever. Although this may be desirable
    * it could also be an oversight so we'll display a message
    * to the administrator
@@ -346,26 +346,26 @@ function userpoints_admin_settings() {
     '#type' => 'date',
     '#title' => t('Expire !points on this date', userpoints_translation()),
     '#description' => t('Once !points have been obtained by the user they will
-                         last until this date. This setting overrides the 
+                         last until this date. This setting overrides the
                          "Expire after setting" above ', userpoints_translation()). $warning,
     '#default_value' => variable_get(USERPOINTS_EXPIREON_DATE, array('day' => 1, 'month' => 1, 'year' => 1980)),
   );
   $form[$group][USERPOINTS_EXPIRY_DESCRIPTION] = array(
     '#type' => 'textarea',
     '#title' => t('Expiration entry description'),
-    '#description' => t('A negating expiration entry is made to expire 
+    '#description' => t('A negating expiration entry is made to expire
                          !points leaving the original entry intact
                          (e.g. original !points + expiration !points = 0).
                          When the expiration entry is made this description will
                          be placed on the entry. This is useful so the users will
                          know what happened to their !point balance. In crafting
                          your message you can use the following variables.',
- 												 userpoints_translation()). t('
-                         <br /> !points = The name used in branding 
+                         userpoints_translation()). t('
+                         <br /> !points = The name used in branding
                          above (also use !Points and !point)'). t('
                          <br /> !operation = Original operation that granted the !points
                          <br /> !description = Original description for the !point
-                         <br /> !txn_id Original transaction ID 
+                         <br /> !txn_id Original transaction ID
                          <br /> !date = Date of the original entry',  userpoints_translation()),
     '#default_value' => variable_get(USERPOINTS_EXPIRY_DESCRIPTION, ''),
   );
@@ -400,7 +400,7 @@ function userpoints_admin_settings() {
     '#title'         => t('Transactions per page'),
     '#default_value' => variable_get(USERPOINTS_REPORT_LIMIT, 10),
     '#options'       => array(10 => 10, 20 => 20, 30 => 30, 40 => 40, 50 => 50, 100 => 100),
-    '#description'   => t('Limits the number of transactions displayed per page'), 
+    '#description'   => t('Limits the number of transactions displayed per page'),
   );
   $form[$group][USERPOINTS_REPORT_DISPLAYZERO] = array(
     '#type'          => 'radios',
@@ -414,13 +414,13 @@ function userpoints_admin_settings() {
     '#title'         => t('Users per page'),
     '#default_value' => variable_get(USERPOINTS_REPORT_USERCOUNT, 30),
     '#options'       => array(10 => 10, 20 => 20, 30 => 30, 40 => 40, 50 => 50, 100 => 100),
-    '#description'   => t('When listing !points by user limit how many users are displayed on a single page', userpoints_translation()), 
+    '#description'   => t('When listing !points by user limit how many users are displayed on a single page', userpoints_translation()),
   );
-  
 
-  /* Categories will only appear if the taxonomy module is enabled as 
+
+  /* Categories will only appear if the taxonomy module is enabled as
    * the module is required for this functionality but not necessarily
-   * a requirement for the module. 
+   * a requirement for the module.
    */
   if (module_exists('taxonomy')) {
     $group = 'category';
@@ -438,16 +438,16 @@ function userpoints_admin_settings() {
       '#description' => t('By default all !points are assigned to this category.  You can modify what categories are available by modifying the <a href="!url">Userpoints taxonomy</a>',
         array_merge(userpoints_translation(), array('!url' => url('admin/content/taxonomy/'. variable_get(USERPOINTS_CATEGORY_DEFAULT_VID, ''))))),
     );
-    $options = userpoints_get_categories(); 
+    $options = userpoints_get_categories();
     //$options doesn't include all so we'll add it
     $options['all'] = t('All categories');
-	  $form[$group][USERPOINTS_CATEGORY_PROFILE_DISPLAY_TID] = array(
-	    '#type' => 'select',
-	    '#title' => t('Category to display on the user profile page'),
-	    '#default_value' => variable_get(USERPOINTS_CATEGORY_PROFILE_DISPLAY_TID, NULL),
-	    '#options' =>  $options,
-	    '#description' => t('Select which category of !points to display on the user profile page. Select "All" to display a sum total of all categories', userpoints_translation()),
-	  );
+    $form[$group][USERPOINTS_CATEGORY_PROFILE_DISPLAY_TID] = array(
+      '#type' => 'select',
+      '#title' => t('Category to display on the user profile page'),
+      '#default_value' => variable_get(USERPOINTS_CATEGORY_PROFILE_DISPLAY_TID, NULL),
+      '#options' =>  $options,
+      '#description' => t('Select which category of !points to display on the user profile page. Select "All" to display a sum total of all categories', userpoints_translation()),
+    );
   }
   // New configuration options to overide current timestamp
   $group = "stamping";
@@ -467,7 +467,7 @@ function userpoints_admin_settings() {
 
   $form['setting'] = module_invoke_all('userpoints', 'setting');
   return system_settings_form($form);
-}  
+}
 
 /**
  * @param uid: user id of the user to get or lose the points
@@ -475,7 +475,7 @@ function userpoints_admin_settings() {
  * @return number of current points in that user's account
  */
 function userpoints_get_current_points($uid = NULL, $tid = NULL) {
-  if (!$uid) { 
+  if (!$uid) {
     global $user;
     $uid = $user->uid;
   }
@@ -497,7 +497,7 @@ function userpoints_get_max_points($uid 
   static $max = array();
 
   // Check if uid is passed as a parameter
-  if (!$uid) { 
+  if (!$uid) {
     // It is not, so we use the currently logged in user's uid
     global $user;
     $uid = $user->uid;
@@ -528,13 +528,13 @@ function userpoints_get_max_points($uid 
 /**
  * @param $params(array) or (int)
  *    if (int) assumed to be points for current user
- *    Accepts an array of keyed variables and parameters  
+ *    Accepts an array of keyed variables and parameters
  *    'points' => # of points (int) (required)
- *    'moderate' => TRUE/FALSE 
- *    'uid' => $user->uid 
+ *    'moderate' => TRUE/FALSE
+ *    'uid' => $user->uid
  *    'time_stamp' => unix time of the points assignement date
  *    'operation' => 'published' 'moderated' etc.
- *    'tid' => 'category ID' 
+ *    'tid' => 'category ID'
  *    'expirydate' => timestamp or 0, 0 = non-expiring; NULL = site default
  *    'description' => 'description'
  *    'reference' => reserved for module specific use
@@ -543,7 +543,7 @@ function userpoints_get_max_points($uid 
  *    'entity_id' => ID of an entity in the Database. ex. $node->id or $user->uid
  *    'entity_type' => string of the entity type. ex. 'node' or 'user' NOT 'node-content-custom'
  *
- * @return array with status and reason. 
+ * @return array with status and reason.
  *     'status' => FALSE when no action is take, TRUE when points are credited or debited
  *     'reason' => (string) error message to indicate reason for failure
  */
@@ -561,7 +561,7 @@ function userpoints_userpointsapi($param
       //has to be an array to continue
       return array(
         'status' => false,
-        'reason' => 'Parameters did not properly form as an array, 
+        'reason' => 'Parameters did not properly form as an array,
                      this is an internal module error.
                     ',
       );
@@ -575,7 +575,7 @@ function userpoints_userpointsapi($param
     $params_null_check = array('operation', 'description', 'reference', 'display', 'entity_id', 'entity_type');
     foreach($params_null_check as $param_null_check) {
       if (!isset($params[$param_null_check])) {
-        $params[$param_null_check] = NULL; 
+        $params[$param_null_check] = NULL;
       }
     }
 
@@ -618,7 +618,7 @@ function userpoints_userpointsapi($param
       'reason' => 'invalid uid or user account could not be loaded',
     );
   }
-  
+
   // Call the _userpoints hook, and stop if one of them returns FALSE
   $rc = module_invoke_all('userpoints', 'points before', $params);
 
@@ -635,7 +635,7 @@ function userpoints_userpointsapi($param
     $msg = t('lost');
   }
   elseif ($params['status'] == 2) {
-    //points have been declined 
+    //points have been declined
     $msg = t('was declined');
   }
   else {
@@ -649,7 +649,7 @@ function userpoints_userpointsapi($param
       'reason' => 'transaction failed in _userpoints_transaction, this is an internal module error',
     );
   }
-  
+
   if ($params['status'] == 1) {
     $mesg = (t('User %uname %op %pointsvalue !points, pending administrator approval.',
       array_merge(userpoints_translation(), array(
@@ -659,7 +659,7 @@ function userpoints_userpointsapi($param
         '%total'  => userpoints_get_current_points($params['uid'], $params['tid']),
         ))
       ));
-  } 
+  }
   else {
     $mesg = (t('User %uname %op %pointsvalue !points Total now is %total !points.',
       array_merge(userpoints_translation(), array(
@@ -682,19 +682,19 @@ function userpoints_userpointsapi($param
 
 /*
  * Adds the points to the txn table
- * PRIVATE FUNCTION use userpoints_userpointsapi! 
+ * PRIVATE FUNCTION use userpoints_userpointsapi!
  */
 function _userpoints_transaction(&$params) {
   //Check, again, for a properly formed array
-  if (!is_array($params)) { 
-    return false; 
+  if (!is_array($params)) {
+    return false;
   }
   if (!isset($params['txn_id'])) {
     //If a txn_id is preset we UPDATE the record instead of adding one
     //the standard checks don't apply
-    if (!is_numeric($params['points'])) { 
-      return false; 
-    } 
+    if (!is_numeric($params['points'])) {
+      return false;
+    }
     if (!isset($params['uid'])) {
       global $user;
       $params['uid'] = $user->uid;
@@ -716,14 +716,14 @@ function _userpoints_transaction(&$param
       }
     }
     if (isset($params['expirydate']) && !is_numeric($params['expirydate'])) {
-      return false;	
+      return false;
     }
 
     // check if parameters are set
     $params_null_check = array('operation', 'description', 'reference', 'expired', 'parent_txn_id', 'entity_id', 'entity_type');
     foreach($params_null_check as $param_null_check) {
       if (!isset($params[$param_null_check])) {
-        $params[$param_null_check] = NULL; 
+        $params[$param_null_check] = NULL;
       }
     }
 
@@ -735,7 +735,7 @@ function _userpoints_transaction(&$param
       //this is a backwards compatibilty issue
       $params['tid'] = NULL;
     }
-    if (!isset($params['expirydate'])) { 
+    if (!isset($params['expirydate'])) {
       $params['expirydate'] = userpoints_get_default_expiry_date();
     }
   } // if txn_id
@@ -751,8 +751,8 @@ function _userpoints_transaction(&$param
 
   if (!empty($params['txn_id']) && is_numeric($params['txn_id'])) {
     //A transaction ID was passed in so we'll update the transaction
-    $result = db_query("SELECT txn_id, uid, approver_uid, points, 
-      time_stamp, status, operation, description, reference, expirydate, expired, 
+    $result = db_query("SELECT txn_id, uid, approver_uid, points,
+      time_stamp, status, operation, description, reference, expirydate, expired,
       parent_txn_id, tid, entity_id, entity_type
       FROM {userpoints_txn}
       WHERE txn_id = %d",
@@ -784,7 +784,7 @@ function _userpoints_transaction(&$param
  */
 function _userpoints_update_cache(&$params) {
   if ( $params['status'] != 0 || $params['expired'] == 1) {
-      //Only update the cache for fully approved non-expired points 
+      //Only update the cache for fully approved non-expired points
       return false;
   }
   if (!isset($params['tid'])) {
@@ -804,7 +804,7 @@ function _userpoints_update_cache(&$para
   // insert or update the userpoints caching table with the user's current points
   if (_userpoints_user_exists($params['uid'], $params['tid'])) {
     db_query("UPDATE {userpoints}
-              SET points = %d, max_points = %d, last_update = %d 
+              SET points = %d, max_points = %d, last_update = %d
               WHERE uid = %d AND tid = %d",
               $current_points,
               $max_points,
@@ -835,8 +835,8 @@ function userpoints_get_default_expiry_d
   $expirydate = userpoints_date_to_timestamp(variable_get(USERPOINTS_EXPIREON_DATE, NULL));
   if ($expirydate < time()) {
     $expirydate = variable_get(USERPOINTS_EXPIREAFTER_DATE, NULL);
-    if ($expirydate) { 
-      $expirydate = time() + $expirydate; 
+    if ($expirydate) {
+      $expirydate = time() + $expirydate;
     }
   }
   return $expirydate;
@@ -845,23 +845,23 @@ function userpoints_get_default_expiry_d
 /*
  * Purpose: Checks to ensure that a user exists corresponding to a category
  * @param $uid User ID to check for existence of points for the user
- * @param $tid taxonomy id of the category to limit to, if omitted 
+ * @param $tid taxonomy id of the category to limit to, if omitted
  *   if the use has points in any category the return is true
- * Returns : true if user found, falase otherwise 
+ * Returns : true if user found, falase otherwise
  */
 function _userpoints_user_exists($uid, $tid = NULL) {
   if (is_numeric($tid) ) {
     return (int)db_result(
-      db_query('SELECT COUNT(uid) 
-      FROM {userpoints} 
-      WHERE uid = %d AND tid = %d', 
+      db_query('SELECT COUNT(uid)
+      FROM {userpoints}
+      WHERE uid = %d AND tid = %d',
       $uid, $tid));
   }
   else {
     return (int)db_result(
-      db_query('SELECT COUNT(uid) 
-      FROM {userpoints} 
-      WHERE uid = %d', 
+      db_query('SELECT COUNT(uid)
+      FROM {userpoints}
+      WHERE uid = %d',
       $uid));
 
   }
@@ -872,7 +872,7 @@ function _userpoints_user_exists($uid, $
  *
  */
 function userpoints_user($op, &$edit, &$account, $category = '') {
-	global $user;
+  global $user;
   switch ($op) {
     case 'delete':
       // The user is being deleted, delete all traces in userpoints and txn tables
@@ -884,27 +884,27 @@ function userpoints_user($op, &$edit, &$
       if (user_access(USERPOINTS_PERM_VIEW) || (user_access(USERPOINTS_PERM_VIEW_OWN) && $user->uid == $account->uid )) {
         $details = null;
         if (userpoints_access_my_points()) {
-		  		$details .= l(t('View'), 'myuserpoints/'. $account->uid, array('attributes' => array('title' => t('View detailed transactions'))));
-	    	}
+          $details .= l(t('View'), 'myuserpoints/'. $account->uid, array('attributes' => array('title' => t('View detailed transactions'))));
+        }
         if (user_access(USERPOINTS_PERM_ADMIN)) {
-	        if (!is_null($details)) {
-						$details .= ', ';
-					}
+          if (!is_null($details)) {
+            $details .= ', ';
+          }
           $details .= l(t('Adjust'), 'admin/user/userpoints/add/'. $account->uid, array('attributes' => array('title' => t('Add/substract !points from this user', userpoints_translation()))));
         }
 
-        //Which points are we display? 
+        //Which points are we display?
         $points = userpoints_get_current_points($account->uid, variable_get(USERPOINTS_CATEGORY_PROFILE_DISPLAY_TID, 0));
 
         $account->content['userpoints'] = array(
           '#type' => 'user_profile_category',
           '#title' => t('User !points', userpoints_translation()),
-				);
-				$account->content['userpoints']['points'] = array(
-		  		'#type' => 'user_profile_item',
-		  		'#title' => t('!Points', userpoints_translation()),
-		  		'#value' => $details ? $points .' - '. $details : $points,
-				);
+        );
+        $account->content['userpoints']['points'] = array(
+          '#type' => 'user_profile_item',
+          '#title' => t('!Points', userpoints_translation()),
+          '#value' => $details ? $points .' - '. $details : $points,
+        );
       }
       break;
   }
@@ -925,12 +925,12 @@ function userpoints_admin_manage() {
 
   $sql = "SELECT p.txn_id, p.uid, p.time_stamp, p.points, p.operation, p.status,
           p.entity_type, p.entity_id, t.name as cat
-          FROM {userpoints_txn} p 
-          LEFT JOIN {term_data} t ON p.tid = t.tid 
+          FROM {userpoints_txn} p
+          LEFT JOIN {term_data} t ON p.tid = t.tid
           WHERE p.status = %d";
 
   //Check for filtering
-  if (is_numeric($tid) && $tid == 0) { 
+  if (is_numeric($tid) && $tid == 0) {
     $sql .= " AND (p.tid IS NULL OR p.tid = '')";
     $cat = t('!Uncategorized', userpoints_translation());
   }
@@ -1046,12 +1046,12 @@ function userpoints_confirm_approve($for
     $form,
     t('Are you sure you want to @op txn @txn_id', array('@op' => $operation, '@txn_id' => $txn_id)),
     'admin/user/userpoints/moderate'
-    );  
+    );
 }
-       
+
 function userpoints_confirm_approve_submit($form, &$form_state) {
   global $user;
-  
+
   switch ($form_state['values']['operation']) {
     case 'approve':
       $status = USERPOINTS_TXN_STATUS_APPROVED;
@@ -1060,7 +1060,7 @@ function userpoints_confirm_approve_subm
       $status = USERPOINTS_TXN_STATUS_DECLINED;
       break;
     default:
-      return false; 
+      return false;
   }
 
   $params = array(
@@ -1118,7 +1118,7 @@ function userpoints_admin_txn($form_stat
     '#size'          => 30,
     '#maxlength'     => 30,
     '#description'   => t('Date and time of this transaction, in the form YYYY-MM-DD HH:MM +ZZZZ'),
-    );  
+    );
 
   if ($txn->txn_id) {
     if ($txn->expirydate > 0) {
@@ -1131,7 +1131,7 @@ function userpoints_admin_txn($form_stat
     if ($expirydate) {
       $expirydate = format_date($expirydate, 'custom', 'Y-m-d H:i O');
     }
-  }  
+  }
   $form['expirydate'] = array(
     '#type'          => 'textfield',
     '#title'         => t('Expiration date'),
@@ -1158,7 +1158,7 @@ function userpoints_admin_txn($form_stat
     '#size'          => 30,
     '#maxlength'     => 128,
     '#description'   => t('Enter optional reference for this transaction. This field will be indexed and searchable.'),
-    ); 
+    );
 
   $form['description'] = array(
     '#type'          => 'textarea',
@@ -1194,7 +1194,7 @@ function userpoints_admin_txn($form_stat
       break;
 
     case 'edit':
-     
+
       $form['txn_user']['#disabled'] = true;
       unset($form['txn_user']['#autocomplete_path']);
 
@@ -1226,8 +1226,8 @@ function userpoints_admin_txn($form_stat
 
       $form['status'] = array(
         '#title' => t('Approval status'),
-        '#type' => 'radios', 
-        '#options' => userpoints_txn_status(), 
+        '#type' => 'radios',
+        '#options' => userpoints_txn_status(),
         '#description' => t('Approval status of the transaction.'),
         '#default_value' => $txn->status,
         );
@@ -1265,12 +1265,12 @@ function userpoints_admin_txn_submit($fo
                   'time_stamp' => strtotime($form_state['values']['time_stamp']),
                 );
       if ($form_state['values']['expirydate']) {
-        //Check for the existence of an expirydate 
+        //Check for the existence of an expirydate
         $params['expirydate'] = strtotime($form_state['values']['expirydate']);
       }
       userpoints_userpointsapi($params);
       break;
-      
+
     case 'edit':
       if ($form_state['values']['expirydate']) {
         $expirydate = strtotime($form_state['values']['expirydate']);
@@ -1289,7 +1289,7 @@ function userpoints_admin_txn_submit($fo
       );
       userpoints_userpointsapi($params);
   }
-  
+
   $form_state['redirect'] = 'admin/user/userpoints';
 }
 
@@ -1300,15 +1300,15 @@ function userpoints_admin_points() {
   $tid = arg(3);
   $cat_count = count(userpoints_get_categories());
 
-  $sql = "SELECT p.uid, u.name, p.points, p.tid, t.name as cat 
-          FROM {userpoints} p INNER JOIN {users} u USING (uid) 
+  $sql = "SELECT p.uid, u.name, p.points, p.tid, t.name as cat
+          FROM {userpoints} p INNER JOIN {users} u USING (uid)
           LEFT JOIN {term_data} t ON p.tid = t.tid
           ";
 
   //Check for filtering
   if ( $tid === 0) {
     $sql .= "WHERE p.tid = 0";
-    $cat = t('!Uncategorized', userpoints_translation()); 
+    $cat = t('!Uncategorized', userpoints_translation());
   }
   elseif (is_numeric($tid)) {
     $sql .= "WHERE p.tid = %d";
@@ -1319,8 +1319,8 @@ function userpoints_admin_points() {
   }
   drupal_set_title(t($cat) ." ". t("!points", userpoints_translation()));
 
-  $sql_cnt = "SELECT COUNT(DISTINCT(uid)) 
-              FROM {userpoints} 
+  $sql_cnt = "SELECT COUNT(DISTINCT(uid))
+              FROM {userpoints}
               WHERE tid = %d
               ";
 
@@ -1371,8 +1371,8 @@ function userpoints_admin_points() {
 function userpoints_list_users() {
   $tid = arg(1);
 
-  $sql = "SELECT p.uid, u.name, p.points, p.tid, t.name as cat 
-          FROM {userpoints} p INNER JOIN {users} u USING (uid) 
+  $sql = "SELECT p.uid, u.name, p.points, p.tid, t.name as cat
+          FROM {userpoints} p INNER JOIN {users} u USING (uid)
           LEFT JOIN {term_data} t ON p.tid = t.tid
           ";
 
@@ -1384,15 +1384,15 @@ function userpoints_list_users() {
     }
     else {
       $sql .= "WHERE p.tid = %d";
-      $cat = t('!Uncategorized', userpoints_translation()); 
+      $cat = t('!Uncategorized', userpoints_translation());
     }
   }
   else {
     $cat = t('All');
   }
 
-  $sql_cnt = "SELECT COUNT(DISTINCT(uid)) 
-              FROM {userpoints} 
+  $sql_cnt = "SELECT COUNT(DISTINCT(uid))
+              FROM {userpoints}
               WHERE tid = %d
               ";
 
@@ -1420,7 +1420,7 @@ function userpoints_list_users() {
 /*
  * Themes the output of users by points page accessible at /userpoints
  * individual rows are themed with theme_userpoints_list_users_rows
- * 
+ *
  * @return
  *   HTML of the table and a pager
  */
@@ -1439,7 +1439,7 @@ function theme_userpoints_list_users($he
 }
 /*
  * Themes the header of the table on the "user by points" page accessible at /userpoints
- * 
+ *
  * @return
  *   An array suitable for use with tablesort_sql
  */
@@ -1483,7 +1483,7 @@ function userpoints_filter_cat_select($f
   $form = array();
   $formname = 'catselect';
   $sql = "SELECT DISTINCT p.tid, t.name
-          FROM {userpoints_txn} p 
+          FROM {userpoints_txn} p
           LEFT JOIN {term_data} t on p.tid = t.tid";
   $cats = userpoints_get_categories();
   $options = array();
@@ -1515,9 +1515,9 @@ function userpoints_block($op = 'list', 
       //Grab a list of the available terms
       $terms = userpoints_get_categories();
       foreach ($terms as $key => $value) {
-        $blocks[$key]['info'] = t("Highest $value !points", userpoints_translation());; 
+        $blocks[$key]['info'] = t("Highest $value !points", userpoints_translation());;
       } //foreach
-      
+
       return $blocks;
 
     case 'view':
@@ -1543,7 +1543,7 @@ function userpoints_block($op = 'list', 
           if ( $delta == 0 ) {
             $sql .= ' WHERE p.tid = 0 OR p.tid IS NULL ORDER BY p.points DESC';
             $result = db_query_range($sql, 0, $num);
-          } 
+          }
           else {
             $sql .= ' WHERE p.tid = %d ORDER BY p.points DESC';
             $result = db_query_range($sql, $delta, 0, $num);
@@ -1597,10 +1597,10 @@ function expiry_dates() {
   2419200  => 'Four Weeks',
   31536000 => '365 Days',
   );
-} //expiry_dates 
+} //expiry_dates
 
 /* userpoints_date_to_timestamp
- * Purpose: modifies FAPI date setting to timestamp 
+ * Purpose: modifies FAPI date setting to timestamp
  * Returns UNIX timestamp
  */
 function userpoints_date_to_timestamp($date) {
@@ -1611,22 +1611,22 @@ function userpoints_date_to_timestamp($d
 }
 
 /*
- * Purpose: Finds all transactions with a expirydate < time() and posts 
+ * Purpose: Finds all transactions with a expirydate < time() and posts
  *          opposite transactions (sum of 0)
  */
 function userpoints_expire_transactions() {
-  $sql = "SELECT txn_id, uid, points, time_stamp, operation, description 
-          FROM {userpoints_txn} 
-          WHERE status = 0 AND expired = 0 
-          AND (expirydate < %d AND expirydate != 0)"; 
+  $sql = "SELECT txn_id, uid, points, time_stamp, operation, description
+          FROM {userpoints_txn}
+          WHERE status = 0 AND expired = 0
+          AND (expirydate < %d AND expirydate != 0)";
   $results = db_query($sql, time());
   while ($line = db_fetch_array($results)) {
-    $line['time_stamp'] = format_date($line['time_stamp'], 'custom', 'Y-m-d H:i'); 
-    $description = t(variable_get(USERPOINTS_EXPIRY_DESCRIPTION, NULL), 
-      array_merge(userpoints_translation(), 
-      array('!operation' => $line['operation'], 
-        '!description' => $line['description'], 
-        '!txn_id' => $line['txn_id'], 
+    $line['time_stamp'] = format_date($line['time_stamp'], 'custom', 'Y-m-d H:i');
+    $description = t(variable_get(USERPOINTS_EXPIRY_DESCRIPTION, NULL),
+      array_merge(userpoints_translation(),
+      array('!operation' => $line['operation'],
+        '!description' => $line['description'],
+        '!txn_id' => $line['txn_id'],
         '!date' => $line['time_stamp']
         )
       )
@@ -1659,7 +1659,7 @@ function userpoints_cron() {
 
 /*
  * Purpose: Displays a detailed transaction report for an individual user
- * no URL argument returns current user otherwise accepts uid. 
+ * no URL argument returns current user otherwise accepts uid.
  */
 function userpoints_list_my_userpoints() {
   $overall_total = 0;
@@ -1689,7 +1689,7 @@ function userpoints_list_my_userpoints()
     drupal_access_denied();
     return;
   }
-		
+
   $title = t('!Points for ', userpoints_translation()) . check_plain($point_user->name);
   drupal_set_title($title);
 
@@ -1697,15 +1697,15 @@ function userpoints_list_my_userpoints()
   $sql = "SELECT p.tid, t.name
     FROM {userpoints_txn} p
     LEFT JOIN {term_data} t on p.tid = t.tid
-    WHERE uid = %d 
+    WHERE uid = %d
     GROUP BY p.tid, t.name";
-  $results = db_query($sql, $uid);  
+  $results = db_query($sql, $uid);
   $grand_total = 0;
   while ($result = db_fetch_array($results)) {
     if ($result['name'] == null) {
       $result['name'] = t('!Uncategorized', userpoints_translation());
     }
-    //pull the sum from the caching table for resource reason and b/c the 
+    //pull the sum from the caching table for resource reason and b/c the
     $result['total'] = userpoints_get_current_points($uid, $result['tid']);
     $args['subtotals'][$result['tid']] = $result;
 
@@ -1732,8 +1732,8 @@ function userpoints_list_my_userpoints()
     array('data' => t('Category'), 'field' => 'cat'),
     array('data' => t('Description'), 'field' => 'description'),
   );
-  $sql  = "SELECT p.points, p.time_stamp, p.operation, p.description, p.status, p.tid, t.name as cat , p.entity_id, p.entity_type 
-           FROM {userpoints_txn} p 
+  $sql  = "SELECT p.points, p.time_stamp, p.operation, p.description, p.status, p.tid, t.name as cat , p.entity_id, p.entity_type
+           FROM {userpoints_txn} p
            LEFT JOIN {term_data} t on p.tid = t.tid
            WHERE p.uid = %d";
   $sql .= tablesort_sql($header);
@@ -1745,7 +1745,7 @@ function userpoints_list_my_userpoints()
   while ($row = db_fetch_object($result)) {
     $num_rows++;
     $status = $stati[$row->status];
-    if (!$row->cat) { 
+    if (!$row->cat) {
       $row->cat = t('!Uncategorized', userpoints_translation());
     }
     if ($row->description) {
@@ -1793,11 +1793,11 @@ function userpoints_list_my_userpoints()
       array('data' => $row->cat),
       array('data' => $description),
     );
-  	if ($num_rows <= 0) {
-    	$rows[] = array(
+    if ($num_rows <= 0) {
+      $rows[] = array(
           array('data' => t('No !Points earned', userpoints_translation()), 'colspan' => 5, 'align' => 'center')
-    			);
-  	}
+          );
+    }
   }
   return theme('userpoints_list_my_userpoints', $args, $header, $rows);
 }
@@ -1807,9 +1807,9 @@ function userpoints_list_my_userpoints()
  *  if no vocab exists it will create one
  */
 function userpoints_get_vid() {
-	if (!module_exists('taxonomy')) {
+  if (!module_exists('taxonomy')) {
     return false;
-	}
+  }
   //code lovingly inspired by the image.module w/ code by drewish
   $vid = variable_get(USERPOINTS_CATEGORY_DEFAULT_VID, '');
   if (empty($vid) || !taxonomy_vocabulary_load($vid)) {
@@ -1817,7 +1817,7 @@ function userpoints_get_vid() {
     $vid = db_result(db_query($sql));
     if (!$vid) {
       drupal_set_message(t("Created Userpoints vocabulary"));
-      //No vocabulary exists, we'll create one 
+      //No vocabulary exists, we'll create one
       $vocab = array(
         'name' => t(USERPOINTS_CATEGORY_NAME),
         'description' => t('Automatically created by the userpoints module'),
@@ -1850,7 +1850,7 @@ function userpoints_get_categories() {
     if ($vid) {
       $tree = taxonomy_get_tree($vid, 0, -1, 1);
       foreach ($tree as $term) {
-        $options[$term->tid] = $term->name;  
+        $options[$term->tid] = $term->name;
       }
     }
   }
