session_start(); require_once( '../config.php' ); require_once( 'lib/xml_func.php' ); ///////////////////////////////////////////////////////////////////////////////////////// // Now, get HTML output of Shopping Cart Content, using viewcart_content.php require_once( "comsoltech/CShoppingCart.php" ); // First, load shopping cart so that viewcart_content.php can generate shopping cart contents $basket = new CShoppingCart(); if( isset( $_SESSION['items'] ) ) { $basket->setItems( $_SESSION['items'] ); } $items = $basket->getItems(); $disableEditing = true; // doesn't display UPDATE or REMOVE button $file_loc = 'viewcart_content.php'; include( 'phpoutput.inc.php' ); // $subTotal already contains Total of all the items in the shopping cart, calculated inside viewcart_content.php ///////////////////////////////////////////////////////////////////////////////////////// function redirect2($to) { //header("HTTP/1.1 301 Moved Permanently"); header("HTTP/1.1 302 Found"); // header("HTTP/1.1 303 See Other"); header("Location: $to"); exit(); } if( $_POST['action'] == 'post' || $_GET['action'] == 'post' ) { // send mail to sales... $_GET is for after PayPal, it returns to GET method. //if( $_POST['email'] == 'test@comsoltech.com' || $_POST['email'] == '' || $_SERVER['REMOTE_ADDR'] == "68.104.203.25" ) { $shipping = 0; if( $_POST['country'] == 'United States' || $_POST['country'] == 'USA' ) { $shipping = 5; } elseif( $_POST['country'] == 'Canada' || $_POST['country'] == 'Mexico' ) { $shipping = 8; // $8.00 up to 2 lb } else { $shipping = 15; } if( $_POST['hiddensubmit'] == 'COD' ) { $COD = 'Yes'; $shipping += 6; // $6.00 extra for COD order } $tax = ToCurr( 0 ); $taxDescription = 'CA Tax 7.75%'; if( strtolower( $_POST['state'] ) == 'ca' || strtolower( $_POST['state'] ) == 'california' ) { $tax = ToCurr( $subTotal * .0775 ); // California Tax Rate as of 3/24/2004 : 7.75% == 0.0775 } $shipping = ToCurr( $shipping ); $grandTotal = ToCurr( $subTotal + $tax + $shipping ); $subTotal = ToCurr( $subTotal ); // now store this in Hash Array so we can pass as a function parameter $hTotal = array( 'subTotal' => $subTotal, 'shipping' => $shipping, 'tax' => $tax, 'taxDescription' => $taxDescription, 'grandTotal' => $grandTotal ); if( $_POST['hiddensubmit'] == 'Paypal' ) { // user clicked on paypal, so redirect user to paypal page! $OrderID = CreateXMLAndSaveToDB( $config->connParam, $config->site, $hTotal, $xml_data ); $ExtraOrderID = date("Ymd"); if( $tax > 0 ) { // if there's tax $itemNumber = "Order ID: $ExtraOrderID-$OrderID, $totalItemCount Item(s), $taxDescription=$tax Total=$grandTotal"; } else { $itemNumber = "Order ID: $ExtraOrderID-$OrderID, $totalItemCount Item(s), (Tax-Exempt) Total=$grandTotal"; } $hPaypal = array( 'cmd' => '_xclick', 'business' => 'jlau@coilws.com', 'item_name' => $config->site . " Order #$ExtraOrderID-$OrderID ($totalItemCount item(s), Shipping=(to be determined)" . ')' ,'item_number' => $itemNumber // $totalItemCount is calculated from viewcart_content.php ,'amount' => $grandTotal ,'no_shipping' => '0' ,'return' => "https://www.cwsbytemark.com/buy/paypal.php?oid=$OrderID&paypal=A&S=$shipping&ST=$subTotal&T=$tax&E=" . urlencode( $_POST['email'] ) . '&Secure=yes' ,'cancel_return' => 'https://www.cwsbytemark.com/buy/viewcart.php' ,'currency_code' => 'USD' ,'lc' => 'US' ); foreach( $hPaypal as $key => $value ) { $url .= urlencode($key) . '=' . urlencode($value) . '&'; } redirect2('https://www.paypal.com/cgi-bin/webscr?' . $url); } else { // regular user submit by supplying Credit Card in the site $OrderID = CreateXMLAndSaveToDB( $config->connParam, $config->site, $hTotal, $xml_data ); } require_once( 'lib/email_func.php' ); if( $_POST['hiddensubmit'] == 'COD' ) { SendOrderViaEmail($config->smtp_server, $_POST['email'], $config->salesEmail, "[ORDER - COD] $config->site - Order #$OrderID" , $OrderID, $hTotal, $content, $xml_data , "\nThis Order is C.O.D. Order.\n"); // Now send confirmation to the customer SendOrderViaEmail($config->smtp_server, $config->salesEmail, $_POST['email'], "$config->site - Order #$OrderID Confirmation" , $OrderID, $hTotal, $content, '' , "\nThis Order is C.O.D. Order.\n"); } else { SendOrderViaEmail($config->smtp_server, $_POST['email'], $config->salesEmail, "[ORDER - CC] $config->site - Order #$OrderID" , $OrderID, $hTotal, $content, $xml_data); // Now send confirmation to the customer SendOrderViaEmail($config->smtp_server, $config->salesEmail, $_POST['email'], "$config->site - Order #$OrderID Confirmation" , $OrderID, $hTotal, $content); } $basket->removeAll(); // empty shopping cart! $_SESSION['items'] = null; $items = $basket->getItems(); redirect ("checkout_ok.php"); } ?>