<?php
	//Program utk atur hak akses :
	//- Jika ada menu baru (.php) maka user yang butuh musti di tambahakan hakgroup nya kl tidak di anggap tidak berhak akses
	
	//aktifkan session
	if(!isset($_SESSION)){session_start();}
	//20160408, ditutup karena butuh nulis ke session (aslinya on) session_write_close();

	//open connection
	include ('connect-DB.php');
	$username =isset($_SESSION['f_user']) ? $_SESSION['f_user'] : "";
	$password =isset($_SESSION['f_pass']) ? $_SESSION['f_pass'] : "";
	//nama prog di baca saat memanggil page tertentu -> $nameprog =basename($_SERVER['PHP_SELF']);
	//$nameprog ='absen.php';

	//set initial nilai awal 
	$add_hakx='disabled';
	$edit_hakx='disabled';
	$del_hakx='disabled';
	$print_hakx='disabled';
	$bcadd_hakx='disabled';
	$bcdel_hakx='disabled';
	$open_hakx='disabled';

	$qstring="
	SELECT hak.* FROM apl_user 
		INNER JOIN hakgroup ON hakgroup.`level`=apl_user.`LEVEL`
		INNER JOIN hak ON hak.`id_hak`=hakgroup.`id_hak`
	WHERE upper(trim(apl_user.`user`))=upper(trim('$username')) AND upper(trim(hakgroup.`nm_file_php`))=upper(trim('$nameprog'))
	";
	$rs = mysqli_query($conn_login,$qstring);

	$_SESSION['f_open']=false;
	if (!$rs) {
		//$arr = array ('isimsg'=>'Invalid query: '.mysqli_error());
		echo mysqli_error();
	}else{
		while ($row = mysqli_fetch_array($rs,MYSQL_ASSOC)) {//loop through the retrieved values
			$open_hakx=$row['OPEN_HAK']==1		? 'true':'disabled';
			$add_hakx=$row['ADD_HAK']==1		? 'true':'disabled'; 
			$edit_hakx=$row['EDIT_HAK']==1		? 'true':'disabled';
			$del_hakx=$row['DEL_HAK']==1		? 'true':'disabled';
			$print_hakx=$row['PRINT_HAK']==1	? 'true':'disabled';
			$bcadd_hakx=$row['BCADD_HAK']==1	? 'true':'disabled';
			$bcdel_hakx=$row['BCDEL_HAK']==1	? 'true':'disabled';

			//utk cek apakah seseorang berhak buka, sementara di gunakan di toner.php
			$_SESSION['f_open']=$row['OPEN_HAK']==1		? true:false;

		}
	}
	//$wherex=$qstring;
	//include("LogCekVar.php");die();
	//echo $bcadd_hakx;
?>