<?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">Coconut Project</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>



								Coconut Project



							</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.");



			}



			



		  }



		  });







});







});





$(document).ready(function(){



$(".variety").change(function() {



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



		//alert(vvt);



		if(vvt=='Others')

		{



			$('.others').show();



		}

		else

		{



			$('.others').hide();



		}



});



});




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



		



		//alert(mob);



		



		if(mob<10)



		{



			alert("Enter Valid Mobile No");



			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'];



$mobile=$_POST['mobile'];



$state=$_POST['state'];



$district=$_POST['district'];



$taluk=$_POST['taluk'];



$village=$_POST['village'];



$agricultureexperience=$_POST['agricultureexperience'];



$farming=$_POST['farming'];



$variety=$_POST['variety'];



$intercrops=$_POST['intercrops'];



$whichtypeoffertilizer=$_POST['whichtypeoffertilizer'];



$irrigationsystem=$_POST['irrigationsystem'];



$typeofsoil=$_POST['typeofsoil'];



$averageyieldpertree=$_POST['averageyieldpertree'];



$whichtypeofproblem=$_POST['whichtypeofproblem'];



$totalagriland=$_POST['totalagriland'];



$spacingdistance=$_POST['spacingdistance'];



$cropstage=$_POST['cropstage'];



$variety1=$_POST['variety1'];




/*
if($variety=='Others')

{

	$variety=$variety1;

}

else

{

	$variety=$variety;

}
*/




$ins=mysql_query("update coconutproject set name='$name',mobile='$mobile',state='$state',district='$district',taluk='$taluk',village='$village',agricultureexperience='$agricultureexperience',farming='$farming',variety='$variety',variety1='$variety1',intercrops='$intercrops',whichtypeoffertilizer='$whichtypeoffertilizer',irrigationsystem='$irrigationsystem',typesofsoil='$typeofsoil',averageyieldpertree='$averageyieldpertree',whichtypeofproblem='$whichtypeofproblem',totalagriland='$totalagriland',spacingdistance='$spacingdistance',cropstage='$cropstage' where ID='$id'") or die(mysql_error());



if($ins)
{

	header("location:viewcoconutproject.php?s=3");

}

else
{

	header("location:viewcoconutproject.php?s=4");

}


}

else
{

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

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


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

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

}

else
{

$nxf='';

}


echo'<form id="course" action="viewcoconutproject.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>:</td><td><input type="text" name="name" required autocomplete="off" value="'.$ex1['name'].'" /></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" value="'.$ex1['mobile'].'" /></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></tr>


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


$dis=mysql_query("select * from districts where state='$ex1[state]'");
while($dis1=mysql_fetch_array($dis))
{

	$sdis="<option value='".$dis1['ID']."'>".$dis1['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></tr>


<tr><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>Agriculture Experience</td><td>:</td><td><input type="text" name="agricultureexperience" value="'.$ex1['agricultureexperience'].'" /></td></tr>


<tr><td>Farming</td><td>:</td><td><select name="farming"><option value="">-- Select --</option>';


?>


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

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


<?php


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


<tr><td style="width:32%;">Variety</td><td>:</td><td><select name="variety" class="variety"><option value="">-- Select --</option>';

?>

<option value="T x T (நெட்டை)" <?php if($ex1['variety']=='T x T (நெட்டை)'){ echo'selected="selected"'; } ?>>T x T (நெட்டை)</option>

<option value="d x d (குட்டை)" <?php if($ex1['variety']=='d x d (குட்டை)') {echo'selected="selected"'; } ?>>d x d (குட்டை)</option>

<option value="T x d (நெட்டை குட்டை)" <?php if($ex1['variety']=='T x d (நெட்டை குட்டை)'){ echo'selected="selected"'; } ?>>T x d (நெட்டை குட்டை)</option>

<option value="d x T (குட்டை)" <?php if($ex1['variety']=='d x T (குட்டை)') { echo'selected="selected"'; } ?>>d x T (குட்டை)</option>

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

<?php

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

<tr><td colspan="3" style="padding-top:15px;">';

?>

<div class="others" <?php if($ex1['variety']=='Others'){ echo'style="width:100%; display:block;"'; } else{ echo'style="width:100%; display:none;"'; } ?>>

<table style="width:100%;">

<tr><td style="width:32%;">Variety</td><td>:</td><td><input type="text" name="variety1" style="width:220px;" value="<?php echo $ex1['variety1'] ?>" /></td></tr>

</table>

<?php

echo'</div>

</td></tr>

<tr><td>Inter Crops</td><td>:</td><td><input type="text" name="intercrops" style="width:220px;" value="'.$ex1['intercrops'].'" /></td></tr>


<tr><td>Which type of fertilizer used</td><td>:</td><td><input type="text" name="whichtypeoffertilizer" value="'.$ex1['whichtypeoffertilizer'].'" /></td></tr>


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


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


<tr><td>Average yield per tree</td><td>:</td><td><input type="text" name="averageyieldpertree" autocomplete="off" value="'.$ex1['averageyieldpertree'].'" /></td></tr>


<tr><td>Which type of problem</td><td>:</td><td><input type="text" name="whichtypeofproblem" autocomplete="off" value="'.$ex1['whichtypeofproblem'].'" /></td></tr>


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


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


<tr><td>Crop Stage</td><td>:</td><td><input type="text" name="cropstage" autocomplete="off" value="'.$ex1['cropstage'].'" /></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>';

}


}

else
{


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

	{



	 $status=$_GET['s'];		



		 if($status=='3')

		 {



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



		 }



		 elseif($status=='4')

		 {



			 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 edited. please try again.



				  </div>';



		 }



		 elseif($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);




if($nmrw>0)
{

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

echo"<center><b style='font-size:17px;'>New Customers</b></center>

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

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

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

	<th width='15%'>State</th>

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

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

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

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


if($nmrw>0)
{
	$getsite3="select * from coconutproject where date='$dt' 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 coconutproject where executive='$usr' and date='$dt' order by name asc";
}

	$getsite4=mysql_query($getsite3) or die("Could not get");
	$sno=0;
	while($getsite5=mysql_fetch_array($getsite4))
	{

		$sno=$sno+1;

		$ste=mysql_query("select * from statecode where ID='$getsite5[state]'");
		$ste1=mysql_fetch_array($ste);

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

		$tlk=mysql_query("select * from taluk where ID='$getsite5[taluk]'");
		$tlk1=mysql_fetch_array($tlk);
	
		$vil=mysql_query("select * from villages where ID='$getsite5[district]'");
		$vil1=mysql_fetch_array($vil);


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

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

		<td>".$ste1['state']."</td>

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

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

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

		<td>

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

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

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

														if($nmrw>0)
														{
														echo"<a href='del.php?id=".$getsite5['ID']."&desc=coconutproject' title='Delete'>

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

														echo"</div>

		</td></tr>";

		}

		echo"</table>";

}


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



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



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



                                        </td>



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



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



										<a href="coconutprojectexcel.php"><button class="btn btn-minier btn-info">Excel</button></a>



										</td></tr>



                                        </table>';





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



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



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



	<th width='15%'>State</th>



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

	

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

	

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



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


if($nmrw>0)
{
	$getsite3="select * from coconutproject 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 coconutproject 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;

		$ste=mysql_query("select * from statecode where ID='$getsite5[state]'");
		$ste1=mysql_fetch_array($ste);

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

		$tlk=mysql_query("select * from taluk where ID='$getsite5[taluk]'");
		$tlk1=mysql_fetch_array($tlk);
	
		$vil=mysql_query("select * from villages where ID='$getsite5[district]'");
		$vil1=mysql_fetch_array($vil);


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

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

		<td>".$ste1['state']."</td>

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

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

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

		<td>

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

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

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

														if($nmrw>0)
														{
														echo"<a href='del.php?id=".$getsite5['ID']."&desc=coconutproject' 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();

?>