<?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 Konten Baru");
	$page->addPlugin("upload");
	$page->addPlugin("imagemanager");
	$judul="";
	$sekarang=date('Y-m-d H:m:i');
	$arrtg=explode(" ", $sekarang);
	$tanggal=$db->sql_date($arrtg[0]);
	$jam=$arrtg[1];
	$keterangan="";
	$idkategori=0;
	$idgambar=0;
	$namaawal="PILIH FILE UNTUK UPLOAD BANNER BERITA";
	$namabaru="";
	$folder="";
	$idlevel=0;
	$idlsp=0;
	$namalsp="KLIK UNTUK PILIH LSP";
	if($id>0){
		$page->setJudul("Edit Konten");
		
		$wh="";
		$datapush=array($id);
		if($_SESSION['profile']['level']<25){
			$wh.="and t1.idlsp=? ";
			array_push($datapush,$_SESSION['profile']['idlsp']);			
		}
		
		$query="SELECT t1.`id`,
				t1.`tanggal`,
				t1.`iduser`,
				t1.`idkategori`,
				t1.`judul`,
				t1.`konten`,
				t1.`status`,
				t1.`utama`,
				t1.`dibaca`,
				t1.`idgambar`,
				if(t2.nama_awal is null,'PILIH FILE UNTUK UPLOAD BANNER BERITA',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_konten as t1
			left join tb_dokumen as t2 on t1.idgambar=t2.id
			WHERE t1.id=? ".$wh;
		$rs=$db->loadAssoc($query,$datapush);
		if(isset($rs['id'])){
			$judul=$rs['judul'];
			$arrtg=explode(" ", $rs['tanggal']);
			if(sizeof($arrtg)==2){
				$tanggal=$db->sql_date($arrtg[0]);
				$jam=$arrtg[1];
			}
			$keterangan=$rs['konten'];
			$idkategori=$rs['idkategori'];
			$idgambar=$rs['idgambar'];
			$namaawal=$rs['nama_awal'];
			$namabaru=$rs['nama_baru'];
			$folder=$rs['folder'];
		}
	}
	$datakonten=array("id"=>$id,
		"idkategori"=>$idkategori,
		"idgambar"=>$idgambar,"nama_awal"=>$namaawal,
		"nama_baru"=>$namabaru,"folder"=>$folder);
	$page->addLoad("managkonten.edit(".json_encode($datakonten,true).")");
	?>
	<div class="box_main_konten">
		<h3>DATA KONTEN</h3>
		<div class="group_form">
			<title>Kategori</title>
			<div class="col10">
				<select id="sl_kategori">
				<?php
				$qr="select * from tb_konten_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>Tanggal</title>
			<div class="col10"><input style="width: 110px" id="tanggal" value="<?php echo $tanggal;?>" />
				
			</div>
		</div>
		<div class="group_form">
			<title>Jam</title>
			<div class="col10"><input style="width: 110px" id="jam" value="<?php echo $jam;?>" />
				
			</div>
		</div>
		<div class="group_form">
			<title>Judul</title>
			<div class="col10"><input id="judul" value="<?php echo $judul;?>" />
				
			</div>
		</div>
	
		<div class="group_form">
			<title>Gambar Konten</title>
			<div class="col10">
				<div id="box_upload_icon"></div>
			</div>
		</div>
		
		<div style="clear: both;"></div>
	</div>
	<div class="box_main_konten">
		<div style="clear: both;"></div>
		<h3>DETAIL KONTEN</h3>
		<div>
			<textarea id="keterangan"><?php echo $keterangan;?></textarea>
		</div>
	</div>
	<div class="box_button_bawah" style="border-top: 1px solid #000000;padding-top: 15px;">
		<div id="loader_simpan_konten" class="error"></div>
		<span class="btmerah btncancel" onclick="managkonten.kembali()">Kembali</span>&nbsp;&nbsp;<span onclick="managkonten.simpan()" class="bthijau btnsave">Simpan</span>
	</div>
	<div style="clear: both"></div>
	
	<?php
}else{
	$page->addLoad("managkonten.load()");
	$page->setJudul("Master Data Informasi/Konten");
	?>
	<div class="box_button_atas">
		Jumlah baris: <select id="jumlah_hal" class="slkecil" onchange="managkonten.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="managkonten.load()"><option value="1">1</option></select>
		&nbsp;Kategori: <select id="sl_kategori" class="slkecil" onchange="managkonten.load()">
			<option value="0">Semua Kategori</option>
			<?php
			$query="select * from tb_konten_kategori order by id asc";
			$rsj=$db->getObj($query);
			foreach ($rsj as $obj) {
				?>
				<option value="<?php echo $obj->id;?>"><?php echo $obj->nama;?></option>
				<?php
			}
			?>
		</select>
		&nbsp;<input placeholder="Default: Judul" onkeypress="managkonten.enter(event)" id="cari" class="in_cari" />
		&nbsp;&nbsp;<span id="btcari" class="btnone btncari" onclick="managkonten.loade()">Cari</span>
		&nbsp;&nbsp;<span class="btnone btncanggih" onclick="managkonten.caricanggih()">Cari Detail</span>
	</div>
	<div id="grid_managkonten"></div>
	<div id="loader_datakonten" class="error"></div>
	<div class="box_button_bawah">
		<span onclick="managkonten.buat(0)" class="bthijau btninput">Input Informasi/Konten Baru</span>
	</div>
	<div id="btedit" style="display:none;">
		<span class="icon_del" onclick="managkonten.hapus(#{id})"></span>
		<span class="icon_edit" onclick="managkonten.buat(#{id})"></span>
	</div>
	<span id="btstatus" class="#(#{status}==1)?'mini_ok':'mini_dis'#" style="display:none;" onclick="managkonten.setstatus(#{id},#{status},this)"></span>
	<span id="btutama" class="#(#{utama}==1)?'mini_ok':'mini_dis'#" style="display:none;" onclick="managkonten.setutama(#{id},##{jumlah_tabel},##{baris_tabel},this)"></span>
	<div id="btdetailkonten" style="display: none;">
		<div>#{tanggal}</div>
		<div><b>#{judul}</b></div>
		<div style="margin-top: 3px">Kategori</div>
		<div><b>#{kategori}</b></div>
	</div>
	<?php
}
?>
