<?php
session_start();
$dbtype = "root";
require("includes/dbconnect.php");
require("includes/config.php");
//require("includes/function.php");

$zdir = $dbname;
$zcomp = 1;
$zdbroot = $zdir;
$focusfield = "user";

if (isset($_POST["submit"])) {
    $udbf = $zdbroot . "passmain";

    $login = mysqli_query($conn, "SELECT * FROM `passmain` WHERE `user` = '" . mysqli_real_escape_string($conn, $_POST['user']) . "'
                         AND `password` = '" . mysqli_real_escape_string($conn, $_POST['pass']) . "'") or die(mysqli_error($conn));


    $_SESSION["zdbroot"] = $zdbroot;
    $_SESSION["zdir"] = $zdir;

    $_SESSION["zcompany"] = 'TRAVEL CLUB';

    if (mysqli_num_rows($login) == 1) {
        $_SESSION['username_' . $dbname] = $_POST["user"];
        $_SESSION['logged-in'] = true;
        $getuser_dtl = mysqli_fetch_object($login);
        $admin = $getuser_dtl->admin;
        $usertype = $getuser_dtl->usertype;
        $_SESSION["username_" . $dbname] = $getuser_dtl->user;
        $_SESSION['usertype_' . $dbname] = $usertype;
        $_SESSION["admin_" . $dbname] = $admin;
        $_SESSION["zdbyear_$dbname"] = $dbyear;

        header("Location: year.php");
    } else {
        print '<script type="text/javascript">';
        print 'alert("Invalid Login Credentials")';
        print '</script>';
    }
}
include("includes/linkshead.php");
?>
</head>

<body class="animated fadeIn modern-login-page">
    <section class="login-shell">
        <div class="login-card animated fadeInUp">
            <div class="login-brand">
                <div class="login-logo-wrap">
                    <i class="fa fa-cubes" aria-hidden="true"></i>
                </div>
                <div>
                    <p class="login-eyebrow">Enterprise Resource Planning</p>
                    <h1><?php Echo $project_title; ?></h1>
                </div>
            </div>
            <form class="login-form" action="" method="POST">
                <div class="login-field">
                    <label for="email">Username</label>
                    <div class="login-input">
                        <i class="fa fa-user"></i>
                        <input type="text" class="form-control" id="email" placeholder="Enter username" name="user" autofocus required>
                    </div>
                </div>
                <div class="login-field">
                    <label for="password">Password</label>
                    <div class="login-input">
                        <i class="fa fa-lock"></i>
                        <input type="password" class="form-control" id="password" placeholder="Enter password" name="pass" required>
                        <button type="button" class="password-toggle" aria-label="Show password">
                            <i class="fa fa-eye"></i>
                        </button>
                    </div>
                </div>
                <input type="submit" name="submit" value="Sign in" class="btn btn-primary btn-block login-submit">
            </form>
        </div>
    </section>
    <script>
        $(document).ready(function () {
            $(".password-toggle").on("click", function () {
                var password = $("#password");
                var isHidden = password.attr("type") === "password";
                password.attr("type", isHidden ? "text" : "password");
                $(this).attr("aria-label", isHidden ? "Hide password" : "Show password");
                $(this).find("i").toggleClass("fa-eye fa-eye-slash");
            });
        });
    </script>
    <?php include("includes/linksfoot.php") ?>
</body>
</html>
