<?php
session_start();
$_SESSION[sid] = session_id();
/*echo "<pre>";
print_r($_POST);
echo "</pre>";*/
//die();
if (($_POST['email']) && ($_POST['password'])) {
    require_once("../lib/dbconn.php");

    if (strlen($_POST['password']) < 6) {
	$_SESSION[error] = "Password salah.";
    } else {
	$md5paz = md5($_POST[password]);
	$checkUid = mysql_query("SELECT nama_user FROM tbl_user WHERE nama_user='".$_POST[email]."'");
	$rowUid = mysql_num_rows($checkUid);
	$checkAll = mysql_query("SELECT nama_user, pass_user FROM tbl_user WHERE nama_user='".$_POST[email]."' AND pass_user='$md5paz'",$con);
	$rowAll = mysql_num_rows($checkAll);
        //echo "SELECT nama_user, pass_user FROM tbl_user WHERE nama_user='".$_POST[email]."' AND pass_user='$md5paz'";
        //die();
	if ((!$rowUid) || ($rowUid == 0)) {            
            //$checkUid;
            $error = base64_encode("Username tidak ada 1.");
            
            //header("Location: ../index.php?ck=".$error);
            echo "<script language='JavaScript'>document.location='../index.php?ck=$error'</script>";
	} elseif ((!$rowAll) || ($rowAll == 0)) {
	    $error = base64_encode("Username tidak ada 2.");
            echo "<script language='JavaScript'>document.location='../index.php?ck=$error'</script>";
	} elseif ($rowAll == 1) {
	    //unset($_SESSION[error]);
	    $vpaz = $md5paz;
	    $getInfo = mysql_query("SELECT * FROM tbl_user WHERE nama_user='".$_POST[email]."' AND pass_user='$vpaz'");
	    $rowInfo = mysql_fetch_object($getInfo);
	    //echo "SELECT * FROM tbl_user WHERE nama_user='".$_POST[email]."' AND pass_user='$vpaz'";
        $_SESSION[uid] = $rowInfo->nama_user;
	    $_SESSION[vuid] = md5($_SESSION[sid].$_SESSION[uid]);
	    
	    $_SESSION[nama_usr] = $rowInfo->nama_lengkap; 	    
	    $_SESSION[gr] = trim($rowInfo->kd_bagian); 
            
            header("Location: ../index3.php?user=".$_SESSION[uid]);
            echo "<script language='JavaScript'>document.location='../index3.php?user=".$_SESSION[uid]."'</script>";
	}
    }
} else {
    $error = base64_encode("Isikan data dengan benar");
    echo "<script language='JavaScript'>document.location='../index.php?ck=$error'</script>";
}


echo "<br><br><br><br>";
echo "<center><font class=form_title><b>proses...</b></font></center>";


?>
