? 668258.patch
Index: hotel_booking/hotel_booking.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/uc_hotel/hotel_booking/hotel_booking.module,v
retrieving revision 1.12
diff -u -p -r1.12 hotel_booking.module
--- hotel_booking/hotel_booking.module	17 Dec 2009 19:12:10 -0000	1.12
+++ hotel_booking/hotel_booking.module	31 Dec 2009 06:11:00 -0000
@@ -1123,6 +1123,8 @@ function hotel_booking_cart_pane() {
       'title' => t('Booking Details'),
       'weight' => -15,
       'body' => drupal_get_form('hotel_booking_details_pane_cart'),
+      'collapsible' => TRUE,
+      'collapsed'   => FALSE,
     );
     return $panes;
   }
@@ -1141,7 +1143,7 @@ function hotel_booking_checkout_pane() {
       $panes[] = array(
         'id'          => 'reward_membership',
         'callback'    => 'hotel_booking_rewards',
-        'title'       => t('Membership Information'),
+        'title'       => t('Reward Membership'),
         'weight'      => 6,
         'enabled'     => TRUE,
         'process'     => TRUE,
@@ -1233,43 +1235,7 @@ function hotel_booking_pane_rewards($op,
 
 
 /**
- * Callbacks for checkout pane
- */
-function hotel_booking_rewards($op, &$arg1, $arg2) {
-  switch ($op) {
-    case 'view':
-      $description = t('If you have a reward membership card, please enter the number here.');
-      $contents['reward_membership'] = array(
-        '#type'          => 'textfield',
-        '#title'         => variable_get('hotel_booking_reward_prompt', ''),
-        '#default_value' => ($arg1->reward_membership) ? $arg1->reward_membership : '',
-      );
-      return array('description' => $description, 'contents' => $contents);
-    case 'process':
-      $arg1->reward_membership = $arg2['reward_membership'];
-      return TRUE;
-    case 'review':
-      $review = ($arg1->reward_membership) ? $arg1->reward_membership : NULL;
-      return $review;
-  }
-}
-
-function hotel_booking_details_pane_checkout($op, &$order, $arg2) {
-  switch ($op) {
-    case 'view':
-      if (!$order) {
-        // If the order object doesn't exist yet, use the cart pane function
-        return array('description' => drupal_get_form('hotel_booking_details_pane_cart'));
-      }
-      else {
-        return drupal_get_form('hotel_booking_details_pane_order', $order->products);
-      }
-  }
-}
-
-
-/**
- * Functions to build fieldsets & tables for order & checkout panes (when order object exists)
+ * Functions to build fieldsets & tables for order pane
  */
 function hotel_booking_details_pane_order($form_state, $products) {
   foreach ($products as $product) {
@@ -1293,7 +1259,7 @@ function hotel_booking_details_pane_orde
       $desc .= '<div class="booking_details_blurb"><p>The following table breaks down your stay by day, listing price per night of the room';
       $desc .= ($product->data['booking_upgrades']) ? ', along with any applicable date based Add-On items.</p><p>Other Add-On items apply to your entire stay.</p>' : '.</p>';
       $desc .= '</div>';
-      $form['booking_details'][$product->order_product_id] = array(
+      $contents['booking_details'][$product->order_product_id] = array(
         '#type' => 'fieldset',
         '#title' => $title,
         '#description' => $desc,
@@ -1304,17 +1270,17 @@ function hotel_booking_details_pane_orde
         '#collapsed' => (sizeof($numnights) > 1 || (count($product->data['nights']) > 3 && sizeof($product->data['booking_upgrades']) > 2) || (count($product->data['nights']) > 5)) ? TRUE : FALSE,
       );
       $val = hotel_booking_order_details_table($product, $products);
-      $form['booking_details'][$product->order_product_id]['nid'] = array(
+      $contents['booking_details'][$product->order_product_id]['nid'] = array(
         '#value' => $val[0],
       );
       if ($val[1]) {
-        $form['booking_details'][$product->order_product_id]['nid']['additional'] = array(
+        $contents['booking_details'][$product->order_product_id]['nid']['additional'] = array(
           '#value' => hotel_booking_order_details_table($product, $products, TRUE),
         );
       }
     }
   }
-  return $form;
+  return array('contents' => $contents);
 }
 
 function hotel_booking_order_details_table(&$item, $products, $additional = FALSE) {
@@ -1382,7 +1348,7 @@ function hotel_booking_order_details_tab
 
 
 /**
- * Functions to build fieldsets & tables for cart & checkout panes (when order object does not exist)
+ * Functions to build fieldsets & tables for cart pane
  */
 
 function hotel_booking_details_pane_cart() {
@@ -1393,17 +1359,14 @@ function hotel_booking_details_pane_cart
     }
   }
 
-  // Since we're reusing this function in the checkout pane when the order object
-  // doesn't yet exist, disable the container fieldset if it's being called from
-  // there because it's already been created in that case.
-  if (substr(drupal_get_destination(), -8, 8) != 'checkout') {
-    $form['booking_details'] = array(
+  $contents['booking_details'] = array(
       '#type' => 'fieldset',
       '#title' => t('Booking Details'),
       '#description' => (sizeof($numnights) > 1) ? t('Click on the Room Types below to view your booking details.') : '',
-      '#collapsible' => FALSE,
-    );
-  }
+      '#collapsible' => TRUE,
+      '#collapsed'   => FALSE,
+  );
+
   foreach ($items as $item) {
     if ($item->module == 'hotel_booking') {
       $title = t('@title', array('@title' => $item->title));
@@ -1416,7 +1379,7 @@ function hotel_booking_details_pane_cart
       $title .= ')';
       $foo = node_load($item->nid);
 
-      $desc = (variable_get('hotel_booking_teaser_in_panes','FALSE')) ? '' : $foo->teaser;
+      $desc = (variable_get('hotel_booking_teaser_in_panes','FALSE')) ? $foo->teaser : '';
       $desc .= '<div class="booking_details_blurb"><p>The following table breaks down your stay by day, listing price per night of the room';
       $desc .= ($item->data['booking_upgrades']) ? ', along with any applicable date based Add-On items.</p><p>Other Add-On items apply to your entire stay.</p>' : '.</p>';
       if (substr(drupal_get_destination(), -8, 8) != 'checkout') {
@@ -1425,7 +1388,7 @@ function hotel_booking_details_pane_cart
       else {
         $desc .= '</div>';
       }
-      $form['booking_details'][$item->cart_item_id] = array(
+      $contents['booking_details'][$item->cart_item_id] = array(
         '#type' => 'fieldset',
         '#title' => $title,
         '#description' => $desc,
@@ -1436,17 +1399,99 @@ function hotel_booking_details_pane_cart
         '#collapsed' => (sizeof($numnights) > 1 || ($numnights[$item->cart_item_id] > 3 && sizeof($item->data['booking_upgrades']) > 2) || ($numnights[$item->cart_item_id] > 5)) ? TRUE : FALSE,
       );
       $val = hotel_booking_cart_details_table($item);
-      $form['booking_details'][$item->cart_item_id]['nid'] = array(
+      $contents['booking_details'][$item->cart_item_id]['nid'] = array(
         '#value' => $val[0],
       );
       if ($val[1]) {
-        $form['booking_details'][$item->cart_item_id]['nid']['additional'] = array(
+        $contents['booking_details'][$item->cart_item_id]['nid']['additional'] = array(
           '#value' => hotel_booking_cart_details_table($item, TRUE),
         );
       }
     }
   }
-  return $form;
+  return array('contents' => $contents);
+}
+
+
+
+/**
+ * Callbacks for checkout pane
+ */
+function hotel_booking_rewards($op, &$order, $newvalue) {
+  switch ($op) {
+    case 'view':
+      $description = t('If you have a reward membership card, please enter the number here.');
+      $contents['reward_membership'] = array(
+        '#type'          => 'textfield',
+        '#title'         => variable_get('hotel_booking_reward_prompt', ''),
+        '#default_value' => ($order->reward_membership) ? $order->reward_membership : '',
+      );
+      return array('description' => $description, 'contents' => $contents);
+    case 'process':
+      $order->reward_membership = $newvalue['reward_membership'];
+      return TRUE;
+    case 'review':
+      $review = ($order->reward_membership) ? $order->reward_membership : NULL;
+      return $review;
+  }
+}
+
+function hotel_booking_details_pane_checkout($op, &$order, $arg2) {
+  switch ($op) {
+    case 'view':
+      $contents = array();
+
+      $items = uc_cart_get_contents();
+      foreach ($items as $item) {
+        if ($item->module == 'hotel_booking') {
+          $numnights[$item->cart_item_id] = count($item->data['nights']);
+        }
+      }
+
+      foreach ($items as $item) {
+        if ($item->module == 'hotel_booking') {
+          $title = t('@title', array('@title' => $item->title));
+          $title .= ' ('. count($item->data['nights']);
+          $title .= (count($item->data['nights']) > 1) ? t(' Nights, ') : t(' Night, ');
+          $title .= ($item->data['adults'] > 1) ? $item->data['adults'] .t(' Adults') : $item->data['adults'] .t(' Adult');
+          if ($item->data['children']) {
+            $title .= ($item->data['children'] > 1) ? ', '. $item->data['children'] .t(' Children') : ', '. $item->data['children'] .t(' Child');
+          }
+          $title .= ')';
+          $foo = node_load($item->nid);
+
+          $desc = (variable_get('hotel_booking_teaser_in_panes','FALSE')) ? $foo->teaser : '';
+          $desc .= '<div class="booking_details_blurb"><p>The following table breaks down your stay by day, listing price per night of the room';
+          $desc .= ($item->data['booking_upgrades']) ? ', along with any applicable date based Add-On items.</p><p>Other Add-On items apply to your entire stay.</p>' : '.</p>';
+          if (substr(drupal_get_destination(), -8, 8) != 'checkout') {
+            $desc .= (is_array($item->data['booking_upgrades'])) ? '<p>'. l('Edit Addons & Upgrades', 'booking_upgrades/'. $item->cart_item_id) .'</p></div>' : '</div>';
+          }
+          else {
+            $desc .= '</div>';
+          }
+          $contents['booking_details'][$item->cart_item_id] = array(
+            '#type' => 'fieldset',
+            '#title' => $title,
+            '#description' => $desc,
+            '#collapsible' => TRUE,
+            // Default to collapsed if there are multiple room booking items in the cart,
+            // or the booking has more than three nights and more than two addons, or if
+            // the a single booking item has more than 5 nights.
+            '#collapsed' => (sizeof($numnights) > 1 || ($numnights[$item->cart_item_id] > 3 && sizeof($item->data['booking_upgrades']) > 2) || ($numnights[$item->cart_item_id] > 5)) ? TRUE : FALSE,
+          );
+          $val = hotel_booking_cart_details_table($item);
+          $contents['booking_details'][$item->cart_item_id]['nid'] = array(
+            '#value' => $val[0],
+          );
+          if ($val[1]) {
+            $contents['booking_details'][$item->cart_item_id]['nid']['additional'] = array(
+              '#value' => hotel_booking_cart_details_table($item, TRUE),
+            );
+          }
+        }
+      }
+      return array('contents' => $contents);
+  }
 }
 
 function hotel_booking_cart_details_table(&$item, $additional = FALSE) {
