<?php 
ob_start();
session_start();
$error_message='';
include "config/config.php";
include "config/session.php";

if(isset($session)) {
	header('location: index.php'); 
	exit;
}

if(isset($_POST['login'])) {
        
    if(empty($_POST['username']) || empty($_POST['password'])) {
        $error_message = 'Username or Password can not be empty';
    } else {
		
		$username = strip_tags($_POST['username']);
		$password = strip_tags($_POST['password']);

        $statement = $pdo->prepare("SELECT u.*, r.role_name, r.permission FROM `tbl_users` u 
        INNER JOIN tbl_role r ON u.role=r.id 
        WHERE u.emp_code=? AND u.password=?");
    	$statement->execute(array($username,$password));
        $total = $statement->rowCount();    
        $result = $statement->fetchAll(PDO::FETCH_ASSOC);    
        if($total==0) {
            $error_message = 'Username does not match';
        }
        
        else if($result[0]['status']==0){$error_message = 'This ID is Inactive Contact Admin!!!';}
        else {       
				$_SESSION["$session_name"] = $result[0];
				$_SESSION['permission'] = json_decode($result[0]['permission'], true);
                header("location: index.php");
        }
    }

    
}


?>

<!DOCTYPE html>
<html lang="en">
<head>
<title><?=$site_name?> | Login</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<link rel="icon" type="image/png" href="<?=$site_favicon?>" />

<link rel="stylesheet" type="text/css" href="asst/vendor/bootstrap/css/bootstrap.min.css">

<link rel="stylesheet" type="text/css" href="asst/fonts/font-awesome-4.7.0/css/font-awesome.min.css">

<link rel="stylesheet" type="text/css" href="asst/vendor/animate/animate.css">

<link rel="stylesheet" type="text/css" href="asst/vendor/css-hamburgers/hamburgers.min.css">

<link rel="stylesheet" type="text/css" href="asst/vendor/select2/select2.min.css">

<link rel="stylesheet" type="text/css" href="asst/css/util.css">
<link rel="stylesheet" type="text/css" href="asst/css/main.css">

<meta name="robots" content="noindex, follow">
<script nonce="6cd161a3-1111-4208-819f-1fa93f104004">(function(w,d){!function(dk,dl,dm,dn){dk[dm]=dk[dm]||{};dk[dm].executed=[];dk.zaraz={deferred:[],listeners:[]};dk.zaraz.q=[];dk.zaraz._f=function(dp){return function(){var dq=Array.prototype.slice.call(arguments);dk.zaraz.q.push({m:dp,a:dq})}};for(const dr of["track","set","debug"])dk.zaraz[dr]=dk.zaraz._f(dr);dk.zaraz.init=()=>{var ds=dl.getElementsByTagName(dn)[0],dt=dl.createElement(dn),du=dl.getElementsByTagName("title")[0];du&&(dk[dm].t=dl.getElementsByTagName("title")[0].text);dk[dm].x=Math.random();dk[dm].w=dk.screen.width;dk[dm].h=dk.screen.height;dk[dm].j=dk.innerHeight;dk[dm].e=dk.innerWidth;dk[dm].l=dk.location.href;dk[dm].r=dl.referrer;dk[dm].k=dk.screen.colorDepth;dk[dm].n=dl.characterSet;dk[dm].o=(new Date).getTimezoneOffset();if(dk.dataLayer)for(const dy of Object.entries(Object.entries(dataLayer).reduce(((dz,dA)=>({...dz[1],...dA[1]})))))zaraz.set(dy[0],dy[1],{scope:"page"});dk[dm].q=[];for(;dk.zaraz.q.length;){const dB=dk.zaraz.q.shift();dk[dm].q.push(dB)}dt.defer=!0;for(const dC of[localStorage,sessionStorage])Object.keys(dC||{}).filter((dE=>dE.startsWith("_zaraz_"))).forEach((dD=>{try{dk[dm]["z_"+dD.slice(7)]=JSON.parse(dC.getItem(dD))}catch{dk[dm]["z_"+dD.slice(7)]=dC.getItem(dD)}}));dt.referrerPolicy="origin";dt.src="../../../cdn-cgi/zaraz/sd0d9.js?z="+btoa(encodeURIComponent(JSON.stringify(dk[dm])));ds.parentNode.insertBefore(dt,ds)};["complete","interactive"].includes(dl.readyState)?zaraz.init():dk.addEventListener("DOMContentLoaded",zaraz.init)}(w,d,"zarazData","script");})(window,document);</script>
</head>
<body>
<div class="limiter">
	<div class="container-login100">
		<div class="wrap-login100" style="padding-top: 100px;">
			<div class="login100-pic js-tilt" data-tilt>
				<img src="<?=$setting[0]['logo']?>" alt="IMG">
			</div>
			
			<form class="login100-form validate-form" method="post" action="" >
			    
				<span class="login100-form-title"><?=$site_name?></span>
				
				<?php 
            	    if( (isset($error_message)) && ($error_message!='') ):
            	        
            	        echo '  <div class="alert alert-warning alert-dismissible fade show" role="alert">
                                 <strong>'.$error_message.'</strong> 
                                  <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                </div>';
            	    endif;
    	        ?>

				
				<div class="wrap-input100 validate-input" data-validate="Username is required">
					<input class="input100" type="text" name="username" id="username" placeholder="Username">
					<span class="focus-input100"></span>
					<span class="symbol-input100"><i class="fa fa-user" aria-hidden="true"></i></span>
				</div>
				
				<div class="wrap-input100 validate-input" data-validate="Password is required">
					<input class="input100" type="password" name="password" id="myPassword" placeholder="Password">
					<span class="focus-input100"></span>
					<span class="symbol-input100"><i class="fa fa-lock" aria-hidden="true"></i></span>
				</div>
				
				
				<!--<span class="symbol-input100" onclick="show()" id="btn_show"><i class="fa fa-eye"></i> Show Password</span>
                <span class="symbol-input100" onclick="hide()" id="btn_hide"><i class="fa fa-eye-slash"></i> Hide Password</span>-->
                
				<div class="container-login100-form-btn">
					<button type="submit" name="login" class="login100-form-btn">Login</button>
				</div>
				
				<!--<div class="text-center p-t-12">
					<span class="txt1"></span>
					<a class="txt2" href="#">Forgot Password?</a>
				</div>-->
				
			</form>
			
		</div>
	</div>
</div>

<script src="asst/vendor/jquery/jquery-3.2.1.min.js"></script>

<script src="asst/vendor/bootstrap/js/popper.js"></script>
<script src="asst/vendor/bootstrap/js/bootstrap.min.js"></script>

<script src="asst/vendor/select2/select2.min.js"></script>

<script src="asst/vendor/tilt/tilt.jquery.min.js"></script>

<script>
    $(function () {
        if ($('#identity').val())
            $('#password').focus();
        else
            $('#identity').focus();
        $('input').iCheck({
            checkboxClass: 'icheckbox_square-blue',
            radioClass: 'iradio_square-blue',
            increaseArea: '20%'
        });
    });
</script>

<script>
    $( document ).ready(function() {
        $('#btn_show').show();
        $('#btn_hide').hide();
        
    });
    
        function show() {
          var obj = document.getElementById('myPassword');
          obj.type = "text";
          $('#btn_show').hide();$('#btn_hide').show();
        }
    function hide() {
      var obj = document.getElementById('myPassword');
      obj.type = "password";
      $('#btn_show').show();$('#btn_hide').hide();
    }
</script>


<script>
		$('.js-tilt').tilt({
			scale: 1.1
		})
	</script>

<script async src="https://www.googletagmanager.com/gtag/js?id=UA-23581568-13"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-23581568-13');
</script>

<script src="asst/js/main.js"></script>
<script defer src="https://static.cloudflareinsights.com/beacon.min.js/v52afc6f149f6479b8c77fa569edb01181681764108816" integrity="sha512-jGCTpDpBAYDGNYR5ztKt4BQPGef1P0giN6ZGVUi835kFF88FOmmn8jBQWNgrNd8g/Yu421NdgWhwQoaOPFflDw==" data-cf-beacon='{"rayId":"7bf58fb228f0a905","version":"2023.4.0","b":1,"token":"cd0b4b3a733644fc843ef0b185f98241","si":100}' crossorigin="anonymous"></script>
</body>
</html>
