Version 5.0.0 beta 1

This commit is contained in:
Neo committed 2025-12-19 16:27:35 -08:00
1 parent 25ddeb65d6
commit 15c7beabc5
6736 files changed
+627902 -497943

No files matched your search

@@ -12,63 +12,91 @@
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\Application;
use IPS\Db;
use IPS\Dispatcher\Controller;
use IPS\Helpers\Form;
use IPS\Helpers\Form\Number;
use IPS\Http\Url;
use IPS\Login;
use IPS\Member;
use IPS\nexus\Customer;
use IPS\nexus\Invoice;
use IPS\nexus\Invoice\Item\Renewal;
use IPS\nexus\Purchase;
use IPS\Output;
use IPS\Patterns\ActiveRecordIterator;
use IPS\Request;
use IPS\Session;
use IPS\Theme;
use OutOfRangeException;
use function count;
use function defined;
use function intval;
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;
}
/**
* Purchases
*/
class _purchases extends \IPS\Dispatcher\Controller
class purchases extends Controller
{
/**
* @brief Purchase object
*/
protected ?Purchase $purchase = NULL;
/**
* Execute
*
* @return void
*/
public function execute()
public function execute() : void
{
if ( !\IPS\Member::loggedIn()->member_id )
if ( !Member::loggedIn()->member_id )
{
\IPS\Output::i()->error( 'no_module_permission_guest', '2X212/6', 403, '' );
Output::i()->error( 'no_module_permission_guest', '2X212/6', 403, '' );
}
/* Purchases breadcrumb */
\IPS\Output::i()->breadcrumb[] = array( \IPS\Http\Url::internal( 'app=nexus&module=clients&controller=purchases', 'front', 'clientspurchases' ), \IPS\Member::loggedIn()->language()->addToStack('client_purchases') );
Output::i()->breadcrumb[] = array( Url::internal( 'app=nexus&module=clients&controller=purchases', 'front', 'clientspurchases' ), Member::loggedIn()->language()->addToStack('client_purchases') );
/* Load Purchase */
if ( isset( \IPS\Request::i()->id ) )
if ( isset( Request::i()->id ) )
{
try
{
$this->purchase = \IPS\nexus\Purchase::load( \IPS\Request::i()->id );
$this->purchase = Purchase::load( Request::i()->id );
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException )
{
\IPS\Output::i()->error( 'node_error', '2X212/1', 404, '' );
Output::i()->error( 'node_error', '2X212/1', 404, '' );
}
if ( !$this->purchase->canView() )
{
\IPS\Output::i()->error( 'no_module_permission', '2X212/2', 403, '' );
Output::i()->error( 'no_module_permission', '2X212/2', 403, '' );
}
\IPS\Output::i()->breadcrumb[] = array( $this->purchase->url(), $this->purchase->name );
\IPS\Output::i()->title = $this->purchase->name;
Output::i()->breadcrumb[] = array( $this->purchase->url(), $this->purchase->name );
Output::i()->title = $this->purchase->name;
}
else
{
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('client_purchases');
if ( isset( \IPS\Request::i()->do ) )
Output::i()->title = Member::loggedIn()->language()->addToStack('client_purchases');
if ( isset( Request::i()->do ) )
{
\IPS\Output::i()->error( 'node_error', '2X212/3', 403, '' );
Output::i()->error( 'node_error', '2X212/3', 403, '' );
}
}
/* Execute */
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'clients.css', 'nexus' ) );
\IPS\Output::i()->sidebar['enabled'] = FALSE;
Output::i()->cssFiles = array_merge( Output::i()->cssFiles, Theme::i()->css( 'clients.css', 'nexus' ) );
Output::i()->sidebar['enabled'] = FALSE;
parent::execute();
}
@@ -77,30 +105,29 @@ class _purchases extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function manage()
protected function manage() : void
{
$where = array( array( 'ps_member=?', \IPS\Member::loggedIn()->member_id ) );
$where = array( array( 'ps_member=?', Member::loggedIn()->member_id ) );
$parentContacts = \IPS\nexus\Customer::loggedIn()->parentContacts();
if ( \count( $parentContacts ) )
$parentContacts = Customer::loggedIn()->parentContacts();
if ( count( $parentContacts ) )
{
$or = array();
foreach ( $parentContacts as $contact )
{
$where[0][0] .= ' OR ' . \IPS\Db::i()->in( 'ps_id', $contact->purchaseIds() );
$where[0][0] .= ' OR ' . Db::i()->in( 'ps_id', $contact->purchaseIds() );
}
}
$where[] = array( 'ps_show=1' );
/* Get only the purchases from active applications */
$where[] = array( "ps_app IN('" . implode( "','", array_keys( \IPS\Application::enabledApplications() ) ) . "')" );
$where[] = array( "ps_app IN('" . implode( "','", array_keys( Application::enabledApplications() ) ) . "')" );
$purchases = array();
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_purchases', $where, 'ps_active DESC, ps_expire DESC, ps_start DESC' ), 'IPS\nexus\Purchase' ) as $purchase )
foreach( new ActiveRecordIterator( Db::i()->select( '*', 'nexus_purchases', $where, 'ps_active DESC, ps_expire DESC, ps_start DESC' ), 'IPS\nexus\Purchase' ) as $purchase )
{
$purchases[ $purchase->parent ][ $purchase->id ] = $purchase;
}
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('clients')->purchases( $purchases );
Output::i()->output = Theme::i()->getTemplate('clients')->purchases( $purchases );
}
/**
@@ -108,9 +135,9 @@ class _purchases extends \IPS\Dispatcher\Controller
*
* @return void
*/
public function view()
public function view() : void
{
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('clients')->purchase( $this->purchase );
Output::i()->output = Theme::i()->getTemplate('clients')->purchase( $this->purchase );
}
/**
@@ -118,23 +145,10 @@ class _purchases extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function extra()
protected function extra() : void
{
if ( $output = $this->purchase->clientAreaAction() )
{
if ( \IPS\Request::i()->isAjax() )
{
\IPS\Output::i()->output = $output;
}
else
{
\IPS\Output::i()->output = $output;
}
}
else
{
\IPS\Output::i()->redirect( $this->purchase->url() );
}
$this->purchase->clientAreaAction();
Output::i()->redirect( $this->purchase->url() );
}
/**
@@ -142,20 +156,20 @@ class _purchases extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function renew()
protected function renew() : void
{
$cycles = $this->purchase->canRenewUntil( NULL, TRUE );
if ( $cycles === FALSE )
{
\IPS\Output::i()->error( 'you_cannot_renew', '2X212/4', 403, '' );
Output::i()->error( 'you_cannot_renew', '2X212/4', 403, '' );
}
elseif ( $cycles === 1 )
{
\IPS\Session::i()->csrfCheck();
Session::i()->csrfCheck();
}
elseif ( isset( \IPS\Request::i()->cycles ) and \IPS\Login::compareHashes( (string) \IPS\Session::i()->csrfKey, (string) \IPS\Request::i()->csrfKey ) )
elseif ( isset( Request::i()->cycles ) and Login::compareHashes( (string) Session::i()->csrfKey, (string) Request::i()->csrfKey ) )
{
$_cycles = \intval( \IPS\Request::i()->cycles );
$_cycles = intval( Request::i()->cycles );
if ( $_cycles >= 1 and ( $cycles === TRUE or $_cycles <= $cycles ) )
{
$cycles = $_cycles;
@@ -172,31 +186,31 @@ class _purchases extends \IPS\Dispatcher\Controller
switch( $term['unit'] )
{
case 'd':
$suffix = \IPS\Member::loggedIn()->language()->addToStack('days');
$suffix = Member::loggedIn()->language()->addToStack('days');
break;
case 'm':
$suffix = \IPS\Member::loggedIn()->language()->addToStack('months');
$suffix = Member::loggedIn()->language()->addToStack('months');
break;
case 'y':
$suffix = \IPS\Member::loggedIn()->language()->addToStack('years');
$suffix = Member::loggedIn()->language()->addToStack('years');
break;
}
}
$form = new \IPS\Helpers\Form( 'form', 'continue' );
$form->class = 'ipsForm_vertical';
$form->add( new \IPS\Helpers\Form\Number( 'renew_for', 1, TRUE, array( 'min' => 1, 'max' => $cycles === TRUE ? NULL : $cycles ), NULL, NULL, $suffix ) );
$form = new Form( 'form', 'continue' );
$form->class = 'ipsForm--vertical ipsForm--renew';
$form->add( new Number( 'renew_for', 1, TRUE, array( 'min' => 1, 'max' => $cycles === TRUE ? NULL : $cycles ), NULL, NULL, $suffix ) );
if( $values = $form->values() or $cycles === 1 )
{
if ( $pendingInvoice = $this->purchase->invoice_pending and $pendingInvoice->status === $pendingInvoice::STATUS_PENDING )
{
if ( \count( $pendingInvoice->items ) === 1 )
if ( count( $pendingInvoice->items ) === 1 )
{
foreach ( $pendingInvoice->items as $item )
{
if ( $item instanceof \IPS\nexus\Invoice\Item\Renewal and $item->id === $this->purchase->id and $item->quantity === ( $cycles === 1 ? 1 : $values['renew_for'] ) )
if ( $item instanceof Renewal and $item->id === $this->purchase->id and $item->quantity === ( $cycles === 1 ? 1 : $values['renew_for'] ) )
{
\IPS\Output::i()->redirect( $pendingInvoice->checkoutUrl() );
Output::i()->redirect( $pendingInvoice->checkoutUrl() );
}
}
}
@@ -206,19 +220,19 @@ class _purchases extends \IPS\Dispatcher\Controller
$pendingInvoice->member->log( 'invoice', array( 'type' => 'status', 'new' => 'canc', 'id' => $pendingInvoice->id, 'title' => $pendingInvoice->title ) );
}
$invoice = new \IPS\nexus\Invoice;
$invoice->member = \IPS\nexus\Customer::loggedIn();
$invoice = new Invoice;
$invoice->member = Customer::loggedIn();
$invoice->currency = $this->purchase->renewals->cost->currency;
$invoice->addItem( \IPS\nexus\Invoice\Item\Renewal::create( $this->purchase, $cycles === 1 ? 1 : $values['renew_for'] ) );
$invoice->addItem( Renewal::create( $this->purchase, $cycles === 1 ? 1 : $values['renew_for'] ) );
$invoice->save();
$this->purchase->invoice_pending = $invoice;
$this->purchase->save();
\IPS\Output::i()->redirect( $invoice->checkoutUrl() );
Output::i()->redirect( $invoice->checkoutUrl() );
}
\IPS\Output::i()->output = $form->customTemplate( array( \IPS\Theme::i()->getTemplate( 'forms', 'core' ), 'popupTemplate' ) );
Output::i()->output = $form->customTemplate( array( Theme::i()->getTemplate( 'forms', 'core' ), 'popupTemplate' ) );
}
/**
@@ -226,13 +240,13 @@ class _purchases extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function cancel()
protected function cancel() : void
{
\IPS\Session::i()->csrfCheck();
Session::i()->csrfCheck();
if ( !$this->purchase->canCancel() )
{
\IPS\Output::i()->error( 'you_cannot_cancel', '2X212/5', 403, '' );
Output::i()->error( 'you_cannot_cancel', '2X212/5', 403, '' );
}
$this->purchase->member->log( 'purchase', array( 'type' => 'info', 'id' => $this->purchase->id, 'name' => $this->purchase->name, 'info' => 'remove_renewals' ) );
@@ -240,7 +254,7 @@ class _purchases extends \IPS\Dispatcher\Controller
/* If we have a pending renewal invoice, cancel it (as at this point, we need to reactivate instead) */
if ( $this->purchase->invoice_pending )
{
$this->purchase->invoice_pending->status = \IPS\nexus\Invoice::STATUS_CANCELED; # The constant has a typo and it make me sad
$this->purchase->invoice_pending->status = Invoice::STATUS_CANCELED; # The constant has a typo and it make me sad
$this->purchase->invoice_pending->save();
$this->purchase->invoice_pending = NULL;
@@ -250,10 +264,10 @@ class _purchases extends \IPS\Dispatcher\Controller
$this->purchase->can_reactivate = TRUE;
$this->purchase->save();
if ( $ref = \IPS\Request::i()->referrer( FALSE, TRUE ) )
if ( $ref = Request::i()->referrer( FALSE, TRUE ) )
{
\IPS\Output::i()->redirect( $ref );
Output::i()->redirect( $ref );
}
\IPS\Output::i()->redirect( $this->purchase->url() );
Output::i()->redirect( $this->purchase->url() );
}
}