<?php
require("includes/check_auth_user.php");
session_unset($_SESSION["zdbyear_".$zdir]);
session_unset($_SESSION["admin_".$zdir]);

require("includes/dbconnect.php");
require("includes/config.php");
require("includes/function.php");

$zdir = $dbname;
$zcomp = 1;
$zdbroot = $zdir;

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

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

    $_SESSION["username_" . $dbname] = $login["user"];

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

    $_SESSION["zcompany"] = 'Purchase Order Inventory';

    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;
        $_SESSION["admin_" . $dbname] = $admin;
        $_SESSION["zdbyear_$dbname"] = $dbyear;

        header("Location: year.php");
        /* header("Location: year.php"); */
    } else {
        print '<script type="text/javascript">';
        print 'alert("Invalid Login Credentials")';
        //header('refresh: 1; index.php');
        print '</script>';
    }
}
?>
<?php include("includes/files.php"); ?>
<html lang="en-US">
    <head>
        <meta charset="UTF-8" />
        <!-- <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">  -->
        <title>Deeniyat</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
        <meta name="description" content="Purchase Order Inventory" />
        <meta name="keywords" content="html5, css3, form, switch, animation, :target, pseudo-class" />
        <meta name="author" content="Codrops" />
        <link rel="shortcut icon" href="../favicon.ico"> 
        <link rel="stylesheet" type="text/css" href="css/demo.css" />
        <link rel="stylesheet" type="text/css" href="css/style.css" />
        <link rel="stylesheet" type="text/css" href="css2/layout.css" />
        <link rel="stylesheet" type="text/css" href="css/animate-custom.css" />
        
        <script type="text/javascript">
//            function validateEmail(username){
//                var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
//
//                if (reg.test(username.value) == false) 
//                {
//                    alert('Invalid Email Address');
//                    return false;
//                }
//
//                return true;
//
//        }
        </script>

    </head>
    <body class="" style="background-color: #ffffff;">
        
        <div class="notice">

            <a href="" class="close">close</a>
            <p class="warn">You have been Successfully Logged Out .</p>

        </div>
        
        <div class="">
            <div class="codrops-top">
                <a href="">
                </a>
                <span class="right">
                </span>
                <div class="clr"></div>
            </div>
            <header>
            </header><br><br><br>
            <section>				
                <div id="container_demo" >
                    <a class="hiddenanchor" id="toregister"></a>
                    <a class="hiddenanchor" id="tologin"></a>
                    <div id="wrapper" >
                        <div id="login" class="animate form" style="background-color: #808080">
                            <form action="" autocomplete="on" method="POST" id="form_id"> 
                                <!--<h1><capitalize><font style="font-family: cipher;  ">DEENIYAT</font></capitalize></h1>--> 
                                <h1 >Stock Inventory System</h1> 
                                <p> 
                                    <label for="username" class="uname" data-icon="u" style="font-size: 10pt; color: #ffffff; font-family: cipher-regular,helvetica;;"> Your Username </label>
                                    <input id="username" name="user" required="required" type="text" placeholder="Username" autofocus="autofocus" onblur="validateEmail(this);"/>
                                    <!--<input id="username" name="user" required="required" type="text" placeholder="Username" autofocus="autofocus" />-->
                                </p>
                                <p> 
                                    <label for="password" class="youpasswd" data-icon="p" style="font-size: 10pt; color: #ffffff; font-family: cipher-regular,helvetica;;"> Your Password </label>
                                    <input id="password" name="pass" required="required" type="password" placeholder="Password" /> 
                                </p>
                                <p class="log button"> 
                                    <!--<button class="form-control" style="background-color: #607d8b; height: 40px; color: white;border-color: white;" name='submit' type="submit" autofocus >Login</button>-->
                                    <button class="form-control" style="background-color: #4CAF50; height: 40px; color: white;border-color: white;" name='submit' type="submit" autofocus >Login</button>
                                </p>
                            </form>
                        </div>
                    </div>
                </div>  
            </section>
        </div>
    </body>
</html>
