<?php
session_start();
require_once "admin/connection.inc.php";

$cmd = isset($_POST['__cmd']) ? $_POST['__cmd'] : '';

$message = '';

if ('login' == $cmd) {

    $user_name = getIsset('__username');
    $password = getIsset('__password');
	
    $chk_login = $conn->select('Memployee', array('username' => $user_name, 'password' => $password), true);
	
    if ($chk_login != null) {
        $level =  $conn->select('MuserLevel', array('userlevelid' => $chk_login['userlevelid']), true);
		
		
        $session = array(
            "id" => $chk_login["employeeid"],
            "fullname" => $chk_login["fname"] . " " . $chk_login["lname"],
            "positionName" => $level["userlevelname"],
            "level" => 1,
            "permission" =>$chk_login["userlevelid"],
            "data" => $chk_login);
			
			
        $_SESSION["uprofile"] = $session;
		
        redirectTo(ROOTPATH . '/admin/index.php');

    } else {
        $message = generate_action_tag('error', 'Username หรือ Password ผิดพลาด กรุณาตรวจสอบ');
    }
}
?>



<html>
<head>
    <title></title>

    <!-- Meta -->
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="description" content="Insight Station Network">
    <meta name="author" content="Insight Station Network">

    <!-- Theme style -->
    <link href="admin/dist/css/font-awesome.min.css" rel="stylesheet" type="text/css"/>
    <link href="admin/bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css"/>
    <link href="admin/dist/css/ionicons.min.css" rel="stylesheet" type="text/css"/>
    <link href="admin/assets/css/custom.css" rel="stylesheet" type="text/css"/>
    <style>
        input, select {
            height: 28px !important;
            padding-top: 0px !important;
            padding-bottom: 0px !important;
            border-radius: 0px !important;
        }
    </style>
</head>
<body style="margin:0px">
<div
    style="background-image:url('admin/assets/img/home-bg.jpg');background-size:cover;width:100%;height:100%;position:absolute">
    <div
        style="max-width:400px;min-width: 250px;height:auto;margin:0 auto;padding:20px;position:relative;top:20%;background-color:rgba(0,0,0,0.5);border-radius:10px">
        <div class="row">
            <div class="col-xs-12 text-center">
                <h2 style="color:white"><?php echo TITLE; ?></h2>
            </div>
        </div>

        <hr>

        <div id="UpdatePanel1">
            <form class="form-horizontal" method="post" id="form_login" name="form_login">
                <input type="hidden" name="__cmd" id="__cmd" value="login">
                <h3 style="color:white;margin-bottom:10px">Login</h3>

                <div class="input-group" style="margin-bottom:20px;">
                    <span class="input-group-addon"><i class="fa fa-user"></i></span>
                    <input name="__username" type="text" maxlength="20" id="__username"
                           class=" form-control input-sm " placeholder="User Name" required>
                </div>

                <div class="input-group" style="margin-bottom:20px;">
                    <span class="input-group-addon"><i class="fa fa-lock"></i></span>
                    <input name="__password" type="password" maxlength="20" id="__password"
                           class=" form-control input-sm " placeholder="Password" required>
                </div>

                <div class="row">
                    <div class="col-md-6">
                    </div>

                    <div class="col-md-6">
                        <button class="btn btn-info pull-right" type="submit">Login</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<div class="modal flat" id="alertModal">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header" style="background-color: white">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <span>
                <span class="glyphicon glyphicon-info-sign" style="font-size:30px;color:#f2b712"></span>
                <span style="font-size: 20px;" id="alertTitle"></span></span>
            </div>
        </div>
    </div>
</div>
<script src="admin/plugins/jQuery/jQuery-2.1.4.min.js"></script>
<script src="admin/bootstrap/js/bootstrap.min.js"></script>
<script src="admin/plugins/select2/select2.full.min.js"></script>
<script src="admin/plugins/daterangepicker/daterangepicker.js"></script>
<script src="admin/plugins/colorpicker/bootstrap-colorpicker.min.js"></script>
<script src="admin/plugins/timepicker/bootstrap-timepicker.min.js"></script>
<script src="admin/plugins/slimScroll/jquery.slimscroll.min.js"></script>
<script src="admin/plugins/iCheck/icheck.min.js"></script>
<script src="admin/plugins/fastclick/fastclick.min.js"></script>
<script src="admin/dist/js/app.min.js"></script>
<script src="admin/dist/js/demo.js"></script>
<script src="admin/js/screen.js"></script>
<script>
    function showModal() {
        $('#alertTitle').text('<?php echo isset($message) ? $message : ""; ?>');
        $('#alertModal').modal();
    }
</script>
<?php if($error_type){
    echo '<script>showModal()</script>';
}?>
</body>
</html>
