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

$this->loginRequired(Flux::message('LoginToDonate'));

$title = 'Make a Donation';

$donationAmount = false;



if (count($_POST) && $params->get('setamount')) {
	$minimum = Flux::config('MinDonationAmount');
	$amount  = (float)$params->get('amount');
	
	if (!$amount || $amount < $minimum) {
		$errorMessage = sprintf('Donation amount must be greater than or equal to %s %s!',
			$this->formatCurrency($minimum), Flux::config('DonationCurrency'));
	}
	else {
		$donationAmount = $amount;
	}

}

if (count($_POST) && $params->get('newdonation')) {
	if ($server->loginServer->applydonation($session->account->account_id)) {
		require_once 'Flux/Mailer.php';
		$mail = new Flux_Mailer();
		$email= Flux::config('PayPalBusinessEmail');
		$subject = "New Donation Request";
		$tmpl = "https://last-ro.com/?module=donate&action=approvals";
		$opts = array('_ignoreTemplate' => true, '_useMarkdown' => true);
			if ($mail->send($email, $subject, $tmpl, $opts)) {
				$this->redirect($this->url('donate'));
			}
			else {
				//$errorMessage = Flux::message('MailerFailedToSend');
			}
	}
}
if (!$params->get('setamount') && $params->get('resetamount')) {
	$this->redirect($this->url);
}

?>