Version 4.7.0

This commit is contained in:
Neo committed 2025-12-19 16:00:35 -08:00
1 parent 517a5e1f70
commit 8ba7d43898
1933 files changed
+65613 -11332

No files matched your search

@@ -145,30 +145,6 @@ class _subscribers extends \IPS\Dispatcher\Controller
\IPS\Output::i()->output = (string) $table;
}
/**
* Remove a manually added member
*
* @return void
*/
protected function remove()
{
\IPS\Session::i()->csrfCheck();
try
{
$sub = \IPS\nexus\Subscription::load( \IPS\Request::i()->id );
$package = \IPS\nexus\Subscription\Package::load( $sub->package_id );
$customer = \IPS\nexus\Customer::load( $sub->member_id );
$package->removeMember( $customer );
\IPS\Output::i()->redirect( $customer->acpUrl(), 'nexus_sub_member_removed' );
}
catch( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'nexus_sub_no_invoice', '2X378/1', 404, '' );
}
}
/**
* Find an purchase and redirect to it.
*
@@ -309,24 +309,53 @@ class _subscriptions extends \IPS\Node\Controller
{
if ( $val instanceof \IPS\Member )
{
try
$sub = \IPS\nexus\Subscription::loadByMember( $val, false );
/* We have cannot have duplicate active subscriptions, so error out */
if( $sub !== NULL )
{
$package = \IPS\nexus\Subscription\Package::load( \IPS\Request::i()->id );
$sub = \IPS\nexus\Subscription::loadByMemberAndPackage( $val, $package, TRUE );
/* We have cannot have duplicate active subscriptions, so error out */
throw new \InvalidArgumentException('nexus_subs_add_member_already_subscribed');
}
catch( \OutOfRangeException $e )
{
/* Nothing found, so that's all lovely and good */
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 );
if( $term = $package->renewalTerm() )
{
$newOption = json_decode( $package->renew_options, TRUE );
$costs = array();
foreach ( $newOption['cost'] as $data )
{
$costs[] = new \IPS\nexus\Money( $data['amount'], $data['currency'] );
}
switch ( $newOption['unit'] )
{
case 'd':
$term = \IPS\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'] ) ) );
break;
case 'y':
$term = \IPS\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, [
'options' => [
0 => 'nexus_subs_forever',
1 => \IPS\Member::loggedIn()->language()->addToStack( 'nexus_subs_until_renew', FALSE, [ 'sprintf' => [ $newOption['term'], $term, \IPS\Member::loggedIn()->language()->formatList( $costs, \IPS\Member::loggedIn()->language()->get('or_list_format') ), $term ] ] )
]
] ) );
}
if ( $values = $form->values() )
{
$sub = \IPS\nexus\Subscription\Package::load( \IPS\Request::i()->id )->addMember( $values['nexus_subs_member_to_add'] );
$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, (bool) $values['nexus_subs_free_period'] );
$sub->added_manually = 1;
$sub->save();
@@ -334,7 +363,7 @@ class _subscriptions extends \IPS\Node\Controller
}
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('nexus_subs_add_member');
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'subscription', 'nexus' )->addMemberMessage( $form );
\IPS\Output::i()->output = $form;
}
/**
@@ -349,14 +378,20 @@ class _subscriptions extends \IPS\Node\Controller
{
$groups[ $group->g_id ] = $group->name;
}
$form = new \IPS\Helpers\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\YesNo( 'nexus_subs_register', \IPS\Settings::i()->nexus_subs_register, FALSE, array(), NULL, NULL, NULL, 'nexus_subs_register' ) );
$form->add( new \IPS\Helpers\Form\Radio( 'nexus_subs_register', (int) \IPS\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, 'min' => NULL ), NULL, NULL, NULL, 'nexus_subs_invoice_grace' ) );
$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 ) ) );
@@ -392,7 +427,7 @@ class _subscriptions extends \IPS\Node\Controller
}
$values['nexus_subs_exclude_groups'] = implode( ',', $values['nexus_subs_exclude_groups'] );
$form->saveAsSettings( $values );
\IPS\Session::i()->log( 'acplog__nexus_subs_settings' );
@@ -472,6 +507,7 @@ class _subscriptions extends \IPS\Node\Controller
{
if ( isset( $changes['renew_options'] ) )
{
\IPS\Output::i()->bypassCsrfKeyCheck = TRUE;
$matrix = new \IPS\Helpers\Form\Matrix( 'matrix', 'continue' );
$matrix->manageable = FALSE;
@@ -606,10 +642,15 @@ class _subscriptions extends \IPS\Node\Controller
'processing'=> 1,
'ba' => isset( \IPS\Request::i()->ba ) ? \IPS\Request::i()->ba : 0
) )->csrf(),
function( $offset ) use ( $package, $changes )
function( $data ) use ( $package, $changes )
{
$offset = \intval( $offset );
$select = \IPS\Db::i()->select( '*', 'nexus_purchases', array( "ps_app=? and ps_type=? and ps_item_id=?", 'nexus', 'subscription', $package->id ), 'ps_id', array( $offset, 1 ) );
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 );
try
{
@@ -617,8 +658,8 @@ class _subscriptions extends \IPS\Node\Controller
$total = \IPS\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 );
return array( ++$offset, \IPS\Member::loggedIn()->language()->get('processing'), 100 / $total * $offset );
return array( [ 'offset' => ++$data['offset'], 'lastId' => $purchase->id ], \IPS\Member::loggedIn()->language()->get('processing'), 100 / $total * $data['offset'] );
}
catch ( \UnderflowException $e )
{