<?php
error_reporting(0);
include "config/koneksi.php";
$pass=md5($_POST[password]);
$level=$_POST[level];
$username = $_POST[id_user];
if ($level=='Admin')
{
$login=mysql_query("SELECT * FROM rb_users
			WHERE username='".mysql_real_escape_string($username)."' AND password='$pass' AND level='$level'");
$cocok=mysql_num_rows($login);
$r=mysql_fetch_array($login);

if ($cocok > 0){
	session_start();
	$_SESSION[idu]     = $r[id_user];
	$_SESSION[namauser]     = $r[username];
  	$_SESSION[namalengkap]  = $r[nama_lengkap];
  	$_SESSION[passuser]     = $r[password];
  	$_SESSION[leveluser]    = $r[level];
  	$_SESSION[status]    	= $r[status];

	$sid_lama = session_id();	
	session_regenerate_id();
	$sid_baru = session_id();
  	mysql_query("UPDATE rb_users SET id_session='$sid_baru' WHERE username='$username'");	
	header('location:system/media.php?module=home');
	}
else {
   echo "<script>window.alert('Username Atau Password Anda salah!!!');
        window.location=('javascript:history.go(-1)')</script>";
}
}

else if ($level=='Karyawan'){
$login=mysql_query("SELECT * FROM rb_users
			WHERE username='".mysql_real_escape_string($username)."' AND password='$pass' AND level='$level'");
$cocok=mysql_num_rows($login);
$r=mysql_fetch_array($login);

if ($cocok > 0){
	session_start();
	$_SESSION[idu]     = $r[id_user];
	$_SESSION[namauser]     = $r[username];
  	$_SESSION[namalengkap]  = $r[nama_lengkap];
  	$_SESSION[passuser]     = $r[password];
  	$_SESSION[leveluser]    = $r[level];
  	$_SESSION[status]    	= $r[status];

	$sid_lama = session_id();	
	session_regenerate_id();
	$sid_baru = session_id();
  	mysql_query("UPDATE rb_users SET id_session='$sid_baru' WHERE username='$username'");	
	header('location:system/media.php?module=home');
}else {
   echo "<script>window.alert('Username Atau Password Anda salah!!!');
        window.location=('javascript:history.go(-1)')</script>";
}
}

?>
<link href="templates/style.css" rel="stylesheet" type="text/css" /> 