<?php session_start();
include("../../config/config.php");

include("../validateuserlogin.php");

$category = secureSuperGlobalPOST($_REQUEST[SESS_MASTER.'category']);

$metatitle =   secureSuperGlobalPOST($_REQUEST[SESS_MASTER.'metatitle']);

$metadesc =   secureSuperGlobalPOST($_REQUEST[SESS_MASTER.'metadesc']);

$metakey =   secureSuperGlobalPOST($_REQUEST[SESS_MASTER.'metakey']);

$blogtitle =   secureSuperGlobalPOST($_REQUEST[SESS_MASTER.'blogtitle']);

$idcodes =   secureSuperGlobalPOST($_REQUEST[SESS_MASTER.'idcodes']);

$nospace=str_replace(" ","-",$blogtitle);
$addblog=strtolower($nospace);

$editor1 =   secureSuperGlobalPOST($_REQUEST['editor1']);
echo $idcodes;
echo $metatitle;


/*file upload*/

if (!empty($_FILES[SESS_MASTER.'file_up']['name'])){

  $file_upload_flag="true";
  
  $file_up_size=$_FILES[SESS_MASTER.'file_up']['size'];
  
  if ($_FILES[SESS_MASTER.'file_up']['size']>2500000){
  
  $msg=$msg."Your uploaded file size is more than 2500KB ";
  
  $msg.=" so please reduce the file size and then upload.<BR>";
  
  $file_upload_flag="false";
  
  }
  
  
  
  // allow only jpeg or gif files, remove this if not required //
  
  if (!($_FILES[SESS_MASTER.'file_up']['type'] =="image/jpeg" OR $_FILES[SESS_MASTER.'file_up']['type'] =="image/png"))
  
  {$msg=$msg."Your uploaded file must be of JPG or GIF. ";
  
  $msg.="Other file types are not allowed<BR>";
  
  $file_upload_flag="false";}
  
  
  
  $file_name=$_FILES[SESS_MASTER.'file_up']['name'];
  
  $temp = explode(".", $file_name);
  
  $newfilename = round(microtime(true)) . '.' . end($temp);
  
  // the path with the file name where the file will be stored
  
  $add="upload/".$newfilename; 
  
  
  
  if($file_upload_flag=="true"){ // checking the Flag value 
  
  
  
  if(move_uploaded_file($_FILES[SESS_MASTER.'file_up']['tmp_name'], $add)){
  
  // do your coding here to give a thanks message or any other thing.
  
  $msg="File successfully uploaded";
  
  }else{
  
  echo "Failed to upload file Contact Site admin to fix the problem";
  
  }
  
  }else{
  
  $msg .= " Failed to upload file ";
  
  }
  
  }
  
  /*file upload*/
  
  $datecreated=date("Y-m-d H:i:s");
  
  
  
  if($_POST OR $_FILES){
  
    try{
  
    
  
       $user_id=$_SESSION[ADD_TAG.'_UserId'];
  
           
  
       $olgaquerys="INSERT INTO blog_category_add SET datecreated='$datecreated' " ;
  
       if(!empty($category)){

        $olgaquerys = $olgaquerys." ,category='$category'";
  
       }
       if(!empty($metatitle)){
  
        $olgaquerys = $olgaquerys." ,   metatitle='$metatitle'";
  
       }
       if(!empty($blogtitle)){
  
        $olgaquerys = $olgaquerys." ,   blogtitle='$blogtitle'";
  
       }
  
        if(!empty($metadesc)){
  
        $olgaquerys = $olgaquerys." ,   metadesc='$metadesc'";
  
       }
       if(!empty($metakey)){
  
        $olgaquerys = $olgaquerys." ,   metakey='$metakey'";
  
       }
       if(!empty($addblog)){
  
        $olgaquerys = $olgaquerys." ,   addblog='$addblog'";
  
       }
       if(!empty($idcodes)){
  
        $olgaquerys = $olgaquerys." ,   idcodes='$idcodes'";
  
       }
       if(!empty($editor1)){
  
        $olgaquerys = $olgaquerys." ,   editor1='$editor1'";
  
       }
       if (!empty($_FILES[SESS_MASTER.'file_up']['name'])){

        $olgaquerys= $olgaquerys.", blog_image='$add' ";

         }



    // $olgaquerys = $olgaquerys." WHERE rowId='$user_id'";

      $stmts = $conn->prepare($olgaquerys);

      echo $olgaquerys;

        if($stmts->execute()){

         $_SESSION['save-blog'] = "Save Successfully";

      header("location:../create-post.php");



}







}

   

 /*error*/

  catch(PDOException $exception){

      die('ERROR: ' . $exception->getMessage());

  }

}





// if($_POST){
//    try{
//       $user_id=$_SESSION[ADD_TAG.'_UserId'];
//       $olgaquerys="INSERT INTO blog_category_add SET category_name='$category' " ;
//       $olgaquerys = $olgaquerys." WHERE s_no='$user_id'";

//       $stmts = $conn->prepare($olgaquerys);
//     echo $olgaquerys;
// 		if($stmts->execute()){
		 
// 			 header("location: ../create-post.php");

// 			}
//    }
//     /*error*/
//     catch(PDOException $exception){
//       die('ERROR: ' . $exception->getMessage());
//   }
// }
?>