<?php
$errmsg='';
$sucmsg='';
if(isset($_POST['chgpswd'])){
    extract($_POST);
    $errmsg='';
    $sucmsg='';
    
	$oldpswd=trim($oldpswd);
    $newpswd=trim($newpswd);
    $conpswd=trim($conpswd);
    $oldpswd=sha1($oldpswd);
    $newpswd=sha1($newpswd);
    $conpswd=sha1($conpswd);
	//echo $oldpswd."<br>";
	//echo $applicant_id;
	
    if($newpswd!=$conpswd){
        $errmsg='New password and Confirm password mismatch';
    }
	$q = "Select * from pci_application where id=$applicant_id limit 1";
    $qry=mysqli_query($con, $q);
    $row=mysqli_fetch_assoc($qry);
    $old=$row['password'];
	$cid=$row['id'];
	$s=$row['memberSurname'];
	
    if($oldpswd!=$old){
        $errmsg='Old password is incorrect';
		
    echo $oldpswd."<br>";
    }else{
        $qry2=mysqli_query($con, "UPDATE pci_application SET password='$newpswd' WHERE id=$applicant_id");
        if($qry2){
            $sucmsg='Password Changed Successfully!';
        }else{
            $errmsg=die();
        }
        
    }
}
?>

<div class="graph-visual tables-main">
<h2 class="inner-tittle">CHANGE PASSWORD</h2>
	<div class="graph-form">
    		<div class="form-body">
    			<form method="post" name="password" action="index.php?page=password"> 
                <?php 
                if($errmsg!=''){
                    echo '<div class="alert alert-danger">'.$errmsg.'</div>';
                }elseif($sucmsg!=''){
                    echo '<div class="alert alert-success">'.$sucmsg.'</div>';
                }
                
                ?>
                    <div class="form-group"> 
                        <label for="oldpswd">Old Password</label> 
                        <input type="password" class="form-control" name="oldpswd" placeholder="Old Password" required=""/> 
                    </div> 
                    <div class="form-group"> 
                        <label for="newpswd">New Password</label> 
                        <input type="password" class="form-control" name="newpswd" placeholder="New Password" required=""/> 
                    </div> 
                    <div class="form-group"> 
                        <label for="conpswd">Confirm New Password</label> 
                        <input type="password" class="form-control" name="conpswd" placeholder="Confirm New Password" required=""/> 
                    </div>
                    <input name="chgpswd" type="submit" class="btn btn-default" value="Change Password"/> 
                </form> 
    		</div>
    
    </div>

</div>