<?php require_once('Connections/sistem.php'); ?>
<?php
// memulai session
session_start();
$id_user=$_POST['id'];
$password=$_POST['password'];
$kode_unit= $_POST['kode_unit'];
$tahun= $_POST['tahun'];
$bulan= $_POST['bulan'];


if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_sistem, $sistem);
$query_userid = "SELECT * FROM user_tb where id='$id_user' and kode_unit ='$kode_unit'";
$userid = mysql_query($query_userid, $sistem) or die(mysql_error());
$row_userid = mysql_fetch_assoc($userid);
$totalRows_userid = mysql_num_rows($userid);

// cek kesesuaian password
if (md5($password) == $row_userid['password'])
{ 
    // menyimpan username dan level ke dalam session
	$_SESSION['pass'] = $row_userid['password'];
	$_SESSION['Id_admin'] = $row_userid['id'];
     $_SESSION['nama'] = $row_userid['nama_unit'];
	$_SESSION['kode'] = $row_userid['kode_unit'];
	$_SESSION['alamat'] = $row_userid['alamat'];
	$_SESSION['telp'] = $row_userid['telp'];
	$_SESSION['email'] = $row_userid['email']; 
    $_SESSION['level'] = $row_userid['level'];
	$_SESSION['admin'] = $row_userid['nama_admin'];
	$_SESSION['tahun'] = $tahun;
	$_SESSION['bulan'] = $bulan;
	$_SESSION['smt'] = $smt;
	
    // tampilkan menu
  
 include 'main_menu.php'; 
 
}
else
{
	?>
		<script>
			alert ("Maaf..!! User / Password Anda Salah/ Tidak Aktif"); history.back();
		</script>
	<?php
}
?>
