<?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 "includes/arrays.inc.php";
set_time_limit(0);
$shippingMode=$_SESSION["sessShippingMethod"];
$adminCurrency	= GetAdminCurrency();
//session_unregister("sess_addresses_collected");
if(isset($_SESSION["sess_userid"]) && $_SESSION["sess_userid"]!= "") {
    $userid = $_SESSION["sess_userid"];
    if(isCartEmpty($userid)) {
        header("Location:viewcart.php");
        exit;
    }
}else {
    header("Location:viewcart.php");
    exit;
}
if (get_magic_quotes_gpc()) {
    $_POST = array_map('stripslashes_deep', $_POST);
    $_GET = array_map('stripslashes_deep', $_GET);
    $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
}

$uspsRequired_Service =  array("Express Mail","Express Mail Hold For Pickup","Express Mail Sunday/Holiday Delivery","Priority Mail","Parcel Post","Priority Mail Large Flat Rate Box","
Priority Mail Express 2-Day","Priority Mail 2-Day","Priority Mail 2-Day Small Flat Rate Box","Media Mail","Library Mail");


//===================Getting Currency Type=========================
$currency_attributes = displayCurrencyType();

$flatrateEnabled=getSettingsValue('enable_flatrate');
/*display the active template*/

//checking shipping gateway and doing basic settings - Santhosh

switch($_SESSION["sessShippingMethod"]) {
    CASE "FDXE":
    CASE "FDXG":
require_once 'library/class.fedex.php';
require_once 'library/class.fedex.rate.php';
require_once 'library/class.fedex.package.php';
ini_set("soap.wsdl_cache_enabled", "0");
        
    $sql="select * from ".$tableprefix."fedexsettings ";
        $rs=mysql_query($sql) or die (mysql_error());
        if(mysql_num_rows($rs)>0) {
            $serviceName=array();
            $row=mysql_fetch_array($rs);
            $fedexaccno=stripslashes($row['FedexAccno']);
            $fedexmeterno=stripslashes($row['FedexMeterno']);
            $weightunits=$row['FedexWeight'];
            $server=$row['FedexServer'];
            $dropoff=stripslashes($row['FedexDropOff']);
            $packageTypes=stripslashes($row['FedexPackage']);
            $fedexPassword = stripslashes($row['FedexPassword']);
            $fedexKey = stripslashes($row['FedexKey']);
            $sName=$row['FedexService'];
            $currency=$row['FedexCurrency'];
            if($_SESSION["sessShippingMethod"]=="FDXE") {
                $sarry=$fedexService;
                $shippingTitle = "Fedex Express Shipping";
            }
            else {
                $sarry=$fedexGroundService;
                $shippingTitle = "Fedex Express Ground Shipping";
            }
            
                $objRates   = new stdClass();
                $objRates->ship_account =trim($fedexaccno);
                $objRates->meter = trim($fedexmeterno);
                $objRates->password = trim($fedexPassword);
                $objRates->account         =    "";
                $objRates->bill_account         =    "";
                $objRates->duty_account         =    "";
                $objRates->account_to_validate  =    "";
                $objRates->track_account        =    "";
                $objRates->key                  =   trim($fedexKey);
                
                switch($server) {
            case "test":
                $fedexserver="https://gatewaybeta.fedex.com/GatewayDC";
                $objRates->wsdl_path                =   "RateService_v13_Test.wsdl";
                break;
            case "production":
            // change this to actual server when go on live
                $fedexserver="https://gateway.fedex.com/GatewayDC";
                $objRates->wsdl_path                =   "RateService_v13.wsdl";
                break;
            default:
                $fedexserver="https://gatewaybeta.fedex.com/GatewayDC";
                $objRates->wsdl_path                =   "RateService_v13_Test.wsdl";
                break;
        }
              
        

                $objRate = new fedexRates();
                $objRate->requestType("rate");

                $objRate->setData($objRates);

                $objRate->wsdl_root_path = "wsdl/";
                
               $client = new SoapClient($objRate->wsdl_root_path.$objRate->wsdl_path, array('trace' => 1));


        } // end num rows check
    break;

    CASE "USPS":
//// check enabled shipping is usps or not
        include_once("usps/xmlparser.php");
        include_once('usps/usps.php');
        $shippingTitle = "USPS";
        $sql="select * from ".$tableprefix."usps_settings ";
        $rs=mysql_query($sql) or die (mysql_error());
        if(mysql_num_rows($rs)>0) {
            $row=mysql_fetch_array($rs);
            $uspsid=$row['username'];
            $server=$row['server'];
        }	// end num rows check
        switch($server) {
            case "test":
                $uspsserver="http://testing.shippingapis.com/ShippingAPITest.dll";
                break;
            case "production":
            //change this line when usps is on live
                $uspsserver="http://Production.ShippingAPIs.com/ShippingAPI.dll";
                break;
            default :
                $uspsserver="http://testing.shippingapis.com/ShippingAPITest.dll";
                break;
        } // end switch




        break;
    CASE "UPS":
        require("ups.php");
        include_once("shipping.php");
        include_once('http_client.php');
        $shippingTitle = "UPS";
// Shipping setting for UPS Shipping
        $select_shipping_settings = "SELECT * FROM ".$tableprefix."shipping_settings";
        $result_shipping_settings = mysql_query($select_shipping_settings);
        if(mysql_num_rows($result_shipping_settings)>0) {
            $rs_ship=mysql_fetch_array($result_shipping_settings);
            $ups_weight=$rs_ship['nShippingweight'];
            $ups_rate=$rs_ship['ups_rate'];
            $ups_container=$rs_ship['container_type'];
            $ups_type=$rs_ship['address_quote_method'];

        }
        $upsrate = new Ups;
        break;
    CASE "AP":
        $shippingTitle = "Australian Post";
//$australianServiceArray  = array("STANDARD"=>"Standard Post","EXPRESS"=>"Express Post","AIR"=>"Air Post","SEA"=>"Sea Post","ECONOMY"=>"Economy Post");
        $australianServiceArray  = array("STANDARD"=>"Standard Post","EXPRESS"=>"Express Post","AIR"=>"Air Post","SEA"=>"Sea Post");
        break;
    CASE "CP":
        require_once("includes/class.canadapost.php");
        $shippingTitle = "Canada Post";
        break;
    CASE "Flat Rate":
        $shippingTitle = "Our Shipping";
    DEFAULT:

}
// end usps check
$active_template = displayTemplate();
include "includes/htmltop.php";
/* Top File Name */
include_once ("includes/".$active_template[0]);
//===============================================Check if Button pressed or not =========================================
$select_cart_details = "SELECT prd.product_id,prd.product_name,po.product_option_id,po.product_length,po.product_width,po.product_height,crt.quantity,
                       po.product_shipping_weight,art.country AS origin_country,art.state AS origin_state,art.zip AS origin_zip,art.artist_id,
                       art.defaultflatrate,art.additionalflatrate
                       FROM ".$tableprefix."cart crt
                       INNER JOIN ".$tableprefix."product_options po ON crt.product_option_id = po.product_option_id
                       INNER JOIN ".$tableprefix."products prd ON prd.product_id = po.product_id
                       INNER JOIN ".$tableprefix."artists art ON art.artist_id = prd.product_artist_id
                       WHERE crt.user_id = ".$_SESSION["sess_userid"]." ORDER BY crt.cart_id";
$result_cart_details = mysql_query($select_cart_details) or die(mysql_error());
$_SESSION["SHIPPING_DETAILS"] = array();
$_SESSION["SHIPPING_TOTAL"] = 0;
if(isset($_POST['proceed'])) {
    if(mysql_num_rows($result_cart_details)) {
        while($cartObj = mysql_fetch_object($result_cart_details)) {
            $shipVal = $_POST["shipping_option_".$cartObj->product_option_id];
            if($shipVal !="") {
                $shipValArr = explode('=>',$shipVal);
                $_SESSION["SHIPPING_DETAILS"][$cartObj->product_option_id] = array("preffered_shipping"=>$shipValArr[0],"rate"=>$shipValArr[1]);
                $_SESSION["SHIPPING_TOTAL"] += $shipValArr[1];
            }else {
                $_SESSION["SHIPPING_DETAILS"][$cartObj->product_option_id] = array();
            }

        }
    }

    echo '<script>window.location.href="paymentoptions.php";</script>';
    exit();
}


$productArray = array();
$resultShippingArray = array();
if(mysql_num_rows($result_cart_details) == 0) {
//as no products there is no point in staying in shipping options
    header("location:viewcart.php");
}else {


    //Now we need to take shipping rates for various products - Santhosh
    while($cart_details_row = mysql_fetch_array($result_cart_details)) {

        $shipping_weight    = trim($cart_details_row['product_shipping_weight']);
        $origin_country     = $cart_details_row['origin_country'];
        $origin_state       = $cart_details_row['origin_state'];
        $origin_zip         = $cart_details_row['origin_zip'];

        $destination_country     = $_SESSION['sessShippingCountry'];
        $destination_state       = $_SESSION['sessShippingState'];
        $destination_zip         = $_SESSION['sessShippingZIP'];

        $product_name       = $cart_details_row['product_name'];
        $artist_id          = $cart_details_row['artist_id'];
        $product_id         = $cart_details_row['product_id'];
        $product_option_id  = $cart_details_row['product_option_id'];
        $optionsStr         = "";
        $optionVal          = getProductOptionsName($product_option_id);
        if($optionVal!="") {
            $optionsStr         = "<br>".$optionVal;
        }
        $productArray[$product_option_id] = $product_name.$optionsStr;
        $quantity           = trim($cart_details_row['quantity']);


        $product_length         = $cart_details_row['product_length'];
        $product_height         = $cart_details_row['product_height'];
        $product_width          = $cart_details_row['product_width'];

        $fedex_shipping_weight  = $shipping_weight * $quantity;

        //set for ups only

        //======================Getting rates for each product from shipping gateways-Santhosh=================================
        switch($_SESSION["sessShippingMethod"]) {

            CASE "FDXE":
            CASE "FDXG":

                 $aryShipper = array(
		'Contact' => array(
			'PersonName' => 'Sender Name',
			'CompanyName' => 'Sender Company Name',
			'PhoneNumber' => '9012638716'),
		'Address' => array(
			'StreetLines' => array('Address Line 1'),
			'City' => $origin_city,
			'StateOrProvinceCode' => $origin_state,
			'PostalCode' => $origin_zip,
			'CountryCode' => $origin_country)
	);

   $aryRecipient = array(
		'Contact' => array(
			'PersonName' => 'Recipient Name',
			'CompanyName' => 'Company Name',
			'PhoneNumber' => '9012637906'
		),
		'Address' => array(
			'StreetLines' => array('Address Line 1'),
			'City' => $destination_city,
			'StateOrProvinceCode' => $destination_state,
			'PostalCode' => $destination_zip,
			'CountryCode' => $destination_country,
			'Residential' => false)
	);
   
   
   $fedexService                      = array('PRIORITY_OVERNIGHT','STANDARD_OVERNIGHT','INTERNATIONAL_PRIORITY','FEDEX_GROUND','FIRST_OVERNIGHT','FEDEX2DAY');

   $rateResponseArr                   = array();
   
   
            foreach($fedexService as $serviceNames) {  
                     $packages = array();

                     $aryPackage = array();

                     $total_packages = 1;
                     
                     if($product_length==0 || $product_length>70)
                     {
                         $product_length = '17.88';
                     }
                     
                      if($product_width==0 || $product_width>70)
                     {
                         $product_width = '12.88';
                     }
                     
                     if($product_height==0 || $product_height>10)
                     {
                         $product_height = '3.00';
                     }
                     

                     $packages[0] = new Package("FEDEX Package # 1", $total_packages, 1);
                     $packages[0]->setPackageWeight($fedex_shipping_weight);     //Package Actual Weight
                     $packages[0]->setPackageDimensions($product_length, $product_width, $product_height);       //Package (Length x Width x Height)
                     $aryPackage[0] = $packages[0]->getObjectArray();

                     $aryOrder = array(
                                     'TotalPackages' => $total_packages,
                                     'PackageType' => 'YOUR_PACKAGING',        #FEDEX_10KG_BOX, FEDEX_25KG_BOX, FEDEX_BOX, FEDEX_ENVELOPE, FEDEX_PAK, FEDEX_TUBE, YOUR_PACKAGING
                                     'ServiceType' => $serviceNames,
                                     'TermsOfSaleType' => "DDU",         #    DDU/DDP
                                     'DropoffType' => 'REGULAR_PICKUP'         # BUSINESS_SERVICE_CENTER, DROP_BOX, REGULAR_PICKUP, REQUEST_COURIER, STATION
                     );

                     $request = $objRate->rateRequest($aryRecipient,$aryShipper,$aryOrder,$aryPackage);


                     $rateResponseArr[]    = $objRate->getRates($request,$client);
                     
                

           }  
 if(!empty($rateResponseArr))  {
    foreach($rateResponseArr as $serviceVals)
     {
       if(@$serviceVals->error=='' && $serviceVals->ServiceName!='') 
        $resultShippingArray[$product_option_id][]= array("service_name"=>@$serviceVals->ServiceName,"rate"=>@$serviceVals->amount);
     }
 }
              
                break;
            CASE "USPS":
                $usps_shipping_weight = $shipping_weight * $quantity;
                if($usps_shipping_weight<1) {
                    $usps_shipping_weight = 1;
                }
                $usps_shipping_weightSplit = explode(".", $usps_shipping_weight);
                $shipping_pounds = $usps_shipping_weightSplit[0];
                $ouncelength     =  count_digit($usps_shipping_weightSplit[1]);
                if($ouncelength == 0) {
                    $shipping_ounces = 0;
                }
                if($ouncelength == 1) {
                    $shipping_ounces = ($usps_shipping_weightSplit[1] / 10) * 16;
                }
                if($ouncelength == 2) {
                    $shipping_ounces = ($usps_shipping_weightSplit[1] / 100) * 16;
                }
                if($ouncelength == 3) {
                    $shipping_ounces = ($usps_shipping_weightSplit[1] / 1000) * 16;
                }
                if($ouncelength == 4) {
                    $shipping_ounces = ($usps_shipping_weightSplit[1] / 10000) * 16;
                }
               
                $usps = new USPS;
                if($server=="test") {
                    $usps->setWeight(10,5);
                    $usps->setDestZip("20008");
                    $usps->setOrigZip("10022");
                }else {
                    $usps->setDestZip($destination_zip);
                    $usps->setOrigZip($origin_zip);
                    $usps->setWeight($shipping_pounds,$shipping_ounces);
                }
                $usps->setServer($uspsserver);
                $usps->setUserName($uspsid);
                $uspspaswd = "";
                $usps->setPass($uspspaswd);
                $usps->setService("All");
                //$usps->setContainer("Flat Rate Box");

                $usps->setCountry("USA");

                $usps->setMachinable("true");

                $usps->setSize("REGULAR");

                $uspsprice = array();

                $uspsprice = $usps->getPrice();
                
                

               $special_chars = "&lt;sup&gt;&amp;reg;&lt;/sup&gt;";
                         if($uspsprice->error->description=="") {
                            foreach($uspsprice->list AS $eachItem) {
                                if($eachItem->mailservice!="" && $eachItem->rate!="") {
                                  //$eachItemServicename = str_replace($special_chars,"",$eachItem->mailservice);
                                   $eachItemServicename  = @htmlspecialchars_decode($eachItem->mailservice);
                                   $eachItemServicename = @preg_replace ("/<sup>(.*?)<\/sup>/i", "", $eachItemServicename);
                                  if(in_array($eachItemServicename,$uspsRequired_Service)) {
                                          $resultShippingArray[$product_option_id][]= array("service_name"=>$eachItemServicename,"rate"=>$eachItem->rate);
                                }
                                }
                            }
                        }
                break;
            CASE "UPS":

                $ups_shipping_weight = $shipping_weight * $quantity;
            
       //Ups Country Code Selection Modification done Bu asha On 26/11/2012
                if($destination_country=='UK')
                    {
                         $destination_country='GB';
                    }

                     if($origin_country=='UK')
                    {
                         $origin_country='GB';
                    }
    // Remove Space from Zip Codes  Modified By Asha ON 22/11/2012
                    
      $destination_zip = preg_replace('/\s+/', '', $destination_zip);

      $origin_zip = preg_replace('/\s+/', '', $origin_zip);
      

                $ups_shipping_weight = ($ups_shipping_weight < 0.1 ? 0.1 : $ups_shipping_weight);
                foreach($ups_types as $types=>$ups) {

                    $upsrate->upsProduct($types); // See upsProduct() function for codes

                    $upsrate->origin($origin_zip,$origin_country); // Use ISO country codes!

                    $upsrate->dest($destination_zip,$destination_country); // Use ISO country codes!

                    $upsrate->rate($ups_rate); // See the rate() function for codes

                    $upsrate->container($ups_container); // See the container() function for codes

                    $upsrate->weight(number_format($ups_shipping_weight,2,".",""));

                    $upsrate->rescom($ups_type); // See the rescom() function for codes

                    $quote = $upsrate->getQuote();

                    if($quote!="error" && $ups!="" && $quote!="") {
                        $resultShippingArray[$product_option_id][]= array("service_name"=>$ups,"rate"=>$quote);
                    }

                    // end price empty check

                }//end foreach
                break;
            CASE "AP":
            //weight in LBS

                foreach($australianServiceArray AS $eachService =>$eachServiceVal) {

                    $query = 'Pickup_Postcode='.$origin_zip;
                    $query .= '&Destination_Postcode='.$destination_zip;
                    $query .= '&Country='.$destination_country;
                    //LBS to gram Conversion - Santhosh thomas Alexander
                    //If the Site is customized and product weight is in grams then no need to convert
                    $query .= '&Weight='.number_format(($shipping_weight*0.454*1000),2);
                    $query .= '&Service_Type='.$eachService;
                    $query .= '&Length='.number_format(($product_length*10),2);
                    $query .= '&Width='.number_format(($product_width*10),2);
                    $query .= '&Height='.number_format(($product_height*10),2);
                    $query .= '&Quantity='.$quantity;
                    if($product_length<15)
                        $product_length = 15;
                    if($product_width<15)
                        $product_width = 15;
                    $girth =  (($product_height + $product_width)*2) + $product_length;
                   
                    $myfile = file('http://drc.edeliver.com.au/ratecalc.asp?'.$query);


                    $APchargeArray = split('=',$myfile[0]);
                    $charge = $APchargeArray[1];
                    $APerrorArray = split('=',$myfile[2]);
                    $strAPerrorMessage_epi = trim($APerrorArray[1]);
                    $errormessage[] = $strAPerrorMessage_epi;
                    if($strAPerrorMessage_epi=="OK") {
                        if($eachServiceVal !="" && $charge!="") {
                            $resultShippingArray[$product_option_id][]= array("service_name"=>$eachServiceVal,"rate"=>$charge);
                        }
                    }
                }
                break;
            CASE "CP":
                $cPost = new CanadaPost();
                $cPost->setPrice($product_price);
                $cPost->setCustomer( array(
                        'city' => '',
                        'provOrState' =>$destination_state,
                        'country' => $destination_country,
                        'postalCode' => $destination_zip
                        )
                );
                $shipping_weight.$product_length.$product_width.$product_height;
                $cPost->addProduct ( array (
                        'quantity' =>$quantity,
                        'weight' =>$shipping_weight,
                        'length' =>$product_length,
                        'width' =>$product_width ,
                        'height' =>$product_height ,
                        'description' =>'Product Description'
                        )
                );
                $assoc_Array = array();
                $assoc_Array[$product_option_id] = $cPost->getRates('array');

                if($cPost->getErrorMessage()=="success") {
                    foreach($assoc_Array[$product_option_id]['product'] AS $canShipping) {
                        if($canShipping['name']!="" && $canShipping['rate']!="") {
                            $resultShippingArray[$product_option_id][]= array("service_name"=>$canShipping['name'],"rate"=>$canShipping['rate']);
                        }
                    }
                }


                break;
            case "Flat Rate":
                $queryFlatRate         = "SELECT * FROM ".$tableprefix."flat_rate_seller WHERE seller_id ='".$artist_id."'";
                $queryFlatRateQ        = mysql_query($queryFlatRate);
                if(mysql_num_rows($queryFlatRateQ)==0) {
                    $queryFlatRate     = "SELECT * FROM ".$tableprefix."flat_rate_default";
                    $queryFlatRateQ    = mysql_query($queryFlatRate);
                }
                while($flatRateObj = mysql_fetch_object($queryFlatRateQ)) {
                    $flat_rate_name = $flatRateObj->flat_rate_name;
                    $first_Item_charge = $flatRateObj->first_Item_charge;
                    $additional_Item_charge = $flatRateObj->additional_Item_charge;
                    $rate = $first_Item_charge+($additional_Item_charge*($quantity-1));
                    $resultShippingArray[$product_option_id][]= array("service_name"=>stripslashes($flat_rate_name),"rate"=>$rate);
                }
            DEFAULT:

        }
        // if the rate array is empty for other shipping Options check whether
        // admin has enabled the flat rate shipping so that customer can still
        // buy with the flat option.

        $Selected_Shipping_options  = $shippingTitle;
        if(empty($selectedShippingOption)) {
            $selectedShippingOption = $shippingTitle;
        }
       
        $shipping_options_availabe  = count($resultShippingArray[$product_option_id]);

        if($shipping_options_availabe == 0 && $_SESSION["sessShippingMethod"]!="Flat Rate") {
            if($flatrateEnabled=='Y' ) {
                $queryFlatRate         = "SELECT * FROM ".$tableprefix."flat_rate_seller WHERE seller_id ='".$artist_id."'";
                $queryFlatRateQ        = mysql_query($queryFlatRate);

                if(mysql_num_rows($queryFlatRateQ)==0) {
                    $queryFlatRate     = "SELECT * FROM ".$tableprefix."flat_rate_default";
                    $queryFlatRateQ    = mysql_query($queryFlatRate);
                }
                $shippingTitle = "Flat Rate Shipping" ;

                while($flatRateObj = mysql_fetch_object($queryFlatRateQ)) {
                    $flat_rate_name = $flatRateObj->flat_rate_name;
                    $first_Item_charge = $flatRateObj->first_Item_charge;
                    $additional_Item_charge = $flatRateObj->additional_Item_charge;
                    $rate = $first_Item_charge+($additional_Item_charge*($quantity-1));
                    $resultShippingArray[$product_option_id][]= array("service_name"=>$flat_rate_name,"rate"=>$rate);
                }
                ?>
                <?php
            }


        }

        //
        //

    } // end while loop

}

if($selectedShippingOption != $shippingTitle) {
    $errFlag = 1;
}

?>
<script>
    function goto()
    {
                   window.location.href="checkout.php";
    
    }
    function checkShipping()
    {
         var haschecked=false;

        if($('.checkbox:checked').length>0)
        {
            haschecked=true;
        }
        if(haschecked==false)
        {
            alert("<?php echo SHIP_OPTION_TEXT; ?>");
            return false;
        }
    }
</script>
<style type="text/css">
    <!--
    .style1 {color: #0033CC}
    -->
</style>
<style type="text/css">
    <!--
    .style2 {color: #ff0000}
    -->
    .err{
        padding:0 0 5px 21px;
    }
</style>
<div align="left" class="main_body">
    <!--mainbody area start -->
    <!--center content area start-->
    <form name="frmShippingOptions" method="post" action="#">
        <div align="left" id="item_details">
            <!--items display area start -->
            <div align="left" id="items_top_area">
                <div align="left" id="items_top_area_ttl"><?php echo SHIP_DETAILS_TEXT;?></div>
            </div>
            <div>&nbsp;</div>
            <div class="text_information" align="center"><?php echo $message?></div>
            <div>
                <table cellpadding="0" cellspacing="0" width="100%">
                    <?php
                    echo $hidden_values;
                    ?>
                    <tr>
                        <td align="left" valign="top"><b><?php echo SHIP_ADDR_TEXT;?></b></td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td>
                            <fieldset>
                                <table cellpadding="0"  id="itemBigimage2"  cellspacing="5" width="100%" border="0">
                                    <tr>
                                        <td width="9%" align="right"><b><?php echo FIRST_NAME_TEXT;?></b></td>
                                        <td width="3%">&nbsp;:&nbsp;</td>
                                        <td width="88%"><?php echo stripslashes($_SESSION["sessShippingFirstName"])?></td>
                                    </tr>
                                    <tr>
                                        <td width="9%" align="right"><b><?php echo LAST_NAME_TEXT;?></b></td>
                                        <td>&nbsp;:&nbsp;</td>
                                        <td width="88%"><?php echo stripslashes($_SESSION["sessShippingLastName"])?></td>
                                    </tr>
                                    <tr>
                                        <td width="9%" align="right"><b><?php echo ADDR1_TEXT;?></b></td>
                                        <td>&nbsp;:&nbsp;</td>
                                        <td width="88%"><?php echo stripslashes($_SESSION["sessShippingAddress1"])?></td>
                                    </tr>
                                    <tr>
                                        <td width="9%" align="right"><b><?php echo ADDR2_TEXT;?></b></td>
                                        <td>&nbsp;:&nbsp;</td>
                                        <td width="88%"><?php echo stripslashes($_SESSION["sessShippingAddress2"])?></td>
                                    </tr>
                                    <tr>
                                        <td width="9%" align="right"><b><?php echo CITY_TEXT;?></b></td>
                                        <td>&nbsp;:&nbsp;</td>
                                        <td width="88%"><?php echo stripslashes($_SESSION["sessShippingCity"])?></td>
                                    </tr>
                                    <tr>
                                        <td width="9%" align="right"><b><?php echo STATE_LABEL;?></b></td>
                                        <td>&nbsp;:&nbsp;</td>
                                        <td width="88%"><?php echo stripslashes($_SESSION["sessShippingState"])?></td>
                                    </tr>
                                    <tr>
                                        <td width="9%" align="right"><b><?php echo ZIP_TEXT;?></b></td>
                                        <td>&nbsp;:&nbsp;</td>
                                        <td width="88%"><?php echo stripslashes($_SESSION["sessShippingZIP"])?></td>
                                    </tr>
                                    <tr>
                                        <td width="9%" align="right"><b><?php echo FAX_TEXT;?></b></td>
                                        <td>&nbsp;:&nbsp;</td>
                                        <td width="88%"><?php echo stripslashes($_SESSION["sessShippingFAX"])?></td>
                                    </tr>
                                    <tr>
                                        <td width="9%" align="right"><b><?php echo PHONE_TEXT;?></b></td>
                                        <td>&nbsp;:&nbsp;</td>
                                        <td width="88%"><?php echo stripslashes($_SESSION["sessShippingPhone"])?></td>
                                    </tr>
                                    <tr>
                                        <td width="9%" align="right"><b><?php echo EMAIL_LABEL;?></b></td>
                                        <td>&nbsp;:&nbsp;</td>
                                        <td width="88%"><?php echo stripslashes($_SESSION["sessShippingEmail"])?></td>
                                    </tr>
                                    <tr>
                                        <td width="9%" align="right"><b><?php echo COUNTRY_TEXT;?></b></td>
                                        <td>&nbsp;:&nbsp;</td>
                                        <td width="88%"><?php echo getCountryName($_SESSION["sessShippingCountry"])?></td>
                                    </tr>
                                </table>
                            </fieldset>
                        </td>
                    </tr>
                    <tr>
                        <td align="left" valign="top">&nbsp;</td>
                    </tr>
                    <?php
                    if($_SESSION['shipping_enabled']!="false") {
                       // if($shipping_options_availabe==0) {$errFlag
                        if($errFlag == 1) {
                            ?>

                    <tr><td class="text_information"> <?php
                    $infoRates = SHIPPING_OPTION_RATE_TEXT;
                    echo $infoRates = str_replace("{TITLE}", $selectedShippingOption, $infoRates);
                    //echo $selectedShippingOption; ?></td></tr>
                            <?php } ?>
                    <tr>
                        <td align="left" valign="top"><b><?php
                        $title = SHIPPING_OPTION_TEXT;
                        echo $title = str_replace("{TITLE}", $shippingTitle, $title);
                        //echo $shippingTitle;?></b></td>
                    </tr>
                    <tr>
                        <td>
                            <div class="shopcart_list">
                                <table cellpadding="5" cellspacing="1" width="100%" border="0" >
                                    <tr class="shopcart_heads">
                                        <td width="300"><?php echo PRODUCT_TEXT;?></td><td><?php echo TEXT_SHIPPING_RATE;?></td>
                                    </tr>
                                        <?php

                                        foreach ($productArray AS $key=>$val) {
                                            ?>
                                    <tr>
                                        <td width="300"><?php echo stripslashes($val)?></td>
                                        <td>
                                                    <?php
                                                    if(count($resultShippingArray[$key])) {
                                                        $chkCnt = 0;
                                                        $error = 0;
                                                        foreach($resultShippingArray[$key] AS $eachShippingArr) {

                                                            $chkCnt++;
                                                            $radiochecked = "";
                                                            if($chkCnt==1) {
                                                                $radiochecked = "checked";
                                                            }
                                                            $serviceName	=$val;

                                                            $display_shipping_rate	= ConvertUSDollorToUserCurrency($currency_attributes[2]) *  $eachShippingArr['rate'];
                                                            $display_shipping_rate =number_format($display_shipping_rate,2,".","");

                                                             if($eachShippingArr['rate']=='')
                                                                {
                                                                   $error++;
                                                                   $error_message  =  FLAT_RATE_MSG;
                                                              }

                                                            ?>
                                            <input type="radio" <?php echo $radiochecked?> name="shipping_option_<?php echo $key?>"  class="checkbox" value="<?php echo $eachShippingArr['service_name']."=>".number_format($eachShippingArr['rate'],2,".","")?>">&nbsp;<?php echo $eachShippingArr['service_name']."&nbsp;&nbsp;(<b>".$currency_attributes[0]."&nbsp;".$display_shipping_rate?></b>)<br>
                                                            <?php
                                                        }
                                                    }
                                                    ?>
                                        </td>
                                    </tr>

                                    <?php if(count($resultShippingArray[$key])==$error) {
                                               $error_message  =  FLAT_RATE_MSG;
                                        ?>
                                    <tr><td class="text_information" colspan="2"> <br><?php echo $error_message; ?> <br></td></tr>
                                        <?php 
                                                     
                                                 }
                                       ?>
                                            <?php
                                        }
                                        ?>
                                </table>
                            </div>
                        </td>
                    </tr>
                        <?php
                    }
                    ?>
                    <tr>
                        <td>&nbsp;</td>
                    </tr>
                    <tr><td align="center"><input type='button' name='cancel' value='<?php echo BACK_TEXT;?>' class='button' onClick="goto();">&nbsp;<input type='submit' name='proceed' value='<?php echo PROCEED_BUTTON;?>' class='button' onclick="return checkShipping();">
                        </td>
                    </tr>
                    <tr><td>&nbsp;</td></tr>
                </table>
            </div>
            <div align="left" class="float_clear1"></div>
            <!--items display area end -->
        </div>
    </form>
    <!--center content area end-->
    <!--mainbody area end -->
</div>
<?php
include "includes/".$active_template[2];	/* Bottom File Name */
?>