<?php
// checking for minimum PHP version
if (version_compare(PHP_VERSION, '5.3.7', '<')) {
    exit("Sorry, Simple PHP Login does not run on a PHP version smaller than 5.3.7 !");
} else if (version_compare(PHP_VERSION, '5.5.0', '<')) {
    // if you are using PHP 5.3 or PHP 5.4 you have to include the password_api_compatibility_library.php
    // (this library adds the PHP 5.5 password hashing functions to older versions of PHP)
    require_once "vistas/libraries/password_compatibility_library.php";
}

// include the configs / constants for the database connection
require_once "vistas/db.php";

// load the login class
require_once "classes/Login.php";

// create a login object. when this object is created, it will do all login/logout stuff automatically
// so this single line handles the entire login process. in consequence, you can simply ...
$login = new Login();

// ... ask if we are logged in here:
if ($login->isUserLoggedIn() == true) {
    // the user is logged in. you can do whatever you want here.
    // for demonstration purposes, we simply show the "you are logged in" view.
    header("location: vistas/html/principal.php");

} else {
    // the user is not logged in. you can do whatever you want here.
    // for demonstration purposes, we simply show the "you are not logged in" view.
    ?>
    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width,initial-scale=1">
        <meta name="description" content="A fully featured admin theme which can be used to build CRM, CMS, etc.">
        <meta name="author" content="Coderthemes">

        <link rel="shortcut icon" href="assets/images/favicon.png">

        <title>Del Rancho- Pupuseria & Cafe</title>

        <link href="../plugins/switchery/switchery.min.css" rel="stylesheet" />

        <link href="assets/css/bootstrap.min.css" rel="stylesheet" type="text/css">
        <link href="assets/css/icons.css" rel="stylesheet" type="text/css">
        <link href="assets/css/style.css" rel="stylesheet" type="text/css">

        <script src="assets/js/modernizr.min.js"></script>
         <style>
           
        </style>

    </head>
    <body>

        <div class="wrapper-page">
        <div class="portlet">
            <div class="portlet-heading bg-dark" style="background: #2C3E50">
                <h3 class="portlet-title">
                    Inicia Sesión
                </h3>

                <div class="clearfix"></div>
            </div>
            <div id="bg-success" class="panel-collapse collapse show">
                <div class="portlet-body">
                <div id="resultados_ajax"></div><br>
                 <div align="center">
                     <img src="img/logo.png" class="img-responsive" alt="profile-image" width="200px" height="150px">
                </div>
<br>
                <form method="post" accept-charset="utf-8" action="login.php" name="loginform" class="form-signin">
                    <?php
// show potential errors / feedback (from login object)
    if (isset($login)) {
        if ($login->errors) {
            ?>
                            <div class="alert alert-danger alert-dismissible" role="alert">
                                <strong>Error!</strong>

                                <?php
foreach ($login->errors as $error) {
                echo $error;
            }
            ?>
                            </div>
                            <?php
}
        if ($login->messages) {
            ?>
                            <div class="alert alert-success alert-dismissible" role="alert">
                                <strong>Aviso!</strong>
                                <?php
foreach ($login->messages as $message) {
                echo $message;
            }
            ?>
                            </div>
                            <?php
}
    }
    ?>

                    <div class="form-group row">
                        <div class="col-12">
                            <div class="input-group">
                                <span class="input-group-addon"><i class="mdi mdi-account"></i></span>
                                <select class='form-control' name='usuario_users' id='usuario_users' required>
												<option value="">-- Selecciona --</option>
												<?php
                                                /* Connect To Database*/
require_once "vistas/db.php"; //Contiene las variables de configuracion para conectar a la base de datos
require_once "vistas/php_conexion.php"; //Contiene funcion que conecta a la base de datos

    $users = mysqli_query($conexion, "select * from users order by nombre_users");
    while ($rw = mysqli_fetch_array($users)) {
        ?>
													<option value="<?php echo $rw['usuario_users']; ?>"><?php echo $rw['usuario_users']; ?></option>
													<?php
}
    ?>
											</select>
                            </div>
                        </div>
                    </div>

                    <div class="form-group row">
                        <div class="col-12">
                            <div class="input-group">
                                <span class="input-group-addon"><i class="mdi mdi-radar"></i></span>
                                <input class="form-control" type="password" name="con_users" required="" placeholder="Contraseña" autocomplete="off">
                            </div>
                        </div>
                    </div>
<br>
                    <div class="form-group text-right m-t-20">
                        <div class="col-xs-12">
                            <button class="btn btn-lg btn-dark waves-effect waves-light btn-block btn-signin" type="submit" name="login" id="submit"><i class='fa fa-unlock'></i> Iniciar Sesión
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>

</div>


        <script>
            var resizefunc = [];
        </script>

        <!-- Plugins  -->
        <script src="assets/js/jquery.min.js"></script>
        <script src="assets/js/tether.min.js"></script>
        <script src="assets/js/bootstrap.min.js"></script>
        <script src="assets/js/detect.js"></script>
        <script src="assets/js/fastclick.js"></script>
        <script src="assets/js/jquery.slimscroll.js"></script>
        <script src="assets/js/jquery.blockUI.js"></script>
        <script src="assets/js/waves.js"></script>
        <script src="assets/js/wow.min.js"></script>
        <script src="assets/js/jquery.nicescroll.js"></script>
        <script src="assets/js/jquery.scrollTo.min.js"></script>
        <script src="../plugins/switchery/switchery.min.js"></script>

        <!-- Custom main Js -->
        <script src="assets/js/jquery.core.js"></script>
        <script src="assets/js/jquery.app.js"></script>

    </body>
    </html>
    <?php
}