<?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">Users</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>

								Users

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

	$('#register').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;

			};

		});

		

		return valid;

	});

	

});	



</script>

                                

<?php       





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

{



$id=$_POST['id'];

$name=$_POST['name'];

$email=$_POST['email'];

$type=$_POST['type'];

$username=$_POST['username'];



$chk=mysqli_query($conn,"select * from admin where username='$username' and ID!='$id'");

$chk1=mysqli_num_rows($chk);



if($chk1>0)

{

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

}



else

{	  



if($username)

{



$insert= "UPDATE admin set name='$name',email='$email',username='$username',type='$type' where ID='$id'";



 	$update = mysqli_query($conn,$insert);

	

}



if($update)

{

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

}	





else

{

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

}



}



}



elseif($_GET['id'])

{

$id=$_GET['id'];



$ret=mysqli_query($conn,"select * from admin where ID='$id'");

$ret1=mysqli_fetch_assoc($ret);





echo'

<form id="register" action="viewusers.php?id='.$id.'" method="post" id="register">



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



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



<tr><td>Name <span class="red">  </span></td><td id="page"></td><td><input  class="form-control" style="width: 30ch; margin-bottom:10px"  type="text" id="required" title="Enter Name" name="name" value="'.$ret1['name'].'" /></td></tr>



<tr><td>E-Mail Id </td><td id="page"></td><td><input  class="form-control" style="width: 30ch; margin-bottom:10px" autocomplete="off" type="text" name="email" value="'.$ret1['email'].'" /></td></tr>



<tr><td>User Name <span class="red"> </span></td><td id="page"></td><td><input  class="form-control" style="width: 30ch; margin-bottom:10px" autocomplete="off" type="text" name="username" id="required" title="Enter User Name" value="'.$ret1['username'].'" /></td></tr>



<tr><td>Type <span class="red">  </span></td><td id="page"></td><td><select  class="form-control" style="width: 30ch; margin-bottom:10px" name="type" id="required" title="Select Type" style="width:220px;"><option value="">Select Type</option>';

?>



<option value="admin" <?php if($ret1['type']=='admin'){ echo'selected="selected"'; } ?>>Admin</option>

<option value="staff" <?php if($ret1['type']=='staff'){ echo'selected="selected"'; } ?>>Staff</option>



<?php



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



echo'<tr><td></td><td></td><td align="left"><button type="submit" value="Save" class="btn btn btn-primary" name="submit">Save</button></td></tr>



</table>



 </form>';



}



else

{



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

	{

	 $status=$_GET['s'];

		 if($status=='1')

		 {

           echo'<div class="alert alert-success alert-dismissable">

                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>

                <span style="text-align:left;">Values Edited Successfully.</span>

                </div><br />';

		}

		elseif($status=='3')

		 {

           echo'<div class="alert alert-error alert-dismissable">

                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>

                <span style="text-align:left;">Email is already registered. Please try again.</span>

                </div><br />';

		}

		elseif($status=='4')

		 {

           echo'<div class="alert alert-error alert-dismissable">

                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>

                <span style="text-align:left;">Values Not Edited. Try Again.</span>

                </div><br />';

		}

		elseif($status=='5')

		 {

           echo'<div class="alert alert-success alert-dismissable">

                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>

                <span style="text-align:left;">Values Deleted Successfully.</span>

                </div><br />';

		}

		elseif($status=='6')

		 {

           echo'<div class="alert alert-success alert-dismissable">

                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>

                <span style="text-align:left;">Password Changed Successfully.</span>

                </div><br />';

		}

	}

	

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

                                        

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

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

                                        </td>

                                        

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

                                        

                                        <td style="width:30%;">

                                        

                                        </td>

                                        

                                        </tr>

                                        

                                        </table>';

		

	$get=mysqli_query($conn,"select * from admin order by ID DESC") or die("unable to get");

	$sno=0;

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

		<thead><th width="5%">Sno</th><th width="20%">Name</th><th width="15%">Type</th><th width="15%">User Name</th><th width="20%">Actions</th></thead>';

		while($get1=mysqli_fetch_assoc($get))

		{

		$sno=$sno+1;

			echo '<tr><td>'.$sno.'.</td><td style="padding-left:5px;">'.$get1['name'].'</td>

			<td style="padding-left:5px;">'.$get1['type'].'</td><td style="padding-left:5px;">'.$get1['username'].'</td>

			<td>

			

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

													   

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

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



								<a href="del.php?id='.$get1['ID'].'&desc=user" title="Delete">

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

			

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



?>