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,26 +12,66 @@
|
||||
namespace IPS\nexus\modules\admin\subscriptions;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use DateInterval;
|
||||
use Exception;
|
||||
use InvalidArgumentException;
|
||||
use IPS\Db;
|
||||
use IPS\Dispatcher;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\CheckboxSet;
|
||||
use IPS\Helpers\Form\Interval;
|
||||
use IPS\Helpers\Form\Matrix;
|
||||
use IPS\Helpers\Form\Node;
|
||||
use IPS\Helpers\Form\Radio;
|
||||
use IPS\Helpers\Form\Select;
|
||||
use IPS\Helpers\Form\YesNo;
|
||||
use IPS\Helpers\MultipleRedirect;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Lang;
|
||||
use IPS\Member;
|
||||
use IPS\Member\Group;
|
||||
use IPS\nexus\Customer;
|
||||
use IPS\nexus\Form\RenewalTerm;
|
||||
use IPS\nexus\Money;
|
||||
use IPS\nexus\Purchase;
|
||||
use IPS\nexus\Subscription;
|
||||
use IPS\nexus\Subscription\Package;
|
||||
use IPS\nexus\Tax;
|
||||
use IPS\Node\Controller;
|
||||
use IPS\Node\Model;
|
||||
use IPS\Output;
|
||||
use IPS\Request;
|
||||
use IPS\Session;
|
||||
use IPS\Settings;
|
||||
use IPS\Theme;
|
||||
use OutOfRangeException;
|
||||
use UnderflowException;
|
||||
use function count;
|
||||
use function defined;
|
||||
use function in_array;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* subscriptions
|
||||
*/
|
||||
class _subscriptions extends \IPS\Node\Controller
|
||||
class subscriptions extends Controller
|
||||
{
|
||||
/**
|
||||
* @brief Has been CSRF-protected
|
||||
*/
|
||||
public static $csrfProtected = TRUE;
|
||||
public static bool $csrfProtected = TRUE;
|
||||
|
||||
/**
|
||||
* Node Class
|
||||
*/
|
||||
protected $nodeClass = 'IPS\nexus\Subscription\Package';
|
||||
protected string $nodeClass = 'IPS\nexus\Subscription\Package';
|
||||
|
||||
/**
|
||||
* Fetch any additional HTML for this row
|
||||
@@ -39,12 +79,12 @@ class _subscriptions extends \IPS\Node\Controller
|
||||
* @param object $node Node returned from $nodeClass::load()
|
||||
* @return NULL|string
|
||||
*/
|
||||
public function _getRowHtml( $node )
|
||||
public function _getRowHtml( object $node ): ?string
|
||||
{
|
||||
$active = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_member_subscriptions', array( 'sub_package_id=? and sub_active=1', $node->id ) )->first();
|
||||
$inactive = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_member_subscriptions', array( 'sub_package_id=? and sub_active=0', $node->id ) )->first();
|
||||
$active = Db::i()->select( 'COUNT(*)', 'nexus_member_subscriptions', array( 'sub_package_id=? and sub_active=1', $node->id ) )->first();
|
||||
$inactive = Db::i()->select( 'COUNT(*)', 'nexus_member_subscriptions', array( 'sub_package_id=? and sub_active=0', $node->id ) )->first();
|
||||
|
||||
return \IPS\Theme::i()->getTemplate( 'subscription', 'nexus' )->rowHtml( $node, $node->priceBlurb(), $active, $inactive );
|
||||
return Theme::i()->getTemplate( 'subscription', 'nexus' )->rowHtml( $node, $node->priceBlurb(), $active, $inactive );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -52,9 +92,9 @@ class _subscriptions extends \IPS\Node\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
public function execute() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'subscriptions_manage' );
|
||||
Dispatcher::i()->checkAcpPermission( 'subscriptions_manage' );
|
||||
|
||||
parent::execute();
|
||||
}
|
||||
@@ -64,22 +104,22 @@ class _subscriptions extends \IPS\Node\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function manage()
|
||||
public function manage() : void
|
||||
{
|
||||
if ( \IPS\Settings::i()->nexus_subs_enabled )
|
||||
if ( Settings::i()->nexus_subs_enabled )
|
||||
{
|
||||
\IPS\Output::i()->sidebar['actions']['settings'] = array(
|
||||
Output::i()->sidebar['actions']['settings'] = array(
|
||||
'primary' => false,
|
||||
'title' => 'settings',
|
||||
'icon' => 'cog',
|
||||
'link' => \IPS\Http\Url::internal('app=nexus&module=subscriptions&controller=subscriptions&do=settings')
|
||||
'link' => Url::internal('app=nexus&module=subscriptions&controller=subscriptions&do=settings')
|
||||
);
|
||||
|
||||
parent::manage();
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'subscription' )->disabled();
|
||||
Output::i()->output = Theme::i()->getTemplate( 'subscription' )->disabled();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,30 +128,30 @@ class _subscriptions extends \IPS\Node\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertToSubscription()
|
||||
public function convertToSubscription() : void
|
||||
{
|
||||
try
|
||||
{
|
||||
$package = \IPS\nexus\Package::load( \IPS\Request::i()->id );
|
||||
$package = \IPS\nexus\Package::load( Request::i()->id );
|
||||
if ( $package->deleteOrMoveQueued() )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
throw new OutOfRangeException;
|
||||
}
|
||||
}
|
||||
catch( \OutOfRangeException $ex )
|
||||
catch( OutOfRangeException )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X393/2', 404, '' );
|
||||
Output::i()->error( 'node_error', '2X393/2', 404, '' );
|
||||
}
|
||||
|
||||
$renewOptions = array();
|
||||
if ( $package->renew_options and $_renewOptions = json_decode( $package->renew_options, TRUE ) and \is_array( $_renewOptions ) )
|
||||
if ( $package->renew_options and $_renewOptions = json_decode( $package->renew_options, TRUE ) and is_array( $_renewOptions ) )
|
||||
{
|
||||
foreach ( $_renewOptions as $option )
|
||||
{
|
||||
$costs = array();
|
||||
foreach ( $option['cost'] as $cost )
|
||||
{
|
||||
$costs[ $cost['currency'] ] = new \IPS\nexus\Money( $cost['amount'], $cost['currency'] );
|
||||
$costs[ $cost['currency'] ] = new Money( $cost['amount'], $cost['currency'] );
|
||||
}
|
||||
|
||||
/* Figure out tax */
|
||||
@@ -121,37 +161,37 @@ class _subscriptions extends \IPS\Node\Controller
|
||||
{
|
||||
if( $package->tax )
|
||||
{
|
||||
$tax = \IPS\nexus\Tax::load( $package->tax );
|
||||
$tax = Tax::load( $package->tax );
|
||||
}
|
||||
}
|
||||
catch( \OutOfRangeException $e ){}
|
||||
catch( OutOfRangeException ){}
|
||||
|
||||
/* Catch any invalid renewal terms, these can occasionally appear from legacy IP.Subscriptions */
|
||||
try
|
||||
{
|
||||
$renewOptions[] = new \IPS\nexus\Purchase\RenewalTerm( $costs, new \DateInterval( "P{$option['term']}" . mb_strtoupper( $option['unit'] ) ), $tax, $option['add'] );
|
||||
$renewOptions[] = new Purchase\RenewalTerm( $costs, new DateInterval( "P{$option['term']}" . mb_strtoupper( $option['unit'] ) ), $tax, $option['add'] );
|
||||
}
|
||||
catch( \Exception $ex) {}
|
||||
catch( Exception ) {}
|
||||
}
|
||||
}
|
||||
|
||||
$useRenewals = array_pop( $renewOptions );
|
||||
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form = new Form;
|
||||
$form->addHeader('nexus_subs_review_pricing');
|
||||
$form->add( new \IPS\nexus\Form\Money( 'sp_price', $package->base_price, TRUE ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'sp_renews', !empty( $useRenewals ), FALSE, array( 'togglesOn' => array( 'sp_renew_options' ) ), NULL, NULL, NULL, 'sp_renews' ) );
|
||||
$form->add( new \IPS\nexus\Form\RenewalTerm( 'sp_renew_options', $useRenewals, NULL, array( 'allCurrencies' => TRUE ), NULL, NULL, NULL, 'sp_renew_options' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'sp_tax', (int) $package->tax, FALSE, array( 'class' => 'IPS\nexus\Tax', 'zeroVal' => 'do_not_tax' ) ) );
|
||||
$form->add( new YesNo( 'sp_renews', !empty( $useRenewals ), FALSE, array( 'togglesOn' => array( 'sp_renew_options' ) ), NULL, NULL, NULL, 'sp_renews' ) );
|
||||
$form->add( new RenewalTerm( 'sp_renew_options', $useRenewals, NULL, array( 'allCurrencies' => TRUE ), NULL, NULL, NULL, 'sp_renew_options' ) );
|
||||
$form->add( new Node( 'sp_tax', (int) $package->tax, FALSE, array( 'class' => 'IPS\nexus\Tax', 'zeroVal' => 'do_not_tax' ) ) );
|
||||
$form->addHeader('nexus_subs_after_conversion');
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'sp_after_conversion_delete', FALSE, FALSE ) );
|
||||
$form->add( new YesNo( 'sp_after_conversion_delete', FALSE, FALSE ) );
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
$sub = new \IPS\nexus\Subscription\Package;
|
||||
$sub = new Package;
|
||||
$sub->enabled = 1;
|
||||
$sub->tax = $values['sp_tax'] ? $values['sp_tax']->id : 0;
|
||||
$sub->gateways = ( isset( $values['sp_gateways'] ) and \is_array( $values['sp_gateways'] ) ) ? implode( ',', array_keys( $values['sp_gateways'] ) ) : '*';
|
||||
$sub->gateways = ( isset( $values['sp_gateways'] ) and is_array( $values['sp_gateways'] ) ) ? implode( ',', array_keys( $values['sp_gateways'] ) ) : '*';
|
||||
$sub->price = json_encode( $values['sp_price'] );
|
||||
|
||||
foreach( array( 'primary_group', 'secondary_group') as $thingsWotAreTheSame )
|
||||
@@ -180,17 +220,17 @@ class _subscriptions extends \IPS\Node\Controller
|
||||
$sub->save();
|
||||
|
||||
/* Language stuffs */
|
||||
\IPS\Lang::copyCustom( 'nexus', "nexus_package_{$package->id}", "nexus_subs_{$sub->id}" );
|
||||
\IPS\Lang::copyCustom( 'nexus', "nexus_package_{$package->id}_desc", "nexus_subs_{$sub->id}_desc" );
|
||||
Lang::copyCustom( 'nexus', "nexus_package_{$package->id}", "nexus_subs_{$sub->id}" );
|
||||
Lang::copyCustom( 'nexus', "nexus_package_{$package->id}_desc", "nexus_subs_{$sub->id}_desc" );
|
||||
|
||||
/* Purchases */
|
||||
foreach( \IPS\Db::i()->select( '*', 'nexus_purchases', array( 'ps_app=? and ps_type=? and ps_active=1 and ps_cancelled=0 and ps_item_id=?', 'nexus', 'package', $package->id ) ) as $purchase )
|
||||
foreach( Db::i()->select( '*', 'nexus_purchases', array( 'ps_app=? and ps_type=? and ps_active=1 and ps_cancelled=0 and ps_item_id=?', 'nexus', 'package', $package->id ) ) as $purchase )
|
||||
{
|
||||
try
|
||||
{
|
||||
$customer = \IPS\nexus\Customer::load( $purchase['ps_member'] );
|
||||
$customer = Customer::load( $purchase['ps_member'] );
|
||||
|
||||
\IPS\Db::i()->update( 'nexus_purchases', array( 'ps_type' => 'subscription', 'ps_item_id' => $sub->id ), array( 'ps_id=?', $purchase['ps_id'] ) );
|
||||
Db::i()->update( 'nexus_purchases', array( 'ps_type' => 'subscription', 'ps_item_id' => $sub->id ), array( 'ps_id=?', $purchase['ps_id'] ) );
|
||||
|
||||
$subscription = $sub->addMember( $customer );
|
||||
$subscription->purchase_id = $purchase['ps_id'];
|
||||
@@ -199,7 +239,7 @@ class _subscriptions extends \IPS\Node\Controller
|
||||
$subscription->start = $purchase['ps_start'];
|
||||
$subscription->save();
|
||||
}
|
||||
catch( \Exception $e ) { }
|
||||
catch( Exception ) { }
|
||||
}
|
||||
|
||||
/* Delete original product */
|
||||
@@ -208,13 +248,13 @@ class _subscriptions extends \IPS\Node\Controller
|
||||
$package->delete();
|
||||
}
|
||||
|
||||
\IPS\Session::i()->log( 'acplogs__nexus_sub_converted', array( "nexus_subs_{$sub->id}" => TRUE ) );
|
||||
Session::i()->log( 'acplogs__nexus_sub_converted', array( "nexus_subs_{$sub->id}" => TRUE ) );
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=subscriptions&controller=subscriptions'), 'nexus_package_converted_lovely' );
|
||||
Output::i()->redirect( Url::internal('app=nexus&module=subscriptions&controller=subscriptions'), 'nexus_package_converted_lovely' );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('nexus_subs_convert');
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'subscription', 'nexus' )->convert( $form, $package );
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack('nexus_subs_convert');
|
||||
Output::i()->output = Theme::i()->getTemplate( 'subscription', 'nexus' )->convert( $form, $package );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -222,15 +262,15 @@ class _subscriptions extends \IPS\Node\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function enable()
|
||||
public function enable() : void
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
Session::i()->csrfCheck();
|
||||
|
||||
\IPS\Settings::i()->changeValues( array( 'nexus_subs_enabled' => true ) );
|
||||
Settings::i()->changeValues( array( 'nexus_subs_enabled' => true ) );
|
||||
|
||||
\IPS\Session::i()->log( 'acplog__subscription_settings' );
|
||||
Session::i()->log( 'acplog__subscription_settings' );
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=subscriptions&controller=subscriptions') );
|
||||
Output::i()->redirect( Url::internal('app=nexus&module=subscriptions&controller=subscriptions') );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -238,37 +278,38 @@ class _subscriptions extends \IPS\Node\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
public function delete() : void
|
||||
{
|
||||
/* Load package */
|
||||
try
|
||||
{
|
||||
$package = \IPS\nexus\Subscription\Package::load( \IPS\Request::i()->id );
|
||||
$package = Package::load( Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException )
|
||||
{
|
||||
return parent::delete();
|
||||
parent::delete();
|
||||
return;
|
||||
}
|
||||
|
||||
/* Are there any purchases of this product? */
|
||||
if ( !isset( \IPS\Request::i()->confirmImplications ) and \IPS\Db::i()->select( 'COUNT(*)', 'nexus_purchases', array( 'ps_app=? AND ps_type=? AND ps_item_id=?', 'nexus', 'subscription', $package->id ) )->first() )
|
||||
if ( !isset( Request::i()->confirmImplications ) and Db::i()->select( 'COUNT(*)', 'nexus_purchases', array( 'ps_app=? AND ps_type=? AND ps_item_id=?', 'nexus', 'subscription', $package->id ) )->first() )
|
||||
{
|
||||
\IPS\Output::i()->bypassCsrfKeyCheck = TRUE;
|
||||
Output::i()->bypassCsrfKeyCheck = TRUE;
|
||||
$options = array(
|
||||
'product_delete_confirm' => \IPS\Http\Url::internal( "app=nexus&module=subscriptions&controller=subscriptions&do=delete&wasConfirmed=1&id={$package->_id}&confirmImplications=1" )->csrf(),
|
||||
'product_delete_confirm' => Url::internal( "app=nexus&module=subscriptions&controller=subscriptions&do=delete&wasConfirmed=1&id={$package->_id}&confirmImplications=1" )->csrf(),
|
||||
);
|
||||
if ( $package->enabled )
|
||||
{
|
||||
$options['product_delete_hide'] = \IPS\Http\Url::internal( "app=nexus&module=subscriptions&controller=subscriptions&do=hide&id={$package->_id}" )->csrf();
|
||||
$options['product_delete_hide'] = Url::internal( "app=nexus&module=subscriptions&controller=subscriptions&do=hide&id={$package->_id}" )->csrf();
|
||||
}
|
||||
$options['cancel'] = \IPS\Http\Url::internal( "app=nexus&module=subscriptions&controller=subscriptions" );
|
||||
$options['cancel'] = Url::internal( "app=nexus&module=subscriptions&controller=subscriptions" );
|
||||
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->decision( 'subscription_delete_blurb', $options );
|
||||
Output::i()->output = Theme::i()->getTemplate( 'global', 'core' )->decision( 'subscription_delete_blurb', $options );
|
||||
return;
|
||||
}
|
||||
|
||||
/* If not, just handle the delete as normal */
|
||||
return parent::delete();
|
||||
parent::delete();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -276,28 +317,28 @@ class _subscriptions extends \IPS\Node\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function hide()
|
||||
public function hide() : void
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
Session::i()->csrfCheck();
|
||||
|
||||
/* Load package */
|
||||
try
|
||||
{
|
||||
$package = \IPS\nexus\Subscription\Package::load( \IPS\Request::i()->id );
|
||||
$package = Package::load( Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '1X393/2', 404, '' );
|
||||
Output::i()->error( 'node_error', '1X393/2', 404, '' );
|
||||
}
|
||||
|
||||
/* Do it */
|
||||
$package->enabled = FALSE;
|
||||
$package->save();
|
||||
|
||||
\IPS\Session::i()->log( 'aplogs__nexus_sub_hidden', array( "nexus_subs_{$package->id}" => TRUE ) );
|
||||
|
||||
Session::i()->log( 'aplogs__nexus_sub_hidden', array( "nexus_subs_{$package->id}" => TRUE ) );
|
||||
|
||||
/* Redirect */
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=nexus&module=subscriptions&controller=subscriptions" ) );
|
||||
Output::i()->redirect( Url::internal( "app=nexus&module=subscriptions&controller=subscriptions" ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -305,24 +346,24 @@ class _subscriptions extends \IPS\Node\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function addMember()
|
||||
protected function addMember() : void
|
||||
{
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->add( new \IPS\Helpers\Form\Member( 'nexus_subs_member_to_add', NULL, TRUE, array(), function( $val )
|
||||
$form = new Form;
|
||||
$form->add( new Form\Member( 'nexus_subs_member_to_add', NULL, TRUE, array(), function($val )
|
||||
{
|
||||
if ( $val instanceof \IPS\Member )
|
||||
if ( $val instanceof Member )
|
||||
{
|
||||
$sub = \IPS\nexus\Subscription::loadByMember( $val, false );
|
||||
$sub = Subscription::loadByMember( $val, false );
|
||||
|
||||
/* We have cannot have duplicate active subscriptions, so error out */
|
||||
if( $sub !== NULL )
|
||||
{
|
||||
throw new \InvalidArgumentException( 'nexus_subs_add_member_already_subscribed' );
|
||||
throw new InvalidArgumentException( 'nexus_subs_add_member_already_subscribed' );
|
||||
}
|
||||
}
|
||||
}, NULL, NULL, 'nexus_subs_member_to_add' ) );
|
||||
|
||||
$package = \IPS\nexus\Subscription\Package::load( \IPS\Request::i()->id );
|
||||
$package = Package::load( Request::i()->id );
|
||||
if( $term = $package->renewalTerm() )
|
||||
{
|
||||
|
||||
@@ -331,45 +372,45 @@ class _subscriptions extends \IPS\Node\Controller
|
||||
$costs = array();
|
||||
foreach ( $newOption['cost'] as $data )
|
||||
{
|
||||
$costs[] = new \IPS\nexus\Money( $data['amount'], $data['currency'] );
|
||||
$costs[] = new Money( $data['amount'], $data['currency'] );
|
||||
}
|
||||
|
||||
switch ( $newOption['unit'] )
|
||||
{
|
||||
case 'd':
|
||||
$initialTerm = \IPS\Member::loggedIn()->language()->addToStack('renew_days_no_term', FALSE, array( 'pluralize' => array( $newOption['term'] ) ) );
|
||||
$term = \IPS\Member::loggedIn()->language()->addToStack('renew_days', FALSE, array( 'pluralize' => array( $newOption['term'] ) ) );
|
||||
$initialTerm = Member::loggedIn()->language()->addToStack('renew_days_no_term', FALSE, array( 'pluralize' => array( $newOption['term'] ) ) );
|
||||
$term = Member::loggedIn()->language()->addToStack('renew_days', FALSE, array( 'pluralize' => array( $newOption['term'] ) ) );
|
||||
break;
|
||||
case 'm':
|
||||
$initialTerm = \IPS\Member::loggedIn()->language()->addToStack('renew_months_no_term', FALSE, array( 'pluralize' => array( $newOption['term'] ) ) );
|
||||
$term = \IPS\Member::loggedIn()->language()->addToStack('renew_months', FALSE, array( 'pluralize' => array( $newOption['term'] ) ) );
|
||||
$initialTerm = Member::loggedIn()->language()->addToStack('renew_months_no_term', FALSE, array( 'pluralize' => array( $newOption['term'] ) ) );
|
||||
$term = Member::loggedIn()->language()->addToStack('renew_months', FALSE, array( 'pluralize' => array( $newOption['term'] ) ) );
|
||||
break;
|
||||
case 'y':
|
||||
$initialTerm = \IPS\Member::loggedIn()->language()->addToStack('renew_years_no_term', FALSE, array( 'pluralize' => array( $newOption['term'] ) ) );
|
||||
$term = \IPS\Member::loggedIn()->language()->addToStack('renew_years', FALSE, array( 'pluralize' => array( $newOption['term'] ) ) );
|
||||
$initialTerm = Member::loggedIn()->language()->addToStack('renew_years_no_term', FALSE, array( 'pluralize' => array( $newOption['term'] ) ) );
|
||||
$term = Member::loggedIn()->language()->addToStack('renew_years', FALSE, array( 'pluralize' => array( $newOption['term'] ) ) );
|
||||
break;
|
||||
}
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'nexus_subs_free_period', NULL, TRUE, [
|
||||
$form->add( new Radio( 'nexus_subs_free_period', NULL, TRUE, [
|
||||
'options' => [
|
||||
0 => 'nexus_subs_forever',
|
||||
1 => \IPS\Member::loggedIn()->language()->addToStack( 'nexus_subs_until_renew', FALSE, [ 'sprintf' => [ $newOption['term'], $initialTerm, \IPS\Member::loggedIn()->language()->formatList( $costs, \IPS\Member::loggedIn()->language()->get('or_list_format') ), $term ] ] )
|
||||
1 => Member::loggedIn()->language()->addToStack( 'nexus_subs_until_renew', FALSE, [ 'sprintf' => [ $newOption['term'], $initialTerm, Member::loggedIn()->language()->formatList( $costs, Member::loggedIn()->language()->get('or_list_format') ), $term ] ] )
|
||||
]
|
||||
] ) );
|
||||
}
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
$customer = \IPS\nexus\Customer::load( $values['nexus_subs_member_to_add']->member_id );
|
||||
$sub = \IPS\nexus\Subscription\Package::load( \IPS\Request::i()->id )->addMember( $customer, TRUE, isset( $values[ 'nexus_subs_free_period' ] ) && (bool) $values[ 'nexus_subs_free_period' ] );
|
||||
$customer = Customer::load( $values['nexus_subs_member_to_add']->member_id );
|
||||
$sub = Package::load( Request::i()->id )->addMember( $customer, TRUE, isset( $values[ 'nexus_subs_free_period' ] ) && (bool) $values[ 'nexus_subs_free_period' ] );
|
||||
$sub->added_manually = 1;
|
||||
$sub->save();
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=subscriptions&controller=subscriptions'), 'nexus_sub_member_added' );
|
||||
Output::i()->redirect( Url::internal('app=nexus&module=subscriptions&controller=subscriptions'), 'nexus_sub_member_added' );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('nexus_subs_add_member');
|
||||
\IPS\Output::i()->output = $form;
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack('nexus_subs_add_member');
|
||||
Output::i()->output = $form;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -377,39 +418,39 @@ class _subscriptions extends \IPS\Node\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function settings()
|
||||
protected function settings() : void
|
||||
{
|
||||
$groups = array();
|
||||
foreach ( \IPS\Member\Group::groups( FALSE, FALSE ) as $group )
|
||||
foreach ( Group::groups( FALSE, FALSE ) as $group )
|
||||
{
|
||||
$groups[ $group->g_id ] = $group->name;
|
||||
}
|
||||
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form = new Form;
|
||||
|
||||
$form->addHeader('subscription_basic_settings');
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'nexus_subs_enabled', \IPS\Settings::i()->nexus_subs_enabled, FALSE, array(), NULL, NULL, NULL, 'nexus_subs_enabled' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'nexus_subs_register', (int) \IPS\Settings::i()->nexus_subs_register, FALSE, [
|
||||
$form->add( new YesNo( 'nexus_subs_enabled', Settings::i()->nexus_subs_enabled, FALSE, array(), NULL, NULL, NULL, 'nexus_subs_enabled' ) );
|
||||
$form->add( new Radio( 'nexus_subs_register', (int) Settings::i()->nexus_subs_register, FALSE, [
|
||||
'options' => [
|
||||
0 => 'nexus_subs_register_none',
|
||||
1 => 'nexus_subs_register_reg',
|
||||
2 => 'nexus_subs_register_always'
|
||||
]
|
||||
], NULL, NULL, NULL, 'nexus_subs_register' ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'nexus_subs_show_public', \IPS\Settings::i()->nexus_subs_show_public, FALSE, array(), NULL, NULL, NULL, 'nexus_subs_show_public' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Interval( 'nexus_subs_invoice_grace', \IPS\Settings::i()->nexus_subs_invoice_grace ?: 0, FALSE, array( 'valueAs' => \IPS\Helpers\Form\Interval::DAYS ), NULL, NULL, NULL, 'nexus_subs_invoice_grace' ) );
|
||||
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'nexus_subs_exclude_groups', explode( ',', \IPS\Settings::i()->nexus_subs_exclude_groups ), FALSE, array( 'options' => $groups, 'multiple' => TRUE ) ) );
|
||||
$form->add( new YesNo( 'nexus_subs_show_public', Settings::i()->nexus_subs_show_public, FALSE, array(), NULL, NULL, NULL, 'nexus_subs_show_public' ) );
|
||||
$form->add( new Interval( 'nexus_subs_invoice_grace', Settings::i()->nexus_subs_invoice_grace ?: 0, FALSE, array( 'valueAs' => Interval::DAYS ), NULL, NULL, NULL, 'nexus_subs_invoice_grace' ) );
|
||||
$form->add( new CheckboxSet( 'nexus_subs_exclude_groups', explode( ',', Settings::i()->nexus_subs_exclude_groups ), FALSE, array( 'options' => $groups, 'multiple' => TRUE ) ) );
|
||||
|
||||
|
||||
$form->addHeader('package_upgrade_downgrade');
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'nexus_subs_upgrade_toggle', \IPS\Settings::i()->nexus_subs_upgrade > -1, FALSE, array( 'togglesOn' => array( 'nexus_subs_upgrade' ) ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'nexus_subs_upgrade', \IPS\Settings::i()->nexus_subs_upgrade, FALSE, array( 'options' => array(
|
||||
$form->add( new YesNo( 'nexus_subs_upgrade_toggle', Settings::i()->nexus_subs_upgrade > -1, FALSE, array( 'togglesOn' => array( 'nexus_subs_upgrade' ) ) ) );
|
||||
$form->add( new Radio( 'nexus_subs_upgrade', Settings::i()->nexus_subs_upgrade, FALSE, array( 'options' => array(
|
||||
0 => 'p_upgrade_charge_none',
|
||||
1 => 'p_upgrade_charge_full',
|
||||
2 => 'p_upgrade_charge_prorate'
|
||||
) ), NULL, NULL, NULL, 'nexus_subs_upgrade' ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'nexus_subs_downgrade_toggle', \IPS\Settings::i()->nexus_subs_downgrade > -1, FALSE, array( 'togglesOn' => array( 'nexus_subs_downgrade' ) ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'nexus_subs_downgrade', \IPS\Settings::i()->nexus_subs_downgrade, FALSE, array( 'options' => array(
|
||||
$form->add( new YesNo( 'nexus_subs_downgrade_toggle', Settings::i()->nexus_subs_downgrade > -1, FALSE, array( 'togglesOn' => array( 'nexus_subs_downgrade' ) ) ) );
|
||||
$form->add( new Radio( 'nexus_subs_downgrade', Settings::i()->nexus_subs_downgrade, FALSE, array( 'options' => array(
|
||||
0 => 'p_downgrade_refund_none',
|
||||
1 => 'p_downgrade_refund_full',
|
||||
2 => 'p_downgrade_refund_prorate'
|
||||
@@ -436,23 +477,23 @@ class _subscriptions extends \IPS\Node\Controller
|
||||
|
||||
$form->saveAsSettings( $values );
|
||||
|
||||
\IPS\Session::i()->log( 'acplog__nexus_subs_settings' );
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=subscriptions&controller=subscriptions') );
|
||||
Session::i()->log( 'acplog__nexus_subs_settings' );
|
||||
Output::i()->redirect( Url::internal('app=nexus&module=subscriptions&controller=subscriptions') );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('settings');
|
||||
\IPS\Output::i()->output = $form;
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack('settings');
|
||||
Output::i()->output = $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect after save
|
||||
*
|
||||
* @param \IPS\Node\Model $old A clone of the node as it was before or NULL if this is a creation
|
||||
* @param \IPS\Node\Model $new The node now
|
||||
* @param Model|null $old A clone of the node as it was before or NULL if this is a creation
|
||||
* @param Model $new The node now
|
||||
* @param string $lastUsedTab The tab last used in the form
|
||||
* @return void
|
||||
*/
|
||||
protected function _afterSave( ?\IPS\Node\Model $old, \IPS\Node\Model $new, $lastUsedTab = FALSE )
|
||||
protected function _afterSave( ?Model $old, Model $new, mixed $lastUsedTab = FALSE ): void
|
||||
{
|
||||
$changes = array();
|
||||
if ( $old )
|
||||
@@ -469,23 +510,23 @@ class _subscriptions extends \IPS\Node\Controller
|
||||
/* If something has changed, see if anyone has purchased */
|
||||
$purchases = 0;
|
||||
|
||||
if( \count( $changes ) )
|
||||
if( count( $changes ) )
|
||||
{
|
||||
$purchases = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_member_subscriptions', array( 'sub_package_id=? AND sub_active=1 and sub_added_manually=0', $new->id ) )->first();
|
||||
$purchases = Db::i()->select( 'COUNT(*)', 'nexus_member_subscriptions', array( 'sub_package_id=? AND sub_active=1 and sub_added_manually=0', $new->id ) )->first();
|
||||
}
|
||||
|
||||
/* Only show this screen if the package has been purchased. Otherwise even just copying a package and saving asks if you want to update
|
||||
existing purchases unnecessarily */
|
||||
if ( !empty( $changes ) AND $purchases )
|
||||
{
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->decision( 'product_change_blurb', array(
|
||||
'product_change_blurb_existing' => \IPS\Http\Url::internal( "app=nexus&module=subscriptions&controller=subscriptions&do=updateExisting&id={$new->_id}" )->setQueryString( 'changes', json_encode( $changes ) )->csrf(),
|
||||
Output::i()->output = Theme::i()->getTemplate( 'global', 'core' )->decision( 'product_change_blurb', array(
|
||||
'product_change_blurb_existing' => Url::internal( "app=nexus&module=subscriptions&controller=subscriptions&do=updateExisting&id={$new->_id}" )->setQueryString( 'changes', json_encode( $changes ) )->csrf(),
|
||||
'product_change_blurb_new' => $this->url->setQueryString( array( 'root' => ( $new->parent() ? $new->parent()->_id : '' ) ) ),
|
||||
) );
|
||||
}
|
||||
else
|
||||
{
|
||||
return parent::_afterSave( $old, $new, $lastUsedTab );
|
||||
parent::_afterSave( $old, $new, $lastUsedTab );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -494,55 +535,55 @@ class _subscriptions extends \IPS\Node\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function updateExisting()
|
||||
public function updateExisting() : void
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
Session::i()->csrfCheck();
|
||||
|
||||
try
|
||||
{
|
||||
$package = \IPS\nexus\Subscription\Package::load( \IPS\Request::i()->id );
|
||||
$package = Package::load( Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '1X393/1', 404, '' );
|
||||
Output::i()->error( 'node_error', '1X393/1', 404, '' );
|
||||
}
|
||||
|
||||
$changes = json_decode( \IPS\Request::i()->changes, TRUE );
|
||||
$changes = json_decode( Request::i()->changes, TRUE );
|
||||
|
||||
if ( !isset( \IPS\Request::i()->processing ) )
|
||||
if ( !isset( Request::i()->processing ) )
|
||||
{
|
||||
if ( isset( $changes['renew_options'] ) )
|
||||
{
|
||||
\IPS\Output::i()->bypassCsrfKeyCheck = TRUE;
|
||||
$matrix = new \IPS\Helpers\Form\Matrix( 'matrix', 'continue' );
|
||||
Output::i()->bypassCsrfKeyCheck = TRUE;
|
||||
$matrix = new Matrix( 'matrix', 'continue' );
|
||||
$matrix->manageable = FALSE;
|
||||
|
||||
$newOptions = array( '-' => \IPS\Member::loggedIn()->language()->addToStack('do_not_change') );
|
||||
$newOptions = array( '-' => Member::loggedIn()->language()->addToStack('do_not_change') );
|
||||
$newOption = json_decode( $package->renew_options, TRUE );
|
||||
|
||||
$costs = array();
|
||||
foreach ( $newOption['cost'] as $data )
|
||||
{
|
||||
$costs[] = new \IPS\nexus\Money( $data['amount'], $data['currency'] );
|
||||
$costs[] = new Money( $data['amount'], $data['currency'] );
|
||||
}
|
||||
|
||||
switch ( $newOption['unit'] )
|
||||
{
|
||||
case 'd':
|
||||
$term = \IPS\Member::loggedIn()->language()->addToStack('renew_days', FALSE, array( 'pluralize' => array( $newOption['term'] ) ) );
|
||||
$term = Member::loggedIn()->language()->addToStack('renew_days', FALSE, array( 'pluralize' => array( $newOption['term'] ) ) );
|
||||
break;
|
||||
case 'm':
|
||||
$term = \IPS\Member::loggedIn()->language()->addToStack('renew_months', FALSE, array( 'pluralize' => array( $newOption['term'] ) ) );
|
||||
$term = Member::loggedIn()->language()->addToStack('renew_months', FALSE, array( 'pluralize' => array( $newOption['term'] ) ) );
|
||||
break;
|
||||
case 'y':
|
||||
$term = \IPS\Member::loggedIn()->language()->addToStack('renew_years', FALSE, array( 'pluralize' => array( $newOption['term'] ) ) );
|
||||
$term = Member::loggedIn()->language()->addToStack('renew_years', FALSE, array( 'pluralize' => array( $newOption['term'] ) ) );
|
||||
break;
|
||||
}
|
||||
|
||||
$newOptions['o'] = \IPS\Member::loggedIn()->language()->addToStack( 'renew_option', FALSE, array( 'sprintf' => array( \IPS\Member::loggedIn()->language()->formatList( $costs, \IPS\Member::loggedIn()->language()->get('or_list_format') ), $term ) ) );
|
||||
$newOptions['z'] = \IPS\Member::loggedIn()->language()->addToStack('remove_renewal_no_expire_leave');
|
||||
$newOptions['y'] = \IPS\Member::loggedIn()->language()->addToStack('remove_renewal_no_expire_reactivate');
|
||||
$newOptions['x'] = \IPS\Member::loggedIn()->language()->addToStack('remove_renewal_expire');
|
||||
$newOptions['o'] = Member::loggedIn()->language()->addToStack( 'renew_option', FALSE, array( 'sprintf' => array( Member::loggedIn()->language()->formatList( $costs, Member::loggedIn()->language()->get('or_list_format') ), $term ) ) );
|
||||
$newOptions['z'] = Member::loggedIn()->language()->addToStack('remove_renewal_no_expire_leave');
|
||||
$newOptions['y'] = Member::loggedIn()->language()->addToStack('remove_renewal_no_expire_reactivate');
|
||||
$newOptions['x'] = Member::loggedIn()->language()->addToStack('remove_renewal_expire');
|
||||
$matrix->columns = array(
|
||||
'customers_currently_paying' => function( $key, $value, $data )
|
||||
{
|
||||
@@ -550,7 +591,7 @@ class _subscriptions extends \IPS\Node\Controller
|
||||
},
|
||||
'now_pay' => function( $key, $value, $data ) use ( $newOptions )
|
||||
{
|
||||
return new \IPS\Helpers\Form\Select( $key, $data[1], TRUE, array( 'options' => $newOptions, 'noDefault' => TRUE ) );
|
||||
return new Select( $key, $data[1], TRUE, array( 'options' => $newOptions, 'noDefault' => TRUE ) );
|
||||
},
|
||||
);
|
||||
|
||||
@@ -561,23 +602,23 @@ class _subscriptions extends \IPS\Node\Controller
|
||||
|
||||
foreach ( $oldOption['cost'] as $data )
|
||||
{
|
||||
$costs[] = new \IPS\nexus\Money( $data['amount'], $data['currency'] );
|
||||
$costs[] = new Money( $data['amount'], $data['currency'] );
|
||||
}
|
||||
|
||||
switch ( $oldOption['unit'] )
|
||||
{
|
||||
case 'd':
|
||||
$term = \IPS\Member::loggedIn()->language()->addToStack('renew_days', FALSE, array( 'pluralize' => array( $oldOption['term'] ) ) );
|
||||
$term = Member::loggedIn()->language()->addToStack('renew_days', FALSE, array( 'pluralize' => array( $oldOption['term'] ) ) );
|
||||
break;
|
||||
case 'm':
|
||||
$term = \IPS\Member::loggedIn()->language()->addToStack('renew_months', FALSE, array( 'pluralize' => array( $oldOption['term'] ) ) );
|
||||
$term = Member::loggedIn()->language()->addToStack('renew_months', FALSE, array( 'pluralize' => array( $oldOption['term'] ) ) );
|
||||
break;
|
||||
case 'y':
|
||||
$term = \IPS\Member::loggedIn()->language()->addToStack('renew_years', FALSE, array( 'pluralize' => array( $oldOption['term'] ) ) );
|
||||
$term = Member::loggedIn()->language()->addToStack('renew_years', FALSE, array( 'pluralize' => array( $oldOption['term'] ) ) );
|
||||
break;
|
||||
}
|
||||
|
||||
$matrix->rows[ 1 ] = array( \IPS\Member::loggedIn()->language()->addToStack( 'renew_option', FALSE, array( 'sprintf' => array( \IPS\Member::loggedIn()->language()->formatList( $costs, \IPS\Member::loggedIn()->language()->get('or_list_format') ), $term ) ) ), "o" );
|
||||
$matrix->rows[ 1 ] = array( Member::loggedIn()->language()->addToStack( 'renew_option', FALSE, array( 'sprintf' => array( Member::loggedIn()->language()->formatList( $costs, Member::loggedIn()->language()->get('or_list_format') ), $term ) ) ), "o" );
|
||||
}
|
||||
|
||||
if ( $values = $matrix->values() )
|
||||
@@ -591,17 +632,17 @@ class _subscriptions extends \IPS\Node\Controller
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->output .= $matrix;
|
||||
Output::i()->output .= $matrix;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ( isset( $changes['renew_options'] ) or isset( $changes['tax'] ) ) and !isset( \IPS\Request::i()->ba ) )
|
||||
if ( ( isset( $changes['renew_options'] ) or isset( $changes['tax'] ) ) and !isset( Request::i()->ba ) )
|
||||
{
|
||||
$needBaPrompt = FALSE;
|
||||
$canChangeOptions = FALSE;
|
||||
if ( isset( $changes['renew_options'] ) and !\in_array( $changes['renew_options']['new'], array( '-', 'x', 'y', 'z' ) ) )
|
||||
if ( isset( $changes['renew_options'] ) and !in_array( $changes['renew_options']['new'], array( '-', 'x', 'y', 'z' ) ) )
|
||||
{
|
||||
$needBaPrompt = TRUE;
|
||||
$canChangeOptions = TRUE;
|
||||
@@ -611,17 +652,17 @@ class _subscriptions extends \IPS\Node\Controller
|
||||
$needBaPrompt = TRUE;
|
||||
}
|
||||
|
||||
if ( $needBaPrompt and $withBillingAgreement = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_purchases', array( 'ps_app=? AND ps_type=? AND ps_item_id=? AND ps_billing_agreement>0 AND ba_canceled=0', 'nexus', 'subscription', $package->id ) )->join( 'nexus_billing_agreements', 'ba_id=ps_billing_agreement' )->first() )
|
||||
if ( $needBaPrompt and $withBillingAgreement = Db::i()->select( 'COUNT(*)', 'nexus_purchases', array( 'ps_app=? AND ps_type=? AND ps_item_id=? AND ps_billing_agreement>0 AND ba_canceled=0', 'nexus', 'subscription', $package->id ) )->join( 'nexus_billing_agreements', 'ba_id=ps_billing_agreement' )->first() )
|
||||
{
|
||||
$options = array(
|
||||
'change_renew_ba_skip' => \IPS\Http\Url::internal( "app=nexus&module=subscriptions&controller=subscriptions&do=updateExisting" )->setQueryString( array(
|
||||
'id' => \IPS\Request::i()->id,
|
||||
'change_renew_ba_skip' => Url::internal( "app=nexus&module=subscriptions&controller=subscriptions&do=updateExisting" )->setQueryString( array(
|
||||
'id' => Request::i()->id,
|
||||
'changes' => json_encode( $changes ),
|
||||
'processing'=> 1,
|
||||
'ba' => 0
|
||||
) )->csrf(),
|
||||
'change_renew_ba_cancel' => \IPS\Http\Url::internal( "app=nexus&module=subscriptions&controller=subscriptions&do=updateExisting" )->setQueryString( array(
|
||||
'id' => \IPS\Request::i()->id,
|
||||
'change_renew_ba_cancel' => Url::internal( "app=nexus&module=subscriptions&controller=subscriptions&do=updateExisting" )->setQueryString( array(
|
||||
'id' => Request::i()->id,
|
||||
'changes' => json_encode( $changes ),
|
||||
'processing'=> 1,
|
||||
'ba' => 1
|
||||
@@ -630,44 +671,44 @@ class _subscriptions extends \IPS\Node\Controller
|
||||
|
||||
if ( $canChangeOptions )
|
||||
{
|
||||
$options['change_renew_ba_go_back'] = \IPS\Http\Url::internal( "app=nexus&module=subscriptions&controller=subscriptions&do=updateExisting" )->setQueryString( array(
|
||||
'id' => \IPS\Request::i()->id,
|
||||
'changes' => \IPS\Request::i()->changes,
|
||||
$options['change_renew_ba_go_back'] = Url::internal( "app=nexus&module=subscriptions&controller=subscriptions&do=updateExisting" )->setQueryString( array(
|
||||
'id' => Request::i()->id,
|
||||
'changes' => Request::i()->changes,
|
||||
) )->csrf();
|
||||
}
|
||||
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->decision( 'change_renew_ba_blurb', $options );
|
||||
Output::i()->output = Theme::i()->getTemplate( 'global', 'core' )->decision( 'change_renew_ba_blurb', $options );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
\IPS\Output::i()->output = new \IPS\Helpers\MultipleRedirect(
|
||||
\IPS\Http\Url::internal( "app=nexus&module=subscriptions&controller=subscriptions&do=updateExisting&id=1&changes=secondary_group" )->setQueryString( array(
|
||||
'id' => \IPS\Request::i()->id,
|
||||
Output::i()->output = new MultipleRedirect(
|
||||
Url::internal( "app=nexus&module=subscriptions&controller=subscriptions&do=updateExisting&id=1&changes=secondary_group" )->setQueryString( array(
|
||||
'id' => Request::i()->id,
|
||||
'changes' => json_encode( $changes ),
|
||||
'processing'=> 1,
|
||||
'ba' => isset( \IPS\Request::i()->ba ) ? \IPS\Request::i()->ba : 0
|
||||
'ba' => isset( Request::i()->ba ) ? Request::i()->ba : 0
|
||||
) )->csrf(),
|
||||
function( $data ) use ( $package, $changes )
|
||||
{
|
||||
if( !\is_array( $data ) )
|
||||
if( !is_array( $data ) )
|
||||
{
|
||||
$data['offset'] = 0;
|
||||
$data['lastId'] = 0;
|
||||
}
|
||||
|
||||
$select = \IPS\Db::i()->select( '*', 'nexus_purchases', array( "ps_id>? and ps_app=? and ps_type=? and ps_item_id=?", $data['lastId'], 'nexus', 'subscription', $package->id ), 'ps_id', 1 );
|
||||
$select = Db::i()->select( '*', 'nexus_purchases', array( "ps_id>? and ps_app=? and ps_type=? and ps_item_id=?", $data['lastId'], 'nexus', 'subscription', $package->id ), 'ps_id', 1 );
|
||||
|
||||
try
|
||||
{
|
||||
$purchase = \IPS\nexus\Purchase::constructFromData( $select->first() );
|
||||
$total = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_purchases', array( "ps_app=? and ps_type=? and ps_item_id=?", 'nexus', 'subscription', $package->id ) )->first();
|
||||
$purchase = Purchase::constructFromData( $select->first() );
|
||||
$total = Db::i()->select( 'COUNT(*)', 'nexus_purchases', array( "ps_app=? and ps_type=? and ps_item_id=?", 'nexus', 'subscription', $package->id ) )->first();
|
||||
|
||||
$package->updatePurchase( $purchase, $changes, \IPS\Request::i()->ba );
|
||||
$package->updatePurchase( $purchase, $changes, Request::i()->ba );
|
||||
|
||||
return array( [ 'offset' => ++$data['offset'], 'lastId' => $purchase->id ], \IPS\Member::loggedIn()->language()->get('processing'), 100 / $total * $data['offset'] );
|
||||
return array( [ 'offset' => ++$data['offset'], 'lastId' => $purchase->id ], Member::loggedIn()->language()->get('processing'), 100 / $total * $data['offset'] );
|
||||
}
|
||||
catch ( \UnderflowException $e )
|
||||
catch ( UnderflowException )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
@@ -675,7 +716,7 @@ class _subscriptions extends \IPS\Node\Controller
|
||||
},
|
||||
function() use ( $package )
|
||||
{
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=nexus&module=subscriptions&controller=subscriptions" )->setQueryString( array( 'root' => ( $package->parent() ? $package->parent()->_id : '' ) ) ) );
|
||||
Output::i()->redirect( Url::internal( "app=nexus&module=subscriptions&controller=subscriptions" )->setQueryString( array( 'root' => ( $package->parent() ? $package->parent()->_id : '' ) ) ) );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user