Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -12,48 +12,60 @@
|
||||
namespace IPS\nexus\modules\front\clients;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\Dispatcher\Controller;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\Number;
|
||||
use IPS\Helpers\Form\Radio;
|
||||
use IPS\Helpers\Form\YesNo;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Member;
|
||||
use IPS\nexus\Customer;
|
||||
use IPS\nexus\Donation\Goal;
|
||||
use IPS\nexus\extensions\nexus\Item\Donation;
|
||||
use IPS\nexus\Invoice;
|
||||
use IPS\nexus\Money;
|
||||
use IPS\Output;
|
||||
use IPS\Request;
|
||||
use IPS\Theme;
|
||||
use OutOfRangeException;
|
||||
use function count;
|
||||
use function defined;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Donations
|
||||
*/
|
||||
class _donations extends \IPS\Dispatcher\Controller
|
||||
class donations extends Controller
|
||||
{
|
||||
/**
|
||||
* View List
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
protected function manage() : void
|
||||
{
|
||||
if ( isset( \IPS\Request::i()->id ) )
|
||||
if ( isset( Request::i()->id ) and !Request::i()->isAjax() )
|
||||
{
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=nexus&module=clients&controller=donations', 'front', 'clientsdonations' ) );
|
||||
}
|
||||
Output::i()->redirect( Url::internal( 'app=nexus&module=clients&controller=donations', 'front', 'clientsdonations' ) );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->breadcrumb[] = array( \IPS\Http\Url::internal( 'app=nexus&module=clients&controller=donations', 'front', 'clientsdonations' ), \IPS\Member::loggedIn()->language()->addToStack('client_donations') );
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('client_donations');
|
||||
\IPS\Output::i()->sidebar['enabled'] = FALSE;
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'donations.css' ) );
|
||||
Output::i()->breadcrumb[] = array( Url::internal( 'app=nexus&module=clients&controller=donations', 'front', 'clientsdonations' ), Member::loggedIn()->language()->addToStack('client_donations') );
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack('client_donations');
|
||||
Output::i()->sidebar['enabled'] = FALSE;
|
||||
|
||||
/* "Nowt 'ere lad, may as well knock it over tut 404" - Marc */
|
||||
if( \count( \IPS\nexus\Donation\Goal::roots() ) === 0 )
|
||||
if( count( Goal::roots() ) === 0 )
|
||||
{
|
||||
\IPS\Output::i()->error( 'nexus_no_donations_found', '1X238/2', 404, '' );
|
||||
Output::i()->error( 'nexus_no_donations_found', '1X238/2', 404, '' );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('clients')->donations();
|
||||
Output::i()->output = Theme::i()->getTemplate('clients')->donations();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,45 +73,80 @@ class _donations extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function donate()
|
||||
public function donate() : void
|
||||
{
|
||||
if( !\IPS\Member::loggedIn()->member_id )
|
||||
if( !Member::loggedIn()->member_id )
|
||||
{
|
||||
\IPS\Output::i()->error( 'no_module_permission_guest', '1X238/3', 403, '' );
|
||||
Output::i()->error( 'no_module_permission_guest', '1X238/3', 403, '' );
|
||||
}
|
||||
try
|
||||
{
|
||||
$goal = \IPS\nexus\Donation\Goal::load( \IPS\Request::i()->id );
|
||||
$goal = Goal::load( Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X238/1', 404, '' );
|
||||
Output::i()->error( 'node_error', '2X238/1', 404, '' );
|
||||
}
|
||||
|
||||
$form = new \IPS\Helpers\Form( 'donate', 'donate' );
|
||||
$form->class = 'ipsForm_vertical';
|
||||
if ( !isset( \IPS\Request::i()->noDesc ) and $desc = \IPS\Member::loggedIn()->language()->get("nexus_donategoal_{$goal->id}_desc") )
|
||||
$form = new Form( 'donate', 'donate' );
|
||||
$form->class = 'ipsForm--vertical ipsForm--donate';
|
||||
if ( !isset( Request::i()->noDesc ) and $desc = Member::loggedIn()->language()->get("nexus_donategoal_{$goal->id}_desc") )
|
||||
{
|
||||
$form->addMessage( $desc, '', FALSE );
|
||||
}
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'donate_amount', 0, TRUE, array( 'decimals' => TRUE, 'min' => 0.01 ), NULL, NULL, $goal->currency ) );
|
||||
|
||||
|
||||
/* Work out what our options are */
|
||||
$options = array();
|
||||
|
||||
if( $goal->suggestions )
|
||||
{
|
||||
foreach ( json_decode( $goal->suggestions ) as $suggestion )
|
||||
{
|
||||
$options[ $suggestion ] = new Money( $suggestion, $goal->currency );
|
||||
}
|
||||
}
|
||||
|
||||
if ( empty( $options ) )
|
||||
{
|
||||
$form->add( new Number( 'donate_amount', 0, TRUE, array( 'decimals' => TRUE, 'min' => 0.01 ), NULL, NULL, $goal->currency ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( $goal->suggestions_open )
|
||||
{
|
||||
$options['x'] = Member::loggedIn()->language()->addToStack('other');
|
||||
}
|
||||
|
||||
$form->add( new Radio( 'donate_amount', NULL, TRUE, array( 'options' => $options, 'parse' => 'normal', 'userSuppliedInput' => 'x' ) ) );
|
||||
}
|
||||
|
||||
$form->add( new YesNo( 'donate_anonymous', FALSE ) );
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
$item = new \IPS\nexus\extensions\nexus\Item\Donation( \IPS\Member::loggedIn()->language()->get( 'nexus_donategoal_' . $goal->_id ), new \IPS\nexus\Money( $values['donate_amount'], $goal->currency ) );
|
||||
$item->id = $goal->_id;
|
||||
|
||||
$invoice = new \IPS\nexus\Invoice;
|
||||
$invoice->member = \IPS\nexus\Customer::loggedIn();
|
||||
$invoice->currency = $goal->currency;
|
||||
$invoice->addItem( $item );
|
||||
$invoice->return_uri = 'app=nexus&module=clients&controller=donations&thanks=1';
|
||||
$invoice->save();
|
||||
|
||||
\IPS\Output::i()->redirect( $invoice->checkoutUrl() );
|
||||
if( !is_numeric( $values['donate_amount'] ) )
|
||||
{
|
||||
$form->error = Member::loggedIn()->language()->addToStack( 'donation_invalid_amount' );
|
||||
}
|
||||
|
||||
if( !$form->error )
|
||||
{
|
||||
$item = new Donation( Member::loggedIn()->language()->get( 'nexus_donategoal_' . $goal->_id ), new Money( $values['donate_amount'], $goal->currency ) );
|
||||
$item->id = $goal->_id;
|
||||
$item->extra = array( 'anonymous' => $values['donate_anonymous'] );
|
||||
|
||||
$invoice = new Invoice;
|
||||
$invoice->member = Customer::loggedIn();
|
||||
$invoice->currency = $goal->currency;
|
||||
$invoice->addItem( $item );
|
||||
$invoice->return_uri = 'app=nexus&module=clients&controller=donations&thanks=1';
|
||||
$invoice->save();
|
||||
|
||||
Output::i()->redirect( $invoice->checkoutUrl() );
|
||||
}
|
||||
}
|
||||
|
||||
\IPS\Output::i()->title = $goal->_title;
|
||||
\IPS\Output::i()->output = $form->customTemplate( array( \IPS\Theme::i()->getTemplate( 'forms', 'core' ), 'popupTemplate' ) );
|
||||
Output::i()->title = $goal->_title;
|
||||
Output::i()->output = $form->customTemplate( array( Theme::i()->getTemplate( 'forms', 'core' ), 'popupTemplate' ) );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user