<?php
$servername = "localhost";
$username = "graveprm_paraapp";
$password = "0m=s^TD[a8G3";
$db = "graveprm_paraapp";

// Create connection
$conn = new mysqli($servername, $username, $password , $db);

// Check connection
// if ($conn->connect_error) {
//   die("Connection failed: " . $conn->connect_error);
// }
// echo "Connected successfully";





if ((isset($_POST['inquiry'])) || (isset($_POST['company'])) || (isset($_POST['ip'])))  {
$body_att = 'colspan="2" align="left" style="background-color:#000;color:#E84704;text-align: center;"';
$body_att1 = 'colspan="2" align="left" style="background-color:#57585B;color:#fff;"';
// Get data
$data = (isset($_POST['inquiry'])) ? $_POST['inquiry'] : $_POST['company'];
        //   $data_value = json_encode($data);
          
          $data_value = base64_encode(json_encode($data)); // Added by developer
          
        	$sql = "INSERT INTO seo(seo,ip)
            VALUES('$data_value','$ipv4')";
            if ($conn->query($sql) === TRUE) {
             $new_id =  $conn->insert_id;        
            //return "true"
            // echo $new_id;
          }else{
             // return "false";
          }
    
      $ip =$_SERVER['REMOTE_ADDR'];
      $data['ip'] = $_SERVER["REMOTE_ADDR"];
      
      
   
    
    $sql1 = "SELECT * FROM  `seo` WHERE id=$new_id"; 

   
      $result = $conn->query($sql1);
      
      if($result) {
    $return = array();
    while($row = $result->fetch_assoc()) {
      $return = $row;
      
      /* Remove special character */
        // $json_data = preg_replace('/[[:cntrl:]]/', '', $return['seo']);
        // $data = json_decode($json_data, true);
    
        // if ($data === null && json_last_error() !== JSON_ERROR_NONE) {
        //     echo "Error decoding JSON: " . json_last_error_msg().$row['id']; 
        //     //die();
        // } else {
        //     $data_value = (object) $data;
        // }
        /* Remove special character */
      $data_value = json_decode(base64_decode($return['seo'])); // Added by developer
    // $data_value = json_decode($return['seo']);
    
         }
  } else {
    $return = array();
  }

$to = "brief@paradigmappstudio.com";

$subject = (isset($_POST['inquiry'])) ? "Inquiry - Form Alert" : "Search Engine Optimization  - Form";

$message = "
<html>
<head>
<title>Search Engiene Optimization - Form</title>
</head>
<body>

<div style='margin-top:-10px'>
      <p>Hi, <br> <br> Use Below URL to access Search Engiene Optimization details for</p>
      <p style='line-height: 1.2;'><b>Name</b>: $data_value->company_person_name</p>
      <p style='line-height: 1.2;'><b>Email</b>: $data_value->company_person_email</p>
      <p style='line-height: 1.2;'><b>Phone</b>: $data_value->company_phone</p>
      <p style='line-height: 1.2;'><b>Address</b>: $data_value->company_address</p>
      <p style='line-height: 1.2;'><b>Buisness</b>: $data_value->company_business</p>
      <p><b>url</b>: https://paradigmappstudio.com/questionnaire/seo/show_data.php?id=$new_id</p><br>
       <p>Thank you <br><br>Regards,<br><br>Seo</p>
      </div>";
       
  
	
$message.= "</body></html>";


//  echo $message;

// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

$headers .= 'From: Para Digm App Studio <leads@paradigmappstudio.com>' . "\r\n";
$headers .= 'Cc: info@paradigmappstudio.com' . "\r\n";

if(mail($to,$subject,$message,$headers)){
  // echo "1";
	$parm['status'] = 1;
//   echo json_encode($parm);
   header('Location: thankyou.php');
}
else{
    $parm['status'] = 0;
    // echo json_encode($parm);
     header('Location: index.php');
}

 }

?>