--- sites/all/modules/uc_auction/uc_auction-broke.module	2008-10-03 13:36:23.000000000 -0700
+++ sites/all/modules/uc_auction/uc_auction.module	2008-10-06 09:35:54.000000000 -0700
@@ -1,5 +1,5 @@
 <?php
-// $Id: uc_auction.module,v 1.1.2.5 2008/10/03 20:36:23 garrettalbright Exp $
+// $Id$
 
 /**
  * @file
@@ -101,7 +101,6 @@ function uc_auction_perm() {
  */
 
 function uc_auction_form_alter(&$form, $form_state, $form_id) {
-//	drupal_set_message($form_id);
 	if ($form_id === 'product_node_form') {
 		// The product node editing form. Add options to auction-ize this item.
 		$is_auction = isset($form['#node']->uc_auction) || (!isset($form['#node']->nid) && variable_get('uc_auction_new_default', FALSE));
@@ -140,7 +139,7 @@ function uc_auction_form_alter(&$form, $
 	elseif (strpos($form_id, 'uc_product_add_to_cart_form') === 0) {
 		// The "Add to Cart" button.
 		if (!isset($form['#parameters'][2]->uc_auction)) {
-			// This isn't an auction. Return
+			// This isn't an auction. Return!
 			return;
 		}
 		global $user;
@@ -186,6 +185,7 @@ function uc_auction_nodeapi(&$node, $op,
 			}
 			else {
 				$expiry = NULL;
+				$sell = FALSE;
 			}
 		}
 		elseif ($op === 'insert' && $node->is_auction) {
@@ -198,29 +198,37 @@ function uc_auction_nodeapi(&$node, $op,
 			drupal_write_record('uc_auction', $record);
 		}
 		elseif ($op === 'update') {
-			if ($prev_expiry = db_result(db_query('SELECT expiry FROM {uc_auction} WHERE nid = %d', $node->nid))) {
-				// This is a previously-existing auction. Are we baleeting it?
-				if ($expiry !== NULL && $expiry != $prev_expiry) {
-					// This is a previously-existing auction with an updating expiry time.
+			// Did we do the validation above?
+			if ($sell !== NULL) {
+				if ($prev_expiry = db_result(db_query('SELECT expiry FROM {uc_auction} WHERE nid = %d', $node->nid))) {
+					// This is a previously-existing auction. Are we baleeting it?
+					if ($expiry !== NULL && $expiry != $prev_expiry) {
+						// This is a previously-existing auction with an updating expiry time.
+						$record = array(
+							'nid' => $node->nid,
+							'expiry' => $expiry,
+						);
+						drupal_write_record('uc_auction', $record, 'nid');
+					}
+					elseif ($expiry === NULL) {
+						// This is no longer an auction, so delete auction info.
+						$edon = node_load($node->nid);
+						db_query('DELETE FROM {uc_auction} WHERE nid = %d', $node->nid);
+						db_query('DELETE FROM {uc_auction_bids} WHERE nid = %d', $node->nid);
+						$edon->sell_price = $edon->uc_auction['start_price'];
+						unset($edon->uc_auction);
+						node_save($edon);
+					}
+				}
+				elseif ($expiry !== NULL) {
+					// This is a previously-existing product which is becoming an auction.
 					$record = array(
 						'nid' => $node->nid,
 						'expiry' => $expiry,
+						'start_price' => $sell,
 					);
-					drupal_write_record('uc_auction', $record, 'nid');
+					drupal_write_record('uc_auction', $record);
 				}
-				elseif ($expiry === NULL) {
-					// This is no longer an auction, so delete auction info.
-					db_query('DELETE FROM {uc_auction} WHERE nid = %d', $node->nid);
-				}
-			}
-			elseif ($expiry !== NULL) {
-				// This is a previously-existing product which is becoming an auction.
-				$record = array(
-					'nid' => $node->nid,
-					'expiry' => $expiry,
-					'start_price' => $sell,
-				);
-				drupal_write_record('uc_auction', $record);
 			}
 		}
 		elseif ($op === 'delete') {
@@ -231,29 +239,20 @@ function uc_auction_nodeapi(&$node, $op,
 		}
 		elseif ($op === 'load') {
 			global $user;
-//			$expiry = db_result(db_query('SELECT expiry FROM {uc_auction} WHERE nid = %d', $node->nid));
 			$rez = db_query('SELECT * FROM {uc_auction} WHERE nid = %d', $node->nid);
 			if ($items = db_fetch_array($rez)) {
 				$node->uc_auction = $items;
 				$node->uc_auction['bids'] = array();
-//			if ($expiry) {
-//				$node->uc_auction = array(
-//					'expiry' => $expiry,
-//					'bids' => array(),
-//				);
 				$rez = db_query('SELECT * FROM {uc_auction_bids} WHERE nid = %d ORDER BY time ASC', $node->nid);
 				while ($bid = db_fetch_array($rez)) {
 					$node->uc_auction['bids'][] = $bid;
 				}
 				$node->uc_auction['bid_count'] = count($node->uc_auction['bids']);
 				$last_bid = $node->uc_auction['bid_count'] ? $node->uc_auction['bids'][$node->uc_auction['bid_count'] - 1] : FALSE;
-//				$node->uc_auction['high_bidder'] = $last_bid ? $last_bid['uid'] : FALSE;
 				$node->uc_auction['min_bid'] = $node->sell_price + variable_get('uc_auction_min_increase', .5);
 			}
 		}
 		elseif ($op === 'view' && isset($node->uc_auction)) {
-//			var_dump($node->content); die();
-			$node->content['#attributes'] = array('class' => 'uc_auction');
 			unset($node->content['display_price']);
 			global $user;
 			$node->content['uc_auction'] = array(
@@ -813,20 +812,11 @@ function _uc_auction_mod_zero($big, $sma
  */
 
 function uc_auction_add_to_cart($nid, $qty, $data) {
-//	drupal_set_message('Hi, I\'m being called.');
 	$node = node_load($nid);
 	if (!isset($node->uc_auction)) {
 		// This isn't an auction item.
 		return;
 	}
-/*	if ($qty > 1 && variable_get('uc_auction_enforce_single', TRUE)) {
-		return array(
-			array(
-				'success' => FALSE,
-				'message' => t('You may only add one of any item which you have won via auction to your cart.'),
-			),
-		);
-	}*/
 	global $user;
 	return array(
 		array(
@@ -864,19 +854,9 @@ function uc_auction_order($op, &$arg1, $
 		// We'll lazily go ahead and dumb-update all of these. No harm if they're
 		// not actually auctioned products (and therefore not in the table).
 		db_query('UPDATE {uc_auction} SET purchased = 1 WHERE nid IN (%s)', implode(',', $nids));
-//		var_dump($arg1);die();
 	}
 }
 
-/**
- * Implementation of hook_cart_item() (an Ubercart hook).
- * http://www.ubercart.org/docs/api/hook_cart_item
- */
-
-//function uc_auction_cart_item($op, &$item) {
-//	if ($op === 'load') {
-//		$rez = db_query('SELEC
-
 // Token hooks /////////////////////////////////////////////////////////////////
 
 /**
@@ -914,4 +894,16 @@ function uc_auction_token_values($type, 
 			'formatted-price' => uc_currency_format($object->sell_price),
 		);
 	}
-}
\ No newline at end of file
+}
+
+// Views hooks /////////////////////////////////////////////////////////////////
+
+/**
+ * Implementation of hook_views_api()
+ */
+
+/*function uc_auction_views_api() {
+	return array(
+		'api' => 2,
+	);
+}*/
\ No newline at end of file
