<?php
include_once("../include/main.inc.php");

check_session('MyCpanel','index.php');


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

	@extract($_POST);

	if($pageDesc ==''){

		$_SESSION[opmsg]="Cannot Update!!You have left the content field empty.~msgadminerr";

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

		$redirect_url = SITE_URL_PATH."/".ADMIN_DIR."/page-content.php?cid=$st_id";
        echo "<script>window.location.href='$redirect_url';</script>";

		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]="Page content has been updated successfully.";


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

	$redirect_url = SITE_URL_PATH."/".ADMIN_DIR."/page-content.php?cid=$st_id";
        echo "<script>window.location.href='$redirect_url';</script>";

	exit;

}}

//Display starts here...

admin_header();

?>

<br/>

<table width="99%" border="0" align="center" cellpadding="0" cellspacing="1" id="box3" valign="top">

<tr><td bgcolor="#f1f1f1"  align="center" ><font size="4"><b id="pgtitle _Container"><?=$title;?></b></font></td></tr>

 <tr>

<?php

 if($_SESSION[opmsg]!=''){

	 $class=getClass();

?>

<tr><td align="center" ><span class="<?=$class;?>"><?=print_message();?></span></td></tr>

<?php

}

?>

</table>

<?php

echo $pageDesc;


echo addEditLinks($_REQUEST[cid]);

admin_footer();

?>