Version 4.5.0

This commit is contained in:
Neo committed 2025-12-19 05:51:58 -08:00
1 parent 1a0c7fd3c2
commit f79dcf067a
3791 files changed
+248032 -76372

No files matched your search

@@ -12,7 +12,7 @@
namespace IPS\nexus\modules\admin\customers;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -23,6 +23,11 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
*/
class _view extends \IPS\Dispatcher\Controller
{
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
/**
* @brief Member
*/
@@ -82,12 +87,13 @@ class _view extends \IPS\Dispatcher\Controller
*/
protected function addresses()
{
$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 = 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->parsers = array( 'address' => function( $val )
{
return \IPS\GeoLocation::buildFromJson( $val )->toString( '<br>' );
$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 ) ) : '' );
} );
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'customers_edit_details' ) )
{
@@ -122,23 +128,6 @@ class _view extends \IPS\Dispatcher\Controller
$addresses->rowsTemplate = array( \IPS\Theme::i()->getTemplate('customers'), 'addressTableRows' );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('customers')->customerPopup( $addresses );
}
/**
* View Purchase List
*
* @return void
*/
protected function purchaseList()
{
$purchases = \IPS\nexus\Purchase::tree( \IPS\Http\Url::internal("app=nexus&module=customers&controller=view&id={$this->member->member_id}")->setQueryString( 'do', 'purchaseList' ), array( array( 'ps_member=?', $this->member->member_id ) ) );
$purchases->rootsPerPage = 25;
$purchases->getTotalRoots = function()
{
return \IPS\Db::i()->select( 'COUNT(*)', 'nexus_purchases', array( 'ps_member=? AND ps_show=1 AND ps_parent=0', $this->member->member_id ) )->first();
};
\IPS\Output::i()->output = $purchases;
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'members_purchases', FALSE, array( 'sprintf' => array( $this->member->cm_name ) ) );
}
/**
* Edit Customer Fields
@@ -157,6 +146,10 @@ class _view extends \IPS\Dispatcher\Controller
foreach ( \IPS\nexus\Customer\CustomField::roots() as $field )
{
$column = $field->column;
if ( $field->type === 'Editor' )
{
$field::$editorOptions = array_merge( $field::$editorOptions, array( 'attachIds' => array( $this->member->member_id ) ) );
}
$form->add( $field->buildHelper( $this->member->$column ) );
}
@@ -249,7 +242,7 @@ class _view extends \IPS\Dispatcher\Controller
if ( \IPS\Request::i()->note_id )
{
\IPS\Dispatcher::i()->checkAcpPermission( 'customer_notes_edit' );
$noteId = intval( \IPS\Request::i()->note_id );
$noteId = \intval( \IPS\Request::i()->note_id );
try
{
$note = \IPS\Db::i()->select( 'note_text', 'nexus_notes', array( 'note_id=?', \IPS\Request::i()->note_id ) )->first();
@@ -363,12 +356,28 @@ class _view extends \IPS\Dispatcher\Controller
{
$address = new \IPS\nexus\Customer\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 = ( \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 );
}
$needTaxStatus = NULL;
foreach ( \IPS\nexus\Tax::roots() as $tax )
{
if ( $tax->type === 'eu' )
{
$needTaxStatus = 'eu';
break;
}
if ( $tax->type === 'business' )
{
$needTaxStatus = 'business';
}
}
$addressHelperClass = $needTaxStatus ? 'IPS\nexus\Form\BusinessAddress' : 'IPS\Helpers\Form\Address';
$addressHelperOptions = ( $needTaxStatus === 'eu' ) ? array( 'vat' => TRUE ) : array();
$form = new \IPS\Helpers\Form;
$form->add( new \IPS\Helpers\Form\Address( 'address', $address->address, TRUE ) );
$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 ) );
if ( $values = $form->values() )
@@ -381,12 +390,12 @@ 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 ) );
\IPS\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 ) );
\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'] ) ) );
}
}
@@ -430,12 +439,13 @@ class _view extends \IPS\Dispatcher\Controller
/**
* Add Card
*
* @csrfChecked Uses Form helper in Gateway classes 7 Oct 2019
* @return void
*/
public function addCard()
{
\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 );
$form = \IPS\nexus\Customer\CreditCard::create( $this->member, TRUE );
if ( $form instanceof \IPS\nexus\Customer\CreditCard )
{
$this->member->log( 'card', array( 'type' => 'add', 'number' => $form->card->lastFour ) );
@@ -444,8 +454,7 @@ class _view extends \IPS\Dispatcher\Controller
else
{
\IPS\Output::i()->output = $form;
}
}
}
/**
@@ -488,7 +497,13 @@ class _view extends \IPS\Dispatcher\Controller
$form = new \IPS\Helpers\Form;
if ( !$existing )
{
$form->add( new \IPS\Helpers\Form\Member( 'altcontact_member_admin', NULL, TRUE ) );
$form->add( new \IPS\Helpers\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');
}
} ) );
}
$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 ) );
@@ -548,6 +563,7 @@ class _view extends \IPS\Dispatcher\Controller
if ( isset( \IPS\Request::i()->process ) )
{
\IPS\Session::i()->csrfCheck();
$values = array(
'void_refund_transactions' => \IPS\Request::i()->trans,
'void_cancel_billing_agreements' => \IPS\Request::i()->ba,
@@ -617,14 +633,14 @@ 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(
'do' => 'void',
'do' => 'void',
'process' => 1,
'trans' => $values['void_refund_transactions'],
'ba' => isset( $values['void_cancel_billing_agreements'] ) ? $values['void_cancel_billing_agreements'] : FALSE ,
'purch' => $values['void_cancel_purchases'],
) ), function( $data ) use ( $member )
) )->csrf(), function( $data ) use ( $member )
{
if ( !is_array( $data ) )
if ( !\is_array( $data ) )
{
$data = array( 'trans' => 0, 'ba' => 0, 'purch' => 0, 'fail' => array() );
}
@@ -635,16 +651,16 @@ class _view extends \IPS\Dispatcher\Controller
{
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 )
{
if ( in_array( $transaction->status, array( $transaction::STATUS_PENDING, $transaction::STATUS_WAITING, $transaction::STATUS_GATEWAY_PENDING ) ) )
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 ( $this->auth and in_array( $this->status, array( static::STATUS_HELD, static::STATUS_REVIEW ) ) )
if ( $this->auth and \in_array( $this->status, array( static::STATUS_HELD, static::STATUS_REVIEW ) ) )
{
$transaction->void();
}
@@ -710,7 +726,7 @@ 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' ) );
}