<?php
include('../db/model.php');
$obj = new Model();

$id=0;

if (isset($_POST['id']) && is_numeric($_POST['id'])) {
    $id = (int)$_POST['id'];
}

if ($_POST['type']=='up') {
    $password = $_POST['currentPassword'];
    $user=$obj->GetUser($_POST['id'], "id");

    if (isset($user)) {
        if (count($user)>0) {

            if (password_verify($password, $user['password'])) {
                $obj->UpdateUserPassword($_POST);
            } else {
                echo "cpi"; //current password incorrect
                exit;
            }
        } else {
            echo "no no no";
            exit;
        }
    } else {
        echo "unv"; //user not valid
        exit;
    }
    
}

?>

    <div class="modal fade" id="passModal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="passModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-md">
            <div class="modal-content">
                <div class="modal-header text-center">
                    <h1 class="modal-title fs-5 w-100" id="passModalLabel">Update Password</h1>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                
                <div id="custom-form-light">
                    <div class="modal-body">
                    
                        <input type="hidden" name="mId" id="mId" value="<?php echo $id; ?>">

                        <div class="mb-3">
                            <label for="currentPassword">Current Password</label>
                            <div class="input-group">
                                <span class="input-group-text"><i class="bi bi-key-fill"></i></span>
                                <input type="password" name="currentPassword" id="currentPassword" value="" class="form-control">
                                <button type="button" class="input-group-text" id="showCurrentPass" onclick="TogglePassword('currentPassword', 'showCurrentPass')"><i class="bi bi-eye-slash"></i></button>
                            </div>
                        </div>

                        <div class="mb-3">
                            <label for="newPassword">New Password</label>
                            <div class="input-group">
                                <span class="input-group-text"><i class="bi bi-key-fill"></i></span>
                                <input type="password" name="newPassword" id="newPassword" value="" class="form-control">
                                <button type="button" class="input-group-text" id="showNewPass" onclick="TogglePassword('newPassword', 'showNewPass')"><i class="bi bi-eye-slash"></i></button>
                            </div>
                        </div>

                        <div class="mb-3">
                            <label for="confirmNewPassword">Confirm New Password</label>
                            <div class="input-group">
                                <span class="input-group-text"><i class="bi bi-key-fill"></i></span>
                                <input type="password" name="confirmNewPassword" id="confirmNewPassword" value="" class="form-control">
                                <button type="button" class="input-group-text" id="showConfirmPass" onclick="TogglePassword('confirmNewPassword', 'showConfirmPass')"><i class="bi bi-eye-slash"></i></button>
                            </div>
                        </div>

                    </div>
                    <div class="modal-footer">
                        <div class="validationErrorMsg"></div>

                        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
                        
                        <button type="submit" name="payment" class="btn btn-primary" onclick="UpdatePass()">Change Password</button>
                        

                    </div>
                </div>
                <!-- </form> -->
            </div>
        </div>
    </div>