<?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";
$project_title = "RapidRes";

$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["series_" . $dbname] = $getuser_dtl->series;

        $_SESSION["usercode_" . $dbname] = $getuser_dtl->code;
        $_SESSION["usertype"] = $getuser_dtl->usertype;
        $_SESSION["username"] = $getuser_dtl->user;
        $_SESSION["admin_" . $dbname] = $admin;
        $_SESSION["zdbyear_$dbname"] = $dbyear;

//        browse($getuser_dtl->series);

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

        print '<script type="text/javascript">';
        print 'alert("Invalid Login Credentials")';
        print '</script>';
    }
}

include("includes/linkshead.php");
?>

<style>
    body {
        animation: fadeInAnimation ease 3s; 
        animation-iteration-count: 1;
        animation-fill-mode: forwards;
    }

    @keyframes fadeInAnimation {
        0% {
            opacity: 0;
        }
        100% {
            opacity: 1;
        }
    }
    .shadow2 { 
        box-shadow: 0 7px 30px -10px rgba(150,170,180,0.5);
        padding: 40px;
        background: #fff;
        max-width: 360px;
        border-radius: 20px;
        margin: 60px auto;

    }
    .btn-submit {
        width: 106%;
        height: 50px;
        font-size: 20px;
        font-weight: bold;
        border-radius: 7px; 
    }
    .compLogo {
        display: block;
        margin-left: auto;
        margin-right: auto;
        width: 60%;
        
    }
    .form-control:focus {
        background-color: #F6DFEB;
        border-bottom: 1px solid blue;
    }
</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 shadow2 login-form" style="border-color: white;">
                            <div class="text-center">
                                <!--<img class="compLogo" src="" alt="Rapid Residency">-->
                                <h5 class="content-group" style="font-weight: bold;font-size: 25px;color: #57606f;padding: 15px;"><?php Echo $project_title; ?>Login </h5>
                            </div>

                            <div class="form-group has-feedback has-feedback-left">
                                <input type="text" class="form-control user" id="email" placeholder="Username" name='user' autofocus style="color: #57606f;height: 38px;width: 85%;font-weight:bold;border-radius:4px;" 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 user" id="password" placeholder="Password" name='pass' style="color: #57606f;position:static;height: 38px;width: 85%;font-weight: bold;border-radius:4px;" required>
                                <div class="form-control-feedback">
                                    <i class="icon-lock2 text-muted"></i>
                                </div>
                            </div>

                            <div class="form-group" style="width: 100%; text-align: center;">
                                <button type="submit" name="submit" class="btn btn-primary btn-block btn-submit" >Sign in <i class="icon-circle-right2 position-right"></i></button>
                            </div>
                        </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>