<?php 
// mengaktifkan session php
session_start();

// menghubungkan dengan koneksi
include_once "library/inc.connection.php";
include_once "library/inc.library.php";

// menangkap data yang dikirim dari form
$username = $_POST['username'];
$password = $_POST['password'];

// menyeleksi data admin dengan username dan password yang sesuai
$data = mysql_query("SELECT * FROM user WHERE userid='".$username."' AND password='".md5($password)."'", $koneksidb);

// menghitung jumlah data yang ditemukan
$cek = mysql_num_rows($data);

if($cek > 0){
	$loginData = mysql_fetch_assoc($data);
	// Jika yang login Administrator
	if($loginData['level']=="Admin") 
	{
		$_SESSION['nama'] = $loginData['nama'];
		$_SESSION['SES_ADMIN'] = "Admin";
		$_SESSION['level'] = "Admin";
		$_SESSION['SES_LOGIN'] = $loginData['userid'];
		$_SESSION['status'] = "login";
		header("location:admin/index.php?page=Halaman-Utama"); 

	}

	// Jika yang login Kasir
	else if($loginData['level']=="Kasir") 
	{
		$_SESSION['nama'] = $loginData['nama'];
		$_SESSION['SES_KASIR'] = "Kasir";
		$_SESSION['level'] = "Kasir";
		$_SESSION['SES_LOGIN'] = $loginData['userid']; 
		$_SESSION['status'] = "login";
		header("location:admin/index.php?page=Halaman-Utama"); 
		// Refresh
		// echo "<meta http-equiv='refresh' content='0; url=admin/index.php?page=Halaman-Utama'>";
	}
	else
	{
		header("location:index.php?pesan=gagal");
	}
	
}else{
	header("location:index.php?pesan=gagal");
}
?>