<?php session_start(); error_reporting(0); if(!isset($_SESSION['jj_user']) && !isset($_SESSION['j_admin'])){ $url = urlencode("http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]");header('location:../login/?url='.$url.''); } ?>
<!doctype html>
<html lang="en"> 
	<head>
		<?php
		require_once("../j_conn/url.php");
		require_once("../j_conn/dbc.php");
		require_once("../j_incs/functions.php");
		$page_name="Edit News";
		$page_desc="$company_desc";
		$page_img="".$dir."j_files/j_img/logo/logo-meta.png";
		$page_author="$company";
		$page_keywords="".$company.", $page_name, $page_desc, ".$company_motto.", $company_desc";
		$page_url="".$dir."blog-edit/";
		require_once("../j_incs/metas.php");
		require_once("../j_incs/scripts-top.php");
		?>
	</head>
	<body>
		<div class="container-scroller">
			<?php require_once("../j_incs/header.php"); ?>
			<div class="container-fluid page-body-wrapper">
				<?php require_once("../j_incs/nav.php"); ?>
				<div class="main-panel">
					<div class="content-wrapper">
						<div class="page-header">
							<h3 class="page-title">
							  <?php echo $page_name; ?>
							</h3>
							<nav aria-label="breadcrumb">
							  <ol class="breadcrumb">
								<li class="breadcrumb-item"><a href="<?php echo $dir; ?>">Dashboard</a></li>
								<li class="breadcrumb-item"><a href="<?php echo $dir; ?>blog/">Manage News</a></li>
								<li class="breadcrumb-item active" aria-current="page"><?php echo $page_name; ?></li>
							  </ol>
							</nav>
						</div>
						
						<?php 
						$ref = RMC($_GET['r']);
						$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'];
						?>
						
						<div class="row grid-margin">
							<div class="col-12">
								<div class="card">
									<div class="card-body">
										<form method="POST" action="" id="form">
											<div class="form-group  row required">
												<label class="col-sm-3 control-label">Title <sup> * </sup></label>   
												<div class="col-sm-9">
													<input value="<?php echo urldecode($title); ?>" placeholder="Title" name="title" type="text" class="form-control"/>
													
													<input style="display:none;" value="<?php echo DRMC($ref); ?>" style="font-size:13px;" placeholder="Ref" name="ref" type="text" class="form-control"/>
													
												</div>
											</div>
											
											
											<div class="form-group  row required">
												<label class="col-sm-3 control-label">Short Description <sup> * </sup></label>   
												<div class="col-sm-9">
													<input value="<?php echo urldecode($content_sm); ?>" placeholder="Short Description" name="content_sm" type="text" class="form-control"/>
												</div>
											</div>
											
											
											<div class="form-group  row required">
												<label class="col-sm-3 control-label">Full Descriptiopn<sup> * </sup></label>   
												<div class="col-sm-9">
													<textarea style="min-height:150px;" rows="5"  placeholder="Content" name="content" type="text" class="form-control"><?php echo urldecode($content); ?></textarea>
												</div>
											</div>
											
											
											<div class="form-group  row required">
												<label class="col-sm-3 control-label">Cover Image  <sup></sup>
												</label>   
												<div class="col-sm-9">
													<input placeholder="File" name="file1" type="file" class="form-control"/>
												</div>
											</div>
											
											
											
											<br>
											<p class="help-block">On submit, News will be updated instantly. </p>
											<button id="submit" type="submit" class="btn btn-primary">Update Content</button>
										</form>
										
										<div id="formresult" class="mt-2"></div>
									</div>
								</div>
							</div>
						</div>
					</div>
					<?php require_once("../j_incs/footer.php"); ?>
				</div> <!-- main-panel ends -->
			</div> <!-- page-body-wrapper ends -->
		</div>
		<!-- container-scroller -->
		<?php require_once("../j_incs/scripts-bottom.php"); ?>
		<script>
	
			var form = "#form";
			var button = "#submit";
			var button_val = $(button).html();
			var result = "#formresult";
			var loader = ".j_loader";
			$(form).on('submit',(function(e) {
			e.preventDefault();
			$(button).attr('disabled', '');
			$(button).html('<span class="fa fa-circle-notch fa-spin fa-1x fa-fw"></span> PROCESSING...');
			$(loader).show('slow');
			 $(result).html("");
			var xhr = $.ajax({
			url: "save.php",
			type: "POST",
			data: new FormData(this),
			contentType: false,
			cache: false,
			processData:false,
			success: function(data)
			{
			if(data){
			 $(button).removeAttr('disabled');
			$(button).html(button_val);
			$(result).html(data);
			}else{
			$(result).html("Error occurred.");
			$(button).removeAttr('disabled');
			$(button).html(button_val);
			}
			}
			});
				setTimeout(function(){
					xhr.abort();
					$(button).removeAttr('disabled');
					$(button).html(button_val);
					//$(result).html("");
				}, 10000);
			}));
		</script>
	</body>
</html>