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

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


  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/css/bootstrap-datepicker.min.css">
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/js/bootstrap-datepicker.min.js"></script>
  <script>
    $(function() {
      // Initialize the datepicker
      $("#datepicker").datepicker({
        format: "dd/mm/yyyy",
        autoclose: true,
        todayHighlight: true
      });

      // Adjust the positioning of the datepicker dropdown
      $("#datepicker").on("show", function(e) {
        var inputOffset = $(this).offset();
        var inputHeight = $(this).outerHeight();
        var datepickerDropdown = $(".datepicker-dropdown");

        datepickerDropdown.css({
          top: inputOffset.top + inputHeight + 10,
          left: inputOffset.left
        });
      });
    });
  </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.");

			}

			

		  }

		  });



});



});



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

$fathername=$_POST['fathername'];

$mobile=$_POST['mobile'];

$qualification=$_POST['qualification'];

$state=$_POST['state'];

$district=$_POST['district'];

$taluk=$_POST['taluk'];

$village=$_POST['village'];

$totalacre=$_POST['totalacre'];

$crops=$_POST['crops'];

$experience=$_POST['experience'];

$business=$_POST['business'];

$remarks=$_POST['remarks'];

$followdate=$_POST['followdate'];



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



$up=mysqli_query($conn,"update newproject set name='$name',fathername='$fathername',mobile='$mobile',qualification='$qualification',state='$state',district='$district',taluk='$taluk',village='$village',totalacre='$totalacre',crops='$crops',agricultureexperience='$experience',business='$business',remarks='$remarks',nextfollowup='$followdate' where ID='$id'") or die(mysqli_error($conn));



if($up)

{

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

}

else

{

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

}



}



else

{



$ex=mysqli_query($conn,"select * from newproject where ID='".$id."'");

$ex1=mysqli_fetch_assoc($ex);



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

$nmrw=mysqli_num_rows($sel);

$sel1=mysqli_fetch_assoc($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="viewnewproject.php?id='.$id.'" method="post">



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



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



<tr><td>Name</td><td></td><td><input class="form-control" style="width: 30ch; margin-bottom:10px" type="text" name="name" value="'.$ex1['name'].'" /></td></tr>



<tr><td>Father Name </td><td></td><td><input class="form-control" style="width: 30ch; margin-bottom:10px" type="text" name="fathername" autocomplete="off" value="'.$ex1['fathername'].'" /></td></tr>



<tr><td>Mobile</td><td></td><td><input class="form-control" style="width: 30ch; margin-bottom:10px" type="text" name="mobile" value="'.$ex1['mobile'].'" /></td></tr>



<tr><td>Qualification</td><td></td><td><input class="form-control" style="width: 30ch; margin-bottom:10px" type="text" name="qualification" value="'.$ex1['qualification'].'" /></td></tr>



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



$ste=mysqli_query($conn,"select * from statecode order by ID asc");

while($ste1=mysqli_fetch_assoc($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  style="width: 30ch; margin-bottom:10px;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>';



$dis=mysqli_query($conn,"select * from districts where state='$ex1[state]'");

while($dis1=mysqli_fetch_assoc($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  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="" selected="selected">-- Select --</option>';



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

while($tlk1=mysqli_fetch_assoc($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  style="width: 30ch; margin-bottom:10px;padding-left:10px; height:34px;border-radius: 5px;border: 1px solid #c0c0c0;" name="village" class="village" style="width:220px;"><option value="" selected="selected">-- Select --</option>';



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

while($vil1=mysqli_fetch_assoc($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>Total Acre</td><td></td><td><input class="form-control" style="width: 30ch; margin-bottom:10px" type="text" name="totalacre" value="'.$ex1['totalacre'].'" /></td></tr>



<tr><td>Crops</td><td></td><td><input class="form-control" style="width: 30ch; margin-bottom:10px" type="text" name="crops" autocomplete="off" value="'.$ex1['crops'].'" /></td></tr>



<tr><td>Agriculture Experience</td><td></td><td><input class="form-control" style="width: 30ch; margin-bottom:10px" type="text" name="experience" autocomplete="off" value="'.$ex1['agricultureexperience'].'" /></td></tr>



<tr><td>Business</td><td></td><td><input class="form-control" style="width: 30ch; margin-bottom:10px" type="text" name="business" style="width:220px;" value="'.$ex1['business'].'" /></td></tr>



<tr><td>Remarks</td><td></td><td><textarea class="form-control" style="width: 30ch; margin-bottom:10px" name="remarks">'.$ex1['remarks'].'</textarea></td></tr>



<tr><td>Next Follow Up Date</td><td></td><td><input class="form-control" style="width: 30ch; margin-bottom:10px" type="text" name="followdate" autocomplete="off" class="popupdatepicker" id="datepicker" value="'.$nxf.'" /></td></tr>



<tr><td colspan="3" style="text-align:center; padding-top:7px;"><button type="submit" name="submit" class="btn btn 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>';

		 }

		 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=mysqli_query($conn,"select * from admin where username='$user'");

$nmrw=mysqli_num_rows($sel);

$sel1=mysqli_fetch_assoc($sel);



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

                                        

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

                                        <a href="newproject.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="newprojectexcel.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='15%'>Father Name</th>

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

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

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

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

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



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

	$getsite4=mysqli_query($conn,$getsite3) or die("Could not get");

	$sno=0;

	while($getsite5=mysqli_fetch_assoc($getsite4))

	{

		$sno=$sno+1;

		

		$ste=mysqli_query($conn,"select * from statecode where ID='$getsite5[state]'");

		$ste1=mysqli_fetch_assoc($ste);

		

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

		$dis1=mysqli_fetch_assoc($dis);

		

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

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

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

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

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

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

		<td>



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

														<a href='viewnewproject.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=newproject' title='Delete'>

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

																

														</div>

		</td></tr>";



		}



		echo"</table>";



	}



?>









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





?>