Version 4.3.0

This commit is contained in:
Neo committed 2025-12-19 05:47:12 -08:00
1 parent 96997ddd8e
commit fe1acf984a
1349 files changed
+116159 -67711

No files matched your search

@@ -144,8 +144,7 @@ class _EasyPost
}
else
{
\IPS\Db::i()->update( 'core_sys_conf_settings', array( 'conf_value' => '' ), array( 'conf_key=?', 'easypost_api_key' ) );
unset( \IPS\Data\Store::i()->settings );
\IPS\Settings::i()->changeValues( array( 'easypost_api_key' => '' ) );
}
}
@@ -106,8 +106,7 @@ class _Enom
}
else
{
\IPS\Db::i()->update( 'core_sys_conf_settings', array( 'conf_value' => '' ), array( 'conf_key=? OR conf_key=?', 'nexus_enom_un', 'nexus_enom_pw' ) );
unset( \IPS\Data\Store::i()->settings );
\IPS\Settings::i()->changeValues( array( 'nexus_enom_un' => '', 'nexus_enom_pw' => '' ) );
}
}
}
@@ -119,8 +119,7 @@ class _MaxMind
}
else
{
\IPS\Db::i()->update( 'core_sys_conf_settings', array( 'conf_value' => '' ), array( 'conf_key=?', 'maxmind_key' ) );
unset( \IPS\Data\Store::i()->settings );
\IPS\Settings::i()->changeValues( array( 'maxmind_key' => '' ) );
}
}
@@ -1,6 +1,6 @@
<?php
/**
* @brief Content Router extension: Reviews
* @brief Content Router extension: Products & Reviews
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
@@ -19,7 +19,7 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
}
/**
* @brief Content Router extension: Reviews
* @brief Content Router extension: Products & Reviews
*/
class _Reviews
{
@@ -36,19 +36,9 @@ class _Reviews
*/
public function __construct( $member = NULL )
{
if( !isset( \IPS\Data\Store::i()->nexusPackagesWithReviews ) )
if ( ( $member === NULL or $member->canAccessModule( \IPS\Application\Module::get( 'nexus', 'store', 'front' ) ) ) )
{
\IPS\Data\Store::i()->nexusPackagesWithReviews = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_packages', array( 'p_store=1 AND p_reviewable=1' ) )->first();
}
if ( ( $member === NULL or $member->canAccessModule( \IPS\Application\Module::get( 'nexus', 'store', 'front' ) ) ) and \IPS\Data\Store::i()->nexusPackagesWithReviews > 0 )
{
$this->classes[] = 'IPS\nexus\Package\Review';
$this->classes[] = 'IPS\nexus\Package\Item';
}
}
/**
* @brief Item Classes for embed only
*/
public $embeddableContent = array( 'IPS\nexus\Package\Item' );
}
@@ -52,7 +52,7 @@ class _PendingActions
$pendingTransactions = NULL;
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'transactions_manage' ) )
{
$pendingTransactions = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_transactions', array( 't_status=?', \IPS\nexus\Transaction::STATUS_HELD ) )->first();
$pendingTransactions = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_transactions', array( '( t_status=? OR t_status=? OR t_status=? )', \IPS\nexus\Transaction::STATUS_HELD, \IPS\nexus\Transaction::STATUS_REVIEW, \IPS\nexus\Transaction::STATUS_DISPUTED ) )->first();
if ( !$pendingTransactions and !\IPS\Db::i()->select( 'COUNT(*)', 'nexus_fraud_rules' )->first() )
{
$pendingTransactions = NULL;
@@ -43,6 +43,10 @@ class _Admin
*/
public function canAttach( $member, $field )
{
if ( mb_substr( $field->options['autoSaveKey'], -6 ) == '-email' )
{
return FALSE;
}
return NULL;
}
@@ -64,6 +68,7 @@ class _Admin
{
case 'pkg':
case 'pkg-assoc':
case 'pkg-email':
return \IPS\nexus\Package\Item::load( $id1 )->canView( $member );
case 'pkg-pg':
@@ -123,6 +128,7 @@ class _Admin
case 'pkg':
case 'pkg-assoc':
case 'pkg-pg':
case 'pkg-email':
return \IPS\Http\Url::internal( "app=nexus&module=store&controller=packages&subnode=1&do=form&id={$id1}", 'admin' );
case 'pgroup':
@@ -257,8 +263,7 @@ class _Admin
if( $newMessage !== FALSE )
{
\IPS\Db::i()->update( 'core_sys_conf_settings', array( 'conf_value' => $newMessage ), array( "conf_key=?", $k ) );
unset( \IPS\Data\Store::i()->settings );
\IPS\Settings::i()->changeValues( array( $k => $newMessage ) );
}
}
}
@@ -279,7 +284,7 @@ class _Admin
}
else
{
$rebuilt = call_user_func( $callback, $package['p_page'] );
$rebuilt = call_user_func( $callback, $package['p_page'], NULL, FALSE, 'nexus_Admin', $package['p_id'], NULL, 'pkg-pg' );
}
}
catch( \InvalidArgumentException $e )
@@ -87,7 +87,7 @@ class _Customer
}
else
{
return \IPS\Http\Url::internal( 'app=nexus&module=clients&controller=info', 'front', 'clientsinfo', array(), \IPS\Settings::i()->nexus_https );
return \IPS\Http\Url::internal( 'app=nexus&module=clients&controller=info', 'front', 'clientsinfo' );
}
}
@@ -40,7 +40,7 @@ class _Addresses extends \IPS\core\FrontNavigation\FrontNavigationAbstract
*/
public function canAccessContent()
{
return \IPS\Member::loggedIn()->canAccessModule( \IPS\Application\Module::get( 'nexus', 'clients' ) );
return ( \IPS\Member::loggedIn()->member_id AND \IPS\Member::loggedIn()->canAccessModule( \IPS\Application\Module::get( 'nexus', 'clients' ) ) );
}
/**
@@ -60,7 +60,7 @@ class _Addresses extends \IPS\core\FrontNavigation\FrontNavigationAbstract
*/
public function link()
{
return \IPS\Http\Url::internal( "app=nexus&module=clients&controller=addresses", 'front', 'clientsaddresses', \IPS\Settings::i()->nexus_https );
return \IPS\Http\Url::internal( "app=nexus&module=clients&controller=addresses", 'front', 'clientsaddresses' );
}
/**
@@ -40,7 +40,7 @@ class _Alternatives extends \IPS\core\FrontNavigation\FrontNavigationAbstract
*/
public function canAccessContent()
{
return \IPS\Member::loggedIn()->canAccessModule( \IPS\Application\Module::get( 'nexus', 'clients' ) );
return ( \IPS\Member::loggedIn()->member_id AND \IPS\Member::loggedIn()->canAccessModule( \IPS\Application\Module::get( 'nexus', 'clients' ) ) );
}
/**
@@ -60,7 +60,7 @@ class _Alternatives extends \IPS\core\FrontNavigation\FrontNavigationAbstract
*/
public function link()
{
return \IPS\Http\Url::internal( "app=nexus&module=clients&controller=alternatives", 'front', 'clientsalternatives', \IPS\Settings::i()->nexus_https );
return \IPS\Http\Url::internal( "app=nexus&module=clients&controller=alternatives", 'front', 'clientsalternatives' );
}
/**
@@ -52,7 +52,7 @@ class _BillingAgreements extends \IPS\core\FrontNavigation\FrontNavigationAbstra
*/
public function canAccessContent()
{
return \IPS\Member::loggedIn()->canAccessModule( \IPS\Application\Module::get( 'nexus', 'clients' ) );
return ( \IPS\Member::loggedIn()->member_id AND \IPS\Member::loggedIn()->canAccessModule( \IPS\Application\Module::get( 'nexus', 'clients' ) ) );
}
/**
@@ -72,7 +72,7 @@ class _BillingAgreements extends \IPS\core\FrontNavigation\FrontNavigationAbstra
*/
public function link()
{
return \IPS\Http\Url::internal( "app=nexus&module=clients&controller=billingagreements", 'front', 'clientsbillingagreements', \IPS\Settings::i()->nexus_https );
return \IPS\Http\Url::internal( "app=nexus&module=clients&controller=billingagreements", 'front', 'clientsbillingagreements' );
}
/**
@@ -52,7 +52,7 @@ class _Cards extends \IPS\core\FrontNavigation\FrontNavigationAbstract
*/
public function canAccessContent()
{
return \IPS\Member::loggedIn()->canAccessModule( \IPS\Application\Module::get( 'nexus', 'clients' ) );
return ( \IPS\Member::loggedIn()->member_id AND \IPS\Member::loggedIn()->canAccessModule( \IPS\Application\Module::get( 'nexus', 'clients' ) ) );
}
/**
@@ -72,7 +72,7 @@ class _Cards extends \IPS\core\FrontNavigation\FrontNavigationAbstract
*/
public function link()
{
return \IPS\Http\Url::internal( "app=nexus&module=clients&controller=cards", 'front', 'clientscards', \IPS\Settings::i()->nexus_https );
return \IPS\Http\Url::internal( "app=nexus&module=clients&controller=cards", 'front', 'clientscards' );
}
/**
@@ -43,7 +43,7 @@ class _Credit extends \IPS\core\FrontNavigation\FrontNavigationAbstract
*/
public static function isEnabled()
{
return ( \IPS\Settings::i()->nexus_min_topup or count( json_decode( \IPS\Settings::i()->nexus_payout, TRUE ) ) );
return ( \IPS\Settings::i()->nexus_min_topup or ( is_array( json_decode( \IPS\Settings::i()->nexus_payout, TRUE ) ) AND count( json_decode( \IPS\Settings::i()->nexus_payout, TRUE ) ) ) );
}
/**
@@ -53,7 +53,7 @@ class _Credit extends \IPS\core\FrontNavigation\FrontNavigationAbstract
*/
public function canAccessContent()
{
return \IPS\Member::loggedIn()->canAccessModule( \IPS\Application\Module::get( 'nexus', 'clients' ) );
return ( \IPS\Member::loggedIn()->member_id AND \IPS\Member::loggedIn()->canAccessModule( \IPS\Application\Module::get( 'nexus', 'clients' ) ) );
}
/**
@@ -73,7 +73,7 @@ class _Credit extends \IPS\core\FrontNavigation\FrontNavigationAbstract
*/
public function link()
{
return \IPS\Http\Url::internal( "app=nexus&module=clients&controller=credit", 'front', 'clientscredit', \IPS\Settings::i()->nexus_https );
return \IPS\Http\Url::internal( "app=nexus&module=clients&controller=credit", 'front', 'clientscredit' );
}
/**
@@ -72,7 +72,7 @@ class _Donations extends \IPS\core\FrontNavigation\FrontNavigationAbstract
*/
public function link()
{
return \IPS\Http\Url::internal( "app=nexus&module=clients&controller=donations", 'front', 'clientsdonations', \IPS\Settings::i()->nexus_https );
return \IPS\Http\Url::internal( "app=nexus&module=clients&controller=donations", 'front', 'clientsdonations' );
}
/**
@@ -40,7 +40,7 @@ class _Info extends \IPS\core\FrontNavigation\FrontNavigationAbstract
*/
public function canAccessContent()
{
return \IPS\Member::loggedIn()->canAccessModule( \IPS\Application\Module::get( 'nexus', 'clients' ) );
return ( \IPS\Member::loggedIn()->member_id AND \IPS\Member::loggedIn()->canAccessModule( \IPS\Application\Module::get( 'nexus', 'clients' ) ) );
}
/**
@@ -60,7 +60,7 @@ class _Info extends \IPS\core\FrontNavigation\FrontNavigationAbstract
*/
public function link()
{
return \IPS\Http\Url::internal( "app=nexus&module=clients&controller=info", 'front', 'clientsinfo', \IPS\Settings::i()->nexus_https );
return \IPS\Http\Url::internal( "app=nexus&module=clients&controller=info", 'front', 'clientsinfo' );
}
/**
@@ -40,7 +40,7 @@ class _Orders extends \IPS\core\FrontNavigation\FrontNavigationAbstract
*/
public function canAccessContent()
{
return \IPS\Member::loggedIn()->canAccessModule( \IPS\Application\Module::get( 'nexus', 'clients' ) );
return ( \IPS\Member::loggedIn()->member_id AND \IPS\Member::loggedIn()->canAccessModule( \IPS\Application\Module::get( 'nexus', 'clients' ) ) );
}
/**
@@ -60,7 +60,7 @@ class _Orders extends \IPS\core\FrontNavigation\FrontNavigationAbstract
*/
public function link()
{
return \IPS\Http\Url::internal( "app=nexus&module=clients&controller=invoices", 'front', 'clientsinvoices', \IPS\Settings::i()->nexus_https );
return \IPS\Http\Url::internal( "app=nexus&module=clients&controller=invoices", 'front', 'clientsinvoices' );
}
/**
@@ -40,7 +40,7 @@ class _Purchases extends \IPS\core\FrontNavigation\FrontNavigationAbstract
*/
public function canAccessContent()
{
return \IPS\Member::loggedIn()->canAccessModule( \IPS\Application\Module::get( 'nexus', 'clients' ) ) and \IPS\Db::i()->select( 'COUNT(*)', 'nexus_purchases', array( 'ps_member=? AND ps_show=1', \IPS\Member::loggedIn()->member_id ) );
return ( \IPS\Member::loggedIn()->member_id AND \IPS\Member::loggedIn()->canAccessModule( \IPS\Application\Module::get( 'nexus', 'clients' ) ) and \IPS\Db::i()->select( 'COUNT(*)', 'nexus_purchases', array( 'ps_member=? AND ps_show=1', \IPS\Member::loggedIn()->member_id ) ) );
}
/**
@@ -60,7 +60,7 @@ class _Purchases extends \IPS\core\FrontNavigation\FrontNavigationAbstract
*/
public function link()
{
return \IPS\Http\Url::internal( "app=nexus&module=clients&controller=purchases", 'front', 'clientspurchases', \IPS\Settings::i()->nexus_https );
return \IPS\Http\Url::internal( "app=nexus&module=clients&controller=purchases", 'front', 'clientspurchases' );
}
/**
@@ -52,7 +52,7 @@ class _Referrals extends \IPS\core\FrontNavigation\FrontNavigationAbstract
*/
public function canAccessContent()
{
return \IPS\Member::loggedIn()->canAccessModule( \IPS\Application\Module::get( 'nexus', 'clients' ) );
return ( \IPS\Member::loggedIn()->member_id AND \IPS\Member::loggedIn()->canAccessModule( \IPS\Application\Module::get( 'nexus', 'clients' ) ) );
}
/**
@@ -72,7 +72,7 @@ class _Referrals extends \IPS\core\FrontNavigation\FrontNavigationAbstract
*/
public function link()
{
return \IPS\Http\Url::internal( "app=nexus&module=clients&controller=referrals", 'front', 'clientsreferrals', \IPS\Settings::i()->nexus_https );
return \IPS\Http\Url::internal( "app=nexus&module=clients&controller=referrals", 'front', 'clientsreferrals' );
}
/**
@@ -70,6 +70,6 @@ class _Store extends \IPS\core\FrontNavigation\FrontNavigationAbstract
*/
public function active()
{
return \IPS\Dispatcher::i()->application->directory === 'nexus' and \IPS\Dispatcher::i()->module and \IPS\Dispatcher::i()->module->key === 'store';
return \IPS\Dispatcher::i()->application->directory === 'nexus' and \IPS\Dispatcher::i()->module and ( \IPS\Dispatcher::i()->module->key === 'store' or \IPS\Dispatcher::i()->module->key === 'subscriptions' );
}
}
@@ -0,0 +1,87 @@
<?php
/**
* @brief Front Navigation Extension: Subscriptions
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @subpackage Nexus
* @since 29 Apr 2014
*/
namespace IPS\nexus\extensions\core\FrontNavigation;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Front Navigation Extension: Subscriptions
*/
class _Subscriptions extends \IPS\core\FrontNavigation\FrontNavigationAbstract
{
/**
* Get Type Title which will display in the AdminCP Menu Manager
*
* @return string
*/
public static function typeTitle()
{
return \IPS\Member::loggedIn()->language()->addToStack('nexus_subscriptions');
}
/**
* Can this item be used at all?
* For example, if this will link to a particular feature which has been diabled, it should
* not be available, even if the user has permission
*
* @return bool
*/
public static function isEnabled()
{
return \IPS\Settings::i()->nexus_subs_enabled;
}
/**
* Can the currently logged in user access the content this item links to?
*
* @return bool
*/
public function canAccessContent()
{
return \IPS\Member::loggedIn()->canAccessModule( \IPS\Application\Module::get( 'nexus', 'subscriptions' ) );
}
/**
* Get Title
*
* @return string
*/
public function title()
{
return \IPS\Member::loggedIn()->language()->addToStack('nexus_subscriptions');
}
/**
* Get Link
*
* @return \IPS\Http\Url
*/
public function link()
{
return \IPS\Http\Url::internal( "app=nexus&module=subscriptions&controller=subscriptions", 'front', 'nexus_subscriptions' );
}
/**
* Is Active?
*
* @return bool
*/
public function active()
{
return \IPS\Dispatcher::i()->application->directory === 'nexus' and \IPS\Dispatcher::i()->module and \IPS\Dispatcher::i()->module->key === 'subscriptions' and \IPS\Dispatcher::i()->controller == 'subscriptions';
}
}
@@ -40,7 +40,7 @@ class _Support extends \IPS\core\FrontNavigation\FrontNavigationAbstract
*/
public function canAccessContent()
{
return \IPS\Member::loggedIn()->canAccessModule( \IPS\Application\Module::get( 'nexus', 'support' ) );
return ( \IPS\Member::loggedIn()->member_id AND \IPS\Member::loggedIn()->canAccessModule( \IPS\Application\Module::get( 'nexus', 'support' ) ) );
}
/**
@@ -144,7 +144,7 @@ class _Nexus
/* Customers */
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'customers_view' ) )
{
foreach ( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_customers', array( "LOWER( name ) LIKE CONCAT( '%', ?, '%' ) OR LOWER( email ) LIKE CONCAT( '%', ?, '%' ) OR CONCAT( LOWER( cm_first_name ), ' ', LOWER( cm_last_name ) ) LIKE CONCAT( '%', ?, '%' )", mb_strtolower( $searchTerm ), mb_strtolower( $searchTerm ), mb_strtolower( $searchTerm ) ), NULL, 50 )->join( 'core_members', 'core_members.member_id=nexus_customers.member_id' ), 'IPS\nexus\Customer' ) as $customer )
foreach ( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_customers', array( "LOWER( core_members.name ) LIKE CONCAT( '%', ?, '%' ) OR LOWER( core_members.email ) LIKE CONCAT( '%', ?, '%' ) OR CONCAT( LOWER( nexus_customers.cm_first_name ), ' ', LOWER( nexus_customers.cm_last_name ) ) LIKE CONCAT( '%', ?, '%' )", mb_strtolower( $searchTerm ), mb_strtolower( $searchTerm ), mb_strtolower( $searchTerm ) ), NULL, 50 )->join( 'core_members', 'core_members.member_id=nexus_customers.member_id' ), 'IPS\nexus\Customer' ) as $customer )
{
$results[] = \IPS\Theme::i()->getTemplate('livesearch', 'nexus')->customer( $customer );
}
@@ -154,7 +154,7 @@ class _Nexus
/* For either, search for transaction gateway IDs */
foreach ( \IPS\Db::i()->select( '*', 'nexus_transactions', array( 't_gw_id=?', $searchTerm ) ) as $transactionData )
{
$results[] = \IPS\Theme::i()->getTemplate( 'livesearch', 'nexus' )->transaction( \IPS\nexus\Transaction::constructFromData( $transactionData ) );
$results[] = \IPS\Theme::i()->getTemplate( 'livesearch', 'nexus' )->transaction( \IPS\nexus\Transaction::constructFromData( $transactionData ) );
}
/* Return */
@@ -0,0 +1,485 @@
<?php
/**
* @brief ACP Member Profile Block
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @subpackage Commerce
* @since 05 Dec 2017
*/
namespace IPS\nexus\extensions\core\MemberACPProfileBlocks;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* @brief ACP Member Profile Block
*/
class _AccountInformation extends \IPS\core\MemberACPProfile\TabbedBlock
{
/**
* Get Tab Names
*
* @return string
*/
public function tabs()
{
$tabs = array(
'overview' => array(
'icon' => 'ellipsis-h',
'count' => 0
)
);
if ( count( \IPS\nexus\Gateway::cardStorageGateways() ) )
{
$tabs['cards'] = array(
'icon' => 'credit-card',
'count' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_customer_cards', array( 'card_member=?', $this->member->member_id ) )->first()
);
}
if ( count( \IPS\nexus\Gateway::billingAgreementGateways() ) )
{
$tabs['paypal'] = array(
'icon' => 'paypal',
'count' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_billing_agreements', array( 'ba_member=? AND ba_canceled=0', $this->member->member_id ) )->first()
);
}
$tabs['alts'] = array(
'icon' => 'user',
'count' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_alternate_contacts', array( 'main_id=?', $this->member->member_id ) )->first()
);
$tabs['referrers'] = array(
'icon' => 'retweet',
'count' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_referrals', array( 'referred_by=?', $this->member->member_id ) )->first()
);
return $tabs;
}
/**
* Get output: OVERVIEW
*
* @return string
*/
protected function _overview()
{
/* Sparkline */
$rows = array();
$oneYearAgo = \IPS\DateTime::create()->sub( new \DateInterval('P1Y') );
$date = clone $oneYearAgo;
$endOfLastMonth = mktime( 23, 59, 59, date('n') - 1, date('t'), date('Y') );
while ( $date->getTimestamp() < $endOfLastMonth )
{
foreach ( \IPS\nexus\Money::currencies() as $currency )
{
$rows[ $date->format( 'n Y' ) ][ $currency ] = 0;
}
$date->add( new \DateInterval( 'P1M' ) );
}
$sparkline = new \IPS\Helpers\Chart;
foreach( \IPS\Db::i()->select( 'DATE_FORMAT( FROM_UNIXTIME(t_date), \'%c %Y\' ) AS time, SUM(t_amount)-SUM(t_partial_refund) AS amount, t_currency', 'nexus_transactions', array( array( "t_member=? AND ( t_status=? OR t_status=? ) AND t_date>? AND t_date<?", $this->member->member_id, \IPS\nexus\Transaction::STATUS_PAID, \IPS\nexus\Transaction::STATUS_PART_REFUNDED, $oneYearAgo->getTimestamp(), time() ) ), NULL, NULL, array( 'time', 't_currency' ) ) as $row )
{
if ( isset( $rows[ $row['time'] ][ $row['t_currency'] ] ) ) // Currency may no longer exist
{
$rows[ $row['time'] ][ $row['t_currency'] ] += $row['amount'];
}
}
$sparkline->addHeader( \IPS\Member::loggedIn()->language()->addToStack('date'), 'date' );
foreach ( \IPS\nexus\Money::currencies() as $currency )
{
$sparkline->addHeader( $currency, 'number' );
}
foreach ( $rows as $time => $row )
{
$datetime = new \IPS\DateTime;
$datetime->setTime( 0, 0, 0 );
$exploded = explode( ' ', $time );
$datetime->setDate( $exploded[1], $exploded[0], 1 );
foreach( $row as $currency => $value )
{
$row[ $currency ] = number_format( $value, 2, '.', '' );
}
$sparkline->addRow( array_merge( array( $datetime ), $row ) );
}
$sparkline = $sparkline->render( 'AreaChart', array(
'areaOpacity' => 0.4,
'backgroundColor' => '#fff',
'colors' => array( '#10967e' ),
'chartArea' => array(
'left' => 0,
'top' => 0,
'width' => '100%',
'height' => '100%',
),
'hAxis' => array(
'baselineColor' => '#F3F3F3',
'gridlines' => array(
'count' => 0,
)
),
'height' => 60,
'legend' => array(
'position' => 'none',
),
'lineWidth' => 1,
'vAxis' => array(
'baselineColor' => '#F3F3F3',
'gridlines' => array(
'count' => 0,
)
),
) );
/* Referrals */
try
{
$referredBy = \IPS\nexus\Customer::load( \IPS\Db::i()->select( 'referred_by', 'nexus_referrals', array( 'member_id=?', $this->member->member_id ) )->first() );
}
catch ( \UnderflowException $e )
{
$referredBy = NULL;
}
/* Primary Billing Address */
$primaryBillingAddress = NULL;
try
{
$primaryBillingAddress = \IPS\nexus\Customer\Address::constructFromData( \IPS\Db::i()->select( '*', 'nexus_customer_addresses', array( 'member=? AND primary_billing=1', $this->member->member_id ) )->first() )->address;
}
catch ( \UnderflowException $e ) { }
$addressCount = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_customer_addresses', array( 'member=?', $this->member->member_id ) )->first();
/* Display */
return \IPS\Theme::i()->getTemplate( 'customers', 'nexus' )->accountInformationOverview( $this->member, $sparkline, $referredBy, $primaryBillingAddress, $addressCount );
}
/**
* Get output: CARDS
*
* @param bool $edit Edit view?
* @return string
*/
protected function _cards( $edit = FALSE )
{
$cards = array();
foreach ( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_customer_cards', array( 'card_member=?', $this->member->member_id ), NULL, \IPS\Request::i()->view === 'cards' ? NULL : 2 ), 'IPS\nexus\Customer\CreditCard' ) as $card )
{
try
{
$cardData = $card->card;
$cards[ $card->id ] = array(
'id' => $card->id,
'card_type' => $cardData->type,
'card_member' => $card->member->member_id,
'card_number' => $cardData->lastFour,
'card_expire' => ( !is_null( $cardData->expMonth ) AND !is_null( $cardData->expYear ) ) ? str_pad( $cardData->expMonth , 2, '0', STR_PAD_LEFT ). '/' . $cardData->expYear : NULL
);
}
catch ( \Exception $e ) { }
}
$cards = new \IPS\Helpers\Table\Custom( $cards, $this->member->acpUrl()->setQueryString( 'view', 'cards' ) );
$cards->rootButtons = array(
'add' => array(
'link' => \IPS\Http\Url::internal("app=nexus&module=customers&controller=view&id={$this->member->member_id}")->setQueryString( 'do', 'addCard' ),
'title' => 'add',
'icon' => 'plus',
'data' => array( 'ipsDialog' => true, 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('add_card') )
)
);
$cards->rowButtons = function( $row )
{
return array(
'delete' => array(
'link' => \IPS\Http\Url::internal("app=nexus&module=customers&controller=view&id={$this->member->member_id}")->setQueryString( array( 'do' => 'deleteCard', 'card_id' => $row['id'] ) ),
'title' => 'delete',
'icon' => 'times-circle',
'data' => array( 'delete' => '' )
)
);
};
if ( $edit )
{
$cards->tableTemplate = array( \IPS\Theme::i()->getTemplate( 'customers', 'nexus' ), 'cardsTable' );
$cards->rowsTemplate = array( \IPS\Theme::i()->getTemplate( 'customers', 'nexus' ), 'cardsTableRows' );
return \IPS\Theme::i()->getTemplate( 'customers', 'nexus' )->customerPopup( $cards );
}
else
{
$cards->tableTemplate = array( \IPS\Theme::i()->getTemplate( 'customers', 'nexus' ), 'cardsOverview' );
$cards->rowsTemplate = array( \IPS\Theme::i()->getTemplate( 'customers', 'nexus' ), 'cardsOverviewRows' );
$cardCount = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_customer_cards', array( 'card_member=?', $this->member->member_id ) )->first();
return \IPS\Theme::i()->getTemplate( 'customers', 'nexus' )->accountInformationTablePreview( $this->member, $cards, \IPS\Member::loggedIn()->language()->addToStack( 'num_credit_card', FALSE, array( 'pluralize' => array( $cardCount ) ) ), 'cards' );
}
}
/**
* Get output: BILLING AGREEMENTS
*
* @param bool $edit Edit view?
* @return string
*/
protected function _paypal( $edit = FALSE )
{
$billingAgreementCount = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_billing_agreements', array( 'ba_member=? AND ba_canceled=0', $this->member->member_id ) )->first();
$billingAgreements = array();
foreach ( \IPS\Db::i()->select( '*', 'nexus_billing_agreements', array( 'ba_member=? AND ba_canceled=0', $this->member->member_id ), NULL, \IPS\Request::i()->view === 'billingagreements' ? NULL : 2 ) as $billingAgreement )
{
$billingAgreements[ $billingAgreement['ba_id'] ] = array(
'id' => $billingAgreement['ba_id'],
'gw_id' => $billingAgreement['ba_gw_id'],
'started' => $billingAgreement['ba_started'],
'next_cycle' => $billingAgreement['ba_next_cycle'],
);
}
$billingAgreements = new \IPS\Helpers\Table\Custom( $billingAgreements, $this->member->acpUrl()->setQueryString( 'view', 'billingagreements' ) );
$billingAgreements->parsers = array(
'started' => function( $val ) {
return $val ? \IPS\DateTime::ts( $val )->relative() : null;
},
'next_cycle' => function( $val ) {
return $val ? \IPS\DateTime::ts( $val )->relative() : null;
},
);
$billingAgreements->rowButtons = function( $row, $id )
{
return array(
'view' => array(
'link' => \IPS\Http\Url::internal("app=nexus&module=payments&controller=billingagreements&id={$id}"),
'title' => 'view',
'icon' => 'search',
)
);
};
if ( $edit )
{
$billingAgreements->exclude = array( 'id', 'last_transaction_currency' );
$billingAgreements->langPrefix = 'ba_';
return \IPS\Theme::i()->getTemplate( 'customers', 'nexus' )->customerPopup( $billingAgreements );
}
else
{
$billingAgreements->tableTemplate = array( \IPS\Theme::i()->getTemplate( 'customers', 'nexus' ), 'billingAgreementsOverview' );
$billingAgreements->rowsTemplate = array( \IPS\Theme::i()->getTemplate( 'customers', 'nexus' ), 'billingAgreementsOverviewRows' );
return \IPS\Theme::i()->getTemplate( 'customers', 'nexus' )->accountInformationTablePreview( $this->member, $billingAgreements, \IPS\Member::loggedIn()->language()->addToStack( 'num_billing_agreements', FALSE, array( 'pluralize' => array( $billingAgreementCount ) ) ), 'paypal' );
}
}
/**
* Get output: ALTERNATE CONTACTS
*
* @param bool $edit Edit view?
* @return string
*/
protected function _alts( $edit = FALSE )
{
$altContactCount = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_alternate_contacts', array( 'main_id=?', $this->member->member_id ) )->first();
$alternativeContacts = new \IPS\Helpers\Table\Db( 'nexus_alternate_contacts', $this->member->acpUrl()->setQueryString( 'view', 'alternatives' ), array( 'main_id=?', $this->member->member_id ) );
$alternativeContacts->langPrefix = 'altcontactTable_';
$alternativeContacts->include = array( 'alt_id', 'purchases', 'billing', 'support' );
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'customers_edit_details' ) )
{
$alternativeContacts->parsers = array(
'alt_id' => function( $val )
{
return \IPS\Theme::i()->getTemplate( 'global', 'nexus' )->userLink( \IPS\nexus\Customer::load( $val ) );
},
'email' => function ( $val, $row )
{
return htmlspecialchars( \IPS\nexus\Customer::load( $row['alt_id'] )->email, ENT_DISALLOWED, 'UTF-8', FALSE );
},
'purchases' => function( $val )
{
return implode( '<br>', array_map( function( $id )
{
try
{
return \IPS\Theme::i()->getTemplate( 'purchases', 'nexus' )->link( \IPS\nexus\Purchase::load( $id ) );
}
catch ( \OutOfRangeException $e )
{
return '';
}
}, explode( ',', $val ) ) );
},
'billing' => function( $val )
{
return $val ? "<i class='fa fa-check'></i>" : "<i class='fa fa-times'></i>";
},
'support' => function( $val )
{
return $val ? "<i class='fa fa-check'></i>" : "<i class='fa fa-times'></i>";
}
);
$alternativeContacts->rootButtons = array(
'add' => array(
'link' => \IPS\Http\Url::internal("app=nexus&module=customers&controller=view&id={$this->member->member_id}")->setQueryString( 'do', 'alternativeContactForm' ),
'title' => 'add',
'icon' => 'plus',
'data' => array( 'ipsDialog' => true, 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('altcontact_add') )
)
);
$alternativeContacts->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' => 'alternativeContactForm', 'alt_id' => $row['alt_id'] ) ),
'title' => 'edit',
'icon' => 'pencil',
'data' => array( 'ipsDialog' => true )
),
'delete' => array(
'link' => \IPS\Http\Url::internal("app=nexus&module=customers&controller=view&id={$this->member->member_id}")->setQueryString( array( 'do' => 'deleteAlternativeContact', 'alt_id' => $row['alt_id'] ) ),
'title' => 'delete',
'icon' => 'times-circle',
'data' => array( 'delete' => '' )
)
);
};
}
if ( $edit )
{
return \IPS\Theme::i()->getTemplate( 'customers', 'nexus' )->customerPopup( $alternativeContacts );
}
else
{
$alternativeContacts->include[] = 'email';
$alternativeContacts->limit = 2;
$alternativeContacts->tableTemplate = array( \IPS\Theme::i()->getTemplate( 'customers', 'nexus' ), 'altContactsOverview' );
$alternativeContacts->rowsTemplate = array( \IPS\Theme::i()->getTemplate( 'customers', 'nexus' ), 'altContactsOverviewRows' );
return \IPS\Theme::i()->getTemplate( 'customers', 'nexus' )->accountInformationTablePreview( $this->member, $alternativeContacts, \IPS\Member::loggedIn()->language()->addToStack( 'num_alternate_contacts', FALSE, array( 'pluralize' => array( $altContactCount ) ) ), 'alts' );
}
}
/**
* Get output: REFERRERS
*
* @param bool $edit Edit view?
* @return string
*/
protected function _referrers( $edit = FALSE )
{
$referCount = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_referrals', array( 'referred_by=?', $this->member->member_id ) )->first();
$referrals = new \IPS\Helpers\Table\Db( 'nexus_referrals', $this->member->acpUrl()->setQueryString( 'view', 'referrals' ), array( 'referred_by=?', $this->member->member_id ) );
$referrals->langPrefix = 'ref_';
$referrals->include = array( 'member_id', 'amount' );
$referrals->sortBy = $referrals->sortBy ?: 'member_id';
$referrals->parsers = array(
'member_id' => function( $v )
{
try
{
return \IPS\Theme::i()->getTemplate( 'global', 'nexus' )->userLink( \IPS\nexus\Customer::load( $v ) );
}
catch ( \OutOfRangeException $e )
{
return \IPS\Member::loggedIn()->language()->addToStack('deleted_member');
}
},
'email' => function( $v, $row )
{
try
{
return htmlspecialchars( \IPS\nexus\Customer::load( $row['member_id'] )->email, ENT_DISALLOWED, 'UTF-8', FALSE );
}
catch ( \OutOfRangeException $e )
{
return \IPS\Member::loggedIn()->language()->addToStack('deleted_member');
}
},
'amount' => function( $v )
{
$return = array();
if ( $v )
{
foreach ( json_decode( $v, TRUE ) as $currency => $amount )
{
$return[] = new \IPS\nexus\Money( $amount, $currency );
}
}
else
{
$return[] = new \IPS\nexus\Money( 0, $this->member->defaultCurrency() );
}
return implode( '<br>', $return );
}
);
if ( $edit )
{
return \IPS\Theme::i()->getTemplate( 'customers', 'nexus' )->customerPopup( $referrals );
}
else
{
$referrals->include[] = 'email';
$referrals->limit = 2;
$referrals->tableTemplate = array( \IPS\Theme::i()->getTemplate( 'customers', 'nexus' ), 'referralsOverview' );
$referrals->rowsTemplate = array( \IPS\Theme::i()->getTemplate( 'customers', 'nexus' ), 'referralsOverviewRows' );
return \IPS\Theme::i()->getTemplate( 'customers', 'nexus' )->accountInformationTablePreview( $this->member, $referrals, \IPS\Member::loggedIn()->language()->addToStack( 'num_refer_count', FALSE, array( 'pluralize' => array( $referCount ) ) ), 'referrers' );
}
}
/**
* Get output
*
* @return string
*/
public function tabOutput( $tab )
{
$method = "_{$tab}";
return $this->$method();
}
/**
* Edit Window
*
* @return string
*/
public function edit()
{
if ( array_key_exists( \IPS\Request::i()->type, $this->tabs() ) )
{
$method = "_" . \IPS\Request::i()->type;
return $this->$method( TRUE );
}
return parent::edit();
}
/**
* Get output
*
* @return string
*/
public function output()
{
$tabs = $this->tabs();
if ( !count( $tabs ) )
{
return '';
}
$tabKeys = array_keys( $tabs );
$activeTabKey = ( isset( \IPS\Request::i()->block['nexus_AccountInformation'] ) and array_key_exists( \IPS\Request::i()->block['nexus_AccountInformation'], $tabs ) ) ? \IPS\Request::i()->block['nexus_AccountInformation'] : array_shift( $tabKeys );
$activeSubscription = FALSE;
if ( \IPS\Settings::i()->nexus_subs_enabled )
{
$activeSubscription = \IPS\nexus\Subscription::loadActiveByMember( $this->member );
}
return \IPS\Theme::i()->getTemplate( 'customers', 'nexus' )->accountInformation( $this->member, $tabs, $activeTabKey, $this->tabOutput( $activeTabKey ), $activeSubscription );
}
}
@@ -0,0 +1,50 @@
<?php
/**
* @brief ACP Member Profile: Invoices
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @since 5 Dec 2017
*/
namespace IPS\nexus\extensions\core\MemberACPProfileBlocks;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* @brief ACP Member Profile: Invoices
*/
class _Invoices extends \IPS\core\MemberACPProfile\Block
{
/**
* Get output
*
* @return string
*/
public function output()
{
$invoiceCount = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_invoices', array( 'i_member=?', $this->member->member_id ) )->first();
$invoices = \IPS\nexus\Invoice::table( array( 'i_member=?', $this->member->member_id ), $this->member->acpUrl()->setQueryString( 'tab', 'invoices' ), 'c' );
$invoices->limit = 15;
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'invoices_add' ) )
{
$invoices->rootButtons = array(
'add' => array(
'link' => \IPS\Http\Url::internal( "app=nexus&module=payments&controller=invoices&do=generate&member={$this->member->member_id}" ),
'title' => 'add',
'icon' => 'plus',
)
);
}
$invoices->tableTemplate = array( \IPS\Theme::i()->getTemplate( 'customers', 'nexus' ), 'invoicesTable' );
$invoices->rowsTemplate = array( \IPS\Theme::i()->getTemplate( 'customers', 'nexus' ), 'invoicesTableRows' );
return \IPS\Theme::i()->getTemplate( 'customers', 'nexus' )->invoices( $this->member, $invoices, $invoiceCount );
}
}
@@ -0,0 +1,138 @@
<?php
/**
* @brief ACP Member Profile: Notes
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @since 5 Dec 2017
*/
namespace IPS\nexus\extensions\core\MemberACPProfileBlocks;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* @brief ACP Member Profile: Notes
*/
class _Notes extends \IPS\core\MemberACPProfile\Block
{
/**
* @brief Notes
*/
protected $notes;
/**
* @brief Note Count
*/
protected $noteCount;
/**
* Constructor
*
* @param \IPS\Member $member Member
* @return void
*/
public function __construct( \IPS\Member $member )
{
parent::__construct( $member );
$this->notes = NULL;
$this->noteCount = 0;
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'customer_notes_view' ) )
{
$this->noteCount = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_notes', array( 'note_member=?', $this->member->member_id ) )->first();
$this->notes = new \IPS\Helpers\Table\Db( 'nexus_notes', $this->member->acpUrl()->setQueryString( array( 'view' => 'notes', 'support' => isset( \IPS\Request::i()->support ) ? \IPS\Request::i()->support : 0 ) ), array( 'note_member=?', $this->member->member_id ) );
$this->notes->tableTemplate = array( \IPS\Theme::i()->getTemplate( 'customers', 'nexus' ), 'notes' );
$this->notes->sortBy = 'note_date';
$this->notes->parsers = array(
'note_member' => function( $val )
{
return \IPS\Member::load( $val );
},
'note_text' => function( $val )
{
return $val;
}
);
$this->notes->rowButtons = function( $row )
{
$return = array();
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'customer_notes_edit' ) )
{
if ( !isset( \IPS\Request::i()->support ) or !\IPS\Request::i()->support )
{
$return['edit'] = array(
'link' => \IPS\Http\Url::internal("app=nexus&module=customers&controller=view&id={$this->member->member_id}")->setQueryString( array( 'do' => 'noteForm', 'note_id' => $row['note_id'], 'support' => isset( \IPS\Request::i()->support ) ? \IPS\Request::i()->support : 0 ) ),
'title' => 'edit',
'icon' => 'pencil',
'data' => array( 'ipsDialog' => true, 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('edit_note') )
);
}
else
{
$return['edit'] = array(
'link' => \IPS\Http\Url::internal("app=nexus&module=customers&controller=view&id={$this->member->member_id}")->setQueryString( array( 'do' => 'noteForm', 'note_id' => $row['note_id'], 'support' => isset( \IPS\Request::i()->support ) ? \IPS\Request::i()->support : 0 ) ),
'title' => 'edit',
'icon' => 'pencil',
);
}
}
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'customer_notes_delete' ) )
{
$return['delete'] = array(
'link' => \IPS\Http\Url::internal("app=nexus&module=customers&controller=view&id={$this->member->member_id}")->setQueryString( array( 'do' => 'deleteNote', 'note_id' => $row['note_id'], 'support' => isset( \IPS\Request::i()->support ) ? \IPS\Request::i()->support : 0 ) ),
'title' => 'delete',
'icon' => 'times-circle',
'data' => array( 'delete' => '' )
);
}
return $return;
};
if ( ( !isset( \IPS\Request::i()->support ) or !\IPS\Request::i()->support ) and \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'customer_notes_add' ) )
{
$this->notes->rootButtons = array(
'add' => array(
'link' => \IPS\Http\Url::internal("app=nexus&module=customers&controller=view&id={$this->member->member_id}")->setQueryString( array( 'do' => 'noteForm', 'support' => isset( \IPS\Request::i()->support ) ? \IPS\Request::i()->support : 0 ) ),
'title' => 'add',
'icon' => 'plus',
'data' => array( 'ipsDialog' => true, 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('add_note') )
)
);
}
}
}
/**
* Get output
*
* @return string
*/
public function output()
{
$this->notes->limit = 2;
$this->notes->tableTemplate = array( \IPS\Theme::i()->getTemplate( 'customers', 'nexus' ), 'notesOverview' );
$this->notes->rowsTemplate = array( \IPS\Theme::i()->getTemplate( 'customers', 'nexus' ), 'notesOverviewRows' );
return \IPS\Theme::i()->getTemplate( 'customers', 'nexus' )->notesBlock( $this->member, $this->noteCount, $this->notes );
}
/**
* Get output
*
* @return string
*/
public function edit()
{
return \IPS\Theme::i()->getTemplate( 'customers', 'nexus' )->customerPopup( $this->notes );
}
}
@@ -0,0 +1,43 @@
<?php
/**
* @brief ACP Member Profile: Parent Accounts Block
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @since 5 Dec 2017
*/
namespace IPS\nexus\extensions\core\MemberACPProfileBlocks;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* @brief ACP Member Profile: Customer Statistics Block
*/
class _ParentAccounts extends \IPS\core\MemberACPProfile\Block
{
/**
* Get output
*
* @return string
*/
public function output()
{
$parents = array();
foreach ( \IPS\Db::i()->select( 'main_id', 'nexus_alternate_contacts', array( 'alt_id=?', $this->member->member_id ) ) as $row )
{
$parents[] = \IPS\nexus\Customer::load( $row );
}
if ( count( $parents ) )
{
return \IPS\Theme::i()->getTemplate( 'customers', 'nexus' )->parentAccounts( $parents );
}
}
}
@@ -0,0 +1,71 @@
<?php
/**
* @brief ACP Member Profile: Purchases
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @since 5 Dec 2017
*/
namespace IPS\nexus\extensions\core\MemberACPProfileBlocks;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* @brief ACP Member Profile: Purchases
*/
class _Purchases extends \IPS\core\MemberACPProfile\Block
{
/**
* Purchase tree
*/
protected $_purchases = NULL;
/**
* Get purchase table
*
* @return \IPS\IPS\Helpers\Tree
*/
protected function purchases()
{
if ( $this->_purchases === NULL )
{
$this->_purchases = \IPS\nexus\Purchase::tree( $this->member->acpUrl()->setQueryString( 'blockKey', 'nexus_Purchases' ), array( array( 'ps_member=?', $this->member->member_id ) ) );
$this->_purchases->rootsPerPage = 15;
$this->_purchases->getTotalRoots = function()
{
return NULL;
};
}
return $this->_purchases;
}
/**
* Get output
*
* @return string
*/
public function output()
{
$purchaseCount = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_purchases', array( 'ps_member=? AND ps_show=1', $this->member->member_id ) )->first();
$purchaseRootCount = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_purchases', array( 'ps_member=? AND ps_show=1 AND ps_parent=0', $this->member->member_id ) )->first();
return \IPS\Theme::i()->getTemplate( 'customers', 'nexus' )->purchases( $this->member, $this->purchases(), $purchaseCount, $purchaseRootCount );
}
/**
* Get output
*
* @return string
*/
public function tabOutput()
{
return (string) $this->purchases();
}
}
@@ -0,0 +1,124 @@
<?php
/**
* @brief ACP Member Profile: Customer Statistics Block
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @since 5 Dec 2017
*/
namespace IPS\nexus\extensions\core\MemberACPProfileBlocks;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* @brief ACP Member Profile: Customer Statistics Block
*/
class _Statistics extends \IPS\core\MemberACPProfile\LazyLoadingBlock
{
/**
* Get output
*
* @return string
*/
public function lazyOutput()
{
$standing = array();
$time = time();
foreach ( \IPS\nexus\Money::currencies() as $currency )
{
/* Total spent */
$comparisons = \IPS\Db::i()->select( 'AVG(xval) AS avg, MAX(xval) AS max, MIN(xval) AS min', \IPS\Db::i()->select( "(SUM(t_amount)-SUM(t_partial_refund)) as xval", 'nexus_transactions', array( '( t_status=? OR t_status=? ) AND t_currency=? AND t_member<>0', \IPS\nexus\Transaction::STATUS_PAID, \IPS\nexus\Transaction::STATUS_PART_REFUNDED, $currency ), NULL, NULL, 't_member' ), 'xval>0' )->first();
$val = \IPS\Db::i()->select( 'SUM(t_amount)-SUM(t_partial_refund)', 'nexus_transactions', array( 't_member=? AND ( t_status=? OR t_status=? ) AND t_currency=?', $this->member->member_id, \IPS\nexus\Transaction::STATUS_PAID, \IPS\nexus\Transaction::STATUS_PART_REFUNDED, $currency ) )->first();
$standing[ \IPS\Member::loggedIn()->language()->addToStack( 'total_spent_currency', FALSE, array( 'sprintf' => array( $currency ) ) ) ] = array(
'value' => new \IPS\nexus\Money( $val ?: '0', $currency ),
'avg' => new \IPS\nexus\Money( $comparisons['avg'], $currency ),
'highest' => new \IPS\nexus\Money( $comparisons['max'], $currency ),
'lowest' => new \IPS\nexus\Money( $comparisons['min'], $currency ),
'lowval' => $comparisons['min'],
'highval' => $comparisons['max'],
'avgval' => $comparisons['avg'],
'thisval' => $val,
'avgpct' => $comparisons['max'] ? round( ( ( $comparisons['avg'] - $comparisons['min'] ) / $comparisons['max'] ) * 100, 1 ) : 0,
'thispct' => $comparisons['max'] ? round( ( ( $val - $comparisons['min'] ) / $comparisons['max'] ) * 100, 1 ) : 0,
'type' => 'totalspent'
);
/* Average monthly spend */
$sum = "( SUM(t_amount) / ( ( {$time} - core_members.joined ) / 2592000 ) )";
$where = array( array( "( t_status=? OR t_status=? ) AND ({$time} - core_members.joined > 2592000) AND t_currency=?", \IPS\nexus\Transaction::STATUS_PAID, \IPS\nexus\Transaction::STATUS_PART_REFUNDED, $currency ) );
try
{
$val = \IPS\Db::i()->select( "{$sum} as sum", 'nexus_transactions', array_merge( $where, array( array( 't_member=?', $this->member->member_id ) ) ), 'joined', NULL, 'joined' )->join( 'core_members', 'member_id=t_member' )->first();
}
catch( \UnderflowException $e )
{
$val = 0;
}
$comparisons = \IPS\Db::i()->select( 'AVG(xval) AS avg, MAX(xval) AS max, MIN(xval) AS min', \IPS\Db::i()->select( "{$sum} as xval", 'nexus_transactions', array_merge( $where, array( array( 't_member<>0' ) ) ), NULL, NULL, array( 't_member', 'joined' ) ), 'xval>0' )->join( 'core_members', 'member_id=t_member' )->first();
$standing[ \IPS\Member::loggedIn()->language()->addToStack( 'average_spend_currency', FALSE, array( 'sprintf' => array( $currency ) ) ) ] = array(
'value' => new \IPS\nexus\Money( $val, $currency ),
'avg' => new \IPS\nexus\Money( $comparisons['avg'], $currency ),
'highest' => new \IPS\nexus\Money( $comparisons['max'], $currency ),
'lowest' => new \IPS\nexus\Money( $comparisons['min'], $currency ),
'lowval' => $comparisons['min'],
'highval' => $comparisons['max'],
'avgval' => $comparisons['avg'],
'thisval' => $val,
'avgpct' => $comparisons['max'] ? round( ( ( $comparisons['avg'] - $comparisons['min'] ) / $comparisons['max'] ) * 100, 1 ) : 0,
'thispct' => $comparisons['max'] ? round( ( ( $val - $comparisons['min'] ) / $comparisons['max'] ) * 100, 1 ) : 0,
'type' => 'avgspent'
);
}
$sum = "ROUND( ( AVG( i_paid - i_date ) / 86400 ), 2 )";
$where = array( array( "i_status=? AND i_date>0 AND i_paid>0", \IPS\nexus\Invoice::STATUS_PAID ) );
$val = \IPS\Db::i()->select( "{$sum} as sum", 'nexus_invoices', array_merge( $where, array( array( 'i_member=?', $this->member->member_id ) ) ) )->join( 'core_members', 'member_id=i_member' )->first();
$comparisons = \IPS\Db::i()->select( 'AVG(xval) AS avg, MAX(xval) AS max, MIN(xval) AS min', \IPS\Db::i()->select( "{$sum} as xval", 'nexus_invoices', array_merge( $where, array( array( 'i_member<>0' ) ) ), NULL, NULL, array( 'i_member', 'joined' ) ), 'xval>0' )->join( 'core_members', 'member_id=i_member' )->first();
$standing[ \IPS\Member::loggedIn()->language()->addToStack( 'average_time_to_pay' ) ] = array(
'value' => \IPS\Member::loggedIn()->language()->formatNumber( $val, 2 ) . ' ' . \IPS\Member::loggedIn()->language()->addToStack('days'),
'avg' => \IPS\Member::loggedIn()->language()->formatNumber( $comparisons['avg'], 2 ) . ' ' . \IPS\Member::loggedIn()->language()->addToStack('days'),
'highest' => \IPS\Member::loggedIn()->language()->formatNumber( $comparisons['max'], 2 ) . ' ' . \IPS\Member::loggedIn()->language()->addToStack('days'),
'lowest' => \IPS\Member::loggedIn()->language()->formatNumber( $comparisons['min'], 2 ) . ' ' . \IPS\Member::loggedIn()->language()->addToStack('days'),
'lowval' => $comparisons['min'],
'highval' => $comparisons['max'],
'avgval' => $comparisons['avg'],
'thisval' => $val,
'avgpct' => floatval( $comparisons['max'] ) ? round( ( ( $comparisons['avg'] - $comparisons['min'] ) / $comparisons['max'] ) * 100, 1 ) : 0,
'thispct' => floatval( $comparisons['max'] ) ? round( ( ( $val - $comparisons['min'] ) / $comparisons['max'] ) * 100, 1 ) : 0,
'type' => 'timetopay'
);
$sum = "LEAST( ( COUNT(*) / ( ( {$time} - core_members.joined ) / 2592000 ) ), COUNT(*) )";
try
{
$val = \IPS\Db::i()->select( "{$sum} as sum", 'nexus_support_requests', array( 'r_member=?', $this->member->member_id ), 'joined', NULL, 'joined' )->join( 'core_members', 'member_id=r_member' )->first();
}
catch( \UnderflowException $e )
{
$val = 0;
}
$comparisons = \IPS\Db::i()->select( 'AVG(xval) AS avg, MAX(xval) AS max, MIN(xval) AS min', \IPS\Db::i()->select( "{$sum} as xval", 'nexus_support_requests', 'r_member<>0', NULL, NULL, 'joined' ) )->join( 'core_members', 'member_id=r_member' )->first();
$standing[ \IPS\Member::loggedIn()->language()->addToStack( 'average_monthly_support_requests' ) ] = array(
'value' => \IPS\Member::loggedIn()->language()->formatNumber( $val, 2 ),
'avg' => \IPS\Member::loggedIn()->language()->formatNumber( $comparisons['avg'], 2 ),
'highest' => \IPS\Member::loggedIn()->language()->formatNumber( $comparisons['max'], 2 ),
'lowest' => \IPS\Member::loggedIn()->language()->formatNumber( $comparisons['min'], 2 ),
'lowval' => $comparisons['min'],
'highval' => $comparisons['max'],
'avgval' => $comparisons['avg'],
'thisval' => $val,
'avgpct' => $comparisons['max'] ? round( ( ( $comparisons['avg'] - $comparisons['min'] ) / $comparisons['max'] ) * 100, 1 ) : 0,
'thispct' => $comparisons['max'] ? round( ( ( $val - $comparisons['min'] ) / $comparisons['max'] ) * 100, 1 ) : 0,
'type' => 'support'
);
return \IPS\Theme::i()->getTemplate( 'customers', 'nexus' )->standing( $standing );
}
}
@@ -0,0 +1,42 @@
<?php
/**
* @brief ACP Member Profile: Support
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @since 5 Dec 2017
*/
namespace IPS\nexus\extensions\core\MemberACPProfileBlocks;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* @brief ACP Member Profile: Support
*/
class _Support extends \IPS\core\MemberACPProfile\Block
{
/**
* Get output
*
* @return string
*/
public function output()
{
$customerStream = \IPS\nexus\Support\Stream::customer( $this->member );
$supportCount = $customerStream->count( \IPS\Member::loggedIn() );
$results = $customerStream->results( \IPS\Member::loggedIn(), 'r_started DESC', 1, 15 );
$supportRequestsInView = array_keys( iterator_to_array( $results ) );
$tracked = iterator_to_array( \IPS\Db::i()->select( array( 'request_id', 'notify' ), 'nexus_support_tracker', array( array( 'member_id=?', \IPS\Member::loggedIn()->member_id ), array( \IPS\Db::i()->in( 'request_id', $supportRequestsInView ) ) ) )->setKeyField( 'request_id' )->setValueField( 'notify' ) );
$participatedIn = iterator_to_array( \IPS\Db::i()->select( 'DISTINCT reply_request', 'nexus_support_replies', array( array( 'reply_member=?', \IPS\Member::loggedIn()->member_id ), array( \IPS\Db::i()->in( 'reply_request', $supportRequestsInView ) ) ) ) );
$support = \IPS\Theme::i()->getTemplate( 'support', 'nexus' )->requestsTableResults( $results, NULL, FALSE, $tracked, $participatedIn, FALSE );
return \IPS\Theme::i()->getTemplate( 'customers', 'nexus' )->support( $this->member, $support, $supportCount );
}
}
@@ -0,0 +1,84 @@
<?php
/**
* @brief ACP Member Profile: Customer Tab
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @since 20 Nov 2017
*/
namespace IPS\nexus\extensions\core\MemberACPProfileTabs;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* @brief ACP Member Profile: Customer Tab
*/
class _Main extends \IPS\core\MemberACPProfile\MainTab
{
/**
* Constructor
*
* @param \IPS\Member $member Member
* @return void
*/
public function __construct( \IPS\Member $member )
{
$this->member = \IPS\nexus\Customer::load( $member->member_id );
}
/**
* Get left-column blocks
*
* @return array
*/
public function leftColumnBlocks()
{
return array(
'IPS\nexus\extensions\core\MemberACPProfileBlocks\AccountInformation',
);
}
/**
* Get main-column blocks
*
* @return array
*/
public function mainColumnBlocks()
{
return array(
'IPS\nexus\extensions\core\MemberACPProfileBlocks\Statistics',
'IPS\nexus\extensions\core\MemberACPProfileBlocks\ParentAccounts',
'IPS\nexus\extensions\core\MemberACPProfileBlocks\Notes',
'IPS\nexus\extensions\core\MemberACPProfileBlocks\Purchases',
'IPS\nexus\extensions\core\MemberACPProfileBlocks\Invoices',
'IPS\nexus\extensions\core\MemberACPProfileBlocks\Support',
);
}
/**
* Get Output
*
* @return string
*/
public function output()
{
\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' ) );
return parent::output();
}
}
@@ -53,11 +53,19 @@ class _Purchases
{
return NULL;
}
}, explode( ',', $criteria['nexus_bm_filters_packages'] ) ) ) : 0, FALSE, array( 'zeroVal' => 'nexus_bm_filters_packages_none', 'multiple' => TRUE, 'class' => 'IPS\nexus\Package\Group', 'zeroValTogglesOff' => array( 'nexus_bm_filters_types' ), 'permissionCheck' => function( $node )
}, explode( ',', $criteria['nexus_bm_filters_packages'] ) ) ) : 0, FALSE, array( 'zeroVal' => 'nexus_bm_filters_packages_none', 'multiple' => TRUE, 'class' => 'IPS\nexus\Package\Group', 'zeroValTogglesOff' => array( 'nexus_bm_filters_pkg_active', 'nexus_bm_filters_pkg_expired', 'nexus_bm_filters_pkg_canceled' ), 'permissionCheck' => function( $node )
{
return !( $node instanceof \IPS\nexus\Package\Group );
} ) ),
new \IPS\Helpers\Form\CheckboxSet( 'nexus_bm_filters_type', isset( $criteria['nexus_bm_filters_type'] ) ? explode( ',', $criteria['nexus_bm_filters_type'] ) : array( 'active' ), FALSE, array( 'options' => array( 'active' => 'nexus_bm_filters_type_active', 'expired' => 'nexus_bm_filters_type_expired', 'canceled' => 'nexus_bm_filters_type_canceled' ) ), NULL, NULL, NULL, 'nexus_bm_filters_types' )
new \IPS\Helpers\Form\CheckboxSet( 'nexus_bm_filters_type', isset( $criteria['nexus_bm_filters_type'] ) ? explode( ',', $criteria['nexus_bm_filters_type'] ) : array( 'active' ), FALSE, array( 'toggles' => array( 'expired' => array( 'nexus_bm_filters_pkg_expired' ) ), 'options' => array( 'active' => 'nexus_bm_filters_type_active', 'expired' => 'nexus_bm_filters_type_expired', 'canceled' => 'nexus_bm_filters_type_canceled' ) ), NULL, NULL, NULL, 'nexus_bm_filters_types' ),
new \IPS\Helpers\Form\Custom( 'nexus_bm_filters_pkg_expired', array( 0 => isset( $criteria['nexus_bm_filters_pkg_expired']['range'] ) ? $criteria['nexus_bm_filters_pkg_expired']['range'] : '', 1 => isset( $criteria['nexus_bm_filters_pkg_expired']['days'] ) ? $criteria['nexus_bm_filters_pkg_expired']['days'] : NULL ), FALSE, array(
'getHtml' => function( $element )
{
$dateRange = new \IPS\Helpers\Form\DateRange( "{$element->name}[0]", $element->value[0], FALSE );
return \IPS\Theme::i()->getTemplate( 'members', 'core', 'global' )->dateFilters( $dateRange, $element );
}
), NULL, NULL, NULL, 'nexus_bm_filters_pkg_expired' ),
);
}
@@ -77,8 +85,26 @@ class _Purchases
{
$ids[] = $package->id;
}
return array( 'nexus_bm_filters_packages' => implode( ',', $ids ), 'nexus_bm_filters_type' => implode( ',', $post['nexus_bm_filters_type'] ) );
$return = array(
'nexus_bm_filters_packages' => implode( ',', $ids ),
'nexus_bm_filters_pkg_active' => (bool) ( in_array( "active", $post['nexus_bm_filters_type'] ) ),
'nexus_bm_filters_pkg_canceled' => (bool) ( in_array( "canceled", $post['nexus_bm_filters_type'] ) ),
'nexus_bm_filters_pkg_expired' => NULL
);
if( isset( $post['nexus_bm_filters_pkg_expired'][2] ) AND $post['nexus_bm_filters_pkg_expired'][2] == 'days' )
{
$return['nexus_bm_filters_pkg_expired'] = $post['nexus_bm_filters_pkg_expired'][1] ? array( 'days' => intval( $post['nexus_bm_filters_pkg_expired'][1] ) ) : FALSE;
}
else
{
/* Normalize objects to their array form. Bulk mailer stores options as a json array where as member export does not, so $data['range']['start'] is a DateTime object */
$return['nexus_bm_filters_pkg_expired'] = ( empty($post['nexus_bm_filters_pkg_expired'][0]) ) ? FALSE : array( 'range' => json_decode( json_encode( $post['nexus_bm_filters_pkg_expired'][0] ), TRUE ) );
}
return $return;
}
return FALSE;
@@ -112,25 +138,36 @@ class _Purchases
if ( isset( $data['nexus_bm_filters_packages'] ) and $data['nexus_bm_filters_packages'] )
{
$types = array();
$_types = explode( ',', $data['nexus_bm_filters_type'] );
if ( in_array( 'active', $_types ) )
if ( isset($data[ 'nexus_bm_filters_pkg_active' ]) and $data[ 'nexus_bm_filters_pkg_active' ] )
{
$types[] = 'nexus_purchases.ps_active=1';
}
if ( in_array( 'expired', $_types ) )
{
$types[] = '( nexus_purchases.ps_active=0 AND nexus_purchases.ps_cancelled=0 )';
}
if ( in_array( 'canceled', $_types ) )
if ( isset( $data[ 'nexus_bm_filters_pkg_canceled' ] ) and $data[ 'nexus_bm_filters_pkg_canceled' ] )
{
$types[] = 'nexus_purchases.ps_cancelled=1';
}
if ( !empty( $data[ 'nexus_bm_filters_pkg_expired' ][ 'range' ] ) AND !empty( $data[ 'nexus_bm_filters_pkg_expired' ][ 'range' ][ 'end' ] ) )
{
$start = ( $data[ 'nexus_bm_filters_pkg_expired' ][ 'range' ][ 'start' ] ) ? new \IPS\DateTime( $data[ 'nexus_bm_filters_pkg_expired' ][ 'range' ][ 'start' ] ) : NULL;
$end = ( $data[ 'nexus_bm_filters_pkg_expired' ][ 'range' ][ 'end' ] ) ? new \IPS\DateTime( $data[ 'nexus_bm_filters_pkg_expired' ][ 'range' ][ 'end' ] ) : NULL;
if ( $start and $end )
{
$types[] = "( nexus_purchases.ps_active=0 AND nexus_purchases.ps_cancelled=0 AND nexus_purchases.ps_expire BETWEEN {$start->getTimestamp()} AND {$end->getTimestamp()})";
}
}
elseif ( !empty( $data[ 'nexus_bm_filters_pkg_expired' ][ 'days' ] ) )
{
$date = \IPS\DateTime::create()->sub( new \DateInterval( 'P' . $data[ 'nexus_bm_filters_pkg_expired' ][ 'days' ] . 'D' ) );
$types[] = "( nexus_purchases.ps_active=0 AND nexus_purchases.ps_cancelled=0 AND nexus_purchases.ps_expire < {$date->getTimestamp()})";
}
if ( !empty( $types ) )
{
$types = implode( ' OR ', $types );
$query->join( 'nexus_purchases', "nexus_purchases.ps_app='nexus' AND nexus_purchases.ps_type='package' AND nexus_purchases.ps_member=core_members.member_id AND " . \IPS\Db::i()->in( 'nexus_purchases.ps_item_id', explode( ',', $data['nexus_bm_filters_packages'] ) ) . " AND ( {$types} )" );
}
}
@@ -0,0 +1,173 @@
<?php
/**
* @brief Member filter extension
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @subpackage Nexus
* @since 20 Apr 2015
*/
namespace IPS\nexus\extensions\core\MemberFilter;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Member filter extension
*/
class _Subscriptions
{
/**
* Determine if the filter is available in a given area
*
* @param string $area Area to check
* @return bool
*/
public function availableIn( $area )
{
return in_array( $area, array( 'bulkmail' ) );
}
/**
* Get Setting Field
*
* @param mixed $criteria Value returned from the save() method
* @return array Array of form elements
*/
public function getSettingField( $criteria )
{
return array(
new \IPS\Helpers\Form\Node( 'nexus_bm_filters_subscription_pkgs', isset( $criteria['nexus_bm_filters_subscription_pkgs'] ) ? array_filter( array_map( function( $val )
{
try
{
return \IPS\nexus\Subscription\Package::load( $val );
}
catch ( \OutOfRangeException $e )
{
return NULL;
}
}, explode( ',', $criteria['nexus_bm_filters_subscription_pkgs'] ) ) ) : 0, FALSE, array( 'zeroVal' => 'nexus_bm_filters_subscription_none', 'multiple' => TRUE, 'class' => 'IPS\nexus\Subscription\Package', 'zeroValTogglesOff' => array( 'nexus_bm_filters_subscription_type' ) ) ),
new \IPS\Helpers\Form\CheckboxSet( 'nexus_bm_filters_subscription_type', isset( $criteria['nexus_bm_filters_subscription_type'] ) ? explode( ',', $criteria['nexus_bm_filters_subscription_type'] ) : array( 'active' ), FALSE, array( 'toggles' => array( 'expired' => array( 'nexus_bm_filters_type_expired_date' ) ), 'options' => array( 'active' => 'nexus_bm_filters_type_active', 'expired' => 'nexus_bm_filters_type_expired' ) ), NULL, NULL, NULL, 'nexus_bm_filters_subscription_type' ),
new \IPS\Helpers\Form\Custom( 'nexus_bm_filters_type_expired_date', array( 0 => isset( $criteria['nexus_bm_filters_type_expired_date']['range'] ) ? $criteria['nexus_bm_filters_type_expired_date']['range'] : '', 1 => isset( $criteria['nexus_bm_filters_type_expired_date']['days'] ) ? $criteria['nexus_bm_filters_type_expired_date']['days'] : NULL ), FALSE, array(
'getHtml' => function( $element )
{
$dateRange = new \IPS\Helpers\Form\DateRange( "{$element->name}[0]", $element->value[0], FALSE );
return \IPS\Theme::i()->getTemplate( 'members', 'core', 'global' )->dateFilters( $dateRange, $element );
}
), NULL, NULL, NULL, 'nexus_bm_filters_type_expired_date' ),
);
}
/**
* Save the filter data
*
* @param array $post Form values
* @return mixed False, or an array of data to use later when filtering the members
* @throws \LogicException
*/
public function save( $post )
{
if ( is_array( $post['nexus_bm_filters_subscription_pkgs'] ) )
{
$ids = array();
foreach ( $post['nexus_bm_filters_subscription_pkgs'] as $package )
{
$ids[] = $package->id;
}
$return = array(
'nexus_bm_filters_subscription_pkgs' => implode( ',', $ids ),
'nexus_bm_filters_subscription_active' => (bool) ( in_array( "active", $post['nexus_bm_filters_subscription_type'] ) ),
'nexus_bm_filters_subscription_canceled' => (bool) ( in_array( "canceled", $post['nexus_bm_filters_subscription_type'] ) ),
);
if( isset( $post['nexus_bm_filters_type_expired_date'][2] ) AND $post['nexus_bm_filters_type_expired_date'][2] == 'days' )
{
$return['nexus_bm_filters_type_expired_date'] = $post['nexus_bm_filters_type_expired_date'][1] ? array( 'days' => intval( $post['nexus_bm_filters_type_expired_date'][1] ) ) : FALSE;
}
else
{
/* Normalize objects to their array form. Bulk mailer stores options as a json array where as member export does not, so $data['range']['start'] is a DateTime object */
$return['nexus_bm_filters_type_expired_date'] = ( empty($post['nexus_bm_filters_type_expired_date'][0]) ) ? FALSE : array( 'range' => json_decode( json_encode( $post['nexus_bm_filters_type_expired_date'][0] ), TRUE ) );
}
return $return;
}
return FALSE;
}
/**
* Get where clause to add to the member retrieval database query
*
* @param mixed $data The array returned from the save() method
* @return string|array|NULL Where clause
*/
public function getQueryWhereClause( $data )
{
if ( isset( $data['nexus_bm_filters_subscription_pkgs'] ) and $data['nexus_bm_filters_subscription_pkgs'] )
{
return 'nexus_purchases.ps_id IS NOT NULL';
}
return NULL;
}
/**
* Callback for member retrieval database query
* Can be used to set joins
*
* @param mixed $data The array returned from the save() method
* @param \IPS\Db\Query $query The query
* @return void
*/
public function queryCallback( $data, &$query )
{
if ( isset( $data['nexus_bm_filters_subscription_pkgs'] ) and $data['nexus_bm_filters_subscription_pkgs'] )
{
$types = array();
if ( isset($data[ 'nexus_bm_filters_subscription_active' ]) and $data[ 'nexus_bm_filters_subscription_active' ] )
{
$types[] = 'nexus_purchases.ps_active=1';
}
if ( isset( $data[ 'nexus_bm_filters_subscription_canceled' ] ) and $data[ 'nexus_bm_filters_subscription_canceled' ] )
{
$types[] = 'nexus_purchases.ps_cancelled=1';
}
if ( !empty( $data[ 'nexus_bm_filters_type_expired_date' ][ 'range' ] ) AND !empty( $data[ 'nexus_bm_filters_type_expired_date' ][ 'range' ][ 'end' ] ) )
{
$start = ( $data[ 'nexus_bm_filters_type_expired_date' ][ 'range' ][ 'start' ] ) ? new \IPS\DateTime( $data[ 'nexus_bm_filters_type_expired_date' ][ 'range' ][ 'start' ] ) : NULL;
$end = ( $data[ 'nexus_bm_filters_type_expired_date' ][ 'range' ][ 'end' ] ) ? new \IPS\DateTime( $data[ 'nexus_bm_filters_type_expired_date' ][ 'range' ][ 'end' ] ) : NULL;
if ( $start and $end )
{
$types[] = "( nexus_purchases.ps_active=0 AND nexus_purchases.ps_cancelled=0 AND nexus_purchases.ps_expire BETWEEN {$start->getTimestamp()} AND {$end->getTimestamp()})";
}
}
elseif ( !empty( $data[ 'nexus_bm_filters_type_expired_date' ][ 'days' ] ) )
{
$date = \IPS\DateTime::create()->sub( new \DateInterval( 'P' . $data[ 'nexus_bm_filters_type_expired_date' ][ 'days' ] . 'D' ) );
$types[] = "( nexus_purchases.ps_active=0 AND nexus_purchases.ps_cancelled=0 AND nexus_purchases.ps_expire < {$date->getTimestamp()})";
}
if ( !empty( $types ) )
{
$types = implode( ' OR ', $types );
$query->join( 'nexus_purchases', "nexus_purchases.ps_app='nexus' AND nexus_purchases.ps_type='subscription' AND nexus_purchases.ps_member=core_members.member_id AND " . \IPS\Db::i()->in( 'nexus_purchases.ps_item_id', explode( ',', $data['nexus_bm_filters_subscription_pkgs'] ) ) . " AND ( {$types} )" );
}
}
}
}
@@ -276,6 +276,12 @@ class _Nexus
case 'remove_renewals':
return \IPS\Member::loggedIn()->language()->addToStack( 'history_purchase_renewals_removed', FALSE, array( 'htmlsprintf' => array( $purchase, ( isset( $val['system'] ) and $val['system'] ) ? '' : $byStaff ) ) );
case 'never_expire':
return \IPS\Member::loggedIn()->language()->addToStack( 'history_purchase_never_expire', FALSE, array( 'htmlsprintf' => array( $purchase, $byStaff ) ) );
case 'restored_expire':
return \IPS\Member::loggedIn()->language()->addToStack( 'history_purchase_restored_expire', FALSE, array( 'htmlsprintf' => array( $purchase, $byStaff ) ) );
}
}
return \IPS\Member::loggedIn()->language()->addToStack( 'history_purchase_edited', FALSE, array( 'htmlsprintf' => array( $purchase, ( isset( $val['system'] ) and $val['system'] ) ? '' : $byStaff ) ) );
@@ -470,7 +476,7 @@ class _Nexus
$value = implode( ', ', $_value );
$change['value'] = htmlspecialchars( $value, \IPS\HTMLENTITIES, 'UTF-8', FALSE );
$change['value'] = htmlspecialchars( $value, ENT_DISALLOWED, 'UTF-8', FALSE );
}
}
@@ -625,7 +631,7 @@ class _Nexus
}
catch ( \OutOfRangeException $e )
{
$options = array( 'htmlsprintf' => array( $file, htmlspecialchars( $val['ps_name'], ENT_QUOTES | \IPS\HTMLENTITIES, 'UTF-8', FALSE ) ) );
$options = array( 'htmlsprintf' => array( $file, htmlspecialchars( $val['ps_name'], ENT_QUOTES | ENT_DISALLOWED, 'UTF-8', FALSE ) ) );
}
return \IPS\Member::loggedIn()->language()->addToStack( 'history_download_with_purchase', FALSE, $options );
}
@@ -667,7 +673,35 @@ class _Nexus
case 'custom':
return $val['message'];
break;
case 'subscription':
if ( isset( $val['type'] ) )
{
switch( $val['type'] )
{
case 'cancelrenewals':
try
{
return \IPS\Member::loggedIn()->language()->addToStack( 'nexus_history_cancelrenewals_with_name', NULL, array( 'sprintf' => array( \IPS\nexus\Subscription\Package::load( $val['id'] )->_title, $byCustomer ) ) );
}
catch ( \OutOfRangeException $e )
{
return \IPS\Member::loggedIn()->language()->addToStack( 'nexus_history_cancelrenewals', NULL, array( 'sprintf' => array( $byCustomer ) ) );
}
break;
case 'change':
try
{
return \IPS\Member::loggedIn()->language()->addToStack( 'nexus_history_subscription_changed_with_name', FALSE, array( 'sprintf' => array( $val['old'], ( isset( $val['system'] ) and $val['system'] ) ? '' : $byStaff, $val['name'] ) ) );
}
catch ( \OutOfRangeException $e )
{
return \IPS\Member::loggedIn()->language()->addToStack( 'nexus_history_subscription_changed', NULL, array( 'sprintf' => array( ( isset( $val['system'] ) and $val['system'] ) ? '' : $byStaff ) ) );
}
break;
}
}
break;
}
return '';
@@ -55,10 +55,9 @@ class _Nexus
* Member has logged on
*
* @param \IPS\Member $member Member that logged in
* @param \IPS\Http\Url $redirectUrl The URL to send the user back to
* @return void
*/
public function onLogin( $member, $returnUrl )
public function onLogin( $member )
{
if ( isset( \IPS\Request::i()->cookie['cm_reg'] ) and \IPS\Request::i()->cookie['cm_reg'] )
{
@@ -107,6 +106,31 @@ class _Nexus
\IPS\Db::i()->update( 'nexus_alternate_contacts', array( 'alt_id' => $member->member_id ), array( 'alt_id=?', $member2->member_id ) );
\IPS\Db::i()->update( 'nexus_support_streams', array( 'stream_owner' => $member->member_id ), array( 'stream_owner=?', $member2->member_id ) );
\IPS\Db::i()->update( 'nexus_billing_agreements', array( 'ba_member' => $member->member_id ), array( 'ba_member=?', $member2->member_id ) );
\IPS\Db::i()->update( 'nexus_support_requests', array( 'r_member' => $member->member_id ), array( 'r_member=?', $member2->member_id ) );
\IPS\Db::i()->update( 'nexus_support_requests', array( 'r_last_reply_by' => $member->member_id ), array( 'r_last_reply_by=?', $member2->member_id ) );
\IPS\Db::i()->update( 'nexus_support_replies', array( 'reply_member' => $member->member_id ), array( 'reply_member=?', $member2->member_id ) );
/* Account Credit */
$customerToKeep = \IPS\nexus\Customer::load( $member->member_id );
$creditToKeep = $customerToKeep->cm_credits;
$creditToMerge = \IPS\nexus\Customer::load( $member2->member_id )->cm_credits;
foreach( \IPS\nexus\Money::currencies() as $currency )
{
if( isset( $creditToMerge[$currency] ) )
{
if( isset( $creditToKeep[$currency] ) )
{
$creditToKeep[$currency]->amount = $creditToKeep[$currency]->amount->add( $creditToMerge[$currency]->amount );
}
else
{
$creditToKeep[$currency] = $creditToMerge[$currency];
}
}
}
$customerToKeep->cm_credits = $creditToKeep;
$customerToKeep->save();
}
/**
@@ -181,7 +205,7 @@ class _Nexus
}
}
if ( $refresh === TRUE )
if ( $refresh === TRUE and isset( \IPS\Data\Store::i()->supportStaff ) )
{
unset( \IPS\Data\Store::i()->supportStaff );
}
@@ -0,0 +1,120 @@
<?php
/**
* @brief Background Task
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @subpackage Commerce
* @since 03 Aug 2017
*/
namespace IPS\nexus\extensions\core\Queue;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Background Task
*/
class _MoveCustomerHistory
{
public $perCycle = 500;
/**
* Parse data before queuing
*
* @param array $data
* @return array
*/
public function preQueueData( $data )
{
/* Task is not needed if this table doesn't exist */
if( !\IPS\Db::i()->checkForTable( 'nexus_customer_history' ) )
{
return NULL;
}
$data['count'] = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_customer_history' )->first();
if( $data['count'] == 0 )
{
\IPS\Db::i()->dropTable( 'nexus_customer_history' );
return NULL;
}
$data['done'] = 0;
return $data;
}
/**
* Run Background Task
*
* @param mixed $data Data as it was passed to \IPS\Task::queue()
* @param int $offset Offset
* @return int New offset
* @throws \IPS\Task\Queue\OutOfRangeException Indicates offset doesn't exist and thus task is complete
*/
public function run( $data, $offset )
{
$logs = \IPS\Db::i()->select( '*', 'nexus_customer_history', array( 'log_id>?', $offset ), 'log_id ASC', $this->perCycle );
$lastId = 0;
foreach( $logs as $log )
{
$lastId = $log['log_id'];
unset( $log['log_id'] );
/* Set log app */
$log['log_app'] = 'nexus';
/* Convert nexus info into member history format */
if( $log['log_data'] == 'info' )
{
$json = json_decode( $log['log_data'], TRUE );
if( isset( $json['email'] ) )
{
$log['log_app'] = 'core';
$log['log_data'] = json_encode( array( 'old' => $data['email'], 'new' => '' ) );
}
elseif( isset( $data['password'] ) )
{
$log['log_app'] = 'core';
$log['log_data'] = json_encode( array( 'password' => '' ) );
}
}
/* Insert into member history */
\IPS\Db::i()->insert( 'core_member_history', $log );
}
if( $lastId == 0 )
{
\IPS\Db::i()->dropTable( 'nexus_customer_history' );
throw new \IPS\Task\Queue\OutOfRangeException;
}
$data['done'] += $this->perCycle;
return $lastId;
}
/**
* Get Progress
*
* @param mixed $data Data as it was passed to \IPS\Task::queue()
* @param int $offset Offset
* @return array( 'text' => 'Doing something...', 'complete' => 50 ) Text explaining task and percentage complete
* @throws \OutOfRangeException Indicates offset doesn't exist and thus task is complete
*/
public function getProgress( $data, $offset )
{
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack('moving_customer_history'), 'complete' => $data['done'] ? ( round( 100 / $data['done'] * $data['count'], 2 ) ) : 0 );
}
}