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,35 +12,40 @@
namespace IPS\nexus\modules\admin\customers;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\Dispatcher;
use IPS\Node\Controller;
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;
}
/**
* fields
*/
class _fields extends \IPS\Node\Controller
class fields extends Controller
{
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
public static bool $csrfProtected = TRUE;
/**
* Node Class
*/
protected $nodeClass = 'IPS\nexus\Customer\CustomField';
protected string $nodeClass = 'IPS\nexus\Customer\CustomField';
/**
* Execute
*
* @return void
*/
public function execute()
public function execute() : void
{
\IPS\Dispatcher::i()->checkAcpPermission( 'customer_fields_manage' );
Dispatcher::i()->checkAcpPermission( 'customer_fields_manage' );
parent::execute();
}
}
@@ -12,43 +12,78 @@
namespace IPS\nexus\modules\admin\customers;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use DateInterval;
use DomainException;
use Exception;
use IPS\Db;
use IPS\Dispatcher;
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\Member;
use IPS\nexus\Invoice;
use IPS\nexus\Invoice\Item\Renewal;
use IPS\nexus\Money;
use IPS\nexus\Package\CustomField;
use IPS\nexus\Purchase;
use IPS\nexus\Purchase\RenewalTerm;
use IPS\nexus\Tax;
use IPS\Output;
use IPS\Request;
use IPS\Session;
use IPS\Theme;
use LogicException;
use OutOfRangeException;
use function defined;
use const IPS\Helpers\Table\SEARCH_DATE_RANGE;
use const IPS\Helpers\Table\SEARCH_NUMERIC;
use const IPS\Helpers\Table\SEARCH_SELECT;
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 Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
public static bool $csrfProtected = TRUE;
/**
* @var Purchase|null
*/
protected ?Purchase $purchase = null;
/**
* View
*
* @return void
*/
public function execute()
public function execute() : void
{
\IPS\Dispatcher::i()->checkAcpPermission( 'purchases_view' );
Dispatcher::i()->checkAcpPermission( 'purchases_view' );
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', '2X195/2', 404, '' );
Output::i()->error( 'node_error', '2X195/2', 404, '' );
}
\IPS\Output::i()->title = $this->purchase->name . " (#{$this->purchase->id})";
Output::i()->title = $this->purchase->name . " (#{$this->purchase->id})";
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'purchases.css', 'nexus', 'admin' ) );
Output::i()->cssFiles = array_merge( Output::i()->cssFiles, Theme::i()->css( 'purchases.css', 'nexus', 'admin' ) );
parent::execute();
}
@@ -57,7 +92,7 @@ class _purchases extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function manage()
protected function manage() : void
{
$this->view();
}
@@ -67,20 +102,20 @@ class _purchases extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function view()
protected function view() : void
{
/* Popup view */
if ( \IPS\Request::i()->isAjax() and isset( \IPS\Request::i()->hovercard ) )
if ( Request::i()->isAjax() and isset( Request::i()->hovercard ) )
{
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'purchases' )->hovercard( $this->purchase );
Output::i()->output = Theme::i()->getTemplate( 'purchases' )->hovercard( $this->purchase );
return;
}
/* Create children tree */
$children = \IPS\nexus\Purchase::tree( $this->purchase->acpUrl(), array(), "p{$this->purchase->id}", $this->purchase, FALSE );
if ( \IPS\Request::i()->isAjax() )
$children = Purchase::tree( $this->purchase->acpUrl(), array(), "p{$this->purchase->id}", $this->purchase, FALSE );
if ( Request::i()->isAjax() )
{
\IPS\Output::i()->output = $children;
Output::i()->output = $children;
return;
}
@@ -90,12 +125,12 @@ class _purchases extends \IPS\Dispatcher\Controller
{
try
{
if ( $displayValue = trim( \IPS\nexus\Package\CustomField::load( $k )->displayValue( $v, TRUE ) ) )
if ( $displayValue = trim( CustomField::load( $k )->displayValue( $v, TRUE ) ) )
{
$customFields[ $k ] = $displayValue;
}
}
catch ( \OutOfRangeException $e ) { }
catch ( OutOfRangeException ) { }
}
/* Get customer */
@@ -103,15 +138,15 @@ class _purchases extends \IPS\Dispatcher\Controller
{
$customer = $this->purchase->member;
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException )
{
$customer = NULL;
}
/* Display */
\IPS\Output::i()->sidebar['actions'] = $this->purchase->buttons();
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'purchases' )->view( $this->purchase, $customer, $children, $customFields );
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'admin_members.js', 'core' ) );
Output::i()->sidebar['actions'] = $this->purchase->buttons();
Output::i()->output = Theme::i()->getTemplate( 'purchases' )->view( $this->purchase, $customer, $children, $customFields );
Output::i()->jsFiles = array_merge( Output::i()->jsFiles, Output::i()->js( 'admin_members.js', 'core' ) );
}
/**
@@ -120,28 +155,28 @@ class _purchases extends \IPS\Dispatcher\Controller
* @note This is lazy loaded after the purchase page is generated
* @return void
*/
protected function showInvoices()
protected function showInvoices() : void
{
/* Create associated invoices table */
try
{
$originalInvoice = $this->purchase->original_invoice;
$invoices = \IPS\nexus\Invoice::table( array( array( 'i_id=? OR ' . \IPS\Db::i()->findInSet( 'i_renewal_ids', array( $this->purchase->id ) ), $originalInvoice->id ) ), $this->purchase->acpUrl()->setQueryString( 'do', 'showInvoices' ), "p.{$this->purchase->id}" );
$invoices = Invoice::table( array( array( 'i_id=? OR ' . Db::i()->findInSet( 'i_renewal_ids', array( $this->purchase->id ) ), $originalInvoice->id ) ), $this->purchase->acpUrl()->setQueryString( 'do', 'showInvoices' ), "p.{$this->purchase->id}" );
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException )
{
$invoices = \IPS\nexus\Invoice::table( array( array( \IPS\Db::i()->findInSet( 'i_renewal_ids', array( $this->purchase->id ) ) ) ), $this->purchase->acpUrl()->setQueryString( 'do', 'showInvoices' ), "p.{$this->purchase->id}" );
$invoices = Invoice::table( array( array( Db::i()->findInSet( 'i_renewal_ids', array( $this->purchase->id ) ) ) ), $this->purchase->acpUrl()->setQueryString( 'do', 'showInvoices' ), "p.{$this->purchase->id}" );
}
$invoices->filters = array(
'paid' => array( 'i_status=?', \IPS\nexus\Invoice::STATUS_PAID )
'paid' => array( 'i_status=?', Invoice::STATUS_PAID )
);
$invoices->advancedSearch = array(
'i_status' => array( \IPS\Helpers\Table\SEARCH_SELECT, array( 'options' => \IPS\nexus\Invoice::statuses(), 'multiple' => TRUE ) ),
'i_total' => \IPS\Helpers\Table\SEARCH_NUMERIC,
'i_date' => \IPS\Helpers\Table\SEARCH_DATE_RANGE,
'i_status' => array( SEARCH_SELECT, array( 'options' => Invoice::statuses(), 'multiple' => TRUE ) ),
'i_total' => SEARCH_NUMERIC,
'i_date' => SEARCH_DATE_RANGE,
);
\IPS\Output::i()->output = (string) $invoices;
Output::i()->output = (string) $invoices;
}
/**
@@ -149,14 +184,14 @@ class _purchases extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function edit()
protected function edit() : void
{
\IPS\Dispatcher::i()->checkAcpPermission( 'purchases_edit' );
Dispatcher::i()->checkAcpPermission( 'purchases_edit' );
/* Work stuff out */
$renewals = $this->purchase->renewals ?: NULL;
$groupedChildren = array();
if ( $renewals and \IPS\Db::i()->select( 'COUNT(*)', 'nexus_purchases', array( 'ps_parent=? AND ps_grouped_renewals<>? AND ps_cancelled=0', $this->purchase->id, '' ) )->first() )
if ( $renewals and Db::i()->select( 'COUNT(*)', 'nexus_purchases', array( 'ps_parent=? AND ps_grouped_renewals<>? AND ps_cancelled=0', $this->purchase->id, '' ) )->first() )
{
$renewals = $this->purchase->renewals;
foreach ( $this->purchase->children() as $child )
@@ -173,23 +208,23 @@ class _purchases extends \IPS\Dispatcher\Controller
{
if( $this->purchase->tax )
{
$tax = \IPS\nexus\Tax::load( $this->purchase->tax );
$tax = Tax::load( $this->purchase->tax );
}
}
catch( \OutOfRangeException $e ){}
catch( OutOfRangeException ){}
try
{
$childGroupedRenewalTerm = new \IPS\nexus\Purchase\RenewalTerm( new \IPS\nexus\Money( $childGroupedRenewals['price'], $this->purchase->renewals->cost->currency ), new \DateInterval( 'P' . $childGroupedRenewals['term'] . mb_strtoupper( $childGroupedRenewals['unit'] ) ), $tax );
$renewals = new \IPS\nexus\Purchase\RenewalTerm( $renewals->subtract( $childGroupedRenewalTerm ), $renewals->interval );
$childGroupedRenewalTerm = new RenewalTerm( new Money( $childGroupedRenewals['price'], $this->purchase->renewals->cost->currency ), new DateInterval( 'P' . $childGroupedRenewals['term'] . mb_strtoupper( $childGroupedRenewals['unit'] ) ), $tax );
$renewals = new RenewalTerm( $renewals->subtract( $childGroupedRenewalTerm ), $renewals->interval );
}
catch ( \Exception $e ) { }
catch ( Exception ) { }
}
}
}
/* Build form */
$form = new \IPS\Helpers\Form;
$form = new Form;
$this->purchase->acpEdit( $form, $renewals );
/* Handle submissions */
@@ -218,7 +253,7 @@ class _purchases extends \IPS\Dispatcher\Controller
}
/* Display */
\IPS\Output::i()->output = $form;
Output::i()->output = $form;
}
/**
@@ -226,21 +261,21 @@ class _purchases extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function transfer()
protected function transfer() : void
{
\IPS\Dispatcher::i()->checkAcpPermission( 'purchases_transfer' );
Dispatcher::i()->checkAcpPermission( 'purchases_transfer' );
if ( $this->purchase->grouped_renewals )
{
\IPS\Output::i()->error( 'not_with_grouped', '2X195/6', 403, '' );
Output::i()->error( 'not_with_grouped', '2X195/6', 403, '' );
}
if ( $this->purchase->billing_agreement and !$this->purchase->billing_agreement->canceled )
{
\IPS\Output::i()->error( 'not_with_billing_agreement', '2X195/G', 403, '' );
Output::i()->error( 'not_with_billing_agreement', '2X195/G', 403, '' );
}
/* Build form */
$form = new \IPS\Helpers\Form;
$form->add( new \IPS\Helpers\Form\Member( 'ps_member', NULL, TRUE ) );
$form = new Form;
$form->add( new Form\Member( 'ps_member', NULL, TRUE ) );
/* Handle submissions */
if ( $values = $form->values() )
@@ -251,9 +286,9 @@ class _purchases extends \IPS\Dispatcher\Controller
{
$this->purchase->transfer( $values['ps_member'] );
}
catch ( \DomainException $e )
catch ( DomainException $e )
{
\IPS\Output::i()->error( $e->getMessage(), '2X195/8', 403 );
Output::i()->error( $e->getMessage(), '2X195/8', 403 );
}
/* Log */
@@ -265,7 +300,7 @@ class _purchases extends \IPS\Dispatcher\Controller
}
/* Display */
\IPS\Output::i()->output = $form;
Output::i()->output = $form;
}
/**
@@ -273,39 +308,39 @@ class _purchases extends \IPS\Dispatcher\Controller
*
* @return void
*/
public function renew()
public function renew() : void
{
\IPS\Dispatcher::i()->checkAcpPermission( 'invoices_add', 'nexus', 'payments' );
Dispatcher::i()->checkAcpPermission( 'invoices_add', 'nexus', 'payments' );
if ( $this->purchase->grouped_renewals )
{
\IPS\Output::i()->error( 'not_with_grouped', '2X195/7', 403, '' );
Output::i()->error( 'not_with_grouped', '2X195/7', 403, '' );
}
if ( $this->purchase->billing_agreement and !$this->purchase->billing_agreement->canceled )
{
\IPS\Output::i()->error( 'not_with_billing_agreement', '2X195/D', 403, '' );
Output::i()->error( 'not_with_billing_agreement', '2X195/D', 403, '' );
}
/* If this purchase has renewal term, we cannot generate a renewal invoice */
if ( !$this->purchase->renewals )
{
\IPS\Output::i()->error( 'purchase_no_renew', '2X195/3', 403, '' );
Output::i()->error( 'purchase_no_renew', '2X195/3', 403, '' );
}
/* Build form */
$form = new \IPS\Helpers\Form;
$form = new Form;
$cycles = $this->purchase->canRenewUntil( NULL, TRUE, TRUE );
$form->add( new \IPS\Helpers\Form\Number( 'renew_cycles', 1, TRUE, array( 'min' => 1, 'max' => ( $cycles === TRUE ? NULL : $cycles ) ) ) );
$form->add( new Number( 'renew_cycles', 1, TRUE, array( 'min' => 1, 'max' => ( $cycles === TRUE ? NULL : $cycles ) ) ) );
/* Handle submissions */
if ( $values = $form->values() )
{
/* Generate Invoice */
$invoice = new \IPS\nexus\Invoice;
$invoice = new Invoice;
$invoice->currency = $this->purchase->renewal_currency;
$invoice->member = $this->purchase->member;
$invoice->billaddress = $this->purchase->member->primaryBillingAddress();
$invoice->addItem( \IPS\nexus\Invoice\Item\Renewal::create( $this->purchase, $values['renew_cycles'] ) );
$invoice->addItem( Renewal::create( $this->purchase, $values['renew_cycles'] ) );
$invoice->save();
$invoice->sendNotification();
@@ -314,26 +349,26 @@ class _purchases extends \IPS\Dispatcher\Controller
$this->purchase->save();
/* Take us to that invoice */
\IPS\Output::i()->redirect( $invoice->acpUrl() );
Output::i()->redirect( $invoice->acpUrl() );
}
/* If this purchase already has an unpaid renewal invoice, display a warning */
if ( $this->purchase->invoice_pending )
{
/* Which will be a proper warning if that invoice is still pending */
if ( $this->purchase->invoice_pending->status === \IPS\nexus\Invoice::STATUS_PENDING )
if ( $this->purchase->invoice_pending->status === Invoice::STATUS_PENDING )
{
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'global', 'core' )->message( \IPS\Member::loggedIn()->language()->addToStack('warn_renew_invoice_pending', FALSE, array( 'sprintf' => array( $this->purchase->invoice_pending->acpUrl() ) ) ), 'warning', NULL, FALSE, TRUE );
Output::i()->output .= Theme::i()->getTemplate( 'global', 'core' )->message( Member::loggedIn()->language()->addToStack('warn_renew_invoice_pending', FALSE, array( 'sprintf' => array( $this->purchase->invoice_pending->acpUrl() ) ) ), 'warning', NULL, FALSE, TRUE );
}
/* Or just informational if it is canceled or expired */
elseif ( $this->purchase->invoice_pending->status !== \IPS\nexus\Invoice::STATUS_PAID )
elseif ( $this->purchase->invoice_pending->status !== Invoice::STATUS_PAID )
{
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'global', 'core' )->message( \IPS\Member::loggedIn()->language()->addToStack('info_renew_invoice_pending', FALSE, array( 'sprintf' => array( $this->purchase->invoice_pending->acpUrl() ) ) ), 'information', NULL, FALSE, TRUE );
Output::i()->output .= Theme::i()->getTemplate( 'global', 'core' )->message( Member::loggedIn()->language()->addToStack('info_renew_invoice_pending', FALSE, array( 'sprintf' => array( $this->purchase->invoice_pending->acpUrl() ) ) ), 'information', NULL, FALSE, TRUE );
}
}
/* Display */
\IPS\Output::i()->output .= $form;
Output::i()->output .= $form;
}
/**
@@ -341,15 +376,15 @@ class _purchases extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function cancel()
protected function cancel() : void
{
\IPS\Dispatcher::i()->checkAcpPermission( 'purchases_cancel' );
Dispatcher::i()->checkAcpPermission( 'purchases_cancel' );
$parent = $this->purchase->parent();
if ( ( $this->purchase->billing_agreement and !$this->purchase->billing_agreement->canceled ) or ( $this->purchase->grouped_renewals and $parent->billing_agreement and !$parent->billing_agreement->canceled ) )
{
\IPS\Output::i()->error( 'not_with_billing_agreement', '2X195/H', 403, '' );
Output::i()->error( 'not_with_billing_agreement', '2X195/H', 403, '' );
}
/* What options are available for cancelling? */
@@ -361,15 +396,15 @@ class _purchases extends \IPS\Dispatcher\Controller
$options['cancel'] = 'cancel_type_cancel';
/* Build form */
$form = new \IPS\Helpers\Form;
$form->add( new \IPS\Helpers\Form\Radio( 'cancel_type', 'no_renew', FALSE, array(
$form = new Form;
$form->add( new Radio( 'cancel_type', 'no_renew', FALSE, array(
'options' => $options,
'toggles' => array( 'cancel' => array( 'form_cancel_type_warning' ) )
) ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'ps_can_reactivate', FALSE ) );
$form->add( new YesNo( 'ps_can_reactivate', FALSE ) );
if ( $onCancelWarning = $this->purchase->onCancelWarning() )
{
\IPS\Member::loggedIn()->language()->words['cancel_type_warning'] = $onCancelWarning;
Member::loggedIn()->language()->words['cancel_type_warning'] = $onCancelWarning;
}
/* Handle submissions */
@@ -409,7 +444,7 @@ class _purchases extends \IPS\Dispatcher\Controller
}
/* Display form */
\IPS\Output::i()->output = $form;
Output::i()->output = $form;
}
/**
@@ -417,22 +452,22 @@ class _purchases extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function reactivate()
protected function reactivate() : void
{
\IPS\Dispatcher::i()->checkAcpPermission( 'purchases_cancel' );
\IPS\Session::i()->csrfCheck();
Dispatcher::i()->checkAcpPermission( 'purchases_cancel' );
Session::i()->csrfCheck();
$error = NULL;
if ( !$this->purchase->canAcpReactivate( $error ) )
{
\IPS\Output::i()->error( $error ?? 'can_not_reactivate', '2X195/K', 403, '' );
Output::i()->error( $error ?? 'can_not_reactivate', '2X195/K', 403, '' );
}
$parent = $this->purchase->parent();
if ( ( $this->purchase->billing_agreement and !$this->purchase->billing_agreement->canceled ) or ( $this->purchase->grouped_renewals and $parent->billing_agreement and !$parent->billing_agreement->canceled ) )
{
\IPS\Output::i()->error( 'not_with_billing_agreement', '2X195/I', 403, '' );
Output::i()->error( 'not_with_billing_agreement', '2X195/I', 403, '' );
}
/* If grouped, ungroup */
@@ -464,16 +499,16 @@ class _purchases extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function delete()
protected function delete() : void
{
\IPS\Dispatcher::i()->checkAcpPermission( 'purchases_delete' );
\IPS\Request::i()->confirmedDelete();
Dispatcher::i()->checkAcpPermission( 'purchases_delete' );
Request::i()->confirmedDelete();
$parent = $this->purchase->parent();
if ( ( $this->purchase->billing_agreement and !$this->purchase->billing_agreement->canceled ) or ( $this->purchase->grouped_renewals and $parent->billing_agreement and !$parent->billing_agreement->canceled ) )
{
\IPS\Output::i()->error( 'not_with_billing_agreement', '2X195/J', 403, '' );
Output::i()->error( 'not_with_billing_agreement', '2X195/J', 403, '' );
}
if ( $this->purchase->grouped_renewals )
@@ -487,11 +522,11 @@ class _purchases extends \IPS\Dispatcher\Controller
if ( $parent )
{
\IPS\Output::i()->redirect( $parent->acpUrl() );
Output::i()->redirect( $parent->acpUrl() );
}
else
{
\IPS\Output::i()->redirect( $this->purchase->member->acpUrl() );
Output::i()->redirect( $this->purchase->member->acpUrl() );
}
}
@@ -500,15 +535,15 @@ class _purchases extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function extra()
protected function extra() : void
{
if ( $output = $this->purchase->acpAction() )
{
\IPS\Output::i()->output = $output;
Output::i()->output = $output;
}
else
{
\IPS\Output::i()->redirect( $this->purchase->acpUrl() );
Output::i()->redirect( $this->purchase->acpUrl() );
}
}
@@ -517,14 +552,14 @@ class _purchases extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function group()
protected function group() : void
{
\IPS\Dispatcher::i()->checkAcpPermission( 'purchases_edit' );
\IPS\Session::i()->csrfCheck();
Dispatcher::i()->checkAcpPermission( 'purchases_edit' );
Session::i()->csrfCheck();
if ( $this->purchase->billing_agreement and !$this->purchase->billing_agreement->canceled )
{
\IPS\Output::i()->error( 'not_with_billing_agreement', '2X195/E', 403, '' );
Output::i()->error( 'not_with_billing_agreement', '2X195/E', 403, '' );
}
try
@@ -532,9 +567,9 @@ class _purchases extends \IPS\Dispatcher\Controller
$this->purchase->groupWithParent();
$this->purchase->member->log( 'purchase', array( 'type' => 'group', 'id' => $this->purchase->id, 'name' => $this->purchase->name ) );
}
catch ( \LogicException $e )
catch ( LogicException $e )
{
\IPS\Output::i()->error( 'grouperr_' . $e->getMessage(), '1X195/4', 403, '' );
Output::i()->error( 'grouperr_' . $e->getMessage(), '1X195/4', 403, '' );
}
$this->_redirect();
}
@@ -544,14 +579,14 @@ class _purchases extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function ungroup()
protected function ungroup() : void
{
\IPS\Dispatcher::i()->checkAcpPermission( 'purchases_edit' );
\IPS\Session::i()->csrfCheck();
Dispatcher::i()->checkAcpPermission( 'purchases_edit' );
Session::i()->csrfCheck();
if ( $this->purchase->billing_agreement and !$this->purchase->billing_agreement->canceled )
{
\IPS\Output::i()->error( 'not_with_billing_agreement', '2X195/F', 403, '' );
Output::i()->error( 'not_with_billing_agreement', '2X195/F', 403, '' );
}
try
@@ -559,9 +594,9 @@ class _purchases extends \IPS\Dispatcher\Controller
$this->purchase->ungroupFromParent();
$this->purchase->member->log( 'purchase', array( 'type' => 'ungroup', 'id' => $this->purchase->id, 'name' => $this->purchase->name ) );
}
catch ( \LogicException $e )
catch ( LogicException )
{
\IPS\Output::i()->error( '', '1X195/5', 403, '' );
Output::i()->error( '', '1X195/5', 403, '' );
}
$this->_redirect();
}
@@ -571,37 +606,33 @@ class _purchases extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function _redirect()
protected function _redirect() : void
{
if ( isset( \IPS\Request::i()->r ) )
if ( isset( Request::i()->r ) )
{
switch ( mb_substr( \IPS\Request::i()->r, 0, 1 ) )
switch ( mb_substr( Request::i()->r, 0, 1 ) )
{
case 'p':
try
{
\IPS\Output::i()->redirect( \IPS\nexus\Purchase::load( $this->purchase->parent )->acpUrl() );
Output::i()->redirect( Purchase::load( $this->purchase->parent )->acpUrl() );
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException )
{
\IPS\Output::i()->redirect( $this->purchase->member->acpUrl() );
Output::i()->redirect( $this->purchase->member->acpUrl() );
}
break;
case 'v':
\IPS\Output::i()->redirect( $this->purchase->acpUrl() );
Output::i()->redirect( $this->purchase->acpUrl() );
break;
case 'c':
\IPS\Output::i()->redirect( $this->purchase->member->acpUrl() );
break;
case 's':
\IPS\Output::i()->redirect( \IPS\nexus\Support\Request::load( mb_substr( \IPS\Request::i()->r, 2 ) )->acpUrl() );
Output::i()->redirect( $this->purchase->member->acpUrl() );
break;
}
}
\IPS\Output::i()->redirect( $this->purchase->acpUrl() );
Output::i()->redirect( $this->purchase->acpUrl() );
}
}
@@ -12,30 +12,48 @@
namespace IPS\nexus\modules\admin\customers;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\Dispatcher;
use IPS\Dispatcher\Controller;
use IPS\GeoLocation;
use IPS\Helpers\Table\Db;
use IPS\Http\Url;
use IPS\Member;
use IPS\nexus\Customer\CustomField;
use IPS\Output;
use IPS\Theme;
use function defined;
use const IPS\Helpers\Table\SEARCH_BOOL;
use const IPS\Helpers\Table\SEARCH_CONTAINS_TEXT;
use const IPS\Helpers\Table\SEARCH_DATE_RANGE;
use const IPS\Helpers\Table\SEARCH_MEMBER;
use const IPS\Helpers\Table\SEARCH_NUMERIC;
use const IPS\Helpers\Table\SEARCH_SELECT;
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;
}
/**
* Customer Search
*/
class _search extends \IPS\Dispatcher\Controller
class search extends Controller
{
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
public static bool $csrfProtected = TRUE;
/**
* Execute
*
* @return void
*/
public function execute()
public function execute() : void
{
\IPS\Dispatcher::i()->checkAcpPermission( 'customers_view' );
Dispatcher::i()->checkAcpPermission( 'customers_view' );
parent::execute();
}
@@ -44,9 +62,9 @@ class _search extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function manage()
protected function manage() : void
{
$table = new \IPS\Helpers\Table\Db( 'core_members', \IPS\Http\Url::internal('app=nexus&module=customers&controller=search') );
$table = new Db( 'core_members', Url::internal('app=nexus&module=customers&controller=search') );
$table->langPrefix = 'customerTable_';
$table->joins = array(
array(
@@ -64,11 +82,11 @@ class _search extends \IPS\Dispatcher\Controller
$table->parsers = array(
'photo' => function( $val, $row )
{
return \IPS\Theme::i()->getTemplate('customers')->rowPhoto( \IPS\Member::constructFromData( $row ) );
return Theme::i()->getTemplate('customers')->rowPhoto( Member::constructFromData( $row ) );
},
'address' => function( $val )
{
return \IPS\GeoLocation::buildFromJson( $val );
return $val ? GeoLocation::buildFromJson( $val ) : NULL;
}
);
$table->noSort = array( 'photo', 'address' );
@@ -76,44 +94,44 @@ class _search extends \IPS\Dispatcher\Controller
$table->rowClasses = array( 'address' => array( 'ipsTable_wrap' ) );
$table->advancedSearch = array(
'cm_first_name' => \IPS\Helpers\Table\SEARCH_CONTAINS_TEXT,
'cm_last_name' => \IPS\Helpers\Table\SEARCH_CONTAINS_TEXT,
'email' => \IPS\Helpers\Table\SEARCH_CONTAINS_TEXT,
'name' => \IPS\Helpers\Table\SEARCH_CONTAINS_TEXT
'cm_first_name' => SEARCH_CONTAINS_TEXT,
'cm_last_name' => SEARCH_CONTAINS_TEXT,
'email' => SEARCH_CONTAINS_TEXT,
'name' => SEARCH_CONTAINS_TEXT
);
foreach ( \IPS\nexus\Customer\CustomField::roots() as $field )
foreach ( CustomField::roots() as $field )
{
switch ( $field->type )
{
case 'Checkbox':
case 'YesNo':
$table->advancedSearch[ $field->column ] = \IPS\Helpers\Table\SEARCH_BOOL;
$table->advancedSearch[ $field->column ] = SEARCH_BOOL;
break;
case 'CheckboxSet':
case 'Select':
case 'Radio':
$table->advancedSearch[ $field->column ] = array( \IPS\Helpers\Table\SEARCH_SELECT, array( 'options' => json_decode( $field->extra ), 'multiple' => $field->multiple ) );
$table->advancedSearch[ $field->column ] = array( SEARCH_SELECT, array( 'options' => json_decode( $field->extra ), 'multiple' => $field->multiple ) );
break;
case 'Date':
$table->advancedSearch[ $field->column ] = \IPS\Helpers\Table\SEARCH_DATE_RANGE;
$table->advancedSearch[ $field->column ] = SEARCH_DATE_RANGE;
break;
case 'Member':
$table->advancedSearch[ $field->column ] = array( \IPS\Helpers\Table\SEARCH_MEMBER, array( 'multiple' => $field->multiple ) );
$table->advancedSearch[ $field->column ] = array( SEARCH_MEMBER, array( 'multiple' => $field->multiple ) );
break;
case 'Number':
$table->advancedSearch[ $field->column ] = \IPS\Helpers\Table\SEARCH_NUMERIC;
$table->advancedSearch[ $field->column ] = SEARCH_NUMERIC;
break;
default:
$table->advancedSearch[ $field->column ] = \IPS\Helpers\Table\SEARCH_CONTAINS_TEXT;
$table->advancedSearch[ $field->column ] = SEARCH_CONTAINS_TEXT;
break;
}
\IPS\Member::loggedIn()->language()->words[ 'customerTable_field_' . $field->id ] = $field->_title;
Member::loggedIn()->language()->words[ 'customerTable_field_' . $field->id ] = $field->_title;
$table->parsers[ $field->column ] = array( $field, 'displayValue' );
}
@@ -124,12 +142,12 @@ class _search extends \IPS\Dispatcher\Controller
'view' => array(
'icon' => 'search',
'title' => 'view',
'link' => \IPS\Http\Url::internal("app=core&module=members&controller=members&do=view&tab=nexus_Main&id={$row['member_id']}"),
'link' => Url::internal("app=core&module=members&controller=members&do=view&tab=nexus_Main&id={$row['member_id']}"),
),
);
};
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__nexus_customers');
\IPS\Output::i()->output = (string) $table;
Output::i()->title = Member::loggedIn()->language()->addToStack('menu__nexus_customers');
Output::i()->output = (string) $table;
}
}
@@ -12,59 +12,92 @@
namespace IPS\nexus\modules\admin\customers;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use DomainException;
use Exception;
use IPS\Db;
use IPS\Dispatcher;
use IPS\Dispatcher\Controller;
use IPS\File;
use IPS\GeoLocation;
use IPS\Helpers\Form;
use IPS\Helpers\Form\Editor;
use IPS\Helpers\Form\Node;
use IPS\Helpers\Form\Text;
use IPS\Helpers\Form\YesNo;
use IPS\Helpers\MultipleRedirect;
use IPS\Http\Url;
use IPS\Math\Number;
use IPS\Member;
use IPS\nexus\Customer;
use IPS\nexus\Customer\Address;
use IPS\nexus\Customer\AlternativeContact;
use IPS\nexus\Customer\CreditCard;
use IPS\nexus\Customer\CustomField;
use IPS\nexus\Gateway;
use IPS\nexus\Invoice;
use IPS\nexus\Money;
use IPS\nexus\Tax;
use IPS\nexus\Transaction;
use IPS\Output;
use IPS\Patterns\ActiveRecordIterator;
use IPS\Request;
use IPS\Session;
use IPS\Theme;
use OutOfRangeException;
use UnderflowException;
use function count;
use function defined;
use function in_array;
use function intval;
use function is_array;
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;
}
/**
* View
*/
class _view extends \IPS\Dispatcher\Controller
class view extends Controller
{
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
public static bool $csrfProtected = TRUE;
/**
* @brief Member
*/
protected $member;
protected Customer $member;
/**
* Execute
*
* @return void
*/
public function execute()
public function execute() : void
{
\IPS\Dispatcher::i()->checkAcpPermission( 'customers_view' );
Dispatcher::i()->checkAcpPermission( 'customers_view' );
try
{
$this->member = \IPS\nexus\Customer::load( \IPS\Request::i()->id );
$this->member = Customer::load( Request::i()->id );
if ( !$this->member->member_id )
{
throw new \OutOfRangeException;
throw new OutOfRangeException;
}
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException )
{
\IPS\Output::i()->error( 'node_error', '2X233/1', 404, '' );
Output::i()->error( 'node_error', '2X233/1', 404, '' );
}
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'customer.css', 'nexus', 'admin' ) );
if ( \IPS\Theme::i()->settings['responsive'] )
{
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'customer_responsive.css', 'nexus', 'admin' ) );
}
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'support.css', 'nexus', 'admin' ) );
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'admin_customer.js', 'nexus', 'admin' ) );
\IPS\Output::i()->title = "{$this->member->cm_name}";
Output::i()->cssFiles = array_merge( Output::i()->cssFiles, Theme::i()->css( 'customer.css', 'nexus', 'admin' ) );
Output::i()->jsFiles = array_merge( Output::i()->jsFiles, Output::i()->js( 'admin_customer.js', 'nexus', 'admin' ) );
Output::i()->title = "{$this->member->cm_name}";
parent::execute();
}
@@ -75,9 +108,9 @@ class _view extends \IPS\Dispatcher\Controller
* @return void
* @deprecated
*/
protected function manage()
protected function manage() : void
{
\IPS\Output::i()->redirect( $this->member->acpUrl() );
Output::i()->redirect( $this->member->acpUrl() );
}
/**
@@ -85,37 +118,37 @@ class _view extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function addresses()
protected function addresses() : void
{
$addresses = new \IPS\Helpers\Table\Db( 'nexus_customer_addresses', \IPS\Http\Url::internal("app=nexus&module=customers&controller=view&id={$this->member->member_id}")->setQueryString( 'view', 'addresses' ), array( '`member`=?', $this->member->member_id ) );
$addresses->sortBy = 'primary_billing, primary_shipping, added';
$addresses->include = array( 'address', 'primary_billing', 'primary_shipping' );
$addresses = new \IPS\Helpers\Table\Db( 'nexus_customer_addresses', Url::internal("app=nexus&module=customers&controller=view&id={$this->member->member_id}")->setQueryString( 'view', 'addresses' ), array( '`member`=?', $this->member->member_id ) );
$addresses->sortBy = 'primary_billing, added';
$addresses->include = array( 'address', 'primary_billing' );
$addresses->parsers = array( 'address' => function( $val )
{
$address = \IPS\GeoLocation::buildFromJson( $val );
return $address->toString( '<br>' ) . ( ( isset( $address->business ) and $address->business and isset( $address->vat ) and $address->vat ) ? ( '<br>' . \IPS\Member::loggedIn()->language()->addToStack('cm_checkout_vat_number') . ': ' .\IPS\Theme::i()->getTemplate( 'global', 'nexus' )->vatNumber( $address->vat ) ) : '' );
$address = GeoLocation::buildFromJson( $val );
return $address->toString( '<br>' ) . ( ( isset( $address->business ) and $address->business and isset( $address->vat ) and $address->vat ) ? ( '<br>' . Member::loggedIn()->language()->addToStack('cm_checkout_vat_number') . ': ' . Theme::i()->getTemplate( 'global', 'nexus' )->vatNumber( $address->vat ) ) : '' );
} );
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'customers_edit_details' ) )
if ( Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'customers_edit_details' ) )
{
$addresses->rootButtons = array(
'add' => array(
'link' => \IPS\Http\Url::internal("app=nexus&module=customers&controller=view&id={$this->member->member_id}")->setQueryString( 'do', 'addressForm' ),
'link' => Url::internal("app=nexus&module=customers&controller=view&id={$this->member->member_id}")->setQueryString( 'do', 'addressForm' ),
'title' => 'add',
'icon' => 'plus',
'data' => array( 'ipsDialog' => true, 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('add_address') )
'data' => array( 'ipsDialog' => true, 'ipsDialog-title' => Member::loggedIn()->language()->addToStack('add_address') )
)
);
$addresses->rowButtons = function( $row )
{
return array(
'edit' => array(
'link' => \IPS\Http\Url::internal("app=nexus&module=customers&controller=view&id={$this->member->member_id}")->setQueryString( array( 'do' => 'addressForm', 'address_id' => $row['id'] ) ),
'link' => Url::internal("app=nexus&module=customers&controller=view&id={$this->member->member_id}")->setQueryString( array( 'do' => 'addressForm', 'address_id' => $row['id'] ) ),
'title' => 'edit',
'icon' => 'pencil',
'data' => array( 'ipsDialog' => true, 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('edit_address') )
'data' => array( 'ipsDialog' => true, 'ipsDialog-title' => Member::loggedIn()->language()->addToStack('edit_address') )
),
'delete' => array(
'link' => \IPS\Http\Url::internal("app=nexus&module=customers&controller=view&id={$this->member->member_id}")->setQueryString( array( 'do' => 'deleteAddress', 'address_id' => $row['id'] ) ),
'link' => Url::internal("app=nexus&module=customers&controller=view&id={$this->member->member_id}")->setQueryString( array( 'do' => 'deleteAddress', 'address_id' => $row['id'] ) ),
'title' => 'delete',
'icon' => 'times-circle',
'data' => array( 'delete' => '' )
@@ -124,9 +157,9 @@ class _view extends \IPS\Dispatcher\Controller
};
}
$addresses->tableTemplate = array( \IPS\Theme::i()->getTemplate('customers'), 'addressTable' );
$addresses->rowsTemplate = array( \IPS\Theme::i()->getTemplate('customers'), 'addressTableRows' );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('customers')->customerPopup( $addresses );
$addresses->tableTemplate = array( Theme::i()->getTemplate('customers'), 'addressTable' );
$addresses->rowsTemplate = array( Theme::i()->getTemplate('customers'), 'addressTableRows' );
Output::i()->output = Theme::i()->getTemplate('customers')->customerPopup( $addresses );
}
/**
@@ -134,17 +167,18 @@ class _view extends \IPS\Dispatcher\Controller
*
* @return void
*/
public function edit()
public function edit() : void
{
\IPS\Dispatcher::i()->checkAcpPermission( 'customers_edit_details' );
Dispatcher::i()->checkAcpPermission( 'customers_edit_details' );
$form = new \IPS\Helpers\Form;
$form = new Form;
$form->add( new \IPS\Helpers\Form\Text( 'cm_first_name', $this->member->cm_first_name, FALSE ) );
$form->add( new \IPS\Helpers\Form\Text( 'cm_last_name', $this->member->cm_last_name, FALSE ) );
$form->add( new Text( 'cm_first_name', $this->member->cm_first_name, FALSE ) );
$form->add( new Text( 'cm_last_name', $this->member->cm_last_name, FALSE ) );
foreach ( \IPS\nexus\Customer\CustomField::roots() as $field )
foreach ( CustomField::roots() as $field )
{
/* @var CustomField $field */
$column = $field->column;
if ( $field->type === 'Editor' )
{
@@ -153,7 +187,7 @@ class _view extends \IPS\Dispatcher\Controller
$form->add( $field->buildHelper( $this->member->$column ) );
}
if ( $values = $form->values( TRUE ) )
if ( $values = $form->values(TRUE) )
{
$changes = array();
foreach ( array( 'cm_first_name', 'cm_last_name' ) as $k )
@@ -169,8 +203,9 @@ class _view extends \IPS\Dispatcher\Controller
$this->member->$k = $values[ $k ];
}
}
foreach ( \IPS\nexus\Customer\CustomField::roots() as $field )
foreach ( CustomField::roots() as $field )
{
/* @var CustomField $field */
$column = $field->column;
if ( $this->member->$column != $values["nexus_ccfield_{$field->id}"] )
{
@@ -188,10 +223,10 @@ class _view extends \IPS\Dispatcher\Controller
$this->member->log( 'info', $changes );
}
$this->member->save();
\IPS\Output::i()->redirect( $this->member->acpUrl() );
Output::i()->redirect( $this->member->acpUrl() );
}
\IPS\Output::i()->output = $form;
Output::i()->output = $form;
}
/**
@@ -199,15 +234,15 @@ class _view extends \IPS\Dispatcher\Controller
*
* @return void
*/
public function credits()
public function credits() : void
{
\IPS\Dispatcher::i()->checkAcpPermission( 'customers_edit_credit' );
Dispatcher::i()->checkAcpPermission( 'customers_edit_credit' );
$form = new \IPS\Helpers\Form;
$form->class = 'ipsForm_vertical';
foreach ( \IPS\nexus\Money::currencies() as $currency )
$form = new Form;
$form->class = 'ipsForm--vertical ipsForm--edit-credits';
foreach ( Money::currencies() as $currency )
{
$form->add( new \IPS\Helpers\Form\Number( $currency, isset( $this->member->cm_credits[ $currency ] ) ? $this->member->cm_credits[ $currency ]->amount : 0, FALSE, array( 'min' => 0, 'decimals' => \IPS\nexus\Money::numberOfDecimalsForCurrency( $currency ) ), NULL, NULL, $currency ) );
$form->add( new Form\Number( $currency, isset( $this->member->cm_credits[ $currency ] ) ? $this->member->cm_credits[ $currency ]->amount : 0, FALSE, array( 'min' => 0, 'decimals' => Money::numberOfDecimalsForCurrency( $currency ) ), NULL, NULL, $currency ) );
}
if ( $values = $form->values() )
@@ -215,19 +250,19 @@ class _view extends \IPS\Dispatcher\Controller
$credits = $this->member->cm_credits;
foreach ( $values as $currency => $amount )
{
$amount = new \IPS\Math\Number( number_format( $amount, \IPS\nexus\Money::numberOfDecimalsForCurrency( $currency ), '.', '' ) );
$amount = new Number( number_format( $amount, Money::numberOfDecimalsForCurrency( $currency ), '.', '' ) );
if ( ( isset( $this->member->cm_credits[ $currency ] ) and $this->member->cm_credits[ $currency ]->amount->compare( $amount ) !== 0 ) or $amount )
{
$this->member->log( 'comission', array( 'type' => 'manual', 'old' => isset( $this->member->cm_credits[ $currency ] ) ? $this->member->cm_credits[ $currency ]->amountAsString() : 0, 'new' => (string) $amount, 'currency' => $currency ) );
}
$credits[ $currency ] = new \IPS\nexus\Money( $amount, $currency );
$credits[ $currency ] = new Money( $amount, $currency );
}
$this->member->cm_credits = $credits;
$this->member->save();
\IPS\Output::i()->redirect( $this->member->acpUrl() );
Output::i()->redirect( $this->member->acpUrl() );
}
\IPS\Output::i()->output = (string) $form;
Output::i()->output = (string) $form;
}
/**
@@ -235,31 +270,31 @@ class _view extends \IPS\Dispatcher\Controller
*
* @return void
*/
public function noteForm()
public function noteForm() : void
{
$noteId = NULL;
$note = NULL;
if ( \IPS\Request::i()->note_id )
if ( Request::i()->note_id )
{
\IPS\Dispatcher::i()->checkAcpPermission( 'customer_notes_edit' );
$noteId = \intval( \IPS\Request::i()->note_id );
Dispatcher::i()->checkAcpPermission( 'customer_notes_edit' );
$noteId = intval( Request::i()->note_id );
try
{
$note = \IPS\Db::i()->select( 'note_text', 'nexus_notes', array( 'note_id=?', \IPS\Request::i()->note_id ) )->first();
$note = Db::i()->select( 'note_text', 'nexus_notes', array( 'note_id=?', Request::i()->note_id ) )->first();
}
catch ( \UnderflowException $e )
catch ( UnderflowException )
{
\IPS\Output::i()->error( 'node_error', '2X233/3', 404, '' );
Output::i()->error( 'node_error', '2X233/3', 404, '' );
}
}
else
{
\IPS\Dispatcher::i()->checkAcpPermission( 'customer_notes_add' );
Dispatcher::i()->checkAcpPermission( 'customer_notes_add' );
}
$form = new \IPS\Helpers\Form;
$form->class = 'ipsForm_vertical';
$form->add( new \IPS\Helpers\Form\Editor( 'customer_note', $note, TRUE, array(
$form = new Form;
$form->class = 'ipsForm--vertical ipsForm--customer-notes';
$form->add( new Editor( 'customer_note', $note, TRUE, array(
'app' => 'nexus',
'key' => 'Customer',
'autoSaveKey' => $noteId ? "nexus-note-{$this->member->member_id}-{$noteId}" : "nexus-note-{$this->member->member_id}-new",
@@ -267,39 +302,31 @@ class _view extends \IPS\Dispatcher\Controller
) ) );
if ( $values = $form->values() )
{
if ( \IPS\Request::i()->note_id )
if ( Request::i()->note_id )
{
\IPS\Db::i()->update( 'nexus_notes', array(
Db::i()->update( 'nexus_notes', array(
'note_text' => $values['customer_note']
), array( 'note_id=?', \IPS\Request::i()->note_id ) );
), array( 'note_id=?', Request::i()->note_id ) );
$this->member->log( 'note', 'edited' );
}
else
{
$noteId = \IPS\Db::i()->insert( 'nexus_notes', array(
$noteId = Db::i()->insert( 'nexus_notes', array(
'note_member' => $this->member->member_id,
'note_text' => $values['customer_note'],
'note_author' => \IPS\Member::loggedIn()->member_id,
'note_author' => Member::loggedIn()->member_id,
'note_date' => time(),
) );
\IPS\File::claimAttachments( "nexus-note-{$this->member->member_id}-new", $this->member->member_id, $noteId, 'note' );
File::claimAttachments( "nexus-note-{$this->member->member_id}-new", $this->member->member_id, $noteId, 'note' );
$this->member->log( 'note', 'added' );
}
if ( isset( \IPS\Request::i()->support ) and \IPS\Request::i()->support )
{
try
{
\IPS\Output::i()->redirect( \IPS\nexus\Support\Request::load( \IPS\Request::i()->support )->acpUrl() );
}
catch ( \OutOfRangeException $e ) {}
}
\IPS\Output::i()->redirect( $this->member->acpUrl() );
Output::i()->redirect( $this->member->acpUrl() );
}
\IPS\Output::i()->output = $form;
Output::i()->output = $form;
}
/**
@@ -307,25 +334,17 @@ class _view extends \IPS\Dispatcher\Controller
*
* @return void
*/
public function deleteNote()
public function deleteNote() : void
{
\IPS\Dispatcher::i()->checkAcpPermission( 'customer_notes_delete' );
Dispatcher::i()->checkAcpPermission( 'customer_notes_delete' );
/* Make sure the user confirmed the deletion */
\IPS\Request::i()->confirmedDelete();
Request::i()->confirmedDelete();
\IPS\Db::i()->delete( 'nexus_notes', array( 'note_id=?', \IPS\Request::i()->note_id ) );
Db::i()->delete( 'nexus_notes', array( 'note_id=?', Request::i()->note_id ) );
$this->member->log( 'note', 'deleted' );
if ( isset( \IPS\Request::i()->support ) and \IPS\Request::i()->support )
{
try
{
\IPS\Output::i()->redirect( \IPS\nexus\Support\Request::load( \IPS\Request::i()->support )->acpUrl() );
}
catch ( \OutOfRangeException $e ) {}
}
\IPS\Output::i()->redirect( $this->member->acpUrl() );
Output::i()->redirect( $this->member->acpUrl() );
}
/**
@@ -333,35 +352,34 @@ class _view extends \IPS\Dispatcher\Controller
*
* @return void
*/
public function addressForm()
public function addressForm() : void
{
\IPS\Dispatcher::i()->checkAcpPermission( 'customers_edit_details' );
Dispatcher::i()->checkAcpPermission( 'customers_edit_details' );
if ( \IPS\Request::i()->address_id )
if ( Request::i()->address_id )
{
try
{
$address = \IPS\nexus\Customer\Address::load( \IPS\Request::i()->address_id );
$address = Address::load( Request::i()->address_id );
if ( $address->member !== $this->member )
{
throw new \OutOfRangeException;
throw new OutOfRangeException;
}
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException )
{
\IPS\Output::i()->error( 'node_error', '2X233/2', 404, '' );
Output::i()->error( 'node_error', '2X233/2', 404, '' );
}
}
else
{
$address = new \IPS\nexus\Customer\Address;
$address = new Address;
$address->member = $this->member;
$address->primary_billing = ( \IPS\Db::i()->select( 'COUNT(*)', 'nexus_customer_addresses', array( '`member`=? AND primary_billing=1', $this->member->member_id ) )->first() == 0 );
$address->primary_shipping = ( \IPS\Db::i()->select( 'COUNT(*)', 'nexus_customer_addresses', array( '`member`=? AND primary_shipping=1', $this->member->member_id ) )->first() == 0 );
$address->primary_billing = ( Db::i()->select( 'COUNT(*)', 'nexus_customer_addresses', array( '`member`=? AND primary_billing=1', $this->member->member_id ) )->first() == 0 );
}
$needTaxStatus = NULL;
foreach ( \IPS\nexus\Tax::roots() as $tax )
foreach ( Tax::roots() as $tax )
{
if ( $tax->type === 'eu' )
{
@@ -376,10 +394,9 @@ class _view extends \IPS\Dispatcher\Controller
$addressHelperClass = $needTaxStatus ? 'IPS\nexus\Form\BusinessAddress' : 'IPS\Helpers\Form\Address';
$addressHelperOptions = ( $needTaxStatus === 'eu' ) ? array( 'vat' => TRUE ) : array();
$form = new \IPS\Helpers\Form;
$form = new Form;
$form->add( new $addressHelperClass( 'address', $address->address, TRUE, $addressHelperOptions ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'primary_billing', $address->primary_billing ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'primary_shipping', $address->primary_shipping ) );
$form->add( new YesNo( 'primary_billing', $address->primary_billing ) );
if ( $values = $form->values() )
{
if ( $address->id )
@@ -390,14 +407,9 @@ class _view extends \IPS\Dispatcher\Controller
}
if ( $values['primary_billing'] and !$address->primary_billing )
{
\IPS\Db::i()->update( 'nexus_customer_addresses', array( 'primary_billing' => 0 ), array( '`member`=?', $this->member->member_id ) );
Db::i()->update( 'nexus_customer_addresses', array( 'primary_billing' => 0 ), array( '`member`=?', $this->member->member_id ) );
$this->member->log( 'address', array( 'type' => 'primary_billing', 'details' => json_encode( $values['address'] ) ) );
}
if ( $values['primary_shipping'] and !$address->primary_shipping )
{
\IPS\Db::i()->update( 'nexus_customer_addresses', array( 'primary_shipping' => 0 ), array( '`member`=?', $this->member->member_id ) );
$this->member->log( 'address', array( 'type' => 'primary_shipping', 'details' => json_encode( $values['address'] ) ) );
}
}
else
{
@@ -406,12 +418,11 @@ class _view extends \IPS\Dispatcher\Controller
$address->address = $values['address'];
$address->primary_billing = $values['primary_billing'];
$address->primary_shipping = $values['primary_shipping'];
$address->save();
\IPS\Output::i()->redirect( $this->member->acpUrl() );
Output::i()->redirect( $this->member->acpUrl() );
}
\IPS\Output::i()->output = $form;
Output::i()->output = $form;
}
/**
@@ -419,21 +430,21 @@ class _view extends \IPS\Dispatcher\Controller
*
* @return void
*/
public function deleteAddress()
public function deleteAddress() : void
{
\IPS\Dispatcher::i()->checkAcpPermission( 'customers_edit_details' );
Dispatcher::i()->checkAcpPermission( 'customers_edit_details' );
/* Make sure the user confirmed the deletion */
\IPS\Request::i()->confirmedDelete();
Request::i()->confirmedDelete();
try
{
$address = \IPS\nexus\Customer\Address::load( \IPS\Request::i()->address_id );
$address = Address::load( Request::i()->address_id );
$this->member->log( 'address', array( 'type' => 'delete', 'details' => json_encode( $address->address ) ) );
$address->delete();
}
catch ( \OutOfRangeException $e ) { }
\IPS\Output::i()->redirect( $this->member->acpUrl() );
catch ( OutOfRangeException ) { }
Output::i()->redirect( $this->member->acpUrl() );
}
/**
@@ -442,18 +453,18 @@ class _view extends \IPS\Dispatcher\Controller
* @csrfChecked Uses Form helper in Gateway classes 7 Oct 2019
* @return void
*/
public function addCard()
public function addCard() : void
{
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'global_gateways.js', 'nexus', 'global' ) );
$form = \IPS\nexus\Customer\CreditCard::create( $this->member, TRUE );
if ( $form instanceof \IPS\nexus\Customer\CreditCard )
Output::i()->jsFiles = array_merge( Output::i()->jsFiles, Output::i()->js( 'global_gateways.js', 'nexus', 'global' ) );
$form = CreditCard::create( $this->member, TRUE );
if ( $form instanceof CreditCard )
{
$this->member->log( 'card', array( 'type' => 'add', 'number' => $form->card->lastFour ) );
\IPS\Output::i()->redirect( $this->member->acpUrl() );
Output::i()->redirect( $this->member->acpUrl() );
}
else
{
\IPS\Output::i()->output = $form;
Output::i()->output = $form;
}
}
@@ -462,19 +473,19 @@ class _view extends \IPS\Dispatcher\Controller
*
* @return void
*/
public function deleteCard()
public function deleteCard() : void
{
/* Make sure the user confirmed the deletion */
\IPS\Request::i()->confirmedDelete();
Request::i()->confirmedDelete();
try
{
$card = \IPS\nexus\Customer\CreditCard::load( \IPS\Request::i()->card_id );
$card = CreditCard::load( Request::i()->card_id );
$this->member->log( 'card', array( 'type' => 'delete', 'number' => $card->card->lastFour ) );
$card->delete();
}
catch ( \OutOfRangeException $e ) { }
\IPS\Output::i()->redirect( $this->member->acpUrl() );
catch ( OutOfRangeException ) { }
Output::i()->redirect( $this->member->acpUrl() );
}
/**
@@ -482,54 +493,52 @@ class _view extends \IPS\Dispatcher\Controller
*
* @return void
*/
public function alternativeContactForm()
public function alternativeContactForm() : void
{
$existing = NULL;
if ( isset( \IPS\Request::i()->alt_id ) )
if ( isset( Request::i()->alt_id ) )
{
try
{
$existing = \IPS\nexus\Customer\AlternativeContact::constructFromData( \IPS\Db::i()->select( '*', 'nexus_alternate_contacts', array( 'main_id=? AND alt_id=?', $this->member->member_id, \IPS\Request::i()->alt_id ) )->first() );
$existing = AlternativeContact::constructFromData( Db::i()->select( '*', 'nexus_alternate_contacts', array( 'main_id=? AND alt_id=?', $this->member->member_id, Request::i()->alt_id ) )->first() );
}
catch ( \UnderflowException $e ) {}
catch ( UnderflowException ) {}
}
$form = new \IPS\Helpers\Form;
$form = new Form;
if ( !$existing )
{
$form->add( new \IPS\Helpers\Form\Member( 'altcontact_member_admin', NULL, TRUE, array(), function( $val )
$form->add( new Form\Member( 'altcontact_member_admin', NULL, TRUE, array(), function( $val )
{
if( $this->member->member_id === $val->member_id )
{
throw new \DomainException('altcontact_member_admin_self');
throw new DomainException('altcontact_member_admin_self');
}
} ) );
}
$form->add( new \IPS\Helpers\Form\Node( 'altcontact_purchases_admin', $existing ? iterator_to_array( $existing->purchases ) : NULL, FALSE, array( 'class' => 'IPS\nexus\Purchase', 'forceOwner' => $this->member, 'multiple' => TRUE ) ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'altcontact_support_admin', $existing ? $existing->support : FALSE ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'altcontact_billing_admin', $existing ? $existing->billing : FALSE ) );
$form->add( new Node( 'altcontact_purchases_admin', $existing ? iterator_to_array( $existing->purchases ) : NULL, FALSE, array( 'class' => 'IPS\nexus\Purchase', 'forceOwner' => $this->member, 'multiple' => TRUE ) ) );
$form->add( new YesNo( 'altcontact_billing_admin', $existing ? $existing->billing : FALSE ) );
if ( $values = $form->values() )
{
if ( $existing )
{
$altContact = $existing;
$this->member->log( 'alternative', array( 'type' => 'edit', 'alt_id' => $altContact->alt_id->member_id, 'alt_name' => $altContact->alt_id->name, 'purchases' => json_encode( $values['altcontact_purchases_admin'] ? $values['altcontact_purchases_admin'] : array() ), 'billing' => $values['altcontact_billing_admin'], 'support' => $values['altcontact_support_admin'] ) );
$this->member->log( 'alternative', array( 'type' => 'edit', 'alt_id' => $altContact->alt_id->member_id, 'alt_name' => $altContact->alt_id->name, 'purchases' => json_encode( $values['altcontact_purchases_admin'] ?: array() ), 'billing' => $values['altcontact_billing_admin'] ) );
}
else
{
$altContact = new \IPS\nexus\Customer\AlternativeContact;
$altContact = new AlternativeContact;
$altContact->main_id = $this->member;
$altContact->alt_id = $values['altcontact_member_admin'];
$this->member->log( 'alternative', array( 'type' => 'add', 'alt_id' => $values['altcontact_member_admin']->member_id, 'alt_name' => $values['altcontact_member_admin']->name, 'purchases' => json_encode( $values['altcontact_purchases_admin'] ? $values['altcontact_purchases_admin'] : array() ), 'billing' => $values['altcontact_billing_admin'], 'support' => $values['altcontact_support_admin'] ) );
$this->member->log( 'alternative', array( 'type' => 'add', 'alt_id' => $values['altcontact_member_admin']->member_id, 'alt_name' => $values['altcontact_member_admin']->name, 'purchases' => json_encode( $values['altcontact_purchases_admin'] ?: array() ), 'billing' => $values['altcontact_billing_admin'] ) );
}
$altContact->purchases = $values['altcontact_purchases_admin'] ? $values['altcontact_purchases_admin'] : array();
$altContact->purchases = $values['altcontact_purchases_admin'] ?: array();
$altContact->billing = $values['altcontact_billing_admin'];
$altContact->support = $values['altcontact_support_admin'];
$altContact->save();
\IPS\Output::i()->redirect( $this->member->acpUrl() );
Output::i()->redirect( $this->member->acpUrl() );
}
\IPS\Output::i()->output = $form;
Output::i()->output = $form;
}
/**
@@ -537,19 +546,19 @@ class _view extends \IPS\Dispatcher\Controller
*
* @return void
*/
public function deleteAlternativeContact()
public function deleteAlternativeContact() : void
{
/* Make sure the user confirmed the deletion */
\IPS\Request::i()->confirmedDelete();
Request::i()->confirmedDelete();
try
{
$contact = \IPS\nexus\Customer\AlternativeContact::constructFromData( \IPS\Db::i()->select( '*', 'nexus_alternate_contacts', array( 'main_id=? AND alt_id=?', $this->member->member_id, \IPS\Request::i()->alt_id ) )->first() );
$contact = AlternativeContact::constructFromData( Db::i()->select( '*', 'nexus_alternate_contacts', array( 'main_id=? AND alt_id=?', $this->member->member_id, Request::i()->alt_id ) )->first() );
$this->member->log( 'alternative', array( 'type' => 'delete', 'alt_id' => $contact->alt_id->member_id, 'alt_name' => $contact->alt_id->name ) );
$contact->delete();
}
catch ( \OutOfRangeException $e ) { }
\IPS\Output::i()->redirect( $this->member->acpUrl() );
catch ( OutOfRangeException ) { }
Output::i()->redirect( $this->member->acpUrl() );
}
/**
@@ -557,37 +566,36 @@ class _view extends \IPS\Dispatcher\Controller
*
* @return void
*/
public function void()
public function void() : void
{
\IPS\Dispatcher::i()->checkAcpPermission( 'customers_void' );
Dispatcher::i()->checkAcpPermission( 'customers_void' );
if ( isset( \IPS\Request::i()->process ) )
if ( isset( Request::i()->process ) )
{
\IPS\Session::i()->csrfCheck();
Session::i()->csrfCheck();
$values = array(
'void_refund_transactions' => \IPS\Request::i()->trans,
'void_cancel_billing_agreements' => \IPS\Request::i()->ba,
'void_cancel_purchases' => \IPS\Request::i()->purch,
'void_refund_transactions' => Request::i()->trans,
'void_cancel_billing_agreements' => Request::i()->ba,
'void_cancel_purchases' => Request::i()->purch,
);
}
else
{
$form = new \IPS\Helpers\Form( 'void_account', 'void_account' );
$form = new Form( 'void_account', 'void_account' );
$form->ajaxOutput = TRUE;
$form->addMessage( 'void_account_warning' );
$form->add( new \IPS\Helpers\Form\YesNo( 'void_refund_transactions', TRUE ) );
if ( \IPS\nexus\Gateway::billingAgreementGateways() )
$form->add( new YesNo( 'void_refund_transactions', TRUE ) );
if ( Gateway::billingAgreementGateways() )
{
$form->add( new \IPS\Helpers\Form\YesNo( 'void_cancel_billing_agreements', TRUE ) );
$form->add( new YesNo( 'void_cancel_billing_agreements', TRUE ) );
}
$form->add( new \IPS\Helpers\Form\YesNo( 'void_cancel_purchases', TRUE ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'void_cancel_invoices', TRUE ) );
$form->add( new \IPS\Helpers\Form\Node( 'void_resolve_support', \IPS\Settings::i()->nexus_autoresolve_status, FALSE, array( 'class' => 'IPS\nexus\Support\Status', 'zeroVal' => 'do_not_change' ) ) );
if ( $this->member->member_id != \IPS\Member::loggedIn()->member_id )
$form->add( new YesNo( 'void_cancel_purchases', TRUE ) );
$form->add( new YesNo( 'void_cancel_invoices', TRUE ) );
if ( $this->member->member_id != Member::loggedIn()->member_id )
{
$form->add( new \IPS\Helpers\Form\YesNo( 'void_ban_account', TRUE ) );
$form->add( new YesNo( 'void_ban_account', TRUE ) );
}
$form->add( new \IPS\Helpers\Form\Editor( 'void_add_note', NULL, FALSE, array(
$form->add( new Editor( 'void_add_note', NULL, FALSE, array(
'app' => 'nexus',
'key' => 'Customer',
'autoSaveKey' => "nexus-note-{$this->member->member_id}-new",
@@ -598,32 +606,28 @@ class _view extends \IPS\Dispatcher\Controller
{
if ( $values['void_cancel_invoices'] )
{
\IPS\Db::i()->update( 'nexus_invoices', array( 'i_status' => \IPS\nexus\Invoice::STATUS_CANCELED ), array( 'i_member=? AND i_status<>?', $this->member->member_id, \IPS\nexus\Invoice::STATUS_PAID ) );
Db::i()->update( 'nexus_invoices', array( 'i_status' => Invoice::STATUS_CANCELED ), array( 'i_member=? AND i_status<>?', $this->member->member_id, Invoice::STATUS_PAID ) );
}
if ( $values['void_resolve_support'] )
{
\IPS\Db::i()->update( 'nexus_support_requests', array( 'r_status' => $values['void_resolve_support']->_id ), array( 'r_member=?', $this->member->member_id ) );
}
if ( $this->member->member_id != \IPS\Member::loggedIn()->member_id and $values['void_ban_account'] )
if ( $this->member->member_id != Member::loggedIn()->member_id and $values['void_ban_account'] )
{
$this->member->temp_ban = -1;
$this->member->save();
}
if ( $values['void_add_note'] )
{
$noteId = \IPS\Db::i()->insert( 'nexus_notes', array(
$noteId = Db::i()->insert( 'nexus_notes', array(
'note_member' => $this->member->member_id,
'note_text' => $values['void_add_note'],
'note_author' => \IPS\Member::loggedIn()->member_id,
'note_author' => Member::loggedIn()->member_id,
'note_date' => time(),
) );
\IPS\File::claimAttachments( "nexus-note-{$this->member->member_id}-new", $this->member->id, $noteId, 'note' );
File::claimAttachments( "nexus-note-{$this->member->member_id}-new", $this->member->id, $noteId, 'note' );
}
if ( !$values['void_refund_transactions'] and !$values['void_cancel_purchases'] and !$values['void_cancel_billing_agreements'] )
{
\IPS\Output::i()->redirect( $this->member->acpUrl() );
Output::i()->redirect( $this->member->acpUrl() );
}
}
}
@@ -632,35 +636,36 @@ class _view extends \IPS\Dispatcher\Controller
{
$member = $this->member;
\IPS\Output::i()->output = new \IPS\Helpers\MultipleRedirect( \IPS\Http\Url::internal("app=nexus&module=customers&controller=view&id={$this->member->member_id}")->setQueryString( array(
Output::i()->output = new MultipleRedirect( Url::internal("app=nexus&module=customers&controller=view&id={$this->member->member_id}")->setQueryString( array(
'do' => 'void',
'process' => 1,
'trans' => $values['void_refund_transactions'],
'ba' => isset( $values['void_cancel_billing_agreements'] ) ? $values['void_cancel_billing_agreements'] : FALSE ,
'ba' => $values['void_cancel_billing_agreements'] ?? FALSE,
'purch' => $values['void_cancel_purchases'],
) )->csrf(), function( $data ) use ( $member )
{
if ( !\is_array( $data ) )
if ( !is_array( $data ) )
{
$data = array( 'trans' => 0, 'ba' => 0, 'purch' => 0, 'fail' => array() );
}
$done = 0;
if ( \IPS\Request::i()->trans )
if ( Request::i()->trans )
{
foreach ( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_transactions', array( 't_member=?', $member->member_id ), 't_id', array( $data['trans'], 10 ) ), 'IPS\nexus\Transaction' ) as $transaction )
foreach ( new ActiveRecordIterator( Db::i()->select( '*', 'nexus_transactions', array( 't_member=?', $member->member_id ), 't_id', array( $data['trans'], 10 ) ), 'IPS\nexus\Transaction' ) as $transaction )
{
if ( \in_array( $transaction->status, array( $transaction::STATUS_PENDING, $transaction::STATUS_WAITING, $transaction::STATUS_GATEWAY_PENDING ) ) )
/* @var Transaction $transaction */
if ( in_array( $transaction->status, array( $transaction::STATUS_PENDING, $transaction::STATUS_WAITING, $transaction::STATUS_GATEWAY_PENDING ) ) )
{
$transaction->status = $transaction::STATUS_REVIEW;
$transaction->save();
}
elseif ( \in_array( $transaction->status, array( $transaction::STATUS_PAID, $transaction::STATUS_HELD, $transaction::STATUS_REVIEW, $transaction::STATUS_PART_REFUNDED ) ) )
elseif ( in_array( $transaction->status, array( $transaction::STATUS_PAID, $transaction::STATUS_HELD, $transaction::STATUS_REVIEW, $transaction::STATUS_PART_REFUNDED ) ) )
{
try
{
if ( $transaction->auth and \in_array( $transaction->status, array( $transaction::STATUS_HELD, $transaction::STATUS_REVIEW ) ) )
if ( $transaction->auth and in_array( $transaction->status, array( $transaction::STATUS_HELD, $transaction::STATUS_REVIEW ) ) )
{
$transaction->void();
}
@@ -669,9 +674,9 @@ class _view extends \IPS\Dispatcher\Controller
$transaction->refund();
}
$transaction->invoice->markUnpaid( \IPS\nexus\Invoice::STATUS_CANCELED, \IPS\Member::loggedIn() );
$transaction->invoice->markUnpaid( Invoice::STATUS_CANCELED, Member::loggedIn() );
}
catch ( \Exception $e )
catch ( Exception )
{
$data['fail'][] = $transaction->id;
}
@@ -681,33 +686,34 @@ class _view extends \IPS\Dispatcher\Controller
$done++;
if ( $done >= 10 )
{
return array( $data, \IPS\Member::loggedIn()->language()->addToStack('processing') );
return array( $data, Member::loggedIn()->language()->addToStack('processing') );
}
}
}
if ( \IPS\Request::i()->ba )
if ( Request::i()->ba )
{
foreach ( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_billing_agreements', array( 'ba_member=?', $member->member_id ), 'ba_id', array( $data['ba'], 10 ) ), 'IPS\nexus\Customer\BillingAgreement' ) as $billingAgreement )
foreach ( new ActiveRecordIterator( Db::i()->select( '*', 'nexus_billing_agreements', array( 'ba_member=?', $member->member_id ), 'ba_id', array( $data['ba'], 10 ) ), 'IPS\nexus\Customer\BillingAgreement' ) as $billingAgreement )
{
/* @var Customer\BillingAgreement $billingAgreement */
try
{
$billingAgreement->cancel();
}
catch ( \Exception $e ) { }
catch ( Exception ) { }
$data['ba']++;
$done++;
if ( $done >= 10 )
{
return array( $data, \IPS\Member::loggedIn()->language()->addToStack('processing') );
return array( $data, Member::loggedIn()->language()->addToStack('processing') );
}
}
}
if ( \IPS\Request::i()->purch )
if ( Request::i()->purch )
{
foreach ( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_purchases', array( 'ps_member=?', $member->member_id ), 'ps_id', array( $data['purch'], 10 ) ), 'IPS\nexus\Purchase' ) as $purchase )
foreach ( new ActiveRecordIterator( Db::i()->select( '*', 'nexus_purchases', array( 'ps_member=?', $member->member_id ), 'ps_id', array( $data['purch'], 10 ) ), 'IPS\nexus\Purchase' ) as $purchase )
{
$purchase->cancelled = TRUE;
$purchase->can_reactivate = FALSE;
@@ -717,7 +723,7 @@ class _view extends \IPS\Dispatcher\Controller
$done++;
if ( $done >= 10 )
{
return array( $data, \IPS\Member::loggedIn()->language()->addToStack('processing') );
return array( $data, Member::loggedIn()->language()->addToStack('processing') );
}
}
}
@@ -726,20 +732,19 @@ class _view extends \IPS\Dispatcher\Controller
return NULL;
}, function() use ( $member )
{
if ( \count( $_SESSION['voidAccountFails'] ) )
if ( count( $_SESSION['voidAccountFails'] ) )
{
\IPS\Output::i()->redirect( $member->acpUrl()->setQueryString( 'do', 'voidFails' ) );
Output::i()->redirect( $member->acpUrl()->setQueryString( 'do', 'voidFails' ) );
}
else
{
\IPS\Output::i()->redirect( $member->acpUrl() );
Output::i()->redirect( $member->acpUrl() );
}
} );
return;
}
else
{
\IPS\Output::i()->output = $form;
Output::i()->output = $form;
}
}
@@ -748,8 +753,8 @@ class _view extends \IPS\Dispatcher\Controller
*
* @return void
*/
public function voidFails()
public function voidFails() : void
{
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'customers' )->voidFails( $_SESSION['voidAccountFails'] );
Output::i()->output = Theme::i()->getTemplate( 'customers' )->voidFails( $_SESSION['voidAccountFails'] );
}
}