? 644396.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.7
diff -u -p -r1.7 hotel_booking.module
--- hotel_booking/hotel_booking.module  1 Dec 2009 01:31:40 -0000       1.7
+++ hotel_booking/hotel_booking.module  1 Dec 2009 02:03:02 -0000
@@ -437,18 +437,24 @@ function hotel_search_view($args) {
   foreach ($rooms as $rtid => $data) {
     $adult_query = db_query('SELECT o.threshold, o.value FROM {hotel_occupancy_modifiers} AS o, {hotel_room_occupancy_modifiers} AS ro WHERE ro.nid = %d AND ro.hoid = o.hoid AND adult_child = "adult" AND %d > threshold', $rtid, $adults);
     $child_query = db_query('SELECT o.threshold, o.value FROM {hotel_occupancy_modifiers} AS o, {hotel_room_occupancy_modifiers} AS ro WHERE ro.nid = %d AND ro.hoid = o.hoid AND adult_child = "child" AND %d > threshold', $rtid, $children);
+    $both_query = db_query('SELECT o.threshold, o.value FROM {hotel_occupancy_modifiers} AS o, {hotel_room_occupancy_modifiers} AS ro WHERE ro.nid = %d AND ro.hoid = o.hoid AND adult_child = "occup" AND %d > threshold', $rtid, ($adults + $children));
     $adult_om = array();
     $child_om = array();
+    $both_om = array();
     while ($adult_result = db_fetch_array($adult_query)) {
       $adult_om[] = $adult_result;
     }
     while ($child_result = db_fetch_array($child_query)) {
       $child_om[] = $child_result;
     }
+    while ($both_result = db_fetch_array($both_query)) {
+      $both_om[] = $both_result;
+    }
     $total = 0;
     foreach ($data['nights'] as $night => $nightdata) {
       $a = $adults;
       $c = $children;
+      $b = $a + $c;
       if ($data['modifier']['method'] == 'value') {
         $rooms[$rtid]['nights'][$night]['price'] += $data['modifier']['amount'];
       }
@@ -472,6 +478,15 @@ function hotel_search_view($args) {
           $c -= $new_c;
         }
       }
+
+      // Apply Overall Occupant (Adults & Children) Occupancy Modifier(s)
+      for ($z = sizeof($both_om)-1; $z >= 0; $z--) {
+        if ($b > $both_om[$z]['threshold']) {
+          $new_b = $b - $both_om[$z]['threshold'];
+          $rooms[$rtid]['nights'][$night]['price'] += ($new_b * $both_om[$z]['value']);
+          $b -= $new_b;
+        }
+      }
       $total += $rooms[$rtid]['nights'][$night]['price'];
     }
     $sorted_rates[$rtid] = $total;
Index: hotel_booking/hotel_booking_admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/uc_hotel/hotel_booking/hotel_booking_admin.inc,v
retrieving revision 1.4
diff -u -p -r1.4 hotel_booking_admin.inc
--- hotel_booking/hotel_booking_admin.inc       30 Nov 2009 23:23:42 -0000      1.4
+++ hotel_booking/hotel_booking_admin.inc       1 Dec 2009 02:03:02 -0000
@@ -270,9 +270,12 @@ function hotel_booking_occupancy_modifie
     if (check_plain($modifier->adult_child) == "adult") {
       $criteria .= (check_plain($modifier->threshold) == 1) ? " adult" : " adults";
     }
-    else {
+    elseif (check_plain($modifier->adult_child) == "child") {
       $criteria .= (check_plain($modifier->threshold) == 1) ? " child" : " children";
     }
+    else {
+      $criteria .= (check_plain($modifier->threshold) == 1) ? " occupant" : " occupants";
+    }
     $rows[] = array(
       $criteria,
       '$ '. number_format(check_plain($modifier->value), 2, '.', ','),
@@ -363,8 +366,8 @@ function hotel_booking_occupancy_modifie
   $form['adult_child'] = array(
     '#type'        => 'radios',
     '#title'       => 'Guest type',
-    '#description' => 'Whether this modifier applies to adults or children',
-    '#options'     => array('adult' => 'Adults', 'child' => 'Children'),
+    '#description' => 'Select whether this modifier applies to adults, children, or overall number of occupants',
+    '#options'     => array('adult' => 'Adults', 'child' => 'Children', 'occup' => 'Occupants'),
     '#default_value' => isset($modifier->adult_child) ? check_plain($modifier->adult_child) : 'adult',
   );
   $form['threshold'] = array(
Index: hotel_room_type/hotel_room_type.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/uc_hotel/hotel_room_type/hotel_room_type.module,v
retrieving revision 1.2
diff -u -p -r1.2 hotel_room_type.module
--- hotel_room_type/hotel_room_type.module      4 Nov 2009 00:44:59 -0000       1.2
+++ hotel_room_type/hotel_room_type.module      1 Dec 2009 02:03:02 -0000
@@ -76,8 +76,10 @@ function hotel_room_type_form($node) {
   $rate_modifiers = _get_rate_modifiers();
   $adult_occupancy_modifiers = _get_occupancy_modifiers(1); // 1 = adult
   $child_occupancy_modifiers = _get_occupancy_modifiers(0); // 0 = child
+  $both_occupancy_modifiers = _get_occupancy_modifiers(2); // 2 = occupant
   $selected_aom = _get_selected_occupancy_modifiers(1, $node->nid);
   $selected_com = _get_selected_occupancy_modifiers(0, $node->nid);
+  $selected_bom = _get_selected_occupancy_modifiers(2, $node->nid);

   $form['title'] = array(
     '#type'          => 'textfield',
@@ -133,7 +135,7 @@ function hotel_room_type_form($node) {
   $form['rate']['occupancy'] = array(
     '#type'          => 'fieldset',
     '#title'         => 'Occupancy modifiers',
-    '#description'   => 'Occupancy modifiers that apply to this room type.',
+    '#description'   => 'Occupancy modifiers that apply to this room type. Adult & Children modifiers apply only to adults and children, the Occupants modifiers apply to overall occupant count.',
     '#weight'        => 0,
     '#collapsible'   => TRUE,
     '#collapsed'     => TRUE,
@@ -152,6 +154,13 @@ function hotel_room_type_form($node) {
     '#default_value' => $selected_com,
     '#weight'        => -2,
   );
+  $form['rate']['occupancy']['both_occupancy_modifiers'] = array(
+    '#type'          => 'checkboxes',
+    '#title'         => 'Occupants',
+    '#options'       => $both_occupancy_modifiers,
+    '#default_value' => $selected_bom,
+    '#weight'        => -2,
+  );
   $form['room'] = array(
     '#type'          => 'fieldset',
     '#title'         => 'Room type settings',
@@ -250,7 +259,7 @@ function hotel_room_type_insert($node) {
   db_query('INSERT INTO {hotel_room_types} (nid, vid, smoking, capacity, rate_type, rate_modifier, min_occ, avail, model) VALUES (%d, %d, %d, %d, %d, %d, %d, %d, "%s")', $node->nid, $node->vid, $node->smoking, $node->capacity, $node->rate_type, $node->rate_modifier, $node->min_occ, $node->avail, $node->model);

   // Process occupancy modifiers
-  _add_occupancy_modifiers($node->adult_occupancy_modifiers, $node->child_occupancy_modifiers, $node->nid);
+  _add_occupancy_modifiers($node->adult_occupancy_modifiers, $node->child_occupancy_modifiers, $node->both_occupancy_modifiers, $node->nid);
 }


@@ -268,7 +277,7 @@ function hotel_room_type_update($node) {

   // Process occupancy modifiers
   _delete_occupancy_modifiers($node->nid);
-  _add_occupancy_modifiers($node->adult_occupancy_modifiers, $node->child_occupancy_modifiers, $node->nid);
+  _add_occupancy_modifiers($node->adult_occupancy_modifiers, $node->child_occupancy_modifiers, $node->both_occupancy_modifiers, $node->nid);
 }


@@ -337,12 +346,15 @@ function _get_rate_modifiers() {
 function _get_occupancy_modifiers($a_or_c) {
   $modifiers = array();

-  if ($a_or_c > 0) {
+  if ($a_or_c == 1) {
     $results = db_query('SELECT hoid,threshold, value FROM {hotel_occupancy_modifiers} WHERE adult_child = "adult" ORDER BY threshold, value');
   }
-  else {
+  elseif ($a_or_c == 0) {
     $results = db_query('SELECT hoid,threshold, value FROM {hotel_occupancy_modifiers} WHERE adult_child = "child" ORDER BY threshold, value');
   }
+  else {
+    $results = db_query('SELECT hoid,threshold, value FROM {hotel_occupancy_modifiers} WHERE adult_child = "occup" ORDER BY threshold, value');
+  }

   while ($result = db_fetch_array($results)) {
     $modifiers[$result['hoid']] = '$'. number_format($result['value'], 2, '.', ',') .' each additional over '. $result['threshold'];
@@ -361,12 +373,15 @@ function _get_occupancy_modifiers($a_or_
 function _get_selected_occupancy_modifiers($a_or_c, $nid) {
   $selected_modifiers = array();

-  if ($a_or_c > 0) {
+  if ($a_or_c == 1) {
     $results = db_query('SELECT r.hoid FROM {hotel_room_occupancy_modifiers} AS r, {hotel_occupancy_modifiers} AS o WHERE r.nid = %d AND o.hoid = r.hoid AND o.adult_child = "adult"', $nid);
   }
-  else {
+  elseif ($a_or_c == 0) {
     $results = db_query('SELECT r.hoid FROM {hotel_room_occupancy_modifiers} AS r, {hotel_occupancy_modifiers} AS o WHERE r.nid = %d AND o.hoid = r.hoid AND o.adult_child = "child"', $nid);
   }
+  else {
+    $results = db_query('SELECT r.hoid FROM {hotel_room_occupancy_modifiers} AS r, {hotel_occupancy_modifiers} AS o WHERE r.nid = %d AND o.hoid = r.hoid AND o.adult_child = "occup"', $nid);
+  }

   while ($result = db_fetch_array($results)) {
     $selected_modifiers[] = $result['hoid'];
@@ -380,7 +395,7 @@ function _get_selected_occupancy_modifie
 /**
  * Add selected occupancy modifiers to database
  */
-function _add_occupancy_modifiers($aom, $com, $nid) {
+function _add_occupancy_modifiers($aom, $com, $bom, $nid) {
   foreach ($aom as $key => $value) {
     if ($value > 0) {
       db_query('INSERT into {hotel_room_occupancy_modifiers} (nid, hoid) VALUES (%d, %d)', $nid, $key);
@@ -391,6 +406,11 @@ function _add_occupancy_modifiers($aom,
       db_query('INSERT into {hotel_room_occupancy_modifiers} (nid, hoid) VALUES (%d, %d)', $nid, $key);
     }
   }
+  foreach ($bom as $key => $value) {
+    if ($value > 0) {
+      db_query('INSERT into {hotel_room_occupancy_modifiers} (nid, hoid) VALUES (%d, %d)', $nid, $key);
+    }
+  }
 }


