<?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">Premium Customer</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>

								Premium Customer

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

	

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;

			};

		});

		

	});

	

});	



</script>







<?php

if(isset($_POST['submit']))
{
	
	$id=$_POST['id'];
	
	$up=mysqli_query($conn, "update crm_customer set premium='' where ID='$id'");
	
	if($up)
	{
		header("location:premiumcustomer.php?s=3");
	}
	
}
elseif($_GET['id'])
{
	
	$id=$_GET['id'];
	
	echo"<form action='premiumcustomer.php?id=".$id."' method='post'>
	
	<input type='hidden' name='id' value='".$id."' /><br />
	
	<center>Are you want to delete this entry<br />
	
	<button type='submit' name='submit' value='yes'>Yes</button> &nbsp; <a href='premiumcustomer.php' style='text-decoration:none; color:#666;'><button type='button'>No</button></a>
	
	</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 Updated Successfully.

				  </div>';

		 }
		 
		 elseif($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 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="updatepremium.php"><button class="btn btn-minier btn-info">+ Update Premium</button></a>

                                        </td>

                                        

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

                                        

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

										

										<a href="premiumcustomerexcel.php"><button type="submit" 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='10%'>Actions</th>

	</thead>";



if($nmrw>0)

{	

	$getsite3="select * from crm_customer where premium!='' order by name asc";

}

else

{

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

	$empd1=mysqli_fetch_assoc($empd);



	$usr=$empd1['ID'];



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

		

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

		$tlk1=mysqli_fetch_assoc($tlk);

		

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

		

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

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

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

		<td>".$tlk1['taluk']."</td>
		
		<td><a href='premiumcustomer.php?id=".$getsite5['ID']."'><img src='assets/images/trash.png' /></a></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();





?>