<?php
	session_start(0);
	error_reporting(0);
	include("config.php");
	$id = mysql_query("SELECT serial FROM orders ORDER BY serial DESC LIMIT 1");
	$id = mysql_fetch_array($id);
	$order_id=$id['serial'];
	  $inc=$order_id+1;
	 $anu="AM";
	$user=$_SESSION['username'];
	// Check, if username session is NOT set then this page will jump to login page
	if (!isset($_SESSION['username']))
		{
			header("Location:login.php");
		}
        include("include/functions.php");
	
	if(isset($_REQUEST['submit'])){
		 $name=$_REQUEST['name'];
		$email=$_REQUEST['email'];
		$address=$_REQUEST['address'];
		$city=$_REQUEST['city'];
		$phone=$_REQUEST['phone'];
		$ship=$_REQUEST['ship'];
		
		$pay=$_REQUEST['pay'];
		
	
		
		
		//start implode 
		 $proid=$_REQUEST['proid'];
		 $proid = implode(",",$proid);
		
		$pname=$_REQUEST['pname'];
		 $pname = implode(",",$pname);
		
		$qnty=$_REQUEST['qnty'];
		$qnty = implode(",",$qnty);
		//end implode
		
		 
		$amount1=$_REQUEST['amount'];
		$shippingcost=$_REQUEST['shippingcost'];
		
	 	$amount=$amount1+$ship;
		$customer_id=$_REQUEST['customer_id'];
		
		
		date_default_timezone_set('Asia/Kolkata');
		 $ddate=date('Y-m-d');// date for insert table
	     $date=date('dmY');// date for cancatenate
	     $conca=$anu.$date.$customer_id.$inc;
	    
	    
$set=mysql_query("select * from `picture` where id='1'");
$fet=mysql_fetch_array($set);	    
$logo=$fet['image'];	    
$to .=$email;
$subject = "Order Confirmation";
$message .= "<div style=width:700px; height:730px; border:solid; color:#00F;>
<div style='width:700px; height:140px;'>
<div style='float:left; width:300px; height:140px;'><img src='".$activatieon_url."/CryoM@dmin/$logo' width='400' height='150' /></div>
<div style=' float:left;width:300px; height:140px; margin-left:70px;'>
<div style='margin-left:150px;font-size:20px; color:#03C'><p><img src='".$activatieon_url."/images/cal.jpg' width='67' height='59'></p><p>+91 9677646815</p><p>&nbsp;</p>
</div>
</div>
</div>
<div style='margin-left:10px; color:#000'>--------------------------------------------------------------------</div>
<div style='width:750px; height:140px;'>
<div style='float:left; width:px; height:140px;'>
<div style='margin-left:20px;font-size:20px; color:#03C; margin-top:60px;'>
Dear <font size='8'>".$name."</font></div>
</div>
<div style=' float:left;width:100px; height:140px;'>
<div style='margin-left:-10px;font-size:20px; color:#03C'><p><img src='".$activatieon_url."/images/xx.jpg' width='131' height='124'></p>
</div>
</div>
</div>
<div style='width:750px;; height:140px;'>
<div style='height:110px; width:700px; margin-top:30px; margin-left:150px;'>
  <p>We will defenitely help you!!!!!......</p>
  <p>Exited???? We defenitely are!!...</p>
  <p>Moving On Here are the details of your order:</p>
  <p>Order ID:&nbsp;&nbsp;<font color='black'><b>".$conca."</b></font> </p>
</div>
</div>
<div style='width:750px; height:110px;'>
<table width='693' height='99' border='1' bordercolor='#999999'>
<tr>
	<th width='182' height='52'>Product Name</th>
	<th width='87'>Quantity</th><th width='130'>date</th>
	<th width='156'>Toatal Order Amount</th><th width='104'>Status</th>
</tr>
<tr>
	<td align='center'>".$pname."</td>
	<td align='center'>".$qnty."</td>
	<td align='center'>".$ddate."</td>
	<td align='center'>&#x20B9;".$amount."</td>
	<td align='center'>Not Paid</td>
</tr>
</table>
</div>
<div style='width:730; height:30; margin-left:5px;'>
<b>Note:</b> Keep your order number handy for any future communication with us regarding this number.
</div>
<div style='width:750px; height:50px;'>
<div style='width:200px; height:70px; margin-left:250px; color:#900;'>
  <h2>Happy Shopping!!!</h2>
  <h4>&nbsp;&nbsp;&nbsp;&nbsp;Our Team </h4>
</div>
</div>
</div>";
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From:<info@infostech.com>'."\r\n";
$headers .= 'Cc: ' . "\r\n";
$headers .= 'Bcc: ' . "\r\n";
mail($to, $subject, $message, $headers);
	    
	    //SMS
		/*
		$url ='http://bulksms.mysmsmantra.com:8080/WebSMS/SMSAPI.jsp?username=darsara&password=indian12&sendername=dasara&mobileno='.$phone.'&message=your-Order-ID:'.$conca.'-your-amount-Rs:'.$amount.''; 
		$ch = curl_init($url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		$curl_scraped_page = curl_exec($ch);
		curl_close($ch);
		$curl_scraped_page;
		*/
	
	    $result=mysql_query("insert into `orders` values('','$ddate','$customer_id','$name','$address','$city','$email','$phone','$proid','$pname','$qnty','','$amount','$shippingcost','$conca','','','$pay','','','','')");
		$orderid=mysql_insert_id();
		$resultt=mysql_query("insert into `trackorder` values('','$conca','$name','$phone','','','','')");
		$orderidd=mysql_insert_id();
		
//.TAX START..........................................
		 $select="select * from `orders` where `order_id`='$conca'";
		$run=mysql_query($select);
		while($row = mysql_fetch_array($run))
		{

 $items = explode (",",$row['product_id']); 
$quantities = explode (",",$row['quantity']);
$date= $row['date'];

$number = count($items); 
for ($i=0; $i<=$number; $i++) 
{ 
     $itno = $items[$i]; 
     $quant = $quantities[$i]; 
	 
	     $query_select13=mysql_query("select * from  `products` where `serial`='$itno'");
		 $fetch1234=mysql_fetch_array($query_select13);
		 $real_cost= $fetch1234['pur_price'];
		 $sell_cost= $fetch1234['price'];
		 $tot_amount=$quant*$sell_cost;
		 $profit=$sell_cost-$real_cost;		 
		 $total_profit=$quant*$profit;
		 $sale_tax= $fetch1234['sale_tax'];
    	 $tot_tax=$sale_tax*$quant; 
		 
        $insertprofit="insert into `profit`(`product_id`,`real_cost`,`sell_cost`,`tot_amount`,`profit`,`date`,`order_id`,`quantity`,`total_profit`,`sale_tax`,`tot_tax`)
		values('$itno','$real_cost','$sell_cost','$tot_amount','$profit','$date','$conca','$quant','$total_profit','$sale_tax','$tot_tax')";
  
	 	 $add=mysql_query($insertprofit); 
		 } 
		}
		//.TAX END..........................................
		
		
	//......ADD BANK........................
	$conca=base64_encode($conca);
	$query_select=mysql_query("select * from `bank1` order by `id` desc ");
	 $run_query=mysql_fetch_array($query_select);
	 $collection=$run_query['collection'];
	$collection2=$collection+$amount;
	$close=$run_query['closecash'];
	$clos=$close+$amount;
	 $update=mysql_query("update `bank1` set `closecash`='$clos',`collection`='$collection2' where `cashdate`='$ddate'"); 
	//.........END BANK.............................
	
	
$pay=$_REQUEST['pay'];
	if($pay=='Paymentgateway'){
       ?><script>window.location="payment.php?ad=su&&co=<? echo $conca?>&&paytype=pay&&phone=<? echo $phone; ?>";</script><? } 
	if($pay=='COD') {
      ?><script>window.location="payment.php?ad=su&&co=<? echo $conca; ?>&&paytype=cod";</script><? }}
?>
<!DOCTYPE HTML>
<html>
	<head>
		<title><?php echo $tittle;?></title>
		<link href="css/style.css" rel='stylesheet' type='text/css' />
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<script type="application/x-javascript"> addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } </script>
		</script>
		<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700,800' rel='stylesheet' type='text/css'>
		<script src="js/jquery.min.js"></script>
		<script type="text/javascript" src="js/jquery.easy-ticker.js"></script>
		<script type="text/javascript">
		$(document).ready(function(){
			$('#demo').hide();
			$('.vticker').easyTicker();
		});
		</script>
		<link href="css/megamenu.css" rel="stylesheet" type="text/css" media="all" />
		<script type="text/javascript" src="js/megamenu.js"></script>
		<script>$(document).ready(function(){$(".megamenu").megamenu();});</script>
		<script src="js/menu_jquery.js"></script>
		<link rel="stylesheet" href="css/slippry.css">
       </head>
	<body>
			<?php include("include/header.php"); ?>
		<div class="clear"> </div>
		<div class="wrap">
			<div class="price-rage">
			</div>
		</div>
		<div class="content">
			<div class="wrap">
				<div class="content-left">
						<div class="content-left-top-grid">
							<div class="content-left-price-selection">
						</div>
						</div>
						<?php include("include/left.php"); ?>
				</div>
				<div class="content-right">
					<div class="product-grids">
           <div class="register-grids">              
           <form name="form1" action="<?php echo $_SERVER['PHP_SELF']; ?>" autocomplete="off" id="chgpass">
		       <script src="prototype.js" type="text/javascript"></script>
               <script src="validation.js" type="text/javascript"></script>
               
				 <div class="register-top-grid">
					<h3>ORDER CONFIRMATION / PAYMENT METHOD</h3>
                    <?php
                if(is_array($_SESSION['cart'])){
                     $max=count($_SESSION['cart']);
                    for($i=0;$i<$max;$i++){
                        $pid=$_SESSION['cart'][$i]['productid'];
                         $q=$_SESSION['cart'][$i]['qty'];
                         $pname=get_product_name($pid);
                        if($q==0) continue;
                        $qur="select * from `products` where `serial` ='$pid' order by serial desc "; 
            $result = mysql_query($qur)or die('Have an error in viewing data'.mysql_error());
            $row_section = mysql_fetch_array($result);
                                $product_id=$row_section['product_id'];
                ?>
                <input type="hidden" name="pname[]" value="<?php echo $pname?>"/>
                <input type="hidden" name="qnty[]" value="<?php echo $q?>"/>
                <input type="hidden" name="proid[]" value="<?php echo $pid?>"/>
                
                 <?php }} ?>
                <?
                $selshippicost=mysql_query("select * from `picture` where `id`='9'");
 $shippingcost=mysql_fetch_array($selshippicost);
 $shippingcost1234=$shippingcost['image']*$q;
 $net_total_orders=get_order_total();
 $net_total_orders12345=$net_total_orders+$shippingcost1234;
 ?>
					 <div>
					<span>Order Total</span>
					<input type="text" name="order_total" value="<?php echo get_order_total()?>" required readonly/> 
					 </div>
                     <div>
					<span>Shipping Cost</span>
					<input type="text" name="shippingcost" value="<?php echo $shippingcost1234;?>" required readonly/> 
					 </div>
                     <div>
					<span>Net Total</span>
					<input type="text" name="amount" value="<?php echo $net_total_orders12345;?>" required readonly/> 
					 </div>
                    <?
$user=$_SESSION['username'];
$select="select * from `shipping_address` where `username`='$user' order by `id` desc";
$result=mysql_query($select);
$row = mysql_fetch_array($result);
?>
                     <input type="hidden" name="customer_id" value="<?php echo $row['id']; ?>" readonly/> 
                     <div>
						<span>Contact No</span>
						<input type="text" name="phone" value="<?php echo $row['phone']; ?>" required readonly/> 
					 </div>
                     <div>
						<span>Your Name</span>
						<input type="text" name="name" value="<?php echo $row['name']; ?>" required readonly> 
					 </div>
                     <div>
						<span>Email</span>
						<input type="text" name="email" value="<?php echo $row['email']; ?>" required readonly> 
					 </div>
                     <div>
<span>Address</span>
<textarea required name="address" style="width:440px;resize:none;height:80px;"><?=$row['door_no'];?>,<?=$row['locality'];?>,<?=$row['street'];?>,<?=$row['city'];?>,<?=$row['district'];?>,<?=$row['state'];?>,<?php echo $row['country'];?>pin-<?=$row['pincode'];?></textarea>
					 </div>
                     <div>
						<span>PAYMENT METHOD</span>
						<input type="radio" name="pay" required value="Paymentgateway">PAYMENT GATEWAY
						<input type="radio" name="pay" required value="COD">COD
					 </div>
                     <div>
						<span><label style="color:#F00;"></label></span>
						 <input class="sub" type="submit" name="submit" value="submit"> 
					 </div>
                      </div>
                   </form>
<script type="text/javascript">
						function formCallback(result, form) 
						{window.status = "valiation callback for form '" + form.id + "': result = " + result;}
						var valid = new Validation('chgpass', {immediate : true, onFormValidate : formCallback});
					</script>    
		  </div>   
		  </div>
          </div>
		</div>
	</div>
    <div class="clearfix" style="clear:both;"> </div>
	<?php include("include/footer.php"); ?>