<?php

include_once '../includes/processes.php';
$Process = new Login_Process;

$pageLink = basename($_SERVER['REQUEST_URI']);
$Process->check_status($pageLink);
if($_SESSION['dept_id']!=7) {
	
	header("location:../");
}

 require 'db_config/config.php';

?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>I.T Asset Listing</title>
			 	<link rel="icon" type="image/ico" href="img/airicon.ico"/>
    <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet"  href="customstyle.css">

    
  </head>
  <body>
    <header>
       <?php navigation("change_password"); ?>

    </header> 
    <div class="container padding-top-120">
    <div class="col-md-7 col-md-offset-2">
    <div class="panel panel-primary">
    <div class="panel-heading font-weight-bold initialism">Change Password</div>
      <div class="panel-body">
      <form action="change_password.php" method="POST" >
	   
          <div class="row padding-top-10">
             <div class="col-md-6">
           <label class="control-label" for="username">Old Password:</label>
            <input type="password" class="form-control" name="password" placeholder="Old password" id="old_password" required />
          </div>
          </div>
          <div>
            <div class="row padding-top-10">
              <div class="col-md-6">
                <label class="control-label" for="password">New Password:</label>
            <input type="Password" class="form-control" name="newpassword" placeholder="Password" id="password" required />
              </div>
              <div class="col-md-6">
                <label class="control-label" for="cpassword">Comfirm Password:</label>
            <input type="Password" class="form-control" name="cpassword" placeholder="Comfirm Password" id="cpassword" required />
              </div>
            </div>
          </div>
      <div class="row padding-top-70">
             <div class="col-md-3">
            <button type="submit" class=" btn btn-success control-label" name="submit_btn">GO</button>
            </div>
          </div>
      </form>
         <?php
		 if(isset($_POST['submit_btn']))
		{   
			//$username=$_POST['username'];
			$username=$_SESSION["killer"]["username"];
			$password=md5($_POST['password']);
			$newpassword=$_POST['newpassword'];
			$cpassword=$_POST['cpassword'];
			
			if($newpassword==$cpassword)
			{
			$query="SELECT * FROM user_info WHERE username='$username' AND password='$password'";	
			$query_run = mysqli_query($connect,$query);
			if(mysqli_num_rows($query_run)>0)
			{		
		        //$passwordmd5 = md5($newpassword);
			    $passwordmd5 = md5($newpassword);
				
      		 $query = "UPDATE user_info SET password='$passwordmd5' WHERE username='$username'";
			 if(mysqli_query($connect,$query))
			 {
            // echo '<script type="text/javascript"> alert("Update successfull") </script>';
			  echo "<br />";
			 echo '<div class="alert alert-success">
			       <a href="#" class="close" data-dismiss="alert">&times;</a>
				   Update successfull
				   </div>';
			}
			else
			{
			//echo '<script type="text/javascript"> alert("update did not work") </script>';
			 echo "<br />";
			 echo '<div class="alert alert-danger">
			       <a href="#" class="close" data-dismiss="alert">&times;</a>
				   Update did not work
				   </div>';
			}
		    }
			else{
			//echo '<script type="text/javascript"> alert("old password does not match") </script>';
			 echo "<br />";
			 echo '<div class="alert alert-danger">
			       <a href="#" class="close" data-dismiss="alert">&times;</a>
				   Old Password does not match
				   </div>';
			}
			}
			else{
			//echo '<script type="text/javascript"> alert("new password does not match ") </script>';
			 echo "<br />";
			 echo '<div class="alert alert-danger">
			       <a href="#" class="close" data-dismiss="alert">&times;</a>
				   New password does not match
				   </div>';
			}
		}

	 ?>
      </div>
    </div>
    </div>
    </div>


 
  
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    
    <script src="bootstrap/js/bootstrap.min.js"></script>
  </body>
</html>