<?php include ("connection/conn.php");

$select="select * from tbl_cms where new_id='".$_REQUEST['news_id']."'";
$query=mysqli_query($link,$select);
$assoc=mysqli_fetch_assoc($query);

	if(isset($_POST['postnews']))
		{
		$news_title=addslashes($_POST['news_title']);
		$news_meta_key=$_POST['news_meta_key'];
		$news_meta_des=$_POST['news_meta_des'];
		$description=addslashes($_POST['description']);
		  
			if($news_title=="")
			{
				$Error_msg="Please enter Title.<br>";
			}
			 if($_FILES['img']['name']!="")
			{
                $img=$_FILES['img']['name'];
                $tenthorgext=substr(strrchr($img,"."),1);
                $img=date('d-m-Yhis').rand(0,9999).'.'.$tenthorgext;
                $upload_path_img=$_FILES['img']['tmp_name'];	
               move_uploaded_file($upload_path_img,"../listblg/".$img);
            }
			else if($_FILES['img']['name']=="")
			{
				$img=$assoc['img'];
			}
			if($Error_msg=="")
			{	
			 $updateBlog="update tbl_cms set title='".$news_title."',news_meta_key='".$news_meta_key."',news_meta_des='".$news_meta_des."',description='".$description."',img='".$img."' where new_id='".$_REQUEST['news_id']."' ";
			mysqli_query($link,$updateBlog);
			header("location:manage-cms.php?success=CMS has been Update sucessfully.");
			exit();
			}
		}
?>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>Administrator</title>
		<link href="css/bootstrap.css" rel="stylesheet" />
		<link href="css/style.css" rel="stylesheet" />
		<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
	</head>
	
	<body>
		<div id="wrapper">
			<?php
				include("top-header.php");
				include("right-sec.php");
			?>
			<div id="page-wrapper" >
				<div id="page-inner">
					<div class="row">
						<div class="col-md-12">
							<h3 class="page-header">
								Add Blog  <small></small>
							</h3>
							<div class="table-sec">
								<div class="srch_box">
									<form name="pnews" id="pnews" method="post" action="" enctype="multipart/form-data">
										<div class="row">
											
											<div class="col-md-12 col-xs-12">
												<div class="pnl_box"> 
													<div class="col-md-6 col-xs-6">	
														<div class="form-group form-select">
															<label>Title <span>*</span></label>
															<input class="form-control" type="text"  name="news_title" value="<?php echo $assoc['news_title'];?>">
														</div>		
													</div>
													<div class="col-md-6 col-xs-6">
														<div class="form-group form-select">
															<label>Meta Keyword <span>*</span></label>
															<textarea type="text" name="news_meta_des"><?php echo $assoc['news_meta_key'];?></textarea>
														</div>		
													</div>
													<div class="col-md-6 col-xs-6">
														<div class="form-group form-select">
															<label>Meta Description <span>*</span></label>
															<textarea type="text" name="news_meta_des"><?php echo $assoc['news_meta_des'];?></textarea>
														</div>		
													</div>
													<div class="col-md-6 col-xs-6">	
														<div class="form-group form-select">
															<label>Description<span>*</span></label>
															<textarea name="description"  rows="5" cols="10" id="txtContent" ><?php echo $assoc['description'];?></textarea><?php include("Editor/editor.php");?>
														</div>		
													</div>
													<div class="col-md-6 col-xs-6">	
														<div class="form-group form-select">
															<label>Image <span>*</span></label>
															<input class="form-control" type="file"  name="img"><img src="/listblg/<?php echo $assoc['img'];?>" height="50" width="50"  />
														</div>		
													</div>
													
												</div>	
												
											</div>
										</div>
										<div class="row">
											<div class="col-md-4 col-xs-4">	
												<div class="btn_sec">
														<input type="submit" name="submit" value="Submit" />
												</div>
											</div>
										</div>
									</form>
								</div>
							</div>
						</div>
					</div> 
				</div>
			</div>
			<footer class="footer-sec">
				<div class="container">
					<div class="row">
						<div class="col-md-12">
							<p class="text-center">All right reserved. Template Design by: <a href="">Anshul Chittouria</a></p>
						</div>
					</div>
				</div>
			</footer>
		</div>
		
		
		<!-- jQuery Js -->
		<script src="js/jquery-1.10.2.js"></script>
		<script src="js/bootstrap.min.js"></script>
		<script src="js/jquery.metisMenu.js"></script>
		<script src="js/custom-scripts.js"></script>
	</body>
</html>
