<?php
if(count(get_included_files()) ==1) exit("Direct access not permitted.");
if(!$statuslogin) exit;
$mod = basename(__FILE__, '.php');
$page->tbJs($mod);
$page->addPlugin("upload");
if(isset($_GET['id'])){
	$id=strip_tags(stripslashes($_GET['id']));
	$page->setJudul("Input Album Gallery");
	$nama="";
	$keterangan="";
	$datafile=array();
	$idkategori=0;
	$iddokumen=0;
	$namaawal="PILIH FILE UNTUK UPLOAD FILE GALLERY";
	$namabaru="";
	$folder="";
	if($id>0){
		$page->setJudul("Edit Album Gallery");
		$query="select t1.`id`,
				t1.`tanggal`,
				t1.`idkategori`,
				t1.`nama`,
				t1.`keterangan`,
				t1.`idgambar`,
				t1.`status`,
				t2.folder,
				t2.nama_awal,
				t2.nama_baru
			from tb_album as t1
			inner join tb_dokumen as t2 on t1.idgambar=t2.id
			WHERE t1.id=?";
		$rs=$db->loadAssoc($query,array($id));
		if(isset($rs['id'])){
			$nama=$rs['nama'];
			$keterangan=$rs['keterangan'];
			$idkategori=$rs['idkategori'];
			$iddokumen=$rs['idgambar'];
			$namaawal=$rs['nama_awal'];
			$namabaru=$rs['nama_baru'];
			$folder=$rs['folder'];
		}else{
			exit();
		}
		
	}
	$datafile=array(
		"id"=>$id,
		"nama_awal"=>$namaawal,
		"nama_baru"=>$namabaru,
		"idgambar"=>$iddokumen,
		"idkategori"=>$idkategori,
		"folder"=>$folder
	);
	$page->addLoad("managgallery.edit(".json_encode($datafile).")");
	?>
	<div class="box_main_konten">
		<h3>DETAIL GALLERY</h3>
		<div class="group_form">
			<title>Kategori</title>
			<div class="col10">
				<select id="sl_kategori">
				<?php
				$qr="select * from tb_album_kategori where status=1 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>Nama Gallery</title>
			<div class="col10"><input id="nama" value="<?php echo $nama;?>"/>
				
			</div>
		</div>
		<div class="group_form">
			<title>Keterangan</title>
			<div class="col10"><input id="keterangan" value="<?php echo $keterangan;?>"/>
				
			</div>
		</div>
		<div class="group_form">
			<title>Upload</title>
			<div class="col10">
				<div id="box_upload_img"></div>
			</div>
		</div>
		<div style="clear: both;"></div>
	</div>
	<div class="box_button_bawah">
		<div id="loader_gallery" class="error"></div>
		<span class="btmerah btncancel" onclick="managgallery.kembali()">Kembali</span>&nbsp;&nbsp;<span onclick="managgallery.simpan()" class="bthijau btnsave">Simpan</span>
	</div>
	
	<?php
}else{
	$page->addLoad("managgallery.load()");
	$page->setJudul("Daftar File Gallery");
	?>
	<div class="box_button_atas">
		Jumlah baris: <select id="jumlah_hal" class="slkecil" onchange="managgallery.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="managgallery.load()"><option value="1">1</option></select>
		&nbsp;<input placeholder="Default: Nama Gallery" onkeypress="managgallery.enter(event)" id="cari" class="in_cari" />
		&nbsp;&nbsp;<span id="btcari" class="btnone btncari" onclick="managgallery.loade()">Cari</span>
		&nbsp;&nbsp;<span class="btnone btncanggih" onclick="managgallery.caricanggih()">Cari Detail</span>
	</div>
	<div id="grid_managgallery"></div>
	<div id="loader_datagallery" class="error"></div>
	<div class="box_button_bawah">
		<span onclick="managgallery.buat(0)" class="bthijau btninput">Tambah File Gallery</span>
	</div>
	<div id="btedit" style="display:none;">
		<span class="icon_del" onclick="managgallery.hapusdokumen(#{id},##{jumlah_tabel},##{baris_tabel},this)"></span>
		<span class="icon_edit" onclick="managgallery.buat(#{id})"></span>
	</div>
	<span id="btstatusfile" class="#(#{status}==1)?'mini_ok':'mini_dis'#" style="display:none;" onclick="managgallery.setstatus(#{id},##{jumlah_tabel},##{baris_tabel},this)"></span>
	<div id="btdetailgallery" style="display: none;">
		<div>#{tanggal}</div>
		<div><b>#{nama}</b></div>
		<div style="margin-top: 3px;">Kategori</div>
		<div><b>#{kategori}</b></div>
	</div>
	<?php
}
?>
