Version 4.5.0
This commit is contained in:
1 parent
1a0c7fd3c2
commit
f79dcf067a
3791 files changed
+248032
-76372
No files matched your search
@@ -12,7 +12,7 @@
|
||||
namespace IPS\nexus\modules\admin\store;
|
||||
|
||||
/* 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 _packages extends \IPS\Node\Controller
|
||||
{
|
||||
/**
|
||||
* @brief Has been CSRF-protected
|
||||
*/
|
||||
public static $csrfProtected = TRUE;
|
||||
|
||||
/**
|
||||
* Node Class
|
||||
*/
|
||||
@@ -37,8 +42,8 @@ class _packages extends \IPS\Node\Controller
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'packages_manage' );
|
||||
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'admin_store.js', 'nexus', 'admin' ) );
|
||||
parent::execute();
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__nexus_store_packages');
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,6 +63,24 @@ class _packages extends \IPS\Node\Controller
|
||||
return $buttons;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch any additional HTML for this row
|
||||
*
|
||||
* @param object $node Node returned from $nodeClass::load()
|
||||
* @return NULL|string
|
||||
*/
|
||||
public function _getRowHtml( $node )
|
||||
{
|
||||
if ( $node instanceof \IPS\nexus\Package and \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'purchases_view' ) )
|
||||
{
|
||||
$active = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_purchases', array( 'ps_app=? AND ps_type=? AND ps_item_id=? AND ps_active=1', 'nexus', 'package', $node->_id ) )->first();
|
||||
$expired = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_purchases', array( 'ps_app=? AND ps_type=? AND ps_item_id=? AND ps_active=0 AND ps_cancelled=0', 'nexus', 'package', $node->_id ) )->first();
|
||||
$canceled = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_purchases', array( 'ps_app=? AND ps_type=? AND ps_item_id=? AND ps_active=0 AND ps_cancelled=1', 'nexus', 'package', $node->_id ) )->first();
|
||||
|
||||
return \IPS\Theme::i()->getTemplate( 'store', 'nexus' )->productRowHtml( $node, $active, $expired, $canceled );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect after save
|
||||
*
|
||||
@@ -72,7 +95,7 @@ class _packages extends \IPS\Node\Controller
|
||||
{
|
||||
return parent::_afterSave( $old, $new, $lastUsedTab );
|
||||
}
|
||||
|
||||
|
||||
$changes = array();
|
||||
if ( $old )
|
||||
{
|
||||
@@ -91,7 +114,7 @@ class _packages 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_purchases', array( 'ps_app=? AND ps_type=? AND ps_item_id=?', 'nexus', 'package', $new->id ) )->first();
|
||||
}
|
||||
@@ -101,7 +124,7 @@ class _packages extends \IPS\Node\Controller
|
||||
if ( !empty( $changes ) AND $purchases )
|
||||
{
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->decision( 'product_change_blurb', array(
|
||||
'product_change_blurb_existing' => \IPS\Http\Url::internal( "app=nexus&module=store&controller=packages&do=updateExisting&id={$new->_id}" )->setQueryString( 'changes', json_encode( $changes ) ),
|
||||
'product_change_blurb_existing' => \IPS\Http\Url::internal( "app=nexus&module=store&controller=packages&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 : '' ) ) ),
|
||||
) );
|
||||
}
|
||||
@@ -111,13 +134,134 @@ class _packages extends \IPS\Node\Controller
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
/* If &subnode=1 is not in the URL, we are deleting a group and not a package, so we don't need to check the package */
|
||||
if( !\IPS\Request::i()->subnode )
|
||||
{
|
||||
return parent::delete();
|
||||
}
|
||||
|
||||
/* Load package */
|
||||
try
|
||||
{
|
||||
$package = \IPS\nexus\Package::load( \IPS\Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
return parent::delete();
|
||||
}
|
||||
|
||||
/* Are there any purchases of this product? */
|
||||
$active = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_purchases', array( 'ps_app=? AND ps_type=? AND ps_item_id=? AND ps_active=1', 'nexus', 'package', $package->_id ) )->first();
|
||||
$expiredRenewable = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_purchases', array( 'ps_app=? AND ps_type=? AND ps_item_id=? AND ps_active=0 AND ps_cancelled=0 AND ps_renewals>0', 'nexus', 'package', $package->_id ) )->first();
|
||||
$expredNonRenewable = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_purchases', array( 'ps_app=? AND ps_type=? AND ps_item_id=? AND ps_active=0 AND ps_cancelled=0 AND ps_renewals=0', 'nexus', 'package', $package->_id ) )->first();
|
||||
$canceledCanBeReactivated = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_purchases', array( 'ps_app=? AND ps_type=? AND ps_item_id=? AND ps_active=0 AND ps_cancelled=1 AND ps_can_reactivate=1', 'nexus', 'package', $package->_id ) )->first();
|
||||
$canceledCannotBeReactivated = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_purchases', array( 'ps_app=? AND ps_type=? AND ps_item_id=? AND ps_active=0 AND ps_cancelled=1 AND ps_can_reactivate=0', 'nexus', 'package', $package->_id ) )->first();
|
||||
if ( $active or $expiredRenewable or $canceledCanBeReactivated )
|
||||
{
|
||||
$upgradeTo = FALSE;
|
||||
$prices = json_decode( $package->base_price, TRUE );
|
||||
if ( $package->renew_options )
|
||||
{
|
||||
$renewalOptions = json_decode( $package->renew_options, TRUE );
|
||||
if ( !empty( $renewalOptions ) )
|
||||
{
|
||||
$option = array_shift( $renewalOptions );
|
||||
if ( $option['add'] )
|
||||
{
|
||||
foreach ( $prices as $currency => $_price )
|
||||
{
|
||||
$prices[ $currency ]['amount'] += ( $option['cost'][ $currency ]['amount'] );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ( $package->parent()->children() as $_package )
|
||||
{
|
||||
if ( $_package->id === $package->id )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$_prices = json_decode( $_package->base_price, TRUE );
|
||||
if ( $_package->renew_options )
|
||||
{
|
||||
$renewalOptions = json_decode( $_package->renew_options, TRUE );
|
||||
if ( !empty( $renewalOptions ) )
|
||||
{
|
||||
$option = array_shift( $renewalOptions );
|
||||
if ( $option['add'] )
|
||||
{
|
||||
foreach ( $_prices as $currency => $_price )
|
||||
{
|
||||
$_prices[ $currency ]['amount'] += ( $option['cost'][ $currency ]['amount'] );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( $_prices as $currency => $_price )
|
||||
{
|
||||
if ( ( $_price['amount'] <= $prices[ $currency ]['amount'] and $_package->allow_upgrading ) or ( $_price['amount'] > $prices[ $currency ]['amount'] and $_package->allow_downgrading ) )
|
||||
{
|
||||
$upgradeTo = TRUE;
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
\IPS\Output::i()->title = $package->_title;
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'store' )->productDeleteWarning( $package, $active, $expiredRenewable, $expredNonRenewable, $canceledCanBeReactivated, $canceledCannotBeReactivated, $upgradeTo );
|
||||
return;
|
||||
}
|
||||
|
||||
/* If not, just handle the delete as normal */
|
||||
return parent::delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide from store
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function hide()
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
|
||||
/* Load package */
|
||||
try
|
||||
{
|
||||
$package = \IPS\nexus\Package::load( \IPS\Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X249/3', 404, '' );
|
||||
}
|
||||
|
||||
/* Do it */
|
||||
$package->store = FALSE;
|
||||
$package->reg = FALSE;
|
||||
$package->save();
|
||||
|
||||
/* Redirect */
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=nexus&module=store&controller=packages" )->setQueryString( array( 'root' => ( $package->parent() ? $package->parent()->_id : '' ) ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update Existing Purchases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function updateExisting()
|
||||
{
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
|
||||
try
|
||||
{
|
||||
$package = \IPS\nexus\Package::load( \IPS\Request::i()->id );
|
||||
@@ -139,7 +283,7 @@ class _packages extends \IPS\Node\Controller
|
||||
$newOptions = array( '-' => \IPS\Member::loggedIn()->language()->addToStack('do_not_change') );
|
||||
$existingRenewOptions = json_decode( $package->renew_options, TRUE );
|
||||
|
||||
if( !is_array( $existingRenewOptions ) )
|
||||
if( !\is_array( $existingRenewOptions ) )
|
||||
{
|
||||
$existingRenewOptions = array();
|
||||
}
|
||||
@@ -231,38 +375,52 @@ class _packages extends \IPS\Node\Controller
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $changes['renew_options'] ) and !isset( \IPS\Request::i()->ba ) )
|
||||
if ( ( isset( $changes['tax'] ) or isset( $changes['renew_options'] ) ) and !isset( \IPS\Request::i()->ba ) )
|
||||
{
|
||||
$needBaPrompt = FALSE;
|
||||
foreach ( $changes['renew_options'] as $ro )
|
||||
$canChangeOptions = FALSE;
|
||||
if ( isset( $changes['renew_options'] ) )
|
||||
{
|
||||
if ( !in_array( $ro['new'], array( '-', 'x', 'y', 'z' ) ) )
|
||||
foreach ( $changes['renew_options'] as $ro )
|
||||
{
|
||||
$needBaPrompt = TRUE;
|
||||
break;
|
||||
if ( !\in_array( $ro['new'], array( '-', 'x', 'y', 'z' ) ) )
|
||||
{
|
||||
$canChangeOptions = TRUE;
|
||||
$needBaPrompt = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( isset( $changes['tax'] ) )
|
||||
{
|
||||
$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', 'package', $package->id ) )->join( 'nexus_billing_agreements', 'ba_id=ps_billing_agreement' )->first() )
|
||||
{
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->decision( 'change_renew_ba_blurb', array(
|
||||
$options = array(
|
||||
'change_renew_ba_skip' => \IPS\Http\Url::internal( "app=nexus&module=store&controller=packages&do=updateExisting" )->setQueryString( array(
|
||||
'id' => \IPS\Request::i()->id,
|
||||
'changes' => json_encode( $changes ),
|
||||
'processing'=> 1,
|
||||
'ba' => 0
|
||||
) ),
|
||||
) )->csrf(),
|
||||
'change_renew_ba_cancel' => \IPS\Http\Url::internal( "app=nexus&module=store&controller=packages&do=updateExisting" )->setQueryString( array(
|
||||
'id' => \IPS\Request::i()->id,
|
||||
'changes' => json_encode( $changes ),
|
||||
'processing'=> 1,
|
||||
'ba' => 1
|
||||
) ),
|
||||
'change_renew_ba_go_back' => \IPS\Http\Url::internal( "app=nexus&module=store&controller=packages&do=updateExisting" )->setQueryString( array(
|
||||
) )->csrf()
|
||||
);
|
||||
if ( $canChangeOptions )
|
||||
{
|
||||
$options['change_renew_ba_go_back'] = \IPS\Http\Url::internal( "app=nexus&module=store&controller=packages&do=updateExisting" )->setQueryString( array(
|
||||
'id' => \IPS\Request::i()->id,
|
||||
'changes' => \IPS\Request::i()->changes,
|
||||
) ),
|
||||
) );
|
||||
) )->csrf();
|
||||
}
|
||||
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->decision( 'change_renew_ba_blurb', $options );
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -273,16 +431,16 @@ class _packages extends \IPS\Node\Controller
|
||||
'changes' => json_encode( $changes ),
|
||||
'processing'=> 1,
|
||||
'ba' => isset( \IPS\Request::i()->ba ) ? \IPS\Request::i()->ba : 0
|
||||
) ),
|
||||
) )->csrf(),
|
||||
function( $offset ) use ( $package, $changes )
|
||||
{
|
||||
$offset = intval( $offset );
|
||||
$select = \IPS\Db::i()->select( '*', 'nexus_purchases', array( "ps_app=? and ps_type=? and ps_item_id=?", 'nexus', 'package', $package->id ), 'ps_id', array( $offset, 1 ), NULL, NULL, \IPS\Db::SELECT_SQL_CALC_FOUND_ROWS );
|
||||
$offset = \intval( $offset );
|
||||
$select = \IPS\Db::i()->select( '*', 'nexus_purchases', array( "ps_app=? and ps_type=? and ps_item_id=?", 'nexus', 'package', $package->id ), 'ps_id', array( $offset, 1 ) );
|
||||
|
||||
try
|
||||
{
|
||||
$purchase = \IPS\nexus\Purchase::constructFromData( $select->first() );
|
||||
$total = $select->count( TRUE );
|
||||
$total = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_purchases', array( "ps_app=? and ps_type=? and ps_item_id=?", 'nexus', 'package', $package->id ) )->first();
|
||||
|
||||
$package->updatePurchase( $purchase, $changes, \IPS\Request::i()->ba );
|
||||
|
||||
@@ -358,10 +516,11 @@ class _packages extends \IPS\Node\Controller
|
||||
/**
|
||||
* Little function from the PHP manual comments
|
||||
*
|
||||
* @param array $_ Array
|
||||
* @return array
|
||||
*/
|
||||
protected function arraycartesian($_) {
|
||||
if(count($_) == 0)
|
||||
if(\count($_) == 0)
|
||||
return array(array());
|
||||
foreach($_ as $k=>$a) {
|
||||
unset($_[$k]);
|
||||
@@ -402,7 +561,16 @@ class _packages extends \IPS\Node\Controller
|
||||
'ps_expire' => \IPS\Helpers\Table\SEARCH_DATE_RANGE,
|
||||
);
|
||||
$table->noSort = array( 'purchase_status' );
|
||||
$table->filters = array( 'active' => 'ps_active=1' );
|
||||
|
||||
if ( $package->renew_options or \IPS\Db::i()->select( 'COUNT(*)', 'nexus_purchases', array( 'ps_app=? AND ps_type=? AND ps_item_id=? AND ps_active=0 AND ps_cancelled=0', 'nexus', 'package', $package->_id ) )->first() )
|
||||
{
|
||||
$table->filters = array( 'purchase_tab_active' => 'ps_active=1', 'purchase_tab_expired' => 'ps_active=0 AND ps_cancelled=0', 'purchase_tab_canceled' => 'ps_active=0 AND ps_cancelled=1' );
|
||||
}
|
||||
else
|
||||
{
|
||||
$table->filters = array( 'purchase_tab_active' => 'ps_active=1', 'purchase_tab_canceled' => 'ps_active=0' );
|
||||
}
|
||||
|
||||
$table->parsers = array(
|
||||
'ps_member' => function( $val ) {
|
||||
try
|
||||
@@ -457,6 +625,132 @@ class _packages extends \IPS\Node\Controller
|
||||
|
||||
\IPS\Output::i()->title = $package->_title;
|
||||
\IPS\Output::i()->output = $table;
|
||||
\IPS\Output::i()->sidebar['actions'] = array(
|
||||
'cancel_purchases' => array(
|
||||
'icon' => 'arrow-right',
|
||||
'title' => 'mass_change_all_purchases',
|
||||
'link' => \IPS\Http\Url::internal( "app=nexus&module=store&controller=packages" )->setQueryString( array( 'do' => 'massManagePurchases', 'id' => $package->_id ) ),
|
||||
'data' => array(
|
||||
'ipsDialog' => TRUE,
|
||||
'ipsDialog-title' => $package->_title
|
||||
)
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mass Change/Cancel Purchases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function massManagePurchases()
|
||||
{
|
||||
try
|
||||
{
|
||||
$package = \IPS\nexus\Package::load( \IPS\Request::i()->id );
|
||||
if ( $package->deleteOrMoveQueued() )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X249/4', 404, '' );
|
||||
}
|
||||
|
||||
$form = new \IPS\Helpers\Form( 'form', 'go' );
|
||||
$form->addMessage('mass_change_purchases_explain');
|
||||
|
||||
$options = array();
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'purchases_edit' ) )
|
||||
{
|
||||
$options['change'] = 'mass_change_purchases_change';
|
||||
$options['expire'] = 'mass_change_purchases_expire';
|
||||
}
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'purchases_cancel' ) )
|
||||
{
|
||||
$options['cancel'] = 'mass_change_purchases_cancel';
|
||||
}
|
||||
|
||||
$upgradeDowngradeOptions = array();
|
||||
$toggles = array();
|
||||
$renewFields = array();
|
||||
$desciptions = [];
|
||||
foreach ( $package->parent()->children() as $siblingPackage )
|
||||
{
|
||||
if ( $package->id === $siblingPackage->id )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$upgradeDowngradeOptions[ $siblingPackage->id ] = $siblingPackage->_title;
|
||||
|
||||
$renewOptions = json_decode( $siblingPackage->renew_options, TRUE ) ?: array();
|
||||
$renewalOptions = array();
|
||||
$renewFieldsDescriptions = array();
|
||||
foreach ( $renewOptions as $k => $option )
|
||||
{
|
||||
$renewTermObject = new \IPS\nexus\Purchase\RenewalTerm( new \IPS\nexus\Money( 0, '' ), new \DateInterval( 'P' . $option['term'] . mb_strtoupper( $option['unit'] ) ) );
|
||||
|
||||
$costs = array();
|
||||
foreach ( $option['cost'] as $cost )
|
||||
{
|
||||
$costs[] = new \IPS\nexus\Money( $cost['amount'], $cost['currency'] );
|
||||
}
|
||||
|
||||
$renewalOptions[ $k ] = sprintf( \IPS\Member::loggedIn()->language()->get( 'renew_option'), implode( ' / ', $costs ), $renewTermObject->getTermUnit() );
|
||||
}
|
||||
|
||||
if ( $renewalOptions )
|
||||
{
|
||||
$desciptions[ $siblingPackage->id ] = \IPS\Member::loggedIn()->language()->formatList( $renewalOptions, \IPS\Member::loggedIn()->language()->get('or_list_format') );
|
||||
$renewFields[] = new \IPS\Helpers\Form\Radio( 'renew_option_' . $siblingPackage->id, NULL, NULL, array( 'options' => $renewalOptions, 'descriptions' => $renewFieldsDescriptions, 'parse' => 'normal' ), NULL, NULL, NULL, 'renew_option_' . $siblingPackage->id );
|
||||
\IPS\Member::loggedIn()->language()->words['renew_option_' . $siblingPackage->id] = \IPS\Member::loggedIn()->language()->addToStack( 'renewal_term', FALSE );
|
||||
$toggles[ $siblingPackage->id ] = array( 'renew_option_' . $siblingPackage->id );
|
||||
}
|
||||
else
|
||||
{
|
||||
$desciptions[ $siblingPackage->id ] = \IPS\Member::loggedIn()->language()->addToStack('mass_change_purchases_no_renewals');
|
||||
}
|
||||
}
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'cancel_type', NULL, TRUE, array(
|
||||
'options' => $options,
|
||||
'toggles' => array(
|
||||
'change' => array( 'mass_change_purchases_to', 'mass_change_purchases_override' ),
|
||||
'expire' => array( 'ps_can_reactivate' ),
|
||||
'cancel' => array( 'ps_can_reactivate' ),
|
||||
),
|
||||
'disabled' => $upgradeDowngradeOptions ? [] : ['change']
|
||||
) ) );
|
||||
if ( !$upgradeDowngradeOptions )
|
||||
{
|
||||
\IPS\Member::loggedIn()->language()->words['mass_change_purchases_change_desc'] = \IPS\Member::loggedIn()->language()->addToStack('cancel_type_change_no_siblings');
|
||||
}
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'mass_change_purchases_to', NULL, NULL, array( 'options' => $upgradeDowngradeOptions, 'descriptions' => $desciptions, 'toggles' => $toggles, 'parse' => 'normal' ), NULL, NULL, NULL, 'mass_change_purchases_to' ) );
|
||||
foreach ( $renewFields as $field )
|
||||
{
|
||||
$form->add( $field );
|
||||
}
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'mass_change_purchases_override', TRUE, NULL, array(), NULL, NULL, NULL, 'mass_change_purchases_override' ) );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'ps_can_reactivate', NULL, FALSE, array(), NULL, NULL, NULL, 'ps_can_reactivate' ) );
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
// Note: Maybe we cannot upgrade/downgrade cancelled purchases? Reflect that in the form if so
|
||||
// Note: Must cancel billing agreements when upgrading/downgrading purchases. Reflect that in the form
|
||||
|
||||
$values['id'] = $package->_id;
|
||||
$values['admin'] = \IPS\Member::loggedIn()->member_id;
|
||||
\IPS\Task::queue( 'nexus', 'MassChangePurchases', $values );
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=nexus&module=store&controller=packages" )->setQueryString( array( 'root' => ( $package->parent() ? $package->parent()->_id : '' ) ) ), 'mass_change_purchases_confirm' );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->title = $package->_title;
|
||||
\IPS\Output::i()->output = $form;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -466,6 +760,8 @@ class _packages extends \IPS\Node\Controller
|
||||
*/
|
||||
public function emailPreview()
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
|
||||
$functionName = 'emailPreview_' . mt_rand();
|
||||
\IPS\Theme::makeProcessFunction( \IPS\Request::i()->value, $functionName, '$purchase' );
|
||||
|
||||
@@ -480,7 +776,8 @@ class _packages extends \IPS\Node\Controller
|
||||
|
||||
try
|
||||
{
|
||||
$output = \IPS\Email::buildFromContent( 'Test', call_user_func( 'IPS\\Theme\\'.$functionName, $dummyPurchase ) )->compileContent( 'html', \IPS\Member::loggedIn() );
|
||||
$themeFunction = 'IPS\\Theme\\'. $functionName;
|
||||
$output = \IPS\Email::buildFromContent( 'Test', $themeFunction( $dummyPurchase ) )->compileContent( 'html', \IPS\Member::loggedIn() );
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
{
|
||||
@@ -488,4 +785,53 @@ class _packages extends \IPS\Node\Controller
|
||||
}
|
||||
\IPS\Output::i()->sendOutput( $output );
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form to mass move content
|
||||
*
|
||||
* @param \IPS\Helpers\Form $form The form helper object
|
||||
* @param mixed $data Data from the wizard helper
|
||||
* @param string $nodeClass Node class
|
||||
* @param \IPS\Node\Mode $node Node we are working with
|
||||
* @param string $contentItemClass Content item class (if there is one)
|
||||
* @return \IPS\Helpers\Form
|
||||
*/
|
||||
protected function _buildMassMoveForm( $form, $data, $nodeClass, $node, $contentItemClass )
|
||||
{
|
||||
$form->addHeader('node_mass_move_delete_then');
|
||||
$moveToClass = isset( $data['moveToClass'] ) ? $data['moveToClass'] : $nodeClass;
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'node_move_products', isset( $data['moveTo'] ) ? $moveToClass::load( $data['moveTo'] ) : 0, TRUE, array( 'class' => $nodeClass, 'disabledIds' => array( $node->_id ), 'disabledLang' => 'node_move_delete', 'zeroVal' => 'products_delete_content', 'subnodes' => FALSE ) ) );
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the mass move form submission
|
||||
*
|
||||
* @param array $values Values from form submission
|
||||
* @param mixed $data Data from the wizard helper
|
||||
* @param string $nodeClass Node class
|
||||
* @param \IPS\Node\Mode $node Node we are working with
|
||||
* @param string $contentItemClass Content item class (if there is one)
|
||||
* @return array Wizard helper data
|
||||
*/
|
||||
protected function _processMassMoveForm( $values, $data, $nodeClass, $node, $contentItemClass )
|
||||
{
|
||||
$data['deleteWhenDone'] = FALSE;
|
||||
$data['class'] = \get_class( $node );
|
||||
$data['id'] = $node->_id;
|
||||
|
||||
if ( \is_object( $values['node_move_products'] ) )
|
||||
{
|
||||
$data['moveToClass'] = \get_class( $values['node_move_products'] );
|
||||
$data['moveTo'] = $values['node_move_products']->_id;
|
||||
}
|
||||
else
|
||||
{
|
||||
unset( $data['moveToClass'] );
|
||||
unset( $data['moveTo'] );
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user