<?php
//ini_set('display_errors', 1);
//ini_set('display_startup_errors', 1);
//error_reporting(E_ALL);
require_once "sleekdb/SleekDB.php"; 
$dataDir = "mydb";

if($_POST){

    $name = $_POST['name'];
	$email = $_POST['email'];
	$contact = $_POST['contact'];
	$age = $_POST['age'];
	$gender = $_POST['gender'];
	$package = $_POST['package'];
	$date = date('Y-m-d H:i:s');

	
	$honeypot = $_POST['mainfield'];
	//check if the honeypot field is filled out. If not, send a mail.
	if ( !empty($honeypot) ) {
		//return; 
	}else{
	    
	    
	    
if($package=="Standard Package") {
$amount="10000";    

} else {

$amount="15000";        

}

	    $newsStore = \SleekDB\SleekDB::store('jpdb', $dataDir);
$guid=GUID();
$ipaddress=get_client_ip();
$newsInsertable = [
    "name" => $name,
    "package" => $package,
    "email" => $email,
    "contact" => $contact,
    "age" => $age,
    "gender" => $gender,
    "date" => $date,
    "amount" => $amount,
    "ipaddress" => $ipaddress,
    "guid" => $guid
];
$results = $newsStore->insert( $newsInsertable ); 

?>

<form id="paypalform" action="https://www.paypal.com/cgi-bin/webscr" method="post">

  <!-- Identify your business so that you can collect the payments. -->
    <input type="hidden" name="business"
        value="protanjapan@gmail.com">

    <!-- Specify a Donate button. -->
	<!--
    <input type="hidden" name="cmd" value="_donations">
--><input type="hidden" name="cmd" value="_xclick">
    <!-- Specify details about the contribution -->
    <input type="hidden" name="item_name" value="<?php echo $package ; ?>">
    <input type="hidden" name="item_number" value="<?php echo $package . "-" . $guid; ?>">
    <input type="hidden" name="amount" value="<?php echo $amount; ?>"> <!-- $5 - 5.00 -->
    <input type="hidden" name="currency_code" value="JPY">
		  
<input type="hidden" name="quantity" value="1">
    <!-- Donate button. -->	  
  	  
 <!-- Display the payment button. -->
<INPUT TYPE="hidden" name="cancel_return" value="http://www.protan-japan.com/cjbbf/">
    <input type="hidden" name="return" value="http://www.protan-japan.com/cjbbf/thankyou.php">
	 	 
	
<input class="btn btn-info button" id="Submit1" name="Submit1" type="submit" value="Buy Now" alt="Buy Now" style="display:none">
<img alt="" width="1" height="1" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" > 	
</form>


    
    <script type="text/javascript">
    document.getElementById('paypalform').submit(); // SUBMIT FORM
</script>

    

<?php 
	   // echo $honeypot . "bhareli";
	//	mail( $to, $subject, $message, $header );
	$toemail="golddragonint@protonmail.ch";
	$subject="cjbbf/" . $name  ."<br/>";
	$message="Name : " . $name;
	$message=$message . "Email : " . $email  ."<br/>";
	$message=$message . "Package : " . $package  ."<br/>";
	$message=$message . "Age : " . $age  ."<br/>";
	$message=$message . "Gender : " . $gender  ."<br/>";
	$message=$message . "Date : " . $date  ."<br/>";
	$message=$message . "Ipaddress : " . $ipaddress  ."<br/>";
	$message=$message . "Guid : " . $guid  ."<br/>";
    
     $headers .= "Reply-To: Proton Japan <info@protan-japan.com/>\r\n"; 
    $headers .= "Return-Path: Proton Japan <info@protan-japan.com>\r\n"; 
    $headers .= "From: info@protan-japan.com" ."\r\n" .
    $headers .= "Organization: Proton Japan\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset=utf-8\r\n";
    $headers .= "X-Priority: 3\r\n";
    $headers .= "X-Mailer: PHP". phpversion() ."\r\n" ;
		mail( $toemail, $subject, $message, $headers );
	}
}




function GUID()
{
    if (function_exists('com_create_guid') === true)
    {
        return trim(com_create_guid(), '{}');
    }

    return sprintf('%04X%04X-%04X-%04X-%04X-%04X%04X%04X', mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535));
}


function get_client_ip() {
    $ipaddress = '';
    if (isset($_SERVER['HTTP_CLIENT_IP']))
        $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
    else if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
        $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
    else if(isset($_SERVER['HTTP_X_FORWARDED']))
        $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
    else if(isset($_SERVER['HTTP_FORWARDED_FOR']))
        $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
    else if(isset($_SERVER['HTTP_FORWARDED']))
        $ipaddress = $_SERVER['HTTP_FORWARDED'];
    else if(isset($_SERVER['REMOTE_ADDR']))
        $ipaddress = $_SERVER['REMOTE_ADDR'];
    else
        $ipaddress = 'UNKNOWN';
    return $ipaddress;
}


?>