<?php
include("config.php");
include("cart.class.php");
session_start();
// Make a working copy of the shopping cart from session data //
$items = $_SESSION["cart"];
$tix = array('1', '2', '3', '4');
$rooms = array('6', '7', '8');
$cart = new Shopping_Cart($items);
// Retrieve the parameters //
$item = $_GET['type'];
$cost = $_GET['cost'];
$qty = $_GET['qty'];
$name = $_GET['name'];
$pack = $_GET['pid'];
$dat = $_GET['dat'];
$hotel = $_GET['hid'];
if (in_array($item, $tix)) {
if (isset($items[$item])) {$cart->deleteFromCart($item, $items[$item]['qty']);}
$cart->addToCart($item, $qty, $cost, $name);
}
elseif ($item == '5' || $item == '21' || $item == '26') {
if (isset($items[$item])) {$cart->deleteFromCart($item, 1);}
if ($qty > 0) {$cart->addToCart($item, $qty, $cost, $name);}
}
elseif ($item == '13') {
$cart->addToCart($item, 1, $cost, $name.";".$pack);
$qry = mysql_query("SELECT hotelnight FROM prepackaged WHERE pid=".$pack);
$row = mysql_fetch_row($qry);
if ($row[0]) {
if (!isset($items[16]) && !isset($items[17])) {$cart->addToCart(16, 1, 0, 'Single King');}
if (!isset($items[18]) && !isset($items[19])) {$cart->addToCart(18, 1, 0, 'Non-Smoking');}
}
}
// If item is adult or child packages //
elseif ($item == '14' || $item == '15') {
// If the item already exists in the cart, remove it //
if (isset($items[$item])) {$cart->deleteFromCart($item, $items[$item]['qty']);}
// Add the new quantity of the item to the cart //
$cart->addToCart($item, $qty, $cost, $name);
// Update the session cart, and make a new working copy //
[COLOR=red]$_SESSION["cart"] = $cart->getCart();
$items = $_SESSION["cart"];[/color]
// Query the database for hotel quantity pricing //
$qry = mysql_query("SELECT * FROM prepackaged WHERE pid=".$pack);
if (!$qry) {die('Query Failed with Error Message: '.mysql_error());}
$packdat = mysql_fetch_array($qry);
$ppl = 0;
// Calculate the hotel cost based on the number of adult occupants //
switch ($items[14]['qty']) {
case 1:
$ppl = 2;
$price = $packdat['single'];
break;
case 2:
$ppl = 2;
if (!empty($packdat['double'])) {$price = $packdat['double'] * 2;}
else {$price = $packdat['single'] * 2;}
break;
case 3:
$ppl = 3;
if (!empty($packdat['triple'])) {$price = $packdat['triple'] * 3;}
elseif (empty($packdat['triple']) && !empty($packdat['double'])) {$price = $packdat['double'] * 3;}
else {$price = $packdat['single'] * 3;}
break;
case 4:
$ppl = 4;
if (!empty($packdat['quad'])) {$price = $packdat['quad'] * 4;}
elseif (empty($packdat['quad']) && !empty($packdat['triple'])) {$price = $packdat['triple'] * 4;}
elseif (empty($packdat['quad']) && empty($packdat['triple']) && !empty($packdat['double'])) {$price = $packdat['double'] * 4;}
else {$price = $packdat['single'] * 4;}
break;
case 0:
$ppl = 0;
$price = 0;
break;
default:
$price = "NO GOOD!";
break;
}
// If there are children set, add the child rates to the hotel costs//
if (isset($items[15]['qty']) && $items[15]['qty'] > 0){
if (!empty($packdat['child'])) {$price += ($items[15]['qty'] * $packdat['child']);}
else {$price += ($items[15]['qty'] * $packdat['single']);}
$ppl += $items[15]['qty'];
}
// Remove the existing package from the cart, and re-add it with the new cost calculation //
$cart->deleteFromCart(13, 1);
if (($item == '14' && $qty > 0) || $item == '15') {
$cart->addToCart(13, 1, $price, $packdat['name'].";".$pack);
}
// If there are ticket upgrades selected, recalculate their cost on the new number of packages //
if (isset($items[20])) {
$cart ->deleteFromCart(20, $items[20]['qty']);
$cart ->addToCart(20, $ppl, $items[20]['cost'], $items[20]['name']);
}
}
elseif ($item == '20') {
if (isset($items[$item])) {$cart ->deleteFromCart($item, $items[$item]['qty']);}
$ppl = 1;
if (isset($items[14])) {$ppl = $items[14]['qty'];}
if (isset($items[15])) {$ppl += $items[15]['qty'];}
$cart -> addToCart($item, $ppl, $cost, $name);
}
elseif (in_array($item, $rooms)) {
if (isset($items[$item])) {$cart->deleteFromCart($item, $items[$item]['qty']);}
if ($item == '8') {
if (isset($items[22])) {$cost*=$qty * $items[22]['qty'];}
else {$cost*=$qty;}
}
$cart->addToCart($item, $qty, $cost, $name);
}
elseif ($item == '9' || $item == '11' || $item == '16' || $item == '18') {
if (isset($items[$item + 1])) {$cart->deleteFromCart($item + 1, 1);}
$cart->addToCart($item, 1, 0, $name);
}
elseif ($item == '10' || $item == '12' || $item == '17' || $item == '19') {
if (isset($items[$item - 1])) {$cart->deleteFromCart($item - 1, 1);}
$cart->addToCart($item, 1, 0, $name);
}
// If the item being passed is a depart or return date //
elseif ($item == '23' || $item == '24') {
// If there is a number of nights stored in the cart, remove them for recalculation //
if (isset($items[22])) {$cart ->deleteFromCart(22, $items[22]['qty']);}
// If the item is a departure date, update the departure date //
if ($item == '23') {$cart->updateDates($dat, $items['DoR']);}
// If the item is a return date, update the return date //
elseif ($item == '24') {$cart->updateDates($items['DoD'], $dat);}
// Update the session cart with changes, and make a new working copy from the session data //
[COLOR=red]$_SESSION["cart"] = $cart->getCart(); //***************************************************************************
$items = $_SESSION["cart"];
// If only one date is set, assume that the trip is for one night only //
if (!isset($items['DoD']) || !isset($items['DoR'])) {$cart->addToCart(22, 1, 0, 'Nights');}
// If both departure and return dates are set, then calculate the number of nights difference //
else {
$depart = explode("/", $items['DoD']);
$return = explode("/", $items['DoR']);
$date1 = mktime(0, 0, 0, $depart[0], $depart[1], $depart[2]);
$date2 = mktime(0, 0, 0, $return[0], $return[1], $return[2]);
$days = floor(($date2-$date1)/(60*60*24));
$cart ->addToCart(22, $days, 0, 'Nights');
}
// Update the session cart with changes, and make a new working copy from the session data //
$_SESSION["cart"] = $cart->getCart();
$items = $_SESSION["cart"];[/color] //***************************************************************************
// If a number of rooms have been selected //
if (isset($items[8])) {
// Query the database for the hotel price //
$qry = mysql_query ("SELECT * FROM hotel WHERE hid=".$hotel);
$row = mysql_fetch_array($qry);
$cost = $row['ROOM_TYPE_1_PRICE'];
// Remove the current rooms from the shopping cart //
$cart->deleteFromCart(8, $items[8]['qty']);
// If there is a number of nights set, multiply the cost of the room by the number of rooms, and the number of nights //
if (isset($items[22]) && $items[22]['qty'] > 0) {$cost*= $items[8]['qty'] * $items[22]['qty'];}
// If there is no nights set, multiply the cost of the room by the number of rooms //
else {$cost*= $items[8]['qty'];}
// Update the cart with the new room cost //
$cart->addToCart(8, $items[8]['qty'], $cost, $items[8]['name']);
}
}
elseif ($item == '25') {
if (isset($items[$item])) {$cart->deleteFromCart(25, $items[$item]['qty']);}
if ($qty) {
$cost = $items['subTotal'] * 0.1;
$cart->addToCart($item, $qty, $cost, $name);
}
}
$_SESSION["cart"] = $cart->getCart();
if ($item != '25' && $item != '26') {
include("viewcart.php");
//echo "<hr>";
//print_r($_SESSION["cart"]);
}
else {echo "Thanks! Your total has been updated to $", number_format($_SESSION["cart"]['grandTotal'], 2);}
?>