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

$zheadroot = $_SESSION['zheadroot'] = $dbname;

// error_reporting(E_ERROR);
// ini_set('display_errors', 1);

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

$addflag = '';
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));

//    browse(mysqli_num_rows($login));


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

    $_SESSION["zcompany"] = '';

    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["add_r"] = $getuser_dtl->add_r;
        $_SESSION["edit_r"] = $getuser_dtl->edit_r;
        $_SESSION["del_r"] = $getuser_dtl->del_r;
        $_SESSION["series_" . $dbname] = $getuser_dtl->series;
        $_SESSION["usercode_" . $dbname] = $getuser_dtl->code;
        $_SESSION["usertype"] = $getuser_dtl->usertype;
        $_SESSION["usertype_" . $dbname] = $getuser_dtl->usertype;
        $_SESSION["username"] = $getuser_dtl->user;
        $_SESSION["admin_" . $dbname] = $admin;
        $_SESSION["zdbyear_$dbname"] = $dbyear;

        browse($getuser_dtl->usertype);

        header("Location: comp.php");
    } else {

        print '<script type="text/javascript">';
        print 'alert("Invalid Login Credentials")';
        print '</script>';
    }
}
include("includes/linkshead.php");
?>
<style>
@import url("https://fonts.googleapis.com/css2?family=Russo+One&display=swap");

svg {
	font-family: "Russo One", sans-serif;
	width: 100%; height: 100%;
}
svg text {
	animation: stroke 3s infinite alternate;
	stroke-width: 2;
	stroke: #365FA0;
	font-size: 50px;
}
@keyframes stroke {
	0%   {
		fill: rgba(24,82,151,0); stroke: rgba(54,95,160,1);
		stroke-dashoffset: 25%; stroke-dasharray: 0 50%; stroke-width: 2;
	}
	70%  {fill: rgba(24,82,151,0); stroke: rgba(54,95,160,1); }
	80%  {fill: rgba(24,82,151,0); stroke: rgba(54,95,160,1); stroke-width: 3; }
	100% {
		fill: rgba(24,82,151,1); stroke: rgba(54,95,160,0);
		stroke-dashoffset: -25%; stroke-dasharray: 50% 0; stroke-width: 0;
	}
}

.wrapper {background-color: #FFFFFF};
</style>
</head>

<body class="animated fadeIn">
    <!-- Page container -->
    <div class="page-container login-container">
        <!-- Page content -->
        <div class="page-content">
            <!-- Main content -->
            <div class="content-wrapper">
                <!-- Content area -->
                <div class="content">
                    <!-- Simple login form -->
                    <form action="" method="POST">
                        <div class="panel panel-body login-form">
                            <div class="text-center">
                            <div class="wrapper">
	<svg>
		<text x="50%" y="50%" dy=".35em" text-anchor="middle">
        <?= $project_name; ?>
		</text>
	</svg>
</div>
                                <!-- <img style="width: 100%;" src="images/logo/merewbill.jpg" alt="logo"> -->
                                <!-- <h2 class="content-group"></h2> -->
                                <!-- <h5 class="content-group"><small class="display-block">Login</small></h5> -->
                            </div>

                            <div class="form-group has-feedback has-feedback-left">
                                <input type="text" class="form-control" id="email" placeholder="Username" name='user' autofocus style="height: 33px;width: 85%" required>
                                <div class="form-control-feedback">
                                    <i class="icon-user text-muted"></i>
                                </div>
                            </div>

                            <div class="form-group has-feedback has-feedback-left">
                                <input type="password" class="form-control" id="password" placeholder="Password" name='pass' style="height: 33px;width: 85%" required>
                                <div class="form-control-feedback">
                                    <i class="icon-lock2 text-muted"></i>
                                </div>
                            </div>

                            <div class="form-group">
                                <button type="submit" name="submit" class="btn btn-primary btn-block">Sign in <i class="icon-circle-right2 position-right"></i></button>
                            </div>
                        </div>
                    </div>
                </form>
                <!-- /simple login form -->
                <!-- /content area -->
            </div>
            <!-- /main content -->
        </div>
        <!-- /page content -->
    </div>
</div> 
<!-- /page container -->

<?php include("includes/linksfoot.php") ?>
</body>
</html>