<title>Edit Artikel</title>
<div id="pagetitle">EDIT ARTIKEL</div>
<div id="batascontent" class="clearfix">
	<form action="?m=konten_update" method="post" enctype="multipart/form-data">
		<?php 
			$db = mysqli_query($koneksi, "SELECT * FROM cmas_konten WHERE konten_id='$_GET[id]'");
			$dt = mysqli_fetch_array($db);
		?>
		<input name="konten_id" type="hidden" value="<?php echo $dt['konten_id']; ?>">
		
		<div id="wrapgsetting" class="clearfix">
			<div id="gsettingleft">
				<div id="gsettingtitles">GENERAL</div>
				<div id="gsetting" class="clearfix">
					<div id="gsettinglabel">Judul</div>
					<div id="gsettingedit">
						<input name="konten_judul" type="text" value="<?php echo $dt['konten_judul']; ?>">
					</div>
				</div>
				<div id="gsetting" class="clearfix">
					<div id="gsettinglabel">Deskripsi Pendek</div>
					<div id="gsettingedit">
						<textarea name="konten_sdesc" type="text" value="<?php echo $dt['konten_sdesc']; ?>"><?php echo $dt['konten_sdesc']; ?></textarea>
					</div>
				</div>
				<div id="gsetting" class="clearfix">
					<div id="gsettinglabel">Deskripsi Selengkapnya</div>
					<div id="gsettingedit">
						<textarea name="konten_desc" id="content"><?php echo $dt['konten_desc']; ?></textarea>
						<script type="text/javascript">
							CKEDITOR_BASEPATH = 'ckeditor';
							var editor = CKEDITOR.replace('content', {});
						</script>
					</div>
				</div>
				<div id="gsetting" class="clearfix">
					<div id="gsettinglabel">Meta Title</div>
					<div id="gsettingedit">
						<input name="konten_metatitle" type="text" value="<?php echo $dt['konten_metatitle']; ?>">
					</div>
				</div>
				<div id="gsetting" class="clearfix">
					<div id="gsettinglabel">Meta Description</div>
					<div id="gsettingedit">
						<textarea name="konten_metadesc" type="text" value="<?php echo $dt['konten_metadesc']; ?>"><?php echo $dt['konten_metadesc']; ?></textarea>
					</div>
				</div>
				<div id="gsetting" class="clearfix">
					<div id="gsettinglabel">Meta Keywords</div>
					<div id="gsettingedit">
						<textarea name="konten_metakey" type="text" value="<?php echo $dt['konten_metakey']; ?>"><?php echo $dt['konten_metakey']; ?></textarea>
					</div>
				</div>
			</div>
			
			<div id="gsettingrite">
				<div id="gsettingtitles">ATTRIBUTE</div>
				<div id="gsetting" class="clearfix">
					<div id="gsettinglabel">Status</div>
					<div id="gsettingedit">
						<select name="konten_status" required>
							<option value="<?php echo $dt['konten_status']; ?>"><?php echo $dt['konten_status']; ?></option>
							<?php $stdb=mysqli_query($koneksi, "SELECT * FROM cmas_status ORDER BY status_id ASC"); while($stdt=mysqli_fetch_array($stdb)) { ?>
								<option value="<?php echo $stdt['status_nama']; ?>"><?php echo $stdt['status_nama']; ?></option>
							<?php } ?>
						</select>
					</div>
				</div>
				<!-- KATEGORI -->
				<div id="gsetting" class="clearfix">
					<?php
						$sql = "SELECT kontenkat_id,kontenkat_judul FROM cmas_kontenkat WHERE kontenkat_status='Aktif' ORDER BY kontenkat_id ASC";
						$getCombo = mysqli_query($koneksi, $sql) or die ('Query Gagal');
					?>
					<script type="text/javascript">
						$(function() {
							$("#KATID").change(function(){
								$("img#imgLoad").show();
								var kontenkat_id = $(this).val();
								
								$.ajax({
									type: "POST",
									dataType: "html",
									url: "libs/getKontenKat.php",
									data: "kontenkat_id="+kontenkat_id,
									success: function(msg){
										if(msg == ''){
											$("select#KATNAME").html('<option value="">- Pilih -</option>');
											}else{
											$("select#KATNAME").html(msg);                                                       
										}
										$("img#imgLoad").hide();
									}
								});                    
							});
						});
					</script>
					<div id="gsettinglabel">Kategori</div>
					<div id="gsettingedit">
						<select name="kontenkat_id" id="KATID" required>
							<option value="<?php echo $dt['kontenkat_id']; ?>"><?php echo $dt['kontenkat_judul']; ?></option>
							<?php
								while($data = mysqli_fetch_array($getCombo)){
									echo '<option value="'.$data['kontenkat_id'].'">'.$data['kontenkat_judul'].'</option>';
								}
							?>
						</select>
						<select name="kontenkat_judul" id="KATNAME" style="display:none">
							<option value="<?php echo $dt['kontenkat_judul']; ?>"><?php echo $dt['kontenkat_judul']; ?></option>
						</select>
					</div>
				</div>
				<?php if ($dt['kontenkat_id'] != "2") {} else { ?>	
					<div id="gsetting" class="clearfix">
						<div id="gsettinglabel">Tanggal</div>
						<div id="gsettingedit">
							<input name="konten_date" type="date" value="<?php echo $dt['konten_date']; ?>">
						</div>
					</div>
					<div id="gsetting" class="clearfix">
						<div id="gsettinglabel">Sumber</div>
						<div id="gsettingedit">
							<input name="konten_author" type="text" value="<?php echo $dt['konten_author']; ?>">
						</div>
					</div>
				<?php } ?>
				<div id="gsetting" class="clearfix">
					<div id="gsettinglabel">Upload</div>
					<div id="gsettingimage">
						<input name="konten_image" type="file"/>
					</div>
				</div>
				<div id="gsetting" class="clearfix">
					<div id="gsettinglabel"></div>
					<div id="gsettingimgbig">
						<?php if ($dt['konten_imageid'] == 0) { ?>
							<img src="assets/images/noimage.jpg" alt="<?php echo $dt['konten_judul']; ?>" title="<?php echo $dt['konten_judul']; ?>">
						<?php } else { ?>
							<img src="assets/images/konten/<?php echo $dt['konten_image']; ?>" alt="<?php echo $dt['konten_judul']; ?>" title="<?php echo $dt['konten_judul']; ?>">
							
							<a href="?m=konten_hapusfile&id=<?php echo $dt['konten_id']; ?>" onclick="return confirm('DATA AKAN DIHAPUS, ANDA YAKIN?');">
								<span><img src="assets/images/icons/icon_tidak.png" title="Hapus File"></span>
							</a>
						<?php } ?>
					</div>
				</div>
				
				<div id="gsettingtitles">ARTICLE TAG</div>
				<div id="gsetting" class="clearfix">
					<div id="tagstop">
						<a href="?m=kontentag_input&id=<?php echo $dt['konten_id']; ?>" class="tagsbtn">+ Tags</a>
					</div>
					
					<div id="gsettinginputfull">
						<div id="tagsbot" class="clearfix">
							<?php
								$tgdb = mysqli_query($koneksi, "SELECT * FROM cmas_kontentag WHERE konten_id='$dt[konten_id]' ORDER BY kontentag_id DESC");
								$find = mysqli_num_rows($tgdb);
								
								if ($find == 0) {
									echo "No Tag";
								} else {
									while($tgdt = mysqli_fetch_array($tgdb)) {
							?>
									<div id="tagsrows" class="clearfix">
										<div id="tagsleft">
											<?php echo $tgdt['kontentag_title']; ?>
										</div>
										<div id="tagsrite">
											<a href="?m=kontentag_hapus&id=<?php echo $tgdt['kontentag_id']; ?>" class="erasetags">x</a>
										</div>
									</div>
								<?php } ?>
							<?php } ?>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div id="tombolsubmit">
			<a href="?m=konten_indexkat&id=<?php echo $dt['kontenkat_id']; ?>"><input name="button" type="button" value="KEMBALI" class="myButton"/></a>
			<input name="submit" type="submit" value="SIMPAN" class="submitbutton" /> 
		</div>
	</form>
	<div id="infobottom" class="clearfix">
		<div class="infobottomleft">
			Posted by <b><?php echo $dt['posted_nama']; ?></b> on <b><?php echo date_format(date_create($dt['postdated']), 'd/m/Y H:i:s'); ?></b>
		</div>
		<div class="infobottomrite">
			Updated by <b><?php echo $dt['updated_nama']; ?></b> on <b><?php echo date_format(date_create($dt['updated']), 'd/m/Y H:i:s'); ?></b>
		</div>
	</div>
</div>
