Index: auction.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/ecommerce/contrib/auction/auction.module,v
retrieving revision 1.19.2.3.2.1.2.7
diff -u -r1.19.2.3.2.1.2.7 auction.module
--- auction.module	8 Feb 2007 06:46:22 -0000	1.19.2.3.2.1.2.7
+++ auction.module	12 Feb 2007 02:06:51 -0000
@@ -101,10 +101,15 @@
 
   if ($type == 'node' && user_access('access content') && $teaser && $node->ptype == 'auction') {
     if (time() > $node->expires) {
-      $links[] = '<span class="bid-link">'. t('Bidding closed') . '</span>';
+      $links['bid'] = array(
+                    'title' => t('Biding closed'),                    
+                    'attributes' => array('class' => 'bid-link'));
     }
     else {
-      $links[] = l(t('Bid now'), "node/$node->nid", array('title' => t('Place your bid for this item'), 'class' => 'bid-link'));
+      $links['bid'] = array(
+                    'title' => t('Bid now'),
+                    'href' => "node/$node->nid",
+                    'attributes' => array('title' => t('Place your bid for this item'), 'class' => 'bid-link'));
     }
   }
   return $links;
@@ -124,7 +129,7 @@
   }
 }
 
-function auction_productapi(&$node, $op, $a3 = null, $a4 = null) {
+function auction_productapi(&$node, $op, $a3 = null, $a4 = null) {    
 
   switch ($op) {
     /* Due to the way we have to build our node, we have to pass an array of values this module collects. */
@@ -157,7 +162,7 @@
       $buyer = db_result(db_query_range('SELECT uid FROM {ec_auction_bid} WHERE uid = %d ORDER BY created DESC', $user->uid, 0, 1));
       return (($buyer && $expired) ? true : false);
 
-    case 'form':
+    case 'form':     
       if (!$node->expires) {
         $node->expires = time() + (variable_get('auction_days', 1) * 24 * 60 * 60);
       }
@@ -196,10 +201,24 @@
     case 'delete':
       db_query('DELETE FROM {ec_product_auction} WHERE nid = %d', $node->nid);
       db_query('DELETE FROM {ec_auction_bid} WHERE nid = %d', $node->nid);
+      break;    
   }
 }
 
-function auction_page($nid, $action) {
+function auction_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {   
+   switch ($op) {
+   	 case 'view':
+   	   // $a3 is teaser, $a4 is page attr. in $op='view' case
+	   	 global $user;
+	   	 if ($a3) { return $node; }	   	   
+	   	 $form = drupal_get_form('product_auction_view_form',$node,$user);
+	   	 $node->content['body']['#value'] .= $form; // it appends rendered form to node body (node->body go through filters)   	 
+	   	 break;   	 
+   }   
+}
+
+
+function auction_page($nid, $action) {  
   $edit = $_POST['edit'];
   $op   = $_POST['op'];
 
@@ -211,16 +230,7 @@
 
   if (user_access('place bids')) {
     switch ($op ? $op : $action) {
-      case t('Confirm bid'):
-        if (auction_bid_validate($edit)) {
-          auction_bid_save($edit);
-          drupal_goto('node/'. $edit['nid']);
-        }
-        else {
-          $output = auction_bid_form($edit);
-        }
-        break;
-
+      //case t('Confirm bid') control of this part moved to auction_bid_form_validate & submit
       case t('Pay for your items'):
         drupal_goto('cart/'. $edit['nid']. '/add');
         break;
@@ -231,13 +241,13 @@
         }
         else {
           $edit['nid'] = $nid;
-          $output = auction_bid_form($edit);
+          $output = drupal_get_form('auction_bid_form',$edit);
         }
         break;
 
       default:
         $edit['nid'] = $nid;
-        $output = auction_bid_form($edit);
+        $output =  drupal_get_form('auction_bid_form',$edit);
         break;
     }
     return $output;
@@ -286,17 +296,17 @@
  * But between you and me, I am suspicious of the logic.
  *
  */
-function auction_item_paid_for($nid) {
+function auction_item_paid_for($nid) {  
   global $user;
 
   $result = db_query('SELECT DISTINCT nid FROM {ec_auction_bid} WHERE nid = %d ORDER BY nid', $nid);
-  if (!$result) {
+  if ($result) { // NOTE: weird, there was (!$result) before, I've missed something?
     while ($data = db_fetch_object($result)) {
       $item = db_fetch_object(db_query('SELECT nid, bid, uid FROM {ec_auction_bid} WHERE nid = %d ORDER BY created DESC', $data->nid));
       if ($item->uid == $user->uid) {
         $nids[] = $item->nid;
       }
-    }
+    }   
     return db_result(db_query('SELECT COUNT(t.txnid) FROM {ec_transaction_product} tp, {ec_transaction} t WHERE t.payment_status = %d AND t.txnid = tp.txnid AND t.uid = %d AND nid IN (%s)', payment_get_status_id('completed'), $user->uid, implode(',', $nids)));
   }
   else {
@@ -332,7 +342,8 @@
 
   if ($rows) {
     $output = theme('table', $header, $rows);
-  }
+  }    
+  $output.= l(t('Back'),'node/'.$nid);  
   return $output;
 }
 
@@ -341,15 +352,13 @@
  * is a number and is higher than the previous bid.
  *
  */
-function auction_bid_validate($edit) {
+function auction_bid_form_validate($form_id,$form_values) {  
+  if (isset($form_values['bid'])) {
 
-  $errors = array();
-  if (isset($edit['bid'])) {
-
-    if (is_numeric($edit['bid'])) {
-      if ($edit['price']) {
-        if ($edit['bid'] <= $edit['price']) {
-          $errors['bid'] = t('You must bid more than %current-price.', array('%current-price' => payment_format($edit['price'])));
+    if (is_numeric($form_values['bid'])) {
+      if ($form_values['price']) {
+        if ($form_values['bid'] <= $form_values['price']) {
+          $errors['bid'] = t('You must bid more than %current-price.', array('%current-price' => payment_format($form_values['price'])));
         }
       }
       else {
@@ -362,8 +371,12 @@
   }
   foreach ($errors as $name => $message) {
     form_set_error($name, $message);
-  }
-  return count($errors) == 0;
+  }  
+}
+
+function auction_bid_form_submit($form_id,$form_values) {  
+  auction_bid_save($form_values);
+  drupal_goto('node/'. $form_values['nid']);
 }
 
 function auction_bid_save($edit) {
@@ -380,7 +393,7 @@
  *   Object. A replica of the current node for editing.
  */
 function auction_bid_form($edit) {
-  $product = node_load($edit['nid']);
+  $product = node_load($edit['nid']);  
 
   if (time() > $product->expires) {
     drupal_set_message(t('This auction has ended.'));
@@ -412,7 +425,7 @@
     '#type' => 'submit',
     '#value' => t('Confirm bid'),
   );
-  return drupal_get_form('auction_bid_form', $form);
+  return $form;
 }
 
 /**
@@ -439,27 +452,46 @@
   return $output;
 }
 
-/**
+/*
  * Called via product_view() which is an implementation of hook_view().
  * Generates the HTML elements required to view an auction. Contrary to
  * its name, do not retheme this function. Please theme theme_product_auction_form()
  * instead.
+ * NOTE: product_view() missing since e-commerce v.3, use of hook_nodeapi:view is supposed
+ */ 
+// function product_auction_view($node, $teaser = 0, $page = 0) control moved to hook_nodeapi:view
+
+/**
+ * Formats the HTML elements that you see when you _View_ an auction.
+ * You can override this function. Refer to Theming at http://drupal.org/node/55126.
+ * Called indirectly by theme_product_auction_view()
+ *
+ * @param $form
+ *   A formapi array which contains the form elements (eg. the 'Place Bid'
+ *   submit element). $form['theme'] contains the non-form data.
  *
- * @param $node
- *   Object. The node being displayed.
- * @param $tease
- *   Boolean. Whether we are to generate a "teaser" or summary of the node, rather than
- *   display the whole thing.
- * @param $page
- *   Boolean. Whether the node is being displayed as a standalone page. If this is TRUE,
- *   the node title should not be displayed, as it will be printed automatically by the
- *   theme system. Also, the module may choose to alter the default breadcrumb trail in this case.
  */
-function theme_product_auction_view($node, $teaser = 0, $page = 0) {
+function theme_product_auction_view_form($form) {
+  
+  drupal_set_title(t('Bidding History'));
+  $output = '<p class="auction-message">'. $form['theme']['#message'] .'</p>';
 
-  global $user;
-  if ($teaser) { return $node; }
+  $header = array();
+  $rows[] = array(t('Time left:'), format_interval($form['theme']['#expire_time'] - time()));
+  $rows[] = array(t('Current bid:'), $form['theme']['#high_bid_amount']);
+  $rows[] = array(t('High bidder:'), $form['theme']['#high_bid_name']);  
+  $bid_history = l(t('%num-bids',array('%num-bids' => format_plural($form['theme']['#high_bid']['count'], '1 bid', '@count bids'))),'auction/'. $form['theme']['#nid'] .'/bid/history',array(),NULL,NULL,FALSE,TRUE);
+  //WTF? $bid_history = t('(<a href="%bid-history-link">%num-bids</a>)', array('%bid-history-link' => url('auction/'. $form['theme']['#nid'] .'/bid/history'), '%num-bids' => format_plural($form['theme']['#high_bid']['count'], '1 bid', '@count bids')));
+  $rows[] = array(t('Bid history'), '( '.$bid_history.' )');
+  if ($form['theme']['#form']) {$rows[] = array(NULL,drupal_render($form['submit'])); }
 
+  $output .= theme('table', $header, $rows);
+  $output .= drupal_render($form);
+  return $output;
+}
+
+
+function product_auction_view_form($node,$user){
   /* Build some variables for theming. */
   $high_bid = auction_bid_current($node->nid);
   $form['theme'] = array();
@@ -516,37 +548,6 @@
       $form['nid'] =  array('#type' => 'hidden', '#value' => $node->nid);
       $form['#action'] = url("auction/checkout");
     }
-  }
-  $output = '<h3>'. check_plain($node->title) .'</h3>';
-  $output .= drupal_get_form('product_auction_form', $form);
-  $node->body = $output . $node->body;
-  return $node;
-}
-
-/**
- * Formats the HTML elements that you see when you _View_ an auction.
- * You can override this function. Refer to Theming at http://drupal.org/node/55126.
- * Called indirectly by theme_product_auction_view()
- *
- * @param $form
- *   A formapi array which contains the form elements (eg. the 'Place Bid'
- *   submit element). $form['theme'] contains the non-form data.
- *
- */
-function theme_product_auction_form($form) {
-
-  drupal_set_title(t('Bidding History'));
-  $output = '<p class="auction-message">'. $form['theme']['#message'] .'</p>';
-
-  $header = array();
-  $rows[] = array(t('Time left:'), format_interval($form['theme']['#expire_time'] - time()));
-  $rows[] = array(t('Current bid:'), $form['theme']['#high_bid_amount']);
-  $rows[] = array(t('High bidder:'), $form['theme']['#high_bid_name']);
-  $bid_history = t('(<a href="%bid-history-link">%num-bids</a>)', array('%bid-history-link' => url('auction/'. $form['theme']['#nid'] .'/bid/history'), '%num-bids' => format_plural($form['theme']['#high_bid']['count'], '1 bid', '@count bids')));
-  $rows[] = array(t('Bid history'), $bid_history);
-  if ($form['theme']['#form']) {$rows[] = array(NULL,drupal_render($form['submit'])); }
-
-  $output .= theme('table', $header, $rows);
-  $output .= drupal_render($form);
-  return $output;
-}
+  }  
+  return $form;
+}
\ No newline at end of file
