<?php
session_start();
include('includes/config.php');
include('defs.php');

if(strlen($_SESSION['aid'])==0)
  { header('location:index.php');
}

$usr=$_SESSION['uname'];



 ?>

 <!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <title>GLAKB  | Change Password</title>

  <!-- Google Font: Source Sans Pro -->
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="../plugins/fontawesome-free/css/all.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="../dist/css/adminlte.min.css">
  <!--Function Email Availabilty---->

</head>
<body class="hold-transition sidebar-mini">
<div class="wrapper">
  <!-- Navbar -->
<?php include_once("includes/navbar.php");?>
  <!-- /.navbar -->

  <!-- Main Sidebar Container -->
 <?php include_once("includes/sidebar.php");?>

 
  <div class="content-wrapper">

  <html>
<head>
<style>
#suggestions {
            border: 2px solid #ccc;
            display: none;
            position: absolute;
            background-color: white;
            width: 300px;
            max-height: 250px;
            overflow-y: auto;
            z-index: 1000;
        }
        #suggestions div {
            padding: 3px;
            cursor: pointer;
        }
        #suggestions div:hover,
        #suggestions .selected {
            background-color: #f0f0f0;
        }



#suggestions1 {
            border: 2px solid #ccc;
            display: none;
            position: absolute;
            background-color: white;
            width: 300px;
            max-height: 250px;
            overflow-y: auto;
            z-index: 1000;
        }
        #suggestions1 div {
            padding: 3px;
            cursor: pointer;
        }
        #suggestions1 div:hover,
        #suggestions1 .selected {
            background-color: #f0f0f0;
        }

        .input-box {
            width: 100%;
            padding: 2px;
            margin-top: 2px;
            margin-bottom: 2px;
            border: 2px solid gainsboro;
            border-radius: 4px;
            font-size: 16px;

        }
#customers {
  font-family: Times-Roman;
  border-collapse: collapse;
  width: 98%;
}

#customers td, #customers th {
  border: 1px solid #4444;
  padding: 4px;
}

#customers tr:nth-child(even){background-color:gainsboro ;}


#customers th {
  padding-top: 5px;
  padding-bottom: 5px;
  text-align: center;
background-color:dodgerblue;
    color: white;
}
</style>   

<script language="javascript" type="text/javascript">

function validateForm()
  {


if((document.ind.name.value) == '')
    
  {
      alert("Please Enter User Name First!");
document.ind.name.focus();

      return false;
    }
    
if((document.ind.psw.value) == '')
    
  {
      alert("Please Enter Old Password!");
document.ind.psw.focus();

      return false;
    }
    
if((document.ind.npsw.value) == '')
    
  {
      alert("Please Enter New Password!");
document.ind.npsw.focus();

      return false;
    }



if((document.ind.cpsw.value) == '')
    
  {
      alert("Please Enter Confirm Password!");
document.ind.cpsw.focus();

      return false;
    }


if((document.ind.npsw.value) != (document.ind.cpsw.value))
    
  {
      alert("New Passowrd and Confirm Password do not Match!");
document.ind.cpsw.focus();

      return false;
    }


    return true;
  }

</script>

<?
echo "<form name='ind' action='' onSubmit='return validateForm()' method='post'>";
echo "<body style='background-color:DFD7E9   '>";
?>


<link rel="stylesheet" href="css/style.css">

              
             

<table align="center" id="customers">
       
<tr>
    <th colspan="4"><font size="4">UPDATE YOUR PASSWORD</th>

  </tr>                                   

<tr>

 <td width="200"><b><font size=3 color="black">User Name:</b></td>

<td><input type="text" name="name" size="30" onkeydown="return tab(event)" value=<?php echo $usr ?> readonly/></td>
       

<tr>
<td width="200"><b><font size=3 color="black">Old Password:</b></td>
<td><input type="text" name="psw" size="30" onkeydown="return tab(event)" required autofocus /></td>
<tr>   


<td width="200"><b><font size=3 color="black">New Password:</b></td>
<td><input type="text" name="npsw" size="30" onkeydown="return tab(event)" required /></td>
<tr>   

<td width="200"><b><font size=3 color="black">Confirm New Password:</b></td>
<td><input type="text" name="cpsw" size="30" onkeydown="return tab(event)" required /></td>
<tr>   



<td colspan="3" align="center">                             
  
<input type="submit" name="request" value="Update Password" style="background: none; color:#007BFF; border:2px solid #007BFF; padding:2px 20px; border-radius:5px;">    

    
   </table>                                  
                              
                            
                          
                         
 
               
 

     <?               
  if(isset($_POST['request'])) {
$uname = mysqli_real_escape_string($link, $_POST['name']);
$opass = mysqli_real_escape_string($link, $_POST['psw']);
$npass = mysqli_real_escape_string($link, $_POST['npsw']);
$cpass = mysqli_real_escape_string($link, $_POST['cpsw']);


$result = "select pass from user_details where Name  = '$uname'";
$check_result = mysqli_query($link, $result);
if (mysqli_num_rows($check_result) == 0) {
echo "<script language='javascript'>";
echo "alert('Error: Wrong User Password!')";
echo "</script>";
goto a;
}

else
{
$row = mysqli_fetch_object($check_result);
$opas=$row->pass;
if($opass<>$opas)
{
echo "<script language='javascript'>";
echo "alert('Old Password is wrong.')";
echo "</script>";
goto a;
}

mysqli_query($link,"update user_details set pass = '$npass' where Name ='$uname'");
echo "<script language='javascript'>";
echo "alert('Password Updated Successfully ')";
echo "</script>";
mysqli_close($link);
$link = "<script>window.open('logout.php','_self')</script>";
echo $link;

}
}
                           
?>
                       
            <!-- End of Main Content -->
<?php 

a:
include"footer.php"; 
?>
</div>
<!-- ./wrapper -->

<!-- jQuery -->
<script src="../plugins/jquery/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="../plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- bs-custom-file-input -->
<script src="../plugins/bs-custom-file-input/bs-custom-file-input.min.js"></script>
<!-- AdminLTE App -->
<script src="../dist/js/adminlte.min.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="../dist/js/demo.js"></script>
<!-- Page specific script -->
<script>
$(function () {
  bsCustomFileInput.init();
});
</script>
</body>
</html>
<?php  ?>