<?php
session_start();
include "dasar/koneksi.php";

		$user = $_POST['username'];
		$password = $_POST['password'];
		$nama = strtoupper($_POST['nama']);
		
		
		// query untuk mendapatkan record dari user
		$query = "SELECT * FROM reseller WHERE kode = '$user'";
		$hasil = mysqli_query($link,$query);
		$data = mysqli_fetch_array($hasil);
		
		// cek kesesuaian pin
		if ($user == 'demo' && $password == 'demo' && $nama == 'DEMO')
		{
		    $_SESSION['kode'] = 'Demo';
    		$_SESSION['nama'] = 'Demo';
    		$_SESSION['area'] = '';
			$_SESSION['level'] = '';
    	
    		// tampilkan menu
    		header('location:pages/index.php');
		}
		else if($password == $data['pin'] && $nama == strtoupper($data['nama']))
		{
 
    		// menyimpan username dan level ke dalam session
    		$_SESSION['kode'] = $data['kode'];
    		$_SESSION['nama'] = $data['nama'];
			$_SESSION['area'] = $data['kode_area'];
			$_SESSION['level'] = $data['kode_level'];
			$_SESSION['markup'] = $data['markup'];

    		// tampilkan menu
    		header('location:pages/index.php');
		}
		else
		{
			?><script language="javascript">
			alert("Maaf, Username / Password Anda salah!!");
			document.location="index.php";
			</script><?
		//header('location:login.php?ket=Username / Password Salah');
		}

?>
