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

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







if ((isset($_POST['inquiry'])) || (isset($_POST['ebook'])))  {
$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['ebook'];
        //   $data_value = json_encode($data);
            $data_value = base64_encode(json_encode($data)); // Added by developer
        	$sql = "INSERT INTO ebook(ebook,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  `ebook` WHERE id=$new_id"; 

   
      $result = $conn->query($sql1);
      
      if($result) {
    $return = array();
    while($row = $result->fetch_assoc()) {
      $return = $row;
    // $data_value = json_decode($return['ebook']);
    $data_value = json_decode(base64_decode($return['ebook'])); // Added by developer
    
         }
  } else {
    $return = array();
  }

$to = "brief@paradigmappstudio.com";

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

$message = "
<html>
<head>
<title>E-BOOK - Form</title>
</head>
<body>

<div style='margin-top:-10px'>
      <p>Hi, <br> <br> Use Below URL to access E-book details for</p>
      <p style='line-height: 1.2;'><b>Name</b>: $data_value->company_name</p>
      <p style='line-height: 1.2;'><b>Email</b>: $data_value->company_email</p>
      <p style='line-height: 1.2;'><b>Zib</b>: $data_value->company_zip</p>
      <p style='line-height: 1.2;'><b>Phone</b>: $data_value->company_phone</p>
      <p style='line-height: 1.2;'><b>Brief</b>: $data_value->company_brief</p>
      <p><b>url</b>: https://paradigmappstudio.com/questionnaire/ebook/show_data.php?id=$new_id</p><br>
       <p>Thank you <br><br>Regards,<br><br>E-BOOK</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');
 }

 }

?>