<?php session_start();
require_once("../../config/config.php");
//require_once("../config/commonsetting.php");

$myformId=SESS_MASTER;
$myIp= ipCheck() ;
$dateceated=date("Y-m-d G:i:s");
$createdby='0';

$contact=   $_REQUEST[SESS_MASTER.'contact'];
if(!empty($_FILES[SESS_MASTER.'contact_image']['name'])){
$company_logoload_flag="true";
$company_logo_size=$_FILES[SESS_MASTER.'contact_image']['size'];
if ($_FILES[SESS_MASTER.'contact_image']['size']>2500000){
$msg=$msg."Your uploaded file size is more than 2500KB ";
$msg.=" so please reduce the file size and then upload.<BR>";
$company_logoload_flag="false";
}

// allow only jpeg or gif files, remove this if not required //
if (!($_FILES[SESS_MASTER.'contact_image']['type']=="image/jpeg" OR $_FILES[SESS_MASTER.'contact_image']['type'] =="image/png")){
$msg=$msg."Your uploaded file must be of JPG or GIF. ";
$msg.="Other file types are not allowed<BR>";
$company_logoload_flag="false";}

$file_name=$_FILES[SESS_MASTER.'contact_image']['name'];
// the path with the file name where the file will be stored
$add="../../images/web-images/home/contact-us.jpg"; 
$add_data="images/web-images/home/contact-us.jpg";

if($company_logoload_flag=="true"){ // checking the Flag value 
echo $_FILES[SESS_MASTER.'contact_image']['name'];
if(!file_exists($add)){
if(move_uploaded_file($_FILES[SESS_MASTER.'contact_image']['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{
  unlink($add);
if(move_uploaded_file($_FILES[SESS_MASTER.'contact_image']['tmp_name'], $add)){
// do your coding here to give a thanks message or any other thing.
$msg="File successfully uploaded";
}


} }   
else{
$msg .= " Failed to upload file ";
}


}


    
  $sql = "SELECT * FROM contact_master ";
   
    $myquery=$conn->query($sql);
  $mydara= $myquery->fetchAll()  ;
  
  $rows_found = $myquery->rowCount();
   


    if($_POST){
  try{
     if($rows_found=='0'){
      
      $olgaquerys="INSERT INTO contact_master SET createdIp='$myIp',datecreated='$dateceated',banner_image='$add_data',hubspot='$contact'"; 
    $stmts = $conn->prepare($olgaquerys);
    if($stmts->execute()){

      $_SESSION["contact_status"] = '34' ;
      
       header("location:../contact-form.php");

      }
     }else{
          $olgaquerys="UPDATE contact_master SET createdIp='$myIp',datecreated='$dateceated',banner_image='$add_data',hubspot='$contact' "; 
    $stmts = $conn->prepare($olgaquerys);
    if($stmts->execute()){

      $_SESSION["contact_status"] = '34' ;
      
         header("location:../contact-form.php");
    }
     }
 
   }
         
        // show error
        catch(PDOException $exception){
            die('ERROR: ' . $exception->getMessage());
        }
    }
  	     


 


?>