<?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">Farmer Data</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>

								Farmer Data

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



		  }



		  });



});







$(document).ready(function(){



$('.mobile').blur(function(){

	

		  var mobile=$('.mobile').val();

		  var dataString = 'mobile='+ mobile;

		  //alert(dataString);

		  $.ajax

		  ({

		  type: "GET",

		  url: "getmob.php",

		  data: dataString,

		  cache: false,

		  success: function(html)

		  {

			

			//alert(html);

			var warn=$(html).filter('#warn').text();



			if(warn>0)

			{

				alert("Mobile no already exist.");

				$('.warn').val(1);

			}
			else
			{
				
				$('.warn').val('');
				
			}

			

		  }

		  });



});



});





</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;

			};

		});

		

		var mob=$('.mobile').val().length;


		var warn=$('.warn').val();
		

		//alert(mob);

		

		if(mob<10)

		{

			alert("Enter Valid Mobile No.");

			valid = false;

		}
		else if(warn==1)
		{
			
			alert("Mobile No already exist.");

			valid = false;
			
		}

		

		return valid;

		

		$('button:submit').prop('disabled', true);

		

	});

	

});	



</script>







<?php        



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

{



$name=$_POST['name'];

$address=$_POST['address'];

$mobile=$_POST['mobile'];

$state=$_POST['state'];

$district=$_POST['district'];

$taluk=$_POST['taluk'];

$village=$_POST['village'];

$cultivatingcrop=$_POST['cultivatingcrop'];

$nextapply=$_POST['nextapply'];

$executive=$_POST['executive'];

$customertype=$_POST['customertype'];

$product=$_POST['product'];

$followdate=$_POST['followdate'];

$remarks=$_POST['remarks'];

$othercrop=$_POST['othercrop'];

$howmuchyears=$_POST['howmuchyears'];


if($cultivatingcrop=='Others')
{
	$cultivatingcrop=$othercrop;
}


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



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



$mxx=mysql_query("select MAX(ID) as id from crm_customer");

$mxx1=mysql_fetch_array($mxx);



$nmx=$mxx1['id']+1;



$ins=mysql_query("insert into crm_customer(ID,name,address,mobile,state,district,taluk,village,cultivatingcrop,nextapply,executive,customertype,product,date,howmuchyears) values('$nmx','$name','$address','$mobile','$state','$district','$taluk','$village','$cultivatingcrop','$nextapply','$executive','$customertype','$product','$date','$howmuchyears')") or die(mysql_error());



$fol=mysql_query("insert into followup(date,customer,executive,remarks) values('$followdate','$nmx','$executive','$remarks')");



if($ins)

{

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

}

else

{

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

}



}



else 

{



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

$nmrw=mysql_num_rows($sel);

$sel1=mysql_fetch_array($sel);



?>



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

<input type="hidden" class="warn" />

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



<tr><td>Name <span class="red">*</span></td><td>:</td><td><input type="text" name="name" required autocomplete="off" /></td></tr>



<tr><td>Mobile <span class="red">*</span></td><td>:</td><td><input type="text" name="mobile" class="mobile" required maxlength="10" autocomplete="off" /></td></tr>



<tr><td>Address</td><td>:</td><td><textarea name="address" style="width:220px;"></textarea></td></tr>



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



<?php



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

while($ste1=mysql_fetch_array($ste))

{

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

}



?>



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



<tr><td>District <span class="red">*</span></td><td>:</td><td><select name="district" class="district" style="width:220px;" required><option value="" selected="selected">-- Select --</option></select></td></tr>





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





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





<tr><td>Customer Type</td><td>:</td><td><select name="customertype" style="width:220px;"><option value="Farmer">Farmer</option><option value="Non-Farmer">Non-Farmer</option></select></td></tr>



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



<?php



$prd=mysql_query("select * from product where (category='1' or category='2' or category='3' or category='4') order by ID asc");

while($prd1=mysql_fetch_array($prd))

{

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

}



?>



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



<script type="text/javascript">


function showstuff(element){



    document.getElementById("other").style.display = element=="Others"?"block":"none";


}


</script>



<tr><td>Cultivating Crop</td><td>:</td><td><select name="cultivatingcrop" style="width:220px;" onchange="showstuff(this.value)"><option value="">-- Select --</option>

<option value="Paddy">Paddy</option>
<option value="Maize">Maize</option>
<option value="Sorghum">Sorghum</option>
<option value="Black gram">Black gram</option>
<option value="Green gram">Green gram</option>
<option value="Groundnut">Groundnut</option>
<option value="Gingelly">Gingelly</option>
<option value="Cotton">Cotton</option>
<option value="Mango">Mango</option>
<option value="Banana">Banana</option>
<option value="Sapota">Sapota</option>
<option value="Papaya">Papaya</option>
<option value="Guava">Guava</option>
<option value="Acid Lime">Acid Lime</option>
<option value="Grapes">Grapes</option>
<option value="Tomato">Tomato</option>
<option value="Bhendi">Bhendi</option>
<option value="Brinjal">Brinjal</option>
<option value="Chilli">Chilli</option>
<option value="Paprika">Paprika</option>
<option value="Pumpkin">Pumpkin</option>
<option value="Bitter Gourd">Bitter Gourd</option>
<option value="Cucumber">Cucumber</option>
<option value="watermelon">watermelon</option>
<option value="Carrot">Carrot</option>
<option value="Beetroot">Beetroot</option>
<option value="Radish">Radish</option>
<option value="Onion">Onion</option>
<option value="Jasmine">Jasmine</option>
<option value="Coconut">Coconut</option>
<option value="Tea">Tea</option>
<option value="Cashewnut">Cashewnut</option>
<option value="Betelvine">Betelvine</option>
<option value="Arecanut">Arecanut</option>
<option value="Turmeric">Turmeric</option>
<option value="Cardamom">Cardamom</option>
<option value="Cassava">Cassava</option>
<option value="Sweet potato">Sweet potato</option>
<option value="Cluster bean">Cluster bean</option>
<option value="Cabbage">Cabbage</option>
<option value="Cauliflower">Cauliflower</option>
<option value="Curry leaf">Curry leaf</option>
<option value="Rose">Rose</option>
<option value="Marigold">Marigold</option>
<option value="Rupper">Rupper</option>
<option value="Cumbu">Cumbu</option>
<option value="Ragi">Ragi</option>
<option value="Panivaragu">Panivaragu</option>
<option value="Samai">Samai</option>
<option value="Kudiraivali">Kudiraivali</option>
<option value="Sugar cane">Sugar cane</option>
<option value="Drumstick tree">Drumstick tree</option>
<option value="Others">Others</option>

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

<tr><td colspan="3">
<DIV ID="other" style="display:none; width:100%;">
<table>
<tr><td style="width:290px;">Crop</td><td style="padding:0 5px;">:</td><td><input type="text" name="othercrop" /></td></tr>
</table>
</DIV>
</td></tr>

<tr><td>Next Apply</td><td>:</td><td><input type="text" name="nextapply" autocomplete="off" /></td></tr>



<?php



if($nmrw>0)

{

	

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



$exec=mysql_query("select employee.ID as ID, employee.name as name from employee left join department on employee.department=department.ID where department.crm='1' order by employee.ID asc");

while($exec1=mysql_fetch_array($exec))

{

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

}



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' value='".$usr."' />";

	

}



?>



<tr><td>Next Follow Up Date <span class="red">*</span></td><td>:</td><td><input type="text" name="followdate" autocomplete="off" class="popupdatepicker" required /></td></tr>


<tr><td>How Much Years </td><td>:</td><td><input type="text" name="howmuchyears" /></td></tr>


<tr><td>Remarks </td><td>:</td><td><textarea name="remarks"></textarea></td></tr>



<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>



<?php



}

	

?>

                                                                

        

								



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



?>