<?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 Banner Iklan Baru");
	$judul="";
	$tautan="";
	$keterangan="";
	$idgambar=0;
	$namaawal="PILIH FILE UNTUK UPLOAD GAMBAR";
	$namabaru="";
	$folder="";
	if($id>0){
		
		$page->setJudul("Edit Banner Iklan");
		$query="SELECT t1.`id`,
					t1.`judul`,
					t1.`idgambar`,
					t1.`keterangan`,
					t1.`tautan`,
					t1.`urutan`,
					t1.`status`,
					if(t2.nama_awal is null,'PILIH FILE UNTUK UPLOAD GAMBAR',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_linkterkait as t1 
				left join tb_dokumen as t2 on t1.idgambar=t2.id
				WHERE t1.id=? and jenis=2";
		$rs=$db->loadAssoc($query,array($id));
		if(isset($rs['id'])){
			$judul=$rs['judul'];
			$tautan=$rs['tautan'];
			$keterangan=$rs['keterangan'];
			$idgambar=$rs['idgambar'];
			$namaawal=$rs['nama_awal'];
			$namabaru=$rs['nama_baru'];
			$folder=$rs['folder'];
		}
	}
	$datakonten=array("id"=>$id,"idgambar"=>$idgambar,"nama_awal"=>$namaawal,"nama_baru"=>$namabaru,"folder"=>$folder);
	$page->addLoad("banneriklan.edit(".json_encode($datakonten,true).")");
	?>
	<div class="box_main_konten">
		<div class="group_form">
			<title>Judul Banner</title>
			<div class="col10"><input id="judul" value="<?php echo $judul;?>" />
				
			</div>
		</div>
		<div class="group_form">
			<title>Tautan</title>
			<div class="col10"><input id="tautan" value="<?php echo $tautan;?>" />
				
			</div>
		</div>
		
		<div class="group_form">
			<title>Gambar</title>
			<div class="col10"><div id="box_gambar_banner"></div>
				
			</div>
		</div>
		<div class="group_form">
			<title>Keterangan</title>
			<div class="col10">
				<textarea id="keterangan"><?php echo $keterangan;?></textarea>
			</div>
		</div>
		<div style="clear: both;"></div>
	</div>
	<div class="box_button_bawah">
		<div id="loader_banneriklan" class="error"></div>
		<span class="btmerah btncancel" onclick="banneriklan.kembali()">Kembali</span>&nbsp;&nbsp;<span onclick="banneriklan.simpan()" class="bthijau btnsave">Simpan</span>
	</div>
	<div id="box_preview" style="display: none">
		<img id="img_banner" style="width: 100%" />
	</div>
	<?php
}else{
	$page->addLoad("banneriklan.load()");
	$page->setJudul("Manajemen Banner Iklan");
	?>
	<div class="box_button_atas">
		Jumlah baris: <select id="jumlah_hal" class="slkecil" onchange="banneriklan.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="banneriklan.load()"><option value="1">1</option></select>
		&nbsp;<input placeholder="Default: Judul Banner" onkeypress="banneriklan.enter(event)" id="cari" class="in_cari" />
		&nbsp;&nbsp;<span id="btcari" class="btnone btncari" onclick="banneriklan.loade()">Cari</span>
		&nbsp;&nbsp;<span class="btnone btncanggih" onclick="banneriklan.caricanggih()">Cari Detail</span>
	</div>
	<div id="grid_banneriklan"></div>
	<div class="box_button_bawah">
		<span onclick="banneriklan.buat(0)" class="bthijau btninput">Tambah Banner Iklan Baru</span>
	</div>
	<div id="btedit" style="display:none;">
		<span class="icon_del" onclick="banneriklan.hapus(#{id})"></span>
		<span class="icon_edit" onclick="banneriklan.buat(#{id})"></span>
	</div>
	<span id="bturutan" class="btmed" style="display: none;" onclick="banneriklan.ubahurutan(#{id},#{urutan})">#{urutan}</span>
	<div id="box_urutan" style="display: none;">
		<div style="padding: 10px;">
			<div class="group_form">
				<title>Urutan</title>
				<div class="col10"><input id="urutan" style="width: 80px;" />
				</div>
			</div>
			<div style="clear: both;"></div>
			<div class="box_button_bawah" align="center" style="margin-top: 20px;">
				<span class="btmerah" onclick="banneriklan.batalurutan()">Batal</span>&nbsp;&nbsp;<span onclick="banneriklan.simpanurutan()" class="bthijau">Simpan</span>
			</div>
		</div>
	</div>
	<span id="btstatus" style="display: none" class="#(#{status}==1)?'mini_ok':'mini_dis'#" onclick="banneriklan.setstatus(#{id},##{jumlah_tabel},##{baris_tabel},this)"></span>
	<?php
}
?>
