Index: userpoints_rules.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/userpoints/userpoints_rules.module,v
retrieving revision 1.1.2.6
diff -u -p -r1.1.2.6 userpoints_rules.module
--- userpoints_rules.module	13 Sep 2009 02:47:01 -0000	1.1.2.6
+++ userpoints_rules.module	9 Feb 2010 15:04:13 -0000
@@ -13,7 +13,7 @@ function userpoints_rules_userpoints($op
   switch ($op) {
   case 'points after':
     $account = user_load($params['uid']);
-    rules_invoke_event('userpoints_event_points_awarded', $account, $params['points']);
+    rules_invoke_event('userpoints_event_points_awarded', $account, $params);
     break;
   }
 }
\ No newline at end of file
Index: userpoints_rules.rules.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/userpoints/userpoints_rules.rules.inc,v
retrieving revision 1.1.2.2
diff -u -p -r1.1.2.2 userpoints_rules.rules.inc
--- userpoints_rules.rules.inc	21 Nov 2009 00:37:19 -0000	1.1.2.2
+++ userpoints_rules.rules.inc	9 Feb 2010 15:04:13 -0000
@@ -7,6 +7,20 @@
  */
 
 /**
+ * Implementation of hook_rules_data_type_info().
+ */
+function userpoints_rules_data_type_info() {
+  return array(
+    'userpoints_transaction' => array(
+      'label' => t('Userpoints transaction'),
+      'class' => 'rules_data_type',
+      'identifiable' => FALSE,
+      'hidden' => TRUE,
+    ),
+  );
+}
+
+/**
  * Implementation of hook_rules_action_info().
  */
 function userpoints_rules_action_info() {
@@ -30,8 +44,8 @@ function userpoints_rules_event_info() {
     'userpoints_event_points_awarded' => array(
        'label' => t('User was awarded !points', userpoints_translation()),
        'arguments' => array(
-          'user' => array('type' => 'user', 'label' => t('updated user')),
-          'points' => array('type' => 'number', 'label' => t('Points awarded'))
+          'user' => array('type' => 'user', 'label' => t('User')),
+          'userpoints_transaction' => array('type' => 'userpoints_transaction', 'label' => t('Userpoints transaction'))
         ),
        'module' => 'Userpoints',
     ),
@@ -78,10 +92,34 @@ $form['settings']['operation'] = array(
  */
 function userpoints_rules_rules_condition_info() {
   return array(
+    'userpoints_rules_category' => array(
+      'label' => t('Check the transaction category'),
+      'arguments' => array(
+        'userpoints_transaction' => array('type' => 'userpoints_transaction', 'label' => t('Userpoints transaction'))
+      ),
+      'module' => 'Userpoints',
+    ),
+    'userpoints_rules_amount_before' => array(
+      'label' => t('Compare Userpoints before the transaction'),
+      'arguments' => array(
+        'user' => array('type' => 'user', 'label' => t('User')),
+        'userpoints_transaction' => array('type' => 'userpoints_transaction', 'label' => t('Userpoints transaction'))
+      ),
+      'module' => 'Userpoints',
+      'eval input' => array('amount'),
+    ),
+    'userpoints_rules_transaction_amount' => array(
+      'label' => t('Compare the transaction amount'),
+      'arguments' => array(
+        'userpoints_transaction' => array('type' => 'userpoints_transaction', 'label' => t('Userpoints transaction'))
+      ),
+      'module' => 'Userpoints',
+      'eval input' => array('amount'),
+    ),
     'userpoints_rules_amount' => array(
-      'label' => t('Userpoints amount is >= than x'),
+      'label' => t('Compare current Userpoints'),
       'arguments' => array(
-        'user' => array('type' => 'user', 'label' => t('User'))
+        'user' => array('type' => 'user', 'label' => t('User')),
       ),
       'module' => 'Userpoints',
       'eval input' => array('amount'),
@@ -92,28 +130,72 @@ function userpoints_rules_rules_conditio
 /**
  * Rules Condition form configuration - set the amount to compare
  */
-function userpoints_rules_amount_form($settings = array(), &$form) {
+function userpoints_rules_amount_form($settings = array(), &$form, $use_category = TRUE) {
+  if ($use_category) {
+    $form['settings']['type'] = array(
+      '#type' => 'select',
+      '#title' => t('Userpoints category'),
+      '#options' => userpoints_get_categories(),
+      '#default_value' => isset($settings['type']) ? $settings['type'] : '',
+      '#required' => TRUE,
+    );
+  }
+
   $form['settings']['amount'] = array(
     '#type' => 'textfield',
-    '#title' => t('amount to compare'),
+    '#title' => t('Amount to compare'),
     '#default_value' => isset($settings['amount']) ? $settings['amount'] : '',
     '#description' => t('The amount to compare if userpoints are >=. Example:30, will trigger the condition if the user userpoints are >= than 30 points.')
   );
-  
-  $form['settings']['type'] = array(
-    '#type' => 'select',
-    '#title' => t('Userpoints Categories to analyze'),
-    '#options' => userpoints_get_categories(),
-    '#default_value' => isset($settings['type']) ? $settings['type'] : '',
-    '#description' => t('Userpoints Categories to analyze'),
-    '#required' => TRUE,
-  );
 }
 
 /**
- * Rules Condition - Userpoints amount is >= than
+ * Condition: check current Userpoints
  */
 function userpoints_rules_amount($account, $settings) {
   $balance = userpoints_get_current_points($account->uid, $settings['type']);
-return ($balance >= $settings['amount']);
+  return $balance >= $settings['amount'];
+}
+
+/**
+ * Condition: check transaction amount
+ */
+function userpoints_rules_transaction_amount($transaction, $settings) {
+  return $transaction['points'] >= $settings['amount'];
+}
+
+function userpoints_rules_transaction_amount_form($settings = array(), &$form) {
+  return userpoints_rules_amount_form($settings, $form, FALSE);
+}
+
+/**
+ * Condition: check Userpoints before the transaction
+ */
+function userpoints_rules_amount_before($account, $transaction, $settings) {
+  $balance = userpoints_get_current_points($account->uid, $settings['type']) - $transaction['points'];
+  return $balance >= $settings['amount'];
+}
+
+function userpoints_rules_amount_before_form($settings = array(), &$form) {
+  return userpoints_rules_amount_form($settings, $form);
+}
+
+/**
+ * Condition: check the transaction category
+ */
+function userpoints_rules_category($transaction, $settings) {
+  return $transaction['tid'] == $settings['category'];
+}
+
+/**
+ * Condition: check the transaction category configuration form
+ */
+function userpoints_rules_category_form($settings = array(), &$form) {
+  $form['settings']['category'] = array(
+    '#type' => 'select',
+    '#title' => t('Userpoints category'),
+    '#options' => userpoints_get_categories(),
+    '#default_value' => isset($settings['category']) ? $settings['category'] : '',
+    '#required' => TRUE,
+  );
 }
