<? include ("../settings.php"); ?>
<? include ("session.php"); ?>
<?
    if (isset($_REQUEST['registrant_id']) && $_REQUEST['registrant_id']>0){
        
        $bind = array(":search1"=>$_REQUEST['email_id']);
        
        $emails = $db->select("tbl_email", "email_id = :search1", $bind);
        $emailtemplate = $emails[0];
        $subject = $emailtemplate['email_subject'];
        $message = $emailtemplate['email_content'];

        $mail->ClearAddresses();
        $bind = array(":search1"=>$_REQUEST['registrant_id']);
        $results = $db->select("tbl_registrant","registrant_id=:search1",$bind);
        $result = $results[0];
		$date = date("d-m-Y");
            $subject = $emailtemplate['email_subject'];
            $message = $emailtemplate['email_content'];
            $registrant_sn = $result['registrant_sn'];
			$registrant_salutation = $result['registrant_salutation'];
			$registrant_fullname = $result['registrant_fullname'];
			$registrant_organisation = $result['registrant_organisation'];
			$registrant_papernumber = $result['registrant_papernumber'];
			$presentdate = $result['presentdate'];
			$presenttime = $result['presenttime'];
			$presentvenue = $result['presentvenue'];
			if ($result['registrant_cocktail_attend']==1)
				$registrant_cocktail_attend = "Yes";
			else
				$registrant_cocktail_attend = "No";
			$registrant_extra_cocktail = $result['registrant_extra_cocktail'];
			if ($result['registrant_dinner_attend']==1)
				$registrant_dinner_attend = "Yes";
			else
				$registrant_dinner_attend = "No";
			$registrant_extra_dinner = $result['registrant_extra_dinner'];
			$registrant_diet = $result['registrant_diet'];
			$email = $result['registrant_email'];

            $qrcode = "<img src='http://www.events-sp.com/SICC9/generateqr.php?num=".$registrant_sn."'>";
			
			$message = str_replace("@date@",$date,$message);
            $message = str_replace("@registrant_sn@",$registrant_sn,$message);
            $message = str_replace("@registrant_salutation@",$registrant_salutation,$message);
            $message = str_replace("@registrant_fullname@",$registrant_fullname,$message);
			$message = str_replace("@registrant_organisation@",$registrant_organisation,$message);
			$message = str_replace("@registrant_papernumber@",$registrant_papernumber,$message);
			$message = str_replace("@presentdate@",$presentdate,$message);
			$message = str_replace("@presenttime@",$presenttime,$message);
			$message = str_replace("@presentvenue@",$presentvenue,$message);
			$message = str_replace("@registrant_cocktail_attend@",$registrant_cocktail_attend,$message);
			$message = str_replace("@registrant_extra_cocktail@",$registrant_extra_cocktail,$message);
			$message = str_replace("@registrant_dinner_attend@",$registrant_dinner_attend,$message);
			$message = str_replace("@registrant_extra_dinner@",$registrant_extra_dinner,$message);
            $message = str_replace("@qr_code@",$qrcode,$message);

		$mail->IsHTML(true);
		$mail->SetFrom("sylvia@sicc9.org","SICC9 Conference Secretariat");
		$mail->ClearAllRecipients();
		$mail->AddAddress($email);
		$mail->Subject = $subject;
		$mail->Body = $message;
		$mail->Send(); // send message

        // Update Email Sent
        $bind = array(":search1"=>$result['registrant_id']);
        $update = array("email_sent"=>1);
        $db->update("tbl_registrant",$update,"registrant_id=:search1",$bind);
        echo "1";
        
        
        //$mail->Send();       

        //echo "1";
        
    }


?>