<?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'];
	 $pageDesc2 = $_POST['pageDesc2'];
	 $pageDesc3 = $_POST['pageDesc3'];
	 $keyword1=$_POST['keyword1'];
	 $keyword2=$_POST['keyword2'];
     $st_id = $_POST['st_id'];



	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' ,keyword1='$keyword1' ,keyword2='$keyword2' ,keyword3='$keyword3',pageDesc2='$pageDesc2', pageDesc3='$pageDesc3'  where pageID='$st_id' ");

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

	header("location:".site_url."/".ADMIN_DIR."/manage-staticpage.php");
}}

admin_header();

?>
<div class="content-wrapper">
          <div class="page-header">
            <h3 class="page-title" id="pgtitle _Container">
			<?=$heading;?>
            </h3>
            <nav aria-label="breadcrumb">
              <ol class="breadcrumb">
			  <li class="nav-item d-none d-lg-flex">
            <a class="nav-link" href="<?=admin_url?>manage-staticpage.php">
              <span class="btn btn-primary">Go Back</span>
            </a>
          </li>
              </ol>
            </nav>
          </div>
          <div class="row">
            <div class="col-12 grid-margin stretch-card">
              <div class="card">
                <div class="card-body"> 
				<?php echo addEditLinks($_REQUEST['cid']); ?>
                </div>
              </div>
            </div>
          </div>
        </div>
<?php
admin_footer();
?>