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

$zdir = $dbname;
$zcomp = 1;
$zdbroot = $zdir;
$focusfield = "user";
//browse($zdbroot);
$zroot = $_SESSION["zdbroot"];

$zroot1 = substr($zroot, 0, -4);

if (isset($_POST["submit"])) {

    $udbf = $zdbroot . "passmain";
    $password = $_POST['pass'];
    $user = $_POST['user'];

    $login = mysqli_query($conn, "SELECT * FROM `passmain` WHERE `user` = '$user'
                         AND `password` = '$password'") or die(mysqli_error($conn));

    $flogin = mysqli_fetch_array($login);
    $_SESSION["username_" . $dbname] = $flogin["user"];
    $_SESSION["usertype_" . $dbname] = $flogin["usertype"];

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

    $_SESSION["zcompany"] = 'Raisin';


    $count = mysqli_num_rows($login);
//    browse(mysql_num_rows($login));
    if ($count == 1) {

        $_SESSION['username_' . $dbname] = $_POST["user"];
        $_SESSION['logged-in'] = true;

//        $getuser_dtl = mysqli_fetch_object($login);
        $admin = $flogin['admin'];
        $_SESSION["admin_" . $dbname] = $admin;
        $_SESSION["zdbyear_$dbname"] = $dbyear;

        $getcom = mysqli_query($conn, "Select * from `compyear` order by `lastdate` desc limit 0,1 ") or die(msqli_error($conn));
        $fetcom = mysqli_fetch_array($getcom);
        $cono = $fetcom['cono'];
        $year = $fetcom['finyear'];
        $_SESSION["comp_" . $dbname] = $cono;
        $_SESSION[$myyear] = $year;

        $_SESSION["zdbyear_" . $dbname] = substr($_SESSION["zdbroot"], 0, -4) . $cono . '_' . $year;

        $_SESSION["tit_" . $dbname] = $year;


        if ($_SESSION["usertype_" . $dbname] == 'W') {
            header("Location: menu2.php");
        } else {
            header("Location: menu.php");
        }
    } else {
        print '<script type="text/javascript">';
        print 'alert("Invalid Login Credentials")';
        print '</script>';
    }
}
include("includes/linkshead.php");
?>
</head>

<body class="animated fadeIn" style="background: url(assets/img/ship2.jpg) no-repeat;">
    <section id="login-container">
        <div class="row text-center"></div>
        <div class="row">
            <div class="col-md-3" id="login-wrapper">
                <div class="panel panel-primary animated flipInY">
                    <div class="panel-heading">
                        <h3 class="panel-title">     
                            <?php Echo $project_title; ?>
                        </h3>      
                    </div>
                    <div class="panel-body">
                        <p>Login to access your account.</p>
                        <form class="form-horizontal" action='' method="POST">
                            <div class="form-group">
                                <div class="col-md-12">
                                    <input type="text" class="form-control" id="email" placeholder="Username" name='user' autofocus>
                                    <i class="fa fa-user"></i>
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-md-12">
                                    <input type="password" class="form-control" id="password" placeholder="Password" name='pass'>
                                    <i class="fa fa-lock"></i>
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-md-12">
                                    <input type='submit' name='submit' class="btn btn-primary btn-block" >
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </section>
    <?php include("includes/linksfoot.php") ?>
</body>
</html>