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

@@ -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 );
}
}