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

								Update Premium

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

			}

			

		  }

		  });



});



});



</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($_POST['submit']))

{

	

	$customer=$_POST['customer'];

	$check=$_POST['checkbx'];

	
	//echo count($check).'<br />';
	

	foreach($check as $chk)
	{

		$cus=$customer[$chk];
		

		$up=mysql_query("update crm_customer set premium='1' where ID='$cus'");
		

	}

	

	if($up)
	{

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

	}

	else
	{

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

	}



}



elseif(isset($_GET['submit']))
{



$district=$_GET['district'];


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

$nmrw=mysql_num_rows($sel);

$sel1=mysql_fetch_array($sel);



	echo"<form action='updatepremium.php' method='post'>

	

	<table id='dataTables-example' class='table table-striped table-bordered table-hover'>



	<thead><th style='width:5%;'></th>

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

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

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

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

	<th width='15%'>District</th></thead>";



if($nmrw>0)

{	

	$getsite3="select * from crm_customer where district='$district' and premium='' 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 crm_customer where executive='$usr' and district='$district' and premium='' 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);

		

		echo"<tr><td><input type='checkbox' name='checkbx[".$sno."]' value='".$sno."' /></td>

		<td><input type='hidden' name='customer[".$sno."]' value='".$getsite5['ID']."' />".$getsite5['name']."</td>

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

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

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

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



		}



		echo"</table>

		

		<center><button type='submit' name='submit' value='submit'>Submit</button></center>

		

		</form>";



}

else

{



echo"<center><form action='updatepremium.php' method='get'>



<table>



<tr><td>District <span class='red'>*</span></td><td style='padding:0 7px;'>:</td><td><select name='district' required><option value=''>-- Select --</option>";



$dis=mysql_query("select districts.ID as id, districts.district as district from districts left join statecode on districts.state=statecode.ID where statecode.ID='32' order by districts.ID asc");

while($dis1=mysql_fetch_array($dis))

{

	echo"<option value='".$dis1['id']."'>".$dis1['district']."</option>";

}



echo"</select></td></tr>



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



</table>



</form></center>";



}



?>









										<!-- PAGE CONTENT ENDS -->

									</div><!-- /.col -->

								</div><!-- /.row -->

							</div><!-- /.page-content -->

						</div>

					</div><!-- /.main-content -->


<script src="assets/jquery.dataTables.js"></script>
    <script src="assets/dataTables.bootstrap.js"></script>

    <script>
    $(document).ready(function() {
        $('#dataTables-example').dataTable({ 
		
		"aoColumnDefs": [
      
	      { 'bSortable': false, 'aTargets': [0,-1] }
       ],
	   
	   "aaSorting": [1, "asc"]
	   
	  });
		
	  
    });
	
	
    </script>


<?php



include 'bottom.php';



}

else

{



 header("location:login.php");

 

}



ob_flush();




?>