<?PHP
ob_start();
session_start();
include 'connect.php';
if(isset($_SESSION['adminemail']))
{
$user=$_SESSION['adminemail'];

$gtp=mysql_query("select * from admin where username='$user'");
$gtp1=mysql_fetch_array($gtp);

include 'top.php';
?>



			<div class="main-content">
				<div class="main-content-inner">
					<div class="breadcrumbs ace-save-state" id="breadcrumbs">
						<ul class="breadcrumb">
							<li>
								<i class="ace-icon fa fa-home home-icon"></i>
								<a href="#">Home</a>
							</li>
							<li class="active">Product</li>
						</ul><!-- /.breadcrumb -->
					</div>

					<div class="page-content">
			

						<div class="page-header">
                        
<?php

$aca=mysql_query("select * from financial where user='$user' order by ID desc");
$aca1=mysql_fetch_array($aca);

$financial=$aca1['financial'];

?>                        
                        
							<table style="width:100%;">
                        
                        <tr><td style="width:50%;">
                        
							<h1>
								Product
							</h1>
                            
                            </td>
                            
                            <td style="width:50%; text-align:right; padding-right:15px; font-size:15px;">
                            
                            <i class="fa fa-calendar"></i>&nbsp; <?php echo $financial; ?>
                            
                            </td></tr></table>
                            
						</div><!-- /.page-header -->

						<div class="row">
							<div class="col-xs-12">
                            
								<!-- PAGE CONTENT BEGINS -->

<script src="assets/js/jquery.js"></script>

<script>

function acrate()
{
	
	var rate=$('.rate').val()*1;
	var discount=$('.discount').val()*1;

	var ac=rate-discount;

	$('.actualrate').val(ac);

}

$(document).ready(function(){

$('.rate').blur(acrate);
$('.discount').blur(acrate);

});

</script>

<script>
	
jQuery(function($){
		   
	// simple jQuery validation script
	$('#course').submit(function(){
		
		var valid = true;
		var errormsg = 'This field is required!';
		var errorcn = 'error';
		
		$('.' + errorcn, this).remove();			
		
		$('#required', this).each(function(){
			var parent = $(this).parent();
			if( $(this).val() == '' ){
				var msg = $(this).attr('title');
				msg = (msg != '') ? msg : errormsg;
				$('<span style="font-size:13px;color:#FF0000; padding-left:3px;" class="'+ errorcn +'">'+ msg +'</span>')
					.appendTo(parent)
					.fadeIn('fast')
					.click(function(){ $(this).remove(); });
				valid = false;
			};
		});
		
		return valid;
		
		$('input:submit').prop('disabled', true);
		
	});
	
});	

</script>



<?php


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

		$product=mysql_real_escape_string($_POST['product']);
		
		$rate=$_POST['rate'];
		
		$discount=$_POST['discount'];
		
		$actualrate=$_POST['actualrate'];
		
		$unit=$_POST['unit'];
		
		$category=mysql_real_escape_string($_POST['category']);


		if($category)
		{

			$insert=mysql_query("insert into product(product,category,unit,rate,discount,actualrate) values('$product','$category','$unit','$rate','$discount','$actualrate')") or die("unable to insert");

			if($insert)
			{

				header("location:viewproduct.php?s=2");

			}

		}

		else
		{

			echo "<script type='text/javascript'>alert('Field Missing.');</script><META HTTP-EQUIV = 'Refresh' Content = '1; URL =product.php'>";

		}

	}

	else
	{

	if (isset($_GET['s'])) 
	{

	 $status=$_GET['s'];

		 if($status=='1')
		 {

           echo'<div class="alert alert-block alert-danger">
									<button type="button" class="close" data-dismiss="alert">
										<i class="ace-icon fa fa-times"></i>
									</button>
						Product Created Successfully.
				  </div>';

		}

	}


		echo'<center><form action="product.php" method="post" id="course">
		
		
		<table width="60%" style="line-height:35px;">


		<tr><td id="page">Product <span class="red">*</span> </td><td>:</td><td> <input type="text" name="product" id="required" title="*" style="width:220px;" autocomplete="off" /></td></tr>
		
		
		<tr><td id="page">Unit </td><td>:</td><td> <input type="text" name="unit" style="width:220px;" autocomplete="off" class="unit" /></td></tr>
		
		
		<tr><td id="page">Rate </td><td>:</td><td> <input type="text" name="rate" style="width:220px;" autocomplete="off" class="rate" /></td></tr>
		
		
		<tr><td id="page">Discount </td><td>:</td><td> <input type="text" name="discount" style="width:220px;" autocomplete="off" class="discount" /></td></tr>
		
		
		<tr><td id="page">Actual Rate </td><td>:</td><td> <input type="text" name="actualrate" style="width:220px;" autocomplete="off" class="actualrate" /></td></tr>


		<tr><td id="page">Category <span class="red">*</span> </td><td>:</td><td><select name="category" id="required" title="*" style="width:220px;">
		
		<option value="">Select Category</option>';
		
		$cte=mysql_query("select * from product_category order by category asc");
		while($cte1=mysql_fetch_array($cte))
		{
		
			echo"<option value='".$cte1['ID']."'>".$cte1['category']."</option>";
			
		}
	
		echo'</select></td></tr>


		<tr><td></td><td></td><td style="padding-top:7px;"><input class="btn btn-sm btn-primary" type="submit" name="submit" value="Save" /></td></tr></table></form></center>';



	}



?>
                                                                
        
								

										<!-- PAGE CONTENT ENDS -->
									</div><!-- /.col -->
								</div><!-- /.row -->
							</div><!-- /.page-content -->
						</div>
					</div><!-- /.main-content -->


<?php
include 'bottom.php';
}
else
{

 header("location:login.php");
}
ob_flush();
?>