<?php session_start(); error_reporting(0);  
require_once("../j_conn/url.php");
require_once("../j_conn/dbc.php");
require_once("../j_incs/functions.php");
if(isset($_SESSION['j_admin'])){  
if(isset($_POST['title'])){
$title = RMC2($_POST["title"]);  
$content = RMC2($_POST["content"]); 
$content_sm = RMC2($_POST["content_sm"]); 
$ref = RMC($_POST["ref"]); 
if(!empty($content) && !empty($content_sm) && !empty($title)){
	if(strlen($_POST["title"]) <= 100000){
	
	$sql4="SELECT * from j_blog WHERE j_deleted < 1 AND j_id='".$ref."'"; //check 
	$result4 = runSQL($sql4);
	$data4 = mysqli_fetch_array($result4);
	//$title = $data4['j_title'];
	//$content_sm = $data4['j_content_sm'];
	//$content = $data4['j_content'];
	$ref = $data4['j_id'];
	$j_img_cover = $data4['j_img_cover'];
	if(empty($ref)){
		die("<div class='alert alert-danger'> Error: Invalid reference ID.</div>");
	}
		
	require_once("file1.php");
	$img_cover = $filenames;
	
	if(empty($img_cover)){
		$img_cover = $j_img_cover;
	}
	
	//die("$ref $j_img_cover");
	
	$sql5="UPDATE j_blog SET 
	j_title='".$title."',
	j_content='".$content."',
	j_content_sm='".$content_sm."',
	j_img_cover='".$img_cover."'
	WHERE j_id='".$ref."' 
 	";
	$result5=runSQL($sql5);
	if($result5){
	echo "<div class='alert alert-success'> Content has been update. <a href='".$dir."blog/'>View Content</a></div>";	
	
	?>
 	<script>
	//$("#form").trigger('reset');
	</script>
	<?php
	}else{ echo "<div class='alert alert-danger'> Could not update content. Try again.</div>";}
	//
 }else{ echo "<div class='alert alert-danger'> Title must be less or equal 100000.</div>";}
 }else{ echo "<div class='alert alert-danger'> Please write your title and content.</div>";}
} //post
} //not in
?>