<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
// +----------------------------------------------------------------------+
// | PHP version 4/5                                                      |
// +----------------------------------------------------------------------+
// | This source file is a part of iScripts Multicart                     |
// +----------------------------------------------------------------------+
// | Authors: Programmer<programmer@armia.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.                                                       |
// +----------------------------------------------------------------------+

include "includes/config.php";
include "includes/session.php";
include "includes/functions.php";
include "classes/cls_order.php";

if (get_magic_quotes_gpc()) {
    $_POST = array_map('stripslashes_deep', $_POST);
    $_GET = array_map('stripslashes_deep', $_GET);
    $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
}

if(isset( $_SESSION["sess_userid"]) and $_SESSION["sess_userid"]!= ""){
	$userid = $_SESSION["sess_userid"];
}else{
	header("Location:login.php");
	exit;
}
$message = '';
$adminCurrency	= GetAdminCurrency();

$currencySymbol	=$adminCurrency['currency_symbol'];

if(isset( $_GET["orderid"]) and $_GET["orderid"]!= ""){
	$orderid = $_GET["orderid"];
}else if(isset( $_POST["orderid"]) and $_POST["orderid"]!= ""){
	$orderid = $_POST["orderid"];
}else{
	header("Location:orders.php");
	exit;
}

$gift_certificate=0;

$itemlist = isset($_POST["chkitems"])?$_POST["chkitems"]:'';
$ddlStatus = isset($_POST["ddlStatus"])?$_POST["ddlStatus"]:'';

$btn = '';
foreach ($_POST as $key =>$value){

	if($value == GO_BUTTON){
		$btn = $key;
		break;
	}

}


if(isset($_POST[$btn]) && $_POST[$btn] == GO_BUTTON){
	$ar = explode("_",$btn );
	$sid = $ar[1] ;
	$ddl = "ddlStatus_".$sid;
	$status = $_POST[$ddl];
	
	$sql ="UPDATE  ".$tableprefix."order_details SET
		item_status = '".addslashes($status)."'
		WHERE order_id = '".addslashes($orderid)."' AND artist_id = '".addslashes($sid)."' ";
		$res = mysql_query($sql);
		//echo $sql;exit;
		
		// Update Item Delivery Time
		if($status=="4")
		{
		
			   $sql_deliverytime_up	= "UPDATE  ".$tableprefix."order_details SET item_delivery_date =now()
										WHERE order_id = '".addslashes($orderid)."' AND artist_id = '".addslashes($sid)."' ";
								
				mysql_query($sql_deliverytime_up) or die(mysql_error());
                                
                                $orderstatus_new = getArtistOrderStatus($orderid, $sid);

				sendOrderStatusChangeMailToSeller($orderid,$sid,$_SESSION["sess_userid"],$orderstatus_new);
		}
		
		// End 

}

//if($_POST["btnGo"] == "Go"){
if(isset($_POST["btnGo"])){
	$message = "";
	if(!isNotNull($itemlist)){
		$message .= SELECT_ITEM_TEXT." <br>";
	}else{
		$ilist = implode(",",$itemlist );
	}

	if($message  == ""){
		$sql ="UPDATE  ".$tableprefix."order_details SET
		item_status = '".addslashes($ddlStatus)."'
		WHERE 	order_detail_id IN (".addslashes($ilist).")
		";
		$res = mysql_query($sql);
		
		if($ddlStatus=="4")
		{
		
			$sql_deliverytime_up = "UPDATE  ".$tableprefix."order_details SET item_delivery_date =now()
							WHERE order_detail_id IN (".addslashes($ilist).")";
			
			mysql_query($sql_deliverytime_up) or die(mysql_error());				
			
		}


		$message = CHANGE_SAVE_SUCCESS_TEXT."<br>";
	}else{
		 $message = "<br>".CORRECT_ERRORS_TEXT."<br>" . $message;
	}

}

if(isset($_GET["msg"]) and $_GET["msg"]!=""){
	$msg = $_GET["msg"];
	switch($msg){
		case "deleted": $message = MSG_USER_DELETED;break;
		default:
			;
	} // switch

}
$artistlist = getOrderArtists($orderid);
$artists = explode(",",$artistlist );

$order_flag = 0;

$qry="select * from ".$tableprefix."settings ";
$rs_q=mysql_query($qry) or die(mysql_error());
$rr_settings=mysql_fetch_array($rs_q);


  
   $sql=      "SELECT o.*,
			sum( (od.product_price-(od.product_price*product_discount/100)) * od.product_quantity) as order_total_price
			FROM ".$tableprefix."orders o 
			LEFT JOIN ".$tableprefix."order_details od ON od.order_id=o.order_id 
			WHERE o.user_id = '".addslashes($_SESSION["sess_userid"])."' AND o.order_id = ".GetSQLValueString($orderid,"text")." GROUP BY o.order_id ";
		 
$result = mysql_query($sql);

if(mysql_num_rows($result) != 0)
{
	$prow = mysql_fetch_array($result);
	$ordernumber = $prow["order_id"];
	$currencySymbol	=$adminCurrency['currency_symbol'];
	$ordertotal = $prow["order_total_price"];
        
        $couponCodeDiscount=$prow["couponCodeDiscount"];
        if($prow["nused_gift_amount"] >0 || $couponCodeDiscount>0 ) {

           $giftDiscountAmount           = $prow["nused_gift_amount"];

           $couponCodeDiscountAmount = $prow["couponCodeDiscount"];

           $TotalDiscount   = $giftDiscountAmount + $couponCodeDiscountAmount;

           $priceafterdiscount=$ordertotal-$TotalDiscount;

           $ordertotal=number_format($priceafterdiscount,2,".","");

        }
	//$taxrate=$prow["taxrate"];
	$orderdate = $prow["order_date"];
	$orderdate = dateFormat($orderdate,"Y-m-d","m/d/Y");
	$userid = $prow["user_id"];
	
	$exchange_price = isset($prow["nexchange_price"])?$prow["nexchange_price"]:0;
	
	$netTotal=$ordertotal;

}
/*---------Multicart 2.0 Upgradation---------*/
else
{
	$order_flag = 1;
}

$totalshippingAmount = 0;

$totalshippingAmount      =    Order::orderShippingCost($orderid);
$taxtotal                =      Order::getorderTaxTotal($orderid);
$ordertotal=$ordertotal+$totalshippingcost+$taxtotal;

$taxrate                =  $taxtotal;

$netTotal   =   $netTotal + $totalshippingAmount+$taxtotal;
/*---------Multicart 2.0 Upgradation---------*/

$statlist= array();
$statlist[4] = DELIVERED_STATUS_TEXT;

/*display the active template*/

$active_template = displayTemplate();


include "includes/htmltop.php";

/* Top File Name */

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


/*---------Multicart 2.0 Upgradation---------*/

$hide_shipping_display = 0;

$select_order = "SELECT prd.product_id 
				 FROM ".$tableprefix."products prd
                                 INNER JOIN ".$tableprefix."order_details ord_det ON ord_det.product_id = prd.product_id
                                 INNER JOIN ".$tableprefix."orders ord ON ord.order_id = ord_det.order_id
                                 WHERE prd.vdigital_product = 'Y'
				  AND ord.order_id = ".$orderid;
				  
$result_order = mysql_query($select_order) or die(mysql_error());

if(mysql_num_rows($result_order) > 0)
{

	$hide_shipping_display = 1;

}		

			$select_order_gift = "SELECT prd.product_id 
				 	  FROM ".$tableprefix."products prd
                                          INNER JOIN ".$tableprefix."order_details ord_det ON ord_det.product_id = prd.product_id
                                          INNER JOIN ".$tableprefix."orders ord ON ord.order_id = ord_det.order_id
                                          INNER JOIN ".$tableprefix."categories cat ON prd.product_category = cat.category_id
					  WHERE cat.gift_certificate_flag = 'Y'
					  AND ord.order_id = ".$orderid;
				  
$result_order_gift = mysql_query($select_order_gift) or die(mysql_error());

if(mysql_num_rows($result_order_gift) > 0)
{

	$hide_shipping_display = 1;
	$gift_certificate=1;

}	

$hide_shipping_display = 0;
$hide_shipping_display = Order::checkShippingBlockRequiredForOrder($orderid);

/*---------Multicart 2.0 Upgradation---------*/


?>
<SCRIPT>
function confirmDelete(){
	if(confirm('<?php echo CONFIRM_DELETE_TEXT;?>') ){
		return true;
	}
	return false;
}
function confirmStatus(){
	if(confirm('<?php echo CONFIRM_STATUS_CHANGE_TEXT;?>') ){

		return true;
	}
	return false;
}
</SCRIPT>


<!--mainbody area start -->
<div class="main_body">
	<div class="container">
		<div class="row">
		<!--center content area start-->		
		<form name="frmFeedback" action="<?php echo $_SERVER["PHP_SELF"]?>" method="POST">
		<input type="hidden" name="orderid" value="<?php echo htmlentities($orderid);?>">
		<section class="sec_marg">
		<div class="col-sm-12 col-lg-12 col-md-12 ">
			<h3><?php echo ORDER_DETAILS_TEXT;?></h3>
		</div>
		</section>
		<div class="clear"></div>
		<div class="col-sm-12 col-lg-12 col-md-12 ">
			<div class="text_information"><?php echo $message?></div>
		</div>
		
<?php
		
/*--------Multicart 2.0 Upgradation------------

confirming whether the order is placed by the logged in user

inorder to avoid the url mangling

*/		
		
if($order_flag == 0) // start of url checking
{								
					
								
?>				
		<div class="col-sm-12 col-lg-12 col-md-12 ">
		<!--items display area start -->
		<div class="order_detailspg">
		<table width="100%" border=0>
		<tr>
			<td colspan="3">
					<legend class="toplinksCopy"><?php echo ORDER_DETAILS_TEXT;?></legend>
					<div class="border_bgclr">
						<table cellpadding="2" cellspacing="2" width="100%" class="maintext responsive">
							<tr><td colspan="3" class="message" align="left"><?php echo $message;?></td></tr>
                                                        <?php
                                                        $orderDeliveryStatus    =    getOrderStatus($orderid);
                                                        switch ($orderDeliveryStatus)
                                                        {
                                                        	case 'Delivered': $orderStatus = DELIVERED_STATUS_TEXT;
                                                        	break;
                                                        	case 'Pending': $orderStatus = PENDING_STATUS_TEXT;
                                                        	break;
                                                        	case 'Shipped': $orderStatus = SHIPPED_STATUS_TEXT;
                                                        	break;
                                                        	case 'Cancelled': $orderStatus = CANCELLED_STATUS_TEXT;
                                                        	break;
                                                        	case 'Returned to Seller': $orderStatus = RETURNED_STATUS_TEXT;
                                                        	break;
                                                        	case 'Seller Received Back': $orderStatus = RECEIVED_STATUS_TEXT;
                                                        	break;
                                                            default :
                                                                
                                                            $orderStatus = $orderDeliveryStatus;
                                                            break;
                                                        }
                                                        ?>
							<tr><td align="left" width="20%" ><?php echo ORDER_NUM_TEXT;?>&nbsp;</td><td width="2%" >&nbsp;</td><td width="78%" align="left" class="innertextCopy1"><?php echo $ordernumber;?></td></tr>
							<tr><td align="left" ><?php echo ORDER_DATE_TEXT1;?> &nbsp;</td><td >&nbsp;</td><td align="left" class="innertextCopy1"><?php echo $orderdate;?></td></tr>
							<tr><td align="left" ><?php echo ORDER_TOTAL_TEXT;?>&nbsp;</td><td >&nbsp;</td><td align="left" class="innertextCopy1"><div id="totalCost" style="float:left;"><?php echo $adminCurrency['currency_symbol'];?> <?php echo number_format($netTotal,2,".","" );?></div></td></tr>
							<tr><td align="left" ><?php echo ORDER_STATUS_TEXT1;?>&nbsp;</td><td >&nbsp;</td><td align="left" class="innertextCopy1"><?php echo $orderStatus; ?></td></tr>
						</table>
						<div class="clear"></div>
				</div>
			</td>
		</tr>
		<tr><td colspan="3">&nbsp;</td></tr>
		<tr>
			<td colspan="3">
			
				<legend class="toplinksCopy"><?php echo ORDER_PART_DETAILS_TEXT;?></legend>
				<table cellpadding="2" cellspacing="2" width="100%" class="orderpart_detail_tbl">
					
					<?php                                        
					if(isNotNull($artists)){
						$ordermsg = ORDER_CNT_TEXT;
						$ordermsg =str_replace("COUNT",count($artists),$ordermsg);
						echo  $ordermsg;
						$cartTotal = 0;
                                                echo Order::showIconTexts($orderid);
						//echo "This order contains ".count($artists)." sub order(s)";
						for($i=0;$i< count($artists);$i++){
							?>
							<tr>
								<td colspan='3'>
									
									<legend class="toplinksCopy"><?php echo ORDER_PART_TEXT;?> <?php echo $i+1;?></legend>
										<table cellpadding="2" cellspacing="2" width="100%" border='0'>
											<tr class="whitebg">
                                                                                            <td width='100%' colspan='7' align="left" >
                                                                                            <b><?php echo SELLER_TEXT1;?>: &nbsp;<?php echo stripslashes(getArtistName_Location($artists[$i]));?></b>&nbsp;&nbsp;<?php echo ORDER_STATUS_TEXT;?>&nbsp;<b><font color='RED'><?php 
                                                                                            switch (getArtistOrderStatus($orderid,$artists[$i]))
                                                                                            {
                                                                                            	case 'Delivered': $orderStatus = DELIVERED_STATUS_TEXT;
                                                                                            	break;
                                                                                            	case 'Pending': $orderStatus = PENDING_STATUS_TEXT;
                                                                                            	break;
                                                                                            	case 'Shipped': $orderStatus = SHIPPED_STATUS_TEXT;
                                                                                            	break;
                                                                                            	case 'Cancelled': $orderStatus = CANCELLED_STATUS_TEXT;
                                                                                            	break;
                                                                                            	case 'Returned to Seller': $orderStatus = RETURNED_STATUS_TEXT;
                                                                                            	break;
                                                                                            	case 'Seller Received Back': $orderStatus = RECEIVED_STATUS_TEXT;
                                                                                            	break;
                                                                                            }
                                                                                            echo $orderStatus;
                                                                                           // echo getArtistOrderStatus($orderid,$artists[$i]); ?></font></b></td>
											</tr>
		
											<tr><td width='100%' colspan='7'>
											<table BORDER="0" width="100%" class="boxborder responsive">

		
											<tr class="shopcart_heads">
												<td width='3%'><b>#</b></td>
												<td width='20%'><b><?php echo PRODUCT_NAME_TEXT1;?></b></td>
												<td width='10%'><b><?php echo CODE_TEXT;?></b></td>
												<td width='10%'><b><?php echo RATE_TEXT;?></b></td>
												<td width='6%'><b><?php echo QTY_TEXT;?></b></td>
												<td width='6%'><b><?php echo PRICE_TEXT;?></b></td>
												<td width='6%'><strong><?php echo DISCOUNT_TEXT;?></strong></td>
												<td width='10%'><b><?php echo STATUS_TEXT;?></b></td>
                                                                                                                                                                                              
											</tr>
											<tr>
												<td colspan="9">&nbsp;</td>
											</tr>
						<?php
						  if($gift_certificate==0)
						  { // check if products are not gifts certificates
						  	
							 $sql=" SELECT od.*,s.order_status,o.vorder_currency,o.taxrate,gm.ngift_product_id,gm.vgift_coupon_code
                                                                        FROM ".$tableprefix."order_details od
									INNER JOIN ".$tableprefix."order_status s ON s.order_status_id = od.item_status
									LEFT JOIN ".$tableprefix."giftcoupon_master gm ON gm.ngift_product_id=od.product_id 
									LEFT JOIN ".$tableprefix."orders o ON o.order_id=od.order_id 
									WHERE  od.order_id = '".addslashes($orderid)."'  AND  (od.artist_id = '".$artists[$i]."') 
                                    order by  od.product_name";
									
						} // end if 			
							//echo $sql . "<br>";
							
							
					if($gift_certificate==1)
						  { //	check if products are not gifts certificates
							  $sql="SELECT od.*,s.order_status,o.vorder_currency,o.taxrate,gm.ngift_product_id,gm.vgift_coupon_code
                                                                        FROM ".$tableprefix."order_details od
									INNER JOIN ".$tableprefix."order_status s ON s.order_status_id = od.item_status
									LEFT JOIN ".$tableprefix."giftcertificates gm ON gm.ngift_product_id=od.product_id  AND gm.ngift_order_id=od.order_id
									LEFT JOIN ".$tableprefix."products p ON p.product_id=od.product_id 
									LEFT JOIN ".$tableprefix."orders o ON o.order_id=od.order_id 
									WHERE  od.order_id = '".addslashes($orderid)."'  AND  (od.artist_id = '".$artists[$i]."') 
                                    order by  od.product_name";
					    }				
						
						
						
							$result1 = mysql_query($sql);
							$k=1;
							$subtotal = 0;
							$ddlStatus = "ddlStatus_".$artists[$i];
							$$ddlStatus = '';
							$ddl = makeDropDownList($ddlStatus,$statlist,$$ddlStatus ,false ,"textbox" , "","" );
							$btnStatus = "btnGo_".$artists[$i];
							$btn = "<input type='submit' value='".GO_BUTTON."' name='".$btnStatus."' class='button'  onClick='return confirmStatus();'> ";
							while($rw = mysql_fetch_array($result1)){
								$link = "<a href='editmyproduct.php?productid=".$rw["product_id"]."'>";
								
								$check = "<input type='checkbox' name='chkitems[]' value='" . $rw["order_detail_id"] . "' class='checkbox'> ";
								
								$rate = $rw["product_price"];
								
								$currencySymbol	=$adminCurrency['currency_symbol'];
								$qty = $rw["product_quantity"];
								$artistid = $rw["artist_id"];
								$refund_id=$rw["user_refund_id"];
								$giftid=$rw["ngift_product_id"];
								$productid=$rw["product_id"];
								$price = $rate * $qty;
                                                                
        if($rw['digital_product_flag'] == "Y"){           
            $product_shipping_cost = $adminCurrency['currency_symbol'].'&nbsp;0.00';;
            $shippingName = NO_SHIPPING;
            $producttype = DIGITAL_PRODUCT;
        }
        else{
            $product_shipping_cost = ($rw['product_shipping_price']!=0)?$adminCurrency['currency_symbol'].'&nbsp;'.number_format($rw['product_shipping_price'],2,".",""):$adminCurrency['currency_symbol'].'&nbsp;0.00';
            $shippingName = ($rw['product_shipping_price']!=0)?$rw['product_shipping_name']:FREE_SHIP_TEXT;
            $producttype =  ($rw['subscription_product_flag']=='Y')?SUBSCRIPTION_PRODUCT:NORMAL_PRODUCT;
        }
								
                                                                    $discount=0;

                                                                                        if($rw["product_discount"] !="0") {
                                                                                            $discount=($price*$rw["product_discount"]/100);

                                                                                        }


                                                                                        $discountstr="";

                                                                                        if($rw["product_discount"] !="0") {
                                                                                            $price=$price-($price*$rw["product_discount"]/100);
                                                                                            $discountstr="<br>".strtolower(MAIL_ORDER_TEXT_DISCOUNT)."(".$rw["product_discount"]."%)";
                                                                                        }
								$subtotal += $price;
								
								//$taxrate=$rw["taxrate"];
								
								$rate  = number_format($rate,2,".","" );
								$price = number_format($price,2,".","" );
								
								
/*----------Multicart 2.0 Upgradation-----------------------*/								
								
								if($rw["order_status"] != "Cancelled" && getOrderStatus($orderid) != 'Delivered')
								{
								
/*----------Multicart 2.0 Upgradation-----------------------*/																
								
									$txtDdl = CHANGE_STATUS_TEXT."&nbsp;&nbsp;".$ddl."&nbsp;&nbsp;".$btn."&nbsp;";
								}else{
									$txtDdl = "&nbsp;";
								}
								
?>
								   <tr>
										<td valign="top" class=""><?php echo $k; ?></td>
										<td valign="top" align="left" class="" style='word-break:break-all;'><?php echo Order::showDigitalItemIcon($rw["digital_product_flag"]).(generalMethods::html_entity($rw["product_name"])).$discountstr.Order::check_free_ship_product_text($rw["product_id"]); ?>
										
										
										
									 </td>
										<td valign="top" align="left" class="" style='word-break:break-all;'><?php echo generalMethods::html_entity($rw["product_code"]); ?></td>
										<td valign="top" align="left" class=""><?php echo $currencySymbol;?> <?php echo htmlentities($rate); ?></td>
										<td valign="top" align="left" class=""><?php echo htmlentities($qty); ?></td>
										<td align="left" valign="top" class=""><?php echo $currencySymbol;?> <?php echo htmlentities($price); ?></td>
										<td align="left" valign="top" class=""><?php echo $currencySymbol;?><?php echo htmlentities(round($discount,3)); ?></td>                                                                            
										<td valign="top" class=""><?php 
										switch (($rw["order_status"]))
										{
											case 'Delivered': $orderStatus = DELIVERED_STATUS_TEXT;
											break;
											case 'Pending': $orderStatus = PENDING_STATUS_TEXT;
											break;
											case 'Shipped': $orderStatus = SHIPPED_STATUS_TEXT;
											break;
											case 'Cancelled': $orderStatus = CANCELLED_STATUS_TEXT;
											break;
											case 'Returned to Seller': $orderStatus = RETURNED_STATUS_TEXT;
											break;
											case 'Seller Received Back': $orderStatus = RECEIVED_STATUS_TEXT;
											break;
										}echo $orderStatus;
										//echo ($rw["order_status"]); ?>&nbsp;</td>
                                                                              
									</tr>
									
					<tr><td colspan="5"><br><?php if($rw['vgift_coupon_code']!='') {  ?><span class="required"><?php echo GIFT_CERTIFICATE_CODE_TEXT;?> <?php echo $rw['vgift_coupon_code'];?></span><?php } ?></td></tr>

                                                 <?php
                                               $queryOrderDetail_digital = "SELECT gc.vdigital_product_code,gc.ndownload_try,gc.ndownload_expiry,gc.ndownload_expiry_days
  						FROM  ".$tableprefix."digital_product gc where gc.ndigital_productid='".$rw['product_id']."' AND gc.ndigital_orderid='".addslashes($orderid)."' ";
                                                $rs_digital=mysql_query($queryOrderDetail_digital)	or die(mysql_error());
		                               $product_download_details ="";

						$digitalProductRows =  mysql_num_rows($rs_digital);

                   if($digitalProductRows>0)
		{
				$product_download_details_link = "";
				 $download_link = "";

				 $cnt	=1 ;

				while($orderDetailObjdigital=mysql_fetch_object($rs_digital))
				{

                                        $download_link = " <br>".DOWNLOAD_LINK_TEXT." ".$cnt." - ".SITE_URL."/digital_product_download.php?download_code=$orderDetailObjdigital->vdigital_product_code\r\n";
					$product_download_details_link = $download_link;

                ?>
                                                                        <tr > <td colspan="8" valign="top" height="40px;" class="" style='word-break:break-all;'>

                                                                                <b> <a href="<?php echo SITE_URL ;?>/digital_product_download.php?download_code=<?php echo $orderDetailObjdigital->vdigital_product_code?>" target="_blank" class="whitebg"><?php echo $product_download_details_link;?> </a> </b>
                                                                            </td></tr>


                  <?php
                            $cnt++;
                               }

                          }
                ?>
                  
		
							<?php
								$k++;
							}?>
								</table>
								<hr>
								</td></tr>

<?php 
			$grand_total=$subtotal;
?>
	
					<td>&nbsp;

					<?php echo $txtDdl;?>&nbsp;&nbsp;
					</td>
					<td align="right"><strong class="fright"><b><?php echo SUB_TOT_TEXT;?>&nbsp;</b><b><?php echo $currencySymbol;?> <?php echo number_format($grand_total,2,".","" ); ?></b></strong></td>
					<td>&nbsp;</td>
				</tr>
		
								<tr class="">
												<td colspan="7">&nbsp;</td>
										  </tr>
								</table>
									
								</td>
							</tr>
							<tr><td>&nbsp;</td></tr>
						<?php 
						   $cartTotal+=$grand_total;
						}
						
						
					}
					?>
<?php							


 $select_shipping_cost = "SELECT sd.vshipping_name, sd.nshipping_cost,sd.nshp_productname,CONCAT(ar.first_name,' ',ar.last_name)as artist_name
                            FROM ".$tableprefix."shipping_details sd
                            INNER JOIN ".$tableprefix."artists ar ON ar.artist_id = sd.seller_id                          
                            WHERE sd.norder_id = ".$orderid." AND  nshp_status = 'C' order by ar.artist_name";

$result_shipping_cost = mysql_query($select_shipping_cost);
?>
	<tr><td colspan="7">
	
	<legend><?php echo SHIP_DETAILS_TEXT;?></legend>
	
	<div class="border_bgclr">
	<table width="100%" border="0" cellpadding="3" cellspacing="3" class="responsive">
	<tr class="shopcart_heads">
	<td> <b><?php echo SELLER;?></b> </td> <td><b><?php echo SHIP_TYPE_TEXT;?></b> </td><td><b><?php echo SHIPPING_COST_TEXT;?></b></td></tr>
	<?php
								
if(mysql_num_rows($result_shipping_cost) > 0)
{
	while($shipping_row=mysql_fetch_array($result_shipping_cost))
	{
	    $totalshippingcost+=$shipping_row['nshipping_cost'];		
?>	
<tr><td><?php echo stripslashes($shipping_row['artist_name']); ?></td>
<td><?php echo stripslashes($shipping_row['vshipping_name']); ?></td><td><?php echo $currencySymbol;?> <?php echo number_format($shipping_row['nshipping_cost'],2,".","" ); ?></td></tr>
<?php 
    } // end while 
} // end if number of rows
else
{
?>
<tr><td colspan="3" class="text_information"> <?php echo NO_SHIP_DETAILS_TEXT;?></td></tr>
<tr><td colspan="3">&nbsp; </td></tr>
<?php

} // ens else


?>
	</table>
	</div>
		
	</td></tr>	
        
					
	<tr><td height="39"  align="right"><strong class="fright"><?php echo PRODUCT_TOT_TEXT;?> <?php echo $currencySymbol;?> <?php echo number_format($cartTotal,2,".","" ); ?></strong></td><td>&nbsp;</td>
	</tr>
        
 <?php 
                        if($prow['couponCodeDiscount']>0){

                                    $carttotal_tmp=$netTotal-$totalshippingcost-$totaltax;
                                    $priceafterdiscount=$cartTotal-($prow['couponCodeDiscount']);
                                    $couponCodeDiscountAmount = $prow['couponCodeDiscount'];
				?>

<tr><td  align="right" ><strong class="fright"><font color="#FF0000" class="couponpad"><?php echo COUPON_CODE_TEXT1;?>&nbsp;<?php echo $prow['couponCode']?></font><br/><?php echo DISCOUNT_TEXT1;?> <?php echo $currencySymbol;?> &nbsp;<?php echo number_format($couponCodeDiscountAmount,2,".","" ); ?>  </strong> </td><td>&nbsp;</td></tr>								
	
<?php
 }
 ?>

<?php 
if($prow['vgiftcertificate_code']!='' && $prow['nused_gift_amount']!=0 ){

?>


 <tr><td  align="right" class="specialmessage"> <div style="float:right; font-weight:bold;"><?php echo GIFT_CERTIFICATE_AMT_TEXT;?> <?php echo $currencySymbol;?> 

&nbsp;<?php echo number_format($prow['nused_gift_amount'],2,".","" ); ?></div></td><td>&nbsp;</td></tr>

<tr><td  align="right" class="specialmessage"> <div style="float:right; font-weight:bold;"><?php echo GIFT_CERTIFICATE_CODE_TEXT;?> 
&nbsp;<?php echo $prow['vgiftcertificate_code']; ?></div></td><td>&nbsp;</td></tr>
<?php  } ?>

<?php 
 if($prow["nused_gift_amount"]>0 || $prow['couponCodeDiscount']>0 ) {
        $giftDiscountAmount           = $prow["nused_gift_amount"];
                                                                                                   
        $couponCodeDiscountAmount = $prow["couponCodeDiscount"];

        $TotalDiscount   = $giftDiscountAmount + $couponCodeDiscountAmount;

        $priceafterdiscount=$cartTotal-$TotalDiscount;

        $cartTotal=number_format($priceafterdiscount,2,".","");
     
 ?>    
 <tr><td height="39"  align="right" class="specialmessage"><strong class="fright"><?php echo PRODUCT_TOT_TEXT_DISCOUNT;?> <?php echo $currencySymbol;?> <?php echo number_format($cartTotal,2,".","" ); ?></strong></td>
	<td>&nbsp;</td></tr>
 <?php } ?>

<?php if(!empty($totalshippingcost))
{
?>					
	<tr><td height="39"  align="right"><strong class="fright"><?php echo SHIP_TOT_TEXT;?> <?php echo $currencySymbol;?> <?php echo number_format($totalshippingcost,2,".","" ); ?></strong></td>
	<td>&nbsp;</td></tr>			

<?php } // end if ?>		
		
<?php if(!empty($taxrate))
{
?>					
	<tr><td height="39"  align="right"><strong class="fright"><?php echo TAX_RATE_TEXT1;?> <?php echo $currencySymbol;?> <?php echo number_format($taxrate,2,".","" ); ?></strong></td>
	<td>&nbsp;</td></tr>			

<?php } // end if ?>	

 
 

<tr><td align="right" > <div style="float:right; font-weight:bold;"><?php echo ORDER_TOT_TEXT;?> <?php echo $currencySymbol;?> 

&nbsp;<?php echo number_format($cartTotal+$totalshippingcost+$taxrate,2,".","" ); ?></div></td><td>&nbsp;</td></tr>


<tr><td align="right" > <div style="float:right; font-weight:bold;"><?php echo AMT_PAID_TEXT;?> <span class="amt_paid"><?php echo $currencySymbol;?> 

<?php echo number_format($prow['namount_paid'],2,".","" ); ?></span></div></td><td>&nbsp;</td></tr>


</table>
			
		
<?php

if($hide_shipping_display == 0)
{

?>		
		
		<tr><td colspan="3">&nbsp;</td></tr>
		<tr>
			<td colspan="3">
				
					<legend class="toplinksCopy"><?php echo SHIP_ADDR_TEXT;?> </legend>
					
					<div class="border_bgclr">
						<table cellpadding="2" cellspacing="2" width="100%" class="responsive">
							<tr><td align="left" width="22%" ><?php echo FIRST_NAME_TEXT;?>&nbsp;</td><td width="2%" >&nbsp;</td><td class="maintext" width="76%" align="left" ><?php echo ($prow["shipping_first_name"]);?></td></tr>
							<tr><td align="left" ><?php echo LAST_NAME_TEXT;?> &nbsp;</td><td >&nbsp;</td><td align="left" class="maintext"><?php echo ($prow["shipping_last_name"]);?></td></tr>
							<tr><td align="left" ><?php echo ADDR1_TEXT;?>&nbsp;</td><td >&nbsp;</td><td align="left" class="maintext"><?php echo ($prow["shipping_address1"]);?></td></tr>
							<tr><td align="left" ><?php echo ADDR2_TEXT;?>&nbsp;</td><td >&nbsp;</td><td align="left" class="maintext" ><?php echo ($prow["shipping_address2"]);?></td></tr>
							<tr><td align="left" ><?php echo CITY_TEXT;?>&nbsp;</td><td >&nbsp;</td><td align="left" class="maintext"><?php echo ($prow["shipping_city"]);?></td></tr>
							<tr><td align="left" ><?php echo STATE_LABEL;?>&nbsp;</td><td >&nbsp;</td><td align="left" class="maintext"><?php echo getCodeValue($prow["shipping_state"],2,$prow["shipping_country"]);?></td></tr>
							<tr><td align="left" ><?php echo COUNTRY_TEXT;?>&nbsp;</td><td >&nbsp;</td><td align="left" class="maintext"><?php echo getCodeValue($prow["shipping_country"],1);?></td></tr>
							<tr><td align="left" ><?php echo ZIP_TEXT;?>&nbsp;</td><td >&nbsp;</td><td align="left" class="maintext"><?php echo htmlentities($prow["shipping_zip"]);?></td></tr>
							<tr><td align="left" ><?php echo PHONE_TEXT;?>&nbsp;</td><td >&nbsp;</td><td align="left" class="maintext" ><?php echo htmlentities($prow["shipping_phone"]);?></td></tr>
							<tr><td align="left" ><?php echo FAX_TEXT;?>&nbsp;</td><td >&nbsp;</td><td align="left" class="maintext" ><?php echo htmlentities($prow["shipping_fax"]);?></td></tr>
							<tr><td align="left" ><?php echo EMAIL_LABEL;?>&nbsp;</td><td >&nbsp;</td><td align="left" class="maintext"><?php echo htmlentities($prow["shipping_email"]);?></td></tr>
							<tr><td colspan="3">&nbsp;</td></tr>
						</table>
						<div class="clear"></div>
					  </div>
				
			</td>
		</tr>
		
<?php

}

?>		
		
		<tr><td colspan="3">&nbsp;</td></tr>
		<tr>
			<td colspan="3">
				
					<legend class="headng"><?php echo BILL_ADDR_TEXT;?> </legend>
					<div class="border_bgclr">
						<table cellpadding="2" cellspacing="2" width="100%" class="responsive">
							<tr><td align="left" width="22%" ><?php echo FIRST_NAME_TEXT;?>&nbsp;</td><td width="2%" >&nbsp;</td><td width="76%" align="left" class="maintext"><?php echo ($prow["billing_first_name"]);?></td></tr>
							<tr><td align="left" ><?php echo LAST_NAME_TEXT;?> &nbsp;</td><td >&nbsp;</td><td align="left" class="maintext"><?php echo ($prow["billing_last_name"]);?></td></tr>
							<tr><td align="left" ><?php echo ADDR1_TEXT;?>&nbsp;</td><td >&nbsp;</td><td align="left" class="maintext"><?php echo ($prow["billing_address1"]);?></td></tr>
							<tr><td align="left" ><?php echo ADDR2_TEXT;?>&nbsp;</td><td >&nbsp;</td><td align="left" class="maintext"><?php echo ($prow["billing_address2"]);?></td></tr>
							<tr><td align="left" ><?php echo CITY_TEXT;?>&nbsp;</td><td >&nbsp;</td><td align="left" class="maintext"><?php echo ($prow["billing_city"]);?></td></tr>
							<tr><td align="left" ><?php echo STATE_LABEL;?>&nbsp;</td><td >&nbsp;</td><td align="left" class="maintext"><?php echo getCodeValue($prow["billing_state"],2,$prow["billing_country"]);?></td></tr>
							<tr><td align="left" ><?php echo COUNTRY_TEXT;?>&nbsp;</td><td >&nbsp;</td><td align="left" class="maintext"><?php echo getCodeValue($prow["billing_country"],1);?></td></tr>
							<tr><td align="left" ><?php echo ZIP_TEXT;?>&nbsp;</td><td >&nbsp;</td><td align="left" class="maintext"><?php echo htmlentities($prow["billing_zip"]);?></td></tr>
							<tr><td align="left" ><?php echo PHONE_TEXT;?>&nbsp;</td><td >&nbsp;</td><td align="left" class="maintext"><?php echo htmlentities($prow["billing_phone"]);?></td></tr>
							<tr><td align="left" ><?php echo FAX_TEXT;?>&nbsp;</td><td >&nbsp;</td><td align="left" class="maintext"><?php echo htmlentities($prow["billing_fax"]);?></td></tr>
							<tr><td align="left" ><?php echo EMAIL_LABEL;?>&nbsp;</td><td >&nbsp;</td><td align="left" class="maintext"><?php echo htmlentities($prow["billing_email"]);?></td></tr>
							<tr><td colspan="3">&nbsp;</td></tr>
						</table>
					  </div>
				
			</td>
		</tr>
		<tr><td colspan="3">&nbsp;</td></tr>

                <?php if($prow['buyer_comments']!='') { ?>


                <tr><td colspan="3">
                        
                        <div class="border_bgclr">
                            <table cellpadding="2" cellspacing="2" width="100%" class="responsive">
                                <tr><td><?php echo COMMENT_TEXT;?> </td>
                                    <td> <?php echo stripslashes($prow['buyer_comments']) ;?></td></tr>
                            </table>
                        </div>
                    </td></tr>

                <?php  } ?>
                
		<tr><td colspan="3" align="center"><input type="button"  value="<?php echo BACK_ORDERS_BUTTON;?>"  class="button"  onClick="window.location.href='orders.php'" >&nbsp;&nbsp;<input type="button" value="<?php echo ACCOUNT_BACK_BUTTON;?>" name="btnBack"  class="button" onClick="window.location.href='myaccount.php'">
		<?php if($rr_settings['enable_rma']=='Y' &&  (substr_count( getOrderStatus($orderid),"Delivered")>0) && $refund_id==0 && $giftid==''){ ?> <input type="button"  value="<?php echo REQUEST_REFUND_TEXT;?>"  class="button"  onClick="window.location.href='refund_request.php?orderid=<?php echo $orderid;?>'" ><?php }?>
		</td></tr>
		</table>
		<div class="clear"></div>
		
		</div>
		
<?php
}
else
{
?>			
		<br>
		
			<table cellpadding="0" cellspacing="0" border="0" width="100%" class="responsive">
				<tr>
					<td align="center" class="text_information"><?php echo NO_ORDER_TEXT;?></td>				
				</tr>
			</table>	
		
		
<?php

} // end of url checking

?>		
		
	
	
		<div align="left" class="float_clear1"></div>
					
					
		 <!--items display area end -->
		  </div>
		
  </form>
		<!--center content area end-->	


		<div align="left" class="clear" ></div>		
		</div>
	</div>
</div>
<!--mainbody area end -->

		<div class="clear"></div>
				

<?php
include "includes/".$active_template[2];	/* Bottom File Name */
?>																		