<?php
if(count(get_included_files()) ==1) exit("Direct access not permitted.");
if(!$statuslogin) exit;
$mod = basename(__FILE__, '.php');
$page->tbJs($mod);
if(isset($_GET['id'])){
	$id=strip_tags(stripslashes($_GET['id']));
	$page->setJudul("Input Api User Baru");
	$nama="";
	$iduser=0;
	$namauser="";
	$idaddress="";
	$token="";
	$callback="";
	if($id>0){
		$wh="";
		$dataarr=array($id);
		if($_SESSION['profile']['level']<30){
			$wh.="and t1.iduser=? ";
			array_push($dataarr,$_SESSION['profile']['id']);
		}
		
		$page->setJudul("Edit Api User");
		$query="SELECT t1.id,t1.iduser,t1.ipaddress,t1.token,t1.status,t1.callback,
			t2.nama as namauser
			FROM tb_username_api as t1
		inner join tb_username as t2 on t1.iduser=t2.id	
		WHERE t1.id=? ".$wh;
		$rs=$db->loadAssoc($query,$dataarr);
		if(isset($rs['id'])){
			$nama=$rs['nama'];
			$iduser=$rs['iduser'];
			$namauser=$rs['namauser'];
			$idaddress=$rs['ipaddress'];
			$callback=$rs['callback'];
		}
	}
	$hasil=array("id"=>$id,"iduser"=>$iduser,"level"=>$_SESSION['profile']['level']);
	$page->addLoad("userapi.edit(".json_encode($hasil,true).")");
	?>
	<div class="group_form" id="boxnamauser" style="display: none;">
		<title>Nama User</title>
		<div class="col10">
			<input id="namauser" onkeypress="userapi.cariuser(event)" value="<?php echo $namauser;?>" />
		</div>
	</div>
	<div class="group_form">
		<title>IP Address</title>
		<div class="col10"><input id="idaddress" value="<?php echo $idaddress;?>" />
			
		</div>
	</div>
	
	<div class="group_form">
		<title>Callback</title>
		<div class="col10"><input id="callback" value="<?php echo $callback;?>" />
			
		</div>
	</div>
	<div class="group_form">
		<title> </title>
		<div class="col8">
			<div id="box_error_simpan" class="error"></div>
			<div class="box_button_bawah">
				<span class="btmerah btncancel" onclick="userapi.kembali()">Kembali</span>&nbsp;&nbsp;<span onclick="userapi.simpan()" class="bthijau btnsave">Simpan</span>
			</div>
		</div>
	</div>
	<div id="box_cari_user" style="display:none;">
		<div style="padding: 10px;">
			<div class="box_button_atas">
				Baris: <select id="jumlah_hal_user" class="slkecil" onchange="userapi.loadeuser()">
					<option value="30">30</option>
					<option value="50">50</option>
					<option value="100">100</option>
				</select> &nbsp;
				Hal: <select id="hal_ke_user" class="slkecil" onchange="userapi.loaduser()"><option value="1">1</option></select>
				&nbsp;<input placeholder="Default: Nama User" onkeypress="userapi.enteruser(event)" id="cari_user" class="in_cari" />
				&nbsp;&nbsp;<span id="btcari_user" class="btnone btncari" onclick="userapi.loadeuser()">Cari</span>
			</div>
			<div id="grid_data_user"></div>
			<div class="box_button_bawah">
				<div class="error" id="box_loader_input" align="center"></div>
				<span class="btmerah medium" onclick="userapi.batalpilihuser()">BATAL</span>
			</div>
		</div>
	</div>
	<span id="btpilihuser" stpilih="0" style="display:none;" class="bt_next" onclick="userapi.pilihdatauser(#{id},##{jumlah_tabel},##{baris_tabel},this)"></span>
	<?php
}else{
	$page->addLoad("userapi.load()");
	$page->setJudul("Master Api User");
	?>
	<div class="box_button_atas">
		Jumlah baris: <select id="jumlah_hal" class="slkecil" onchange="userapi.loade()">
			<option value="30">30</option>
			<option value="50">50</option>
			<option value="100">100</option>
		</select> &nbsp;
		Hal: <select id="hal_ke" class="slkecil" onchange="userapi.load()"><option value="1">1</option></select>
		&nbsp;<input placeholder="Default: Ip address" onkeypress="userapi.enter(event)" id="cari" class="in_cari" />
		&nbsp;&nbsp;<span id="btcari" class="btnone btncari" onclick="userapi.loade()">Cari</span>
		&nbsp;&nbsp;<span class="btnone btncanggih" onclick="userapi.caricanggih()">Cari Detail</span>
	</div>
	<div id="grid_userapi"></div>
	<div class="box_button_bawah">
		<span onclick="userapi.buat(0)" class="bthijau btninput">Input User Api Baru</span>
	</div>
	<div id="btedit" style="display:none;">
		<span class="icon_del" onclick="userapi.hapus(#{id})"></span>
		<span class="icon_edit" onclick="userapi.buat(#{id})"></span>
	</div>
	<span onclick="userapi.setstatus(#{id},##{jumlah_tabel},##{baris_tabel},this)" id="btstatus" class="#(#{status}==1)?'mini_ok':'mini_dis'#"></span>
	<?php
}
?>
