Version 4.3.6

This commit is contained in:
Neo committed 2025-12-19 05:49:12 -08:00
1 parent fe1acf984a
commit 1a0c7fd3c2
609 files changed
+14707 -5726

No files matched your search

@@ -51,7 +51,7 @@ class _Income
$thirtyDaysAgo = \IPS\DateTime::create()->sub( new \DateInterval('P30D') );
$results = array();
foreach( \IPS\Db::i()->select( "t_currency, DATE_FORMAT( FROM_UNIXTIME( t_date ), '%e %c %Y' ) AS date, SUM(t_amount)-SUM(t_partial_refund) AS amount", 'nexus_transactions', array( 't_date>? AND (t_status=? OR t_status=?)', $thirtyDaysAgo->getTimestamp(), \IPS\nexus\Transaction::STATUS_PAID, \IPS\nexus\Transaction::STATUS_PART_REFUNDED ), NULL, NULL, array( 't_currency', 'date' ) ) as $result )
foreach( \IPS\Db::i()->select( "t_currency, DATE_FORMAT( FROM_UNIXTIME( t_date ), '%e %c %Y' ) AS date, SUM(t_amount)-SUM(t_partial_refund) AS amount", 'nexus_transactions', array( 't_date>? AND (t_status=? OR t_status=?) AND t_method>0', $thirtyDaysAgo->getTimestamp(), \IPS\nexus\Transaction::STATUS_PAID, \IPS\nexus\Transaction::STATUS_PART_REFUNDED ), NULL, NULL, array( 't_currency', 'date' ) ) as $result )
{
$results[ $result['date'] ][ $result['t_currency'] ] = $result['amount'];
}
@@ -58,9 +58,10 @@ class _Admin
* @param int|null $id2 Secondary ID
* @param string|null $id3 Arbitrary data
* @param array $attachment The attachment data
* @param bool $viewOnly If true, just check if the user can see the attachment rather than download it
* @return bool
*/
public function attachmentPermissionCheck( $member, $id1, $id2, $id3, $attachment )
public function attachmentPermissionCheck( $member, $id1, $id2, $id3, $attachment, $viewOnly=FALSE )
{
try
{
@@ -54,14 +54,15 @@ class _Customer
/**
* Permission check for attachments
*
* @param \IPS\Member $member The member
* @param int|null $id1 Primary ID
* @param int|null $id2 Secondary ID
* @param string|null $id3 Arbitrary data
* @param \IPS\Member $member The member
* @param int|null $id1 Primary ID
* @param int|null $id2 Secondary ID
* @param string|null $id3 Arbitrary data
* @param array $attachment The attachment data
* @param bool $viewOnly If true, just check if the user can see the attachment rather than download it
* @return bool
*/
public function attachmentPermissionCheck( $member, $id1, $id2, $id3, $attachment )
public function attachmentPermissionCheck( $member, $id1, $id2, $id3, $attachment, $viewOnly=FALSE )
{
if ( ( $id3 !== 'note' and $member->member_id == $id1 ) or $member->hasAcpRestriction( 'nexus', 'customers', 'customers_view' ) )
{
@@ -49,14 +49,15 @@ class _Purchases
/**
* Permission check for attachments
*
* @param \IPS\Member $member The member
* @param int|null $id1 Primary ID
* @param int|null $id2 Secondary ID
* @param string|null $id3 Arbitrary data
* @param \IPS\Member $member The member
* @param int|null $id1 Primary ID
* @param int|null $id2 Secondary ID
* @param string|null $id3 Arbitrary data
* @param array $attachment The attachment data
* @param bool $viewOnly If true, just check if the user can see the attachment rather than download it
* @return bool
*/
public function attachmentPermissionCheck( $member, $id1, $id2, $id3, $attachment )
public function attachmentPermissionCheck( $member, $id1, $id2, $id3, $attachment, $viewOnly=FALSE )
{
try
{
@@ -49,14 +49,15 @@ class _Store
/**
* Permission check for attachments
*
* @param \IPS\Member $member The member
* @param int|null $id1 Primary ID
* @param int|null $id2 Secondary ID
* @param string|null $id3 Arbitrary data
* @param \IPS\Member $member The member
* @param int|null $id1 Primary ID
* @param int|null $id2 Secondary ID
* @param string|null $id3 Arbitrary data
* @param array $attachment The attachment data
* @param bool $viewOnly If true, just check if the user can see the attachment rather than download it
* @return bool
*/
public function attachmentPermissionCheck( $member, $id1, $id2, $id3, $attachment )
public function attachmentPermissionCheck( $member, $id1, $id2, $id3, $attachment, $viewOnly=FALSE )
{
try
{
@@ -34,6 +34,16 @@ class _Support
return NULL;
}
/**
* Only allow local embeds?
*
* @return bool
*/
public function embedLocalOnly()
{
return TRUE;
}
/**
* Can we use attachments in this editor?
*
@@ -59,14 +69,15 @@ class _Support
/**
* Permission check for attachments
*
* @param \IPS\Member $member The member
* @param int|null $id1 Primary ID
* @param int|null $id2 Secondary ID
* @param string|null $id3 Arbitrary data
* @param \IPS\Member $member The member
* @param int|null $id1 Primary ID
* @param int|null $id2 Secondary ID
* @param string|null $id3 Arbitrary data
* @param array $attachment The attachment data
* @param bool $viewOnly If true, just check if the user can see the attachment rather than download it
* @return bool
*/
public function attachmentPermissionCheck( $member, $id1, $id2, $id3, $attachment )
public function attachmentPermissionCheck( $member, $id1, $id2, $id3, $attachment, $viewOnly=FALSE )
{
try
{
@@ -208,6 +208,16 @@ class _Support
}
catch ( \OutOfRangeException $e ) { }
}
foreach ( $email->cc as $to )
{
try
{
return \IPS\nexus\Support\Department::load( $to, 'dpt_email' );
}
catch ( \OutOfRangeException $e ) { }
}
return NULL;
}
@@ -336,6 +346,32 @@ class _Support
$request->title = $email->subject;
$request->member = (int) $member->member_id;
$request->email = $email->from;
/* Figure out who to notify for replies */
$notify = array();
foreach( $email->to as $to )
{
if ( $to !== $department->email )
{
$notify[] = array( 'type' => 'e', 'value' => $to );
}
}
foreach( $email->cc as $cc )
{
if ( $cc !== $department->email )
{
$notify[] = array( 'type' => 'e', 'value' => $cc );
}
}
foreach( ( $email->bcc ?: array() ) as $cc )
{
if ( $cc !== $department->email )
{
$notify[] = array( 'type' => 'e', 'value' => $cc, 'bcc' => 1 );
}
}
$request->notify = $notify;
$request->save();
/* Create the reply */
@@ -356,7 +392,7 @@ class _Support
$fromName = \IPS\Settings::i()->nexus_sout_from;
break;
}
$confirmationEmail->send( $member->member_id ? $member : $email->from, array(), array(), $request->department->email, $fromName );
$confirmationEmail->send( $member->member_id ? $member : $email->from, array(), array(), $request->department->email, $fromName, array( 'Message-Id' => "<IPS-0-SR{$request->id}.{$request->email_key}-{$request->department->email}>" ) );
}
/* Return */
@@ -426,7 +462,7 @@ class _Support
}
else
{
if ( preg_match( '/From:.+?(\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b)/i', $email->quote, $_matches ) )
if ( preg_match( '/From:.+?(\b[A-Z0-9._%+-\']+@[A-Z0-9.-]+\.[A-Z]{2,9}\b)/i', $email->quote, $_matches ) )
{
$originallyFrom = $_matches[1];
}
@@ -25,37 +25,13 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
*/
class _CustomerHistory
{
/**
* Find Records by IP
*
* @param string $ip The IP Address
* @param \IPS\Http\Url $baseUrl URL table will be displayed on or NULL to return a count
* @return \IPS\Helpers\Table|null
*/
public function findByIp( $ip, \IPS\Http\Url $baseUrl = NULL )
{
return NULL;
}
/**
* Find IPs by Member
* @deprecated
*
* @code
return array(
'::1' => array(
'ip' => '::1'// string (IP Address)
'count' => ... // int (number of times this member has used this IP)
'first' => ... // int (timestamp of first use)
'last' => ... // int (timestamp of most recent use)
),
...
);
* @endcode
* @param \IPS\Member $member The member
* @return array|NULL
*@return bool
*/
public function findByMember( $member )
final public function deprecated()
{
return NULL;
return TRUE;
}
}
@@ -69,75 +69,80 @@ class _AccountInformation extends \IPS\core\MemberACPProfile\TabbedBlock
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 )
$sparkline = NULL;
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'customer', 'customers_view_statistics' ) )
{
$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_method>0 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 )
{
$rows[ $date->format( 'n Y' ) ][ $currency ] = 0;
$sparkline->addHeader( $currency, 'number' );
}
$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
foreach ( $rows as $time => $row )
{
$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 );
$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, '.', '' );
foreach ( $row as $currency => $value )
{
$row[$currency] = number_format( $value, 2, '.', '' );
}
$sparkline->addRow( array_merge( array($datetime), $row ) );
}
$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,
)
),
) );
}
$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
{
@@ -170,7 +175,7 @@ class _AccountInformation extends \IPS\core\MemberACPProfile\TabbedBlock
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 )
foreach ( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_customer_cards', array( 'card_member=?', $this->member->member_id ), NULL, $edit ? NULL : 10 ), 'IPS\nexus\Customer\CreditCard' ) as $card )
{
try
{
@@ -233,7 +238,7 @@ class _AccountInformation extends \IPS\core\MemberACPProfile\TabbedBlock
{
$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 )
foreach ( \IPS\Db::i()->select( '*', 'nexus_billing_agreements', array( 'ba_member=? AND ba_canceled=0', $this->member->member_id ), NULL, $edit ? NULL : 10 ) as $billingAgreement )
{
$billingAgreements[ $billingAgreement['ba_id'] ] = array(
'id' => $billingAgreement['ba_id'],
@@ -412,7 +417,7 @@ class _AccountInformation extends \IPS\core\MemberACPProfile\TabbedBlock
}
else
{
$return[] = new \IPS\nexus\Money( 0, $this->member->defaultCurrency() );
$return[] = new \IPS\nexus\Money( 0, \IPS\nexus\Customer::load( $this->member )->defaultCurrency() );
}
return implode( '<br>', $return );
}
@@ -131,7 +131,7 @@ class _Notes extends \IPS\core\MemberACPProfile\Block
*
* @return string
*/
public function edit()
public function lazyOutput()
{
return \IPS\Theme::i()->getTemplate( 'customers', 'nexus' )->customerPopup( $this->notes );
}
@@ -30,7 +30,7 @@ class _Purchases extends \IPS\core\MemberACPProfile\Block
/**
* Get purchase table
*
* @return \IPS\IPS\Helpers\Tree
* @return \IPS\Helpers\Tree\Tree
*/
protected function purchases()
{
@@ -34,8 +34,8 @@ class _Statistics extends \IPS\core\MemberACPProfile\LazyLoadingBlock
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();
$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_method>0 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_method>0 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 ),
@@ -33,6 +33,16 @@ class _Main extends \IPS\core\MemberACPProfile\MainTab
$this->member = \IPS\nexus\Customer::load( $member->member_id );
}
/**
* Can view this Tab
*
* @return bool
*/
public function canView()
{
return (bool) \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'customers_view' );
}
/**
* Get left-column blocks
*
@@ -52,14 +62,36 @@ class _Main extends \IPS\core\MemberACPProfile\MainTab
*/
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',
);
$return = array();
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'customers_view_credit' ) )
{
$return[] = 'IPS\nexus\extensions\core\MemberACPProfileBlocks\Statistics';
}
$return[] = 'IPS\nexus\extensions\core\MemberACPProfileBlocks\ParentAccounts';
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'customer_notes_view' ) )
{
$return[] = 'IPS\nexus\extensions\core\MemberACPProfileBlocks\Notes';
}
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'purchases_view' ) )
{
$return[] = 'IPS\nexus\extensions\core\MemberACPProfileBlocks\Purchases';
}
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'invoices_manage' ) )
{
$return[] = 'IPS\nexus\extensions\core\MemberACPProfileBlocks\Invoices';
}
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'support', 'requests_manage' ) )
{
$return[] = 'IPS\nexus\extensions\core\MemberACPProfileBlocks\Support';
}
return $return;
}
/**
@@ -0,0 +1,83 @@
<?php
/**
* @brief ACP Export Personal Information
* @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 15 May 2018
*/
namespace IPS\nexus\extensions\core\MemberExportPersonalInformation;
/* 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 Export Personal Information
*/
class _Customer
{
/**
* Return data
* @param \IPS\Member $member The member
*
* @return array
*/
public function getData( \IPS\Member $member )
{
$return = array();
try
{
$customer = \IPS\nexus\Customer::load( $member->member_id );
/* Name and addresses */
$return['customer'] = array(
'first_name' => $customer->cm_first_name,
'last_name' => $customer->cm_last_name
);
foreach( \IPS\Db::i()->select( '*', 'nexus_customer_addresses', array( 'member=?', $member->member_id ) ) as $address )
{
$return['addresses'][] = \IPS\GeoLocation::buildFromJson( $address['address'] )->toString( "," );
}
/* Customer custom fields */
foreach ( \IPS\nexus\Customer\CustomField::roots() as $field )
{
$column = $field->column;
if ( $column )
{
$return['fields'][ $column ] = $field->displayValue( $customer->$column, TRUE );
}
}
/* Credit cards */
foreach ( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_customer_cards', array( 'card_member=?', $member->member_id ) ), 'IPS\nexus\Customer\CreditCard' ) as $card )
{
try
{
$cardData = $card->card;
$return['credit_cards'][ $card->id ] = array(
'card_type' => $cardData->type,
'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 ) {}
}
}
catch( \OutOfRangeException $ex )
{
}
return $return;
}
}
@@ -114,13 +114,13 @@ class _Purchases
* 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
* @return array|NULL Where clause - must be a single array( "clause", ...binds )
*/
public function getQueryWhereClause( $data )
{
if ( isset( $data['nexus_bm_filters_packages'] ) and $data['nexus_bm_filters_packages'] )
{
return 'nexus_purchases.ps_id IS NOT NULL';
return array( 'nexus_purchases.ps_id IS NOT NULL' );
}
return NULL;
}
@@ -112,13 +112,13 @@ class _Subscriptions
* 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
* @return array|NULL Where clause - must be a single array( "clause", ...binds )
*/
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 array( 'nexus_purchases.ps_id IS NOT NULL' );
}
return NULL;
}
@@ -24,26 +24,12 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
class _Nexus
{
/**
* Process Form
* @deprecated
*
* @param \IPS\Helpers\Form $form The form
* @param \IPS\Member $member Existing Member
* @return void
* @return bool
*/
public function process( &$form, $member )
{
}
/**
* Save
*
* @param array $values Values from form
* @param \IPS\Member $member The member
* @return void
*/
public function save( $values, &$member )
final public function deprecated()
{
return TRUE;
}
}
@@ -147,17 +147,31 @@ class _Nexus
{
return \IPS\Member::loggedIn()->language()->addToStack( 'history_transaction_paid', FALSE, array( 'htmlsprintf' => array( $transaction, $invoice, $byStaff, \IPS\Member::loggedIn()->language()->addToStack( 'history_transaction_status_' . $val['status'] ) ) ) );
}
case 'status':
if ( $val['status'] === \IPS\nexus\Transaction::STATUS_REFUNDED or $val['status'] === \IPS\nexus\Transaction::STATUS_PART_REFUNDED )
{
if ( $val['refund'] === 'gateway' )
{
$refundedTo = ( is_object( $transaction ) and $transaction->method ) ? $transaction->method->_title : \IPS\Member::loggedIn()->language()->addToStack('history_transaction_refunded_gateway');
if ( isset( $val['amount'] ) and $val['amount'] )
{
return \IPS\Member::loggedIn()->language()->addToStack( 'history_transaction_part_refunded', FALSE, array( 'htmlsprintf' => array( new \IPS\nexus\Money( $val['amount'], $val['currency'] ), $transaction, $byStaff ) ) );
}
else
{
return \IPS\Member::loggedIn()->language()->addToStack( 'history_transaction_refunded', FALSE, array( 'htmlsprintf' => array( $transaction, $byStaff ) ) );
}
}
else
{
$refundedTo = mb_strtolower( \IPS\Member::loggedIn()->language()->addToStack( 'refund_method_credit' ) );
if ( isset( $val['amount'] ) and $val['amount'] )
{
return \IPS\Member::loggedIn()->language()->addToStack( 'history_transaction_part_credited', FALSE, array( 'htmlsprintf' => array( new \IPS\nexus\Money( $val['amount'], $val['currency'] ), $transaction, $byStaff ) ) );
}
else
{
return \IPS\Member::loggedIn()->language()->addToStack( 'history_transaction_credited', FALSE, array( 'htmlsprintf' => array( $transaction, $byStaff ) ) );
}
}
if ( $val['status'] === \IPS\nexus\Transaction::STATUS_REFUNDED )
@@ -174,6 +188,9 @@ class _Nexus
return \IPS\Member::loggedIn()->language()->addToStack( 'history_transaction_status', FALSE, array( 'htmlsprintf' => array( $transaction, \IPS\Member::loggedIn()->language()->addToStack( 'history_transaction_status_' . $val['status'] ), $byStaff ) ) );
}
case 'undo_credit':
return \IPS\Member::loggedIn()->language()->addToStack( 'history_transaction_undo_credit', FALSE, array( 'htmlsprintf' => array( new \IPS\nexus\Money( $val['amount'], $val['currency'] ), $transaction, $byStaff ) ) );
case 'delete':
return \IPS\Member::loggedIn()->language()->addToStack( 'history_transaction_delete', FALSE, array( 'htmlsprintf' => array( $transaction, $byStaff ) ) );
}
@@ -378,8 +395,6 @@ class _Nexus
}
case 'giftvoucher':
$currency = isset( $val['currency'] ) ? $val['currency'] : \IPS\nexus\Customer::load( $val['by'] )->defaultCurrency();
switch ( $val['type'] )
{
case 'used':
@@ -393,6 +408,8 @@ class _Nexus
$customer = new \IPS\nexus\Customer;
}
$currency = isset( $val['currency'] ) ? $val['currency'] : $customer->defaultCurrency();
return
\IPS\Member::loggedIn()->language()->addToStack( 'history_giftvoucher_used', FALSE, array( 'htmlsprintf' => array(
new \IPS\nexus\Money( $val['amount'], $currency ),
@@ -412,6 +429,8 @@ class _Nexus
$customer = new \IPS\nexus\Customer;
}
$currency = isset( $val['currency'] ) ? $val['currency'] : $customer->defaultCurrency();
return
\IPS\Member::loggedIn()->language()->addToStack( 'history_giftvoucher_redeemed', FALSE, array( 'htmlsprintf' => array(
new \IPS\nexus\Money( $val['amount'], $currency ),
@@ -421,7 +440,6 @@ class _Nexus
) ) );
break;
}
break;
case 'info':
@@ -521,9 +539,16 @@ class _Nexus
break;
case 'alternative':
try
{
$altContact = \IPS\nexus\Customer::load( $val['alt_id'] );
}
catch( \OutOfRangeException $e )
{
$altContact = new \IPS\nexus\Customer;
}
$altContact = \IPS\nexus\Customer::load( $val['alt_id'] );
$altContact = $altContact->member_id ? $altContact->link() : $val['alt_name'];
$altContact = $altContact->member_id ? $altContact->link() : htmlspecialchars( $val['alt_name'], ENT_DISALLOWED, 'UTF-8', FALSE );
switch ( $val['type'] )
{
@@ -109,6 +109,8 @@ class _Nexus
\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 ) );
\IPS\Db::i()->update( 'nexus_support_ratings', array( 'rating_from' => $member->member_id ), array( 'rating_from=?', $member2->member_id ) );
\IPS\Db::i()->update( 'nexus_support_ratings', array( 'rating_staff' => $member->member_id ), array( 'rating_staff=?', $member2->member_id ) );
/* Account Credit */
$customerToKeep = \IPS\nexus\Customer::load( $member->member_id );
@@ -131,6 +133,15 @@ class _Nexus
}
$customerToKeep->cm_credits = $creditToKeep;
$customerToKeep->save();
/* Subscription packages */
if ( $keepSub = \IPS\nexus\Subscription::loadActiveByMember( $member ) )
{
if ( $dropSub = \IPS\nexus\Subscription::loadActiveByMember( $member2 ) )
{
$dropSub->removeMember( \IPS\nexus\Customer::load( $member2->member_id ) );
}
}
}
/**
@@ -165,6 +176,9 @@ class _Nexus
\IPS\Db::i()->update( 'nexus_purchases', array( 'ps_pay_to' => 0 ), array( 'ps_pay_to=?', $member->member_id ) );
\IPS\Db::i()->delete( 'nexus_support_streams', array( 'stream_owner=?', $member->member_id ) );
/* Subscriptions (mop up orphaned members) */
\IPS\Db::i()->delete( 'nexus_member_subscriptions', array( "sub_member_id=?", $member->member_id ) );
}
/**
@@ -0,0 +1,153 @@
<?php
/**
* @brief Background task to fix refunded transactions following the 4.3.5 change to treat refunds and credits separately
* @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 20 June 2018
*/
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 to fix refunded transactions following the 4.3.5 change to treat refunds and credits separately
*/
class _FixRefundTransactions
{
public $perCycle = 500;
/**
* Parse data before queuing
*
* @param array $data
* @return array
*/
public function preQueueData( $data )
{
$data['count'] = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_transactions', array( \IPS\Db::i()->in( 't_status', array( \IPS\nexus\Transaction::STATUS_REFUNDED, \IPS\nexus\Transaction::STATUS_PART_REFUNDED ) ) ) )->first();
if( $data['count'] == 0 )
{
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 )
{
$transactions = \IPS\Db::i()->select( '*', 'nexus_transactions', array( array( 't_id>?', $offset ), array( \IPS\Db::i()->in( 't_status', array( \IPS\nexus\Transaction::STATUS_REFUNDED, \IPS\nexus\Transaction::STATUS_PART_REFUNDED ) ) ) ), 't_id ASC', $this->perCycle );
$lastId = 0;
foreach( $transactions as $transaction )
{
$extra = json_decode( $transaction['t_extra'], TRUE );
if ( $extra and isset( $extra['history'] ) )
{
$credit = new \IPS\Math\Number('0');
$totalRefunded = new \IPS\Math\Number('0');
$update = array();
$updateHistory = FALSE;
foreach ( $extra['history'] as $i => $history )
{
if ( ( $history['s'] === 'rfnd' or $history['s'] === 'prfd' ) )
{
if ( $history['to'] === 'credit' )
{
if ( $history['s'] === 'rfnd' )
{
$updateHistory = TRUE;
$extra['history'][ $i ]['s'] = 'prfd';
}
if ( isset( $history['amount'] ) )
{
$credit = $credit->add( new \IPS\Math\Number( $history['amount'] ) );
}
else
{
$credit = $credit->add( new \IPS\Math\Number( $transaction['t_amount'] ) );
}
}
else
{
if ( isset( $history['amount'] ) )
{
$totalRefunded = $totalRefunded->add( new \IPS\Math\Number( $history['amount'] ) );
}
else
{
$totalRefunded = $totalRefunded->add( new \IPS\Math\Number( $transaction['t_amount'] ) );
}
}
}
}
if ( $updateHistory )
{
$update['t_extra'] = json_encode( $extra );
}
if ( $credit->isGreaterThanZero() )
{
$update['t_credit'] = (string) $credit;
}
if ( $transaction['t_status'] === \IPS\nexus\Transaction::STATUS_PART_REFUNDED and $totalRefunded->compare( new \IPS\Math\Number( $transaction['t_partial_refund'] ) ) !== 0 )
{
$update['t_partial_refund'] = (string) $totalRefunded;
}
if ( $transaction['t_status'] === \IPS\nexus\Transaction::STATUS_REFUNDED and $totalRefunded->compare( new \IPS\Math\Number( $transaction['t_amount'] ) ) !== 0 )
{
$update['t_status'] = \IPS\nexus\Transaction::STATUS_PART_REFUNDED;
}
if ( $update )
{
\IPS\Db::i()->update( 'nexus_transactions', $update, array( 't_id=?', $transaction['t_id'] ) );
}
}
$lastId = $transaction['t_id'];
}
if( $lastId == 0 )
{
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('upgrade_fix_refund_transactions'), 'complete' => $data['done'] ? ( round( 100 / $data['done'] * $data['count'], 2 ) ) : 0 );
}
}