Index: uc_userpoints_award.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/userpoints_ubercart/uc_userpoints_award.module,v
retrieving revision 1.5.2.1
diff -u -p -r1.5.2.1 uc_userpoints_award.module
--- uc_userpoints_award.module	14 May 2009 02:47:13 -0000	1.5.2.1
+++ uc_userpoints_award.module	18 May 2009 20:44:14 -0000
@@ -1,5 +1,4 @@
 <?php
-
 //$Id: uc_userpoints_award.module,v 1.5.2.1 2009/05/14 02:47:13 smokris Exp $
 
 define('USERPOINTS_UC_EARN',      'userpoints_ubercart_earn');
@@ -80,7 +79,12 @@ function uc_userpoints_award_userpoints(
 
 
 /**
+ * Conditional Actions callbacks and forms
+ */
+
+/**
  * Implementation of hook_ca_action
+ * @return array
  */
 function uc_userpoints_award_ca_action() {
 	$order_arg = array(
@@ -100,20 +104,20 @@ function uc_userpoints_award_ca_action()
 	return $actions;
 }
 
-
-/* ************************************************************************* *
- *  Workflow-ng Action Callbacks and Forms                                   *
- * ************************************************************************* */
-
+/**
+ * Conditional Actions buyer award points callback
+ * Gives the user points for their purchase if they did not pay with points.
+ * Also, does not give points for tax or shipping.
+ * @param $order the ubercart order
+ * @param $settings various settings
+ */
 function uc_userpoints_buyer_award_points($order, $settings) {
-  // gives the user points for thier purchase, but checks via sql if they paid with points.  if so they get nothing also dont give points for tax and shipping.
-
   global $user;
-  $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);
-  $total		= db_result($result, $row = 0);
+  $curUserId = $order->uid;
+  $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);
+  $total = db_result($result, $row = 0);
 
   $refUserId = 0; // default to 0 so if referral module is not installed or no referrer, we skip all referral code
   $ref_mult = 1; // assume a multiplier of 1, unless $award_to == 2, in which case we retrieve the value below
@@ -136,52 +140,47 @@ function uc_userpoints_buyer_award_point
       }
     }
   }
-	
 
-	// 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
+  // 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' => 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);
-		}
+    if ($total < $min) {
+	  $points = 0;
 	}
+	else {
+	  $points = intval(($total * $multiplier));
+	  $params = array (
+        'tid' => 0,
+		'uid' => $curUserId,
+		'points' => $points,
+		'operation' => 'insert',
+		'description' => 'User made a purchase, awarding points (Ubercart Order ID ' . $order->order_id . ')',
+		'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' => 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)",$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' => 0,
+		'uid' => $refUserId,
+		'points' => $points,
+		'operation' => 'insert',
+		'description' => 'Purchase made by someone you referred, awarding points to referrer (Ubercart Order ID ' . $order->order_id . ')',
+		'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)",$curUserId, $order->order_id, $points);
 	}
+  }
 }	
Index: uc_userpoints_discount.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/userpoints_ubercart/uc_userpoints_discount.module,v
retrieving revision 1.4.2.2
diff -u -p -r1.4.2.2 uc_userpoints_discount.module
--- uc_userpoints_discount.module	14 May 2009 04:18:27 -0000	1.4.2.2
+++ uc_userpoints_discount.module	18 May 2009 20:44:14 -0000
@@ -1,5 +1,4 @@
 <?php
-
 //$Id: uc_userpoints_discount.module,v 1.4.2.2 2009/05/14 04:18:27 smokris Exp $
 
 define('USERPOINTS_UC_DISC',   'userpoints_ubercart_payment');
@@ -8,6 +7,9 @@ define('UC_USERPOINTS_DISCOUNT_MODERATE'
 define('UC_USERPOINTS_DISCOUNT_MAXP',      'uc_userpoints_discount_maxp');
 define('USERPOINTS_DISCOUNT_CATEGORY',	'userpoints_discount_category');
 
+/**
+ * Implementation of hook_help
+ */
 function uc_userpoints_discount_help($path, $arg) {
   switch ($path) {
     case 'admin/modules#description':
@@ -17,6 +19,9 @@ function uc_userpoints_discount_help($pa
   return $output;
 }
 
+/**
+ * IMplementation of hook_userpoints
+ */
 function uc_userpoints_discount_userpoints($op, $points = 0, $uid = 0, $event = '') {
   switch($op) {
     case 'setting':
@@ -63,7 +68,7 @@ function uc_userpoints_discount_userpoin
         );
       }
       return $form;
-      break;
+	  break;
   }
 }
 
@@ -72,9 +77,9 @@ function uc_userpoints_discount_userpoin
  */
 function uc_userpoints_discount_checkout_pane() {
   global $user;
-  $curUserId	 = $user->uid;
+  $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(
@@ -88,36 +93,41 @@ function uc_userpoints_discount_checkout
   }
 }
 
-
+/**
+ * Ubercart Checkout Pane callback function
+ * @param $op operation
+ * @param &$arg1 argument 1 passed in by reference
+ * @param $arg2 argument 2
+ */
 function uc_checkout_pane_uc_userpoints_discount($op, &$arg1, $arg2) {
   // get point discounts to apply to this order
   global $user;
-  $curUserId	 = $user->uid;
+  $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.  You cannot discount more than ' . $maxpt . '% of this order.  You have a total of ' . uc_currency_format($maxdisc) . ' available via !Points. This field will be ignored if paying with !Points.', userpoints_translation());
-			$contents['ptamt'] = array(
-				'#type' => 'textfield',
-				'#title' => t('Discount Amount'),
-				'#description' => t(''),
-				'#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.  You cannot discount more than ' . $maxpt . '% of this order.  You have a total of ' . uc_currency_format($maxdisc) . ' available via !Points. This field will be ignored if paying with !Points.', userpoints_translation());
+	  $contents['ptamt'] = array(
+		'#type' => 'textfield',
+		'#title' => t('Discount Amount'),
+		'#description' => t(''),
+		'#default_value' => $arg1->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 = $arg2['ptamt'];
+	  if (!empty($ptamt) || $ptamt != '') {
+	    $arg1->ptamt = $ptamt;
+	  }
+	  else {
+		$arg1->ptamt = 0;
+	  }
+	  return TRUE;
+	  break;
   }
 }
 
@@ -125,131 +135,125 @@ function uc_checkout_pane_uc_userpoints_
  * Implementation of hook_order().
  * This is where all the important stuff happens like taking the points...
  */
- 
 function uc_userpoints_discount_order($op, &$arg1, $arg2) {
-  $order 	 = $arg1;
+  global $user;
+  $order = $arg1;
   $paymethod = strtolower($order->payment_method);
   switch ($op) {
     case 'total':
-			/**
-			 * If there is a discount apply it to the order total
-			 */
-			if (variable_get(USERPOINTS_DISCOUNT,1) != 0 && strtolower($order->payment_method) != 'points') {
-				$result = db_query("SELECT * FROM {uc_updiscounts} WHERE oid = %d", $arg1->order_id);
-				if ($data = db_fetch_object($result)) {
-					return -$data->ptamt;
-				}
-			}
-			break;
+	  // If tehre is a discount, apply it to the order total
+	  if (variable_get(USERPOINTS_DISCOUNT,1) != 0 && strtolower($order->payment_method) != 'points') {
+	    $result = db_query("SELECT * FROM {uc_updiscounts} WHERE oid = %d", $arg1->order_id);
+	    if ($data = db_fetch_object($result)) {
+	      return -$data->ptamt;
+	    }
+	  }
+	  break;
     case 'save':
-			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);
-			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;
+	  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);
+	  uc_line_items_calculate($arg1->order_id);	
+	  $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;
 
-			#money value of order
-			$orderamt = $arg1->order_total + $arg1->quote['rate'];
+	  //money value of order
+	  $orderamt = $arg1->order_total + $arg1->quote['rate'];
 			
-			#discount value
-			$ptamt = $arg1->ptamt;
-			#discount value in points
-			$points = -(($ptamt) * $multiplier);
-			$ptdisc = (($ptamt) * $multiplier);
+	  //discount value
+	  $ptamt = $arg1->ptamt;
+	  //discount value in points
+	  $points = -(($ptamt) * $multiplier);
+	  $ptdisc = (($ptamt) * $multiplier);
 			
-			#max discount on order total
-			$ptmaxd = $maxdisc * $orderamt;			
+	  //max discount on order total
+	  $ptmaxd = $maxdisc * $orderamt;			
 			
-			if (variable_get(USERPOINTS_DISCOUNT,1) != 0 && strtolower($order->payment_method) != 'points') {
-				if ((!empty($ptamt) || $ptamt != '') && $ptamt < $orderamt && $ptamt <= $ptmaxd) {
-					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);
-					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 > $ptmaxd && (!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 $' . $ptmaxd . '.  You need to decrease the size of the discount.', userpoints_translation()), 'error');
-					drupal_goto($pagepath);
-				}
-			}
-			elseif (strtolower($order->payment_method) == '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));
+	  if (variable_get(USERPOINTS_DISCOUNT,1) != 0 && strtolower($order->payment_method) != 'points') {
+	    if ((!empty($ptamt) || $ptamt != '') && $ptamt < $orderamt && $ptamt <= $ptmaxd) {
+		  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);
+		  uc_order_line_item_add($arg1->order_id, 'ptdiscount', t('Discount order using !Points',userpoints_translation()), -$ptamt, 1);
+	    }
+		else if ($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 > $ptmaxd && (!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 $' . $ptmaxd . '.  You need to decrease the size of the discount.', userpoints_translation()), 'error');
+		  drupal_goto($pagepath);
+		}
+	  }
+	  elseif (strtolower($order->payment_method) == '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) {
+			$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);
-					db_query('INSERT INTO {uc_updiscounts} (uid, oid, ptamt, points) VALUES (%d, %d, \'%f\', %d)', $curUserId, $arg1->order_id, $ptamt, $points);
-					}
-
-				}
+			// 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);
+			  db_query('INSERT INTO {uc_updiscounts} (uid, oid, ptamt, points) VALUES (%d, %d, \'%f\', %d)', $curUserId, $arg1->order_id, $ptamt, $points);
 			}
-			break;
-		case 'load':
-			$arg1->ptamt = '';
-			$result = db_query("SELECT * FROM {uc_updiscounts} WHERE oid = %d", $arg1->order_id);
-			if ($data = db_fetch_object($result)) {
-				$arg1->ptamt = $data->ptamt;
-			}
-			break;
-		case 'delete':	
-			if (variable_get(USERPOINTS_DISCOUNT,1) != 0 && strtolower($order->payment_method) != '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.';
+		  }
+	    }
+		break;
+	  case 'load':
+		$arg1->ptamt = '';
+		$result = db_query("SELECT * FROM {uc_updiscounts} WHERE oid = %d", $arg1->order_id);
+		if ($data = db_fetch_object($result)) {
+		  $arg1->ptamt = $data->ptamt;
+		}
+		break;
+	  case 'delete':	
+		if (variable_get(USERPOINTS_DISCOUNT,1) != 0 && strtolower($order->payment_method) != 'points') {
+		$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),
-					);
+		  $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);
-					db_query("DELETE FROM {uc_order_line_items} WHERE order_id=%d AND type='ptdiscount'", $arg1->order_id);
-				}
-			}
-			break;
+		  userpoints_userpointsapi($params);
+		  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);
+		}
+	  }
+	  break;
   }
 }
Index: uc_userpoints_payment.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/userpoints_ubercart/uc_userpoints_payment.module,v
retrieving revision 1.6.2.2
diff -u -p -r1.6.2.2 uc_userpoints_payment.module
--- uc_userpoints_payment.module	14 May 2009 04:18:27 -0000	1.6.2.2
+++ uc_userpoints_payment.module	18 May 2009 20:44:15 -0000
@@ -1,279 +1,301 @@
-<?php
-
-//$Id: uc_userpoints_payment.module,v 1.6.2.2 2009/05/14 04:18:27 smokris Exp $
-
-define('USERPOINTS_UC_PAYMENT',   'userpoints_ubercart_payment');
-define('USERPOINTS_DISPLAY',	    'userpoints_display');
-define('USERPOINTS_PAY_MODERATE',	'userpoints_pay_moderate');
-define('USERPOINTS_PAY_CATEGORY',	'userpoints_pay_category');
-
-function uc_userpoints_payment_help($path, $arg) {
-  switch ($path) {
-    case 'admin/modules#description':
-      $output = t('<strong>Userpoints Payment:</strong> Interfaces userpoints with Ubercart so users can make purchases with points.');
-      break;
-  }
-  return $output;
-}
-
-/**
- * Implementation of hook_userpoints api().
- */
-
-function uc_userpoints_payment_userpoints($op, $points = 0, $uid = 0, $event = '') {
-  switch($op) {
-    case 'setting':
-      if (module_exists('uc_cart') && module_exists('uc_payment')) {
-        $group = 'uc_userpoints_payment';
-        $form[$group] = array(
-          '#type' => 'fieldset',
-          '#collapsible' => TRUE,
-          '#collapsed' => TRUE,
-          '#title' => t('Ubercart Payment Options'),
-        );
-        $form[$group][USERPOINTS_UC_PAYMENT] = array(
-          '#type' => 'textfield',
-          '#title' => t('!Points used in payment (for every dollar)', userpoints_translation()),
-          '#default_value' => variable_get(USERPOINTS_UC_PAYMENT, 1),
-          '#size' => 5,
-          '#maxlength' => 5,
-        );
-        $form[$group][USERPOINTS_DISPLAY] = array(
-          '#type' => 'select',
-          '#title' => t('Display Dollars, !Points, or both.', userpoints_translation()),
-          '#default_value' =>  variable_get(USERPOINTS_DISPLAY,2),
-          '#options' => array(1 => t('Dollars'), 2 => t('Both'), 3 => t('Points')),
-        );
-        $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')),
-        );
-		$form[$group][USERPOINTS_PAY_CATEGORY] = array(
-		  '#type' => 'select',
-		  '#title' => t('Payment Category'),
-		  '#default_value' => variable_get(USERPOINTS_PAY_CATEGORY, NULL),
-		  '#options' => userpoints_get_categories(),
-		  '#description' => t('Category to assign awarded !points.', userpoints_translation()),
-		);
-      }
-      return $form;
-      break;
-  }
-}
-
-/**
- * Implementation of hook_noedapi().
- */
-
-function uc_userpoints_payment_nodeapi(&$node, $op, $arg3, $arg4) {
-  switch ($op){
-    case 'view':
-		if ($node->type=='product') {
-			$dispStyle = variable_get(USERPOINTS_DISPLAY,2);
-			//disp 1=dollars, 2=both, 3=points
-
-			if (module_exists('uc_userpoints_product')) {
-			  $points = db_result(db_query("SELECT points FROM {uc_userpoints_products} WHERE nid = %d", $node->nid));
-			  if ($points > 0) {
-			    $dispStyle = 1; // you can't buy a point product with points
-			  }
-			}
-	
-			$pointExchange = intval(variable_get(USERPOINTS_UC_PAYMENT, 1));
-			$pointCost = intval(round($node->sell_price) * $pointExchange);
-			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().
- */
- 
-function uc_userpoints_payment_payment_method() {
-  global $user;
-  $curUserId = $user->uid;
-
-  //how many points does this user have?
-  $curUserPoints = userpoints_get_current_points($uid = $curUserId, $tid = variable_get(USERPOINTS_PAY_CATEGORY, NULL));
-  $maxdisc = $curUserPoints / intval(variable_get(USERPOINTS_UC_PAYMENT, 1));
-
-  // make sure they have points in the first place
-  if ($curUserPoints > 0 || request_uri() != '/cart/checkout') {
-    $methods[]	= array(
-      'id'	=> 'points',
-      'name'	=> t('!Points', userpoints_translation()),
-      'title'	=> t('!Points (Total available via !Points: ' . uc_currency_format($maxdisc) . ')', userpoints_translation()),
-      'desc'	=> t('Pay by !Points.', userpoints_translation()),
-      'callback'=> 'uc_payment_method_points',
-      'weight'	=> 4,
-      'checkout'=> TRUE,
-      'backend'	=> TRUE,
-    );
-
-    return $methods;
-  }
-}
-
-/**
- * Implementation of hook_order().
- */
- 
-function uc_userpoints_payment_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;
-	  }
-}
-
-/*******************************************************************************
- * Callback Functions, Forms, and Tables
- ******************************************************************************/
-
-function uc_payment_method_points($op, &$arg1) {
-  global $user;
-  $curUserId	 = $user->uid;
-  $curUserPoints = intval(userpoints_get_current_points($uid = $curUserId, $tid = variable_get(USERPOINTS_PAY_CATEGORY, NULL)));
-  $pointExchange = intval(variable_get(USERPOINTS_UC_PAYMENT, 1));
-
-  switch ($op) {
-		case 'cart-details':
-			/**
-			 *  Eventually I want to hide the points discount if its enabled.
-			 **/
-			return;
-			break;
-		case 'cart-process':
-			//this would be verification that should be covered else where if possible
-			// check thier points and make sure they have enough to pay for this purchase
-			//order information
-			$order_id 	  = $arg1->order_id;
-			
-			$items = uc_cart_get_contents();
-			foreach ($items as $cartitem) {
-			  $cartbalance += $cartitem->price*$cartitem->qty;
-			}
-			$shipresult		= db_query("select amount from {uc_order_line_items} where `type`='shipping'and  order_id = %d", $order_id);
-			$shipitem 	  = db_fetch_array($shipresult);
-			$orderTotal   = $shipitem['amount']+$cartbalance;
-			$pointsNeeded = intval((round($orderTotal) * $pointExchange));
-
-			if (($curUserPoints < $pointsNeeded && $curUserId != 0)) {
-				drupal_set_message('You do not have enough points to complete this purchase.  You have ' . $curUserPoints . ' but you need ' . $pointsNeeded . '.  Please select another payment method.', '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/settings/userpoints').'.  This area is for enabling points as payment method only.') .'</div>',
-		);
-			return $form;
-			break;
-  }
-}
-
-function uc_userpoints_payment_payment($order) {
-  global $user;
-  $curUserId	= $user->uid;
-  $pointExch	= intval(variable_get(USERPOINTS_UC_PAYMENT, 1));
-  $orderTotal	= $order->order_total;
-  $points		= intval(((round($orderTotal) * $pointExch) * (-1)));
-  $description	= 'User made a purchase and paid with points (Ubercart Order ' . $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();
-  }
-
-  if ($order->payment_method == 'points') {  
-		$params = array (
-			'tid' => variable_get(USERPOINTS_PAY_CATEGORY, NULL),
-			'uid' => $curUserId,
-			'points' => $points,
-			'operation' => 'delete',
-			'description' => $description,
-			'entity_id' => $order->order_id,
-			'entity_type' => 'Ubercart Payment',
-			'moderate' => variable_get(USERPOINTS_PAY_MODERATE, 0),
-		);
-		userpoints_userpointsapi($params);
-		uc_payment_enter($order->order_id, 'points', $orderTotal, $curUserId, NULL, $description);
-		db_query("insert into {uc_up_payment_log} (uid, oid, points) values(%d, %d, %d)",$curUserId, $order->order_id, $points);
-		uc_order_update_status($order->order_id, 'payment_received');
-  }
-}
-
-function uc_userpoints_payment_refund($order) {
-  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);
-  $orderTotal	= $order->order_total;
-  
-  if ($result != FALSE) {
-    $pointinfo = db_fetch_object($result);
-    $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' => 'insert',
-			'description' => $description,
-			'entity_id' => $oid,
-			'entity_type' => 'Ubercart Refund',
-			'moderate' => variable_get(USERPOINTS_PAY_MODERATE, 0),
-		);
-		userpoints_userpointsapi($params);
-  }
-}
+<?php
+//$Id: uc_userpoints_payment.module,v 1.6.2.2 2009/05/14 04:18:27 smokris Exp $
+
+define('USERPOINTS_UC_PAYMENT',   'userpoints_ubercart_payment');
+define('USERPOINTS_DISPLAY',	    'userpoints_display');
+define('USERPOINTS_PAY_MODERATE',	'userpoints_pay_moderate');
+define('USERPOINTS_PAY_CATEGORY',	'userpoints_pay_category');
+
+
+/**
+ * Implementation of hook_help
+ */
+function uc_userpoints_payment_help($path, $arg) {
+  switch ($path) {
+    case 'admin/modules#description':
+      $output = t('<strong>Userpoints Payment:</strong> Interfaces userpoints with Ubercart so users can make purchases with points.');
+      break;
+  }
+  return $output;
+}
+
+/**
+ * Implementation of hook_userpoints
+ * @param $op operation
+ * @param $points points to pass in
+ * @param $uid user id
+ * @param $event text
+ */
+function uc_userpoints_payment_userpoints($op, $points = 0, $uid = 0, $event = '') {
+  switch($op) {
+    case 'setting':
+      if (module_exists('uc_cart') && module_exists('uc_payment')) {
+        $group = 'uc_userpoints_payment';
+        $form[$group] = array(
+          '#type' => 'fieldset',
+          '#collapsible' => TRUE,
+          '#collapsed' => TRUE,
+          '#title' => t('Ubercart Payment Options'),
+        );
+        $form[$group][USERPOINTS_UC_PAYMENT] = array(
+          '#type' => 'textfield',
+          '#title' => t('!Points used in payment (for every dollar)', userpoints_translation()),
+          '#default_value' => variable_get(USERPOINTS_UC_PAYMENT, 1),
+          '#size' => 5,
+          '#maxlength' => 5,
+        );
+        $form[$group][USERPOINTS_DISPLAY] = array(
+          '#type' => 'select',
+          '#title' => t('Display Dollars, !Points, or both.', userpoints_translation()),
+          '#default_value' =>  variable_get(USERPOINTS_DISPLAY,2),
+          '#options' => array(1 => t('Dollars'), 2 => t('Both'), 3 => t('Points')),
+        );
+        $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')),
+        );
+		$form[$group][USERPOINTS_PAY_CATEGORY] = array(
+		  '#type' => 'select',
+		  '#title' => t('Payment Category'),
+		  '#default_value' => variable_get(USERPOINTS_PAY_CATEGORY, NULL),
+		  '#options' => userpoints_get_categories(),
+		  '#description' => t('Category to assign awarded !points.', userpoints_translation()),
+		);
+      }
+      return $form;
+      break;
+  }
+}
+
+/**
+ * Implementation of hook_noedapi().
+ * @param $node referenced node object
+ * @param $op operation
+ * @param $arg3 argument 3
+ * @param $arg4 argument 4
+ */
+function uc_userpoints_payment_nodeapi(&$node, $op, $arg3, $arg4) {
+  switch ($op) {
+    case 'view':
+	  if ($node->type=='product') {
+	    $dispStyle = variable_get(USERPOINTS_DISPLAY,2);
+		//disp 1=dollars, 2=both, 3=points
+
+		if (module_exists('uc_userpoints_product')) {
+		  $points = db_result(db_query("SELECT points FROM {uc_userpoints_products} WHERE nid = %d", $node->nid));
+		  if ($points > 0) {
+		    $dispStyle = 1; // you can't buy a point product with points
+		  }
+		}
+	
+		$pointExchange = intval(variable_get(USERPOINTS_UC_PAYMENT, 1));
+		$pointCost = intval(round($node->sell_price) * $pointExchange);
+		switch($dispStyle) {
+		  case 1: 
+		    //do nothing since we only want dollars
+			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().
+ */
+function uc_userpoints_payment_payment_method() {
+  global $user;
+  $curUserId = $user->uid;
+
+  //how many points does this user have?
+  $curUserPoints = userpoints_get_current_points($uid = $curUserId, $tid = variable_get(USERPOINTS_PAY_CATEGORY, NULL));
+  $maxdisc = $curUserPoints / intval(variable_get(USERPOINTS_UC_PAYMENT, 1));
+
+  // make sure they have points in the first place
+  if ($curUserPoints > 0 || request_uri() != '/cart/checkout') {
+    $methods[]	= array(
+      'id'	=> 'points',
+      'name'	=> t('!Points', userpoints_translation()),
+      'title'	=> t('!Points (Total available via !Points: ' . uc_currency_format($maxdisc) . ')', userpoints_translation()),
+      'desc'	=> t('Pay by !Points.', userpoints_translation()),
+      'callback'=> 'uc_payment_method_points',
+      'weight'	=> 4,
+      'checkout'=> TRUE,
+      'backend'	=> TRUE,
+    );
+
+    return $methods;
+  }
+}
+
+/**
+ * Implementation of hook_order().
+ */
+function uc_userpoints_payment_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') {
+	    $good = uc_userpoints_payment_payment($order);
+		if (!$good) {
+		  return array(
+		  	array(
+			  'pass' => FALSE,
+			  'message' => t('An error has occurred during payment.  Please contact us to ensure your order has submitted.')
+			)
+		  );
+		}
+	  }
+	  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;
+  }
+}
+
+/**
+ * Callback Functions, Forms, and Tables
+ */
+
+/**
+ * Payment Method callback
+ * @param $op operation
+ * @param $arg1 argument 1, passed by reference
+ * @return boolean Whether the order should be passed through or not
+ */
+function uc_payment_method_points($op, &$arg1) {
+  global $user;
+  $curUserId = $user->uid;
+  $curUserPoints = intval(userpoints_get_current_points($uid = $curUserId, $tid = variable_get(USERPOINTS_PAY_CATEGORY, NULL)));
+  $pointExchange = intval(variable_get(USERPOINTS_UC_PAYMENT, 1));
+
+  switch ($op) {
+	case 'cart-details':
+	  //FIXME: Eventually I want to hide the points discount if its enabled.
+	  return;
+	  break;
+	case 'cart-process':
+	  /**
+	   * This would be verification that should be covered elsewhere if possible
+	   * check their points and make sure they have enough to pay for this
+	   * purchase order information
+	   */
+	  $order_id = $arg1->order_id;
+			
+	  $items = uc_cart_get_contents();
+	  foreach ($items as $cartitem) {
+	    $cartbalance += $cartitem->price*$cartitem->qty;
+	  }
+	  $shipresult = db_query("select amount from {uc_order_line_items} where `type`='shipping'and  order_id = %d", $order_id);
+	  $shipitem  = db_fetch_array($shipresult);
+	  $orderTotal = $shipitem['amount']+$cartbalance;
+	  $pointsNeeded = intval((round($orderTotal) * $pointExchange));
+
+	  if (($curUserPoints < $pointsNeeded && $curUserId != 0)) {
+	  drupal_set_message('You do not have enough points to complete this purchase.  You have ' . $curUserPoints . ' but you need ' . $pointsNeeded . '.  Please select another payment method.', 'error');
+	  return FALSE;
+	  }
+	  else {
+		return TRUE;
+	  }
+	  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;
+  }
+}
+
+/**
+ * Payment callback
+ * @param $order order
+ */
+function uc_userpoints_payment_payment($order) {
+  global $user;
+  $curUserId = $user->uid;
+  $pointExch = intval(variable_get(USERPOINTS_UC_PAYMENT, 1));
+  $orderTotal = $order->order_total;
+  $points = intval(((round($orderTotal) * $pointExch) * (-1)));
+  $description = 'User made a purchase and paid with points (Ubercart Order ' . $order->order_id . ')';
+
+  if ($order === FALSE || uc_order_status_data($order->order_status, 'state') != 'in_checkout') {
+	return FALSE;
+  }
+
+  if ($order->payment_method == 'points') {  
+    $params = array (
+	  'tid' => variable_get(USERPOINTS_PAY_CATEGORY, NULL),
+	  'uid' => $curUserId,
+	  'points' => $points,
+	  'operation' => 'delete',
+	  'description' => $description,
+	  'entity_id' => $order->order_id,
+	  'entity_type' => 'Ubercart Payment',
+	  'moderate' => variable_get(USERPOINTS_PAY_MODERATE, 0),
+	);
+	userpoints_userpointsapi($params);
+	uc_payment_enter($order->order_id, 'points', $orderTotal, $curUserId, NULL, $description);
+	db_query("insert into {uc_up_payment_log} (uid, oid, points) values(%d, %d, %d)",$curUserId, $order->order_id, $points);
+	uc_order_update_status($order->order_id, 'payment_received');
+  }
+}
+
+/**
+ * Payment callback for refunding points
+ * @param $order the order
+ */
+function uc_userpoints_payment_refund($order) {
+  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);
+  $orderTotal = $order->order_total;
+  
+  if ($result != FALSE) {
+    $pointinfo = db_fetch_object($result);
+    $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' => 'insert',
+	  'description' => $description,
+	  'entity_id' => $oid,
+	  'entity_type' => 'Ubercart Refund',
+	  'moderate' => variable_get(USERPOINTS_PAY_MODERATE, 0),
+	);
+	userpoints_userpointsapi($params);
+  }
+}
Index: uc_userpoints_product.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/userpoints_ubercart/uc_userpoints_product.module,v
retrieving revision 1.5.2.2
diff -u -p -r1.5.2.2 uc_userpoints_product.module
--- uc_userpoints_product.module	14 May 2009 04:18:27 -0000	1.5.2.2
+++ uc_userpoints_product.module	18 May 2009 20:44:15 -0000
@@ -1,192 +1,209 @@
 <?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');
 
+/**
+ * Implementation of hook_help
+ */
 function uc_userpoints_product_help($path, $arg) {
-    switch ($path) {
-      case 'admin/modules#description':
-        $output = t('<strong>Ubercart Userpoints Product:</strong> Interfaces userpoints with Ubercart, so users can purchase points with products.');
+  switch ($path) {
+    case 'admin/modules#description':
+      $output = t('<strong>Ubercart Userpoints Product:</strong> Interfaces userpoints with Ubercart, so users can purchase points with products.');
       break;
-    }
-    return $output;
+  }
+  return $output;
 }
 
-
+/**
+ * Implementation of hook_userpoints
+ * @param $op operation
+ * @param $params parameters to pass in
+ * @return array form api array
+ */
 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('Category to assign awarded !points.', 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('Category to assign awarded !points.', userpoints_translation()),
+	    );
+     }
+     return $form;
+	 break;
+  }
 }
 
-
+/**
+* Implementation of hook_product_feature().
+*/
 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;
+  $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
+ * @param $node 
+ * @param $feature
+ * @return array $form array
+ */
 function uc_userpoints_product_feature_form($node, $feature) {
-	$points = 0;
+  $points = 0;
+  $nid = arg(1);
 
-	$nid = arg(1);
+  $res = db_query("SELECT * FROM {uc_userpoints_products} ucup, {uc_product_features} ucpf WHERE ucup.pfid = ucpf.pfid AND ucup.nid = %d",$nid);
+  while ($pf = db_fetch_object($res)) {
+    $points = $pf->points;
+  }
 
-	$res = db_query("SELECT * FROM {uc_userpoints_products} ucup, {uc_product_features} ucpf WHERE ucup.pfid = ucpf.pfid AND ucup.nid = %d",$nid);
-	while ($pf = db_fetch_object($res)) {
-	  $points = $pf->points;
-	}
-
-	$form['nid'] = array(
-		'#type' => 'value',
-		'#value' => $node->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,
-	);
-	return uc_product_feature_form($form);
+  $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,
+  );
+  return uc_product_feature_form($form);
 }
 
-
+/**
+ * uc_userpoints_product_feature_form validate callback
+ * @param $form the form
+ * @param &$form_shate form_state passed by reference
+ */
 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');
   }
 }
 
-
 /**
-* Submit the form
-*/
+ * uc_userpoints_product_feature_form submit callback
+ * @param $form the form
+ * @param &$form_state form_state passed by reference
+ */
 function uc_userpoints_product_feature_form_submit($form, &$form_state) {
-	$data = array(
-		'pfid' => $form_state['values']['pfid'],
-		'nid' => $form_state['values']['nid'],
-		'points' => $form_state['values']['points'],
-		'fid' => 'userpoints',
-		'description' => 'Product is now worth '.$form_state['values']['points'].' '.variable_get(USERPOINTS_TRANS_LCPOINTS, 'points'),
-	);
+  $data = array(
+    'pfid' => $form_state['values']['pfid'],
+	'nid' => $form_state['values']['nid'],
+	'points' => $form_state['values']['points'],
+	'fid' => 'userpoints',
+	'description' => 'Product is now worth '.$form_state['values']['points'].' '.variable_get(USERPOINTS_TRANS_LCPOINTS, 'points'),
+  );
 	
-	$ret = uc_product_feature_save($data);
-	if (empty($data['pfid'])) {
-		$pf = db_fetch_object(db_query("select pfid from {uc_userpoints_products} where nid = %d and fid = %d",$data['nid'],$data['fid']));
-		$data['pfid'] = $pf->pfid;
+  $ret = uc_product_feature_save($data);
+  if (empty($data['pfid'])) {
+	$pf = db_fetch_object(db_query("select pfid from {uc_userpoints_products} where nid = %d and fid = %d",$data['nid'],$data['fid']));
+	$data['pfid'] = $pf->pfid;
 
-		db_query("INSERT INTO {uc_userpoints_products} (pfid,nid,points) VALUES (%d,%d,%d)",$data['pfid'],$data['nid'],$data['points']);
-	}
-	else {
-		db_query("UPDATE {uc_userpoints_products} SET points = %d WHERE nid = %d AND pfid = %d",$data['points'],$data['nid'],$data['pfid']);
-	}
+	db_query("INSERT INTO {uc_userpoints_products} (pfid,nid,points) VALUES (%d,%d,%d)",$data['pfid'],$data['nid'],$data['points']);
+  }
+  else {
+    db_query("UPDATE {uc_userpoints_products} SET points = %d WHERE nid = %d AND pfid = %d",$data['points'],$data['nid'],$data['pfid']);
+  }
 
-	$form_state['redirect'] = $ret;
+  $form_state['redirect'] = $ret;
 }
 
-
 /**
- * Feature settings
+ * Implementation of hook_feature_settings
  */
 function uc_userpoints_product_feature_settings() {
 	// Nothing yet.
 }
 
-
 /**
- * Product Feature delete function
+ * Implementation of hook_feature_delete
+ * @param $feature the feature to be deleted
  */
 function uc_userpoints_product_feature_delete($feature) {
-		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_query("DELETE FROM {uc_userpoints_products} WHERE pfid = %d",$feature['pfid']);
+  db_query("DELETE FROM {uc_product_features} WHERE pfid = %d", $feature['pfid']);
 }
 
-
 /**
  * Implementation of hook_order();
+ * @param $op the operation
+ * @param $order the order
+ * @param $status the order status
  */
 function uc_userpoints_product_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) {
-				$totalPoints = 0;
-				foreach ($order->products as $product) {
-					$points = db_result(db_query("SELECT sum(points) FROM {uc_userpoints_products} WHERE nid = %d", $product->nid));
-					if ($points > 0) {
-						//drupal_set_message($product->title.' has '.$points.' '.variable_get(USERPOINTS_TRANS_LCPOINTS, 'points').' attached');
-						$totalPoints += ($product->qty * $points); // Make sure we account for multiple qty of the Points product
-					}
-				}
-
-			$params = array (
-				'tid' => variable_get(USERPOINTS_PRODUCT_CATEGORY, 0),
-				'uid' => $order->uid,
-				'points' => $totalPoints,
-				'operation' => 'add',
-				'description' => t('A user purchased a product containing points for a total of ' .$totalPoints.' '. variable_get(USERPOINTS_TRANS_LCPOINTS, 'points')),
-				'entity_id' => $order->oid,
-				'entity_type' => 'Ubercart Transaction',
-				'moderate' => variable_get(USERPOINTS_PRODUCT_MODERATE, 0),
-			);
-
-		 userpoints_userpointsapi($params);
-		 uc_order_comment_save($order->order_id, 0, t('User earned '.$totalPoints.' points!'), 'admin');
-		}
-	break;
-	}
+  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) {
+		$totalPoints = 0;
+		foreach ($order->products as $product) {
+		  $points = db_result(db_query("SELECT sum(points) FROM {uc_userpoints_products} WHERE nid = %d", $product->nid));
+		  if ($points > 0) {
+		    $totalPoints += ($product->qty * $points); // Make sure we account for multiple qty of the Points product
+		  }
+	    }
+
+		$params = array (
+		  'tid' => variable_get(USERPOINTS_PRODUCT_CATEGORY, 0),
+		  'uid' => $order->uid,
+		  'points' => $totalPoints,
+		  'operation' => 'add',
+		  'description' => t('A user purchased a product containing points for a total of ' .$totalPoints.' '. variable_get(USERPOINTS_TRANS_LCPOINTS, 'points')),
+		  'entity_id' => $order->oid,
+		  'entity_type' => 'Ubercart Transaction',
+		  'moderate' => variable_get(USERPOINTS_PRODUCT_MODERATE, 0),
+		);
+
+		userpoints_userpointsapi($params);
+		uc_order_comment_save($order->order_id, 0, t('User earned '.$totalPoints.' points!'), 'admin');
+	  }
+	  break;
+  }
 }
 
 /**
-* Check and make sure the user isn't trying to buy points with points.
-*  @todo: Make this configurable?
-*/
+ * Implementation of hook_form_alter
+ * Check and make sure that the user is not trying to buy points with points.
+ * @TODO Make this confiurable?
+ * @param &$form form passed by reference
+ * @param &$form_state form_state passed by reference
+ * @param $form_id the form id
+ */
 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');
     }
@@ -204,15 +221,14 @@ 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();
@@ -220,14 +236,12 @@ function uc_userpoints_find_points_produ
 
   foreach ($order->products as $product) {
     $nids[] = check_plain($product->nid);
-        //dsm('Nid: '.$product->nid);
   }
 
   $pointsproducts = array();
   $result = db_query("SELECT * FROM {uc_userpoints_products} WHERE nid IN (". implode(", ", $nids) .")");
   while ($pntproduct = db_fetch_object($result)) {
     $pointsproducts[] = $pntproduct;
-        //dsm('Matched nid: '.$pntproduct->nid);
   }
 
   return $pointsproducts;
Index: uc_userpoints_seller.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/userpoints_ubercart/uc_userpoints_seller.module,v
retrieving revision 1.5.2.1
diff -u -p -r1.5.2.1 uc_userpoints_seller.module
--- uc_userpoints_seller.module	14 May 2009 02:47:13 -0000	1.5.2.1
+++ uc_userpoints_seller.module	18 May 2009 20:44:15 -0000
@@ -1,11 +1,13 @@
 <?php
+//$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');
 
-
-/* Begin Seller History Reporting */
-
+/**
+ * Implementation of hook_menu
+ */
 function uc_userpoints_seller_menu() {
   $items = array();
 
@@ -28,6 +30,8 @@ function uc_userpoints_seller_menu() {
   return $items;
 }
 
+/* Begin Seller History */
+
 /**
  * Returns the sortable table listing of a sellers orders.
  *
@@ -69,6 +73,12 @@ function uc_seller_history_user($usr) {
   return $output;
 }
 
+/**
+ * Returns table data with all of seller history
+ *
+ * @return $output
+ * 	output
+ */
 function uc_seller_history_all() {
   drupal_set_title(t('Sales Points History'));
 
@@ -102,11 +112,16 @@ function uc_seller_history_all() {
   return $output;
 }
 
-
 /* End Seller History */
 
-
-
+/**
+ * Implementation of hook_userpoints
+ * @param $op operation
+ * @param $points points
+ * @param $uid user id
+ * @param $event string
+ * @return $form form
+ */
 function uc_userpoints_seller_userpoints($op, $points = 0, $uid = 0, $event = '') {
   switch($op) {
     case 'setting':
@@ -144,8 +159,11 @@ function uc_userpoints_seller_userpoints
   }
 }
 
+/**
+ * Conditional Actions Callbacks and Forms
+ */
 
-/*
+/**
  * Implementation of hook_ca_action
  */
 function uc_userpoints_seller_ca_action() {
@@ -166,37 +184,35 @@ function uc_userpoints_seller_ca_action(
   return $actions;
 }
 
-
-/* ************************************************************************* *
- *  Workflow-ng Action Callbacks and Forms                                   *
- * ************************************************************************* */
-
+/**
+ * Conditional Action callback to award points
+ * @param $order order
+ * @param $settings settings
+ */
 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);
+	  $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 . ')',
-//					'entity_id' => $order->order_id,
-//					'entity_type' => 'Ubercart Transaction',
-					'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 = '';
+	  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 = '';
     }
   }
 }
