<?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'])){
	$page->addPlugin("upload");
	
	$id=strip_tags(stripslashes($_GET['id']));
	$page->setJudul("Input File Download");
	$nama="";
	$keterangan="";
	$datafile=array();
	$idkategori=0;
	$iddokumen=0;
	$namaawal="";
	$namabaru="";
	if($id>0){
		$page->setJudul("Edit File Download");
		$query="SELECT t1.`id`,
				t1.`tanggal`,
				t1.`iddokumen`,
				t1.`idkategori`,
				t1.`nama`,
				t1.`keterangan`,
				t1.`jumlah_download`,
				t1.`status`,t2.nama_baru,
				t2.nama_awal FROM tb_download as t1
			inner join tb_dokumen as t2 on t1.iddokumen=t2.id
			WHERE t1.id=?";
		$rs=$db->loadAssoc($query,array($id));
		if(isset($rs['id'])){
			$nama=$rs['nama'];
			$keterangan=$rs['keterangan'];
			$iddokumen=$rs['iddokumen'];
			$idkategori=$rs['idkategori'];
			$namaawal=$rs['nama_awal'];
			$namabaru=$rs['nama_baru'];
			
		}
	}
	$datafile=array(
		"id"=>$id,
		"nama_awal"=>$namaawal,
		"iddokumen"=>$iddokumen,
		"idkategori"=>$idkategori);
	$page->addLoad("managdownload.edit(".json_encode($datafile,true).")");
	?>
	<div class="box_main_konten">
		<h3>DETAIL FILE KONTEN</h3>
		<div class="group_form">
			<title>Kategori</title>
			<div class="col10">
				<select id="sl_kategori">
				<?php
				$qr="select * from tb_download_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->kategori;?></option>
					<?php
				}
				?>
				</select>
			</div>
		</div>
		<div class="group_form">
			<title>Judul File</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_simpan_download" class="error"></div>
		<span class="btmerah btncancel" onclick="managdownload.kembali()">Kembali</span>&nbsp;&nbsp;<span onclick="managdownload.simpan()" class="bthijau btnsave">Simpan</span>
	</div>
	<?php
}else{
	$page->addLoad("managdownload.load()");
	$page->setJudul("Daftar File Download");
	?>
	<div class="box_button_atas">
		Jumlah baris: <select id="jumlah_hal" class="slkecil" onchange="managdownload.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="managdownload.load()"><option value="1">1</option></select>
		&nbsp;<input placeholder="Default: Nama Kategori" onkeypress="managdownload.enter(event)" id="cari" class="in_cari" />
		&nbsp;&nbsp;<span id="btcari" class="btnone btncari" onclick="managdownload.loade()">Cari</span>
		&nbsp;&nbsp;<span class="btnone btncanggih" onclick="managdownload.caricanggih()">Cari Detail</span>
	</div>
	<div id="grid_managdownload"></div>
	<div id="loader_datadownload" class="error"></div>
	<div class="box_button_bawah">
		<span onclick="managdownload.buat(0)" class="bthijau btninput">Tambah File Download</span>
	</div>
	<div id="btedit" style="display:none;">
		<span class="icon_del" onclick="managdownload.hapusdokumen(#{id},##{jumlah_tabel},##{baris_tabel},this)"></span>
		<span class="icon_edit" onclick="managdownload.buat(#{id})"></span>
	</div>
	<span id="btstatusfile" class="#(#{status}==1)?'mini_ok':'mini_dis'#" style="display:none;" onclick="managdownload.setstatus(#{id},##{jumlah_tabel},##{baris_tabel},this)"></span>
	<div id="btdetaildownload" style="display: none">
		<div>#{tanggal}</div>
		<div><b>#{nama}</b></div>
		<div style="margin-top: 3px;">Kategori</div>
		<div>#{kategori}</div>
	</div>
	<?php
}
?>
