include('includes/init.php');
$title = "Your Shopping Cart on Furniture2go.com";
$style ="
.listing{
font-family:Arial
}
table.listing{
border: 1px solid #675A1D
}
td.listing {
font-size: 12px;
}
th.listing {
background-color: #EEEEEE;
font-weight:black;
font-size:12px
}
";
//echo "
";
//print_r($_SESSION);
//echo "
";
if($killall==1) unset($_SESSION['cart']);
// set cart
if(!isset($_SESSION['cart'])) $_SESSION['cart'] = array();
//set message
$msg="";
//if products are passed to page
if(isset($_GET['prods']) && !isset($a1)){
//check if there's overlap in products being added and the existing cart
$overlap=0;
foreach ($_GET["prods"] as $key => $value){
$pn= $value;
//if overlap, add 1 to overlap counter and append parameter string if user clicks on 'yes'
if(isset($_SESSION['cart']['x'.$pn])){
$overlap++;
$yesqs .= "&prods[]=$pn";
}else{ //if no overlap for this product, append parameter string if user clicks on 'yes' and if user clicks 'no'
$yesqs .= "&prods[]=$pn";
$noqs .= "&prods[]=$pn";
}
}
// if overlap
if($overlap>0){
$msg .="$overlap of the products you want to add already exist in your shopping cart. Do you really want to add an additional one of each to your cart?";
$msg .="
Yes No, just add the new items to my cart";
}else{
foreach ($_GET["prods"] as $key => $value){
$pn= $value;
$_SESSION['cart']['x'.$pn] = 1;
}
}
}
//if confirming addition to cart after overlap message, add all items being passed to cart
if(isset($a1)){
//loop through products
foreach ($_GET["prods"] as $key => $value){
$pn= $value;
//if one of the overlappers
// echo 'x'.$pn;
if(isset($_SESSION['cart']['x'.$pn])){
// echo "adding one more";
// echo "x".$pn;
$_SESSION['cart']['x'.$pn]++;
//if not one of overlappers, add normally
}else{
$_SESSION['cart']['x'.$pn] = 1;
}
}
$forwardalong=1;
}
//delete a product from the cart
if(isset($r)){
$_SESSION['cart']['x'.$r] = 0;
arsort($_SESSION['cart']);
$grouper = array_count_values($_SESSION['cart']);
$howmanyzeros = $grouper[0];
array_splice($_SESSION['cart'], count($_SESSION['cart'])-$howmanyzeros);
}
//update a quantity a product from the cart
if(isset($update)){
$_SESSION['cart']['x'.$u] = $newqty;
}
//create IN string for query
$inquery = implode("','",array_keys($_SESSION['cart']));
$inquery =str_replace("x","",$inquery);
$inquery = "'".$inquery."'";
//logic to decide on 'continue shopping' link
if(isset($_SESSION['lastview']) && $_SESSION['lastview']!=""){
$lastview = str_replace("short=1","1=1",$_SESSION['lastview']);
$shoppinglink = $lastview;
}else{
$shoppinglink = 'index.php?1=1';
}
include('topinc.php');
//echo "";
//print_r($_SESSION);
//echo "
";
// QUERY BUILDER///////////////////////////////////////
$fields = "spid,pid,text,spcode,dimensions,price,price_lv,price_sf,price_phx,price_nw,price_cad";
$count_sql = "select $fields from subproducts where spid IN ($inquery);";
$prod_sql = "select $fields from subproducts where spid IN ($inquery);";
//echo $prod_sql;
//run query
$count_rs = mysql_query($count_sql) or die(mysql_error());
$prod_rs = mysql_query($prod_sql) or die(mysql_error());
$count = mysql_num_rows($count_rs);
if($count==0){
echo "
Your cart is empty.

";
}else{
//if forward to static page
if($forwardalong==1){
echo "";
}
//Throw msg if set
if(isset($msg) && $msg!=""){
?>
}
// wrapper table
echo "
}
include('bottominc.php')
?>