<?php 
Function make()
{
   
    $ret = "<html>" . 
	"<body>" . 
	"<b> " .  strtoupper(mysql_escape_string($_POST['myName'])) . " has answered 28/28 on his/her quiz.</b><br/><br/>" . 
	"Company: " . mysql_escape_string($_POST['company']) . "<br/>" .
	"Position: " . mysql_escape_string($_POST['position']) . "<br/>" .
	"ABN: " . mysql_escape_string($_POST['abn']) . "<br/>" .
	"Mobile: " . mysql_escape_string($_POST['mobile']) . "<br/>" .
	"Email: " . mysql_escape_string($_POST['email']) . "<br/>".
	"License: " . mysql_escape_string($_POST['lic']) . "<br/>" .
	"</body>" . "</html>";
    
    return $ret;
    
    
    
}
function mailOut($to, $from, $from_name, $subject, $body, $file)
{
	//echo "entered";


	require("class.phpmailer.php");

		//echo "entered2";
	
	$mail = new PHPMailer();

	$mail->IsSMTP(true);                                      // set mailer to use SMTP
	$mail->Host = "smtp.gmail.com";  // specify main and backup server
	$mail->SMTPAuth = true;     // turn on SMTP authentication
	$mail->Username = "realcompemail@gmail.com";  // SMTP username
    $mail->Password = "BrentAnos7282!!"; // SMTP password
	$mail->SMTPSecure = "ssl"; // secure transfer enabled REQUIRED for GMail
	$mail->SMTPDebug = 1;
	$mail->Port = 465;


	$mail->From = $from; //
	$mail->FromName = $from_name; //
	
	 
	$pieces = explode(";", $to);
	
	foreach ($pieces as &$value) 
	{
		if (strlen($value) != 0)
			$mail->AddAddress($value, $value);
	}
	
	
	//$mail->AddAddress($to, $to); // this should be the user's email address
	
	
	//$mail->AddBCC("jocc@hotmail.com"); // this should be the office email address

	$mail->WordWrap = 100;                                 // set word wrap to 50 characters
	$mail->AddAttachment($file);         // add attachments
	//$mail->AddAttachment("/tmp/image.jpg", "new.jpg");    // optional name
	$mail->IsHTML(true);                                  // set email format to HTML

	$mail->Subject = $subject; //"Here is the subject";
	$mail->isHTML(true);
	$mail->Body    = $body; //"This is the HTML message body <b>in bold!</b>";
	//$mail->AltBody = "This is the body in plain text for non-HTML mail clients";

		//echo "entered3";
	
	if(!$mail->Send())
	{
		//echo "Message could not be sent. <p>";
		//echo "Mailer Error: " . $mail->ErrorInfo;
		//exit;
	}

	//echo "Message has been sent";

}





        $cookie_name = "user_cb";

if(!isset($_COOKIE[$cookie_name])) {
   // echo "Cookie named '" . $cookie_name . "' is not set!";
        header('Location: quiz-login.php');
        exit;
} else {
    //echo "Cookie '" . $cookie_name . "' is set!<br>";
    //echo "Value is: " . $_COOKIE[$cookie_name];
}




$examId = $_GET['e'];
$name = mysql_escape_string($_POST['myName']);
$company = mysql_escape_string($_POST['company']);
$position = mysql_escape_string($_POST['position']);
$abn = mysql_escape_string($_POST['abn']);
$mobile = mysql_escape_string($_POST['mobile']);
$email = mysql_escape_string($_POST['email']);
$lic = mysql_escape_string($_POST['lic']);

$name = strtoupper($name);





$myfile = fopen("certs/CERTIFICATE-" . $name . ".doc", "w") or die("Unable to open file!");

$txt =  "<html
    xmlns:o='urn:schemas-microsoft-com:office:office'
    xmlns:w='urn:schemas-microsoft-com:office:word'
    xmlns='http://www.w3.org/TR/REC-html40'>
    <head>";

   $txt = $txt . " <title>CERTIFICATE</title>
        <!--[if gte mso 9]-->
    <xml>
        <w:WordDocument>
            <w:View>Print</w:View>
            <w:Zoom>90</w:Zoom>
            <w:DoNotOptimizeForBrowser/>
        </w:WordDocument>
    </xml>
    <!-- [endif]-->
    <style>
        p.MsoFooter, li.MsoFooter, div.MsoFooter{
            margin: 0cm;
            margin-bottom: 0020pt;
            mso-pagination:widow-orphan;
            font-size: 9.0 pt;
            text-align: right;
        }


        @page Section1{
              size:21cm 29.7cmt; 
    margin:1cm 1cm 1cm 1cm;  
    mso-page-orientation: portrait;  
            mso-footer:f1;
        }
        div.Section1 { page:Section1;}
		
		
    </style>";

	$txt = $txt . '<div class="Section1" style=\'font-family:arial; font-size:20pt;\'>';
	$txt = $txt . "<br/><br/><table width='100%'><tr>
	<td valign='top' width='100%' style=\'font-family:arial; font-size:20pt;\'>
	<center><img height='50%' src='http://carbonblue.com.au/logo.png' /></center><br/><br/><br/>
	<div style='font-size:26pt;font-family:arial;'><b><center>VEET Installer Induction Completion</center></b></div><br/><br/>
	<div style='font-size:12pt;font-family:arial;'>This document certifies that: <b>" . $name . "</b>,
has undergone practical training of commercial lighting upgrades carried out under the VEET Energy Savings Scheme by Carbon Blue.<br/><br/>
This training was completed on the: <b>" . date("d/m/Y") . "</b><br/><br/>"; 	              		

$txt = $txt . "Training qualifies the installer under supervision to complete the following tasks in order for key documents to be created for the purpose of creating VEET Energy Saving Certificates within the Victorian Energy Efficiency Target scheme:
<ul>
<li>Customer Engagement</li>
<li>Observation of OH&S requirements</li>
<li>Photographic evidence of upgrade</li>
<li>Lighting level measurements</li>
<li>Removal, and packaging of old lamps for recycling</li>
</ul>
<br/><br/>
The trainee also acknowledges that they have received an overview of the Energy Services Commission and overview of the energy saving activity.<br/><br/>";

$txt = $txt . "<center>Trainer: Lars Lohmann " . "   Signature:  <img height='60px' src='http://carbonblue.com.au/lars.png' />  </div> 
	 </td></tr></table>";
	$txt = $txt . "</div>";
	
fwrite($myfile, $txt);
fclose($myfile);	

$sendFile = "certs/CERTIFICATE-" . $name . ".doc";

//
mailOut("nicklas@carbonblue.com.au", $name . " Quiz Result", $name . " Quiz Result", $name . " Quiz Result", make(),$sendFile);	
	
echo "<br/><br/><br/><br/><br/><center><span style='font-family:calibri;font-size:20px;'>Thanks - We have received your quiz.</span></center>";




?>