<?php
session_start();
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";
//    $ip = get_ip();
//   browse($ip); 
    $muser = $_POST["user"];
//    if (strtolower($_POST["user"]) != "supervisor" && strtolower($_POST["user"]) != "raj") {
//        validateIp($ip);
//    }

    $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;


    if (mysqli_num_rows($login) == 1) {
        $_SESSION['username_' . $zdir] = $_POST["user"];
        $_SESSION["password_" . $dbname] = $_POST["pass"];

        $_SESSION['logged-in'] = true;
        $getuser_dtl = mysqli_fetch_object($login);
        $admin = $getuser_dtl->admin;
        $active = $getuser_dtl->active;
        $_SESSION["username_" . $zdir] = $getuser_dtl->user;
        $_SESSION["spltype_" . $dbname] = $getuser_dtl->spltype;
//        $_SESSION["password_" . $dbname] = $getuser_dtl->password;



        if ($active == 0) {
            browse('This User Is Not Active. Check Credentials.');
        } else {
            $_SESSION["admin_" . $zdir] = $admin;
            header("refresh:1; year.php?user=$muser");
        }
    } else {
        print '<script type="text/javascript">';
        print 'alert("Invalid Login Credentials")';
        //header('refresh: 1; index.php');
        print '</script>';
    }
}
//session_start();
//require("includes/dbconnect.php");
//require("includes/config.php");
//require("includes/function.php");
//
//$zdir = $dbname;
//$zcomp = 1 ;
//$zdbroot = $zdir;
//$maindb  = "passmain";
//
//if(isset($_POST['submit'])){
//   $udbf = $zdbroot."passmain";
//   $ip = get_ip();
//   
//   $user = mysqli_real_escape_string($conn, $_POST['user']);
//   $pass = mysqli_real_escape_string($conn, $_POST['pass']);
//   
//   $login = mysqli_query($conn, "SELECT * FROM `$maindb` WHERE `user` = '" .$user . "' and `password` = '" .$pass. "'") or die(mysqli_error($conn));
//   validateIp($ip);
//
//   $_SESSION["username_".$zdir] = $login["user"];
//   $_SESSION["zdbroot"]= $zdbroot;
//   $_SESSION["zdir"] =  $zdir;
//   if(mysqli_num_rows($login) == 1){
//      $_SESSION['username_'.$zdir] = $_POST["user"];
//      $_SESSION['logged-in'] = true;
//      $getuser_dtl = mysqli_fetch_object($login);
//      $admin       = $getuser_dtl->admin;
//      $_SESSION["admin_".$zdir] = $admin;
//      
//      header("Location: year.php");
//   }
//   else{
////       browse("INVALID LOGIN CREDENTIALS");
//   }
//}
?>
<?php include("includes/files.php"); ?>
<html lang="en-US">
    <head>
        <meta charset="UTF-8" />
        <link rel="shortcut icon" type="image/x-icon" href="images/deentitle.ico">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">  
        <title>LOMINO</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
        <meta name="description" content="" />
        <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="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: #fac663;">-->        
    <body class="" style="background-color: white;">        
        <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: #808080; height: 40px; color: white;border-color: white;" name='submit' type="submit" autofocus >Login</button>
                                </p>
                            </form>
                        </div>
                    </div>
                </div>  
            </section>
        </div>
    </body>
</html>
