<?php
//session_start();
include "config/conn.php";
if(isset($_POST['btn_login'])){
	if ($_POST['btn_login']=="GO!")
		{ 
				$username = $_POST['username'];
				$password = $_POST['password'];
					if ($username=="" || $password=="")
					{
						$kosong="<font color='red' size='3'><em>Username dan password invalid!</em></font>";	
					} 
						else 
					{
							$pass=md5($password);
							$query = "SELECT
										a.id_user,
										a.username,
										a.`password`,
										a.id_level,
										a.nama_user,
										a.`status`,
										a.id_bbws,
										a.lat,
										a.lng,
										b.nama_bbws,
										b.keterangan_bbws,
										b.unit_bbws,
										b.alamat_bbws,
										b.logo_bbws,
										b.kode_bbws,
										c.kode_das,
										c.nama_das
										FROM
										m_user AS a
										LEFT JOIN m_bbws AS b ON a.id_bbws = b.id_bbws
										LEFT JOIN m_das AS c ON b.id_bbws = c.id_bbws
										WHERE 1 = 1 AND a.username = '$username' and a.password='$pass'";
							$hasil = mysql_query($query);
							$data = mysql_fetch_array($hasil);
							// cek kesesuaian password
							if (($username == $data['username']) && ($pass == $data['password']))
							{
								// menyimpan username dan level ke dalam session
								ini_set('session.gc_maxlifetime', 36000);

								// each client should remember their session id for EXACTLY 1 hour
								session_set_cookie_params(36000);
								session_start();
	//							session_register('username');
								$_SESSION['id_user'] = $data['id_user'];
								$_SESSION['username'] = $data['username'];			
								$_SESSION['password'] = $data['password'];			
								$_SESSION['id_level'] = $data['id_level'];			
								$_SESSION['nama_user'] = $data['nama_user'];			
								$_SESSION['status'] = $data['status'];
								$_SESSION['id_bbws'] = $data['id_bbws'];			
								$_SESSION['nama_bbws'] = $data['nama_bbws'];			
								$_SESSION['keterangan_bbws'] = $data['keterangan_bbws'];			
								$_SESSION['unit_bbws'] = $data['unit_bbws'];			
								$_SESSION['alamat_bbws'] = $data['alamat_bbws'];			
								$_SESSION['logo_bbws'] = $data['logo_bbws'];			
								$_SESSION['kode_das'] = $data['kode_das'];			
								$_SESSION['nama_das'] = $data['nama_das'];			
								$_SESSION['lat'] = $data['lat'];
								$_SESSION['lng'] = $data['lng'];			
								//*
								if($data['id_level']==1) {
								echo "<script>window.location = 'home.php?ajax/module/dwd.php';</script>";
								} else { 
								echo "<script>window.location = 'home.php?page=dashboard';</script>";
								}
								//*/
							}
					}
		}

}
?>
