<?php
session_start();
 /*$conn = mysqli_connect('localhost','akutans1','kh');
 mysqli_select_db($koneksi,'pkap');*/
include ('koneksi.php');


$username = $_POST['username'];
$password = md5($_POST['password']);
$username = mysqli_real_escape_string($koneksi,$username);
$password = mysqli_real_escape_string($koneksi,$password);


if (empty($_POST['username'])){
$_SESSION['username']=$username;
header ('location:form_login.php');

}else if (empty($_POST['password'])){
	$_SESSION['password']=$password;
header ('location:form_login.php');

}else{

$login = mysqli_query($koneksi,"SELECT * FROM user WHERE username='".$username."' and pasword='".$password."' ") or die (mysqli_errno().':'.mysqli_error());
if (mysqli_num_rows($login) > 0){
while ($dt=mysqli_fetch_array($login)){
$level=$dt['level'];
$kode=$dt['kode'];
$nokode=$dt['nokode'];
$kantor=$dt['kantor'];
$instansi=$dt['instansi'];
}
$_SESSION['username'] = $username;
$_SESSION['level'] = $level;
$_SESSION['status'] = "login";
$_SESSION['kode'] = $kode;
$_SESSION['nokode'] = $nokode;
$_SESSION['kantor'] = $kantor;
$_SESSION['instansi'] = $instansi;


//echo '<script>alert("Anda Berhasil Masuk")</script>';

header("location:home.php");
/*header("location:admin.php");*/

}
if($level==10){

header("location:home.php");
/*header("location:admin2.php");*/
}else if ($level !==10){

header("location:home.php");
/*header("location:admin.php");*/

	
}else{


header("location:form_login.php");

}
}

?>