<?php
require_once '../includes/core.php';
require '../includes/connect.php';


if (loggedinadmin()){


$adminname = getfield1('name','admin','admin-id');
$admin_id = getfield1('admin-id','admin','admin-id');
$password = getfield1('password','admin','admin-id');




}
else
{ 
	header('Location:../loginexec.php');
}
?>








<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title> Admin - Dashboard</title>

<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/datepicker3.css" rel="stylesheet">
<link href="css/styles.css" rel="stylesheet">

<link rel="icon" type="image/png" href="../assets/img/favicon.png">

<!--Icons-->
<script src="js/lumino.glyphs.js"></script>

<!--[if lt IE 9]>
<script src="js/html5shiv.js"></script>
<script src="js/respond.min.js"></script>
<![endif]-->

</head>

<body>

    <?php include ('includes/header.php')  ?>

    <?php include ('includes/leftnav.php')  ?>
	
	
		
	<div class="col-sm-9 col-sm-offset-3 col-lg-10 col-lg-offset-2 main" style="margin-top: 20px">			
		<div class="row">
			<ol class="breadcrumb">
				<li><a href="#"><svg class="glyph stroked home"><use xlink:href="#stroked-home"></use></svg></a></li>
				<li class="active">home</li>
			</ol>
		</div><!--/.row-->
		
		<div class="row">
			<div class="col-lg-12">
				<h1 class="page-header"></h1>
			</div>
		</div><!--/.row-->


		
		<div class="row">
			<div class="col-lg-12">
				<div class="panel panel-default">
					<div class="panel-heading">Change Password</div>
					<div class="panel-body">
						<div class="col-md-6">
							<form role="form" action="" method="POST">
							
								
																
								<div class="form-group">
									<label for="pass">Old Password</label>
									<input type="password" id="pass" name="pass" class="form-control">
								</div>
								<div class="form-group">
									<label for="newpass">New Password</label>
									<input type="password" id="newpass" name="newpass" class="form-control">
								</div>
								<div class="form-group">
									<label for="newpass_again">Confirm New Password</label>
									<input type="password" id="newpass_again" name="newpass_again" class="form-control">
								</div>

								<button type="submit" class="btn btn-primary">Submit</button>
								<button type="reset" class="btn btn-default">Reset</button>
		
		
       
						</form>
					</div>
				</div>
			</div>
			</div>
			</div>





			<?php
				
				
				if(isset($_POST['pass']) && isset($_POST['newpass']) && isset($_POST['newpass_again']))
					{
						
						$pass = mysql_real_escape_string($_POST['pass']);
						$newpass = mysql_real_escape_string($_POST['newpass']);
						$newpass_again = mysql_real_escape_string($_POST['newpass_again']);
						$password_hash = ($newpass);
						if(!empty($pass) && !empty($newpass) && !empty($newpass_again))
							{
							if(($_POST['pass']) === $password){
							
								if($newpass == $newpass_again)
									{
										$updatequery1= "UPDATE `admin` SET `password`='$password_hash' WHERE `admin-id`='$admin_id'";
										mysql_query($updatequery1) or die(mysql_error());
										echo '<div class="alert bg-success" role="alert">
					<svg class="glyph stroked cancel"><use xlink:href="#stroked-cancel"></use></svg> Your password has being changed successfully. You can now <a href="../loginexec.php"><button type="submit" class="btn btn-primary">Login</button>
					</a><a href="#" class="pull-right"><span class="glyphicon glyphicon-remove"></span></a>

				</div>';
                      
									}else {
										 echo '<div class="alert bg-danger" role="alert">
					<svg class="glyph stroked cancel"><use xlink:href="#stroked-cancel"></use></svg> New passwords do not match<a href="#" class="pull-right"><span class="glyphicon glyphicon-remove"></span></a>
				</div>';
										}
										}else{
										
										echo 
                                           '<div class="alert bg-danger" role="alert">
					<svg class="glyph stroked cancel"><use xlink:href="#stroked-cancel"></use></svg> Current password is not correct<a href="#" class="pull-right"><span class="glyphicon glyphicon-remove"></span></a>
				</div>';
										}
							}else
								{
									echo '<div class="alert bg-danger" role="alert">
					<svg class="glyph stroked cancel"><use xlink:href="#stroked-cancel"></use></svg> Fill the form before submitting.<a href="#" class="pull-right"><span class="glyphicon glyphicon-remove"></span></a>
				</div>';
								}
					}
				
				?>




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

	<script src="js/jquery-1.11.1.min.js"></script>
	<script src="js/bootstrap.min.js"></script>
	<script src="js/chart.min.js"></script>
	<script src="js/chart-data.js"></script>
	<script src="js/easypiechart.js"></script>
	<script src="js/easypiechart-data.js"></script>
	<script src="js/bootstrap-datepicker.js"></script>
	<script>
		$('#calendar').datepicker({
		});

		!function ($) {
		    $(document).on("click","ul.nav li.parent > a > span.icon", function(){          
		        $(this).find('em:first').toggleClass("glyphicon-minus");      
		    }); 
		    $(".sidebar span.icon").find('em:first').addClass("glyphicon-plus");
		}(window.jQuery);

		$(window).on('resize', function () {
		  if ($(window).width() > 768) $('#sidebar-collapse').collapse('show')
		})
		$(window).on('resize', function () {
		  if ($(window).width() <= 767) $('#sidebar-collapse').collapse('hide')
		})
	</script>	
</body>

</html>
