<?php
include_once("../include/main.inc.php");
check_session('MyCpanel','index.php');


if($_POST['add_ct']=="Save") {//(Add/Update)

	@extract($_POST);
    
    $mtitle = $_POST['mtitle'];
     $mkeyword = $_POST['mkeyword'];
     $mdesc = $_POST['mdesc'];
     $pageDesc = $_POST['pageDesc'];
     $pageDesc1 = $_POST['pageDesc1'];
     $st_id = $_POST['st_id'];

	if($pageDesc ==''){

		$_SESSION['opmsg']="<div class='alert alert-danger' role='alert'>Cannot Update!!You have left the content field empty.~msgadminerr</div>";

		header("location:".site_url."/".ADMIN_DIR."/page-content.php?cid=$st_id");

		exit;	

	}

	if(strlen(trim($st_id))) {
		
		if($_FILES['banner']['name']!="") {
			$res1=getResult("static_pages"," where pageID='$st_id'");
			$filenm1=SITE_DIR_PATH."/uploaded-files/page-banners/".$res1['pageBanner'];
			if (file_exists($filenm1)) {
				unlink($filenm1);
			}
			
			$img_name="banner".date("s");
			$img1=upload_file($img_name,"banner","uploaded-files/page-banners");
			updateTable("static_pages"," pageBanner='$img1' where pageID='$st_id'");
		}
		if($_FILES['image']['name']!="") {
			$res2=getResult("static_pages"," where pageID='$st_id'");
			$filenm2=SITE_DIR_PATH."/uploaded-files/page-images/".$res2['pageImage'];
			if (file_exists($filenm2)) {
				unlink($filenm2);
			}
			
			$img_name1="image".date("s");
			$img2=upload_file($img_name1,"image","uploaded-files/page-images");
			updateTable("static_pages"," pageImage='$img2' where pageID='$st_id'");
		}

		updateTable("static_pages"," page_metatitle='$mtitle', page_keyword='$mkeyword', page_metadesc='$mdesc', pageDesc='$pageDesc',pageDesc1='$pageDesc1' where pageID='$st_id' ");

		$_SESSION['opmsg']="<div class='alert alert-danger'>Page content has been updated successfully.</div>";

	header("location:".site_url."/".ADMIN_DIR."/page-content.php?cid=$st_id");
}}

admin_header();

?>

<div class="row mb-5">
    <h3 id="pgtitle _Container"><?=$title;?></h3>   

<?php
 if($_SESSION['opmsg']!=''){
	 $class=getClass();
?>
<div class="row"><?=print_message();?> <br><br></div>
<?php

}
?>
</div>
<?php

echo $pageDesc;


echo addEditLinks($_REQUEST['cid']);

admin_footer();

?>