<?php
require("../includes/check_auth_user.php");
require("../includes/dbconnect.php");
include('../includes/function.php');

$formname = 'Password Change';
$maindb = 'mainpassw';
$trandb = 'usermain';
$printfile = "";
$file = 'passchng.php';
$trandbexist = 0;
$grid = '';
$keyfld = "code";

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$myyear = $_SESSION[$myyear];
mysqli_select_db($zdb);

include("../includes/vouchno_generate.php");
//include("../includes/prev&next.php");


if (isset($_POST["submit"])) {
    $oldpassword = $_POST["oldpassword"];
    $password = $_POST["password"];
    $oldestring = str_split($oldpassword);
    $estring = str_split($password);
    $oldpassenc = "";
    foreach ($oldestring as $oldchar) {
        $oldpassenc .= ord($oldchar) + 9;
    }

    $login = mysqli_query($conn,"SELECT `locku` FROM `mainpassw` WHERE  `unlockp` = '" . $oldpassenc . "'") or die(mysqli_error($conn));
    $num = mysqli_num_rows($login);
    if ($num > 0) {
        $encrpyted = "";
        foreach ($estring as $char) {
            $encrpyted .= ord($char) + 9;
        }

        mysqli_query($conn,"UPDATE `$maindb` SET  `unlockp`='$encrpyted' WHERE code = 1") or die(mysqli_error($conn));
        updmess();
    } else {
        browse("Old Password Does Not Match !!");
    }
############################## MAIN  ######################################################


    header("refresh: 1; $file?$keyfld=$mvouch&mode=last");
}


if ($addflag != 1) {

    $getvouch = '';
    if ($addflag == 0) {
        $getvouch = $_GET[$keyfld];
    } else {
        $getvouch = $qvouch;
    }

    $result = mysqli_query($conn,"SELECT * FROM `$maindb` WHERE 1") or die(mysqli_error($conn));
    $get = mysqli_fetch_array($result);
}

$senable = "";
$cenable = "";

/* DELETE */
if (isset($_GET["delete"])) {
    delete($zdb, "$maindb", "$keyfld", $_GET[$keyfld], "$file?mode=last");
}

include("../includes/linkshead.php");
?>
<style>
    input[type = checkbox]{
        width: 20px;
        height: 20px;
    }
</style>
<script  type="text/javascript">
    $(document).ready(function () {
        $('#hadd').hide();
        $('#hdelete').hide();
        $('#hprev').hide();
        $('#hnext').hide();
        $('#hsearch').hide();
        $('#hprevious').hide();
        $('#hprint').hide();

//        $(function () {
        $("#confpass").blur(function () {
            var password = $("#password").val();
            var password1 = $("#confpass").val();
            if (password !== password1) {
                alert("Password do not match.");
                $("#confpass").val('');
                $("#password").focus();
                return false;
            }
            return true;
        });
//        });
    });
</script>
<body>
    <!-- Default box -->
    <form action='' method='POST'>
        <!-- Default box -->
        <div class="">
            <div class="col-lg-6">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title"><?php Echo $formname; ?></h3>
                    </div>
                    <div class="panel-body">
                        <!--                        <div class="row">
                                                    <label class="col-sm-3 control-label marg">User Name</label>
                                                    <div class="col-sm-6">
                                                        <input type="text" class="form-control form" name="user" placeholder="User Name" autocomplete="off" value='<? // echo ($addflag != 1) ? $get['user'] : '';    ?>' required="" autofocus>
                                                    </div>
                                                </div>-->
                        
                        <div class="row">
                            <label class="col-sm-3 control-label marg">Password</label>
                            <div class="col-sm-6">
                                <input type="password" class="form-control form" maxlength="20" name="password" id="password" autocomplete="off" placeholder="Password" value='' required>
                            </div>
                        </div>
                        <div class="row">
                            <label class="col-sm-3 control-label marg">Confirm Pass</label>
                            <div class="col-sm-6">
                                <input type="password" name="confpass" id="confpass" maxlength="20" class="form-control form"  placeholder="Confirm Password" required value=''>
                            </div>
                        </div>
                        <div class="row">
                            <label class="col-sm-3 control-label marg">Old Password</label>
                            <div class="col-sm-6">
                                <input type="password" class="form-control form" name="oldpassword" id="oldpassword" autocomplete="off" placeholder="Old Password" required="">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="panel-footer">
                    <?php include("../includes/buttons.php"); ?>
                </div>
            </div>
        </div>
    </div>
</form>
</body>
</html>
<?php include("../includes/linksfoot.php"); ?>