Location: PHPKode > projects > XplainCart > xplaincart-1.0/checkout.php
<?php
require_once '../../mainfile.php';
require_once 'library/define.php';
require_once 'library/init_class.php';
require_once 'library/cart_func_class.php';
require_once 'library/checkout_func_class.php';
class checkout_class{
	var $orderId;
	var $orderAmount;
	function checkout(){
		global $xoopsTpl;
		global $xoopsModuleConfig;
		$cart_func=new cart_func_class;
		$init=new init_class;
		$checkout_func=new checkout_func_class;
		$shopConfig=$init->getShopConfig();
		if ($cart_func->isCartEmpty()) {
			// the shopping cart is still empty
			// so checkout is not allowed
			header ("Cache-Control: no-cache, must-revalidate");
			header('Location: cart.php');
		} else if (isset($_GET['step']) && (int)$_GET['step'] > 0 && (int)$_GET['step'] <= 3) {
			$step = (int)$_GET['step'];
			$xoopsTpl->assign('step',$step);
			if ($step == 1) {
				//////////////////shippingAndPaymentInfo
				//////////////////header
				include 'include/header.php';
				//////////////////content
				$errorMessage = '&nbsp;';
				$xoopsTpl->assign('errorMessage',$errorMessage);
				$xoopsTpl->assign('self',$_SERVER['PHP_SELF']);
				//////////////////footer
				include 'include/footer.php';
			} else if ($step == 2) {
				//////////////////checkoutConfirmation
				//////////////////header
				include 'include/header.php';
				//////////////////content
				$init=new init_class;
				$shopConfig=$init->getShopConfig();
				$cart_func=new cart_func_class;
				if (!defined('WEB_ROOT')
				    || !isset($_GET['step']) || (int)$_GET['step'] != 2
					|| $_SERVER['HTTP_REFERER'] != 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?step=1') {
					exit;
				}
				$errorMessage = '&nbsp;';
				/*
				 Make sure all the required field exist is $_POST and the value is not empty
				 Note: txtShippingAddress2 and txtPaymentAddress2 are optional
				*/
				$requiredField = array('txtShippingFirstName', 'txtShippingLastName', 'txtShippingAddress1', 'txtShippingPhone', 'txtShippingState',  'txtShippingCity', 'txtShippingPostalCode',
		                       'txtPaymentFirstName', 'txtPaymentLastName', 'txtPaymentAddress1', 'txtPaymentPhone', 'txtPaymentState', 'txtPaymentCity', 'txtPaymentPostalCode');
					   
				if (!$init->checkRequiredPost($requiredField)) {
					$errorMessage = 'Input not complete';
				}
				$cartContent = $cart_func->getCartContent();
				$numItem  = count($cartContent);
				$data=array();
				$subTotal = 0;
				for ($i = 0; $i < $numItem; $i++) {
					extract($cartContent[$i]);
					$subTotal += $pd_price * $ct_qty;
					$data[]=array('product'=>$ct_qty.' x '.$pd_name,'pd_price'=>$init->displayAmount($pd_price),'pd_subtotal'=>$init->displayAmount($ct_qty * $pd_price));
				}
				$xoopsTpl->assign('subTotal',$init->displayAmount($subTotal));
				$xoopsTpl->assign('shippingCost',$init->displayAmount($shopConfig['shippingCost']));
				$xoopsTpl->assign('total',$init->displayAmount($shopConfig['shippingCost'] + $subTotal));
				$xoopsTpl->assign('data',$data);
				$xoopsTpl->assign('ShippingFirstName',$_POST['txtShippingFirstName']);
				$xoopsTpl->assign('ShippingLastName',$_POST['txtShippingLastName']);
				$xoopsTpl->assign('ShippingAddress1',$_POST['txtShippingAddress1']);
				$xoopsTpl->assign('ShippingAddress2',$_POST['txtShippingAddress2']);
				$xoopsTpl->assign('ShippingPhone',$_POST['txtShippingPhone']);
				$xoopsTpl->assign('ShippingState',$_POST['txtShippingState']);
				$xoopsTpl->assign('ShippingCity',$_POST['txtShippingCity']);
				$xoopsTpl->assign('ShippingPostalCode',$_POST['txtShippingPostalCode']);
				$xoopsTpl->assign('PaymentFirstName',$_POST['txtPaymentFirstName']);
				$xoopsTpl->assign('PaymentLastName',$_POST['txtPaymentLastName']);
				$xoopsTpl->assign('PaymentAddress1',$_POST['txtPaymentAddress1']);
				$xoopsTpl->assign('PaymentAddress2',$_POST['txtPaymentAddress2']);
				$xoopsTpl->assign('PaymentPhone',$_POST['txtPaymentPhone']);
				$xoopsTpl->assign('PaymentState',$_POST['txtPaymentState']);
				$xoopsTpl->assign('PaymentCity',$_POST['txtPaymentCity']);
				$xoopsTpl->assign('PaymentPostalCode',$_POST['txtPaymentPostalCode']);
				$xoopsTpl->assign('optPayment',$_POST['optPayment']);
				//////////////////footer
				include 'include/footer.php';
			} else if ($step == 3) {
				$orderId     = $checkout_func->saveOrder();
				$this->orderId=$orderId;
				$orderAmount = $checkout_func->getOrderAmount($orderId);
				$this->orderAmount=$orderAmount;
				$_SESSION['orderId'] = $orderId;
				// our next action depends on the payment method
				// if the payment method is COD then show the 
				// success page but when paypal is selected
				// send the order details to paypal
				if ($_POST['hidPaymentMethod'] == 'cod') {
					header ("Cache-Control: no-cache, must-revalidate");
					header('Location: success.php');
					exit;
				} else {
					include 'include/header.php';
					include 'include/paypal/payment.php';
					include 'include/footer.php';
				}
			}
		} else {
			// missing or invalid step number, just redirect
			header ("Cache-Control: no-cache, must-revalidate");
			header('Location: index.php');
		}
	}
}
$xoopsOption['template_main']='checkout_index.html';
include XOOPS_ROOT_PATH.'/header.php';
$checkout=new checkout_class;
$checkout->checkout();
include XOOPS_ROOT_PATH.'/footer.php';
?>
Return current item: XplainCart