<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
// +----------------------------------------------------------------------+
// | PHP version 4/5                                                      |
// +----------------------------------------------------------------------+
// | This source file is a part of iScripts Multicart                     |
// +----------------------------------------------------------------------+
// | Authors: Santhosh Thomas Alexander<santhosh.thomas@armiasystems.com> |
// +----------------------------------------------------------------------+
// | Copyrights Armia Systems, Inc and iScripts.com  2005                 |
// | All rights reserved                                                  |
// +----------------------------------------------------------------------+
// | This script may not be distributed, sold, given away for free to     |
// | third party, or used as a part of any internet services such as      |
// | webdesign etc.                                                       |
// +----------------------------------------------------------------------+
?>
<?php
include "includes/config.php";
include "includes/session.php";
include "includes/functions.php";
include_once "classes/cls_cart.php";
if (get_magic_quotes_gpc()) {
    $_POST = array_map('stripslashes_deep', $_POST);
    $_GET = array_map('stripslashes_deep', $_GET);
    $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
	$_SESSION = array_map('stripslashes_deep', $_SESSION);
}

if(isset( $_SESSION["sess_userid"]) and $_SESSION["sess_userid"]!= ""){
	$userid = $_SESSION["sess_userid"];
}
else
{
	header ("location:viewcart.php");
	exit;
}



  
  //$hide_shipping_division = hideShipping();
  
  if($_SESSION["sess_userid"]!='') 
     {
         $visitorId     =  '';
     }else{
         $visitorId     = generalMethods::sessionid();
     }

 

$currency_attributes= displayCurrencyType();
//$hide_shipping_division = hideShipping();
$adminCurrency	= GetAdminCurrency();

$storeOriginCountry=$_SESSION['store_origin_country'];
$storeOriginState=$_SESSION['store_origin_state'];
$txtBillingState =$_SESSION["sessBillingState"];
$txtBillingCountry = $_SESSION["sessBillingCountry"];
$txtShippingCountry = $_SESSION["sessShippingCountry"];
$txtShippingState = $_SESSION["sessShippingState"];
$txtShippingState = $_SESSION["sessShippingState"];

$sql = "SELECT *  FROM ".$tableprefix."settings ";
$res = mysql_query($sql);

if(mysql_num_rows($res)>0)
{
    $row = mysql_fetch_array($res);
    $siteurl=$row["site_url"];
    //========================================Check Tax Settings for  Products
    $enable_tax=$row["enable_tax"];
    $default_tax_rate=$row['defaulttax_rate'];

    $taxpercentage = $default_tax_rate;
    //==============================================End Tax Check
    $chkPaypal              = $row["enablepaypal"];
    $chkWorldpay            = $row["enableworldpay"];
    $chkGoogleCheckout      = $row["vgoogle_check_enable"];
    $chkYourpay             = $row["vyourpay_enable"];
    $chkAuthorize           = $row["vauthorize_enable"];
    $chkGiftPay             = $row["venable_gift_payment"];
    $chkCouponPay           = $row["venable_couponCode_payment"];
    $enableBuyerToSeller    = $row["enable_buyerToseller"];
    $chkBluepay             = $row["vbluepay_enable"];

    if($enableBuyerToSeller=="Y"){
            $_SESSION['SESS_ARTISTID']= getArtistID($_SESSION["sess_userid"]);
            /*$row_paypal = mysql_fetch_assoc(mysql_query("SELECT enablepaypal FROM ".$tableprefix."artists WHERE artist_id=".$_SESSION['SESS_ARTISTID']));
            $chkPaypal=$row_paypal['enablepaypal'];*/
    }


}
/*display the active template*/
$active_template = displayTemplate();
// Script for Gift Certificate Starts Here



// Check the Gift Certificate Applied is the same seller Items 

if($_SESSION['sess_giftcertificate_code']!='')
{
    $otherSellerItems   =   chekOtherGiftCertificateSellerItems($_SESSION['sess_giftcertificate_code'],$userid);
    
    if($otherSellerItems==1)
    {
        $message = RE_ENTER_GIFT_CODE."<br>";
        
        $_SESSION['sess_giftcertificate_available_amt']    =   0;
         
        $_SESSION['sess_giftcertificate_code'] =   '';
    }
}   


if (isset($_SESSION["sess_userid"]) and $_SESSION["sess_userid"] != "") {
    $sql = "SELECT c.*, p.product_name,p.product_id,CONCAT(a.first_name,' ',a.last_name) AS sellername,state,country,a.storename,a.artist_name,(p.product_price+po.additional_price) AS product_price,po.discount,p.product_artist_id
					FROM " . $tableprefix . "cart c
                                        INNER JOIN " . $tableprefix . "product_options po ON po.product_option_id = c.product_option_id
                                        INNER JOIN " . $tableprefix . "products p ON p.product_id = po.product_id
                                        INNER JOIN " . $tableprefix . "artists a ON a.artist_id = c.seller_id    
					WHERE c.user_id = '" . addslashes($_SESSION["sess_userid"]) . "' ORDER BY seller_id";
} else {
    $sql = "SELECT c.*, p.product_name,p.product_id,CONCAT(a.first_name,' ',a.last_name) AS sellername,state,country,a.storename,a.artist_name,(p.product_price+po.additional_price) AS product_price,po.discount,p.product_artist_id
					FROM " . $tableprefix . "cart c
                                        INNER JOIN " . $tableprefix . "product_options po ON po.product_option_id = c.product_option_id
                                        INNER JOIN " . $tableprefix . "products p ON p.product_id = po.product_id
                                        INNER JOIN " . $tableprefix . "artists a ON a.artist_id = c.seller_id    
                                        WHERE c.visitor_cart_id = '" . addslashes(session_id()) . "' ORDER BY seller_id";
}

$cartItems = DbHelper::customQuery($sql);



if(isset($_POST['btngiftCode']))
{
	 $txtGiftCode	=	$_POST['txtgiftCode'];
         
         $_SESSION['sess_giftcertificate_available_amt']    =   0;
         
         $_SESSION['sess_giftcertificate_code'] =   '';

	 if($txtGiftCode=='')
	 {
	 	$message		= ENTER_GIFT_CODE_TEXT ;
	 }
	 else
	 {

                 $sql_code="SELECT g.* FROM ".$tableprefix."giftcertificates g
                                        where g.vgift_coupon_code='".addslashes($txtGiftCode)."' ";
                 $rs_code  = mysql_query($sql_code) or die(mysql_error());

                if(mysql_num_rows($rs_code)>0)
                {

                                $rsobj=mysql_fetch_object($rs_code);

                                $sellerid=$rsobj->seller_id;

                                $sql_select_products 	= "SELECT p.product_id,p.product_name
                                                           FROM ".$tableprefix."product_options po
                                                           INNER JOIN ".$tableprefix."products p ON po.product_id = p.product_id
                                                           INNER JOIN ".$tableprefix."cart c ON c.product_option_id=po.product_option_id
                                                           WHERE c.user_id='".$userid."' and p.product_artist_id!='".$sellerid."' ";
                                $rs_select_products	 =	mysql_query($sql_select_products) or die(mysql_error());

                                if(mysql_num_rows($rs_select_products)>0)
                                {
                                        while($rows=mysql_fetch_array($rs_select_products))
                                        {
                                                $productnames[]=$rows['product_name'];

                                        }

                                        $products	=join(",",$productnames);
                                  
                                  $message = MSG_VALIDATION_SELLER1."<br>";
                                  $message = str_replace("{SELLER_NAME}", getArtistName($sellerid), $message);
                                  $message.= $products;
                         }
                        else
                        {
                                        $avaibale_gift_amt		=	$rsobj->ngift_coupon_amount-$rsobj->nused_gift_amount;
                                        
                                        $UsercartTotalAmount =    getCartTotal($userid);

                                        if($avaibale_gift_amt>0 )
                                        {
                                          if($UsercartTotalAmount>$avaibale_gift_amt) 
                                          {
                                            $_SESSION['sess_giftcertificate_available_amt'] = $avaibale_gift_amt;
                                            $_SESSION['sess_giftcertificate_code'] = $txtGiftCode;
                                            $success_message = GIFT_APPLY_SUCCESS_TEXT;
                                          }
                                          else{
                                              
                                                $message = CART_AMOUNT_GIFT_TEXT."&nbsp;".$adminCurrency['currency_symbol']."&nbsp;".number_format((getCartTotal($userid)),2,".","")."&nbsp;".LESS_GIFT_AMOUMT . $adminCurrency['currency_symbol']."&nbsp;".number_format($avaibale_gift_amt,2,".",""). " , " .GIFT_USE_AMOUNT  ;
                                             }
                                        }
                                        else
                                        {
                                                $_SESSION['sess_giftcertificate_available_amt']	='';
                                                $message = GIFT_USED_NO_BALANCE_TEXT;
                                        }
                        }

                }

                else
                {
                        $message		= GIFT_CODE_INVALID_TEXT;
                }

	 }

}



// Remove Gift amount if click on remove gift button 

if(isset($_POST['btngiftRemove']))
{
         $_SESSION['sess_giftcertificate_available_amt']    =   0;
         
         $_SESSION['sess_giftcertificate_code'] =   '';
         
         unset($_SESSION['sess_giftcertificate_available_amt']);
         
         unset($_SESSION['sess_giftcertificate_code']);
         
         $success_message = GIFT_REMOVED_SUCCESS_TEXT;
         
}

// Couponcode Discount Removal if requested

if(isset($_POST['couponCodeRemoveButn']))
{
   $_SESSION['couponCode_det'] =array();
   
   $_SESSION['couponCode_det']['ccDiscount'] ='';
   
   unset($_SESSION['couponCode_det']['ccDiscount']);
   
   
   unset($_SESSION['couponCode_det']);
   
    $success_message = COUPON_REMOVED_SUCCESS_TEXT;
}
// if Gift Certificate Order placed
/*if(checkGiftProductsExistsinCart($userid))
{
	
	cartClearDigital($userid);
}*/

       
include "includes/htmltop.php";

/* Top File Name */

include_once ("includes/".$active_template[0]);

if(isset($_SESSION['SESS_google_checkout']))
{
if(function_exists('session_unregister')) {
	session_unregister('SESS_google_checkout');
}
else{
    	unset($_SESSION['SESS_google_checkout']);

}

}
// find total cart amount

if(isset($_POST['couponCodeButn']) && $_POST['couponCode']!=''){
$couponCode=trim($_POST['couponCode']);
$couponCode_det=checkValiditycouponCode($couponCode);
	if(is_array($couponCode_det))
	{
			//$display_total=number_format(getCartTotalcouponCode($_SESSION["sess_userid"],$couponCode_det),2,".","");
			$_POST['couponCode']=$_SESSION['couponCode_det']['ccCode'];
			$success_message	= CODE_APPLY_SUCCESS_TEXT;
                        $success_message	= str_replace("{CODE}", $couponCode, $success_message);

	}else{
                             
                            if(isset($_SESSION['couponCode_det']) && $_SESSION['couponCode_det']!='' ){
                                unset($_SESSION['couponCode_det']);
                                
                                $_SESSION['couponCode_det'] = '';
                            }  
                            $message= INVALID_COUPON_CODE_TEXT;
            }
	}
else if(isset($_POST['couponCodeButn']) && $_POST['couponCode']==''){
	$message= ENTER_COUPON_CODE_TEXT;
}
//Shipping Total is calculated in shipping options page and passed as a session - Santhosh
$shipping_cost = $_SESSION["SHIPPING_TOTAL"];
//$cartAmount=$display_total + $shipping_cost;

//=================================================Tax Calculation========================
if($enable_tax==1)
	{ // check enable tax
		 $sql="select * from ".$tableprefix."taxrate  WHERE (vState LIKE '%".$txtBillingState."%'
				 AND vtaxaddress = 'billing' AND vState!='1') OR (vState LIKE '%".$txtShippingState."%' AND vtaxaddress = 'shipping' AND vState!='1')
				 OR (vCountry LIKE '%".$txtBillingCountry."%' AND vtaxaddress = 'billing' AND vState='1') OR
				 (vCountry LIKE '%".$txtShippingCountry."%' AND vtaxaddress = 'shipping' AND vState='1') AND rate_enable='1' Limit 0,1";
		$rs=mysql_query($sql) or die(mysql_error());
		if(mysql_num_rows($rs)>0)
		{
			$rr=mysql_fetch_array($rs);
			$taxpercentage=$rr['ntaxrate'];
			$tname=stripslashes($rr['taxname']);
			$tbase=$rr['vtaxbase'];

	} // end row check


} // end enbale tax



// Calculate Tax
$_SESSION["TAX_DETAILS"] = array();
$_SESSION["TAX_TOTAL"] = 0;

$select_cart_details  = "SELECT c.*, p.product_name,(p.product_price+po.additional_price) AS product_price,po.discount,p.product_artist_id
					FROM ".$tableprefix."cart c
                                        INNER JOIN ".$tableprefix."product_options po ON po.product_option_id = c.product_option_id
                                        INNER JOIN ".$tableprefix."products p ON p.product_id = po.product_id
					WHERE c.user_id = '".addslashes($_SESSION["sess_userid"])."'";

$result_cart_details = mysql_query($select_cart_details) or die(mysql_error());

$product_price =0;
$product_rate  = 0;

while($rw = mysql_fetch_array($result_cart_details))
	{


                                 $conversionRate	= 	ConvertedCurrencyRate($currency_attributes[2]);
				 $converted_price 	= 	$rw['product_price'] * $conversionRate;

				 $product_rate = $converted_price;
				/*------------Multicart 2.0 Upgradation------------*/
                                $product_option_id = $rw["product_option_id"];
				$qty = $rw["quantity"];
				$product_price  = $qty * $product_rate;

				if($rw["discount"] !=0){

				$discountprice                  = $product_rate-($product_rate*$rw["discount"])/100;
				$discountrate                   = ($discountprice*$qty);
				$product_price                  = $discountrate;

				}


                               // echo "<br>".$_SESSION["SHIPPING_DETAILS"][$product_option_id]['rate'];
                                if($enable_tax=="1")
                                { // check taxrate activated for each state
                                        if($tbase=="Subtotal")
                                        {
                                                $taxrate=$product_price * ($taxpercentage/100);
                                        }

                                        if($tbase=="Subtotal and Shipping")
                                        {   //echo $_SESSION["SHIPPING_DETAILS"][$product_option_id]['rate'];
                                            if(!empty($_SESSION["SHIPPING_DETAILS"])) {
                                            $product_price = $product_price + $_SESSION["SHIPPING_DETAILS"][$product_option_id]['rate'] ;
                                            }
                                            $taxrate = ($product_price + $shipping_cost) * ($taxpercentage/100);
                                           
                                        }
                                }

                                 if($enable_tax=="2")
                                { // check default tax rate activated

                                    $taxrate=$product_price*($taxpercentage/100);
                                }

                                $_SESSION["TAX_DETAILS"][$product_option_id]= number_format($taxrate,2,".","");

                                $_SESSION["TAX_TOTAL"]+=$_SESSION["TAX_DETAILS"][$product_option_id];


}
//echo $product_price + $shipping_cost;
if($enable_tax=="1")
{   // check taxrate activated for each state
	if($tbase=="Subtotal")
	{
		$taxrate = number_format(getCartTotal($userid),2,".","") * ($taxpercentage/100);
	}

	if($tbase=="Subtotal and Shipping")
	{  
		$taxrate = (number_format(getCartTotal($userid),2,".","") + $shipping_cost) * ($taxpercentage/100);		 
	}
}

if($enable_tax=="2")
{ // check default tax rate activated
	//$taxrate=$product_price*($taxpercentage/100);   multicart2.6 bug fix
        $taxrate= number_format((getCartTotal($userid)*$taxpercentage/100),2,".","");
}

//$_SESSION["TAX_DETAILS"][$product_option_id]= number_format($taxrate,2,".","");
$_SESSION["TAX_TOTAL"] = $taxrate;
// End Tax
//=========================If rate per state is not activated and default rate is activated


$exchangeRate=getCurrencyrate($currency_attributes[2]);
//===========================================
if($_SESSION["TAX_TOTAL"]!=0)
{ // if tax rate is not null include tax rate

	$taxrates = $_SESSION["TAX_TOTAL"];
}

$_SESSION['session_taxrate']=$taxrates;

// if Gift Certificate Order placed

 $objGiftCart                 =     Cart::getGiftCertificateItemsCartCount($_SESSION["sess_userid"],$visitorId);
                 if($objGiftCart->status==SUCCESS)
                 {
                        $cartGiftObjVal         =    $objGiftCart->data;
                        $cartGiftCount          =    $cartGiftObjVal->gift_count;  
                 }
                 
if($cartGiftCount>0)
{

	$_SESSION['session_taxrate']	='';
	$_SESSION['SHIPPING_TOTAL']	='';
	//cartClearDigital($userid);
}



//===============================End Tax Calulation===================================

/*function call to fetch details from site settings*/


//echo "hi".$_SESSION['SESS_digital_product'];exit;

if($cartGiftCount<=0)
{
		if($_SESSION['SESS_upscost']!='')
		{
				if($_SESSION["sessBillingFirstName"]=='' || $_SESSION["sessBillingEmail"]=='' || $_SESSION["sessShippingFirstName"]=='' || $_SESSION["sessShippingEmail"]=='')
				{
					$_SESSION["sess_addresses_collected"] = false;

					header("Location:checkout.php");
					exit;

				}
		}
}

$display_total=number_format(getCartTotal($_SESSION["sess_userid"]),2,".","");
?>

<script language="javascript">

function validateForm()
{
	if(confirm("<?php echo PROCEED_PAY_TEXT; ?>"))
	{
		return true;
	}
	else
	{
		return false;
	}
}
</script>

<div class="main_body">
	<div class="container">
		<div class="row">

			<!--mainbody area start -->

			<div align="left" id="body_left_area">
				<!--body left area start -->



			<!--categories area start -->

<?php

	//include_once("includes/categorylist.php");

?>

			<!--categories area end -->

			<!--body left area end -->
				</div>

		<!--center content area start-->
		<!--items display area start -->
		<section class="sec_marg">
		<div class="col-sm-12 col-lg-12 col-md-12 ">
			<h3><?php $pageCaption = PAYMENT_OPTION_TITLE; echo str_replace("{CURRENCY}", $adminCurrency['currency_code'], $pageCaption); ?></h3>
		</div>
		</section>
		<div class="clear"></div>
		<div class="col-sm-12 col-lg-12 col-md-12 " id="item_details">
		<div class="success_message"><br><?php echo $success_message ;?></div>

		<div class="text_information" align="center"><?php echo $message?></div>	
		
                <div>
                    <h3><?php echo SHOPPING_CART_TEXT; ?></h3>
                    <table>
                        <tr><td><?php echo PRODUCTS_TEXT; ?></td>
                            <td><?php echo QUANTITY_TEXT; ?></td>
                            <td><?php echo PRICE_TEXT; ?> </td>
                            <td><?php echo SHIPPING_FEE; ?></td>
                        </tr>
                        <?php $previous_seller_id = 0;
                        foreach ($cartItems as $key => $value) {
                        $seller_name = (!empty($value->sellername)) ? ucfirst($value->sellername) : ucfirst($value->artist_name); 
                        $seller_state = getCodeValue($value->state,2,$value->country);   
                        $seller_country = getCodeValue($value->country,1);
                        
                         // Currency Conversion                             
                        $conversionRate = ConvertedCurrencyRate($currency_attributes[2]);
                        $converted_price = $value->product_price * $conversionRate;
                        $rate = $converted_price;
                        $qty = $value->quantity;
                        $price = $qty * $rate;
                        $discountstr = "";
                        $discountprice = 0;
                        if ($value->discount != "0") {
                            $price = number_format($price, 2, ".", "");
                            $discountprice = $rate - ($rate * $value->discount) / 100;
                            $discountprice = number_format($discountprice, 2, ".", "");
                            $discountrate = ($discountprice * $qty);
                            $price = $discountrate;
                            
                        }
                        $total += $price;
                        // End currency Conversion           
                        if($previous_seller_id != $value->seller_id){ ?>
                        <tr><td colspan="4"><?php echo $seller_name.", ".$seller_state.", ".$seller_country;  ?></td></tr>
                        <?php } ?>
                             <tr>
                                 <td><?php echo $value->product_name;?></td>
                                 <td><?php echo $value->quantity;?></td>
                                 <td><?php echo $currency_attributes[0]. "&nbsp;" . number_format($price, 2, ".", "");?></td>
                                 <td><?php echo $_SESSION['product_shipping_cost'][$value->product_id]?></td>
                            </tr>
                        <?php 
                        $previous_seller_id = $value->seller_id;
                        }                          			
			  $usershipping	=number_format($shipping_cost,2,".","");
			  $display_user_shipping=ConvertedCurrencyRate($currency_attributes[2]) * $usershipping;
			 ?>
                            <?php /*<tr><td colspan="2"><?php echo SHIPPING_COST_TEXT;?>&nbsp;</td><td colspan="3" align="right"><?php echo $currency_attributes[0] . "&nbsp;" . number_format($shipping_cost, 2, ".", ""); ?></td></tr> */?>
                    </table>
                </div>
                <h4 class="paymenthd"><?php echo PAYMENT_DETAILS_TEXT; ?></h4>
                <?php
		// Scripts for Gift Certificate starts here.
		if($chkGiftPay=="Y" &&   !checkGiftProductsExistsinCart($userid))
		{
		?>
		<div class="search_list_box">
				<div class="row">
		

				<div class="search_list_box_row">
					<div class="col-sm-12 col-lg-12 col-md-12">
						<div class="field_wrapper formfield_row"><?php echo SAME_SELLER_GIFT_TEXT; ?></div>
					</div>
				</div>
				<div class="clear"></div>
				<div class="search_list_box_row">
					<form name="frmGiftCertificate" method="post">
					<div class="col-sm-12 col-lg-2 col-md-2">
						<div class="field_wrapper formfield_row">
		  						<?php echo GIFT_CODE_TEXT; ?>
						</div>
					</div>
					<div class="col-sm-12 col-lg-5 col-md-5">
						<div class="field_wrapper formfield_row">
                                                    <input type="text" style="text-align: left !important;" name="txtgiftCode" id="couponCode" size="40" class="form-control" maxlength="40" value="<?php echo $_POST['txtgiftCode'];?>">
						</div>
					</div>
					<div class="col-sm-12 col-lg-5 col-md-5" >
						<div class="field_wrapper formfield_row">
						<input type="submit" name="btngiftCode" value="<?php echo APPLY_BUTTON; ?>" class="button btn_code">
		<?php if($_SESSION['sess_giftcertificate_available_amt']>0) { ?> &nbsp;	&nbsp;  <input type="submit" name="btngiftRemove" value="<?php echo GIFT_REMOVE_BUTTON; ?>" class="button"> <?php } ?>
						</div>
					</div>
				   </form>

				</div>
				<div class="clear"></div>
				
				<div class="col-sm-12 col-lg-12 col-md-12">
					<div class="hr_line"></div>
				</div>
				
				<?php

                }
		// Scripts for Gift Certificate ends here.
		?>
		  	<?php
			// Scripts for coupon code starts here.

			if($chkCouponPay=="Y" && !checkGiftProductsExistsinCart($userid) ){
			 ?>
				<div class="search_list_box_row">
					<form name="couponCodeForm" method="post">
					<div class="col-sm-12 col-lg-2 col-md-2">
						<div class="field_wrapper formfield_row">
								<?php echo COUPON_CODE_TEXT; ?>
						</div>
					</div>
					<div class="col-sm-12 col-lg-5 col-md-5">
						<div class="field_wrapper formfield_row">
							<input type="text" style="text-align: left !important;" name="couponCode" id="couponCode" size="40" class="form-control btn_code" maxlength="40" value="<?php echo $_POST['couponCode'];?>">
						</div>
					</div>
					<div class="col-sm-12 col-lg-5 col-md-5">
						<div class="field_wrapper formfield_row">
						<input type="submit" name="couponCodeButn" value="<?php echo RECALCULATE_BUTTON; ?>" class="button btn_code">
							  <?php if(isset($_SESSION['couponCode_det']) && $_SESSION['couponCode_det']!='' )
								{
								  ?>
									&nbsp;&nbsp;<input type="submit" name="couponCodeRemoveButn" value="<?php echo COUPONCODE_REMOVE_BUTTON; ?>" class="button">
							  <?php
								 }
								?>	 
						</div> 
					</div>
					</form>
				</div>
					
		
		
				<div class="clear"></div>
				</div>
			<div class="clear"></div>
			</div>
<?php }// Scripts for coupon code ends here.?>

		<table  cellpadding="2" cellspacing="2" width="100%" border="0">
		
		<tr>
		  <td>
		  <div class="payments_styles">
		  <table width="100%"  border="0"  align="center" cellpadding="2" cellspacing="2">

                      <?php
                        $giftCertificateDiscountAmount    =   0;
                        $couponcodeDiscountAmount         =   0;
                        
                        $totalDiscountAmount              = 0;
                        
                      
			 if($_SESSION['sess_giftcertificate_available_amt']>0)
			{
                             $giftCertificateDiscountAmount = $_SESSION['sess_giftcertificate_available_amt'];  
                             $_SESSION['sess_gift_amount_used'] =   $_SESSION['sess_giftcertificate_available_amt'];
			 ?>

			 <tr>
              <td width="56%" align="right" class="specialmessage"><?php echo GIFT_AMT_TEXT; ?> </td>
              <td width="44%" class="specialmessage">
			  &nbsp;<?php echo  $adminCurrency['currency_symbol']."&nbsp;".number_format($_SESSION['sess_giftcertificate_available_amt'],2,".","");?>
			  <?php if($adminCurrency['currency_code']!=$currency_attributes[2])
			 			 {
						 	$conversionRate_gift	= 	ConvertedCurrencyRate($currency_attributes[2]);
							$converted_gift_total 	= 	number_format($_SESSION['sess_giftcertificate_available_amt'],2,".","") * $conversionRate;
			 			 ?>
						  &nbsp; ( <?php echo $currency_attributes[0]."&nbsp;".number_format($converted_gift_total,2,".","");?> )

			       <?php } ?>

			  </td>
            </tr>
			<?php } ?>
            
			
            <tr>
              <td width="56%" align="right"><?php echo ITEM_TOTAL_COST_TEXT; ?></td>
              <td width="44%">&nbsp; <?php echo $adminCurrency['currency_symbol'];?> <?php echo number_format(getCartTotal($userid),2,".","");?>
			   <?php if($adminCurrency['currency_code']!=$currency_attributes[2])
			  {
			  ?>
			  &nbsp; ( <?php echo $currency_attributes[0]."&nbsp;".number_format((getUserCurrencyCartTotal($userid)),2,".","");?> )

			  <?php } ?>
			  </td>
            </tr>
            
            <?php if($_SESSION['couponCode_det']['ccDiscount']!='')
			{
                                $couponcodeDiscountAmount   =  getCartTotalcouponCodeDicountamount($userid,$_SESSION['couponCode_det']); 
			?>

            <tr>
              <td width="56%" align="right" class="specialmessage"><?php echo COUPON_CODE_TEXT1; ?> ' <?php echo $_SESSION['couponCode_det']['ccCode'] ?>' <?php echo DISCOUNT_TEXT; ?></td>
              <td width="44%" class="specialmessage">&nbsp; <?php echo $adminCurrency['currency_symbol']."&nbsp;".number_format($couponcodeDiscountAmount,2,".","");?> &nbsp; ( <?php echo $_SESSION['couponCode_det']['ccDiscount'];?> %  <?php echo COUPON_PERCENTAGE_TEXT ;?>)  </td>
            </tr>

			<?php } ?>
            
			<?php if($_SESSION['couponCode_det']['ccDiscount']!='' || $_SESSION['sess_giftcertificate_available_amt']>0){
                                   
                                   $cartTotalAmount =    getCartTotal($userid);
                                   
                                   $totalDiscountAmount =   $giftCertificateDiscountAmount + $couponcodeDiscountAmount;
                                   
                                 
                                   if($cartTotalAmount > $totalDiscountAmount)
                                   {                                                                   
                                       //$totalDiscountAmount     =   number_format($totalDiscountAmount,".","");
                                       $cartTotalAmountAfterDiscount  =  ($cartTotalAmount-$totalDiscountAmount) ;
                                       
                                   }
                                   
                                    
                                   $display_total       =   number_format($cartTotalAmountAfterDiscount,2,".","");
                            ?>

            <tr>
              <td width="56%" align="right" class="specialmessage"><?php echo ITEM_TOTAL_COST_DISCOUNT_TEXT; ?></td>
               <td width="44%" class="specialmessage">&nbsp; <?php echo $adminCurrency['currency_symbol'];?> <?php echo number_format($cartTotalAmountAfterDiscount,2,".","");?>
			   
			  </td>
            </tr>

			<?php  } ?>
            
         
            
                    <?php
			 
			if($hide_shipping_division==1)
			{ // check if the products are digital not  products
			if(!empty($shipping_cost))
			{ // check shipping cost available or not
			?>
            <tr>
              <td align="right"><?php echo SHIPPING_COST_TEXT; ?></td>
             <td>&nbsp;<?php echo $adminCurrency['currency_symbol'];?>

			  <?php
			  $usershipping	=number_format($shipping_cost,2,".","");
			  $display_user_shipping=ConvertedCurrencyRate($currency_attributes[2]) * $usershipping;
			  echo number_format($shipping_cost,2,".","");?>

			  <?php if($adminCurrency['currency_code']!=$currency_attributes[2])
			  {
			  ?>
			    &nbsp; ( <?php echo  $currency_attributes[0]."&nbsp;"?>
				<?php
					   echo number_format($display_user_shipping,2,".","");
				 ?> )
				<?php } ?>
			  </td>
            </tr>
			<?php
			}
				}

			// end check ?>


			<?php

                        if(checkGiftProductsExistsinCart($userid))
                        {
                                $shipping_cost =	0;
                                $taxrates		=	0;

                        }

			 if($enable_tax==1)
			 { // check taxrate activated for each state
					if($_SESSION["TAX_TOTAL"]!=0)
					{ // if tax rate is not null include tax rate

					?>
					<tr>
					  <td align="right"><?php echo $tname;?> <?php echo INCLUDE_TOTAL_TEXT; ?></td>
					  <td>&nbsp; <?php echo $adminCurrency['currency_symbol']."&nbsp;".number_format($_SESSION["TAX_TOTAL"],2,".","");?>
					   <?php if($adminCurrency['currency_code']!=$currency_attributes[2])
			 			 {
						 	$conversionRate	= 	ConvertedCurrencyRate($currency_attributes[2]);
							$converted_tax 	= 	$_SESSION["TAX_TOTAL"] * $conversionRate;
			 			 ?>
						  &nbsp; ( <?php echo $currency_attributes[0]."&nbsp;".number_format($converted_tax,2,".","");?> )

			       <?php } ?>

					  </td>
					</tr>
					<?php
					} // end if
				} // end if
		?>
		<?php
			 if($enable_tax==2)
			 { // check default tax rate activated                            
					if($_SESSION["TAX_TOTAL"]!=0)
					{ // if tax rate is not null include tax rate

					?>
					<tr>
					  <td align="right"> <?php echo TAX_INCLUDE_TOTAL_TEXT; ?></td>
					   <td>&nbsp;&nbsp; <?php echo  $adminCurrency['currency_symbol']."&nbsp;".number_format($_SESSION["TAX_TOTAL"],2,".","");?>
					   <?php if($adminCurrency['currency_code']!=$currency_attributes[2])
			 			 {
						 	$conversionRate	= 	ConvertedCurrencyRate($currency_attributes[2]);
							$converted_tax 	= 	$_SESSION["TAX_TOTAL"] * $conversionRate;
			 			 ?>
						  &nbsp; ( <?php echo $currency_attributes[0]."&nbsp;".number_format($converted_tax,2,".","");?> )

                                            <?php } ?>
					  </td>
					</tr>
					<?php
					} // end if
			} // end if



		?>



              <tr>
              <td width="56%" align="right"><?php echo ORDER_TOTAL_TEXT; ?>   </td>
              <td width="44%">&nbsp;<?php echo  $adminCurrency['currency_symbol']."&nbsp;".number_format($display_total+$shipping_cost+$_SESSION["TAX_TOTAL"],2,".","");?>
				  <?php if($adminCurrency['currency_code']!=$currency_attributes[2])
			 			 {
						 	$c_total			=	$display_total+$shipping_cost+$_SESSION["TAX_TOTAL"];
						 	$conversionRate		= 	ConvertedCurrencyRate($currency_attributes[2]);
							$converted_total 	= 	$c_total * $conversionRate;
			 			 ?>
						  &nbsp; ( <?php echo $currency_attributes[0]."&nbsp;".number_format($converted_total,2,".","");?> )

			       <?php } ?>
			  </td>
            </tr>

		



            <tr class="button">
			<td align="right"><strong><?php echo AMT_PAY_TEXT; ?> </strong></td>
			 <td>&nbsp;
			 <?php
			 $total_cost=       $display_total+$shipping_cost+$_SESSION["TAX_TOTAL"];
					 // Gift Certificate Amount Calculation
					/* if($_SESSION['sess_giftcertificate_available_amt']>0)
					 {

							 if($total_cost>$_SESSION['sess_giftcertificate_available_amt'])
							 {
								$total_display_cost					=	$total_cost - $_SESSION['sess_giftcertificate_available_amt'];

								$_SESSION['sess_gift_amount_used']	=			$_SESSION['sess_giftcertificate_available_amt'];

								$amount_to_pay						=		$total_display_cost;

							 }
							 else
							 {
									$_SESSION['sess_gift_amount_used']	=	$total_cost;
									$amount_to_pay						= 0;
							 }

					 }

					 else
					 {

						$amount_to_pay			=	$total_cost;
					 }*/
                                       $amount_to_pay                   =   $total_cost;
                                       
                                       $_SESSION['amount_paid']	= $amount_to_pay;
                                       
			 // End Gift Certificate Calculation
			 echo  $adminCurrency['currency_symbol']."&nbsp;".number_format($amount_to_pay,2,".","");?>

			    <?php if($adminCurrency['currency_code']!=$currency_attributes[2])
			 			 {
						 	$conversionRate				= 	ConvertedCurrencyRate($currency_attributes[2]);
							$converted_amount_to_pay 	= 	$amount_to_pay * $conversionRate;
			 			 ?>
						  &nbsp; ( <?php echo $currency_attributes[0]."&nbsp;".number_format($converted_amount_to_pay,2,".","");?> )

			       <?php } ?>

			  </td>
		    </tr>

                   

                   
          </table>
		  <div class="clear"></div>
		  </div>
		  </td>
		  </tr>
                  
		</table>

<?php if($amount_to_pay>0) {

?>

		<div class="payment_page_options">
<?php
	if($enableBuyerToSeller == "Y"){
?>
		<table cellpadding="0" border="0" cellspacing="0" width="100%">
<?php

	if($chkPaypal == "Y")
	{
 ?>
		<tr>
		  <td align="center"><?php echo CLICK_PAYPAL_ORDER_TEXT; ?></td>
		  </tr>
		<tr>
			<td align="center">

		<a href="paypal-parallel-payment.php?paymentMethod=PP"><img src="images/pp.jpg" alt="<?php echo CLICK_PAYPAL_ORDER_TEXT; ?>" border="0" title="<?php echo PAYPAL_PAYMENT_LOGO_TITLE; ?>" ></a>

<br>
<?php echo PAYMENT_NOTE_TEXT; ?>
                        </td>
                </tr>
        <?php
	 }
?>

<?php

	if($chkPaypal != "Y" && $chkWorldpay  != "Y" && $chkGoogleCheckout != "Y" && $chkYourpay != "Y" && $chkAuthorize != "Y")
	{
?>


		<tr>
			<td class="text_information"><?php echo PAYMENT_DISABLED_ADMIN_TEXT; ?></td>
		</tr>
		<tr>
			<td align="center"><input type="button" class="button" name="back" value="<?php echo BACK_TEXT; ?>" onClick="Javscript:history.go(-1);"></td>
		</tr>
<?php

	}

?>

		<tr>
			<td>&nbsp;</td>
		</tr>

</table>

<?php }else {?>
<table cellpadding="0" border="0" cellspacing="0" width="100%">
<?php

	if($chkPaypal == "Y")
	{
 ?>
		<tr>
		  <td align="center"><?php echo CLICK_PAYPAL_ORDER_TEXT; ?></td>
		  </tr>
		<tr>
			<td align="center">

		<a href="pay.php?paymentMethod=PP"><img src="images/pp.jpg" alt="<?php echo CLICK_PAYPAL_ORDER_TEXT; ?>" border="0" title="<?php echo PAYPAL_PAYMENT_LOGO_TITLE; ?>" ></a>

<br>
<?php echo PAYMENT_NOTE_TEXT; ?>
                        </td>
	</tr>
	<tr>
		<td>&nbsp;</td>
	</tr>
<?php
	 }

	if(($chkAuthorize == "Y" || $chkYourpay=="Y" || $chkBluepay=="Y" ) &&   $adminCurrency['currency_code']=='USD'){ 
 ?>

	<tr>
            <td align="center" style="text-align:center; ">
                              <?php echo CREDIT_CARD_PAY_TEXT; ?><br>
    <?php
                    $secureurl = SECURE_SITE_URL."/payment.php";
    ?>
                    <a href="<?php echo $secureurl?>"><img src="images/cc.gif" valign="top" title="<?php echo PAY_CARD_TEXT; ?>" border="0" ></a>
            </td>
	</tr>
        <tr>
			<td>&nbsp;</td>
	</tr>
<?php
	}

?>
		<?php if($chkWorldpay =="Y" && $enableBuyerToSeller == "N") {?>
		<tr>
                    <td align="center">
                    <a href="worldpaypayment.php?payment=WP"><img src="images/worldpay.gif" width="139" height="33" border="0"  title="<?php echo WORLDPAY_PAYMENT_LOGO_TITLE; ?>"></a>
                    </td>
		</tr>
		<tr>
		  <td align="center">&nbsp;		    </td>
		</tr>
		<?php
		}
                if($chkGoogleCheckout  =="Y" && $enableBuyerToSeller == "N") {
                ?>
		<tr>
			<td align="center">
                                <a href="google_checkout_payment.php"><img src="images/google_checkout.gif"  border="0" title="<?php echo GC_PAY_GATEWAY_TEXT; ?>"></a>
                        </td>
		</tr>
		<tr>
			<td>&nbsp;</td>
		</tr>
                <?php
                }
                if($chkGiftPay == "Y" && $_SESSION['gift_certificate_flag'] == "N")
                {
                ?>
		<tr>
			<td align="center"><a href="giftcoupon_payment.php"><img src="images/giftcoupon_payment.jpg" border="0" title="<?php echo PAY_GIFT_TEXT; ?>"></a></td>
		</tr>
                <?php
                }
               if($chkPaypal != "Y" && $chkWorldpay  != "Y" && $chkGoogleCheckout != "Y" && $chkYourpay != "Y" && $chkAuthorize != "Y")
                {
                ?>
		<tr>
			<td class="text_information"><?php echo PAYMENT_DISABLED_ADMIN_TEXT; ?></td>
		</tr>
		<tr>
			<td align="center"><input type="button" class="button" name="back" value="Back" onClick="Javscript:history.go(-1);"></td>
		</tr>
                <?php
                }
                ?>
		<tr>
			<td>&nbsp;</td>
		</tr>

</table>
<?php }?>

</td>
</tr>
</table>

</div>
<?php
}
else
{
?>
  <div class="payments_styles">
<form method="post" action="completeorder.php">
<table cellpadding="0" cellspacing="0" border="0" width="50%" align="center">
<tr>
<td align="center">
<input type="submit"  name="btnCompleteOrder" value="<?php echo ORDER_COMPLETE_TEXT; ?>" class="button" onClick="return validateForm();" tabindex="5">
 </td>
</tr>
</table>
</form>
</div>
<?php
}
?>
	<div align="left" class="float_clear1"></div>
	 <!--items display area end -->
	  </div>
	<!--center content area end-->
	<div align="left" class="clear"></div>
	<!--mainbody area end -->
	</div>
	</div>
	</div>
	<div align="left" class="clear"></div>
<?php
include "includes/".$active_template[2];	/* Bottom File Name */
?>