require("includes/variable_defns.inc.php"); $cart = ''; // user updated cart if($_POST['UPDATE']) { // get array of item ids in cart $ids = explode(',', $_POST['ids']); // loop through foreach($ids as $id) { // if did not delete item, add it the cart string, with its quantity if(!$_POST['delete' . $id]) { if($cart != '') $cart .= '|'; if($_POST['quantity' . $id] < 1) $_POST['quantity' . $id] = 1; $cart .= $id . ',' . $_POST['quantity' . $id]; } } // if still have a cart, update the cookie, otherwise, expire the cookie if($cart != '') setcookie('DixieMedCart', $cart, time() + 1800); else setcookie('DixieMedCart', $cart, time() - 216000); } // do we have a cart? else if(isset($_COOKIE['DixieMedCart'])) $cart = $_COOKIE['DixieMedCart']; // if we have a cart, extract the items if($cart) $items = explode('|', $cart); // looks in items for who, returns true if found function item_exists($items, $who) { foreach($items as $item) { $item_info = explode(',', $item); if($item_info[0] == $who) return TRUE; } return FALSE; } function formattedProductText() { global $items; if(!$items) return ''; require_once("includes/db_connect.php"); $text = "Quantity\t\tProduct\n"; $text .= "--------\t\t-------\n"; foreach($items as $item) { // 0 = id, 1 = quantity $item_info = explode(',', $item); // query the db, asking for information about this product $p_query = mysql_query("SELECT title FROM stories WHERE id=" . $item_info[0]); if(!$p_query) $text .= "Error: Could not find information for product " . $item_info[0] . " please contact " . $adminEmail . ". Thank you.\n\n"; else { $p_info = mysql_fetch_array($p_query); $text .= $item_info[1] . "\t\t\t" . $p_info['title'] . "\n"; } } $text .= "\n"; return $text; } // try to add an item, but only if it does not exist if($_GET['add'] && (!$items || ($items && !item_exists($items, $_GET['add'])))) { if($cart != '') $cart .= '|'; $cart .= $_GET['add'] . ',1'; // expire in 30 minutes setcookie('DixieMedCart', $cart, time() + 1800); // refresh the items array, so the new item is in there $items = explode('|', $cart); } $goodCheckout = TRUE; if($_POST['CHECKOUT']) { $name = $_POST['name']; $address = $_POST['address']; $email = $_POST['email']; $phone = $_POST['phone']; $comments = $_POST['comments']; if($name && $email && $phone) { // process request $productString = formattedProductText(); if($_POST['receipt'] && $productString) { $msg = "Hello,\n\nThank you for your inquiry in the following products:\n\n" . $productString; $msg .= "Your information request has been sent. A Dixie Medical Equipment representative has been notified and will provide the requested information shortly. If you need additional assistance, please contact us directly at sales@dixiemed.com or call us toll free at 866.349.4364.\n\n"; $msg .= "Thanks again for your inquiry.\n\nDixie Medical Equipment"; $sentmail = mail($email, "Your Dixie Medical Equpment Information Request", $msg, "From: " . $adminEmail . "\r\n" ."Reply-To: " . $adminEmail . "\r\n" ."X-Mailer: PHP/" . phpversion()); } session_start(); $_SESSION['cart_vars'] = $_POST; $_SESSION['items'] = $items; setcookie('DixieMedCart', $cart, time() - 216000); header("LOCATION: cart_thanks.html"); } else $goodCheckout = FALSE; } ?>