<?php 
include 'inc/conx.php';
    $success = "";
    $danger = "";
    if (isset($_POST['username'])) {
        # code...
        $username = $_POST['username'];
        $oldpassword = $_POST['password'];
        $newpassword = $_POST['password2'];

        $sql = $db->query("SELECT count(*) AS rows FROM users WHERE name = '$username' AND pass = '$oldpassword'");
        $row = $sql->fetchArray();
        $rows = $row['rows'];
        if ($rows > 0) {
            # code...
        $sql = $db->query("UPDATE users SET pass = '$newpassword' WHERE name = '$username'");
        $success = "<strong>Success!</strong> A password reset successfully. You may login now please.";    
        }else{
            $danger = "<strong>Warning!</strong> Something wrong with username or old password";
        }
    }
include 'header.php'; 
?>
	<div class="flip-container">
        <div class="flipper">
            <div class="front">
                <!-- front content -->
                <div class="holder">
                                        
                    <h1 class="heading">
                        <img src="images/header_logo.png" style="width: auto;max-width: 180px" alt="" />                    </h1> 
                    <form action="" class="form login-form" method="post" accept-charset="utf-8">
                        <p>Reset password</p>
                        <?php
                        if (isset($_POST['username'])) {
                        ?>
                        <div class="alert alert-<?php echo ($success) ? "success" : "danger"; ?>"> 
                                <?php echo ($success) ? $success : $danger; ?>                          
                        </div>
                        <?php } ?>
                        <input type="text" name="username" value="" id="username_or_email" class="form-control" placeholder="Username" size="20"  />

                        <input type="text" name="password" id="password" class="form-control" placeholder="Old Password" size="20"  />
                
                        <input type="text" name="password2" id="password2" class="form-control" placeholder="New Password" size="20"  />

                        <div class="bottom_info">
                            <a href="index.php" class="flip-link to-recover">Login</a>
                        </div>      
                        <div class="clearfix"></div>
                        <button type="submit" class="btn btn-primary btn-block">Reset password</button>
                    </form>  
                    <div class="version">
                        <p>
                            <?php echo date("Y"); ?> Version <span class="badge bg-success">16.0</span>
                        </p>
                    </div>
                </div>
            </div>          
        </div>      
    </div>
<?php include 'footer.php'; ?> 