<html>
<head>
<script src="alertify.js"></script>
<link rel="stylesheet" href="alertify.css" />
<link rel="stylesheet" href="alertify.default.css" />
</head>
<body>
<?php
 
$city1 = $addrDetailsArr['geoplugin_city']; 

$country1 = $addrDetailsArr['geoplugin_countryName'];

if(!$city1){
   $city1='Not Define';
}if(!$country1){
   $country1='Not Define';
}

$ip_address11 = explode(".", $ip_address);
$ip_address21 = implode("", $ip_address11);

$time1 = explode(":", date('Y:m:d H:i:s'));
$time11 = implode("", $time1);

$Finish_Pro = $time11." ".$ip_address21;

$Finish_Pro1 = explode(" ", $Finish_Pro);
$Finish_Pro2 = implode("%20", $Finish_Pro1);

 
//get image logo image path
$logoImagePath = 'assets/gws-logo.png';
 
 //echo $logoImagePath;
 
//Get the base-64 string from data
//$filteredData=substr($_POST['img_val'], strpos($_POST['img_val'], ",")+1);
 
//Decode the string
//$unencodedData=base64_decode($filteredData);
 
//Save the image
//file_put_contents('./Final_P_Images/pdf/'.$Finish_Pro2.'.png', $unencodedData);


require('../fpdf181/fpdf.php');

$filteredData=substr($_POST['img_val'], strpos($_POST['img_val'], ",")+1);
 
//Decode the string
$unencodedData=base64_decode($filteredData);

$Final_Images = $_POST['img_val']; 

class PDF extends FPDF
{
    
//     private $logo = false;
// 	function __construct($logoImagePath) {
// 		parent::__construct();
// 		$this->logo = $logoImagePath;
// 		//print "In BaseClass constructor\n";
// 	}
// 	public  $logo;
//       function __construct($logo){
//         $this->logo = $logo;
//       }

 
    
// Page header
function Header()
{
    global $logoImagePath;
    
    // Logo
    $this->Image($logoImagePath,10,20,30);
    //$this->Image('fb-logo.jpg',10,20,30);
    // Arial bold 15
    $this->SetFont('Arial','B',15);
    // Move to the right
    $this->Cell(80);
    // Title
    //$this->Cell(30,10,'Title',1,0,'C');
    // Line break
    $this->Ln(20);
}

// Page footer
function Footer()
{
    // Position at 1.5 cm from bottom
    $this->SetY(-15);
    // Arial italic 8
    $this->SetFont('Arial','I',8);
    // Page number
    //$this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
	$this->Cell(0,10,'Footer',0,0,'C');
}
}

// Instanciation of inherited class
$pdf = new PDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Times','',12);
$pdf->Image($Final_Images,10,40);
//for($i=1;$i<=40;$i++)
    //$pdf->Cell(0,10,'Printing line number '.$i,0,1);
$dir = "./Final_P_Images/pdf/";
$filename = $Finish_Pro2.".pdf";

$pdf->Output($dir.$filename,'F');
$pdfdoc = $pdf->Output($dir.$filename,'S');

 $pdf_file_name=$filename;
 $pdf_content = $pdfdoc;
 
 
/*if(isset($_POST['g-recaptcha-response']) && $_POST['g-recaptcha-response']){
	$secret = "6LfbZDMUAAAAANuqLaKz5MHaIMYEpab-IBPweQRD";
	$ip = $_SERVER['REMOTE_ADDR'];
	$captcha = $_POST['g-recaptcha-response'];
	$rsp = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=$secret&response=$captcha&remoteip$ip");
	$arr = json_decode($rsp,TRUE);
	if($arr['success']){*/
		
		 function inEmail($email) {
			return(preg_match("/^[-_.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])/.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i",$email));
		}

		if (!defined("PHP_EOL")) define("PHP_EOL", "\r\n");
			
		if ('POST' === $_SERVER['REQUEST_METHOD'])   {
		if(empty($_POST['name']) || empty($_POST['email']) || empty($_POST['phone'])  ) {
		echo "Error";
		
		} else {						
			$name = trim($_POST['name']);
			$email = trim($_POST['email']);
			$phone = trim($_POST['phone']);
			$mess = trim($_POST['message']);
			
			//$to = "help@gunwebsystems.com.au";
			$to ="prabavicknesh@gmail.com";
		    $cc = $email;

			/*info@workwearexpress.com*/
			
			$from = "vicknesh.ex@gmail.com";
			$subject = "Gun Web Systems Editor";
			
			$headers = "From: $from";
			
			
			$semi_rand = md5( time() ); 
			$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; 
			
			$headers .= "\nMIME-Version: 1.0\n" . 
						"Content-Type: multipart/mixed;\n" . 
						" boundary=\"{$mime_boundary}\"". "\r\n";
						 
			$headers .= "Cc: $cc";
			//$headers .= "Reply-To: $from";
						
			//$d_body = "You have been contacted by $fname with regards to $phone, their additional message is as follows." . PHP_EOL . PHP_EOL;
			$d_duration     = "Name               : $name". PHP_EOL . PHP_EOL;
			$d_hours        = "E-mail          : $email". PHP_EOL . PHP_EOL;
			$d_cleaners     = "Phone         : $phone". PHP_EOL . PHP_EOL;
			$d_materials    = "Message     : $mess". PHP_EOL . PHP_EOL;

			$body = wordwrap($d_duration . $d_hours . $d_cleaners . $d_materials, 70);

				$message = $body;
				
				$message .= "This is a multi-part message in MIME format.\n\n" . 
						"--{$mime_boundary}\n" . 
						"Content-Type: text/plain; charset=\"iso-8859-1\"\n" . 
						"Content-Transfer-Encoding: 7bit\n\n" . 
						$message . "\n\n";
						
						
				$fileatttype = "application/pdf"; 
				$pdf_content = chunk_split(base64_encode($pdf_content));
				
				
						 
				$message .= "--{$mime_boundary}\n" . 
						 "Content-Type: {$fileatttype};\n" . 
						 " name=\"{$pdf_file_name}\"\n" . 
						 "Content-Disposition: attachment;\n" . 
						 " filename=\"{$pdf_file_name}\"\n" . 
						 "Content-Transfer-Encoding: base64\n\n" . 
						 $pdf_content . "\n\n" . 
						 "--{$mime_boundary}--\n"; 
					

			if(mail($to, $subject, $message, $headers) ) {

			// Email has sent successfully, echo a success page.
				//echo '<script>alertify.success("Your E-mail has been sent successfully!");</script>';
				//echo "<script>window.open('".$currentURL."','_self')</script>";
				header("Location: index.html?msg=success");
				exit;


			} else {
				//echo '<script>alertify.success("Unable to send E-mail?");</script>';
				//echo "<script>window.open('index.php','_self')</script>";
				header("Location: index.html?msg=ERROR");
				exit;

			 }
		}}
	/*}
	
	else{
		echo '<script>alertify.success("Please make sure your not a robot?");</script>';
	}
}	*/







    

?>
</body>
</html>