<? 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];
        
        $registrant_sn = $result['registrant_sn'];
        $registrant_fullname = $result['registrant_fullname'];
        $email = $result['registrant_email'];
        $registrant_time = $result['registrant_time'];


        $qrcode = "<img src='http://www.events-sp.com/PSTADinner/generateqr.php?num=".$registrant_sn."'>";

        $message = str_replace("@registrant_sn@",$registrant_sn,$message);
        $message = str_replace("@registrant_fullname@",$registrant_fullname,$message);
        $message = str_replace("@qr_code@",$qrcode,$message);
        $message = str_replace("@registrant_time@",$registrant_time,$message);

        $mail->IsHTML(true);
        $mail->SetFrom("a-star_PSTA@scei.a-star.edu.sg","PSTA 2016");
        $mail->AddAddress($email);
        $mail->Subject = $subject;
        $mail->Body = $message;
        $mail->Send(); // send message

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

        //echo "1";
        
    }


?>