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

$gtp=mysqli_query($conn,"select * from admin where username='$user'");
$gtp1=mysqli_fetch_assoc($gtp);

include 'top.php';
?>


<div id="page-wrapper" >
          <div id="page-inner">
			<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">Customer</li>
						</ul><!-- /.breadcrumb -->
					</div>

					<div class="page-content">
			

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

$aca=mysqli_query($conn,"select * from financial where user='$user' order by ID desc");
$aca1=mysqli_fetch_assoc($aca);

$financial=$aca1['financial'];

?>
                        
                        <table style="width:100%;">
                        
                        <tr><td style="width:50%;">
                        
							<h1>
								Customer				
							</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>

$(".state").live('change',function() {

		  var state=$(this).val();

		  var dataString = 'state='+ state;

		  //alert(dataString);

		  $.ajax

		  ({

		  type: "GET",

		  url: "getdistrict.php",

		  data: dataString,

		  cache: false,

		  success: function(resp)

		  {
		  
		  $('.district').html($('#district',resp).html());

		  }

		  });

});


$(".district").live('change',function() {

		  var district=$(this).val();

		  var dataString = 'district='+ district;

		  //alert(dataString);

		  $.ajax

		  ({

		  type: "GET",

		  url: "gettaluk.php",

		  data: dataString,

		  cache: false,

		  success: function(resp)

		  {
		  
		  $('.taluk').html($('#taluk',resp).html());

		  }

		  });

});


$(".taluk").live('change',function() {

		  var taluk=$(this).val();

		  var dataString = 'taluk='+ taluk;

		  //alert(dataString);

		  $.ajax

		  ({

		  type: "GET",

		  url: "getvillage.php",

		  data: dataString,

		  cache: false,

		  success: function(resp)

		  {
		  
		  $('.village').html($('#village',resp).html());

		  }

		  });

});




</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;
		
		$('button:submit').prop('disabled', true);
		
	});
	
});	

</script>



<?php        

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

$name = $_POST['name'];

$fathername=$_POST['fathername'];

$customertype=$_POST['customertype'];

$doorno = $_POST['doorno'];

$street = $_POST['street'];

$village=$_POST['village'];

$postcode=$_POST['postcode'];

$taluk=$_POST['taluk'];

$district=$_POST['district'];

$landmark=$_POST['landmark'];

$state=$_POST['state'];

$mobile1=$_POST['mobile1'];

$mobile2=$_POST['mobile2'];

$irregationsystem=$_POST['irregationsystem'];

$typeofsoil=$_POST['typeofsoil'];

$totalland=$_POST['totalland'];

$cultivatingcrop=$_POST['cultivatingcrop'];

$cropstage=$_POST['cropstage'];

$lastapplied=$_POST['lastapplied'];

$nextapply=$_POST['nextapply'];

$executive=$_POST['executive'];

$lastpurchased=$_POST['lastpurchased'];

$qty=$_POST['qty'];

$crop=$_POST['crop'];

$reason=$_POST['reason'];

$product=$_POST['product'];

$aggricultureexp=$_POST['aggricultureexp'];

// now we insert it into the database

$date=date('Y-m-d',strtotime($date));

$lastapplied=date('Y-m-d',strtotime($lastapplied));
$nextapply=date('Y-m-d',strtotime($nextapply));

if($name)
{

$in= "INSERT INTO customer(name,fathername,doorno,street,village,postcode,taluk,district,landmark,state,mobile1,mobile2,irregationsystem,typeofsoil,totalland,cultivatingcrop,cropstage,lastapplied,nextapply,wantedqty,executive,lastpurchased,qty,crop,satisfied,reason,customertype,product,aggricultureexp)

			VALUES('$name','$fathername','$doorno','$street','$village','$postcode','$taluk','$district','$landmark','$state','$mobile1','$mobile2','$irregationsystem','$typeofsoil','$totalland','$cultivatingcrop','$cropstage','$lastapplied','$nextapply','$wantedqty','$executive','$lastpurchased','$qty','$crop','$satisfied','$reason','$customertype','$product','$aggricultureexp')";

$in1 = mysqli_query($conn,$in) or die(mysqli_error($conn));

if($in1)
{

 header("location:customer.php?s=1");

}

}

else
{

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

}

}

else 
{

 if (isset($_GET['s']))
	{
	 $status=$_GET['s'];
		
		 if($status=='1')
		 {
			 echo'<div class="alert alert-block alert-success">
									<button type="button" class="close" data-dismiss="alert">
										<i class="ace-icon fa fa-times"></i>
									</button>
						Customer Added Successfully.
				  </div>';				  
		 }
		 if($status=='2')
		 {
			 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>
						Values Not Inserted. Please try again.
				  </div>';				  
		 }
	}
	
$desig=mysqli_query($conn,"select * from employee_designation where designation='Executive'");
$desig1=mysqli_fetch_assoc($desig);

$design=mysqli_query($conn,"select * from employee_designation where designation='Team Leader'");
$design1=mysqli_fetch_assoc($design);

$sel=mysqli_query($conn,"select * from admin where username='$user'");
$nmrw=mysqli_num_rows($sel);
$sel1=mysqli_fetch_assoc($sel);
 
?>

<form id="course" action="customer.php" method="post">

<table width="70%" style="margin:auto; line-height:35px;">


<tr><td style="white-space: nowrap;  text-indent: -50px;">Name <span class="red"></span></td><td width="11"></td><td><input  class="form-control" style="width: 30ch; margin-bottom:10px" type="text" name="name" id="required" title="*" autocomplete="off" /></td>

<td></td><td style="white-space: nowrap; padding-left: 20px;">Father Name</td>
<td width="11"></td>
<td><input class="form-control" style="width: 30ch; margin-bottom:10px; margin-left: 30px;" type="text" name="fathername" autocomplete="off" /></td>
</tr>


<tr><td style="white-space: nowrap;  text-indent: -50px;">Door Number </td><td></td><td><input  class="form-control" style="width: 30ch; margin-bottom:10px" type="text" name="doorno" autocomplete="off" /></td>

<td></td><td style="white-space: nowrap; padding-left: 20px;">Street</td><td></td><td><input  class="form-control" style="width: 30ch; margin-bottom:10px; margin-left: 30px; " type="text" name="street" autocomplete="off" /></td></tr>


<tr><td style="white-space: nowrap;  text-indent: -50px;">State </td><td></td><td><select  style="width: 30ch; margin-bottom:10px;padding-left:10px; height:34px;border-radius: 5px;border: 1px solid #c0c0c0;" name="state" class="state" style="width:220px;"><option value="">-- Select --</option>

<?php

$ste=mysqli_query($conn,"select * from statecode order by ID asc");
while($ste1=mysqli_fetch_assoc($ste))
{
	echo"<option value='".$ste1['ID']."'>".$ste1['state']."</option>";
}

?>

</select></td>

<td></td><td style="white-space: nowrap; padding-left: 20px;">District </td><td></td><td><select   style="width: 30ch; margin-bottom:10px; margin-left: 30px;padding-left:10px; height:34px;border-radius: 5px;border: 1px solid #c0c0c0;" name="district" class="district" style="width:220px;"><option value="" selected="selected">-- Select --</option></select></td></tr>


<tr><td style="white-space: nowrap;  text-indent: -50px;">Taluk </td><td></td><td><select  style="width: 30ch; margin-bottom:10px;padding-left:10px; height:34px;border-radius: 5px;border: 1px solid #c0c0c0;" name="taluk" class="taluk" style="width:220px;"><option value="">-- Select --</option></select></td>

<td></td><td style="white-space: nowrap; padding-left: 20px;">Village</td><td></td><td><select   style="width: 30ch; margin-bottom:10px; margin-left: 30px;padding-left:10px; height:34px;border-radius: 5px;border: 1px solid #c0c0c0;" name="village" class="village" style="width:220px;"><option value="">-- Select --</option></select></td></tr>


<tr><td style="white-space: nowrap;  text-indent: -50px;">Land Mark </td><td></td><td><input  class="form-control" style="width: 30ch; margin-bottom:10px" autocomplete="off" type="text" name="landmark" autocomplete="off" /></td>

<td></td><td style="white-space: nowrap; padding-left: 20px;">Post &amp; Via</td><td></td><td><input  class="form-control" style="width: 30ch; margin-bottom:10px; margin-left: 30px;" type="text" name="postcode" autocomplete="off" /></td></tr>


<tr><td style="white-space: nowrap;  text-indent: -50px;">Mobile 1 <span class="red"></span></td><td></td><td><input  class="form-control" style="width: 30ch; margin-bottom:10px" autocomplete="off" type="text" name="mobile1" id="required" title="*" autocomplete="off" /></td>

<td></td><td style="white-space: nowrap; padding-left: 20px;">Mobile 2 </td><td></td><td><input  class="form-control" style="width: 30ch; margin-bottom:10px; margin-left: 30px;" type="text" name="mobile2" autocomplete="off" /></td></tr>


<tr><td style="white-space: nowrap;  text-indent: -50px;">Customer Type </td><td></td><td><select  class="form-control" style="width: 30ch; margin-bottom:10px" name="customertype" style="width:220px;"><option value="Farmer">Farmer</option>
<option value="Non-Farmer">Non-Farmer</option></select></td>

<td></td><td style="white-space: nowrap; padding-left: 20px;">Product Required </td><td></td><td><select  class="form-control" style="width: 30ch; margin-bottom:10px; margin-left: 30px;" name="product" style="width:220px;"><option value="">-- Product --</option>

<?php

$prd=mysqli_query($conn,"select * from product where (category='1' or category='2' or category='3' or category='4') order by ID asc");
while($prd1=mysqli_fetch_assoc($prd))
{
	echo"<option value='".$prd1['ID']."'>".$prd1['product']."</option>";
}

?>

</select></td></tr>


<tr><td style="white-space: nowrap;  text-indent: -50px;">Irregation System </td><td></td><td><input  class="form-control" style="width: 30ch; margin-bottom:10px" autocomplete="off" type="text" name="irregationsystem" autocomplete="off" /></td>

<td></td><td style="white-space: nowrap; padding-left: 20px;">Type of Soil </td><td></td><td><input  class="form-control" style="width: 30ch; margin-bottom:10px; margin-left: 30px;" autocomplete="off" type="text" name="typeofsoil" autocomplete="off" /></td></tr>


<tr><td style="white-space: nowrap;  text-indent: -50px;">Total Land </td><td></td><td><input  class="form-control" style="width: 30ch; margin-bottom:10px" autocomplete="off" type="text" name="totalland" autocomplete="off" /></td>

<td></td><td style="white-space: nowrap; padding-left: 20px;">Cultivating Crops </td><td></td><td><input  class="form-control" style="width: 30ch; margin-bottom:10px; margin-left: 30px;" autocomplete="off" type="text" name="cultivatingcrop" autocomplete="off" /></td></tr>


<tr><td style="white-space: nowrap;  text-indent: -50px;">Crop Stage </td><td></td><td><input  class="form-control" style="width: 30ch; margin-bottom:10px" autocomplete="off" type="text" name="cropstage" autocomplete="off" /></td>

<td></td><td style="white-space: nowrap; padding-left: 20px;">Last Applied </td><td></td><td><input  class="form-control" style="width: 30ch; margin-bottom:10px; margin-left: 30px;" autocomplete="off" type="text" name="lastapplied" class="datepicker" autocomplete="off" /></td></tr>


<tr><td style="white-space: nowrap;  text-indent: -50px;" >Next Apply </td><td></td><td><input  class="form-control" style="width: 30ch; margin-bottom:10px" autocomplete="off" type="text" name="nextapply" class="popupdatepicker" autocomplete="off" /></td>

<td></td><td style="white-space: nowrap; padding-left: 20px;">Last Purchased </td><td></td><td><input  class="form-control" style="width: 30ch; margin-bottom:10px; margin-left: 30px;" autocomplete="off" type="text" name="lastpurchased" autocomplete="off" /></td></tr>


<tr><td style="white-space: nowrap;  text-indent: -50px;">Aggriculture Exp </td><td></td><td><input  class="form-control" style="width: 30ch; margin-bottom:10px" autocomplete="off" type="text" name="aggricultureexp" autocomplete="off" /></td>

<td></td><td></td><td></td><td></td></tr>


<tr><td style="white-space: nowrap;  text-indent: -50px;">Quantity </td><td></td><td><input  class="form-control" style="width: 30ch; margin-bottom:10px" autocomplete="off" type="text" name="qty" autocomplete="off" /></td>

<td></td><td style="white-space: nowrap; padding-left: 20px;">Reason </td><td></td><td><textarea  class="form-control" style="width: 30ch; margin-bottom:10px; margin-left: 30px;" name="reason" style="width:220px; height:75px;"></textarea></td></tr>

<?php

if($nmrw>0)
{

echo'<tr><td style="white-space: nowrap;  text-indent: -50px;">Executive </td><td></td><td><select  class="form-control" style="width: 30ch; margin-bottom:10px" name="executive" style="width:220px;"><option value="">Select Executive</option>';

$exec=mysqli_query($conn,"select * from employee order by name asc");
while($exec1=mysqli_fetch_assoc($exec))
{
	echo"<option value='".$exec1['ID']."'>".$exec1['name']."</option>";
}

echo'</select></td></tr>';

}
else
{

$empd=mysqli_query($conn,"select * from employee where username='$user'");
$empd1=mysqli_fetch_assoc($empd);

$usr=$empd1['ID'];

echo"<input type='hidden' name='executive' class='executive' value='".$usr."' />";

}

?>

<tr><td colspan="3" style="text-align:center; padding-top:7px;"><button style="margin-left:400px;" type="submit" name="submit" class="btn btn btn-primary">Submit</button></td></tr>

</table>

</form>

<?php

}
	
?>
                                                                
        
								

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


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

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