<?php include ("kfunctions.php")?>
<html>
<head>
<?php kheader(); ?>
<?php 
require_once("connect.php");
$result=$dbh->query("select * from scrap");

?>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.1/jquery.js"></script>


</head>
<body>

    <div id="wrapper">

        <!-- Navigation -->
        <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
            <!-- Brand and toggle get grouped for better mobile display -->
            <?php ktopbar(); ?>
            <!-- Sidebar Menu Items - These collapse to the responsive navigation menu on small screens -->
            <?php kleftbar(); ?>
            <!-- /.navbar-collapse -->
        </nav>

        <div id="page-wrapper">
        

            <div class="container-fluid">

                <!-- Page Heading -->
                <div class="row">
                    <div class="col-lg-12">
                        <h1 class="page-header">
                           Change your password
                        </h1>
                        
                        <div id="para"></div>
                       <?php
					   
					   if(isset($_POST['submit'])){
$currentpassword=$_POST['currentpassword'];
$newpassword=$_POST['newpassword'];
$confirmpassword=$_POST['confirmpassword'];
$hint=$_POST['hint'];
$rolenumber=$_SESSION["rolenumber"];
require_once('connect.php');

$rolenumber=$_SESSION["rolenumber"];

$result2 = $dbh->query("select * from users where password='$currentpassword'");
$row2 = $result2->fetchObject();
$count2 = $result2->rowCount();

$counter = strlen($confirmpassword);
if(($count2!='0')&&($counter>7)&&($newpassword==$confirmpassword)&&($newpassword!='')&&($currentpassword!='')&&($confirmpassword!='')){

$updatepassword = $dbh->query("update users set password='$newpassword', hint='$hint' where password='$currentpassword' and rolenumber='$rolenumber'");

$updatepassword = $dbh->query("UPDATE keyfields set password='$newpassword' where password='$currentpassword' and rolenumber='$rolenumber'");

useractivity("Password has been changed","30");

echo "<div style='width:49%;' class='alert alert-success'>Success..!!! Your password has been changed</div>";
}else{

echo "<div style='width:49%;' class='alert alert-danger'>Sorry..!!! Your password hasn't been changed</div>";
if ($counter<8) {echo "<div style='width:49%;' class='alert alert-danger'>Error k02: <strong>Not</strong> updated. Password must have atleast 8 characters</div>";
}}

					   }
					   ?>


                    </div>
                </div>

                <!-- /.row -->

                <div class='row'>
                    <div class='col-lg-6'>
                        <div class='panel panel-default'>
                            <div class='panel-body'>
                            
<div class='panel panel-info'><!--Initiative-->
<div class='panel-heading'><h3 class='panel-title'>Fill the form below | Mandatory fields are marked with a star *</h3></div>
<div class='panel-body'>
<form method="post">
<div class="col-lg-7"><input  type="password" id="current1" onKeyUp="shown()" class="form-control" name="currentpassword" placeholder="* Current password"></div><div class="col-lg-5"><div id="current11" readonly class="form-control" ></div></div>
<br><br>

<div class="col-lg-7"><input type="password" id="current2" onKeyUp="shown2()" class="form-control" name="newpassword" placeholder="* New password"></div><div class="col-lg-5"><div id="current22" readonly class="form-control" ></div></div><br><br>

<div class="col-lg-7"><input type="password" id="current3" onKeyUp="shown3()" class="form-control" name="confirmpassword" placeholder="* Confirm new password"></div><div class="col-lg-5"><div id="current33" readonly class="form-control" ></div></div>
<br><br><br>

Helpful incase you forget your password
<input type="text" class="form-control" name="hint" placeholder="Type a password hint"><br>
<input type="submit" class="btn btn-primary" name="submit" value="Change password">
</form>
<input type="submit" id="show" class="btn btn-success"  value="Show">
</div>
</div>  
                                                    </div>
                    

                </div>
</div>





</div>
                            </div> </div>
             
                    
                    
                <!-- /.row -->
             

            </div>
            <!-- /.container-fluid -->

<?php useractivity("on page","30"); ?>
        </div>
        <!-- /#page-wrapper -->

    </div>
    <!-- /#wrapper -->
    <script>
function shown(){
var showm = document.getElementById("current1").value;
document.getElementById("current11").innerHTML = showm;


    $("#current11").hide();


$("#show").click(function(){
    $("#current11").show();
});
}

function shown2(){
var current2 = document.getElementById("current2").value;
document.getElementById("current22").innerHTML = current2;

if(current2.length <=7)
{
document.getElementById('current2').style.borderColor = "red";}

else{document.getElementById('current2').style.borderColor = "green";}


    $("#current22").hide();

$("#show").click(function(){
    $("#current22").show();
});
}

function shown3(){
var showm3 = document.getElementById("current3").value;
document.getElementById("current33").innerHTML = showm3;



    $("#current33").hide();

$("#show").click(function(){
    $("#current33").show();
});
}

</script>

    <!-- jQuery -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.1/jquery.js"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="js/bootstrap.min.js"></script>

</body>

</html>
