<?php
if (!defined('FLUX_ROOT')) exit;

$this->loginRequired();

$title = 'Donation Form Verification Request';
$preview = '';

if (count($_POST)) {
	$prev    	= (bool)$params->get('_preview');
	$to      	= trim($params->get('to'));
	$option  	= trim($params->get('option'));
	$subject 	= trim($params->get('subject'));
	$name    	= trim($params->get('name'));
	$amount    	= trim($params->get('amount'));
	$reference    	= trim($params->get('reference'));
	$mobile   	 = trim($params->get('mobile'));
	$tmpl = "<p>Option: ".$option."</p>";
	$tmpl .= "<p>Name: ".$name."</p>";
	$tmpl .= "<p>Amount: ".$amount."</p>";
	$tmpl .= "<p>Reference: ".$reference."</p>";
	$tmpl .= "<p>Mobile: ".$mobile."</p>";

	if (empty($errorMessage)) {
		if ($prev) {
			require_once 'markdown/markdown.php';
			$preview = Markdown($tmpl);
		}
		else {
			require_once 'Flux/Mailer.php';
			
			$mail = new Flux_Mailer();
			$opts = array('_ignoreTemplate' => true, '_useMarkdown' => true);
			
			if ($mail->send($to, $subject, $tmpl, $opts)) {
				$session->setMessageData(sprintf(Flux::message('MailerEmailHasBeenSent'), $to));
				//$this->redirect();
			}
			else {
				$errorMessage = Flux::message('MailerFailedToSend');
			}
		}
	}
}
?>