<?php

/*
 * @component UserPoints
 * @copyright Copyright (C) 2015-2016 - Bernard Gilly - Adrien Roussel
 * @license : GNU/GPL
 * @Website : https://remository.com
 */

defined('_JEXEC') or die('Restricted access');

use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route;

$doc = Factory::getDocument();
$app = Factory::getApplication();
$action = Route::_('index.php?option=com_userpoints&view=Purchase&task=payment&Itemid=' . $app->input->get('Itemid', ''), false);

//$cparams 			= ComponentHelper::getParams( 'com_userpoints' );
//$showinformations 	= $caprams->get('showinformations',1);	

$show = function ($string) {
    return htmlspecialchars($string, ENT_QUOTES, 'utf-8', false);
};

$showsymbol = function ($string) {
    return htmlspecialchars(Text::_($string), ENT_QUOTES, 'utf-8', false);
};

if ('startform' == $this->task) {
    echo <<<SETUP

        <div class="page-header">
            <h1>{$showsymbol('AUP_PURCHASE_CHOOSE_HOW_MUCH')}</h1>
	</div>
	<div id="purchase-form">
            <form action="$action" method="post" name="purchaseForm" id="purchaseForm" class="form-validate form-horizontal">
                    <p>{$show(sprintf(Text::_('AUP_PURCHASE_POINTS_FOR_UNIT'), $this->fpoints, $this->csymbol, $this->show_currency, $this->points_per_unit))}</p>
                    <label for="howmany">{$show(Text::_('AUP_PURCHASE_CHOOSE_AMOUNT'))}</label>
                    $this->csymbol <input id="howmany" name="howmany" value="0" /> $this->show_currency
                    <input type="submit" value="{$showsymbol('JSUBMIT')}" />
                    <input type="hidden" name="task" value="payment" />
                    $this->token
            </form>		
	</div>
            
SETUP;
                    
}
elseif ('payment' == $this->task) {
    echo <<<PAYMENT
    
        <div class="page-header">
            <h1>{$showsymbol('AUP_PURCHASE_MAKE_PAYMENT')}</h1>
	</div>
	<div id="purchase-form">
            <p>{$show(sprintf(Text::_('AUP_PURCHASE_POINTS_CONFIRM'), $this->csymbol, $this->payamount, $this->show_currency, $this->howmany))}</p>
            <div>$this->button_html</div>
   </div>
    
PAYMENT;
            
}
elseif ('complete' == $this->task) {
    
    echo Text::_('AUP_PURCHASE_ON_COMPLETION');
    
}
else {
    die ("Unknown task $this->task");
}
