Index: userpoints.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/userpoints/userpoints.module,v
retrieving revision 1.67.2.39
diff -u -r1.67.2.39 userpoints.module
--- userpoints.module	17 Feb 2009 15:21:23 -0000	1.67.2.39
+++ userpoints.module	10 Mar 2009 14:33:05 -0000
@@ -34,6 +34,8 @@
 define('USERPOINTS_REPORT_LIMIT', 'userpoints_report_limit');
 define('USERPOINTS_REPORT_DISPLAYZERO', 'userpoints_report_displayzero');
 
+define('USERPOINTS_TRANSACTION_TIMESTAMP', 'userpoints_transaction_timestamp');
+
 define('USERPOINTS_CATEGORY_NAME', 'Userpoints');
 define('USERPOINTS_CATEGORY_DEFAULT_VID', 'userpoints_category_default_vid');
 define('USERPOINTS_CATEGORY_DEFAULT_TID', 'userpoints_category_default_tid');
@@ -421,7 +423,21 @@
 	    '#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()),
 	  );
   }
-
+  $group = "stamping";
+  $form[$group] = array(
+    '#type' => 'fieldset',
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
+    '#title' => t('Transaction stamping'),
+    '#description' => t(''),
+  );
+  $form[$group][USERPOINTS_TRANSACTION_TIMESTAMP] = array(
+    '#type'          => 'checkbox',
+    '#title'         => t('Always use system time'),
+    '#default_value' => variable_get(USERPOINTS_TRANSACTION_TIMESTAMP, 1),
+    '#description'   => t('Sets if the transaction timestamp should obey current time, or can be modified by the API operations. Unchecking this option will allow customization of timetamp for the transactions.'),
+  );
+  
   $form['setting'] = module_invoke_all('userpoints', 'setting');
   return system_settings_form($form);
 }  
@@ -470,7 +486,8 @@
  *    Accepts an array of keyed variables and parameters  
  *    'points' => # of points (int) (required)
  *    'moderate' => TRUE/FALSE 
- *    'uid' => $user->uid 
+ *    'uid' => $user->uid
+ *    'time_stamp' => unix time of the points assignement date
  *    'operation' => 'published' 'moderated' etc.
  *    'tid' => 'category ID' 
  *    'expirydate' => timestamp or 0, 0 = non-expiring; NULL = site default
@@ -706,13 +723,17 @@
     _userpoints_update_cache($params);
   }
   else {
+    //Force time_stamp to be current time()
+    if (variable_get(USERPOINTS_TRANSACTION_TIMESTAMP, 1)) {
+      $params['time_stamp'] = time();
+    }
     $ret = db_query("INSERT INTO {userpoints_txn}
       (uid, points, time_stamp, status, operation, description, 
       reference, expirydate, expired, parent_txn_id, tid, entity_id, entity_type)
       VALUES (%d, %d, %d, %d, '%s', '%s', '%s', %d, %d, %d, %d, %d, '%s')",
       $params['uid'],
       $params['points'],
-      time(),
+      (isset($params['time_stamp'])) ? $params['time_stamp'] : time(),
       $params['status'],
       $params['operation'],
       $params['description'],
@@ -1061,14 +1082,22 @@
     '#description'   => t('Number of !points to add/subtract from the user. For example, 25 (to add !points) or -25 (to subtract !points).', userpoints_translation()),
     );
 
+  //Block timestamp form field if the API should obey time() behaviour
+  //This let administrator view current transaction timestamp without the
+  //option of modifying the value.
   $form['time_stamp'] = array(
     '#type'          => 'textfield',
     '#title'         => t('Date/Time'),
     '#default_value' => $timestamp,
     '#size'          => 30,
     '#maxlength'     => 30,
-    '#description'   => t('Date and time of this transaction, in the form YYYY-MM-DD HH:MM +ZZZZ'),
-    );  
+    '#description'   => t('Date and time of this transaction, in the form YYYY-MM-DD HH:MM +ZZZZ.'),
+    '#disabled'      => variable_get(USERPOINTS_TRANSACTION_TIMESTAMP, 1),
+    );
+    //As a disabled field, we should set the value to be populated to _submit hook
+    if (variable_get(USERPOINTS_TRANSACTION_TIMESTAMP, 1)) {
+      $form['time_stamp']['#value'] = $timestamp;
+    }
 
   if ($txn->txn_id) {
     if ($txn->expirydate > 0) {
@@ -1211,6 +1240,7 @@
                   'operation' => 'admin',
                   'description' => $form_state['values']['description'],
                   'reference' => $form_state['values']['reference'],
+                  'time_stamp' => strtotime($form_state['values']['time_stamp']),
                   'tid' => $form_state['values']['tid'],
                 );
       if ($form_state['values']['expirydate']) {

