diff -up uc_userpoints_award.info uc_userpoints_award.info
--- uc_userpoints_award.info	2011-04-21 19:49:17.026538500 -0300
+++ uc_userpoints_award.info	2011-04-22 03:56:45.350550800 -0300
@@ -9,9 +9,3 @@ dependencies[] = ca
 core = 7.x
 php = 5.x 
 
-; Information added by drupal.org packaging script on 2011-03-27
-version = "6.x-2.0-beta2"
-core = 7.x
-project = "userpoints_ubercart"
-datestamp = "1301267469"
-
diff -up uc_userpoints_award.install uc_userpoints_award.install
--- uc_userpoints_award.install	2011-04-21 19:49:17.206548800 -0300
+++ uc_userpoints_award.install	2011-04-22 04:20:38.451519500 -0300
@@ -1,62 +1,43 @@
 <?php
-/**
- * @file
- * Install, update and uninstall functions for the uc_userpoints_award module.
- *
- */
-
 //$Id;
 
 
 /**
- * Implements hook_schema().
+ * Implementation of hook_schema
  */
 function uc_userpoints_award_schema() {
   $schema['uc_up_award_log'] = array(
     'fields' => array(
-      'uplog_id' => array(
-        'type' => 'serial',
-        'not null' => TRUE,
-      ),
-      'uid' => array(
-        'type' => 'int',
-        'not null' => TRUE,
-        'default' => '0',
-      ),
-      'oid' => array(
-        'type' => 'int',
-        'not null' => TRUE,
-        'default' => '0',
-      ),
+	    'uplog_id' => array(
+	      'type' => 'serial', 
+	      'not null' => TRUE,
+	    ),
+	    'uid' => array(
+	      'type' => 'int', 
+	      'not null' => TRUE, 
+	      'default' => '0',
+	    ),
+	    'oid' => array(
+	      'type' => 'int', 
+	      'not null' => TRUE, 
+	      'default' => '0',
+	    ),
       'points' => array(
-        'type' => 'int',
-        'size' => 'tiny',
+        'type' => 'int', 
+        'size' => 'tiny', 
         'default' => '0',
       ),
-    ),
-    'primary key' => array('uplog_id'),
+	  ),
+	'primary key' => array('uplog_id'),
   );
 
   return $schema;
 }
 
-
-/**
- * Install the initial schema.
- */
-function uc_userpoints_award_install() {
-  // TODO The drupal_(un)install_schema functions are called automatically in D7.
-  // drupal_install_schema('uc_userpoints_award')
-}
-
-
 /**
- * Implements hook_uninstall().
- */
+* Implementation of hook_uninstall().
+*/
 function uc_userpoints_award_uninstall() {
-  // TODO The drupal_(un)install_schema functions are called automatically in D7.
-  // drupal_uninstall_schema('uc_userpoints_award')
-
   variable_del('userpoints_ubercart_earn');
   variable_del('userpoints_min_purchase');
   variable_del('userpoints_award_to');
diff -up uc_userpoints_award.module uc_userpoints_award.module
--- uc_userpoints_award.module	2011-04-21 19:49:17.939590700 -0300
+++ uc_userpoints_award.module	2011-04-23 03:06:17.997655100 -0300
@@ -1,17 +1,13 @@
 <?php
 //$Id;
 
-define('USERPOINTS_UC_EARN',       'userpoints_ubercart_earn');
+define('USERPOINTS_UC_EARN',      'userpoints_ubercart_earn');
 define('USERPOINTS_MIN_PURCHASE', 'userpoints_min_purchase');
-define('USERPOINTS_AWARD_TO',      'userpoints_award_to');
-define('USERPOINTS_REF_MULT',      'userpoints_ref_mult');
-define('USERPOINTS_AWARD_MODERATE',      'userpoints_award_moderate');
-define('USERPOINTS_REF_MODERATE',      'userpoints_ref_moderate');
+define('USERPOINTS_AWARD_TO',     'userpoints_award_to');
+define('USERPOINTS_REF_MULT',     'userpoints_ref_mult');
+define('USERPOINTS_AWARD_MODERATE',     'userpoints_award_moderate');
+define('USERPOINTS_REF_MODERATE',     'userpoints_ref_moderate');
 
-/**
- * @todo Please document this function.
- * @see http://drupal.org/node/1354
- */
 function uc_userpoints_award_help($path, $arg) {
   switch ($path) {
     case 'admin/modules#description':
@@ -19,12 +15,8 @@ function uc_userpoints_award_help($path,
   }
 }
 
-/**
- * @todo Please document this function.
- * @see http://drupal.org/node/1354
- */
 function uc_userpoints_award_userpoints($op, $points = 0, $uid = 0, $event = '') {
-  switch ($op) {
+  switch($op) {
     case 'setting':
       if (module_exists('uc_cart') && module_exists('uc_payment')) {
         $group = 'uc_userpoints_award';
@@ -52,7 +44,7 @@ function uc_userpoints_award_userpoints(
           '#type' => 'radios',
           '#title' => t('Moderate userpoints transaction'),
           '#default_value' => variable_get(USERPOINTS_AWARD_MODERATE, 0),
-          '#options' => array(t('No'), t('Yes')),
+					'#options' => array(t('No'), t('Yes')),
         );
         $form[$group][USERPOINTS_AWARD_CATEGORY] = array(
           '#type' => 'select',
@@ -62,27 +54,27 @@ function uc_userpoints_award_userpoints(
           '#options' => userpoints_get_categories(),
         );
 
-        if (module_exists('referral')) {
+        if(module_exists('referral')) {
           $form[$group][USERPOINTS_AWARD_TO] = array(
             '#type' => 'radios',
             '#title' => t('User to whom !points are awarded on purchase', userpoints_translation()),
-            '#default_value' => variable_get(USERPOINTS_AWARD_TO, 0),
+            '#default_value' =>  variable_get(USERPOINTS_AWARD_TO,0),
             '#options' => array(t('Referrer only'), t('Purchaser only'), t('Referrer and Purchaser')),
           );
           $form[$group][USERPOINTS_REF_MULT] = array(
             '#type' => 'textfield',
             '#title' => t('!points multiplier for referrer', userpoints_translation()),
-            '#default_value' => variable_get(USERPOINTS_REF_MULT, 1),
+            '#default_value' =>  variable_get(USERPOINTS_REF_MULT,1),
             '#size' => 5,
             '#maxlength' => 5,
             '#description' => t('Enter the number of !points awarded per dollar.  <b>This field is only valid when "Referrer and Purchaser" is selected above.  Otherwise the standard multiplier is used.</b>', userpoints_translation()),
           );
-          $form[$group][USERPOINTS_REF_MODERATE] = array(
-            '#type' => 'radios',
-            '#title' => t('Moderate userpoints transaction'),
-            '#default_value' => variable_get(USERPOINTS_REF_MODERATE, 0),
-            '#options' => array(t('No'), t('Yes')),
-          );
+		      $form[$group][USERPOINTS_REF_MODERATE] = array(
+			      '#type' => 'radios',
+			      '#title' => t('Moderate userpoints transaction'),
+			      '#default_value' => variable_get(USERPOINTS_REF_MODERATE, 0),
+			      '#options' => array(t('No'), t('Yes')),
+		      );
         }
       }
       return $form;
@@ -92,83 +84,97 @@ function uc_userpoints_award_userpoints(
 
 
 /**
- * Implements hook_ca_action().
+ * Implementation of hook_ca_action
  */
 function uc_userpoints_award_ca_action() {
-  $order_arg = array(
-    '#entity' => 'uc_order',
-    '#title' => t('Order'),
-  );
-
-  $actions['uc_userpoints_buyer_award_points'] = array(
-    '#title' => t('Award buyer points'),
-    '#category' => t('Order'),
-    '#callback' => 'uc_userpoints_buyer_award_points',
-    '#arguments' => array(
-      'order' => $order_arg,
-    ),
-  );
+	$order_arg = array(
+	  '#entity' => 'uc_order',
+	  '#title' => t('Order'),
+	);
+
+	$actions['uc_userpoints_buyer_award_points'] = array(
+	  '#title' => t('Award buyer points'),
+	  '#category' => t('Order'),
+	  '#callback' => 'uc_userpoints_buyer_award_points',
+	  '#arguments' => array(
+	    'order' => $order_arg,
+	  ),
+	);
 
-  return $actions;
+	return $actions;
 }
 
 /**
- * Implements hook_ca_predicate().
+ * Implementation of hook_ca_predicate
  **/
 function uc_userpoints_award_ca_predicate() {
-  $predicates['uc_userpoints_default_award'] = array(
-    '#title' => t('Award points if order complete'),
-    '#description' => '',
-    '#class' => '',
-    '#status' => '1',
-    '#weight' => '0',
-    '#uid' => '0',
-    '#trigger' => 'uc_order_status_update',
-    '#conditions' => array(
-      '#operator' => 'AND',
-      '#conditions' => array(
-        0 => array(
-          '#operator' => 'AND',
-          '#conditions' => array(
-            0 => array(
-              '#name' => 'uc_order_status_condition',
-              '#title' => 'Check the order status',
-              '#argument_map' => array(
-                'order' => 'updated_order',
-              ),
-              '#settings' => array(
-                'negate' => 0,
-                'order_status' => 'completed',
-              ),
+	$predicates['uc_userpoints_default_award'] = array (
+  '#title' => t('Award points if order complete'),
+  '#description' => '',
+  '#class' => '',
+  '#status' => '1',
+  '#weight' => '0',
+  '#uid' => '0',
+  '#trigger' => 'uc_order_status_update',
+  '#conditions' => 
+  array (
+    '#operator' => 'AND',
+    '#conditions' => 
+    array (
+      0 => 
+      array (
+        '#operator' => 'AND',
+        '#conditions' => 
+        array (
+          0 => 
+          array (
+            '#name' => 'uc_order_status_condition',
+            '#title' => 'Check the order status',
+            '#argument_map' => 
+            array (
+              'order' => 'updated_order',
+            ),
+            '#settings' => 
+            array (
+              'negate' => 0,
+              'order_status' => 'completed',
+            ),
+          ),
+          1 => 
+          array (
+            '#name' => 'uc_order_status_condition',
+            '#title' => 'Check the order status',
+            '#argument_map' => 
+            array (
+              'order' => 'order',
             ),
-            1 => array(
-              '#name' => 'uc_order_status_condition',
-              '#title' => 'Check the order status',
-              '#argument_map' => array(
-                'order' => 'order',
-              ),
-              '#settings' => array(
-                'negate' => 1,
-                'order_status' => 'completed',
-              ),
+            '#settings' => 
+            array (
+              'negate' => 1,
+              'order_status' => 'completed',
             ),
           ),
         ),
       ),
     ),
-    '#actions' => array(
-      0 => array(
-        '#name' => 'uc_userpoints_buyer_award_points',
-        '#title' => t('Award buyer points'),
-        '#argument_map' => array(
-          'order' => 'updated_order',
-        ),
-        '#settings' => array(
-        ),
+  ),
+  '#actions' => 
+  array (
+    0 => 
+    array (
+      '#name' => 'uc_userpoints_buyer_award_points',
+      '#title' => t('Award buyer points'),
+      '#argument_map' => 
+      array (
+        'order' => 'updated_order',
+      ),
+      '#settings' => 
+      array (
       ),
     ),
-  );
-  return $predicates;
+  ),
+);
+return $predicates;
 }
 
 
@@ -183,7 +189,7 @@ function uc_userpoints_buyer_award_point
   $curUserId	= $order->uid; //$user->uid; // $user->uid means nothing when the IPN call comes in...
   $multiplier 	= variable_get(USERPOINTS_UC_EARN, 0);
   $min 			= variable_get(USERPOINTS_MIN_PURCHASE, '0.00');
-  $result 		= db_query("select sum(qty * price) from {uc_order_products} p, {uc_orders} o where p.order_id = o.order_id and o.order_id = %d and o.uid = %d", $order->order_id, $curUserId);
+  $result 		= db_query("SELECT SUM(qty * price) FROM {uc_order_products} p, {uc_orders} o WHERE p.order_id = o.order_id and o.order_id = :oid and o.uid = :uid", array(':oid' => $order->order_id, 'uid' => $curUserId));
   $total		= $result->fetchField();
 
   $refUserId = 0; // default to 0 so if referral module is not installed or no referrer, we skip all referral code
@@ -195,62 +201,77 @@ function uc_userpoints_buyer_award_point
   $award_to     = intval(variable_get(USERPOINTS_AWARD_TO, 1));
 
   if (module_exists('referral')) {
-    if ($award_to == 0 || $award_to == 2) {
+    if($award_to == 0 || $award_to == 2){
       // Look up our referrer if we have one
-      $result = db_query("select referral_uid FROM {referral} WHERE uid = %d", $curUserId);
-      if (!empty($result)) {
-        $ref = db_fetch_object($result);
+      $result = db_query("select referral_uid FROM {referral} WHERE uid = :uid", array(':uid' => $curUserId));
+      foreach ($result as $ref)
         $refUserId = $ref->referral_uid;
-        if ($award_to == 2) {
-          $ref_mult =  variable_get(USERPOINTS_REF_MULT, 1);
+        if($award_to == 2){
+          $ref_mult =  variable_get(USERPOINTS_REF_MULT,1);
         }
       }
     }
   }
+	
 
-
-  // Payment completed
-  // Award points to buyer, if appropriate
-  if ($curUserId != 0 && ($award_to == 1 || $award_to == 2) && strtolower($order->payment_method) != 'points') {
-    // User id from the transaction
-
-    if ($total < $min) {
-      $points = 0;
-    }
-    else {
-      $points = intval(($total * $multiplier));
-      $params = array(
-        'tid' => variable_get(USERPOINTS_AWARD_CATEGORY, 0),
-        'uid' => $curUserId,
-        'points' => $points,
-        'operation' => 'insert',
-        'description' => 'User made a purchase, awarding points (Ubercart Order ID ' . $order->order_id . ')',
-        //				'entity_id' => $order->order_id, //				'entity_type' => 'Ubercart Transaction',
-        'moderate' => variable_get(USERPOINTS_AWARD_MODERATE, 0),
-      );
-      $st = userpoints_userpointsapi($params);
-      db_query("insert into {uc_up_award_log} (uid, oid, points) values(%d, %d, %d)", $curUserId, $order->order_id, $points);
-    }
-  }
-
-  // Award referral points, if appropriate
-  if ($refUserId != 0 && ($award_to == 0 || $award_to == 2)) {
-    if ($total < $min) {
-      $points = 0;
-    }
-    else {
-      $points = intval(($total * $multiplier * $ref_mult));
-      $params = array(
-        'tid' => variable_get(USERPOINTS_AWARD_CATEGORY, 0),
-        'uid' => $refUserId,
-        'points' => $points,
-        'operation' => 'insert',
-        'description' => 'Purchase made by someone you referred, awarding points to referrer (Ubercart Order ID ' . $order->order_id . ')',
-        //				'entity_id' => $order->order_id, //				'entity_type' => 'Ubercart Transaction',
-        'moderate' => variable_get(USERPOINTS_REF_MODERATE, 0),
-      );
-      $st = userpoints_userpointsapi($params);
-      db_query("insert into {uc_up_award_log} (uid, oid, points) values(%d, %d, %d)", $refUserId, $order->order_id, $points);
-    }
-  }
-}
+	// Payment completed
+	// Award points to buyer, if appropriate
+	if ($curUserId != 0 && ($award_to==1 || $award_to==2) && strtolower($order->payment_method) != 'points') {
+		// User id from the transaction
+	
+		if ($total < $min) {
+			$points = 0;
+		}
+		else {
+			$points = intval(($total * $multiplier));
+			$params = array (
+				'tid' => variable_get(USERPOINTS_AWARD_CATEGORY, 0),
+				'uid' => $curUserId,
+				'points' => $points,
+				'operation' => 'insert',
+				'description' => 'User made a purchase, awarding points (Ubercart Order ID ' . $order->order_id . ')',
+//				'entity_id' => $order->order_id,
+//				'entity_type' => 'Ubercart Transaction',
+				'moderate' => variable_get(USERPOINTS_AWARD_MODERATE, 0),
+			);
+			$st = userpoints_userpointsapi($params);
+			db_insert('uc_up_award_log')
+      ->fields(array(
+      'uid' => $curUserId,
+      'oid' => $order->order_id,
+      'points' => $points,
+      ))
+      ->execute(); 
+		}
+	}
+	
+	// Award referral points, if appropriate
+	if ($refUserId != 0 && ($award_to==0 || $award_to==2)) {
+		if ($total < $min) {
+			$points = 0;
+		}
+		else {
+			$points = intval(($total * $multiplier * $ref_mult));
+			$params = array (
+				'tid' => variable_get(USERPOINTS_AWARD_CATEGORY, 0),
+				'uid' => $refUserId,
+				'points' => $points,
+				'operation' => 'insert',
+				'description' => 'Purchase made by someone you referred, awarding points to referrer (Ubercart Order ID ' . $order->order_id . ')',
+//				'entity_id' => $order->order_id,
+//				'entity_type' => 'Ubercart Transaction',
+				'moderate' => variable_get(USERPOINTS_REF_MODERATE, 0),
+			);
+			$st = userpoints_userpointsapi($params);
+			// D6
+      // db_query("insert into {uc_up_award_log} (uid, oid, points) values(%d, %d, %d)", $refUserId, $order->order_id, $points);
+      // D7
+      db_insert('uc_up_award_log')
+      ->fields(array(
+      'uid' => $refUserId,
+      'oid' => $order->order_id,
+      'points' => $points,
+      ))
+      ->execute(); 
+	}
+}	
diff -up uc_userpoints_discount.info uc_userpoints_discount.info
--- uc_userpoints_discount.info	2011-04-21 19:49:17.944591000 -0300
+++ uc_userpoints_discount.info	2011-04-22 03:56:57.112223600 -0300
@@ -8,9 +8,4 @@ dependencies[] = uc_payment
 core = 7.x
 php = 5.x
 
-; Information added by drupal.org packaging script on 2011-03-27
-version = "6.x-2.0-beta2"
-core = 7.x
-project = "userpoints_ubercart"
-datestamp = "1301267469"
 
diff -up uc_userpoints_discount.install uc_userpoints_discount.install
--- uc_userpoints_discount.install	2011-04-21 19:49:18.109600500 -0300
+++ uc_userpoints_discount.install	2011-04-22 04:20:48.954120200 -0300
@@ -1,10 +1,4 @@
 <?php
-/**
- * @file
- * Install, update and uninstall functions for the uc_userpoints_award module.
- *
- */
-
 //$Id;
 
 
@@ -15,55 +9,44 @@ function uc_userpoints_discount_schema()
   $schema['uc_updiscounts'] = array(
     'fields' => array(
       'updlog_id' => array(
-        'type' => 'serial',
-        'not null' => TRUE,
-      ),
-      'uid' => array(
-        'type' => 'int',
-        'not null' => TRUE,
-        'default' => '0',
+        'type' => 'serial', 
+        'not null' => TRUE
       ),
-      'oid' => array(
-        'type' => 'int',
-        'not null' => TRUE,
-        'default' => '0',
-      ),
-      'ptamt' => array(
-        'type' => 'numeric',
-        'precision' => 10,
-        'scale' => 2,
-        'not null' => TRUE,
-        'default' => '0',
-      ),
-      'points' => array(
-        'type' => 'int',
-        'not null' => TRUE,
-        'default' => '0',
-      ),
-    ),
-    'primary key' => array(
-      'updlog_id',
-    ),
+	    'uid' => array(
+	      'type' => 'int', 
+	      'not null' => TRUE, 
+	      'default' => '0'
+	    ),
+	    'oid' => array(
+	      'type' => 'int', 
+	      'not null' => TRUE, 
+	      'default' => '0'
+	    ),
+	    'ptamt' => array(
+	      'type' => 'numeric', 
+	      'precision' => 10, 
+	      'scale' => 2, 
+	      'not null' => TRUE, 
+	      'default' => '0'
+	    ),
+	    'points' => array(
+	      'type' => 'int', 
+	      'not null' => TRUE, 
+	      'default' => '0'
+	    ),
+	  ),
+	'primary key' => array(
+	  'updlog_id'
+	  )
   );
 
   return $schema;
 }
 
-
 /**
- * Install the initial schema.
- */
-function uc_userpoints_discount_install() {
-  drupal_install_schema('uc_userpoints_discount');
-}
-
-
-/**
- * Implementation of hook_uninstall().
- */
+* Implementation of hook_uninstall().
+*/
 function uc_userpoints_discount_uninstall() {
-  drupal_uninstall_schema('uc_userpoints_discount');
-
   variable_del('userpoints_ubercart_payment');
   variable_del('uc_userpoints_discount_maxp');
   variable_del('userpoints_discount');
diff -up uc_userpoints_discount.module uc_userpoints_discount.module
--- uc_userpoints_discount.module	2011-04-21 19:49:19.704691700 -0300
+++ uc_userpoints_discount.module	2011-04-23 02:05:41.465657400 -0300
@@ -1,12 +1,12 @@
 <?php
 
 
-define('USERPOINTS_UC_DISC',    'userpoints_ubercart_payment');
-define('USERPOINTS_DISCOUNT',      'userpoints_discount');
-define('UC_USERPOINTS_DISCOUNT_MODERATE',       'uc_userpoints_discount_moderate');
-define('UC_USERPOINTS_DISCOUNT_MAXP',       'uc_userpoints_discount_maxp');
-define('USERPOINTS_DISCOUNT_CATEGORY', 	'userpoints_discount_category');
-define('UC_USERPOINTS_DISCOUNT_CLASSES', 	'uc_userpoints_discount_classes');
+define('USERPOINTS_UC_DISC',   'userpoints_ubercart_payment');
+define('USERPOINTS_DISCOUNT',     'userpoints_discount');
+define('UC_USERPOINTS_DISCOUNT_MODERATE',      'uc_userpoints_discount_moderate');
+define('UC_USERPOINTS_DISCOUNT_MAXP',      'uc_userpoints_discount_maxp');
+define('USERPOINTS_DISCOUNT_CATEGORY',	'userpoints_discount_category');
+define('UC_USERPOINTS_DISCOUNT_CLASSES',	'uc_userpoints_discount_classes');
 
 
 
@@ -24,7 +24,7 @@ function uc_userpoints_discount_help($pa
 
 function uc_userpoints_discount_userpoints($op, $points = 0, $uid = 0, $event = '') {
   $userpoints_translation = userpoints_translation();
-  switch ($op) {
+  switch($op) {
     case 'setting':
       if (module_exists('uc_cart') && module_exists('uc_payment')) {
         $group = 'uc_userpoints_discount';
@@ -33,7 +33,7 @@ function uc_userpoints_discount_userpoin
           '#collapsible' => TRUE,
           '#collapsed' => TRUE,
           '#title' => t('Ubercart Discount Options'),
-        );
+        );    
         $form[$group][USERPOINTS_UC_DISC] = array(
           '#type' => 'textfield',
           '#title' => t('!Points used in discount (for every @currency)', array('!Points' => $userpoints_translation['!Points'], '@currency' => variable_get('uc_currency_code', 'USD'))),
@@ -51,28 +51,28 @@ function uc_userpoints_discount_userpoin
         $form[$group][USERPOINTS_DISCOUNT] = array(
           '#type' => 'radios',
           '#title' => t('Enable !points as a discount method', userpoints_translation()),
-          '#default_value' => variable_get(USERPOINTS_DISCOUNT, 1),
+          '#default_value' =>  variable_get(USERPOINTS_DISCOUNT,1),
           '#options' => array(t('No'), t('Yes')),
         );
-        $form[$group][USERPOINTS_DISCOUNT_CATEGORY] = array(
-          '#type' => 'select',
-          '#title' => t('Discount Category'),
-          '#description' => t('Category to assign awarded !points.', userpoints_translation()),
-          '#default_value' => variable_get(USERPOINTS_DISCOUNT_CATEGORY, NULL),
-          '#options' => userpoints_get_categories(),
-        );
+		    $form[$group][USERPOINTS_DISCOUNT_CATEGORY] = array(
+    		  '#type' => 'select',
+    		  '#title' => t('Discount Category'),
+    		  '#description' => t('Category to assign awarded !points.', userpoints_translation()),
+    		  '#default_value' => variable_get(USERPOINTS_DISCOUNT_CATEGORY, NULL),
+    		  '#options' => userpoints_get_categories(),
+    		);
         $form[$group][UC_USERPOINTS_DISCOUNT_MODERATE] = array(
           '#type' => 'radios',
           '#title' => t('Moderate userpoints transaction'),
           '#default_value' => variable_get(UC_USERPOINTS_DISCOUNT_MODERATE, 0),
-          '#options' => array(t('No'), t('Yes')),
+		      '#options' => array(t('No'), t('Yes')),
         );
         $form[$group][UC_USERPOINTS_DISCOUNT_CLASSES] = array(
           '#type' => 'checkboxes',
           '#title' => t('Product classes discounts can be applied to'),
           '#description' => t('Leave blank for all.'),
           '#default_value' => variable_get(UC_USERPOINTS_DISCOUNT_CLASSES, array()),
-          '#options' => uc_product_type_names(),
+		      '#options' => uc_product_type_names(),
         );
       }
       return $form;
@@ -83,14 +83,14 @@ function uc_userpoints_discount_userpoin
 
 
 /**
- * Implementation of hook_checkout_pane
+ * Implementation of hook_uc_checkout_pane
  */
-function uc_userpoints_discount_checkout_pane() {
+function uc_userpoints_discount_uc_checkout_pane() {
   global $user;
   $curUserId	 = $user->uid;
   $curUserPoints = intval(userpoints_get_current_points($uid = $curUserId, $tid = NULL));
-  $discMethod	 = variable_get(USERPOINTS_DISCOUNT, 1);
-
+  $discMethod	 = variable_get(USERPOINTS_DISCOUNT,1);
+    
   if ($discMethod != 0 && ($curUserPoints > 0 || request_uri() != '/cart/checkout')) {
     $panes[] = array(
       'id' => 'up_uc_discounts',
@@ -105,46 +105,45 @@ function uc_userpoints_discount_checkout
 
 
 
-function uc_checkout_pane_uc_userpoints_discount($op, &$arg1, $arg2) {
+function uc_checkout_pane_uc_userpoints_discount($op, $order, &$form = NULL, &$form_state = NULL) {
   // get point discounts to apply to this order
   global $user;
   $curUserId = $user->uid;
 
   switch ($op) {
     case 'view':
-      $curUserPoints = intval(userpoints_get_current_points($uid = $curUserId, $tid = NULL));
-      $maxdisc = ($curUserPoints / intval(variable_get(USERPOINTS_UC_DISC, 1)));
-      $maxpt = variable_get(UC_USERPOINTS_DISCOUNT_MAXP, 100);
-      $description = t('Enter the amount to discount this order with !points by. This field will be ignored if paying with !points.', userpoints_translation());
-      // TODO Please change this theme call to use an associative array for the $variables parameter.
-      $description .= theme('uc_userpoints_discount_info_pane', uc_currency_format(uc_userpoints_discount_discountable_total()), uc_currency_format(uc_userpoints_discount_max()), uc_currency_format($maxdisc));
-      $contents['ptamt'] = array(
-        '#type' => 'textfield',
-        '#title' => t('Discount Amount (in @currency)', array('@currency' => variable_get('uc_currency_code', 'USD'))),
-        '#description' => t('Enter the amount that you want to spend from your !points as a discount for this order.', userpoints_translation()),
-        '#default_value' => $arg1->ptamt,
-      );
-      return array('description' => $description, 'contents' => $contents);
-      break;
+			$curUserPoints = intval(userpoints_get_current_points($uid = $curUserId, $tid = NULL));
+			$maxdisc = ($curUserPoints / intval(variable_get(USERPOINTS_UC_DISC, 1)));
+			$maxpt = variable_get(UC_USERPOINTS_DISCOUNT_MAXP, 100);
+			$description = t('Enter the amount to discount this order with !points by. This field will be ignored if paying with !points.', userpoints_translation());
+			$description .= theme('uc_userpoints_discount_info_pane', uc_currency_format(uc_userpoints_discount_discountable_total()), uc_currency_format(uc_userpoints_discount_max()), uc_currency_format($maxdisc));
+			$contents['ptamt'] = array(
+				'#type' => 'textfield',
+				'#title' => t('Discount Amount (in @currency)', array('@currency' => variable_get('uc_currency_code', 'USD'))),
+				'#description' => t('Enter the amount that you want to spend from your !points as a discount for this order.', userpoints_translation()),
+				'#default_value' => $order->ptamt,
+			);
+			return array('description' => $description, 'contents' => $contents);
+			break;	
     case 'process':
-      $ptamt = $arg2['ptamt'];
-      if (!empty($ptamt) || $ptamt != '') {
-        $arg1->ptamt = $ptamt;
-      }
-      else {
-        $arg1->ptamt = 0;
-      }
-      return TRUE;
-      break;
+			$ptamt = $form_state['ptamt'];
+			if (!empty($ptamt) || $ptamt != '') {
+				$order->ptamt = $ptamt;
+			}
+			else {
+				$order->ptamt = 0;
+			}
+			return TRUE;
+			break;
   }
 }
 
 
 
 /**
- * Implementation of hook_line_item()
+ * Implementation of hook_uc_line_item()
  */
-function uc_userpoints_discount_line_item() {
+function uc_userpoints_discount_uc_line_item() {
   $items[] = array(
     'id' => 'ptdiscount',
     'title' => t('Userpoints Discount'),
@@ -159,7 +158,7 @@ function uc_userpoints_discount_line_ite
 
 function uc_userpoints_discount_line_item_calc($op, $arg1) {
   $lines = array();
-
+  
   #discount value
   $ptamt = $arg1->ptamt;
 
@@ -175,171 +174,176 @@ function uc_userpoints_discount_line_ite
       return $lines;
       break;
 
-
+    
   }
 }
 
 
 
 /**
- * Implementation of hook_order().
+ * Implementation of hook_uc_order().
  * This is where all the important stuff happens like taking the points...
  */
-function uc_userpoints_discount_order($op, &$arg1, $arg2) {
+function uc_userpoints_discount_uc_order($op, &$arg1, $arg2) {
   $order 	 = $arg1;
   $paymethod = strtolower($order->payment_method);
   switch ($op) {
     case 'save':
-      // TODO Please review the conversion of this statement to the D7 database API syntax.
-      /* db_query("DELETE FROM {uc_updiscounts} WHERE oid=%d", $arg1->order_id) */
+			// D6
+      // db_query("DELETE FROM {uc_updiscounts} WHERE oid=%d", $arg1->order_id);
+			// db_query("DELETE FROM {uc_order_line_items} WHERE order_id=%d AND type='ptdiscount'", $arg1->order_id);
+			// D7
       db_delete('uc_updiscounts')
-  ->condition('oid', $arg1->order_id)
-  ->execute();
-      // TODO Please review the conversion of this statement to the D7 database API syntax.
-      /* db_query("DELETE FROM {uc_order_line_items} WHERE order_id=%d AND type='ptdiscount'", $arg1->order_id) */
-      db_delete('uc_order_line_items')
-  ->condition('order_id', $arg1->order_id)
-  ->condition('type', 'ptdiscount')
-  ->execute();
-      uc_line_items_calculate($arg1->order_id);
-      global $user;
-      $curUserId = $user->uid;
-      $pagepath = str_replace('destination=', '', urldecode(drupal_get_destination()));
-      $multiplier 	= (variable_get(USERPOINTS_UC_DISC, 0));
-      $maxdisc = variable_get(UC_USERPOINTS_DISCOUNT_MAXP, 100) / 100;
-
-      #discountable money value of order
-      $orderamt = uc_userpoints_discount_discountable_total() + $arg1->quote['rate'];
-
-      $curUserPoints = intval(userpoints_get_current_points($uid = $curUserId, $tid = NULL));
-      $maxdisc = ($curUserPoints / intval(variable_get(USERPOINTS_UC_DISC, 1)));
-
-      #discount value
-      $ptamt = $arg1->ptamt;
-      #discount value in points
-      $points = -(($ptamt) * $multiplier);
-      $ptdisc = (($ptamt) * $multiplier);
-
-      #max discount on order total
-      $ptmaxd = uc_userpoints_discount_max();
-      $ptmaxdPoints = $ptmaxd * $multiplier;
-
-      if (variable_get(USERPOINTS_DISCOUNT, 1) != 0 && $paymethod != 'points') {
-        if ((!empty($ptamt) || $ptamt != '') && $ptamt < $orderamt && $ptdisc <= min($curUserPoints, $ptmaxdPoints)) {
-          // TODO Please review the conversion of this statement to the D7 database API syntax.
-          /* db_query("DELETE FROM {uc_order_line_items} WHERE order_id=%d AND type='ptdiscount'", $arg1->order_id) */
+      ->condition('oid', $arg1->order_id)
+      ->execute();
+			db_delete('uc_order_line_items')
+      ->condition('order_id', $arg1->order_id)
+      ->condition('type', 'ptdiscount')
+      ->execute();
+      
+      uc_line_items_calculate($arg1->order_id);	
+			global $user;
+			$curUserId = $user->uid;
+			$pagepath = str_replace('destination=','',urldecode(drupal_get_destination()));
+			$multiplier 	= (variable_get(USERPOINTS_UC_DISC, 0));
+			$maxdisc = variable_get(UC_USERPOINTS_DISCOUNT_MAXP, 100)/100;
+
+			#discountable money value of order
+			$orderamt = uc_userpoints_discount_discountable_total() + $arg1->quote['rate'];
+
+			$curUserPoints = intval(userpoints_get_current_points($uid = $curUserId, $tid = NULL));
+			$maxdisc = ($curUserPoints / intval(variable_get(USERPOINTS_UC_DISC, 1)));
+
+			#discount value
+			$ptamt = $arg1->ptamt;
+			#discount value in points
+			$points = -(($ptamt) * $multiplier);
+			$ptdisc = (($ptamt) * $multiplier);
+			
+			#max discount on order total
+			$ptmaxd = uc_userpoints_discount_max();
+			$ptmaxdPoints = $ptmaxd * $multiplier;
+			
+			if (variable_get(USERPOINTS_DISCOUNT,1) != 0 && $paymethod != 'points') {
+				if ((!empty($ptamt) || $ptamt != '') && $ptamt < $orderamt && $ptdisc <= min($curUserPoints, $ptmaxdPoints)) {
+					// D6
+          // db_query("DELETE FROM {uc_order_line_items} WHERE order_id=%d AND type='ptdiscount'", $arg1->order_id);
+					// db_query('INSERT INTO {uc_updiscounts} (uid, oid, ptamt, points) VALUES (%d, %d, \'%f\', %d)', $curUserId, $arg1->order_id, $ptamt, $points);
+					// D7
           db_delete('uc_order_line_items')
-  ->condition('order_id', $arg1->order_id)
-  ->condition('type', 'ptdiscount')
-  ->execute();
-          // TODO Please review the conversion of this statement to the D7 database API syntax.
-          /* db_query('INSERT INTO {uc_updiscounts} (uid, oid, ptamt, points) VALUES (%d, %d, \'%f\', %d)', $curUserId, $arg1->order_id, $ptamt, $points) */
-          $id = db_insert('uc_updiscounts')
-  ->fields(array(
-            'uid' => $curUserId,
-            'oid' => $arg1->order_id,
-            'ptamt' => $ptamt,
-            'points' => $points,
+          ->condition('order_id', $arg1->order_id)
+          ->condition('type', 'ptdiscount')
+          ->execute();
+          db_insert('uc_updiscounts')
+          ->fields(array(
+          'uid' => $curUserId, 
+          'oid' => $arg1->order_id, 
+          'ptamt' => $ptamt, 
+          'points' => $points,
           ))
-  ->execute();
-          uc_order_line_item_add($arg1->order_id, 'ptdiscount', t('Discount order using !points', userpoints_translation()), -$ptamt, 1);
-        }
-        elseif ($ptdisc <= $orderamt && (!empty($ptamt) || $ptamt != '')) {
-          #this should be to check it greater than order total
-          drupal_set_message('You cannot discount an order for more than the order total.', 'error');
-          drupal_goto($pagepath);
-        }
-        elseif ($ptdisc > min($curUserPoints, $ptmaxdPoints) && (!empty($ptamt) || $ptamt != '')) {
-          #this should be to check if discount greater than max
-          drupal_set_message(t('The maximum you can discount this order by using points is %maxamount.', array('%maxamount' => uc_currency_format(min($ptmaxd, $maxdisc)))), 'error');
-          drupal_goto($pagepath);
-        }
-      }
-      elseif ($paymethod == 'points' && (!empty($ptamt) || $ptamt != '')) {
-        drupal_set_message(t('You cannot use !points to pay for a product and use !points as a discount method.', userpoints_translation()), 'error');
-        drupal_goto($pagepath);
-      }
-      break;
-    case 'submit':
-      // fires when the order is submitted and adds/subtracts thier points
-      if ($paymethod != 'points') {
-        if (variable_get(USERPOINTS_DISCOUNT, 1) != 0) {
-          global $user;
-          $curUserId = $user->uid;
-          $ptamt = $arg1->ptamt;
-          $multiplier 	= intval(variable_get(USERPOINTS_UC_DISC, 0));
-
-          // Payment completed
-          if ($curUserId != 0) {
-            // User id from the transaction
-            $points = intval(($ptamt) * $multiplier);
-            $points = -$points;
-            $params = array(
-              'tid' => variable_get(USERPOINTS_DISCOUNT_CATEGORY, 0),
-              'uid' => $curUserId,
-              'points' => $points,
-              'operation' => 'delete',
-              'description' => 'User Discount, taking poings (Ubercart Order ID ' . $order->order_id . ')',
-              'entity_id' => $order->order_id,
-              'entity_type' => 'Ubercart Transaction',
-              'moderate' => variable_get(UC_USERPOINTS_DISCOUNT_MODERATE, 0),
-            );
-            userpoints_userpointsapi($params);
-            // TODO Please review the conversion of this statement to the D7 database API syntax.
-            /* db_query('INSERT INTO {uc_updiscounts} (uid, oid, ptamt, points) VALUES (%d, %d, \'%f\', %d)', $curUserId, $arg1->order_id, $ptamt, $points) */
-            $id = db_insert('uc_updiscounts')
-  ->fields(array(
-              'uid' => $curUserId,
-              'oid' => $arg1->order_id,
-              'ptamt' => $ptamt,
-              'points' => $points,
+          ->execute();
+          uc_order_line_item_add($arg1->order_id, 'ptdiscount', t('Discount order using !points',userpoints_translation()), -$ptamt, 1);
+				}
+				elseif ($ptdisc <= $orderamt && (!empty($ptamt) || $ptamt != '')) {
+					#this should be to check it greater than order total
+					drupal_set_message('You cannot discount an order for more than the order total.', 'error');
+					drupal_goto($pagepath);
+				}
+				elseif ($ptdisc > min($curUserPoints, $ptmaxdPoints) && (!empty($ptamt) || $ptamt != '')) {
+					#this should be to check if discount greater than max
+					drupal_set_message(t('The maximum you can discount this order by using points is %maxamount.', array('%maxamount' => uc_currency_format(min($ptmaxd, $maxdisc)))), 'error');
+					drupal_goto($pagepath);
+				}
+			}
+			elseif ($paymethod == 'points' && (!empty($ptamt) || $ptamt != '')) {
+					drupal_set_message(t('You cannot use !points to pay for a product and use !points as a discount method.', check_plain(userpoints_translation())), 'error');
+					drupal_goto($pagepath);
+			}
+			break;
+		case 'submit':
+			// fires when the order is submitted and adds/subtracts thier points
+			if ($paymethod != 'points') {
+				if (variable_get(USERPOINTS_DISCOUNT,1) != 0) {
+					global $user;
+					$curUserId = $user->uid;
+					$ptamt = $arg1->ptamt;
+					$multiplier 	= intval(variable_get(USERPOINTS_UC_DISC, 0));
+				
+					// Payment completed
+					if ($curUserId != 0) {
+					// User id from the transaction
+						$points = intval(($ptamt) * $multiplier);
+						$points = -$points;
+						$params = array (
+						'tid' => variable_get(USERPOINTS_DISCOUNT_CATEGORY, 0),
+						'uid' => $curUserId,
+						'points' => $points,
+						'operation' => 'delete',
+						'description' => 'User Discount, taking poings (Ubercart Order ID ' . $order->order_id . ')',
+						'entity_id' => $order->order_id,
+						'entity_type' => 'Ubercart Transaction',
+						'moderate' => variable_get(UC_USERPOINTS_DISCOUNT_MODERATE, 0),
+						);
+						userpoints_userpointsapi($params);
+					  // D6
+            // db_query('INSERT INTO {uc_updiscounts} (uid, oid, ptamt, points) VALUES (%d, %d, \'%f\', %d)', $curUserId, $arg1->order_id, $ptamt, $points);
+            // D7
+            db_insert('uc_updiscounts')
+            ->fields(array(
+            'uid' => $curUserId, 
+            'oid' => $arg1->order_id, 
+            'ptamt' => $ptamt, 
+            'points' => $points,
             ))
-  ->execute();
-          }
+            ->execute();          
+					}
 
-        }
-      }
-      break;
-    case 'load':
-      $arg1->ptamt = '';
-      $result = db_query("SELECT * FROM {uc_updiscounts} WHERE oid = :oid", array(':oid' => $arg1->order_id));
-      if ($data = db_fetch_object($result)) {
-        $arg1->ptamt = $data->ptamt;
-      }
-      break;
-    case 'delete':
-      if (variable_get(USERPOINTS_DISCOUNT, 1) != 0 && $paymethod != 'points') {
-        global $user;
-        $curUserId	= $user->uid;
-        $oid			= $order->order_id;
-        $result 		= db_query("select updlog_id, points from {uc_updiscounts} where oid = %d and uid = %d and referrer = 0 and discount =1", $oid, $curUserId);
-
-        if ($result != FALSE && $pointinfo = db_fetch_object($result) != FALSE) {
-          $points = intval(($pointinfo->points) * (-1));
-          $description = 'User Discount (Ubercart Order ' . $oid . ') that has been deleted.';
-
-          $params = array(
-            'tid' => variable_get(USERPOINTS_DISCOUNT_CATEGORY, 0),
-            'uid' => $curUserId,
-            'points' => $points,
-            'operation' => 'delete',
-            'description' => $description,
-            'entity_id' => $oid,
-            'entity_type' => 'Ubercart Transaction',
-            'moderate' => variable_get(UC_USERPOINTS_DISCOUNT_MODERATE, 0),
-          );
-
-          userpoints_userpointsapi($params);
-          db_query("delete from {uc_updiscounts} where uplog_id = %d", $pointinfo->uplog_id);
-          // TODO Please review the conversion of this statement to the D7 database API syntax.
-          /* db_query("DELETE FROM {uc_order_line_items} WHERE order_id=%d AND type='ptdiscount'", $arg1->order_id) */
-          db_delete('uc_order_line_items')
-  ->condition('order_id', $arg1->order_id)
-  ->condition('type', 'ptdiscount')
-  ->execute();
-        }
-      }
-      break;
+				}
+			}
+			break;
+		case 'load':
+			$arg1->ptamt = '';
+			$results = db_query("SELECT * FROM {uc_updiscounts} WHERE oid = :oid", array(':oid' => $arg1->order_id));
+			foreach ($results as $data) {
+				$arg1->ptamt = $data->ptamt;
+			}
+			break;
+		case 'delete':	
+			if (variable_get(USERPOINTS_DISCOUNT,1) != 0 && $paymethod != 'points') {
+				global $user;
+				$curUserId	= $user->uid;
+				$oid			= $order->order_id;
+				$results 		= db_query("SELECT updlog_id, points from {uc_updiscounts} where oid = :oid and uid = :uid and referrer=0 and discount=1", array(':oid' =>$oid, ':uid' => $curUserId));
+
+				foreach ($results as $pointinfo) {
+					$points = intval(($pointinfo->points) * (-1));
+					$description = 'User Discount (Ubercart Order ' . $oid . ') that has been deleted.';
+					
+					$params = array (
+						'tid' => variable_get(USERPOINTS_DISCOUNT_CATEGORY, 0),
+						'uid' => $curUserId,
+						'points' => $points,
+						'operation' => 'delete',
+						'description' => $description,
+						'entity_id' => $oid,
+						'entity_type' => 'Ubercart Transaction',
+						'moderate' => variable_get(UC_USERPOINTS_DISCOUNT_MODERATE, 0),
+					);
+					
+					userpoints_userpointsapi($params);
+					// D6
+          // db_query("delete from {uc_updiscounts} where uplog_id = %d", $pointinfo->uplog_id);
+					// db_query("DELETE FROM {uc_order_line_items} WHERE order_id=%d AND type='ptdiscount'", $arg1->order_id);
+          db_delete('uc_updiscounts')
+          ->condition('uplog_id', $pointinfo->uplog_id)
+          ->execute();
+			    db_delete('uc_order_line_items')
+          ->condition('order_id', $arg1->order_id)
+          ->condition('type', 'ptdiscount')
+          ->execute();
+				}
+			}
+			break;
   }
 }
 
@@ -354,10 +358,10 @@ function uc_userpoints_discount_order($o
 function uc_userpoints_discount_checkboxes_status($array) {
   $status = FALSE;
   if (!empty($array)) {
-    foreach ($array as $row) {
+    foreach($array as $row) {
       if (!empty($row)) {
         $status = TRUE;
-      }
+      } 
     }
   }
   return $status;
@@ -370,12 +374,13 @@ function uc_userpoints_discount_checkbox
  * @return array of all product classes
  */
 function uc_userpoints_discount_product_classes() {
-  $result = db_query("SELECT * FROM {uc_product_classes}");
+  $results = db_query("SELECT * FROM {uc_product_classes}");
   $rows = array();
   //Because ubercart doesn't put the standard product class 'product' to the list, we do it manually :(
+  node_type_clear();
   $nodetypes = node_type_get_types();
   $rows['product'] = $nodetypes['product']->name;
-  while ($class = db_fetch_object($result)) {
+  foreach ($results as $class) {
     $rows[$class->pcid] = $class->name;
   }
   return $rows;
@@ -391,7 +396,7 @@ function uc_userpoints_discount_discount
   $cart_contents = uc_cart_get_contents();
   $discountable_classes = variable_get(UC_USERPOINTS_DISCOUNT_CLASSES, NULL);
   $discountable_products = array();
-  foreach ($cart_contents as $cart_item) {
+  foreach($cart_contents as $cart_item) {
     $node = node_load($cart_item->nid);
     if (uc_userpoints_discount_checkboxes_status($discountable_classes) === TRUE) {
       if ($discountable_classes[$node->type] === $node->type) {
@@ -426,8 +431,8 @@ function uc_userpoints_discount_discount
 function uc_userpoints_discount_discountable_total() {
   $discountable_products = uc_userpoints_discount_discountable_products();
   $discountable_total = 0;
-  foreach ($discountable_products as $discountable_product) {
-    $discountable_total += intval($discountable_product['price']) * intval($discountable_product['qty']);
+  foreach($discountable_products as $discountable_product) {
+    $discountable_total += intval($discountable_product['price']) * intval($discountable_product['qty']); 
   }
   return $discountable_total;
 }
@@ -470,7 +475,6 @@ function uc_userpoints_discount_theme() 
  * @return string discount theme info pane for cart/checkout
  */
 function theme_uc_userpoints_discount_info_pane($discountable_total = 0, $discount_max = 0, $discount_points_available = 0) {
-  // TODO: Should this theme uc_userpoints_discount_info_pane be declared in hook_theme()?
   $content = '<div id="discount_info_pane">
                 <div id="discountable_total">
                   <span id="discountable_total_label">'
@@ -497,7 +501,7 @@ function theme_uc_userpoints_discount_in
                   '</span>
                 </div>
               </div>';
-
+              
   return $content;
 }
 
diff -up uc_userpoints_payment.info uc_userpoints_payment.info
--- uc_userpoints_payment.info	2011-04-21 19:49:19.711692100 -0300
+++ uc_userpoints_payment.info	2011-04-22 03:42:42.814360500 -0300
@@ -8,9 +8,3 @@ dependencies[] = uc_payment
 core = 7.x
 php = 5.x
 
-; Information added by drupal.org packaging script on 2011-03-27
-version = "6.x-2.0-beta2"
-core = 7.x
-project = "userpoints_ubercart"
-datestamp = "1301267469"
-
diff -up uc_userpoints_payment.install uc_userpoints_payment.install
--- uc_userpoints_payment.install	2011-04-21 19:49:19.841699500 -0300
+++ uc_userpoints_payment.install	2011-04-22 04:18:37.764616600 -0300
@@ -1,29 +1,10 @@
 <?php
-/**
- * @file
- * Install, update and uninstall functions for the uc_userpoints_award module.
- *
- */
-
 //$Id;
 
-
 /**
- * Implementation of hook_install()
- */
-function uc_userpoints_payment_install() {
-  // Create tables.
-  drupal_install_schema('uc_userpoints_payment');
-}
-
-
-/**
- * Implementation of hook_uninstall().
- */
+* Implementation of hook_uninstall().
+*/
 function uc_userpoints_payment_uninstall() {
-  // Remove tables.
-  drupal_uninstall_schema('uc_userpoints_payment');
-
   // Remove variables
   variable_del('userpoints_ubercart_payment');
   variable_del('userpoints_display');
@@ -39,24 +20,24 @@ function uc_userpoints_payment_schema() 
   $schema['uc_up_payment_log'] = array(
     'fields' => array(
       'uplog_id' => array(
-        'type' => 'serial',
+        'type' => 'serial', 
         'not null' => TRUE,
       ),
       'uid' => array(
-        'type' => 'int',
-        'not null' => TRUE,
+        'type' => 'int', 
+        'not null' => TRUE, 
         'default' => 0,
       ),
       'oid' => array(
-        'type' => 'int',
-        'not null' => TRUE,
+        'type' => 'int', 
+        'not null' => TRUE, 
         'default' => 0,
       ),
       'points' => array(
-        'type' => 'int',
-        'not null' => TRUE,
+        'type' => 'int', 
+        'not null' => TRUE, 
         'default' => 0,
-      ),
+      )
     ),
     'primary key' => array('uplog_id'),
   );
diff -up uc_userpoints_payment.module uc_userpoints_payment.module
--- uc_userpoints_payment.module	2011-04-21 19:49:20.867758200 -0300
+++ uc_userpoints_payment.module	2011-04-23 01:49:29.843083800 -0300
@@ -1,10 +1,12 @@
 <?php
 
+define('UC_USERPOINTS_TRANS_UCPOINTS',   'userpoints_ubercart_translation_uppercase_points');
+define('UC_USERPOINTS_TRANS_LCPOINTS',   'userpoints_ubercart_translation_lowercase_points');
 
-define('USERPOINTS_UC_PAYMENT',    'userpoints_ubercart_payment');
-define('USERPOINTS_DISPLAY',       'userpoints_display');
+define('USERPOINTS_UC_PAYMENT',   'userpoints_ubercart_payment');
+define('USERPOINTS_DISPLAY',      'userpoints_display');
 define('USERPOINTS_PAY_MODERATE', 'userpoints_pay_moderate');
-define('USERPOINTS_PAY_DISPLAY',   'userpoints_pay_display');
+define('USERPOINTS_PAY_DISPLAY',  'userpoints_pay_display');
 define('USERPOINTS_PAY_CATEGORY', 'userpoints_pay_category');
 
 function uc_userpoints_payment_help($path, $arg) {
@@ -19,7 +21,7 @@ function uc_userpoints_payment_help($pat
  */
 
 function uc_userpoints_payment_userpoints($op, $data = NULL) {
-  switch ($op) {
+  switch($op) {
     case 'setting':
       if (module_exists('uc_cart') && module_exists('uc_payment')) {
         $group = 'uc_userpoints_payment';
@@ -40,18 +42,14 @@ function uc_userpoints_payment_userpoint
         $form[$group][USERPOINTS_DISPLAY] = array(
           '#type' => 'select',
           '#title' => t('Display currency, !points, or both', userpoints_translation()),
-          '#default_value' => variable_get(USERPOINTS_DISPLAY, 2),
-          '#options' => array(
-            1 => t('Currency'),
-            3 => t('Points'),
-            2 => t('Both'),
-          ),
+          '#default_value' =>  variable_get(USERPOINTS_DISPLAY,2),
+          '#options' => array(1 => t('Currency'), 3 => t('Points'), 2 => t('Both')),
         );
         $form[$group][USERPOINTS_PAY_MODERATE] = array(
           '#type' => 'radios',
           '#title' => t('Moderate userpoints transaction'),
           '#default_value' => variable_get(USERPOINTS_PAY_MODERATE, 0),
-          '#options' => array(t('No'), t('Yes')),
+					'#options' => array(t('No'), t('Yes')),
         );
         $form[$group][USERPOINTS_PAY_DISPLAY] = array(
           '#type' => 'radios',
@@ -97,10 +95,10 @@ function uc_userpoints_payment_userpoint
         $order = uc_order_load($data->entity_id);
         if ($order) {
           if (user_access('administer orders')) {
-            return l($data->operation, 'admin/store/orders/' . $order->order_id);
+            return l($data->operation, 'admin/store/orders/'. $order->order_id);
           }
           else {
-            return l($data->operation, 'user/' . $order->uid . '/orders/' . $order->order_id);
+            return l($data->operation, 'user/'. $order->uid. '/orders/'. $order->order_id);
           }
         }
       }
@@ -109,48 +107,51 @@ function uc_userpoints_payment_userpoint
 }
 
 /**
- * Implementation of hook_noedapi().
+ * Implementation of hook_node_view().
  */
 
-function uc_userpoints_payment_nodeapi(&$node, $op, $arg3, $arg4) {
-  switch ($op) {
-    case 'view':
-      if (uc_product_is_product($node)) {
-        $dispStyle = variable_get(USERPOINTS_DISPLAY, 2);
-        //disp 1=dollars, 2=both, 3=points
-
-        if (module_exists('uc_userpoints_product')) {
-          $points = db_query("SELECT points FROM {uc_userpoints_products} WHERE nid = :nid", array(':nid' => $node->nid))->fetchField();
-          if ($points > 0) {
-            $dispStyle = 1; // you can't buy a point product with points
-          }
-        }
-
-        $pointCost = ceil($node->sell_price * variable_get(USERPOINTS_UC_PAYMENT, 1));
-        switch ($dispStyle) {
-          case 1:
-            //do nothing since we only want dollars
-            //$node->content['sell_price']['#value'] = '$$';
-            //$node->content['display_price']['#value'] = '$$';
-            break;
-          case 2:
-            $node->content['sell_price']['#value'] .= '<div class="sell_price">' . t('!Points: ' . $pointCost, userpoints_translation()) . '</div>';
-            $node->content['display_price']['#value'] .= '<div class="display_price">' . t('!Points: ' . $pointCost, userpoints_translation()) . '</div>';
-            break;
-          case 3:
-            $node->content['sell_price']['#value'] = '<div class="sell_price">' . t('!Points: ' . $pointCost, userpoints_translation()) . '</div>';
-            $node->content['display_price']['#value'] = '<div class="display_price">' . t('!Points: ' . $pointCost, userpoints_translation()) . '</div>';
+function uc_userpoints_payment_node_view($node, $view_mode, $lang_code) {
+		if (uc_product_is_product($node)) {
+			$dispStyle = variable_get(USERPOINTS_DISPLAY,2);
+			//disp 1=dollars, 2=both, 3=points
+
+			if (module_exists('uc_userpoints_product')) {
+			  // D6
+        // $points = db_result(db_query("SELECT points FROM {uc_userpoints_products} WHERE nid = %d", $node->nid));
+        // D7
+        $query = db_query("SELECT points FROM {uc_userpoints_products} WHERE nid = :nid", array(':nid'=>$node->nid));
+				foreach ($query as $result) {
+  			  if ($result->points > 0) {
+	   		    $dispStyle = 1; // you can't buy a point product with points
             break;
+			    }
         }
-      }
-  }
+			}
+	
+      $pointCost = ceil($node->sell_price * variable_get(USERPOINTS_UC_PAYMENT, 1));
+			switch($dispStyle) {
+				case 1: 
+					//do nothing since we only want dollars
+					//$node->content['sell_price']['#value'] = '$$';
+					//$node->content['display_price']['#value'] = '$$';
+					break;
+				case 2: 
+					$node->content['sell_price']['#value'] .= '<div class="sell_price">' . t('!Points: ' . $pointCost, userpoints_translation()) . '</div>';
+					$node->content['display_price']['#value'] .= '<div class="display_price">' . t('!Points: ' . $pointCost, userpoints_translation()) . '</div>';
+					break;
+				case 3: 
+					$node->content['sell_price']['#value'] = '<div class="sell_price">' . t('!Points: ' . $pointCost, userpoints_translation()) . '</div>';
+					$node->content['display_price']['#value'] = '<div class="display_price">' . t('!Points: ' . $pointCost, userpoints_translation()) . '</div>';
+					break;
+			}
+		}
 }
 
 /**
- * Implementation of hook_payment_method().
+ * Implementation of hook_uc_payment_method().
  */
-
-function uc_userpoints_payment_payment_method() {
+ 
+function uc_userpoints_payment_uc_payment_method() {
   global $user;
 
   $amount = userpoints_get_current_points($user->uid, variable_get(USERPOINTS_PAY_CATEGORY, NULL));
@@ -162,17 +163,17 @@ function uc_userpoints_payment_payment_m
         // Display currency instead of points
         $amount = uc_currency_format($amount / variable_get(USERPOINTS_UC_PAYMENT, 1));
       }
-      $title .= ' ' . t('(total available: !amount)', array('!amount' => $amount));
+      $title .= ' '. t('(total available: !amount)', array('!amount' => $amount));
     }
 
     $methods[]	= array(
-      'id' => 'points',
-      'name' => t('!Points', uc_userpoints_translation()),
+      'id'	=> 'points',
+      'name'	=> t('!Points', uc_userpoints_translation()),
       'title' => $title,
-      'desc' => t('Pay by !points.', uc_userpoints_translation()),
-      'callback' => 'uc_payment_method_points',
-      'weight' => 4,
-      'checkout' => TRUE,
+      'desc'	=> t('Pay by !points.', uc_userpoints_translation()),
+      'callback'=> 'uc_payment_method_points',
+      'weight'	=> 4,
+      'checkout'=> TRUE,
       'no_gateway' => TRUE,
     );
 
@@ -181,36 +182,36 @@ function uc_userpoints_payment_payment_m
 }
 
 /**
- * Implementation of hook_order().
+ * Implementation of hook_uc_order().
  */
-
-function uc_userpoints_payment_order($op, &$arg1, $arg2) {
+ 
+function uc_userpoints_payment_uc_order($op, &$arg1, $arg2) {
   $order 	 = $arg1;
   $paymethod = strtolower($order->payment_method);
   switch ($op) {
-    case 'submit':
-      // fires when the order is submitted and adds/subtracts thier points
-      if ($paymethod == 'points') {
-        uc_userpoints_payment_payment($order);
-      }
-      break;
-    case 'update':
-      // if the order is canceled we need to refund thier points because we are too lazy to do it by hand...
-      if ($arg2 == 'canceled') {
-        if (strtolower($order->payment_method) == 'points') {
-          uc_userpoints_payment_refund($order);
-        }
-      }
-      break;
-    case 'delete':
-      if (strtolower($order->payment_method) == 'points') {
-        uc_userpoints_payment_refund($order);
-      }
-      break;
-    case 'can_delete':
-      return FALSE;
-      break;
-  }
+		case 'submit':
+			// fires when the order is submitted and adds/subtracts thier points
+			if ($paymethod == 'points') {
+				uc_userpoints_payment_payment($order);
+			}
+			break;
+		case 'update':
+			// if the order is canceled we need to refund thier points because we are too lazy to do it by hand...
+			if ($arg2 == 'canceled') {
+				if (strtolower($order->payment_method) == 'points') {
+					uc_userpoints_payment_refund($order);
+				}
+			}
+			break;
+		case 'delete':	
+		  if (strtolower($order->payment_method) == 'points') {
+			uc_userpoints_payment_refund($order);
+	  	  }
+		  break;
+		case 'can_delete';
+		  return FALSE;
+	  	break;
+	  }
 }
 
 /**
@@ -234,17 +235,17 @@ function uc_userpoints_translation() {
 
 function uc_payment_method_points($op, &$arg1) {
   switch ($op) {
-    case 'cart-details':
-      /**
-       *  Eventually I want to hide the points discount if its enabled.
-       **/
-      return;
-      break;
-    case 'cart-process':
+		case 'cart-details':
+			/**
+			 *  Eventually I want to hide the points discount if its enabled.
+			 **/
+			return;
+			break;
+		case 'cart-process':
       $user_points = userpoints_get_current_points($arg1->uid, variable_get(USERPOINTS_PAY_CATEGORY, NULL));
       $order_points = ceil($arg1->order_total * variable_get(USERPOINTS_UC_PAYMENT, 1));
 
-      if ($user_points < $order_points) {
+			if ($user_points < $order_points) {
         if (variable_get(USERPOINTS_PAY_DISPLAY, 1)) {
           // Display point amounts
           if (variable_get(USERPOINTS_DISPLAY, 2) == 1) {
@@ -258,21 +259,22 @@ function uc_payment_method_points($op, &
           // Hide point amounts
           drupal_set_message(t('You do not have enough !points to complete this purchase. Please select another payment method.', array_merge(uc_userpoints_translation(), array('@user_points' => $user_points, '@order_points' => $order_points))), 'error');
         }
-        return FALSE;
-        break;
-      }
-      else {
-        return TRUE;
-        break;
-      }
-      break;
-    case 'settings':
-      // Add a few points related fields to the payment methods settings form.
-      $form['userpoints_ubercart_permission'] = array(
-        '#value' => '<div>' . t('Please adjust the settings for using points under the userpoints section ' . l('userpoints admin settings', 'admin/config/userpoints') . '.  This area is for enabling points as payment method only.') . '</div>',
-      );
-      return $form;
-      break;
+				return FALSE;
+				break;
+			}
+			else
+			{
+				return TRUE;
+				break;
+			}
+			break;
+		case 'settings':
+			// Add a few points related fields to the payment methods settings form.
+			$form['userpoints_ubercart_permission'] = array(
+				'#value' => '<div>'. t('Please adjust the settings for using points under the userpoints section '.l('userpoints admin settings','admin/settings/userpoints').'.  This area is for enabling points as payment method only.') .'</div>',
+		);
+			return $form;
+			break;
   }
 }
 
@@ -283,25 +285,34 @@ function uc_userpoints_payment_payment($
   $description = t('Order #!order_id paid with !points', array_merge(uc_userpoints_translation(), array('!order_id' => $order->order_id)));
 
   if ($order === FALSE || uc_order_status_data($order->order_status, 'state') != 'in_checkout') {
-    print t('An error has occurred during payment.  Please contact us to ensure your order has submitted.');
-    exit();
+		print t('An error has occurred during payment.  Please contact us to ensure your order has submitted.');
+		exit();
   }
 
-  if ($order->payment_method == 'points') {
-    $params = array(
-      'tid' => variable_get(USERPOINTS_PAY_CATEGORY, NULL),
-      'uid' => $order->uid,
-      'points' => -$points,
-      'operation' => 'purchase',
-      'description' => $description,
-      'entity_id' => $order->order_id,
-      'entity_type' => 'uc_order',
-      'moderate' => variable_get(USERPOINTS_PAY_MODERATE, 0),
+  if ($order->payment_method == 'points') {  
+		$params = array (
+			'tid' => variable_get(USERPOINTS_PAY_CATEGORY, NULL),
+			'uid' => $order->uid,
+			'points' => -$points,
+			'operation' => 'purchase',
+			'description' => $description,
+			'entity_id' => $order->order_id,
+			'entity_type' => 'uc_order',
+			'moderate' => variable_get(USERPOINTS_PAY_MODERATE, 0),
       'display' => variable_get(USERPOINTS_PAY_DISPLAY, 1),
-    );
-    userpoints_userpointsapi($params);
-    uc_payment_enter($order->order_id, 'points', $order->order_total, $user->uid, NULL, $description);
-    db_query("insert into {uc_up_payment_log} (uid, oid, points) values(%d, %d, %d)", $order->uid, $order->order_id, $points);
+		);
+		userpoints_userpointsapi($params);
+		uc_payment_enter($order->order_id, 'points', $order->order_total, $user->uid, NULL, $description);
+		// D6
+    // db_query("insert into {uc_up_payment_log} (uid, oid, points) values(%d, %d, %d)", $order->uid, $order->order_id, $points);
+    // D7
+    db_insert('uc_up_payment_log')
+    ->fields(array(
+    'uid' => $order->uid, 
+    'oid' => $order->order_id, 
+    'points' => $points,
+    ))
+    ->execute();
   }
 }
 
@@ -309,28 +320,36 @@ function uc_userpoints_payment_refund($o
   global $user;
   $curUserId	= $user->uid;
   $oid 			= $order->order_id;
-  $result 		= db_query("select uplog_id, points from {uc_up_payment_log} where oid = %d and uid = %d", $oid, $curUserId);
+  $results 		= db_query("select uplog_id, points from {uc_up_payment_log} where oid = :oid and uid = :uid", array(':oid'=>$oid, ':uid'=>$curUserId));
   $orderTotal	= $order->order_total;
-
-  if ($result != FALSE) {
-    $pointinfo = db_fetch_object($result);
+  
+  foreach ($results as $pointinfo) {
     $points = intval((($pointinfo->points) * (-1)));
-    $description	= 'User purchase (Ubercart Order ' . $order->order_id . ') has been canceled.';
-
-    db_query("delete from {uc_payment_receipts} where method = 'Points' and order_id = %d", $oid);
-    db_query("delete from {uc_up_payment_log} where uplog_id = %d", $pointinfo->uplog_id);
-
-    $params = array(
-      'tid' => variable_get('USERPOINTS_PAY_CATEGORY', NULL),
-      'uid' => $curUserId,
-      'points' => $points,
-      'operation' => 'refund',
-      'description' => $description,
-      'entity_id' => $oid,
-      'entity_type' => 'uc_order',
-      'moderate' => variable_get(USERPOINTS_PAY_MODERATE, 0),
+		$description	= 'User purchase (Ubercart Order ' . $order->order_id .') has been canceled.';
+	
+		// D6
+    // db_query("delete from {uc_payment_receipts} where method = 'Points' and order_id = %d", $oid);
+		// db_query("delete from {uc_up_payment_log} where uplog_id = %d", $pointinfo->uplog_id);
+		// D7
+    db_delete('uc_payment_receipts')
+    ->condition('method', 'Points')
+    ->condition('order_id', $oid)
+    ->execute();
+    db_delete('uc_up_payment_log')
+    ->condition('uplog_id', $pointinfo->uplog_id)
+    ->execute();
+    
+		$params = array (
+			'tid' => variable_get('USERPOINTS_PAY_CATEGORY', NULL),
+			'uid' => $curUserId,
+			'points' => $points,
+			'operation' => 'refund',
+			'description' => $description,
+			'entity_id' => $oid,
+			'entity_type' => 'uc_order',
+			'moderate' => variable_get(USERPOINTS_PAY_MODERATE, 0),
       'display' => variable_get(USERPOINTS_PAY_DISPLAY, 1),
-    );
-    userpoints_userpointsapi($params);
+		);
+		userpoints_userpointsapi($params);
   }
 }
diff -up uc_userpoints_product.info uc_userpoints_product.info
--- uc_userpoints_product.info	2011-04-21 19:49:20.872758500 -0300
+++ uc_userpoints_product.info	2011-04-22 03:45:00.147215500 -0300
@@ -8,9 +8,3 @@ dependencies[] = uc_payment
 core = 7.x
 php = 5.x
 
-; Information added by drupal.org packaging script on 2011-03-27
-version = "6.x-2.0-beta2"
-core = 7.x
-project = "userpoints_ubercart"
-datestamp = "1301267469"
-
diff -up uc_userpoints_product.install uc_userpoints_product.install
--- uc_userpoints_product.install	2011-04-21 19:49:21.015766700 -0300
+++ uc_userpoints_product.install	2011-04-22 04:20:12.251021000 -0300
@@ -1,10 +1,4 @@
 <?php
-/**
- * @file
- * Install, update and uninstall functions for the uc_userpoints_award module.
- *
- */
-
 //$Id;
 
 
@@ -15,58 +9,47 @@ function uc_userpoints_product_schema() 
   $schema['uc_userpoints_products'] = array(
     'fields' => array(
       'upid' => array(
-        'type' => 'serial',
+        'type' => 'serial', 
         'not null' => TRUE,
       ),
       'pfid' => array(
-        'type' => 'int',
-        'size' => 'medium',
-        'not null' => TRUE,
-        'default' => 0,
+        'type' => 'int', 
+        'size' => 'medium', 
+        'not null' => TRUE, 
+        'default' => 0, 
         'disp-width' => '9',
       ),
       'nid' => array(
-        'type' => 'int',
-        'size' => 'medium',
-        'not null' => TRUE,
-        'default' => 0,
+        'type' => 'int', 
+        'size' => 'medium', 
+        'not null' => TRUE, 
+        'default' => 0, 
         'disp-width' => '9',
       ),
       'tid' => array(
-        'type' => 'int',
-        'size' => 'medium',
-        'not null' => TRUE,
-        'default' => 0,
+        'type' => 'int', 
+        'size' => 'medium', 
+        'not null' => TRUE, 
+        'default' => 0, 
         'disp-width' => '9',
       ),
       'points' => array(
-        'type' => 'int',
-        'size' => 'medium',
-        'not null' => TRUE,
-        'default' => 0,
+        'type' => 'int', 
+        'size' => 'medium', 
+        'not null' => TRUE, 
+        'default' => 0, 
         'disp-width' => '9',
-      ),
+      )
     ),
     'primary key' => array('upid'),
   );
   return $schema;
 }
 
-
-/**
- * Implementation of hook_install()
- */
-function uc_userpoints_product_install() {
-  drupal_install_schema('uc_userpoints_product');
-}
-
-
 /**
  * Implementation of hook_uninstall()
  */
 function uc_userpoints_product_uninstall() {
-  drupal_uninstall_schema('uc_userpoints_product');
-
   variable_del('userpoints_product_moderate');
   variable_del('userpoints_product_category');
 }
diff -up uc_userpoints_product.module uc_userpoints_product.module
--- uc_userpoints_product.module	2011-04-21 19:49:22.078827500 -0300
+++ uc_userpoints_product.module	2011-04-22 06:12:48.965482900 -0300
@@ -1,261 +1,271 @@
 <?php
+
 /* major contributions and development by torgosPizza */
-/**
- * Implementation of hook_product_feature().
- */
 
-define('USERPOINTS_PRODUCT_MODERATE', 	'userpoints_product_moderate');
-define('USERPOINTS_PRODUCT_CATEGORY', 	'userpoints_product_category');
+define('USERPOINTS_PRODUCT_MODERATE',	'userpoints_product_moderate');
+define('USERPOINTS_PRODUCT_CATEGORY',	'userpoints_product_category');
 
 function uc_userpoints_product_help($path, $arg) {
-  switch ($path) {
-    case 'admin/modules#description':
-      return t('<strong>Ubercart Userpoints Product:</strong> Interfaces userpoints with Ubercart, so users can purchase points with products.');
-  }
+    switch ($path) {
+      case 'admin/modules#description':
+        return t('<strong>Ubercart Userpoints Product:</strong> Interfaces userpoints with Ubercart, so users can purchase points with products.');
+    }
 }
 
 
 function uc_userpoints_product_userpoints($op, $params = array()) {
-  switch ($op) {
-    case 'setting':
-      if (module_exists('uc_cart') && module_exists('uc_payment')) {
-        $group = 'uc_userpoints_product';
-        $form[$group] = array(
-          '#type' => 'fieldset',
-          '#collapsible' => TRUE,
-          '#collapsed' => TRUE,
-          '#title' => t('Ubercart Product Options'),
-        );
-        $form[$group][USERPOINTS_PRODUCT_MODERATE] = array(
-          '#type' => 'radios',
-          '#title' => t('Moderate userpoints transaction'),
-          '#default_value' => variable_get(USERPOINTS_PRODUCT_MODERATE, 0),
-          '#options' => array(t('No'), t('Yes')),
-        );
-        $form[$group][USERPOINTS_PRODUCT_CATEGORY] = array(
-          '#type' => 'select',
-          '#title' => t('Product Category'),
-          '#default_value' => variable_get(USERPOINTS_PRODUCT_CATEGORY, NULL),
-          '#options' => userpoints_get_categories(),
-          '#description' => t('Default category to assign awarded !points. This can be overridden on a per product basis', userpoints_translation()),
-        );
-      }
-      return $form;
-      break;
-  }
+	switch($op) {
+	  case 'setting':
+	    if (module_exists('uc_cart') && module_exists('uc_payment')) {
+		  $group = 'uc_userpoints_product';
+		  $form[$group] = array(
+		    '#type' => 'fieldset',
+			'#collapsible' => TRUE,
+			'#collapsed' => TRUE,
+			'#title' => t('Ubercart Product Options'),
+		  );
+		  $form[$group][USERPOINTS_PRODUCT_MODERATE] = array(
+		    '#type' => 'radios',
+			'#title' => t('Moderate userpoints transaction'),
+			'#default_value' => variable_get(USERPOINTS_PRODUCT_MODERATE, 0), 
+			'#options' => array(t('No'), t('Yes')),
+		  );
+		  $form[$group][USERPOINTS_PRODUCT_CATEGORY] = array(
+		    '#type' => 'select',
+			'#title' => t('Product Category'),
+			'#default_value' => variable_get(USERPOINTS_PRODUCT_CATEGORY, NULL),
+			'#options' => userpoints_get_categories(),
+			'#description' => t('Default category to assign awarded !points. This can be overridden on a per product basis', userpoints_translation()),
+	      );
+		}
+		return $form;
+		break;
+	}
 }
 
 
-function uc_userpoints_product_product_feature() {
-  $features[] = array(
-    'id' => 'userpoints',
-    'title' => t(variable_get(USERPOINTS_TRANS_UCPOINTS, 'Userpoints')),
-    'callback' => 'uc_userpoints_product_feature_form',
-    'delete' => 'uc_userpoints_product_feature_delete',
-    'settings' => array('uc_userpoints_product_feature_settings'),
-  );
-  return $features;
+function uc_userpoints_product_uc_product_feature() {
+	$features[] = array(
+		'id' => 'userpoints',
+		'title' => t(variable_get(USERPOINTS_TRANS_UCPOINTS, 'Userpoints')),
+		'callback' => 'uc_userpoints_product_feature_form',
+		'delete' => 'uc_userpoints_product_feature_delete',
+		'settings' => array('uc_userpoints_product_feature_settings'),
+	);
+	return $features;
 }
 
 /**
- * Build the userpoints feature form
- */
+* Build the userpoints feature form
+*/
 function uc_userpoints_product_feature_form($node, $feature) {
-  $points = 0;
-
-  $nid = arg(1);
-
-  $res = db_query("SELECT * FROM {uc_userpoints_products} ucup, {uc_product_features} ucpf WHERE ucup.pfid = :ucup.pfid AND ucup.nid = :ucup.nid", array(':ucup.pfid' => ucpf . pfid, ':ucup.nid' => $nid));
-  while ($pf = db_fetch_object($res)) {
-    $points = $pf->points;
-    $tid = $pf->tid;
-  }
+	$points = 0;
 
-  $category_options = userpoints_get_categories();
-  $category_options[-1] = t('Default ' . variable_get(USERPOINTS_TRANS_LCPOINTS, 'Points') . ' Product Category');
+	$nid = arg(1);
 
-  $form['nid'] = array(
-    '#type' => 'value',
-    '#value' => $nid,
-  );
-  $form['points'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Number of ' . variable_get(USERPOINTS_TRANS_LCPOINTS, 'points')),
-    '#description' => t('How many ' . variable_get(USERPOINTS_TRANS_LCPOINTS, 'points') . ' to give when this product is purchased.'),
-    '#default_value' => $points,
-  );
-  $form['tid'] = array(
-    '#type' => 'select',
-    '#title' => t('Product Category'),
-    '#default_value' => $tid,
-    '#options' => $category_options,
-    '#description' => t('Category to assign awarded !points. If you choose \'Default ' . variable_get(USERPOINTS_TRANS_LCPOINTS, 'Points') . ' Product Category\', the category on your ' . l(t('Ubercart Product Options'), 'admin/config/userpoints') . ' settings page will be used.', userpoints_translation()),
-  );
+	$res = db_query("SELECT * FROM {uc_userpoints_products} ucup, {uc_product_features} ucpf WHERE ucup.pfid = ucpf.pfid AND ucup.nid = :nid", array(':nid' => $nid));
+	foreach ($res as $pf) {
+	  $points = $pf->points;
+	  $tid = $pf->tid;
+	}
+	
+	$category_options = userpoints_get_categories();
+	$category_options[-1] = t('Default '.variable_get(USERPOINTS_TRANS_LCPOINTS, 'Points').' Product Category');
+
+	$form['nid'] = array(
+		'#type' => 'value',
+		'#value' => $nid,
+	);
+	$form['points'] = array(
+		'#type' => 'textfield',
+		'#title' => t('Number of '.variable_get(USERPOINTS_TRANS_LCPOINTS, 'points')),
+		'#description' => t('How many '.variable_get(USERPOINTS_TRANS_LCPOINTS, 'points').' to give when this product is purchased.'),
+		'#default_value' => $points,
+	);
+	$form['tid'] = array(
+		'#type' => 'select',
+		'#title' => t('Product Category'),
+		'#default_value' => $tid,
+		'#options' => $category_options,
+		'#description' => t('Category to assign awarded !points. If you choose \'Default '.variable_get(USERPOINTS_TRANS_LCPOINTS, 'Points').' Product Category\', the category on your '.l(t('Ubercart Product Options'), 'admin/settings/userpoints').' settings page will be used.', userpoints_translation()),
+	 );
 
-  return uc_product_feature_form($form);
+	return uc_product_feature_form($form);
 }
 
 
 function uc_userpoints_product_feature_form_validate($form, &$form_state) {
   if (!$form_state['values']['points'] || !is_numeric($form_state['values']['points']) || $form_state['values']['points'] < 1) {
-    form_set_error('points', 'You must enter a numeric value, greater than zero for points');
+    form_set_error('points','You must enter a numeric value, greater than zero for points');
   }
 }
 
 
 /**
- * Submit the form
- */
+* Submit the form
+*/
 function uc_userpoints_product_feature_form_submit($form, &$form_state) {
-  if ($form_state['values']['tid'] >= 0) {
-    $term = taxonomy_term_load($form_state['values']['tid']);
-    $term_name = $term->name;
-  }
-  elseif ($form_state['values']['tid'] == '-1') {
-    $term_name = l(t('Default ' . variable_get(USERPOINTS_TRANS_LCPOINTS, 'Points') . ' Product Category'), 'admin/config/userpoints');
-  }
-
-  $term = taxonomy_term_load($form_state['values']['tid']);
-  $data = array(
-    'pfid' => $form_state['values']['pfid'],
-    'nid' => $form_state['values']['nid'],
-    'points' => $form_state['values']['points'],
-    'tid' => $form_state['values']['tid'],
-    'fid' => 'userpoints',
-    'description' => 'Product is now worth ' . $form_state['values']['points'] . ' ' . variable_get(USERPOINTS_TRANS_LCPOINTS, 'points') . ', assigned to the \'' . $term_name . '\' category',
-  );
-
-  $ret = uc_product_feature_save($data);
-  if (empty($data['pfid'])) {
-    $pf = db_fetch_object(db_query("select pfid from {uc_product_features} where nid = %d and fid = '%s'", $data['nid'], $data['fid']));
-    $data['pfid'] = $pf->pfid;
-
-    // TODO Please review the conversion of this statement to the D7 database API syntax.
-    /* db_query("INSERT INTO {uc_userpoints_products} (pfid,nid,points,tid) VALUES (%d,%d,%d,%d)", $data['pfid'], $data['nid'], $data['points'], $data['tid']) */
-    $id = db_insert('uc_userpoints_products')
-  ->fields(array(
-      'pfid' => $data['pfid'],
-      'nid' => $data['nid'],
-      'points' => $data['points'],
-      'tid' => $data['tid'],
-    ))
-  ->execute();
-  }
-  else {
-    // TODO Please review the conversion of this statement to the D7 database API syntax.
-    /* db_query("UPDATE {uc_userpoints_products} SET points = %d, tid= %d WHERE nid = %d AND pfid = %d", $data['points'], $data['tid'], $data['nid'], $data['pfid']) */
+	if ($form_state['values']['tid'] >= 0) {
+		$term = taxonomy_term_load($form_state['values']['tid']);
+		$term_name = $term->name;
+	} elseif ($form_state['values']['tid'] == '-1'){
+		$term_name = l(t('Default '.variable_get(USERPOINTS_TRANS_LCPOINTS, 'Points').' Product Category'), 'admin/config/people/userpoints');
+	}
+	
+	$term = taxonomy_term_load($form_state['values']['tid']);
+	$data = array(
+		'pfid' => $form_state['values']['pfid'],
+		'nid' => $form_state['values']['nid'],
+		'points' => $form_state['values']['points'],
+		'tid' => $form_state['values']['tid'],
+		'fid' => 'userpoints',
+		'description' => 'Product is now worth '.$form_state['values']['points'].' '.variable_get(USERPOINTS_TRANS_LCPOINTS, 'points').', assigned to the \''. $term_name .'\' category',
+	);
+	
+	$ret = uc_product_feature_save($data);
+	if (empty($data['pfid'])) {
+		$pf = db_query("select pfid from {uc_product_features} where nid = :nid and fid = ':fid'", array(':nid'=>$data['nid'],':fid'=>$data['fid']));
+		$data['pfid'] = $pf[0]->pfid;
+
+		// D6
+    // db_query("INSERT INTO {uc_userpoints_products} (pfid,nid,points,tid) VALUES (%d,%d,%d,%d)",$data['pfid'],$data['nid'],$data['points'],$data['tid']);
+		// D7
+    db_insert('uc_userpoints_products')
+    ->fields(array(
+      'pfid'=>$data['pfid'],
+      'nid'=>$data['nid'],
+      'points'=>$data['points'],
+      'tid'=>$data['tid'],
+      ))
+    ->execute();
+	}
+	else {
+		// D6
+    // db_query("UPDATE {uc_userpoints_products} SET points = %d, tid= %d WHERE nid = %d AND pfid = %d",$data['points'],$data['tid'],$data['nid'],$data['pfid']);
+    // D7
     db_update('uc_userpoints_products')
-  ->fields(array(
-      'points' => $data['points'],
-      'tid' => $data['tid'],
+    ->fields(array(
+    'points'=>$data['points'],
+    'tid'=>$data['tid'],
     ))
-  ->condition('nid', $data['nid'])
-  ->condition('pfid', $data['pfid'])
-  ->execute();
-  }
+    ->condition('nid', $data['nid'])
+    ->condition('pfid', $data['pfid'])
+    ->execute();
+	}
 
-  $form_state['redirect'] = $ret;
+	$form_state['redirect'] = $ret;
 }
 
 
 /**
  * Feature settings
  */
-function uc_userpoints_product_feature_settings() {
-  // Nothing yet.
+function uc_userpoints_product_uc_feature_settings() {
+	// Nothing yet.
 }
 
 
 /**
  * Product Feature delete function
  */
-function uc_userpoints_product_feature_delete($feature) {
-  // TODO Please review the conversion of this statement to the D7 database API syntax.
-  /* db_query("DELETE FROM {uc_userpoints_products} WHERE pfid = %d", $feature['pfid']) */
-  db_delete('uc_userpoints_products')
-  ->condition('pfid', $feature['pfid'])
-  ->execute();
-  // TODO Please review the conversion of this statement to the D7 database API syntax.
-  /* db_query("DELETE FROM {uc_product_features} WHERE pfid = %d", $feature['pfid']) */
-  db_delete('uc_product_features')
-  ->condition('pfid', $feature['pfid'])
-  ->execute();
+function uc_userpoints_product_uc_feature_delete($feature) {
+		// D6
+    // db_query("DELETE FROM {uc_userpoints_products} WHERE pfid = %d",$feature['pfid']);
+		// db_query("DELETE FROM {uc_product_features} WHERE pfid = %d", $feature['pfid']);
+    db_delete('uc_userpoints_products')
+    ->condition('pfid', $feature['pfid'])
+    ->execute();
+    db_delete('uc_product_features')
+    ->condition('pfid', $feature['pfid'])
+    ->execute();
 }
 
 
 /**
- * Implementation of hook_order();
+ * Implementation of hook_uc_order();
  */
-function uc_userpoints_product_order($op, $order, $status) {
+function uc_userpoints_product_uc_order($op, $order, $status) {
 
-  switch ($op) {
-    case 'update':
-      // We might want to add the "Order Status" to the Userpoints Ubercart options...
-      // if (($status == 'completed' && $order->uid > 0) && ($order_user = user_load(array('uid' => $order->uid))) !== FALSE) {
+	switch ($op) {
+		case 'update':
+		// We might want to add the "Order Status" to the Userpoints Ubercart options...
+	  // if (($status == 'completed' && $order->uid > 0) && ($order_user = user_load(array('uid' => $order->uid))) !== FALSE) {
       if ($order->order_status != 'completed' && ($status == 'completed' && $order->uid > 0) && ($order_user = user_load($order->uid)) !== FALSE) {
-        $totalPoints = 0; // this will be the total order points
-        foreach ($order->products as $product) {
-          $productPoints = 0; // This will be the product points * quantity
-          $points = db_query("SELECT sum(points) FROM {uc_userpoints_products} WHERE nid = :nid", array(':nid' => $product->nid))->fetchField();
-          $tid = db_query("SELECT tid FROM {uc_userpoints_products} WHERE nid = :nid", array(':nid' => $product->nid))->fetchField();
-          if ($points > 0) {
-            //drupal_set_message($product->title.' has '.$points.' '.variable_get(USERPOINTS_TRANS_LCPOINTS, 'points').' attached');
-            $productPoints = ($product->qty * $points); // Make sure we account for multiple qty of the Points product
-          }
-          if (($tid == '') || ($tid == '-1')) {
-            $tid = variable_get(USERPOINTS_PRODUCT_CATEGORY, 0);
-          }
-
-          $params = array(
-            'tid' => $tid,
-            'uid' => $order->uid,
-            'points' => $productPoints,
-            'operation' => 'add',
-            'description' => t('A user purchased !product containing !amount points.', array('!product' => l($product->title, 'node/' . $product->nid), '!amount' => $productPoints)),
-            'entity_id' => $order->oid,
-            'entity_type' => 'Ubercart Transaction',
-            'moderate' => variable_get(USERPOINTS_PRODUCT_MODERATE, 0),
-          );
-
-          $totalPoints += $productPoints;
-
-          if ($productPoints > 0) {
-            userpoints_userpointsapi($params);
-            uc_order_comment_save($order->order_id, 0, t('User bought ' . $productPoints . ' points with product: ' . $product->title . '!'), 'admin'); //Order comment per product points
-          }
-        }
-        if ($totalPoints > 0) {
-          uc_order_comment_save($order->order_id, 0, t('User bought a total of ' . $totalPoints . ' points on this order!'), 'admin'); //Order comment on total points
-        }
-      }
-
-      break;
-  }
+				$totalPoints = 0; // this will be the total order points
+				foreach ($order->products as $product) {
+					$productPoints = 0; // This will be the product points * quantity
+					// D6
+          // $points = db_result(db_query("SELECT sum(points) FROM {uc_userpoints_products} WHERE nid = %d", $product->nid));
+          // D7
+          $query = db_select('uc_userpoints_products')
+          ->condition('nid', $product->nid)
+          ->addExpression('SUM(points)', 'sum_points')
+          ->execute();
+					$points = $query[0]->sum_points;
+					//
+          // $tid = db_result(db_query("SELECT tid FROM {uc_userpoints_products} WHERE nid = %d", $product->nid));
+          // D7
+          $query = db_select('uc_userpoints_products')
+          ->condition('nid', $product->nid)
+          ->execute();
+          $tid = $query[0]->tid;
+					if ($points > 0) {
+						//drupal_set_message($product->title.' has '.$points.' '.variable_get(USERPOINTS_TRANS_LCPOINTS, 'points').' attached');
+						$productPoints = ($product->qty * $points); // Make sure we account for multiple qty of the Points product
+					}
+					if (($tid == '') || ($tid == '-1')) {
+			            $tid = variable_get(USERPOINTS_PRODUCT_CATEGORY, 0);
+			        }
+			    
+			    $params = array (
+				    'tid' => $tid,
+				    'uid' => $order->uid,
+				    'points' => $productPoints,
+				    'operation' => 'add',
+				    'description' => t('A user purchased !product containing !amount points.', array('!product' => l($product->title, 'node/' . $product->nid), '!amount' => $productPoints)),
+				    'entity_id' => $order->oid,
+				    'entity_type' => 'Ubercart Transaction',
+				    'moderate' => variable_get(USERPOINTS_PRODUCT_MODERATE, 0),
+			    );
+			
+				$totalPoints += $productPoints;
+				
+		        if ($productPoints > 0) {
+					userpoints_userpointsapi($params);
+					uc_order_comment_save($order->order_id, 0, t('User bought '.$productPoints.' points with product: '. $product->title .'!'), 'admin'); //Order comment per product points
+				}
+				}
+				if ($totalPoints > 0) {
+				  uc_order_comment_save($order->order_id, 0, t('User bought a total of '.$totalPoints.' points on this order!'), 'admin'); //Order comment on total points
+				}
+		    }
+		    
+	break;
+	}
 }
 
 /**
- * Check and make sure the user isn't trying to buy points with points.
- *  @todo: Make this configurable?
- */
+* Check and make sure the user isn't trying to buy points with points.
+*  @todo: Make this configurable?
+*/
 function uc_userpoints_product_form_alter(&$form, &$form_state, $form_id) {
   // We may need to alter the checkout form to remove invalid payment methods.
   if ($form_id == 'uc_cart_checkout_form' && isset($form['panes']['payment'])) {
-
+           
     $order->products = uc_cart_get_contents();
 
     // Make no changes if no products containing Userpoints are found.
     if (uc_userpoints_find_points_products($order) == array()) {
       return;
-    }
-    else if (isset($form['panes']['payment']['payment_method']['#options']['points'])) {
+    } else if (isset($form['panes']['payment']['payment_method']['#options']['points'])) {
       unset($form['panes']['payment']['payment_method']['#options']['points']);
-      drupal_set_message(t('You cannot purchase !points with !points, so that payment option has been removed.', userpoints_translation()), 'error');
+      drupal_set_message(t('You cannot purchase !points with !points, so that payment option has been removed.', check_plain(userpoints_translation())),'error');
     }
-
+       
     $count = count($form['panes']['payment']['payment_method']['#options']);
     if ($count == 0) {
       // Display an error message if no payment methods remain.
-      drupal_set_message(t('There are no payment methods available to purchase !points with!', userpoints_translation()), 'error');
+      drupal_set_message(t('There are no payment methods available to purchase !points with!', check_plain(userpoints_translation())), 'error');
       drupal_set_message(t('Please contact an administrator to solve the issue.'), 'error');
     }
     elseif ($count == 1) {
@@ -267,13 +277,13 @@ function uc_userpoints_product_form_alte
 
 
 /**
- * Returns an array of nids associated with user's cart contents
- *
- * @param $order
- *   The order object in question.
- * @return
- *   An array of matching nids from uc_userpoints_products.
- */
+* Returns an array of nids associated with user's cart contents
+*
+* @param $order
+*   The order object in question.
+* @return
+*   An array of matching nids from uc_userpoints_products.
+*/
 function uc_userpoints_find_points_products($order) {
   if (!is_array($order->products) || count($order->products) == 0) {
     return array();
@@ -281,15 +291,17 @@ function uc_userpoints_find_points_produ
 
   foreach ($order->products as $product) {
     $nids[] = check_plain($product->nid);
-    //dsm('Nid: '.$product->nid);
+        //dsm('Nid: '.$product->nid);
   }
 
   $pointsproducts = array();
-  // TODO Please convert this statement to the D7 database API syntax.
-  $result = db_query("SELECT * FROM {uc_userpoints_products} WHERE nid IN (" . implode(", ", $nids) . ")");
-  while ($pntproduct = db_fetch_object($result)) {
+  // D6
+  // $results = db_query("SELECT * FROM {uc_userpoints_products} WHERE nid IN (". implode(", ", $nids) .")");
+  // D7
+  $results = db_query("SELECT * FROM {uc_userpoints_products} WHERE nid IN (:nids)", array(':nids'=>$nids));
+  foreach ($results as $pntproduct) {
     $pointsproducts[] = $pntproduct;
-    //dsm('Matched nid: '.$pntproduct->nid);
+        //dsm('Matched nid: '.$pntproduct->nid);
   }
 
   return $pointsproducts;
diff -up uc_userpoints_seller.info uc_userpoints_seller.info
--- uc_userpoints_seller.info	2011-04-21 19:49:23.078884700 -0300
+++ uc_userpoints_seller.info	2011-04-22 03:57:09.884954100 -0300
@@ -9,20 +9,4 @@ dependencies[] = ca
 core = 7.x
 php = 5.x
 
-; Information added by drupal.org packaging script on 2011-03-27
-version = "6.x-2.0-beta2"
-core = 7.x
-project = "userpoints_ubercart"
-datestamp = "1301267469"
-
 
-files[] = uc_userpoints_award.install
-files[] = uc_userpoints_award.module
-files[] = uc_userpoints_discount.install
-files[] = uc_userpoints_discount.module
-files[] = uc_userpoints_payment.install
-files[] = uc_userpoints_payment.module
-files[] = uc_userpoints_product.install
-files[] = uc_userpoints_product.module
-files[] = uc_userpoints_seller.install
-files[] = uc_userpoints_seller.module
diff -up uc_userpoints_seller.install uc_userpoints_seller.install
--- uc_userpoints_seller.install	2011-04-21 19:49:22.243836900 -0300
+++ uc_userpoints_seller.install	2011-04-22 04:20:24.624728700 -0300
@@ -1,10 +1,4 @@
 <?php
-/**
- * @file
- * Install, update and uninstall functions for the uc_userpoints_award module.
- *
- */
-
 //$Id;
 
 /* major contributions and development by torgosPizza */
@@ -16,66 +10,55 @@
 function uc_userpoints_seller_schema() {
   $schema['uc_up_seller_log'] = array(
     'fields' => array(
-      'uc_up_seller_id' => array(
-        'type' => 'serial',
-        'not null' => TRUE,
-      ),
-      'uid' => array(
-        'type' => 'int',
-        'not null' => TRUE,
-        'default' => '0',
-      ),
-      'oid' => array(
-        'type' => 'int',
-        'not null' => TRUE,
-        'default' => '0',
-      ),
-      'points' => array(
-        'type' => 'int',
-        'not null' => TRUE,
-        'default' => '0',
-      ),
-      'qty' => array(
-        'type' => 'int',
-        'size' => 'small',
-        'not null' => TRUE,
-        'default' => '0',
-      ),
-      'model' => array(
-        'type' => 'varchar',
-        'length' => 255,
-        'not null' => TRUE,
-        'default' => '',
-      ),
-      'sellprice' => array(
-        'type' => 'numeric',
-        'precision' => 10,
-        'scale' => 2,
-        'not null' => TRUE,
-        'default' => '0.00',
-      ),
-    ),
-    'primary key' => array('uc_up_seller_id'),
+	    'uc_up_seller_id' => array(
+	      'type' => 'serial', 
+	      'not null' => TRUE,
+	    ),
+	    'uid' => array(
+	      'type' => 'int', 
+	      'not null' => TRUE, 
+	      'default' => '0',
+	    ),
+	    'oid' => array(
+	      'type' => 'int', 
+	      'not null' => TRUE, 
+	      'default' => '0',
+	    ),
+	    'points' => array(
+	      'type' => 'int', 
+	      'not null' => TRUE, 
+	      'default' => '0',
+	    ),
+	    'qty' => array(
+	      'type' => 'int', 
+	      'size' => 'small', 
+	      'not null' => TRUE, 
+	      'default' => '0',
+	    ),
+	    'model' => array(
+	      'type' => 'varchar', 
+	      'length' => 255, 
+	      'not null' => TRUE, 
+	      'default' => '',
+	    ),
+	    'sellprice' => array(
+	      'type' => 'numeric', 
+	      'precision' => 10, 
+	      'scale' => 2, 
+	      'not null' => TRUE, 
+	      'default' => '0.00',
+	    ),
+	  ),
+	'primary key' => array('uc_up_seller_id'),
   );
 
   return $schema;
 }
 
-
 /**
- * Implementation of hook_install()
- */
-function uc_userpoints_seller_install() {
-  drupal_install_schema('uc_userpoints_seller');
-}
-
-
-/**
- * Implementation of hook_uninstall().
- */
+* Implementation of hook_uninstall().
+*/
 function uc_userpoints_seller_uninstall() {
-  drupal_uninstall_schema('uc_userpoints_seller');
-
   variable_del('uc_userpoints_seller_earn');
   variable_del('uc_userpoints_seller_disp');
   variable_del('uc_userpoints_seller_hist');
diff -up uc_userpoints_seller.module uc_userpoints_seller.module
--- uc_userpoints_seller.module	2011-04-21 19:49:23.073884400 -0300
+++ uc_userpoints_seller.module	2011-04-23 02:44:54.681253600 -0300
@@ -2,9 +2,9 @@
 //$Id;
 
 
-define('UC_USERPOINTS_SELLER_EARN',       'uc_userpoints_seller_earn');
-define('UC_USERPOINTS_SELLER_DISP',       'uc_userpoints_seller_disp');
-define('UC_USERPOINTS_SELLER_HIST',       'uc_userpoints_seller_hist');
+define('UC_USERPOINTS_SELLER_EARN',      'uc_userpoints_seller_earn');
+define('UC_USERPOINTS_SELLER_DISP',      'uc_userpoints_seller_disp');
+define('UC_USERPOINTS_SELLER_HIST',      'uc_userpoints_seller_hist');
 
 
 /* Begin Seller History Reporting */
@@ -14,18 +14,18 @@ function uc_userpoints_seller_menu() {
 
   $items['admin/store/reports/sales-points'] = array(
     'title' => 'Sales Points Reports',
-    'description' => 'View reports for points earned by store sales',
-    'page callback' => 'uc_seller_history_all',
-    'access arguments' => array('view reports'),
-    'type' => MENU_NORMAL_ITEM,
+	  'description' => 'View reports for points earned by store sales',
+	  'page callback' => 'uc_seller_history_all',
+	  'access arguments' => array('view reports'),
+	  'type' => MENU_NORMAL_ITEM,
   );
   $items['user/%user/sales-points'] = array(
     'title' => 'Sales Points',
-    'description' => 'View your points earned by sales',
-    'page callback' => 'uc_seller_history_user',
-    'page arguments' => array(1),
-    'access arguments' => array('view own userpoints'),
-    'type' => MENU_LOCAL_TASK,
+	  'description' => 'View your points earned by sales',
+	  'page callback' => 'uc_seller_history_user',
+	  'page arguments' => array(1),
+	  'access arguments' => array('view own userpoints'),
+	  'type' => MENU_LOCAL_TASK
   );
 
   return $items;
@@ -41,54 +41,42 @@ function uc_seller_history_user($usr) {
   drupal_set_title(t('My Sales Points History'));
 
   $breadcrumb = drupal_get_breadcrumb();
-  $breadcrumb[] = l(t('My account'), 'user/' . $usr->uid);
+  $breadcrumb[] = l(t('My account'), 'user/'. $usr->uid);
   drupal_set_breadcrumb($breadcrumb);
 
   $header = array(
-    array(
-      'data' => t('Order #'),
-      'field' => 'oid',
-    ),
-    array(
-      'data' => t('Qty'),
-      'field' => 'qty',
-    ),
-    array(
-      'data' => t('Model'),
-      'field' => 'model',
-    ),
-    array(
-      'data' => t('Sell Price'),
-      'field' => 'sellprice',
-    ),
-    array(
-      'data' => t('Total'),
-      'field' => 'total',
-    ),
-    array(
-      'data' => t('Points'),
-      'field' => 'points',
-    ),
+    array('data' => t('Order #'), 'field' => 'oid'),
+    array('data' => t('Qty'), 'field' => 'qty'),
+    array('data' => t('Model'), 'field' => 'model'),
+    array('data' => t('Sell Price'), 'field' => 'sellprice'),
+    array('data' => t('Total'), 'field' => 'total'),
+    array('data' => t('Points'), 'field' => 'points'),
   );
 
-  $result = pager_query("SELECT uid, oid, points, qty, model, sellprice, (qty * sellprice) AS total FROM {uc_up_seller_log} WHERE uid = %d" . tablesort_sql($header), 20, 0, "SELECT COUNT(*) FROM {uc_up_seller_log} WHERE uid = %d", $usr->uid, $usr->uid);
+  // D6 
+  // $result = pager_query("SELECT uid, oid, points, qty, model, sellprice, (qty * sellprice) AS total FROM {uc_up_seller_log} WHERE uid = :uid". tablesort_sql($header), 20, 0, "SELECT COUNT(*) FROM {uc_up_seller_log} WHERE uid = :uid", array(':uid' => $usr->uid));
+  // D7
+  $query = db_query("SELECT uid, oid, points, qty, model, sellprice, (qty * sellprice) AS total FROM {uc_up_seller_log} WHERE uid = :uid", array(':uid' => $usr->uid));
+  $count_query = db_query("SELECT COUNT(*) FROM {uc_up_seller_log} WHERE uid = :uid", array(':uid' => $usr->uid));
+  $query = $query->extend('PagerDefault'); // this returns another query object
+  $result = $query->limit(20)
+  ->orderByHeader($header)
+  ->setCountQuery($count_query)
+  ->execute();  
 
   // Build a table based on the customer's sales.
-  while ($sales = db_fetch_object($result)) {
+  foreach ($result as $sales) {
     $rows[] = array(
       array('data' => $sales->oid),
       array('data' => $sales->qty),
       array('data' => $sales->model),
       array('data' => $sales->sellprice),
-      array(
-        'data' => uc_currency_format($sales->total, TRUE),
-        'align' => 'right',
-      ),
+      array('data' => uc_currency_format($sales->total, TRUE), 'align' => 'right'),
       array('data' => $sales->points),
     );
   }
 
-  $output = theme('table', array('header' => $header, 'rows' => $rows)) . theme('pager', array('tags' => null, 'element' => 0));
+  $output = theme('table', $header, $rows) . theme('pager', null, 20, 0);
 
   return $output;
 }
@@ -97,55 +85,40 @@ function uc_seller_history_all() {
   drupal_set_title(t('Sales Points History'));
 
   $header = array(
-    array(
-      'data' => t('User'),
-      'field' => 'uid',
-    ),
-    array(
-      'data' => t('Order #'),
-      'field' => 'oid',
-    ),
-    array(
-      'data' => t('Qty'),
-      'field' => 'qty',
-    ),
-    array(
-      'data' => t('Model'),
-      'field' => 'model',
-    ),
-    array(
-      'data' => t('Sell Price'),
-      'field' => 'sellprice',
-    ),
-    array(
-      'data' => t('Total'),
-      'field' => 'total',
-    ),
-    array(
-      'data' => t('Points'),
-      'field' => 'points',
-    ),
+    array('data' => t('User'), 'field' => 'uid'),
+    array('data' => t('Order #'), 'field' => 'oid'),
+    array('data' => t('Qty'), 'field' => 'qty'),
+    array('data' => t('Model'), 'field' => 'model'),
+    array('data' => t('Sell Price'), 'field' => 'sellprice'),
+    array('data' => t('Total'), 'field' => 'total'),
+    array('data' => t('Points'), 'field' => 'points'),
   );
 
-  $result = pager_query("SELECT u.name, sl.uid, sl.oid, sl.points, sl.qty, sl.model, sl.sellprice, (qty * sellprice) AS total FROM {uc_up_seller_log} sl left join {users} as u on sl.uid = u.uid" . tablesort_sql($header), 20, 0, "SELECT COUNT(*) FROM {uc_up_seller_log}");
-
+  // D6
+  // $result = pager_query("SELECT u.name, sl.uid, sl.oid, sl.points, sl.qty, sl.model, sl.sellprice, (qty * sellprice) AS total FROM {uc_up_seller_log} sl left join {users} as u on sl.uid = u.uid". tablesort_sql($header), 20, 0, "SELECT COUNT(*) FROM {uc_up_seller_log}");
+  // D7
+  $query = db_query("SELECT u.name, sl.uid, sl.oid, sl.points, sl.qty, sl.model, sl.sellprice, (qty * sellprice) AS total FROM {uc_up_seller_log} sl left join {users} as u on sl.uid = u.uid");
+  $count_query = db_query("SELECT COUNT(*) FROM {uc_up_seller_log}");
+  $query = $query->extend('PagerDefault'); // this returns another query object
+  $result = $query->limit(20)
+  ->orderByHeader($header)
+  ->setCountQuery($count_query)
+  ->execute();
+  
   // Build a table based on the customer's sales.
-  while ($sales = db_fetch_object($result)) {
+  foreach ($result as $sales) {
     $rows[] = array(
       array('data' => '<a href="/user/' . $sales->uid . '">' . $sales->name . '</a>'),
       array('data' => $sales->oid),
       array('data' => $sales->qty),
       array('data' => $sales->model),
       array('data' => $sales->sellprice),
-      array(
-        'data' => uc_currency_format($sales->total, TRUE),
-        'align' => 'right',
-      ),
+      array('data' => uc_currency_format($sales->total, TRUE), 'align' => 'right'),
       array('data' => $sales->points),
     );
   }
 
-  $output = theme('table', array('header' => $header, 'rows' => $rows)) . theme('pager', array('tags' => null, 'element' => 0));
+  $output = theme('table', $header, $rows) . theme('pager', null, 20, 0);
 
   return $output;
 }
@@ -156,7 +129,7 @@ function uc_seller_history_all() {
 
 
 function uc_userpoints_seller_userpoints($op, $points = 0, $uid = 0, $event = '') {
-  switch ($op) {
+  switch($op) {
     case 'setting':
       if (module_exists('uc_cart') && module_exists('uc_payment')) {
         $group = 'uc_seller';
@@ -166,7 +139,7 @@ function uc_userpoints_seller_userpoints
           '#collapsed' => TRUE,
           '#title' => t('Ubercart Seller Options'),
         );
-
+    
         $form[$group][UC_USERPOINTS_SELLER_EARN] = array(
           '#type' => 'textfield',
           '#title' => t('!Points awarded to seller purchase (multiplied by product price)', userpoints_translation()),
@@ -178,13 +151,13 @@ function uc_userpoints_seller_userpoints
           '#type' => 'radios',
           '#title' => t('Display amount of !points awarded to seller', userpoints_translation()),
           '#default_value' => variable_get(UC_USERPOINTS_SELLER_DISP, 0),
-          '#options' => array(t('No'), t('Yes')),
+		  '#options' => array(t('No'), t('Yes')),
         );
         $form[$group][UC_USERPOINTS_SELLER_HIST] = array(
           '#type' => 'radios',
           '#title' => t('Allow user to see transaction history under "My Account"'),
           '#default_value' => variable_get(UC_USERPOINTS_SELLER_HIST, 1),
-          '#options' => array(t('No'), t('Yes')),
+	   	  '#options' => array(t('No'), t('Yes')),
         );
       }
       return $form;
@@ -199,24 +172,24 @@ function uc_userpoints_seller_userpoints
 function uc_userpoints_seller_ca_action() {
   $order_arg = array(
     '#entity' => 'uc_order',
-    '#title' => t('Order'),
+	  '#title' => t('Order'),
   );
 
   $actions['uc_userpoints_seller_award_points'] = array(
     '#title' => t('Award seller points'),
-    '#category' => t('Order'),
-    '#callback' => 'uc_userpoints_seller_award_points',
-    '#arguments' => array(
-      'order' => $order_arg,
-    ),
+	  '#category' => t('Order'),
+	  '#callback' => 'uc_userpoints_seller_award_points',
+	  '#arguments' => array(
+  	  'order' => $order_arg,
+	  ),
   );
 
   return $actions;
 }
 
 /**
- * Implementation of hook_ca_predicate().
- */
+* Implementation of hook_ca_predicate().
+*/
 function uc_userpoints_seller_ca_predicate() {
   // Give the seller the points they earned when a payment is received
   // and the balance is less than or equal to 0.
@@ -277,27 +250,39 @@ function uc_userpoints_seller_ca_predica
 function uc_userpoints_seller_award_points(&$order, $settings) {
   if (is_array($order->products)) {
     foreach ($order->products as $product) {
-      $product_info = db_fetch_object(db_query("select n.uid from {node} n, {uc_products} p where n.vid = p.vid and p.model =  '%s'", $product->model));
-      $total = (intval($product->qty) * intval($product->price));
-      $multiplier = variable_get(UC_USERPOINTS_SELLER_EARN, 0);
-      $points = intval(($total * $multiplier));
-      $blnDisplay = variable_get(UC_USERPOINTS_SELLER_DISP, 0);
-
-      if ($points > 0) {
-        $params = array(
-          'tid' => 0,
-          'uid' => $product_info->uid,
-          'points' => $points,
-          'operation' => 'insert',
-          'description' => 'Someone purchased a product belonging to ' . $product_info->uid . ', awarding points (Ubercart Order ID ' . $order->order_id . ')',
-          'display' => $blnDisplay,
-        );
-        $st = userpoints_userpointsapi($params);
-        db_query("insert into {uc_up_seller_log} (uid, oid, points, qty, model, sellprice) values(%d, %d, %d, %d, '%s', %d)", $product_info->uid, $order->order_id, $points, $product->qty, $product->model, $product->price);
-      }
-      $total = '';
-      $multiplier = '';
-      $points = '';
+			$product_info = db_query("SELECT n.uid FROM {node} n, {uc_products} p WHERE n.vid = p.vid AND p.model = ':pmodel'", array(':pmodel' => $product->model))->fetch_object();
+			$total = (intval($product->qty) * intval($product->price));
+			$multiplier = variable_get(UC_USERPOINTS_SELLER_EARN, 0);
+		  $points = intval(($total * $multiplier));
+			$blnDisplay = variable_get(UC_USERPOINTS_SELLER_DISP, 0);
+			
+			if ($points > 0) {
+				$params = array (
+					'tid' => 0,
+					'uid' => $product_info->uid,
+					'points' => $points,
+					'operation' => 'insert',
+					'description' => 'Someone purchased a product belonging to ' . $product_info->uid . ', awarding points (Ubercart Order ID ' . $order->order_id . ')',
+					'display' => $blnDisplay,
+				);
+				$st = userpoints_userpointsapi($params);
+			  // D6
+        // db_query("insert into {uc_up_seller_log} (uid, oid, points, qty, model, sellprice) values(%d, %d, %d, %d, '%s', %d)", $product_info->uid, $order->order_id, $points, $product->qty, $product->model, $product->price);
+        // D7
+        db_insert('uc_up_seller_log')
+        ->fields(array(
+        'uid' => $product_info->uid,
+        'oid' => $order->order_id,
+        'points' => $points,
+        'qty' => $product->qty,
+        'model' => $product->model, 
+        'sellprice' => $product->price,
+        ))
+        ->execute();
+			}
+			$total = '';
+			$multiplier = '';
+			$points = '';
     }
   }
 }
