<?php require_once("header.php");?>
<?php require_once("left-nav.php");?>
<link href="assets/plugins/icheck/skins/all.css" rel="stylesheet" type="text/css"/>
<link href="assets/plugins/bootstrap-toggle/bootstrap-toggle.min.css" rel="stylesheet" type="text/css"/>
<?php
$site_pages_id = $_GET['site_pages_id'];

if($_REQUEST['delImage']!=""){
$isDel=db_query("UPDATE  tbl_site_pages SET  site_pages_image_name='' WHERE 1 and site_pages_id = '$site_pages_id'"); 
@unlink("../static_files/$_REQUEST[delImage]");
header("location:static_page_f.php?site_pages_id=$site_pages_id");
}

if($_REQUEST['delImage_banner']!=""){
$isDel_banner=db_query("UPDATE  tbl_site_pages SET  site_pages_inner_banner='' WHERE 1 and site_pages_id = '$site_pages_id'"); 
@unlink("../static_files/$_REQUEST[delImage_banner]");
header("location:static_page_f.php?site_pages_id=$site_pages_id");
}

if($_REQUEST['delVideo']!=""){
$isDel=db_query("UPDATE  tbl_site_pages SET  site_pages_video_name='' WHERE 1 and site_pages_id = '$site_pages_id'"); 
@unlink("..static_files/video/$_REQUEST[delVideo]");
header("location:static_page_f.php?site_pages_id=$site_pages_id");
}

if(is_post_back()) {
$site_pages_description = sanitize_input($_REQUEST['site_pages_description']);  
$site_pages_meta_title = sanitize_input($_REQUEST['site_pages_meta_title']);
$site_pages_meta_keyword = sanitize_input($_REQUEST['site_pages_meta_keyword']);
$site_pages_meta_description = sanitize_input($_REQUEST['site_pages_meta_description']);

$m_description = sanitize_input($_REQUEST['m_description']);
$m_meta_title = sanitize_input($_REQUEST['m_meta_title']);
$m_meta_description = sanitize_input($_REQUEST['m_meta_description']);
$m_meta_keywords = sanitize_input($_REQUEST['m_meta_keywords']);

$image_alt = sanitize_input($_REQUEST['image_alt']);
$image_title = sanitize_input($_REQUEST['image_title']);

 if($site_pages_name=='Home'){
  $pg_url='index';
 }else{
$pg_url=ami_crete_url($site_pages_name);
}
$ordBY=db_scalar("select MAX(site_pages_order_by) from tbl_site_pages where 1");
$ordBY=$ordBY+1;
  if($site_pages_id!='') {
    ////////////****************** IMAGE RESIZING START HERE *****************************//
//**********  *****************//
//------------FUNCTION TO GET IMAGE EXTENSION START---------------//
 function getExtension($str) {
         $i = strrpos($str,".");
         if (!$i) { return ""; }
         $l = strlen($str) - $i;
         $ext = substr($str,$i+1,$l);
         return $ext;
 }
 //------------FUNCTION TO GET IMAGE EXTENSION END---------------//
  $image =$_FILES["file"]["name"];
  $uploadedfile = $_FILES['file']['tmp_name']; 
  if ($image) {   
      $DelImage=db_scalar("select site_pages_image_name from tbl_site_pages where 1 and site_pages_id = '$_REQUEST[site_pages_id]'");
      @unlink("../static_files/$DelImage");
    $filename = stripslashes($_FILES['file']['name']);  
      $extension = getExtension($filename);
    $extension = strtolower($extension);    
    $imgNAME = rand(1000,5000).".".$extension;

move_uploaded_file($_FILES['file']['tmp_name'],"../static_files/$imgNAME");
}else{
$imgNAME=db_scalar("select site_pages_image_name from tbl_site_pages where 1 and site_pages_id = '$site_pages_id'");
}

/*### INNER BANNER IMAGE ###*/

$image_banner =$_FILES["site_pages_inner_banner"]["name"];
  $uploadedfile_banner = $_FILES['site_pages_inner_banner']['tmp_name']; 
  if ($image_banner) {   
      $DelImage_banner=db_scalar("select site_pages_inner_banner from tbl_site_pages where 1 and site_pages_id = '$_REQUEST[site_pages_id]'");
      @unlink("../static_files/$DelImage_banner");
    $filename_banner = stripslashes($_FILES['site_pages_inner_banner']['name']);  
      $extension_banner = getExtension($filename_banner);
    $extension_banner = strtolower($extension_banner);    
    $imgNAME_banner = rand(1000,5000).".".$extension_banner;

move_uploaded_file($_FILES['site_pages_inner_banner']['tmp_name'],"../static_files/$imgNAME_banner");
}else{
$imgNAME_banner=db_scalar("select site_pages_inner_banner from tbl_site_pages where 1 and site_pages_id = '$site_pages_id'");
}


 if(is_uploaded_file($_FILES['site_pages_video_name']['tmp_name'])){

      $video = $_FILES['site_pages_video_name']['name'];
      $extension = explode('/', $_FILES['site_pages_video_name']['type']);
      $video = rand(1000,5000).'.'.$extension[1];

      move_uploaded_file($_FILES['site_pages_video_name']['tmp_name'],"../static_files/video/$video");
     }else{
      $video = db_scalar("select site_pages_video_name from tbl_site_pages where 1 and site_pages_id = '$site_pages_id'");
     }

////////////****************** IMAGE RESIZING END HERE *****************************//
 $sqlupdate = "update tbl_site_pages set 
                 site_pages_name='$_REQUEST[site_pages_name]', 
                 site_pages_title='$_REQUEST[site_pages_title]',
                 site_pages_image_name='$imgNAME',
                 site_pages_inner_banner='$imgNAME_banner',
                 site_pages_video_name='$_REQUEST[site_pages_video_name]',
                 site_pages_meta_title = '$site_pages_meta_title',
                 site_pages_link='$_REQUEST[site_pages_link]',
                 image_alt='$image_alt',
                 image_title='$image_title',
                 m_description='$m_description',
                 m_meta_title='$m_meta_title',
                 m_meta_description='$m_meta_description',
                 m_meta_keywords='$m_meta_keywords',
                 site_pages_meta_description='$site_pages_meta_description',
                 site_pages_meta_keyword='$site_pages_meta_keyword',
                 site_pages_description='$site_pages_description',
                 site_pages_show_in_header='$_REQUEST[show_in_header]',
                 site_pages_show_in_footer='$_REQUEST[show_in_footer]',
                 site_pages_add_date='$curr_date',
                 site_pages_status='$_REQUEST[site_pages_status]'  
                 where site_pages_id = '$_REQUEST[site_pages_id]' ";
      
  
                     db_query($sqlupdate);
             set_session_msg("Page Updated Successfully !");
    }else{
      //*************** INSERT NEW CATEGORY START ************************//
////////////****************** IMAGE RESIZING START HERE *****************************//

//------------FUNCTION TO GET IMAGE EXTENSION START---------------//
 function getExtension($str) {
         $i = strrpos($str,".");
         if (!$i) { return ""; }
         $l = strlen($str) - $i;
         $ext = substr($str,$i+1,$l);
         return $ext;
 }
 //------------FUNCTION TO GET IMAGE EXTENSION END---------------//
  $image =$_FILES["file"]["name"];
  $uploadedfile = $_FILES['file']['tmp_name']; 
  if ($image) {   
    $filename = stripslashes($_FILES['file']['name']);  
      $extension = getExtension($filename);
    $extension = strtolower($extension);
    $imgNAME = $pg_url.".".$extension;    


move_uploaded_file($_FILES['file']['tmp_name'],"../static_files/$imgNAME");
}

////////////****************** IMAGE RESIZING END HERE *****************************//
    $dupliDataCount=db_scalar("select count(*) from tbl_site_pages where 1 and site_pages_name='$_REQUEST[site_pages_name]'");
 if($dupliDataCount =='0'){
    $sqlinsert = "insert into tbl_site_pages set 
                   site_pages_name='$_REQUEST[site_pages_name]', 
                   site_pages_title='$_REQUEST[site_pages_title]',
                   site_pages_image_name='$imgNAME',
                   site_pages_inner_banner='$imgNAME_banner',
                   site_pages_video_name='$video',
                   site_pages_meta_title = '$site_pages_meta_title',
                   site_pages_link='$_REQUEST[site_pages_link]',
                   site_pages_meta_description='$site_pages_meta_description',
                   site_pages_meta_keyword='$site_pages_meta_keyword',
                   site_pages_description='$site_pages_description',
                   m_description='$m_description',
                   m_meta_title='$m_meta_title',
                   m_meta_description='$m_meta_description',
                   m_meta_keywords='$m_meta_keywords',
                   site_pages_show_in_header='$_REQUEST[show_in_header]',
                   site_pages_show_in_footer='$_REQUEST[show_in_footer]',
                   site_pages_add_date='$curr_date',
                   image_alt='$image_alt',
                   image_title='$image_title',
                   site_pages_status='$_REQUEST[site_pages_status]' ";
                      db_query($sqlinsert);
                   set_session_msg("Page Added Successfully !");
}else{   
  set_session_msg("Sorry! page name is already exist !"); 
}
}
header("Location: static_page_list.php");
exit;
}
if($site_pages_id!=''){
  $sql="select * from tbl_site_pages where site_pages_id = '$site_pages_id'"; 
  $result = db_query($sql);
  if ($line_raw = mysqli_fetch_array($result)) {
    $line = ms_form_value($line_raw);
    @extract($line);
  }
}
?>


<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
 <div class="header-icon">
    <i class="fa fa-file-text"></i>
 </div>
 <div class="header-title">
    <h1>Edit Page</h1>
    <small>Edit Page Content</small>
    
    
<a href="static_page_list.php"><button id="btn-go-back" type="button" class="btn btn-labeled btn-inverse m-b-5 pull-right">
<span class="btn-label" ><i class="fa fa-chevron-circle-left"></i></span>Go Back
</button></a>

    
 </div>
 
 
</section>
<script type="text/javascript">
function formValidation(){
if(document.getElementById('site_pages_link').value==0){
alert("Select page link !");
document.getElementById('site_pages_link').focus();
return false;
}

}
</script>
<!-- Main content -->
<script src="ckeditor/ckeditor.js"></script>            
<section class="content">
<div class="row">
<!-- Form controls -->
<div class="col-sm-12">
<div class="panel panel-bd lobidrag" data-edit-title='false' data-close='false' data-reload='false'>
<div class="panel-heading">
<div class="btn-group" id="buttonexport">
<a href="#">
   <h4>General Information</h4>
</a>
</div>
</div>
<div class="panel-body">
<form name="form1" method="post" onsubmit="return formValidation()" enctype="multipart/form-data" class="col-sm-12" >
<div class="form-group col-lg-6">
   <label>Page Name</label>
<input type="text" class="form-control" placeholder="Enter Name" name="site_pages_name" id="site_pages_name"  value="<?=$site_pages_name?>">
</div>
<div class="form-group col-lg-6">
<label>Page Link</label>
<!-- <input type="text" class="form-control" placeholder="Enter Title" name="site_pages_title" id="site_pages_title" value="<?=$site_pages_title?>" > -->  
<select name="site_pages_link" id="site_pages_link" class="form-control" >
  <option value="">Select Page Link</option>
  <option value="index" <?php if($site_pages_link=='index'){ ?> selected="selected" <? } ?>>index.php</option>
  <option value="about-us" <?php if($site_pages_link=='about-us'){ ?> selected="selected" <? } ?>>about-us.php</option>
  <option value="contact-us" <?php if($site_pages_link=='contact-us'){ ?> selected="selected" <? } ?>>contact-us.php</option>
  <option value="our-services" <?php if($site_pages_link=='our-services'){ ?> selected="selected" <? } ?>>our-services.php</option>
  <option value="latest-updates" <?php if($site_pages_link=='latest-updates'){ ?> selected="selected" <? } ?>>latest-updates.php</option>
  <option value="gallery" <?php if($site_pages_link=='gallery'){ ?> selected="selected" <? } ?>>gallery.php</option>
  <option value="market-area" <?php if($site_pages_link=='market-area'){ ?> selected="selected" <? } ?>>market-area.php</option>
  <option value="sitemap" <?php if($site_pages_link=='sitemap'){ ?> selected="selected" <? } ?>>sitemap.php</option>
  <option value="calculator" <?php if($site_pages_link=='calculator'){ ?> selected="selected" <? } ?>>calculator.php</option>
  <option value="sirs" <?php if($site_pages_link=='sirs'){ ?> selected="selected" <? } ?>>sirs.php</option>
  <option value="nova-scotia-67-point-calculator" <?php if($site_pages_link=='nova-scotia-67-point-calculator'){ ?> selected="selected" <? } ?>>nova-scotia-67-point-calculator.php</option>
  <option value="sinp-calculator" <?php if($site_pages_link=='sinp-calculator'){ ?> selected="selected" <? } ?>>sinp-calculator.php</option>
  <option value="67-calculator" <?php if($site_pages_link=='67-calculator'){ ?> selected="selected" <? } ?>>67-calculator.php</option>
  <option value="business-investor" <?php if($site_pages_link=='business-investor'){ ?> selected="selected" <? } ?>>business-investor.php</option>
 
  </select>
</div>
                             
 <?php if($site_pages_link=='about-us' || $site_pages_link=='customized-work' || $site_pages_link=='enquiry' || $site_pages_link=='services' || $site_pages_link=='career'  ){ ?>
                            
<div class="form-group col-lg-3">
<label>Page Image</label>
<?php if($site_pages_image_name!=""){ ?>
<img src="../static_files/<?=$site_pages_image_name?>" class="form-control" style="width:170px;height:200px" />
<?php }else{?>
<img src="assets/dist/img/no-image.jpg" class="form-control" style="width:170px;height:200px" />
<?php }?>

<?php if($site_pages_image_name!=""){ ?>
<div class="col-lg-12 " ><a href="static_page_f.php?delImage=<?=$site_pages_image_name?>&site_pages_id=<?=$site_pages_id?>" style="font-weight:600;margin-left:15px;text-decoration:underline" >Remove Image</a>                  
</div>
<?php }?>

</div>

<div class="form-group col-lg-3" style="padding-top:100px">
<input type="file" name="file" id="file" />
</div>

<!-- *************** -->

<!-- <div class="form-group col-lg-4">
<label> Video</label>
<?php if($site_pages_video_name!=""){ 
  $ext=explode('.', $line_raw['site_pages_video_name']);?><br>
<video width="300" height="200" controls>
  <source src="../static_files/video/<?=$line_raw['site_pages_video_name']?>" type="video/<?=$ext[1]?>">
</video>
<?php }else{?>
<img src="assets/dist/img/no-video.png" class="form-control" style="width:170px;height:200px" />
<?php }?>

<?php if($site_pages_video_name!=""){ ?>
<div class="col-lg-12 " ><a href="static_page_f.php?delVideo=<?=$site_pages_video_name?>&site_pages_id=<?=$site_pages_id?>" style="font-weight:600;margin-left:15px;text-decoration:underline" >Remove Video</a>                  
</div>
<?php }?>

</div> -->

<!-- <div class="form-group col-lg-6" style="padding-top:100px">
  <label>Enter Video Link</label>
<input type="text" class="form-control" name="site_pages_video_name" id="site_pages_video_name" placeholder="E.g: OTKA2JodaDU" value="<?=$line_raw['site_pages_video_name']?>" />
</div> -->


<!-- **INNER BANNER** -->
<!--<div class="row">
<div class="form-group col-lg-9">
<label>Inner Banner</label>
<?php if($site_pages_inner_banner!=""){ ?>
<img src="../static_files/<?=$site_pages_inner_banner?>" class="form-control" style="width:600px;height:300px" />
<?php }else{?>
<img src="assets/dist/img/no-banner.png" class="form-control" style="width:600px;height:300px" />
<?php }?>

<?php if($site_pages_inner_banner!=""){ ?>
<div class="col-lg-12 " ><a href="static_page_f.php?delImage_banner=<?=$site_pages_inner_banner?>&site_pages_id=<?=$site_pages_id?>" style="font-weight:600;margin-left:15px;text-decoration:underline" >Remove Banner</a>                  
</div>
<?php }?>

</div>

<div class="form-group col-lg-3" style="padding-top:100px">
  <span style="color: red;font-weight: bold;">Size must be: 1920 x 800</span><br>
<input type="file" name="site_pages_inner_banner" id="site_pages_inner_banner" />
</div>
</div>-->

<!-- <div class="form-group col-lg-6">
 <label>Image Alt</label>
<input type="text" class="form-control" name="image_alt" id="image_alt" placeholder="Enter Image Alt" value="<?=$line_raw['image_alt']?>" />    
</div>
<div class="form-group col-lg-6">
 <label>Image Title</label>
<input type="text" class="form-control" name="image_title" id="image_title" placeholder="Enter Image Title" value="<?=$line_raw['image_title']?>" />    
</div> -->

<?php }?>

<!-- **INNER BANNER FOR REGISTRATION PAGE** -->
<?php 
if($line_raw['site_pages_link']=='contact-us' || $line_raw['site_pages_link']=='our-services' || $line_raw['site_pages_link']=='gallery' || $line_raw['site_pages_link']=='latest-updates' || $line_raw['site_pages_link']=='about-us' || $line_raw['site_pages_link']=='sitemap' || $line_raw['site_pages_link']=='market-area'){?>

<div class="row">
<div class="form-group col-lg-9">
<label>Inner Banner</label>
<?php if($site_pages_inner_banner!=""){ ?>
<img src="../static_files/<?=$site_pages_inner_banner?>" class="form-control" style="width:600px;height:150px" />
<?php }else{?>
<img src="assets/dist/img/no-banner.png" class="form-control" style="width:600px;height:150px" />
<?php }?>

<?php if($site_pages_inner_banner!=""){ ?>
<div class="col-lg-12"><a href="static_page_f.php?delImage_banner=<?=$site_pages_inner_banner?>&site_pages_id=<?=$site_pages_id?>" style="font-weight:600;margin-left:15px;text-decoration:underline" >Remove Banner</a>                  
</div>
<?php }?>

</div>

<div class="form-group col-lg-3" style="padding-top:70px">
  <span style="color: red;font-weight: bold;">Size must be: 1519 x 380</span><br>
<input type="file" name="site_pages_inner_banner" id="site_pages_inner_banner" />
</div>
</div>

<?php } ?>                                                      
                             
<div class="form-group col-lg-12">
 <label>Page Content</label>
<textarea class="form-control" name="site_pages_description" rows="3" id="editor1"><?=$site_pages_description?></textarea>
</div>
<script>
CKEDITOR.replace( 'editor1');
</script>

<?php if($site_pages_link == 'index'){?>
<div class="form-group col-lg-12">
 <label>Location Based Content</label>
<textarea class="form-control" name="m_description" rows="3" id="m_description"><?=$m_description?></textarea>
</div>
<script>
CKEDITOR.replace('m_description');
</script>
<?php }?>                       
                           
<div class="form-group col-lg-3">
<select name="site_pages_status" class="form-control" >
<option value="Active" <?php if($site_pages_status=='Active'){ ?> selected="selected" <? } ?>>Active</option>
<option value="Inactive" <?php if($site_pages_status=='Inactive'){ ?> selected="selected" <? } ?>>Inactive</option>
</select>
</div>                             
       
 <div class="form-group col-lg-3">
<select name="show_in_header" class="form-control" >
<option value="">Header</option>
<option value="Yes" <?php if($site_pages_show_in_header=='Yes'){ ?> selected="selected" <? } ?>>Show in header</option>
<option value="No" <?php if($site_pages_show_in_header=='No'){ ?> selected="selected" <? } ?>>Not show in header</option>
</select>
</div>  
<div class="form-group col-lg-3">
<select name="show_in_footer" class="form-control" >
  <option value="">Footer</option>
<option value="Yes" <?php if($site_pages_show_in_footer=='Yes'){ ?> selected="selected" <? } ?>>Show in footer</option>
<option value="No" <?php if($site_pages_show_in_footer=='No'){ ?> selected="selected" <? } ?>>Not show in footer</option>
</select>


</div>  



<div class="col-lg-12" style="padding:0;background-color:#e8f1f3;margin:20px 0 50px 0">
<div class="btn-group" id="buttonexport">
  <a href="#" >
     <h4 style="color:#000;font-weight:600;padding:5px">SEO Related Information</h4>
  </a>
</div>
</div>                             
 
 
<div class="form-group col-lg-12">
   <label>Page Meta Title</label>
<textarea class="form-control" rows="3" name="site_pages_meta_title" id="site_pages_meta_title" placeholder="Enter page meta title here" ><?=$site_pages_meta_title?></textarea>
</div>
<div class="form-group col-lg-12">
   <label>Page Meta Description</label>
<textarea class="form-control" rows="3" placeholder="Enter page meta description here" name="site_pages_meta_description" id="site_pages_meta_description"><?=$site_pages_meta_description?></textarea>
</div>
<div class="form-group col-lg-12">
   <label>Page Meta Keyword</label>
<textarea class="form-control" rows="3" name="site_pages_meta_keyword" placeholder="Enter page meta keywords here" id="site_pages_meta_keyword"><?=$site_pages_meta_keyword?></textarea>
</div> 
  
<?php if($site_pages_link == 'index' || $site_pages_link == 'our-products'){?>  
<div class="col-lg-12" style="padding:0;background-color:#e8f1f3;margin:20px 0 50px 0">
<div class="btn-group" id="buttonexport">
  <a href="#" >
     <h4 style="color:#000;font-weight:600;padding:5px">Location Based SEO</h4>
  </a>
</div>
</div>                             
 
 
<div class="form-group col-lg-12">
   <label> Meta Title</label>
<textarea class="form-control" rows="3" name="m_meta_title" id="m_meta_title" placeholder="Enter meta title here" ><?=$m_meta_title?></textarea>
</div>
<div class="form-group col-lg-12">
   <label> Meta Description</label>
<textarea class="form-control" rows="3" placeholder="Enter meta description here" name="m_meta_description" id="m_meta_description"><?=$m_meta_description?></textarea>
</div>
<div class="form-group col-lg-12">
   <label> Meta Keyword</label>
<textarea class="form-control" rows="3" name="m_meta_keywords" placeholder="Enter meta keywords here" id="m_meta_keywords"><?=$m_meta_keywords?></textarea>
</div>   
<?php }?> 

  <div class="col-lg-12 reset-button">
                                     
     <button type="submit" class="btn btn-add">Update</button>
    
  </div>
</form>
</div>
</div>
</div>
</div>
</section>
<!-- /.content -->
</div>
<?php require_once("footer.php"); ?>
 