<?php
if($_GET) {
	if($_POST) {
		$message = array();
		if ( trim($_POST['txtUser'])=="") {
			$message[] = "<b> User ID </b>  tidak boleh kosong !";		
		}
		if (trim($_POST['txtPassword'])=="") {
			$message[] = "<b> Password </b> tidak boleh kosong !";		
		}
		$txtUser 	= $_POST['txtUser'];
		$txtUser 	= str_replace("'","&acute;",$txtUser);
		$txtPassword=$_POST['txtPassword'];
		$txtPassword= str_replace("'","&acute;",$txtPassword);
		$pengacak = "AJWKXLAJSCLWLW";
		$passEnkrip = md5($pengacak . md5($txtPassword) . $pengacak );
		if(count($message)==0){	
			$loginSql = "SELECT * FROM admin WHERE userid='".$txtUser."' AND password='$passEnkrip' ";
			$loginQry = mysql_query($loginSql, $koneksidb)  or die ("Query Periksa Password Salah : ".mysql_error());
			if($loginQry){
				if (mysql_num_rows($loginQry) >=1) {
					$loginData = mysql_fetch_array($loginQry);
/////////////////// 1. USER BIASA /  KARYAWAN ////////////////////////////////////////
					if($loginData['level']=="User") {
						$_SESSION['SES_USER'] = "User";
						$_SESSION['SES_LOGIN'] = $loginData['userid']; 
						$_SESSION['SES_IDKAR'] = $loginData['id_kar']; 
						$_SESSION['SES_NAMA'] = $loginData['nama_karyawan']; 
						$_SESSION['SES_LEVEL'] = $loginData['level']; 
					}
/////////////////// 2. TEKNISI LAPANG ////////////////////////////////////////
					if($loginData['level']=="Teknisi Lapang") {
						$_SESSION['SES_TEKNISI'] = "Teknisi Lapang";
						$_SESSION['SES_LOGIN'] = $loginData['userid']; 
						$_SESSION['SES_IDKAR'] = $loginData['id_kar']; 
						$_SESSION['SES_NAMA'] = $loginData['nama_karyawan']; 
						$_SESSION['SES_LEVEL'] = $loginData['level']; 
					}
/////////////////// 3. OPERATOR SARANA ////////////////////////////////////////
					if($loginData['level']=="Operator Sarana") {
						$_SESSION['SES_SARANA'] = "Operator Sarana";
						$_SESSION['SES_LOGIN'] = $loginData['userid']; 
						$_SESSION['SES_IDKAR'] = $loginData['id_kar']; 
						$_SESSION['SES_NAMA'] = $loginData['nama_karyawan']; 
						$_SESSION['SES_LEVEL'] = $loginData['level']; 
					}
/////////////////// 4. OPERATOR PRASARANA ////////////////////////////////////////
					if($loginData['level']=="Operator Prasarana") {
						$_SESSION['SES_PRASARANA'] = "Operator Prasarana";
						$_SESSION['SES_LOGIN'] = $loginData['userid']; 
						$_SESSION['SES_IDKAR'] = $loginData['id_kar']; 
						$_SESSION['SES_NAMA'] = $loginData['nama_karyawan']; 
						$_SESSION['SES_LEVEL'] = $loginData['level']; 
					}
/////////////////// 5. KADIV. UMUM & K3 ////////////////////////////////////////
					if($loginData['level']=="Kadiv. Umum & K3") {
						$_SESSION['SES_KADIV'] = "Kadiv. Umum & K3";
						$_SESSION['SES_LOGIN'] = $loginData['userid']; 
						$_SESSION['SES_IDKAR'] = $loginData['id_kar']; 
						$_SESSION['SES_NAMA'] = $loginData['nama_karyawan']; 
						$_SESSION['SES_LEVEL'] = $loginData['level']; 
					}
/////////////////// 6. PIMPINAN ////////////////////////////////////////
					if($loginData['level']=="Pimpinan") {
						$_SESSION['SES_PIMPINAN'] = "Pimpinan";
						$_SESSION['SES_LOGIN'] = $loginData['userid']; 
						$_SESSION['SES_IDKAR'] = $loginData['id_kar']; 
						$_SESSION['SES_NAMA'] = $loginData['nama_karyawan']; 
						$_SESSION['SES_LEVEL'] = $loginData['level']; 
					}
/////////////////// 7. KEPALA PKSPL ////////////////////////////////////////
					if($loginData['level']=="Kepala PKSPL") {
						$_SESSION['SES_KEPALA'] = "Kepala PKSPL";
						$_SESSION['SES_LOGIN'] = $loginData['userid']; 
						$_SESSION['SES_IDKAR'] = $loginData['id_kar']; 
						$_SESSION['SES_NAMA'] = $loginData['nama_karyawan']; 
						$_SESSION['SES_LEVEL'] = $loginData['level']; 
					}
/////////////////// 8. SISWA/I MAGANG ////////////////////////////////////////
					if($loginData['level']=="Magang") {
						$_SESSION['SES_MAGANG'] = "Magang";
						$_SESSION['SES_LOGIN'] = $loginData['userid']; 
						$_SESSION['SES_IDKAR'] = $loginData['id_kar']; 
						$_SESSION['SES_NAMA'] = $loginData['nama_karyawan']; 
						$_SESSION['SES_LEVEL'] = $loginData['level']; 
					}
/////////////////// 9. SUPER ADMIN ////////////////////////////////////////
					if($loginData['level']=="SuperAdmin") {
						$_SESSION['SES_SUPERADMIN'] = "SuperAdmin";
						$_SESSION['SES_LOGIN'] = $loginData['userid']; 
						$_SESSION['SES_IDKAR'] = $loginData['id_kar']; 
						$_SESSION['SES_NAMA'] = $loginData['nama_karyawan']; 
						$_SESSION['SES_LEVEL'] = $loginData['level']; 
					}
					if($loginData['level']=="") {
						$_SESSION['SES_ALL'] = "";
					}
				// Refresh
            echo "<div class='mssgBox'>";
			echo "<center><img src='img/animated_loading.gif'></center><br>";
			echo "<center><img src='img/validasi.png'></center>";
			echo "<center><font color=Green size=4><b>$txtUser</b></font></center><br>";
			echo "<center><font color=Blue size=5><b>Login Sukses</b></font>";
					echo "<meta http-equiv='refresh' content='0; url=?page=halaman-utama'>";
				}
				else {
					echo "<meta http-equiv='refresh' content='0; url=?page=halaman-utama'>";
				}
			}
		}
		# Jika ada error message ditemukan
		if (! count($message)==0 ){
		?>
            <div class="mssgBox">
			<?php 
			echo "<div><center><img src='img/warning.png' width='20%' class='imgBox'><br>
				  <h3 style='padding:8px 0px 0px 0px; margin-top:0px;'>ERROR</h3>";
				$Num=0;
				foreach ($message as $indeks=>$pesan_tampil) { 
				$Num++;
					echo "&nbsp;&nbsp;$Num. $pesan_tampil<br>";	
				} 
			include_once "settings/login.php";
			?>
            
            </div>
			<?php 
		}
	}
}
?>
 
