<?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/edit Menu");
	$page->addPlugin("upload");
	
	$nama="";
	$gambar="noicon.png";
	$tautan="";
	$idjenis=0;
	$jenistautan="";
	$level=10;
	$idicon=0;
	$urutan=0;
	$tautanurl="";
	$idkonten=0;
	$namalama="";
	$namabaru="";
	$folder="";
	$tautankonten="";
	
	if($id>0){
		
		$page->setJudul("Edit Menu");
		$query="SELECT t1.`id`,
					t1.`idjenis`,
					t1.`menu`,
					t1.`jenistautan`,
					t1.`tautan`,
					t1.`urutan`,
					t1.`level`,
					t1.`idicon`,
					t1.`icon`,
					t1.`status`,
					t1.`level_key`,
					t1.`key`,
					t1.`jumlahsub`,
					t1.`jumlah_akses`,
					t1.`jumlah_akses_sub`,
					if(t2.nama_awal is null,'PILIH FILE ICON MENU',t2.nama_awal) as nama_awal,
					if(t2.nama_baru is null,'',t2.nama_baru) as nama_baru,
					if(t2.folder is null,'',t2.folder) as folder 
				FROM tb_menu as t1
				left join tb_dokumen as t2 on t1.idicon=t2.id
				WHERE t1.id=?";
		$rs=$db->loadAssoc($query,array($id));
		if(isset($rs['id'])){
			$nama=$rs['menu'];
			$gambar=$rs['icon'];
			$tautan=$rs['tautan'];
			$level=$rs['level'];
			$idicon=$rs['idicon'];
			$idjenis=$rs['idjenis'];
			$urutan=$rs['urutan'];
			$jenistautan=$rs['jenistautan'];
			if($jenistautan=="url") $tautanurl=$tautan;
			
			$namalama=$rs['nama_awal'];
			$namabaru=$rs['nama_baru'];
			$folder=$rs['folder'];
			if($jenistautan=="konten") {
				$idkonten=$tautan;
				
				$qr="select judul from tb_konten where id=? ";
				$rskonten=$db->loadAssoc($qr,array($idkonten));
				if(isset($rskonten['judul'])) $tautankonten=$rskonten['judul'];
			}
		}
		
	}
	$hasil=array("id"=>$id,
		"level"=>$level,
		"idjenis"=>$idjenis,
		"idicon"=>$idicon,
		"jenistautan"=>$jenistautan,
		"tautan"=>$tautan,
		"idkonten"=>$idkonten,
		"namalama"=>$namalama,
		"namabaru"=>$namabaru,
		"folder"=>$folder
	);
	$page->addLoad("managmenu.edit(".json_encode($hasil,true).")");
	?>
	<div class="box_main_konten">
		<h3>DETAIL MENU</h3>
		<div class="group_form">
			<title>Nama Menu</title>
			<div class="col10"><input id="nama" value="<?php echo $nama;?>" />
				
			</div>
		</div>
		<div class="group_form">
			<title>Level</title>
			<div class="col10">
				<select id="sl_level" onchange="managmenu.gettautan()">
					<option value="0">Semua Level</option>
					<?php
					$qr="select * from tb_level order by id asc";
					$rs=$db->getObj($qr);
					foreach ($rs as $obj) {
						?>
						<option value="<?php echo $obj->id;?>"><?php echo $obj->nama;?></option>
						<?php
					}
					?>
				</select>
			</div>
		</div>
		<div class="group_form">
			<title>Kategori Menu</title>
			<div class="col10">
				<select id="sl_kategorimenu" onchange="managmenu.katch()">
					<?php
					$qr="select * from tb_menu_jenis where id>0 order by id asc";
					$rs=$db->getObj($qr);
					foreach ($rs as $obj) {
						?>
						<option value="<?php echo $obj->id;?>"><?php echo $obj->nama;?></option>
						<?php
					}
					?>
				</select>
			</div>
		</div>
		<div class="group_form">
			<title>Jenis Tautan</title>
			<div class="col10">
				<select id="sl_jenistautan" onchange="managmenu.jenistautanch()"></select>
			</div>
		</div>
		<div class="group_form" id="boxsltautan" style="display: none;">
			<title>Tautan</title>
			<div class="col10">
				<select id="sl_tautan"></select>
			</div>
		</div>
		<div class="group_form" id="boxtautanurl" style="display: none;">
			<title>Tautan URL</title>
			<div class="col10">
				<input id="tautanurl" value="<?php echo $tautanurl;?>" />
			</div>
		</div>
		<div class="group_form" id="boxtautankonten" style="display: none;">
			<title>Tautan Konten</title>
			<div class="col10">
				<input id="tautankonten" disabled="true" value="<?php echo $tautankonten;?>" />
				<div style="margin-top: 5px" >
					
					<span class="medium bthijau" onclick="managmenu.carikonten(0)">Pilih Konten</span>
				</div>
			</div>
		</div>
		<div class="group_form">
			<title>Icon</title>
			<div class="col10">
				<div id="upload_icon"></div>
			</div>
		</div>
		<div style="clear: both;"></div>
	</div>
	<div class="box_button_bawah">
		<div id="loader_simpan_menu" class="error"></div>
		<div>
			<span class="btmerah" onclick="managmenu.kembali()">Kembali</span>&nbsp; 
			<span onclick="managmenu.simpan()" class="bthijau">Simpan</span>
		</div>
		
	</div>
	<?php
}else{
	$page->setJudul("Menu management");
	$page->addLoad("managmenu.load()");
	?>
	<div class="box_button_atas">
		Jumlah baris: <select id="jumlah_hal" class="slkecil" onchange="managmenu.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="managmenu.load()"><option value="1">1</option></select>
		&nbsp;<input placeholder="Default: Nama Menu" onkeypress="managmenu.enter(event)" id="cari" class="in_cari" />
		&nbsp;&nbsp;<span id="btcari" class="btnone btncari" onclick="managmenu.loade()">Cari</span>
		&nbsp;&nbsp;<span class="btnone btncanggih" onclick="managmenu.caricanggih()">Cari Detail</span>
	</div>
	<div id="grid_managmenu"></div>
	<div id="loader_data_menu" class="error"></div>
	<div class="box_button_bawah">
		<span onclick="managmenu.buat(0)" class="bthijau btninput">Tambah Menu</span>
	</div>
	<span id="bttautan" style="width:60px;display:none">#{tautan}</span>
	<span id="btstatus" class="#(#{status}==1)?'mini_ok':'mini_dis'#" style="display:none;cursor:pointer;" onclick="managmenu.setstatus(#{id},##{jumlah_tabel},##{baris_tabel},this)"></span>
	
	<div id="box_urutan" style="display:none;padding:10px">
		<div align="center">
			<input id="urutan_sub" />
			<div class="box_button_bawah" align="center">
				<span class="btmerah btnclose" id="bt_tutup_urutan">Tutup</span> <span class="bthijau btnsave" id="bt_simpan_urutan">Simpan</span>
			</div>
		</div>
	</div>
	<span id="bturutan" class="bthijau medium" style="display:none;cursor:pointer" onclick="managmenu.seturutan(#{id},#{urutan})">#{urutan}</span>
	
	<div id="btedit" style="display:none;">
		<span class="icon_del" onclick="managmenu.hapus(#{id})"></span>
		<span class="icon_edit" onclick="managmenu.buat(#{id})"></span>
	</div>
	<span id="btsub" class="btmed" style="display:none;" onclick="managmenu.bukasub(#{id},##{jumlah_tabel},##{baris_tabel},this)">#{jumlahsub}</span>
	
	<span id="btstlevelsub" style="display:none;">#(#{idlevel}==30)?'Super Admin':(#{idlevel}==20)?'Induk':'Unit'#</span>
	<span id="bturutansub" style="display:none;cursor:pointer" onclick="managmenu.seturutasub(#{id},##{jumlah_tabel},##{baris_tabel},this)">#{urutan}</span>
	<span id="btlevelsub" style="display:none">#{namalevel}</span>
	<span id="bttautansub" style="width:60px;display:none">#{tautan}</span>
	<span id="btaksessublevel" class="bthijau medium" style="display:none;cursor:pointer;" onclick="managmenu.loadaksessub(#{id},##{jumlah_tabel},##{baris_tabel},this)">#{jumlah_akses_sub}</span>
	<span id="btstatussub" class="#(#{status}==1)?'mini_ok':'mini_dis'#" style="display:none;cursor:pointer;" onclick="managmenu.statussub(#{id},##{jumlah_tabel},##{baris_tabel},this)"></span>
	<span id="btlevelsubstatus" style="display:none;" class="#(#{status}>0)?'mini_ok':'mini_dis'#" onclick="managmenu.setaksessub(#{id},##{jumlah_tabel},##{baris_tabel},this)"></span>
	
	<div id="bteditsub" style="display:none;">
		<span class="icon_del" onclick="managmenu.hapussub(#{id},##{jumlah_tabel},##{baris_tabel},this)"></span>
		<span class="icon_edit" onclick="managmenu.editdsub(#{id},##{jumlah_tabel},##{baris_tabel},this)"></span>
	</div>
	<div id="box_edit_sub" style="display: none;padding: 10px;">
		<div class="group_form">
			<title>Nama Sub Menu</title>
			<div class="col10"><input id="nama"/>
				
			</div>
		</div>
		<div class="group_form">
			<title>Urutan</title>
			<div class="col10"><input id="urutan"/>
				
			</div>
		</div>
		<div class="group_form">
			<title>Kategori Menu</title>
			<div class="col10">
				<select id="sl_kategorimenu" disabled="true" onchange="managmenu.katch()">
					<?php
					$qr="select * from tb_menu_jenis where id>0 order by id asc";
					$rs=$db->getObj($qr);
					foreach ($rs as $obj) {
						?>
						<option value="<?php echo $obj->id;?>"><?php echo $obj->nama;?></option>
						<?php
					}
					?>
				</select>
			</div>
		</div>
		<div class="group_form">
			<title>Level</title>
			<div class="col10">
				<select id="sl_level" onchange="managmenu.gettautan()">
					<option value="0">NONE</option>
					<?php
					$qr="select * from tb_level order by id asc";
					$rs=$db->getObj($qr);
					foreach ($rs as $obj) {
						?>
						<option value="<?php echo $obj->id;?>"><?php echo $obj->nama;?></option>
						<?php
					}
					?>
				</select>
			</div>
		</div>
		<div class="group_form">
			<title>Jenis Tautan</title>
			<div class="col10">
				<select id="sl_jenistautan" onchange="managmenu.jenistautanch()"></select>
			</div>
		</div>
		<div class="group_form" id="boxsltautan" style="display: none;">
			<title>Tautan</title>
			<div class="col10">
				<select id="sl_tautan"></select>
			</div>
		</div>
		<div class="group_form" id="boxtautanurl" style="display: none;">
			<title>Tautan URL</title>
			<div class="col10">
				<input id="tautanurl"/>
			</div>
		</div>
		<div class="group_form" id="boxtautankonten" style="display: none;">
			<title>Tautan Konten</title>
			<div class="col10">
				<input id="tautankonten" disabled="true"/>
				<div style="margin-top: 5px" >
					
					<span class="medium bthijau" onclick="managmenu.carikonten(1)">Pilih Konten</span>
				</div>
			</div>
		</div>
		
		<div class="group_form">
			<title>&nbsp;</title>
			<div class="col10">
				<div class="box_button_bawah" style="float:left">
					<div class="err" id="box_loader_submenu"></div>
					<span class="btmerah btncancel" id="btbatalsub" onclick="managmenu.batalsubmenu()">Kembali</span> <span id="btsimpansub" onclick="managmenu.simpansubmenu()" class="bthijau btnsave">Simpan</span>
				</div>
			</div>
		</div>
		
		<div style="clear: both;margin-bottom: 10px;"></div>
	</div>
	<span id="btakses" style="display: none" class="btmed" onclick="managmenu.bukamenuakses(#{id},##{jumlah_tabel},##{baris_tabel},this)">#{jumlah_akses}</span>
	<span id="btstatusmenu" style="display: none;" class="#(#{status}==1)?'mini_ok':'mini_dis'#" onclick="managmenu.setaksesmenu(#{id},##{jumlah_tabel},##{baris_tabel})"></span>
	<span id="btaksessub" style="display: none" class="bthijau medium" onclick="managmenu.bukasubakses(#{id},##{jumlah_tabel},##{baris_tabel},this)">#{jumlah_akses}</span>
	<span id="btstatussubmenu" style="display: none;" class="#(#{status}==1)?'mini_ok':'mini_dis'#" onclick="managmenu.setaksessubmenu(#{id},##{jumlah_tabel},##{baris_tabel})"></span>
	<span id="btaksessubsub" style="display: none" class="bthijau medium" onclick="managmenu.bukasubaksessub(#{id},##{jumlah_tabel},##{baris_tabel},this)">#{jumlah_akses_sub}</span>
	<span id="btstatussubmenusub" style="display: none;" class="#(#{status}>0)?'mini_ok':'mini_dis'#" onclick="managmenu.setaksessubmenusub(#{id},##{jumlah_tabel},##{baris_tabel},this)"></span>
	<span id="btjumlahsubsub" style="display: none" class="bthijau medium" onclick="managmenu.bukasubsub(#{id},##{jumlah_tabel},##{baris_tabel},this)">#{jumlah_sub_sub}</span>
	<div id="bteditsubsub" style="display:none;">
		<span class="icon_del" onclick="managmenu.hapussubsub(#{id},##{jumlah_tabel},##{baris_tabel},this)"></span>
		<span class="icon_edit" onclick="managmenu.editdsubsub(#{id},##{jumlah_tabel},##{baris_tabel},this)"></span>
	</div>
	<span id="btstatussubsub" style="display: none;" class="#(#{status}==1)?'mini_ok':'mini_dis'#" onclick="managmenu.setstatussubsubmenu(#{id},##{jumlah_tabel},##{baris_tabel},this)"></span>
	<span id="bturutansubsub" style="display:none;cursor:pointer" onclick="managmenu.seturutasubsub(#{id},##{jumlah_tabel},##{baris_tabel},this)">#{urutan}</span>
	<?php
}
?>
<div id="box_cari_konten" class="boxwin boxwinhd">
	<div style="padding: 10px;">
		<div class="box_button_atas">
			Baris: <select id="jumlah_hal_konten" class="slkecil" onchange="managmenu.loadekonten()">
				<option value="30">30</option>
				<option value="50">50</option>
				<option value="100">100</option>
			</select> &nbsp;
			Hal: <select id="hal_ke_konten" class="slkecil" onchange="managmenu.loadkonten()"><option value="1">1</option></select>
			&nbsp;<input placeholder="Default: Nama Konten" onkeypress="managmenu.enterkonten(event)" id="cari_konten" class="in_cari" />
			&nbsp;&nbsp;<span id="btcari_konten" class="btnone btncari" onclick="managmenu.loadekonten()">Cari</span>
		</div>
		<div id="grid_data_konten"></div>
		<div class="box_button_bawah">
			<div class="err" id="box_loader_konten"></div>
			<span class="btmerah" onclick="managmenu.batalpilihkonten()">BATAL</span>&nbsp;&nbsp;
		</div>
	</div>
</div>
<span id="btpilihkonten" stpilih="0" style="display:none;" class="bt_next" onclick="managmenu.pilihdatakonten(#{id},##{jumlah_tabel},##{baris_tabel},this)"></span>
