<?php 
require_once "user.php";

error_reporting(0);
if ($_SESSION['warehouse']) {
	header('Location:index.php');
}else{
$error = '';

if (isset($_POST['submit'])) {
	$nik = $_POST['nik'];
	$pass = $_POST['password'];


	if ((trim($nik)) && (trim($pass))) {
		include"koneksi.php";
		$datauser = mysqli_query ($koneksi, "SELECT Nik, Dept
									FROM user
										WHERE Nik='$nik' AND Password='$pass'");
		$row= mysqli_fetch_array($datauser);
		if($row['Dept']!='1') {
			$error = 'Maaf, Anda Tidak Terdaftar di Dept Warehouse';
		} else {
		if($row['Nik']){
			$_SESSION['warehouse'] = $nik;
			date_default_timezone_set('Asia/Jakarta');
			$waktu = date('Y-m-d  H:i:s');
			$query = "UPDATE user SET Start_Activity = '$waktu' WHERE Nik = '$row[Nik]'";
			mysqli_query($koneksi, $query)
			or die ("Gagal Perintah SQL".mysql_error());
			header('Location:index.php');
			}else{
				$error = 'Ada masalah pada saat Login';
			}
		}
	}else{
		$error = 'Nik dan Password wajib diisi';
	}
}else{
	$error = '';
}

?>
<!DOCTYPE html>
<html lang="id">
<head>
	<title> ITA GPL </title>
	<meta charset="utf-8">
	<meta name="viewport" content="width-device-width, initial-scale=1">
	<link rel="stylesheet" type="text/css" href="style/csslogin.css">
</head>
<body>

	<div class="logo" >
      <!-- <img src="image/welcome.png" height="150" width="640" /> -->
      </div>
	<div class="kotak_login">
		<p class="tulisan_login">Silahkan login</p>

		<form action="" method="POST">
			<label>NIK ITA</label>
			<input type="text" name="nik" class="form_login" placeholder="Nik ITA..">

			<label>Password</label>
			<input type="password" name="password" class="form_login" placeholder="Password..">

			<div id="error"><?php echo $error; ?></div><br>

			<input type="submit" name="submit" class="tombol_login" value="LOGIN">
		</form>		
	</div>
</body>

<?php } ?>
