<?php
include("../../check.php");
include('smtp/PHPMailerAutoload.php');
require __DIR__ . '/vendor/vendor/autoload.php';



$id = $_GET['id'];

$getall = $getData->runQuery("SELECT * FROM `customer` WHERE id='$id'");
foreach($getall as $rows){
$dataaa = $rows['standard'];
$result = explode(',',$dataaa);
$counts = count($result);
$name = $rows['name'];
$address = $rows['address'];
$address2 = $rows['address2'];
$scope_of_business = $rows['scope_of_business'];
$create = date('Y-m-d', strtotime($rows['date']));
}



use setasign\Fpdi\Fpdi;

<?php
include("../../check.php");
include('smtp/PHPMailerAutoload.php');
require __DIR__ . '/vendor/vendor/autoload.php';

use setasign\Fpdi\Fpdi;

$id = $_GET['id'];

$getall = $getData->runQuery("SELECT * FROM `customer` WHERE id='$id'");
foreach($getall as $rows){
$dataaa = $rows['standard'];
$result = explode(',',$dataaa);
$counts = count($result);
$name = $rows['name'];
$address = $rows['address'];
$address2 = $rows['address2'];
$scope_of_business = $rows['scope_of_business'];
$create = date('Y-m-d', strtotime($rows['date']));
}

// initiate FPDI
/* This is for BMG */
if ($_GET['body'] == 14) {
	//echo "string";
	$p_id = $_GET['body'];
	$pdf = $getData->runQuery("SELECT * FROM `bodies_tbl` WHERE id='$p_id'");
	$pdf_im = $pdf[0]['pdf'];
	//echo __DIR__ ."../pdf/".$pdf_im;
	$pdf = new Fpdi();
	$pdf->AddPage(); // adds page in landscape
	$pdf->setSourceFile("../bodies/pdf/".$pdf_im);
	// import page 1
	$tplId = $pdf->importPage(1);
	// use the imported page and place it at point 5,5 with your preferred width in mm
	$pdf->useTemplate($tplId, 0, 0, 211);
	$pdf->SetFont('Arial','B',20); // Font Name, Font Style (eg. 'B' for Bold), Font Size
	$pdf->SetTextColor(0,0,0); // RGB

	$pdf->SetXY(55, 84); // X start, Y start in mm

	$pdf->Cell(100, 10, $name, 0, 0, 'C');

	$pdf->SetFont('Arial','',16); // Font Name, Font Style (eg. 'B' for Bold), Font Size

	$pdf->SetXY(47, 99); // X start, Y start in mm
	$pdf->MultiCell(120,7,$address.$address2,0,'C', false);

	$pdf->SetFont('Arial','B',38);
	$pdf->SetXY(58, 146); // X start, Y start in mm

	$pdf->Cell(80, 10, $_GET['st'], 0, 0, 'L');


	$pdf->SetFont('Arial','B',20);
	$pdf->SetXY(47, 175); // X start, Y start in mm

	$pdf->MultiCell(120,7,$scope_of_business,0,'C', false);


	/**/
	$pdf->SetFont('Arial','B',12);
	$pdf->SetXY(110, 196); 
	$pdf->Cell(70, 10, "Draft", 0, 0, 'L');
	/**/
	// adds current date
	$pdf->SetFont('Arial','B',12); 
	$pdf->SetTextColor(0,0,0); 
	$pdf->SetXY(55, 212); 


	$showdate = date('d/m/Y', strtotime($create));
	$date = date('Y-m-d', strtotime($create));
	$pdf->Write(0, $showdate);

	$end = date('Y-m-d', strtotime('+3 years', strtotime($date)));
	$end = date('Y-m-d', strtotime($end));
	$end2= strtotime($end);
	$finalend = date('d/m/Y', strtotime('-1 days', $end2));

	$pdf->SetXY(55, 216); 
	$pdf->Write(0, $finalend);

	$first = date('Y-m-d', strtotime('+1 year', strtotime($date)));
	$first = date('d/m/Y', strtotime('-1 days', strtotime($first)));

	$pdf->SetXY(158, 212); 
	$pdf->Write(0, $first);

	$second = date('Y-m-d', strtotime('+2 year', strtotime($date)));
	$second = date('d/m/Y', strtotime('-1 days', strtotime($second)));

	$pdf->SetXY(158, 216); 
	$pdf->Write(0, $second);
}

if ($_GET['body'] == 15) {
	$p_id = $_GET['body'];
	$pdf = $getData->runQuery("SELECT * FROM `bodies_tbl` WHERE id='$p_id'");
	$pdf_im = $pdf[0]['pdf'];

	$pdf = new Fpdi();
	$pdf->AddPage(); // adds page in landscape
	$pdf->setSourceFile("../bodies/pdf/".$pdf_im);
	// import page 1
	$tplId = $pdf->importPage(1);
	// use the imported page and place it at point 5,5 with your preferred width in mm
	$pdf->useTemplate($tplId, 0, 0, 211);
	$pdf->SetFont('Arial','I',20); // Font Name, Font Style (eg. 'B' for Bold), Font Size
	$pdf->SetTextColor(0,0,0); // RGB

	$pdf->SetXY(50, 80); // X start, Y start in mm
	$pdf->Cell(150, 10, 'Quality Management System of', 0, 0, 'C');

	$pdf->SetXY(50, 96); // X start, Y start in mm
	$pdf->Cell(150, 10, $name, 0, 0, 'C');

	$pdf->SetFont('Arial','',16); // Font Name, Font Style (eg. 'B' for Bold), Font Size

	$pdf->SetXY(65, 114); // X start, Y start in mm
	$pdf->MultiCell(120,7,$address.' '.$address2,0,'C', false);

	$pdf->SetFont('Arial','B',38);
	$pdf->SetXY(78, 153); // X start, Y start in mm

	$pdf->Cell(80, 10, $_GET['st'], 0, 0, 'L');


	$pdf->SetFont('Arial','B',20);
	$pdf->SetXY(64, 182); // X start, Y start in mm

	$pdf->MultiCell(120,7,$scope_of_business,0,'C', false);


	/**/
	$pdf->SetFont('Arial','B',12);
	$pdf->SetXY(145, 208.5); 
	$pdf->Cell(70, 10, "Draft", 0, 0, 'L');
	/**/
	// adds current date
	$pdf->SetFont('Arial','B',12); 
	$pdf->SetTextColor(0,0,0); 
	$pdf->SetXY(76, 231); 

	$create = date('Y-m-d');

	$showdate = date('d/m/Y', strtotime($create));
	$date = date('Y-m-d', strtotime($create));
	$pdf->Write(0, $showdate);

	$end = date('Y-m-d', strtotime('+3 years', strtotime($date)));
	$end = date('Y-m-d', strtotime($end));
	$end2= strtotime($end);
	$finalend = date('d/m/Y', strtotime('-1 days', $end2));

	$pdf->SetXY(76, 236); 
	$pdf->Write(0, $finalend);

	$first = date('Y-m-d', strtotime('+1 year', strtotime($date)));
	$first = date('d/m/Y', strtotime('-1 days', strtotime($first)));

	$pdf->SetXY(174, 231); 
	$pdf->Write(0, $first);

	$second = date('Y-m-d', strtotime('+2 year', strtotime($date)));
	$second = date('d/m/Y', strtotime('-1 days', strtotime($second)));

	$pdf->SetXY(174, 236); 
	$pdf->Write(0, $second);
}




$msg = "This is certificate";
$subject = "certificate";
$to = $_GET['email'];
$mail = new PHPMailer(); 
$mail->SMTPDebug  = 3;
$mail->CharSet = 'UTF-8';
$mail->SetFrom("shekherphp@gmail.com",  'United Web fox');
$mail->AddReplyTo("shekherphp@gmail.com","United Web fox");
$mail->Subject = $subject;
$mail->Body = $msg;
$mail->SMTPDebug  = 3;
$mail->AddAddress($to);

echo "string";
$mail->addStringAttachment($pdf->Output("S",'certificate.pdf'), 'certificate.pdf', $encoding = 'base64', $type = 'application/pdf');
/*$mail->SMTPOptions=array('ssl'=>array(
	'verify_peer'=>false,
	'verify_peer_name'=>false,
	'allow_self_signed'=>false
));*/
if(!$mail->Send()){
	echo $mail->ErrorInfo;
}else{
	echo "string";
	$_SESSION['message']="<span class='text-success'>Email sent successfully</span>";
	header("Location: customer.php");
}


?>