<?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">Customers</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>

								Customers

							</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($_GET['id']))

{



$id=$_GET['id'];



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

{



$id=$_POST['id'];



$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= "update customer set name='$name',fathername='$fathername',doorno='$doorno',street='$street',village='$village',postcode='$postcode',taluk='$taluk',district='$district',landmark='$landmark',state='$state',mobile1='$mobile1',mobile2='$mobile2',irregationsystem='$irregationsystem',typeofsoil='$typeofsoil',totalland='$totalland',cultivatingcrop='$cultivatingcrop',cropstage='$cropstage',lastapplied='$lastapplied',nextapply='$nextapply',wantedqty='$wantedqty',executive='$executive',lastpurchased='$lastpurchased',qty='$qty',crop='$crop',satisfied='$satisfied',reason='$reason',product='$product',aggricultureexp='$aggricultureexp' where ID='$id'";



$in1 = mysql_query($in) or die(mysql_error());



if($in1)

{



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



}



}



else

{



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



}



}



else

{



$ex=mysql_query("select * from customer where ID='".$id."'");

$ex1=mysql_fetch_array($ex);



$desig=mysql_query("select * from employee_designation where designation='Executive'");

$desig1=mysql_fetch_array($desig);



$design=mysql_query("select * from employee_designation where designation='Team Leader'");

$design1=mysql_fetch_array($design);





$sel=mysql_query("select * from admin where username='$user'");

$nmrw=mysql_num_rows($sel);

$sel1=mysql_fetch_array($sel);

 



if($ex1['lastapplied']!='0000-00-00' && $ex1['lastapplied']!='1970-01-01')

{

	$lastapplied=date('d-m-Y',strtotime($ex1['lastapplied']));

}



if($ex1['nextapply']!='0000-00-00' && $ex1['nextapply']!='1970-01-01')

{

	$nextapply=date('d-m-Y',strtotime($ex1['nextapply']));

}



echo'<form id="course" action="viewcustomer.php?id='.$id.'" method="post">



<input type="hidden" name="id" value="'.$id.'" />





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





<tr><td>Name <span class="red">*</span></td><td width="11">:</td><td><input type="text" name="name" id="required" title="*" value="'.$ex1['name'].'" autocomplete="off" /></td>



<td></td><td>Father Name </td><td width="11">:</td><td><input type="text" name="fathername" value="'.$ex1['fathername'].'" autocomplete="off" /></td></tr>





<tr><td>Door Number </td><td>:</td><td><input type="text" name="doorno" value="'.$ex1['doorno'].'" autocomplete="off" /></td>



<td></td><td>Street</td><td>:</td><td><input type="text" name="street" value="'.$ex1['street'].'" autocomplete="off" /></td></tr>





<tr><td>State </td><td>:</td><td><select name="state" class="state" style="width:220px;"><option value="">-- Select --</option>';



$ste=mysql_query("select * from statecode order by ID asc");

while($ste1=mysql_fetch_array($ste))

{

	$sst="<option value='".$ste1['ID']."'>".$ste1['state']."</option>";

	$sst=str_replace("<option value='".$ex1['state']."'","<option value='".$ex1['state']."' selected",$sst);

	echo $sst;

}



echo'</select></td>



<td></td><td>District </td><td>:</td><td><select name="district" class="district" style="width:220px;"><option value="" selected="selected">-- Select --</option>';



$disn=mysql_query("select * from districts where state='$ex1[state]'");

while($disn1=mysql_fetch_array($disn))

{

	$sdis="<option value='".$disn1['ID']."'>".$disn1['district']."</option>";

	$sdis=str_replace("<option value='".$ex1['district']."'","<option value='".$ex1['district']."' selected",$sdis);

	echo $sdis;

}



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





<tr><td>Taluk </td><td>:</td><td><select name="taluk" class="taluk" style="width:220px;"><option value="" selected="selected">-- Select --</option>';



$tlk=mysql_query("select * from taluk where district='$ex1[district]'");

while($tlk1=mysql_fetch_array($tlk))

{

	$stlk="<option value='".$tlk1['ID']."'>".$tlk1['taluk']."</option>";

	$stlk=str_replace("<option value='".$ex1['taluk']."'","<option value='".$ex1['taluk']."' selected",$stlk);

	echo $stlk;

}



echo'</select></td>



<td></td><td>Village</td><td>:</td><td><select name="village" class="village" style="width:220px;"><option value="" selected="selected">-- Select --</option>';



$vil=mysql_query("select * from villages where taluk='$ex1[taluk]'");

while($vil1=mysql_fetch_array($vil))

{

	$svil="<option value='".$vil1['ID']."'>".$vil1['village']."</option>";

	$svil=str_replace("<option value='".$ex1['village']."'","<option value='".$ex1['village']."' selected",$svil);

	echo $svil;

}



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





<tr><td>Land Mark </td><td>:</td><td><input autocomplete="off" type="text" name="landmark" value="'.$ex1['landmark'].'" autocomplete="off" /></td>



<td></td><td>Post &amp; Via</td><td>:</td><td><input type="text" name="postcode" value="'.$ex1['postcode'].'" autocomplete="off" /></td></tr>





<tr><td>Mobile 1 <span class="red">*</span></td><td>:</td><td><input autocomplete="off" type="text" name="mobile1" value="'.$ex1['mobile1'].'" id="required" title="*" autocomplete="off" /></td>



<td></td><td>Mobile 2 </td><td>:</td><td><input type="text" name="mobile2" value="'.$ex1['mobile2'].'" autocomplete="off" /></td></tr>





<tr><td>Customer Type </td><td>:</td><td><select name="customertype" style="width:220px;">';



?>



<option value="Farmer" <?php if($ex1['customertype']=='Farmer'){ echo'selected="selected"'; } ?>>Farmer</option>

<option value="Non-Farmer" <?php if($ex1['customertype']=='Non-Farmer'){ echo'selected="selected"'; } ?>>Non-Farmer</option>



<?php



echo'</select></td>



<td></td><td>Product Required</td><td>:</td><td><select name="product" style="width:220px;"><option value="">-- Select --</option>';



$prd=mysql_query("select * from product order by ID asc");

while($prd1=mysql_fetch_array($prd))

{

	$sprd="<option value='".$prd1['ID']."'>".$prd1['product']."</option>";

	$sprd=str_replace("<option value='".$ex1['product']."'","<option value='".$ex1['product']."' selected",$sprd);

	echo $sprd;

}



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





<tr><td>Irregation System </td><td>:</td><td><input autocomplete="off" type="text" name="irregationsystem" value="'.$ex1['irregationsystem'].'" autocomplete="off" /></td>



<td></td><td>Type of Soil </td><td>:</td><td><input autocomplete="off" type="text" name="typeofsoil" value="'.$ex1['typeofsoil'].'" autocomplete="off" /></td></tr>





<tr><td>Total Land </td><td>:</td><td><input autocomplete="off" type="text" name="totalland" value="'.$ex1['totalland'].'" autocomplete="off" /></td>



<td></td><td>Cultivating Crops </td><td>:</td><td><input autocomplete="off" type="text" name="cultivatingcrop" value="'.$ex1['cultivatingcrop'].'" autocomplete="off" /></td></tr>





<tr><td>Crop Stage </td><td>:</td><td><input autocomplete="off" type="text" name="cropstage" value="'.$ex1['cropstage'].'" autocomplete="off" /></td>



<td></td><td>Last Applied </td><td>:</td><td><input autocomplete="off" type="text" name="lastapplied" class="datepicker" value="'.$lastapplied.'" autocomplete="off" /></td></tr>





<tr><td>Next Apply </td><td>:</td><td><input autocomplete="off" type="text" name="nextapply" class="popupdatepicker" value="'.$nextapply.'" autocomplete="off" /></td>



<td></td><td>Last Purchased </td><td>:</td><td><input autocomplete="off" type="text" name="lastpurchased" value="'.$ex1['lastpurchased'].'" autocomplete="off" /></td></tr>





<tr><td>Aggriculture Exp </td><td>:</td><td><input autocomplete="off" type="text" name="aggricultureexp" autocomplete="off" value="'.$ex1['aggricultureexp'].'" /></td>



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





<tr><td>Quantity </td><td>:</td><td><input autocomplete="off" type="text" name="qty" value="'.$ex1['qty'].'" autocomplete="off" /></td>



<td></td><td>Reason </td><td>:</td><td><textarea name="reason" style="width:220px; height:75px;">'.$ex1['reason'].'</textarea></td></tr>';



if($nmrw>0)

{

	

echo'<tr><td>Executive </td><td>:</td><td><select name="executive" style="width:220px;"><option value="">Select Executive</option>';



$exec=mysql_query("select * from employee order by name asc");

while($exec1=mysql_fetch_array($exec))

{

	$executive="<option value='".$exec1['ID']."'>".$exec1['name']."</option>";

	$executive=str_replace("<option value='".$ex1['executive']."'","<option value='".$ex1['executive']."' selected",$executive);

	echo $executive;

}



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



}

else

{



$empd=mysql_query("select * from employee where username='$user'");

$empd1=mysql_fetch_array($empd);



$usr=$empd1['ID'];



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



}



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



</table>



</form>';



}



}



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>

						Values Edited Successfully.

				  </div>';				  

		 }

		 if($status=='7')

		 {

			 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>

						Values Deleted Successfully.

				  </div>';				  

		 }

	}		



$sel=mysql_query("select * from admin where username='$user'");

$nmrw=mysql_num_rows($sel);

$sel1=mysql_fetch_array($sel);



	$empd=mysql_query("select * from employee where username='$user'");

	$empd1=mysql_fetch_array($empd);



	$usr=$empd1['ID'];



echo'<table style="width:99%; margin:11px auto 10px auto;">

                                        

                                        <tr><td style="width:20%;">

                                        <a href="customer.php"><button class="btn btn-minier btn-info">+ Add Customer</button></a>

                                        </td>

                                        

                                        <td style="width:50%;"></td>

                                        

                                        <td style="width:30%; text-align:right;">';

										

										if($nmrw>0)

										{

										echo'<a href="customersexcel.php"><button class="btn btn-minier btn-info">Excel</button></a>';

										}

										else

										{

										echo'<a href="customersexcel1.php?executive='.$usr.'"><button class="btn btn-minier btn-info">Excel</button></a>';

										}

                                        

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





	echo"<table id='dynamic-table' class='table table-striped table-bordered table-hover'>



	<thead><th width='15%'>Name</th>

	<th width='12%'>Mobile</th>

	<th width='12%'>Village</th>

	<th width='11%'>Taluk</th>

	<th width='12%'>District</th>

	<th width='12%'>Crops</th>";



	if($nmrw>0)

	{

	echo"<th width='10%'>Executive</th>";

	}

	

	echo"<th style='width:10%;'>Edit</th></thead>";





if($nmrw>0)

{

	$getsite3="select * from customer order by name asc";

}

else

{

	

	$empd=mysql_query("select * from employee where username='$user'");

	$empd1=mysql_fetch_array($empd);



	$usr=$empd1['ID'];

	

	$getsite3="select * from customer where executive='$usr' order by name asc";

	

}

	

	$getsite4=mysql_query($getsite3) or die("Could not get");

	$sno=0;

	while($getsite5=mysql_fetch_array($getsite4))

	{

		$sno=$sno+1;

		

		$emp=mysql_query("select * from employee where ID='$getsite5[executive]'");

		$emp1=mysql_fetch_array($emp);

		

		$vil=mysql_query("select * from villages where ID='$getsite5[village]'");

		$vil1=mysql_fetch_array($vil);

		

		$tlk=mysql_query("select * from taluk where ID='$getsite5[taluk]'");

		$tlk1=mysql_fetch_array($tlk);

		

		$dis=mysql_query("select * from districts where ID='$getsite5[district]'");

		$dis1=mysql_fetch_array($dis);

		

		echo"<tr><td>".$getsite5['name']."</td>

		<td>".$getsite5['mobile1']."</td>

		<td>".$vil1['village']."</td>

		<td>".$tlk1['taluk']."</td>

		<td>".$dis1['district']."</td>

		<td>".$getsite5['cultivatingcrop']."</td>";

		

		if($nmrw>0)

		{

			echo"<td>".$emp1['name']."</td>";

		}

		

		echo"<td>

		

														<div class='hidden-sm hidden-xs btn-group'>

														

														<a href='viewcustomerhistory.php?customer=".$getsite5['ID']."' title='View'>

																<i class='ace-icon fa fa-search-plus bigger-100 blue'></i></a> &nbsp;";

																

															if($nmrw>0 || $usr=='6')

															{

															echo"<a href='viewcustomer.php?id=".$getsite5['ID']."' title='Edit'>

																<i class='ace-icon fa fa-pencil bigger-100 green'></i></a> &nbsp; 

															<a href='del.php?id=".$getsite5['ID']."&desc=customer' title='Delete'>

																<i class='ace-icon fa fa-trash-o bigger-110 dark grey'></i></a>";

															}

															

														 echo"</div>

		</td></tr>";



		}



		echo "</table>";



	}



?>









										<!-- 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();



?>