<?php
	include("config.php");
	$level=$_POST["tlevel"];
	
	$qry=mysqli_query($mysqli,"SELECT * FROM m_user WHERE username='$_POST[tuser]' AND sandi=LEFT(PASSWORD('$_POST[tpass]'),15) AND level='$level'");
	

	if(mysqli_num_rows($qry) > 0){
		$data=mysqli_fetch_array($qry);
		session_start();
		$_SESSION["ses_admin_id"]=$data["username"];
		$_SESSION["ses_admin_name"]=$data["nama_lengkap"];	
		$_SESSION["ses_admin_level"]=$data["level"];

		if($level=="TPK"){
			$_SESSION["ses_id_tpk"]=$data["id"];
			$_SESSION["ses_id_desa"]=$data["id_desa"];
			
			savelog($mysqli, $data["id"], "ID TPK: $data[id] berhasil login.");
		}
		
		lempar("admin.php");
	}else{
		
		msgbox("Username atau Password salah!");
		
		lempar("index.php");
	
	}
	
?>