
<?php
include("db_connection.php");
error_reporting(E_ALL);
//print_r($_POST);
if(isset($_POST['submit'])){
 
require("pdf/fpdf.php");

//echo "<pre>"; print_r($_POST); 
class SimpleTable extends FPDF
{
    function generateData()
    {
         $this->cell(0,10,'Company Details',1,1,"C");
           $this->cell(95,10,'Company Name',1,0);
           $this->cell(95,10,$_POST['company_name'],1,1);
           $this->cell(95,10,'Year of Establishment',1,0);
           $this->cell(95,10,$_POST['year_of_establishment'],1,1);
           $this->cell(95,10,'Company Turnover',1,0);
           $this->cell(95,10,$_POST['company_turnover'],1,1);
           $this->cell(95,10,'Company Address',1,0);
           $this->cell(95,10,$_POST['company_address'],1,1);
           $this->cell(95,10,'Company Website',1,0);
           $this->cell(95,10,$_POST['company_website'],1,1);
           
        $this->cell(0,10,'CONTACT PERSON?S DETAILS',1,1,"C");  
           $this->cell(95,10,'Contact Person Name',1,0);
           $this->cell(95,10,$_POST['personal_name'],1,1);
           $this->cell(95,10,'Contact Person Designation',1,0);
           $this->cell(95,10,$_POST['personal_designation'],1,1);
           $this->cell(95,10,'Contact Number',1,0);
           $this->cell(95,10,$_POST['personal_contact_number'],1,1);
           $this->cell(95,10,'How did you come to know about Lifespan?',1,0);
           $this->cell(95,10,$_POST['personal_how_come'],1,1);
           
         $this->cell(0,10,'PRODUCT DETAILS',1,1,"C");  
           $this->cell(95,10,'Product Name',1,0);
           $this->cell(95,10,$_POST['product_name'],1,1);
           
           foreach( $_POST['product_type'] as $key=>$value){
               $product_type = $value;
               $this->cell(95,10,'Product Type',1,0);
               $this->cell(95,10,$value,1,1);
           }
           
           foreach( $_POST['product_type'] as $key=>$value){
               $product_type = $value;
               $this->cell(0,10,strtoupper($value).' DETAILS',1,1,"C");
           
               $this->cell(95,10,'If any other please specify',1,0);
           $this->cell(95,10,$_POST['if_other_product_type_'.$value],1,1);
           $this->cell(95,10,'This Product will be applied under',1,0);
           $this->cell(95,10,$_POST['product_applied_under_'.$value],1,1);
           $this->cell(95,10,'If any other please specify',1,0);
           $this->cell(95,10,$_POST['if_other_product_applied_under_'.$value],1,1);
           $this->cell(95,10,'Product Description',1,0);
           $this->cell(95,10,$_POST['product_description_'.$value],1,1);
           $this->cell(95,10,'Benchmark Products in Market (If any)',1,0);
           $this->cell(95,10,$_POST['benchmark_products_in_market_'.$value],1,1);
           $this->cell(95,10,'Tentative Label Claim/ Ingredients List',1,0);
           $this->cell(95,10,$_POST['tentative_label_claim_'.$value],1,1);
           $this->cell(95,10,'Desired Packaging Options',1,0);
           $this->cell(95,10,$_POST['desired_packaging_options_'.$value],1,1);
           $this->cell(95,10,'Do you require Lifespan to provide Logistics',1,0);
           $this->cell(95,10,$_POST['product_logistics_provided_'.$value],1,1);
           $this->cell(95,10,'Tentative Budget',1,0);
           $this->cell(95,10,$_POST['tentative_budget_'.$value],1,1);
           $this->cell(95,10,'Tentative MOQ',1,0);
           $this->cell(95,10,$_POST['tentative_moq_'.$value],1,1);
           $this->cell(95,10,'Order quantities are for',1,0);
           $this->cell(95,10,$_POST['order_quantities_are_for_'.$value],1,1);
           }
          
           $this->cell(0,10,'Others',1,1,"C");  
           
           
           $this->cell(95,10,'Any Other Specifications/queries',1,0);
           $this->cell(95,10,$_POST['other_query'],1,1);
           
  

    }
}
 
$pdf=new SimpleTable();
$pdf->AddPage();
$pdf->SetFont('Arial','B',12);
$pdf->generateData();
// open pdf file
 $pdf->Output();
//die;
 //echo "hiiiiiiiiiiiiiiii"; 
// Filename that will be used for the file as the attachment
$fileatt_name = time().".pdf";
$dir=$_SERVER['DOCUMENT_ROOT'].'/pdf_file/';  
// save pdf in directory
$pdf ->Output($dir.$fileatt_name, 'F');
//echo "Done";
//die;
//....................

 $data = $pdf->Output("", "S");

//..................
 
  $added_on = date('Y-m-d H:i:s');
            try {
                $sql = "INSERT INTO enquiry_form_1 (company_name,year_of_establishment,company_turnover,company_address,company_website,personal_name,personal_designation,personal_contact_number,personal_how_come,product_name,other_query,added_on)
                VALUES ('".$_POST['company_name']."', '".$_POST['year_of_establishment']."', '".$_POST['company_turnover']."', '".$_POST['company_address']."', '".$_POST['company_website']."', '".$_POST['personal_name']."', '".$_POST['personal_designation']."', '".$_POST['personal_contact_number']."', '".$_POST['personal_how_come']."', '".$_POST['product_name']."','".$_POST['other_query']."', '".$added_on."' )";
               // echo  $sql;// die;
                // use exec() because no results are returned
                $conn->exec($sql);
                $last_id = $conn->lastInsertId();
               foreach( $_POST['product_type'] as $key=>$value){
               $product_type = $value;
              $sql_1 = "INSERT INTO enquiry_form_1_product (e_id,product_type,if_other_product_type,product_applied_under,if_other_product_applied_under,product_description,benchmark_products_in_market,tentative_label_claim,desired_packaging_options,product_logistics_provided,tentative_budget,tentative_moq,order_quantities_are_for)
                VALUES ('".$last_id."',".$_POST['product_type_'.$value]."', '".$_POST['if_other_product_type_'.$value]."', '".$_POST['product_applied_under_'.$value]."', '".$_POST['if_other_product_applied_under_'.$value]."', '".$_POST['product_description_'.$value]."', '".$_POST['benchmark_products_in_market_'.$value]."', '".$_POST['tentative_label_claim_'.$value]."', '".$_POST['desired_packaging_options_'.$value]."', '".$_POST['product_logistics_provided_'.$value]."', '".$_POST['tentative_budget_'.$value]."', '".$_POST['tentative_moq_'.$value]."', '".$_POST['order_quantities_are_for_'.$value]."' )";
               $conn->exec($sql_1);
           }
                
                
                }
            catch(PDOException $e)
                {
                echo $sql . "<br>" . $e->getMessage();
                }
            $conn = null;       
           
            


$email_from = "noreply@lifespan.industries"; // Who the email is from
$email_subject = "Enquiry Form"; // The Subject of the email
//$email_to = "coo@lifespan.industries, nagaraju@wowsupport.in,info@lifespan.industries"; // Who the email is to
$email_to = "n.navpreet@gmail.com, nagaraju@wowsupport.in"; // Who the email is to


$semi_rand = md5(time());
$data = chunk_split(base64_encode($data));

$fileatt_type = "application/pdf"; // File Type
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

// set header ........................
$headers = "From: ".$email_from;
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";

// set email message......................
$email_message = "Enquiry Form";
$email_message .= "<br>";// Message that the email has in it
$email_message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$email_message .= "\n\n";
$email_message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data .= "\n\n" .
"--{$mime_boundary}--\n";

$sent = @mail($email_to, $email_subject, $email_message, $headers);
if($sent) {
    $_SESSION['enquiry_msg'] = 'Your email attachment send successfully';
    header('location:enquiry.php');
} else {
    $_SESSION['enquiry_msg'] = 'Please try again!';
    header('location:enquiry.php');
}
}else{
  $_SESSION['enquiry_msg'] = 'Please try again later!';
  header('location:enquiry.php');  
}

?>



