<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Admin Login</title>
	<link rel="stylesheet" type="text/css" href="style.css">
<link href="https://fonts.googleapis.com/css2?family=Poppins&display=swap" rel="stylesheet">

</head>
<body id="bg-login">

	<div class="box-login">
		<h2>Login</h2>
		<form action="" method="POST">
			<input type="text" name="nama" placeholder="Name" class="input-control">
			<input type="password" name="aidi" placeholder="Employee ID " class="input-control">
			<input type="submit" name="submit" value="Login" class="btn">
		</form>
		<?php
				// juka user click tombol submit, maka...
			if(isset($_POST['submit'])){
				// untuk nyambungin ke file lain
				session_start();
				include 'konek.php';
					// agar mencega dari adanya selain huruf dan angka
				$nama = mysqli_real_escape_string($conn,$_POST['nama']);
				$aidi = mysqli_real_escape_string($conn,$_POST['aidi']);
					// untuk memastikan pw dan nama sesuai dengan yg ada di database
				$cek = mysqli_query($conn, "SELECT * FROM employee WHERE name = '".$nama."'AND employee_id = '".($aidi)."'");
				if(mysqli_num_rows($cek) > 0) {
					$d = mysqli_fetch_object($cek);
					// jika status login, maka bisa akses apapun file yg nyambung
					$_SESSION['status_login'] = true;
					// bisa memanggil nama user di file lain
					$_SESSION['a_global'] = $d;
					//menyimpan data dalam variabel
					$_SESSION['id'] = $d->employee_id;
					// jika benar semua, maka akan dibawah ke file dashboard
					echo '<script>window.location="admin.php"</script>';
				} 
				else{
					echo '<script>alert("Username or Password wrong!")</script>';
				}



				
			}
		?>

   <div class="Reg">
   	<p>No Account?</p>
   	<p class="a"><a href="admin-register.php">Register</a></p>
   </div>





	</div>
</body>
</html>