<?php
session_start();
include_once "include/config.php";

$username   = $_REQUEST['username'];
$password   = $_REQUEST['password'];
//$pengacak   = "AJWKXLAJSCLWLW";
//$passEnkrip = md5($pengacak . md5($password) . $pengacak );
$data_1 = mysql_fetch_array(mysql_query("SELECT user_id,user_name,user_level FROM user
                                        WHERE user_id='$username' AND user_level<>100 "));
$data_2 = mysql_fetch_array(mysql_query("SELECT user_id,user_name,user_level, user_pass FROM user
                                        WHERE user_pass='$password' AND user_level<>100 "));
$data_all = mysql_fetch_array(mysql_query("SELECT user_id,user_name,user_level FROM user
                                        WHERE user_id='$username' AND user_pass='$password' AND user_level<>100 "));										
										
//$password = md5($pswd);
//echo "Test : $password===$data->password";exit;	
if ((strtoupper($username)) <> (strtoupper($data_1['user_id']))){
	?>
	<script language="javascript">
		alert("User ID anda salah...!");
		location.href = "index.php";
	</script>
	<?php 
}elseif ((strtoupper($password)) <> (strtoupper($data_2['user_pass']))){
	?>
	<script language="javascript">
		alert("Password anda salah...!");
		location.href = "index.php";
	</script>
	<?php 
}else{
	$_SESSION['USER_ID']	= $data_all['user_id'];
	$_SESSION['USER_NAME']  = $data_all['user_name'];
	$_SESSION['USER_LEVEL'] = $data_all['user_level'];
	#Insert user log
	mysql_query("INSERT INTO user_log SET usr_id='".$_SESSION['USER_ID']."', usr_date=current_date(), usr_timein=current_time(), usr_status=10");
	#insert history
	mysql_query("INSERT INTO user_activity SET user_id='".$_SESSION['USER_ID']."', user_act='Login ke Program IT Inventory', user_date=current_date(), user_time=current_time()");
	?><script language="javascript">
		window.location = 'main.php?page=Halaman-Utama';
	</script> <?php
}	
?>