<?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.                                                       |
// +----------------------------------------------------------------------+
?>
<?php
include "../includes/config.php";
include "../includes/session.php";
include "../includes/functions.php";

if(isset( $_SESSION["sess_artistid"]) and $_SESSION["sess_artistid"]!= ""){
	$artistid = $_SESSION["sess_artistid"];
}else{
	header("Location:login.php");
	exit;
}

if(checkArtistExpired($artistid)){
	header("Location:seller_plan_upgrade.php?sellerid=".$artistid);
	exit;
}



$order_id = substr($_GET['order_id'],0,strlen($_GET['order_id'])-1);

$order_split = explode(',',$order_id);

//print_r($order_split);

/*foreach($order_split as $order_value)
{

$sql = "SELECT od.product_name,od.product_price,od.product_quantity,prd.product_description,usr.email,usr.first_name,usr.last_name,
			   od.product_discount,art.artist_name
		FROM ".$tableprefix."order_details od,".$tableprefix."products prd,".$tableprefix."orders ord
		 ,".$tableprefix."users usr,".$tableprefix."artists art
		 WHERE od.product_id = prd.product_id
		  AND od.artist_id = art.artist_id
		   AND ord.order_id = ".$order_value.
		  " AND ord.user_id = usr.user_id
		    AND od.order_id = ".$order_value;
			
echo $sql; 		
			
}			*/
		
/*$result = mysql_query($sql) or die(mysql_error());	*/	

/*$select_email_template = "SELECT vemail_body,vreplaceable_variables 
						  FROM ".$tableprefix."email_templates 
						  WHERE vtemplate_name = 'order_acknowledgement' "; */

$select_email_template =  "SELECT rev_tbl.* FROM (SELECT * FROM ".$tableprefix."email_templates WHERE vtemplate_name = 'order_acknowledgement' order by artist_id ='".$artistid."' DESC) as rev_tbl
 group by rev_tbl.vtemplate_name";
						  
$result_email_template = mysql_query($select_email_template) or die(mysql_error());

if(mysql_num_rows($result_email_template) > 0)
{

	$email_body = mysql_fetch_assoc($result_email_template);
	
	$email_template_body = $email_body['vemail_body'];


}						  

include "../includes/htmltop.php";
?>
<script language="JavaScript" type="text/JavaScript">

</script>

		<body>
		
		<center>
		
		<div align="left" id="layout">
		
		<!--header area start -->


		<div align="left" class="header">
		<!--header area start -->
		
			<div align="left" class="logo"><img src="<?php echo $logofolder?>/<?php echo $logoimage?>" alt="" width="125" height="39" /></div>
			
			<div align="right" class="logouts_2">&nbsp;</div>
					
		<!--header area end -->
		</div>
		
		<div align="left" class="main_body">
		<!--main body start -->
													
						
			<div align="left" class="content_area">
			
			<!--content area start -->
					
			<div align="left" class="page_title"><?php echo SALES_ORDER_MAIL;?></div>
			<div align="center" class="text_information grey_tr"><?php echo $message?></div>
			<br>
									
			<div align="left">			
														
			<form action="" method="post" name="frmGiftCoupon">
				
						
<?php

$order_product_details = "";

if(!empty($order_split))
    {
        $order_value = implode("','",$order_split);
}



if(isset($_POST['submit']))
{

		
		$order_product_details = "";


                 $sql_ord="SELECT ord.order_id,ord.billing_email,ord.billing_first_name,ord.billing_last_name
                                    FROM  ".$tableprefix."orders ord where ord.order_id IN ('".$order_value."')  ORDER BY ord.order_id ";

                 $rs_ord = mysql_query($sql_ord) or die(mysql_error());

                 while($pr_rows=mysql_fetch_array($rs_ord)){ 

                                $txtFirstName = $pr_rows['billing_first_name'];
				$txtLastName =  $pr_rows['billing_last_name'];
				$txtSellerName = $_SESSION["sess_artistname"];

                                $useremail=    $pr_rows['billing_email'];
                                
                                $order_id = $pr_rows['order_id'];


                $sql="SELECT od.order_id,od.artist_id,od.product_name,od.product_price,od.product_quantity,od.product_code,ord.billing_email,ord.billing_first_name,ord.billing_last_name,od.product_discount,art.artist_name,art.email as sellermail
                        FROM  ".$tableprefix."orders ord  INNER JOIN ".$tableprefix."order_details od ON od.order_id =ord.order_id
                        INNER JOIN ".$tableprefix."artists art ON od.artist_id=art.artist_id where ord.order_id IN ('".$order_id."') AND od.artist_id=".$artistid."  ORDER BY od.order_id ";
		
		$result = mysql_query($sql) or die(mysql_error());


                 $table_start = "<div align='center'>&nbsp;</div><table width='100%' border='0' cellpadding='0' cellspacing='0' class='manage_table' ><tr><td colspan='6' align='left'> <h4>&nbsp;&nbsp;&nbsp;&nbsp;".TEXT_ORDER_ID."  : ".$order_id." </h4></td></tr><tr><td colspan='6' align='left'> &nbsp;</td><tr><th width='14%' class='maintext'><b>".TXT_PRODUCT_NAME."</b></th><th width='22%' class='maintext'><b>".TXT_PRODUCT_CODE."</b></th><th width='18%' class='maintext'><b>".TXT_PRODUCT_QUQNTITY."</b></th><th width='18%' class='maintext'><b>".TEXT_PRODUCT_PRICE."</b></th><th width='28%' class='maintext'><b>".TEXT_PRODUCT_DISCOUNT."</b></th></tr>
                <tr><td colspan='6'>&nbsp;</td></tr>";
		$table_end = "<tr><td colspan='5'>&nbsp;</td></tr></table><div align='center'>&nbsp;</div>";

               $order_product_details = "";
		if(mysql_num_rows($result) > 0)
		{
			while($product_row = mysql_fetch_array($result))
			{
                           								
				$order_product_details.= "<tr><td  class='maintext' align='center'>".stripslashes($product_row['product_name'])."</td><td  class='maintext' align='center'>".stripslashes($product_row['product_code'])."</td><td  class='maintext' align='center'>".stripslashes($product_row['product_quantity'])."</td><td  class='maintext' align='center'>".$product_row['product_price']."</td><td  class='maintext' align='center'>".stripslashes($product_row['product_discount'])."&nbsp;%</td></tr><br>";
				
				
				$txtEmail = $product_row['sellermail'];
				
				
                               
		   $format_product_details = $table_start.$order_product_details.$table_end;

		
			} // end while
                        
                        
                $mail_start = " <html><head><style>.maintext{font-family: Arial, Helvetica, sans-serif;font-size: 12px;line-height: 20px;color: #000000;text-decoration: none;}</style><link href='".SITE_URL."/style/template1-admin.css' rel='stylesheet' type='text/css'></head><body><center>
		<table width='100%' border='0' cellpadding='2' cellspacing='2' class='manage_table'  style='background-color:#FFFFFF; border:#D5D5D5 solid 1px;font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#000000;'><tr><td>
		<div align='left' id='layout'><div align='left' class='header'><div align='left' class='logo'><img src=".$logofolder."/".$logoimage." width='125' height='39'/></div></div><div>".stripslashes($email_template_body);
		$mail_end =  "</div></div><div align='left' class='clear_float'><img src=".$imagefolder."/clear.gif width=1 height=1/></div></div>";
		$mail_end .= "</div></td></tr></table></center></body></html>";
                
                $mail_body = str_replace('[first_name]',$txtFirstName,$mail_start);
		$mail_body = str_replace('[last_name]',$txtLastName,$mail_body);
		$mail_body = str_replace('[product_details]',$format_product_details,$mail_body);
		$mail_body = str_replace('[seller_name]',$txtSellerName,$mail_body);
		$txtEmailDownload = $useremail;


		$subjectDownload = MAIL_SALES_ACK_TEXT_SUBJECT_DOWNLOAD; // Sales Order Acknowledgement

		$headers  = "MIME-Version: 1.0" . "\r\n";
		$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
		$headers .= "From: ".SITE_NAME."<".$txtEmail.">" . "\r\n";
		$headers .= "Reply-To: ".SITE_NAME."<".$txtEmail.">" . "\r\n";
		$headers .= "Return-Path: ".SITE_NAME."<".$txtEmail.">" . "\r\n";
		$headers .= "Organization: ".SITE_NAME."\r\n";

		/*$headersDownload  = "MIME-Version: 1.0\r\n";
		$headersDownload .= "Content-type: text/html; charset=iso-8859-1\r\n";
		$headersDownload .= "From: ".SITE_EMAIL."<".SITE_EMAIL.">\r\n";
		//$headersDownload = "From: ".SITE_EMAIL."<".SITE_EMAIL.">\r\n";*/
		$product_download_details = $mail_body.$mail_end;
		$product_download_details = nl2br($product_download_details);

              //    echo "<br>".$product_download_details;exit;


		//$txtEmailDownload='asha.s@armiasystems.com';

		mail($txtEmailDownload,$subjectDownload,$product_download_details,$headers);
						



                }// end order loop

			
	
		} // end if
		
			
		
		
		
		$message = ORDER_ACK_TEXT;									
											
		
				
	
		
} // end first if								
?>										
				
					
					<table cellpadding="0" cellspacing="0" border="0" width="100%" class="manage_table">
					<tr>
						<td class="text_information grey_tr" colspan="3" align="center"><?php echo $message?></td>
					</tr>
					<tr>
						<td colspan="3" align="center">&nbsp;</td>
					</tr>
					<tr>
						<td width="22%"><?php echo TEXT_EMAIL_BODY;?></td>
						<td width="57%" align="left">
<?php 

echo nl2br($email_body['vemail_body'])

?>
						</td>
					</tr>
					<tr>
						<td colspan="3" align="center">&nbsp;</td>
					</tr>
					<tr>
						<td><?php echo REPLACE_VARS_TEXT;?></td>
						<td colspan="2"><?php echo $email_body['vreplaceable_variables']?></td>
					</tr>
					<tr>
						<td colspan="3">&nbsp;</td>
					</tr>
					<tr>
						<td>&nbsp;</td>
						<td colspan="2"><span class="required">*</span>&nbsp;<?php echo REPLACE_VAR_TEXT;?></td>
					</tr>
					<tr>
						<td colspan="3">&nbsp;</td>
					</tr>
<?php
	$replaceable_variables = explode(',',$email_body['vreplaceable_variables']);
		
	foreach($replaceable_variables as $replaceable_value)
	{
	
		$format_value = str_replace('[',' ',$replaceable_value);
		$format_value = str_replace(']',' ',$format_value);
		$format_value = str_replace('_',' ',$format_value);
		
?>						
						<tr>
							<td>&nbsp;</td>
							<td><img src="../images/arrow1.gif">&nbsp;<?php echo $replaceable_value?> will be replaced by <b><?php echo ucwords(trim($format_value))?></b></td>
						</tr>
						
<?php
	}


?>											
					<tr>
						<td colspan="3">&nbsp;</td>
					</tr>
					<tr>
						<td align="center" colspan="3">
							<input type="submit" name="submit" value="<?php echo SEND_BUTTON;?>" class="button">
							<input type="button" name="close" value="<?php echo CLOSE_BUTTON;?>" class="button" onClick="Javascript:window.close();">
						</td>
					</tr>
					</table>
					
					
					</form>
				
				</div>
						
					
						
						
				<!--content area end-->
								
				</div>
				
								
					<div align="left" class="clear_float"><img src="<?php echo $imagefolder;?>/clear.gif" alt="" width="1" height="1" /></div>
				<!--main body end -->
				</div>
				
				
<?php
	include "../includes/footer.php";
?>