<?php


include("../classes/manager.class.php");
$m = new Manager();
if (isset($_SESSION['sess_userid'])) {
    header("Location: dboardorderslist.php");
    exit();
}
$action = array_key_exists("action", $_REQUEST) ? $_REQUEST["action"] : 0;
?>
<?
$arr = array('%', '$', '/', '\\', '*', '+', '"', '#', '(', ')', '^', '~', '`', '&', ',', ':', ';', '?'
, '<', '>', '!', '{', '}', '[', ']');

//$user_pwd=str_replace($arr,'','topuser#707');
//echo $user_pwd;
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <?php include('includes/inc_head.php'); ?>
    <link href="<?= PROJECT_URL ?>css/layouts/page-center.css" type="text/css" rel="stylesheet" media="screen,projection">
</head>

<body class="cyan loginScreen">

<!-- Start Page Loading -->
<div id="loader-wrapper">
    <div id="loader"></div>
    <div class="loader-section section-left"></div>
    <div class="loader-section section-right"></div>
</div>
<!-- End Page Loading -->

<div id="login-page" class="row">
    <div class="col s12 z-depth-4 card-panel">
        <form class="form-signin" autocomplete="off" name="login_form" novalidate="novalidate" id="login_form" method="post"
              action="controller/login_ctl.php?action=1">
            <? if ($action == 22) { ?>
                <div id="card-alert" class="card red lighten-5">
                    <div class="card-content red-text">
                        <p>Incorrect ID, Password. Please try again.</p>
                    </div>
                    <button type="button" class="close red-text" data-dismiss="alert" aria-label="Close">
                        <span aria-hidden="true">x</span>
                    </button>
                </div>
            <? } ?>
            <? if ($action == 25) { ?>
                <div id="card-alert" class="card red lighten-5">
                    <div class="card-content red-text">
                        <p>You are not authorized to access</p>
                    </div>
                    <button type="button" class="close red-text" data-dismiss="alert" aria-label="Close">
                        <span aria-hidden="true">x</span>
                    </button>
                </div>
            <? } ?>
            <div class="row">
                <div class="input-field col s12 center">
                    <img src="<?= PROJECT_URL ?>images/logo.png" alt="" class="responsive-img valign">
                    <h4 class="header">Please sign in</h4>
                </div>
            </div>
            <div class="row margin">
                <div class="input-field col s12">
                    <i class="mdi-social-person-outline prefix"></i>
                    <input type="text" name="uname" id="uname" class="form-control">
                    <label for="uname" class="center-align">Username</label>
                </div>
            </div>
            <div class="row margin">
                <div class="input-field col s12">
                    <i class="mdi-action-lock-outline prefix"></i>
                    <input type="password" name="pwd" id="pwd" class="form-control">
                    <label for="pwd">Password</label>
                </div>
            </div>
            <div class="row">
                <div class="input-field col s12">
                    <button class="btn waves-effect waves-light col s12" type="submit">Sign in</button>
                </div>
            </div>
            <div class="row">
                <div class="input-field col s6 m6 l6">
<!--                    <p class="margin medium-small"><a href="page-register.html">Register Now!</a></p>-->
                </div>
                <div class="input-field col s6 m6 l6">
                    <p class="margin right-align medium-small"><a class="modal-trigger" href="#forget_pwd_model">Forgot
                            password ?</a></p>
                </div>
            </div>

        </form>
    </div>
    <!-- forget password Modal -->
    <div id="forget_pwd_model" class="modal">
        <div class="modal-header">
            <div class="col s12">
                <h5 class="modal-title">
                    Forgot Password ?
                </h5>
            </div>
        </div>
        <div class="modal-content">
            <p>Enter your username below to get your password.</p>

            <form role="form" method="post" action="forget_password.php" id="forget_pwd_form">
                <div class="input-field col s12">
                    <i class="mdi-social-person-outline prefix"></i>
                    <input type="text" id="username" name="username"
                           autocomplete="off">
                    <label for="username" class="center-align">Username</label>
                </div>
                <div class="form-group">
                    <button type="submit" style="margin: auto;" class="btn btn-login">
                        Send
                    </button>
                </div>
            </form>
        </div>
        <div class="modal-footer lighten-4">
            <a href="#" class="waves-effect waves-red btn modal-action modal-close">Close</a>
        </div>
    </div>
    <!--end  forget password modal -->
</div>
<?php include('includes/inc_js.php'); ?>
<script>
    $("#forget_pwd_form").validate({
        rules: {
            username: {
                required: true
            }
        }, messages: {
            username: "<span class='label label-warning val_mes'>Please enter your username </span>"
        },
        errorElement : 'div',
        errorPlacement: function(error, element) {
            var placement = $(element).data('error');
            if (placement) {
                $(placement).append(error)
            } else {
                error.insertAfter(element);
            }
        },
        submitHandler: function (form) {
            // form.submit();
            $.ajax({
                url: form.action,
                type: form.method,
                data: $(form).serialize(),
                success: function (response) {
                    if (response == 1) {
                        $("#success").show().fadeOut(5000);
                    }
                    else if (response == 2) {
                        $("#warning").show().fadeOut(5000);
                    }
                    else if (response == 0) {
                        $("#error").show().fadeOut(5000);
                    }
                }
            });
            return false;
        }
    });
</script>
</body>
</html>
