Version 4.0.13.1
This commit is contained in:
1 parent
f9e857d255
commit
c6a86f0d9b
7517 files changed
+597400
-668041
No files matched your search
@@ -0,0 +1,192 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Customer Address Model
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage Nexus
|
||||
* @since 11 Feb 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\Customer;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Customer Address Model
|
||||
*/
|
||||
class _Address extends \IPS\Patterns\ActiveRecord
|
||||
{
|
||||
/**
|
||||
* @brief Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
|
||||
/**
|
||||
* @brief Database Table
|
||||
*/
|
||||
public static $databaseTable = 'nexus_customer_addresses';
|
||||
|
||||
/**
|
||||
* @brief State Codes
|
||||
* @see https://developer.paypal.com/docs/classic/api/state_codes/
|
||||
*/
|
||||
public static $stateCodes = array(
|
||||
'CA' => array(
|
||||
'AB' => "Alberta",
|
||||
'BC' => "British Columbia",
|
||||
'MB' => "Manitoba",
|
||||
'NB' => "New Brunswick",
|
||||
'NL' => "Newfoundland and Labrador",
|
||||
'NT' => "Northwest Territories",
|
||||
'NS' => "Nova Scotia",
|
||||
'NU' => "Nunavut",
|
||||
'ON' => "Ontario",
|
||||
'PE' => "Prince Edward Island",
|
||||
'QC' => "Quebec",
|
||||
'SK' => "Saskatchewan",
|
||||
'YT' => "Yukon",
|
||||
),
|
||||
'US' => array(
|
||||
'AL' => "Alabama",
|
||||
'AK' => "Alaska",
|
||||
'AS' => "American Samoa",
|
||||
'AZ' => "Arizona",
|
||||
'AR' => "Arkansas",
|
||||
'CA' => "California",
|
||||
'CO' => "Colorado",
|
||||
'CT' => "Connecticut",
|
||||
'DE' => "Delaware",
|
||||
'DC' => "District Of Columbia",
|
||||
'FL' => "Florida",
|
||||
'GA' => "Georgia",
|
||||
'GU' => "Guam",
|
||||
'HI' => "Hawaii",
|
||||
'ID' => "Idaho",
|
||||
'IL' => "Illinois",
|
||||
'IN' => "Indiana",
|
||||
'IA' => "Iowa",
|
||||
'KS' => "Kansas",
|
||||
'KY' => "Kentucky",
|
||||
'LA' => "Louisiana",
|
||||
'ME' => "Maine",
|
||||
'MD' => "Maryland",
|
||||
'MA' => "Massachusetts",
|
||||
'MI' => "Michigan",
|
||||
'MN' => "Minnesota",
|
||||
'MS' => "Mississippi",
|
||||
'MO' => "Missouri",
|
||||
'MT' => "Montana",
|
||||
'NE' => "Nebraska",
|
||||
'NV' => "Nevada",
|
||||
'NH' => "New Hampshire",
|
||||
'NJ' => "New Jersey",
|
||||
'NM' => "New Mexico",
|
||||
'NY' => "New York",
|
||||
'NC' => "North Carolina",
|
||||
'ND' => "North Dakota",
|
||||
'MP' => "Northern Mariana Islands",
|
||||
'OH' => "Ohio",
|
||||
'OK' => "Oklahoma",
|
||||
'OR' => "Oregon",
|
||||
'PA' => "Pennsylvania",
|
||||
'PR' => "Puerto Rico",
|
||||
'RI' => "Rhode Island",
|
||||
'SC' => "South Carolina",
|
||||
'SD' => "South Dakota",
|
||||
'TN' => "Tennessee",
|
||||
'TX' => "Texas",
|
||||
'UT' => "Utah",
|
||||
'VT' => "Vermont",
|
||||
'VI' => "Virgin Islands",
|
||||
'VA' => "Virginia",
|
||||
'WA' => "Washington",
|
||||
'WV' => "West Virginia",
|
||||
'WI' => "Wisconsin",
|
||||
'WY' => "Wyoming",
|
||||
'AA' => "Armed Forces - Americas",
|
||||
'AE' => "Armed Forces - Europe",
|
||||
'AP' => "Armed Forces - Pacific",
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Set Default Values
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setDefaultValues()
|
||||
{
|
||||
$this->added = new \IPS\DateTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get member
|
||||
*
|
||||
* @return \IPS\nexus\Customer
|
||||
*/
|
||||
public function get_member()
|
||||
{
|
||||
return \IPS\nexus\Customer::load( $this->_data['member'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set member
|
||||
*
|
||||
* @param \IPS\Member
|
||||
* @return void
|
||||
*/
|
||||
public function set_member( \IPS\Member $member )
|
||||
{
|
||||
$this->_data['member'] = $member->member_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get address
|
||||
*
|
||||
* @return \IPS\GeoLocation
|
||||
*/
|
||||
public function get_address()
|
||||
{
|
||||
return isset( $this->_data['address'] ) ? \IPS\GeoLocation::buildFromJson( $this->_data['address'] ) : new \IPS\GeoLocation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set member
|
||||
*
|
||||
* @param \IPS\Member
|
||||
* @return void
|
||||
*/
|
||||
public function set_address( \IPS\GeoLocation $address )
|
||||
{
|
||||
$this->_data['address'] = json_encode( $address );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get added date
|
||||
*
|
||||
* @return \IPS\DateTime
|
||||
*/
|
||||
public function get_added()
|
||||
{
|
||||
return \IPS\DateTime::ts( $this->_data['added'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set added date
|
||||
*
|
||||
* @param \IPS\DateTime $date The invoice date
|
||||
* @return void
|
||||
*/
|
||||
public function set_added( \IPS\DateTime $date )
|
||||
{
|
||||
$this->_data['added'] = $date->getTimestamp();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Alternative Contact Model
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage Nexus
|
||||
* @since 09 May 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\Customer;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alternative Contact Model
|
||||
*/
|
||||
class _AlternativeContact extends \IPS\Patterns\ActiveRecord
|
||||
{
|
||||
/**
|
||||
* @brief Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
|
||||
/**
|
||||
* @brief Database Table
|
||||
*/
|
||||
public static $databaseTable = 'nexus_alternate_contacts';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] ID Database Column
|
||||
*/
|
||||
public static $databaseColumnId = NULL;
|
||||
|
||||
/**
|
||||
* Get main account
|
||||
*
|
||||
* @return \IPS\nexus\Customer
|
||||
*/
|
||||
public function get_main_id()
|
||||
{
|
||||
return \IPS\nexus\Customer::load( $this->_data['main_id'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set main account
|
||||
*
|
||||
* @param \IPS\Member
|
||||
* @return void
|
||||
*/
|
||||
public function set_main_id( \IPS\Member $member )
|
||||
{
|
||||
$this->_data['main_id'] = $member->member_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get alternate account
|
||||
*
|
||||
* @return \IPS\nexus\Customer
|
||||
*/
|
||||
public function get_alt_id()
|
||||
{
|
||||
return \IPS\nexus\Customer::load( $this->_data['alt_id'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set alternate account
|
||||
*
|
||||
* @param \IPS\Member
|
||||
* @return void
|
||||
*/
|
||||
public function set_alt_id( \IPS\Member $member )
|
||||
{
|
||||
$this->_data['alt_id'] = $member->member_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get purchases
|
||||
*
|
||||
* @return \IPS\Patterns\ActiveRecordIterator
|
||||
*/
|
||||
public function get_purchases()
|
||||
{
|
||||
return new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_purchases', array( array( 'ps_member=?', $this->main_id->member_id ), \IPS\Db::i()->in( 'ps_id', $this->purchaseIds() ) ) ), 'IPS\nexus\Purchase' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get purchase IDs
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function purchaseIds()
|
||||
{
|
||||
return explode( ',', $this->_data['purchases'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set purchases
|
||||
*
|
||||
* @param array $purchases The purchases
|
||||
* @return void
|
||||
*/
|
||||
public function set_purchases( array $purchases )
|
||||
{
|
||||
$this->_data['purchases'] = implode( ',', array_keys( $purchases ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Save Changed Columns
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
if ( $this->_new )
|
||||
{
|
||||
$data = $this->_data;
|
||||
}
|
||||
else
|
||||
{
|
||||
$data = $this->changed;
|
||||
}
|
||||
|
||||
foreach ( array_keys( static::$bitOptions ) as $k )
|
||||
{
|
||||
if ( $this->$k instanceof Bitwise )
|
||||
{
|
||||
foreach( $this->$k->values as $field => $value )
|
||||
{
|
||||
$data[ $field ] = intval( $value );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( $this->_new )
|
||||
{
|
||||
$insert = array();
|
||||
if( static::$databasePrefix === NULL )
|
||||
{
|
||||
$insert = $data;
|
||||
}
|
||||
else
|
||||
{
|
||||
$insert = array();
|
||||
foreach ( $data as $k => $v )
|
||||
{
|
||||
$insert[ static::$databasePrefix . $k ] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
$insertId = static::db()->insert( static::$databaseTable, $insert );
|
||||
|
||||
$this->_new = FALSE;
|
||||
}
|
||||
elseif( !empty( $data ) )
|
||||
{
|
||||
/* Set the column names with a prefix */
|
||||
if( static::$databasePrefix === NULL )
|
||||
{
|
||||
$update = $data;
|
||||
}
|
||||
else
|
||||
{
|
||||
$update = array();
|
||||
foreach ( $data as $k => $v )
|
||||
{
|
||||
$update[ static::$databasePrefix . $k ] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
/* Work out the ID */
|
||||
$idColumn = static::$databaseColumnId;
|
||||
|
||||
/* Save */
|
||||
static::db()->update( static::$databaseTable, $update, array( 'main_id=? AND alt_id=?', $this->main_id->member_id, $this->alt_id->member_id ) );
|
||||
|
||||
/* Reset our log of what's changed */
|
||||
$this->changed = array();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [ActiveRecord] Delete Record
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
static::db()->delete( 'nexus_alternate_contacts', array( 'main_id=? AND alt_id=?', $this->_data['main_id'], $this->_data['alt_id'] ) );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,209 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Customer Stored Card Model
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage Nexus
|
||||
* @since 12 Mar 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\Customer;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Customer Stored Card Model
|
||||
*/
|
||||
class _CreditCard extends \IPS\Patterns\ActiveRecord
|
||||
{
|
||||
/**
|
||||
* @brief Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
|
||||
/**
|
||||
* @brief Database Table
|
||||
*/
|
||||
public static $databaseTable = 'nexus_customer_cards';
|
||||
|
||||
/**
|
||||
* @brief Database Prefix
|
||||
*/
|
||||
public static $databasePrefix = 'card_';
|
||||
|
||||
/**
|
||||
* Construct ActiveRecord from database row
|
||||
*
|
||||
* @param array $data Row from database table
|
||||
* @param bool $updateMultitonStoreIfExists Replace current object in multiton store if it already exists there?
|
||||
* @return static
|
||||
*/
|
||||
public static function constructFromData( $data, $updateMultitonStoreIfExists = TRUE )
|
||||
{
|
||||
$gateway = \IPS\nexus\Gateway::load( $data['card_method'] );
|
||||
$classname = 'IPS\nexus\Gateway\\' . $gateway->gateway . '\\CreditCard';
|
||||
|
||||
/* Initiate an object */
|
||||
$obj = new $classname;
|
||||
$obj->_new = FALSE;
|
||||
|
||||
/* Import data */
|
||||
foreach ( $data as $k => $v )
|
||||
{
|
||||
if( static::$databasePrefix AND mb_strpos( $k, static::$databasePrefix ) === 0 )
|
||||
{
|
||||
$k = \substr( $k, \strlen( static::$databasePrefix ) );
|
||||
}
|
||||
|
||||
$obj->_data[ $k ] = $v;
|
||||
}
|
||||
$obj->changed = array();
|
||||
|
||||
/* Init */
|
||||
if ( method_exists( $obj, 'init' ) )
|
||||
{
|
||||
$obj->init();
|
||||
}
|
||||
|
||||
/* Return */
|
||||
return $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Form
|
||||
*
|
||||
* @param \IPS\nexus\Customer $customer The customer
|
||||
* @return \IPS\Helpers\Form|\IPS\nexus\CreditCard
|
||||
*/
|
||||
public static function create( \IPS\nexus\Customer $customer )
|
||||
{
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$gateways = \IPS\nexus\Gateway::cardStorageGateways();
|
||||
|
||||
$elements = array();
|
||||
$paymentMethodsToggles = array();
|
||||
foreach ( $gateways as $gateway )
|
||||
{
|
||||
$invoice = new \IPS\nexus\Invoice;
|
||||
foreach ( $gateway->paymentScreen( $invoice, $invoice->total ) as $element )
|
||||
{
|
||||
if ( !$element->htmlId )
|
||||
{
|
||||
$element->htmlId = $gateway->id . '-' . $element->name;
|
||||
}
|
||||
if ( isset( $element->options['save'] ) )
|
||||
{
|
||||
$element->options['save'] = NULL;
|
||||
}
|
||||
$elements[] = $element;
|
||||
$paymentMethodsToggles[ $gateway->id ][] = $element->htmlId;
|
||||
}
|
||||
}
|
||||
|
||||
if ( count( $gateways ) > 1 )
|
||||
{
|
||||
$options = array();
|
||||
foreach ( $gateways as $gateway )
|
||||
{
|
||||
$options[ $gateway->id ] = $gateway->_title;
|
||||
}
|
||||
|
||||
$element = new \IPS\Helpers\Form\Radio( 'payment_method', NULL, TRUE, array( 'options' => $options, 'toggles' => $paymentMethodsToggles ) );
|
||||
$element->label = \IPS\Member::loggedIn()->language()->addToStack('card_gateway');
|
||||
$form->add( $element );
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach ( $gateways as $gateway )
|
||||
{
|
||||
$form->hiddenValues['payment_method'] = $gateway->id;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( $elements as $element )
|
||||
{
|
||||
$form->add( $element );
|
||||
}
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
if ( !$values[ \IPS\Request::i()->payment_method . '_card' ] )
|
||||
{
|
||||
$form->error = \IPS\Member::loggedIn()->language()->addToStack('card_number_invalid');
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
$gateway = \IPS\nexus\Gateway::load( \IPS\Request::i()->payment_method );
|
||||
$classname = 'IPS\nexus\Gateway\\' . $gateway->gateway . '\CreditCard';
|
||||
$card = new $classname;
|
||||
$card->member = $customer;
|
||||
$card->method = $gateway;
|
||||
$card->card = $values[ $gateway->id . '_card' ];
|
||||
$card->save();
|
||||
|
||||
$customer->log( 'card', array( 'type' => 'add', 'number' => $card->card->lastFour ) );
|
||||
|
||||
return $card;
|
||||
}
|
||||
catch ( \DomainException $e )
|
||||
{
|
||||
$form->error = $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get member
|
||||
*
|
||||
* @return \IPS\Member
|
||||
*/
|
||||
public function get_member()
|
||||
{
|
||||
return \IPS\nexus\Customer::load( $this->_data['member'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set member
|
||||
*
|
||||
* @param \IPS\Member
|
||||
* @return void
|
||||
*/
|
||||
public function set_member( \IPS\Member $member )
|
||||
{
|
||||
$this->_data['member'] = $member->member_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get payment gateway
|
||||
*
|
||||
* @return \IPS\nexus\Gateway
|
||||
*/
|
||||
public function get_method()
|
||||
{
|
||||
return \IPS\nexus\Gateway::load( $this->_data['method'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set payment gateway
|
||||
*
|
||||
* @param \IPS\nexus\Gateway
|
||||
* @return void
|
||||
*/
|
||||
public function set_method( \IPS\nexus\Gateway $gateway )
|
||||
{
|
||||
$this->_data['method'] = $gateway->id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Custom Customer Field Node
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @since 16 Apr 2013
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\Customer;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom Profile Field Node
|
||||
*/
|
||||
class _CustomField extends \IPS\CustomField
|
||||
{
|
||||
/**
|
||||
* @brief [ActiveRecord] Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Table
|
||||
*/
|
||||
public static $databaseTable = 'nexus_customer_fields';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Prefix
|
||||
*/
|
||||
public static $databasePrefix = 'f_';
|
||||
|
||||
/**
|
||||
* @brief [Node] Order Database Column
|
||||
*/
|
||||
public static $databaseColumnOrder = 'position';
|
||||
|
||||
/**
|
||||
* @brief [CustomField] Title/Description lang prefix
|
||||
*/
|
||||
protected static $langKey = 'nexus_ccfield';
|
||||
|
||||
/**
|
||||
* @brief [CustomField] Content database table
|
||||
*/
|
||||
protected static $contentDatabaseTable = 'nexus_customers';
|
||||
|
||||
/**
|
||||
* @brief [Node] ACP Restrictions
|
||||
* @code
|
||||
array(
|
||||
'app' => 'core', // The application key which holds the restrictrions
|
||||
'module' => 'foo', // The module key which holds the restrictions
|
||||
'map' => array( // [Optional] The key for each restriction - can alternatively use "prefix"
|
||||
'add' => 'foo_add',
|
||||
'edit' => 'foo_edit',
|
||||
'permissions' => 'foo_perms',
|
||||
'delete' => 'foo_delete'
|
||||
),
|
||||
'all' => 'foo_manage', // [Optional] The key to use for any restriction not provided in the map (only needed if not providing all 4)
|
||||
'prefix' => 'foo_', // [Optional] Rather than specifying each key in the map, you can specify a prefix, and it will automatically look for restrictions with the key "[prefix]_add/edit/permissions/delete"
|
||||
* @endcode
|
||||
*/
|
||||
protected static $restrictions = array(
|
||||
'app' => 'nexus',
|
||||
'module' => 'customers',
|
||||
'prefix' => 'customer_fields_'
|
||||
);
|
||||
|
||||
/**
|
||||
* @brief [Node] Node Title
|
||||
*/
|
||||
public static $nodeTitle = 'nexus_customer_fields';
|
||||
|
||||
/**
|
||||
* @brief [Node] Title prefix. If specified, will look for a language key with "{$key}_title" as the key
|
||||
*/
|
||||
public static $titleLangPrefix = 'nexus_ccfield_';
|
||||
|
||||
/**
|
||||
* @brief [CustomField] Column Map
|
||||
*/
|
||||
public static $databaseColumnMap = array(
|
||||
'content' => 'extra',
|
||||
'not_null' => 'required',
|
||||
);
|
||||
|
||||
/**
|
||||
* @brief [CustomField] Editor Options
|
||||
*/
|
||||
public static $editorOptions = array( 'app' => 'nexus', 'key' => 'Customer' );
|
||||
|
||||
/**
|
||||
* @brief [CustomField] Upload Storage Extension
|
||||
*/
|
||||
public static $uploadStorageExtension = 'nexus_';
|
||||
|
||||
/**
|
||||
* [Node] Add/Edit Form
|
||||
*
|
||||
* @param \IPS\Helpers\Form $form The form
|
||||
* @return void
|
||||
*/
|
||||
public function form( &$form )
|
||||
{
|
||||
parent::form( $form );
|
||||
$form->addHeader( 'customer_field_registration' );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'f_reg_show', $this->reg_show ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'f_reg_require', $this->reg_require ) );
|
||||
$form->addHeader( 'customer_field_purchase' );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'f_purchase_show', $this->purchase_show ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'f_purchase_require', $this->purchase_require ) );
|
||||
|
||||
unset( $form->elements[''][1] );
|
||||
unset( $form->elements['']['pf_not_null'] );
|
||||
unset( $form->elements['']['pf_max_input'] );
|
||||
unset( $form->elements['']['pf_input_format'] );
|
||||
unset( $form->elements[''][2] );
|
||||
unset( $form->elements['']['pf_search_type'] );
|
||||
unset( $form->elements['']['pf_format'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Perform actions after saving the form
|
||||
*
|
||||
* @param array $values Values from the form
|
||||
* @return void
|
||||
*/
|
||||
public function postSaveForm( $values )
|
||||
{
|
||||
if ( !$this->column )
|
||||
{
|
||||
$this->column = "field_{$this->id}";
|
||||
$this->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,504 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Customer Model
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage Nexus
|
||||
* @since 11 Feb 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Customer Model
|
||||
*/
|
||||
class _Customer extends \IPS\Member
|
||||
{
|
||||
/**
|
||||
* @brief Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
|
||||
/**
|
||||
* @brief Cached logged in member
|
||||
*/
|
||||
protected static $loggedInMember = NULL;
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] ID Database Column
|
||||
*/
|
||||
public static $databaseColumnId = 'member_id';
|
||||
|
||||
/**
|
||||
* Construct Load Query
|
||||
*
|
||||
* @param int|string $id ID
|
||||
* @param string $idField The database column that the $id parameter pertains to
|
||||
* @param mixed $extraWhereClause Additional where clause(s)
|
||||
* @return \IPS\Db\Select
|
||||
*/
|
||||
protected static function constructLoadQuery( $id, $idField, $extraWhereClause )
|
||||
{
|
||||
$where = array( array( 'core_members.' . $idField . '=?', $id ) );
|
||||
if( $extraWhereClause !== NULL )
|
||||
{
|
||||
if ( !is_array( $extraWhereClause ) or !is_array( $extraWhereClause[0] ) )
|
||||
{
|
||||
$extraWhereClause = array( $extraWhereClause );
|
||||
}
|
||||
$where = array_merge( $where, $extraWhereClause );
|
||||
}
|
||||
|
||||
return static::db()->select( '*, core_members.member_id AS _member_id', static::$databaseTable, $where )->join( 'nexus_customers', 'nexus_customers.member_id=core_members.member_id' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Record
|
||||
*
|
||||
* @see \IPS\Db::build
|
||||
* @param int|string $id ID
|
||||
* @param string $idField The database column that the $id parameter pertains to (NULL will use static::$databaseColumnId)
|
||||
* @param mixed $extraWhereClause Additional where clause(s) (see \IPS\Db::build for details)
|
||||
* @return static
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws \OutOfRangeException
|
||||
*/
|
||||
public static function load( $id, $idField=NULL, $extraWhereClause=NULL )
|
||||
{
|
||||
/* Guests */
|
||||
if( $id === NULL OR $id === 0 OR $id === '' )
|
||||
{
|
||||
$classname = get_called_class();
|
||||
return new $classname;
|
||||
}
|
||||
|
||||
/* If we didn't specify an ID field, assume the default */
|
||||
if( $idField === NULL )
|
||||
{
|
||||
$idField = static::$databasePrefix . static::$databaseColumnId;
|
||||
}
|
||||
|
||||
/* If we did, check it's valid */
|
||||
elseif( !in_array( $idField, static::$databaseIdFields ) )
|
||||
{
|
||||
throw new \InvalidArgumentException;
|
||||
}
|
||||
|
||||
/* Does that exist in the multiton store? */
|
||||
if( $idField === static::$databasePrefix . static::$databaseColumnId and !empty( static::$multitons[ $id ] ) )
|
||||
{
|
||||
return static::$multitons[ $id ];
|
||||
}
|
||||
|
||||
/* If not, find it */
|
||||
else
|
||||
{
|
||||
/* Load it */
|
||||
try
|
||||
{
|
||||
$row = static::constructLoadQuery( $id, $idField, $extraWhereClause )->first();
|
||||
}
|
||||
catch ( \UnderflowException $e )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
|
||||
/* If it doesn't exist in the multiton store, set it */
|
||||
if( !isset( static::$multitons[ $row[ static::$databasePrefix . static::$databaseColumnId ] ] ) )
|
||||
{
|
||||
static::$multitons[ $row['_member_id'] ] = static::constructFromData( $row );
|
||||
}
|
||||
|
||||
/* And return it */
|
||||
return static::$multitons[ $row['_member_id'] ];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct ActiveRecord from database row
|
||||
*
|
||||
* @param array $data Row from database table
|
||||
* @param bool $updateMultitonStoreIfExists Replace current object in multiton store if it already exists there?
|
||||
* @return static
|
||||
*/
|
||||
public static function constructFromData( $data, $updateMultitonStoreIfExists = TRUE )
|
||||
{
|
||||
if ( isset( $data['_member_id'] ) )
|
||||
{
|
||||
$data['member_id'] = $data['_member_id'];
|
||||
unset( $data['_member_id'] );
|
||||
}
|
||||
|
||||
/* If this was guest data there may be no member_id set, which will cause an undefined index */
|
||||
if( !isset( $data['member_id'] ) )
|
||||
{
|
||||
$data['member_id'] = 0;
|
||||
}
|
||||
|
||||
return parent::constructFromData( $data, $updateMultitonStoreIfExists );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Default Values
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setDefaultValues()
|
||||
{
|
||||
$this->_data['cm_first_name'] = '';
|
||||
$this->_data['cm_last_name'] = '';
|
||||
parent::setDefaultValues();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get customer name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_cm_name()
|
||||
{
|
||||
return ( $this->cm_first_name or $this->cm_last_name ) ? "{$this->cm_first_name} {$this->cm_last_name}" : $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get account credit
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_cm_credits()
|
||||
{
|
||||
$amounts = $this->member_id ? json_decode( $this->_data['cm_credits'], TRUE ) : array();
|
||||
$return = array();
|
||||
foreach ( \IPS\nexus\Money::currencies() as $currency )
|
||||
{
|
||||
if ( isset( $amounts[ $currency ] ) )
|
||||
{
|
||||
$return[ $currency ] = new \IPS\nexus\Money( $amounts[ $currency ], $currency );
|
||||
}
|
||||
else
|
||||
{
|
||||
$return[ $currency ] = new \IPS\nexus\Money( 0, $currency );
|
||||
}
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set account credit
|
||||
*
|
||||
* @param array $amounts Amounts
|
||||
* @return void
|
||||
*/
|
||||
public function set_cm_credits( $amounts )
|
||||
{
|
||||
$save = array();
|
||||
foreach ( $amounts as $amount )
|
||||
{
|
||||
$save[ $amount->currency ] = $amount->amount;
|
||||
}
|
||||
$this->_data['cm_credits'] = json_encode( $save );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get profiles
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_cm_profiles()
|
||||
{
|
||||
return $this->_data['cm_profiles'] ? json_decode( $this->_data['cm_profiles'], TRUE ) : array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set profiles
|
||||
*
|
||||
* @param array $profiles Profiles
|
||||
* @return array
|
||||
*/
|
||||
public function set_cm_profiles( $profiles )
|
||||
{
|
||||
$this->_data['cm_profiles'] = json_encode( $profiles );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default currency
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function defaultCurrency()
|
||||
{
|
||||
if ( $currencies = json_decode( \IPS\Settings::i()->nexus_currency, TRUE ) )
|
||||
{
|
||||
foreach ( $currencies as $k => $v )
|
||||
{
|
||||
if ( in_array( $this->language()->id, $v ) )
|
||||
{
|
||||
return $k;
|
||||
}
|
||||
}
|
||||
|
||||
$keys = array_keys( $currencies );
|
||||
return array_shift( $keys );
|
||||
}
|
||||
else
|
||||
{
|
||||
return \IPS\Settings::i()->nexus_currency;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Estimated location
|
||||
*
|
||||
* @return \IPS\GeoLocation|NULL
|
||||
*/
|
||||
public function estimatedLocation()
|
||||
{
|
||||
if ( $this->member_id === \IPS\nexus\Customer::loggedIn()->member_id )
|
||||
{
|
||||
if ( isset( $_SESSION['location'] ) )
|
||||
{
|
||||
$location = $_SESSION['location'] ? \IPS\GeoLocation::buildFromJson( $_SESSION['location'] ) : NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
$defaultAddress = \IPS\Db::i()->select( 'address', 'nexus_customer_addresses', array( 'member=? AND primary_billing=1', $this->member_id ) )->first();
|
||||
$_SESSION['location'] = $defaultAddress;
|
||||
$location = \IPS\GeoLocation::buildFromJson( $defaultAddress );
|
||||
}
|
||||
catch ( \UnderflowException $e )
|
||||
{
|
||||
try
|
||||
{
|
||||
$location = \IPS\GeoLocation::getByIp( \IPS\Request::i()->ipAddress() );
|
||||
$_SESSION['location'] = json_encode( $location );
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
{
|
||||
if( isset( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) )
|
||||
{
|
||||
$exploded = explode( '-', $_SERVER['HTTP_ACCEPT_LANGUAGE'] );
|
||||
|
||||
if ( in_array( mb_strtoupper( $exploded[1] ), \IPS\GeoLocation::$countries ) )
|
||||
{
|
||||
$location = new \IPS\GeoLocation;
|
||||
$location->country = mb_strtoupper( $exploded[1] );
|
||||
$_SESSION['location'] = json_encode( $location );
|
||||
}
|
||||
else
|
||||
{
|
||||
$location = NULL;
|
||||
$_SESSION['location'] = '';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$location = NULL;
|
||||
$_SESSION['location'] = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
$location = \IPS\GeoLocation::buildFromJson( \IPS\Db::i()->select( 'address', 'nexus_customer_addresses', array( 'member=? AND primary_billing=1', $this->member_id ) )->first() );
|
||||
}
|
||||
catch ( \UnderflowException $e )
|
||||
{
|
||||
$location = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return $location;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save Changed Columns
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
$data = $this->_data;
|
||||
|
||||
$customerTable = array();
|
||||
foreach ( ( $this->_new ? $this->_data : $this->changed ) as $k => $v )
|
||||
{
|
||||
if ( ( mb_substr( $k, 0, 3 ) === 'cm_' and !in_array( $k, array( 'cm_credits', 'cm_no_sev', 'cm_return_group', 'cm_reg' ) ) ) or mb_substr( $k, 0, 6 ) === 'field_' )
|
||||
{
|
||||
$customerTable[ $k ] = $v;
|
||||
unset( $this->_data[ $k ] );
|
||||
unset( $this->changed[ $k ] );
|
||||
}
|
||||
}
|
||||
|
||||
parent::save();
|
||||
$data['member_id'] = $this->_data['member_id'];
|
||||
$this->_data = $data;
|
||||
|
||||
if ( count( $customerTable ) )
|
||||
{
|
||||
$customerTable['member_id'] = $this->member_id;
|
||||
\IPS\Db::i()->insert( 'nexus_customers', $customerTable, TRUE );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log Action
|
||||
*
|
||||
* @param string $type Log type
|
||||
* @param mixed $extra Any extra data for the type
|
||||
* @param mixed $by The member performing the action. NULL for currently logged in member or FALSE for no member
|
||||
* @return void
|
||||
*/
|
||||
public function log( $type, $extra=NULL, $by=NULL )
|
||||
{
|
||||
if ( $this->member_id )
|
||||
{
|
||||
if ( $by === NULL )
|
||||
{
|
||||
$by = \IPS\Member::loggedIn();
|
||||
}
|
||||
|
||||
\IPS\Db::i()->insert( 'nexus_customer_history', array(
|
||||
'log_member' => (int) $this->member_id,
|
||||
'log_by' => $by ? $by->member_id : NULL,
|
||||
'log_type' => $type,
|
||||
'log_data' => json_encode( $extra ),
|
||||
'log_date' => microtime( TRUE ),
|
||||
'log_ip_address' => \IPS\Request::i()->ipAddress()
|
||||
) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get total amount spent
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function totalSpent()
|
||||
{
|
||||
$return = array();
|
||||
foreach ( \IPS\Db::i()->select( 't_currency, ( SUM(t_amount)-SUM(t_partial_refund) ) AS amount', 'nexus_transactions', array( 't_member=? AND ( t_status=? OR t_status=? )', $this->member_id, \IPS\nexus\Transaction::STATUS_PAID, \IPS\nexus\Transaction::STATUS_PART_REFUNDED ), NULL, NULL, 't_currency' ) as $amount )
|
||||
{
|
||||
$return[] = (string) new \IPS\nexus\Money( $amount['amount'], $amount['t_currency'] );
|
||||
}
|
||||
return count( $return ) ? implode( ' + ', $return ) : new \IPS\nexus\Money( 0, $this->defaultCurrency() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Number of previous purchases by package ID
|
||||
*/
|
||||
protected $previousPurchasesCount;
|
||||
|
||||
/**
|
||||
* Get number of previous purchases of a package ID (used to calculate loyalty discounts)
|
||||
*
|
||||
* @param int $packageID Package ID
|
||||
* @param bool $activeOnly Active only?
|
||||
* @return array
|
||||
*/
|
||||
public function previousPurchasesCount( $packageID, $activeOnly )
|
||||
{
|
||||
if ( $this->previousPurchasesCount === NULL )
|
||||
{
|
||||
$this->previousPurchasesCount['all'] = iterator_to_array( \IPS\Db::i()->select( 'ps_item_id, COUNT(*)', 'nexus_purchases', array( 'ps_app=? AND ps_type=? AND ps_member=?', 'nexus', 'package', $this->member_id ), NULL, NULL, 'ps_item_id' )->setKeyField('ps_item_id')->setValueField('COUNT(*)') );
|
||||
$this->previousPurchasesCount['active'] = iterator_to_array( \IPS\Db::i()->select( 'ps_item_id, COUNT(*)', 'nexus_purchases', array( 'ps_app=? AND ps_type=? AND ps_member=? AND ps_active=1', 'nexus', 'package', $this->member_id ), NULL, NULL, 'ps_item_id' )->setKeyField('ps_item_id')->setValueField('COUNT(*)') );
|
||||
}
|
||||
|
||||
return isset( $this->previousPurchasesCount[ $activeOnly ? 'active' : 'all' ][ $packageID ] ) ? $this->previousPurchasesCount[ $activeOnly ? 'active' : 'all' ][ $packageID ] : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Client Area Links
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function clientAreaLinks()
|
||||
{
|
||||
$return = array( 'invoices' );
|
||||
if ( \IPS\Db::i()->select( 'COUNT(*)', 'nexus_purchases', array( 'ps_member=? AND ps_show=1', $this->member_id ) ) )
|
||||
{
|
||||
$return[] = 'purchases';
|
||||
}
|
||||
|
||||
$return[] = 'addresses';
|
||||
if ( count( \IPS\nexus\Gateway::cardStorageGateways() ) )
|
||||
{
|
||||
$return[] = 'cards';
|
||||
}
|
||||
if ( count( \IPS\nexus\Customer\CustomField::roots() ) )
|
||||
{
|
||||
$return[] = 'info';
|
||||
}
|
||||
|
||||
if ( \IPS\Settings::i()->nexus_min_topup or count( json_decode( \IPS\Settings::i()->nexus_payout, TRUE ) ) )
|
||||
{
|
||||
$return[] = 'credit';
|
||||
}
|
||||
|
||||
$return[] = 'alternatives';
|
||||
|
||||
if ( count( \IPS\nexus\Donation\Goal::roots() ) )
|
||||
{
|
||||
$return[] = 'donations';
|
||||
}
|
||||
|
||||
if ( \IPS\Settings::i()->cm_ref_on )
|
||||
{
|
||||
$return[] = 'referrals';
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alternative Contacts
|
||||
*
|
||||
* @param array $where WHERE clause
|
||||
* @return \IPS\Patterns\ActiveRecordIterator
|
||||
*/
|
||||
public function alternativeContacts( $where = array() )
|
||||
{
|
||||
$where = count( $where ) ? array( $where ) : $where;
|
||||
$where[] = array( 'main_id=?', $this->member_id );
|
||||
return new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_alternate_contacts', $where )->setKeyField( 'alt_id' ), 'IPS\nexus\Customer\AlternativeContact' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Parent Contacts
|
||||
*
|
||||
* @param array $where WHERE clause
|
||||
* @return \IPS\Patterns\ActiveRecordIterator
|
||||
*/
|
||||
public function parentContacts( $where = array() )
|
||||
{
|
||||
$where = count( $where ) ? array( $where ) : $where;
|
||||
$where[] = array( 'alt_id=?', $this->member_id );
|
||||
return new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_alternate_contacts', $where )->setKeyField( 'main_id' ), 'IPS\nexus\Customer\AlternativeContact' );
|
||||
}
|
||||
|
||||
/**
|
||||
* ACP Customer Page URL
|
||||
*
|
||||
* @return \IPS\Http\Url
|
||||
*/
|
||||
public function acpUrl()
|
||||
{
|
||||
return \IPS\Http\Url::internal("app=nexus&module=customers&controller=view&id={$this->member_id}");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,574 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Customer History Table
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage Nexus
|
||||
* @since 18 Sep 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\Customer;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Customer Model
|
||||
*/
|
||||
class _History extends \IPS\Helpers\Table\Db
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \IPS\Http\Url $url The URL the table will be displayed on
|
||||
* @param mixed $where WHERE clause
|
||||
* @param bool $showIp If the IP address column should be included
|
||||
* @param bool $showCustomer If the customer column should show
|
||||
* @return void
|
||||
*/
|
||||
public function __construct( \IPS\Http\Url $url, $where, $showIp=TRUE, $showCustomer=FALSE )
|
||||
{
|
||||
parent::__construct( 'nexus_customer_history', $url, $where );
|
||||
|
||||
$this->tableTemplate = array( \IPS\Theme::i()->getTemplate( 'customers', 'nexus' ), 'historyTable' );
|
||||
$this->rowsTemplate = array( \IPS\Theme::i()->getTemplate( 'customers', 'nexus' ), 'historyRows' );
|
||||
|
||||
$this->include = array( 'log_type', 'log_date', 'log_data' );
|
||||
if ( $showIp )
|
||||
{
|
||||
$this->include[] = 'log_ip_address';
|
||||
}
|
||||
if ( $showCustomer )
|
||||
{
|
||||
$this->include[] = 'log_member';
|
||||
}
|
||||
|
||||
$this->sortBy = $this->sortBy ?: 'log_date';
|
||||
$this->noSort = array( 'log_type', 'log_ip_address', 'log_data' );
|
||||
$this->parsers = array(
|
||||
'log_type' => function( $val )
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate('customers', 'nexus')->logType( $val );
|
||||
},
|
||||
'log_date' => function( $val )
|
||||
{
|
||||
return \IPS\DateTime::ts( $val );
|
||||
},
|
||||
'log_ip_address' => function( $val )
|
||||
{
|
||||
return "<a href='" . \IPS\Http\Url::internal( "app=core&module=members&controller=ip&ip={$val}" ) . "'>{$val}</a>";
|
||||
},
|
||||
'log_member'=> function( $val )
|
||||
{
|
||||
return \IPS\nexus\Customer::load( $val )->link();
|
||||
},
|
||||
'log_data' => function( $val, $row )
|
||||
{
|
||||
$val = json_decode( $val, TRUE );
|
||||
|
||||
$byCustomer = '';
|
||||
$byStaff = '';
|
||||
if ( $row['log_by'] )
|
||||
{
|
||||
if ( $row['log_by'] === $row['log_member'] )
|
||||
{
|
||||
$byCustomer = \IPS\Member::loggedIn()->language()->addToStack('history_by_customer');
|
||||
}
|
||||
|
||||
$byStaff = \IPS\Member::loggedIn()->language()->addToStack('history_by_staff', FALSE, array( 'sprintf' => array( \IPS\Member::load( $row['log_by'] )->name ) ) );
|
||||
}
|
||||
|
||||
switch ( $row['log_type'] )
|
||||
{
|
||||
case 'invoice':
|
||||
try
|
||||
{
|
||||
$invoice = \IPS\Theme::i()->getTemplate('invoices', 'nexus')->link( \IPS\nexus\Invoice::load( $val['id'] ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
$invoice = $val['title'];
|
||||
}
|
||||
|
||||
if ( isset( $val['type'] ) )
|
||||
{
|
||||
switch ( $val['type'] )
|
||||
{
|
||||
case 'status':
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'history_invoice_status', FALSE, array( 'htmlsprintf' => array( $invoice, mb_strtolower( \IPS\Member::loggedIn()->language()->addToStack( 'istatus_' . $val['new'] ) ), $byStaff ) ) );
|
||||
|
||||
case 'resend':
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'history_invoice_resend', FALSE, array( 'htmlsprintf' => array( $invoice, $byStaff, isset( $val['email'] ) ? \IPS\Member::loggedIn()->language()->addToStack( $val['email'] ? 'history_invoice_resend_email' : 'history_invoice_resend_no_email' ) : '' ) ) );
|
||||
|
||||
case 'delete':
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'history_invoice_delete', FALSE, array( 'htmlsprintf' => array( $invoice, $byStaff ) ) );
|
||||
|
||||
case 'expire':
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'history_invoice_expired', FALSE, array( 'htmlsprintf' => array( $invoice ) ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( isset( $val['system'] ) and $val['system'] )
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'history_invoice_generated', FALSE, array( 'htmlsprintf' => array( $invoice, '' ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'history_invoice_generated', FALSE, array( 'htmlsprintf' => array( $invoice, $byCustomer ?: $byStaff ) ) );
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'transaction':
|
||||
try
|
||||
{
|
||||
$transaction = \IPS\Theme::i()->getTemplate('transactions', 'nexus')->link( \IPS\nexus\Transaction::load( $val['id'] ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
$transaction = \IPS\Member::loggedIn()->language()->addToStack( 'transaction_number', FALSE, array( 'htmlsprintf' => array( $val['id'] ) ) );
|
||||
}
|
||||
|
||||
switch ( $val['type'] )
|
||||
{
|
||||
case 'paid':
|
||||
|
||||
try
|
||||
{
|
||||
$invoice = \IPS\Theme::i()->getTemplate('invoices', 'nexus')->link( \IPS\nexus\Invoice::load( $val['invoice_id'] ), TRUE );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
$invoice = \IPS\Member::loggedIn()->language()->addToStack( 'invoice_number', FALSE, array( 'sprintf' => array( $val['id'] ) ) );
|
||||
}
|
||||
|
||||
if ( isset( $val['automatic'] ) and $val['automatic'] )
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'history_transaction_auto', FALSE, array( 'htmlsprintf' => array( $transaction, $invoice, \IPS\Member::loggedIn()->language()->addToStack( 'history_transaction_status_' . $val['status'] ) ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
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');
|
||||
}
|
||||
else
|
||||
{
|
||||
$refundedTo = mb_strtolower( \IPS\Member::loggedIn()->language()->addToStack( 'refund_method_credit' ) );
|
||||
}
|
||||
|
||||
if ( $val['status'] === \IPS\nexus\Transaction::STATUS_REFUNDED )
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'history_transaction_refunded', FALSE, array( 'htmlsprintf' => array( $transaction, $refundedTo, $byStaff ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'history_transaction_part_refunded', FALSE, array( 'htmlsprintf' => array( new \IPS\nexus\Money( $val['amount'], $val['currency'] ), $transaction, $refundedTo, $byStaff ) ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
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 'delete':
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'history_transaction_delete', FALSE, array( 'htmlsprintf' => array( $transaction, $byStaff ) ) );
|
||||
}
|
||||
break;
|
||||
|
||||
case 'shipping':
|
||||
try
|
||||
{
|
||||
$shipment = \IPS\Theme::i()->getTemplate('shiporders', 'nexus')->link( \IPS\nexus\Shipping\Order::load( $val['id'] ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
$shipment = \IPS\Member::loggedIn()->language()->addToStack( 'shipment_number', FALSE, array( 'sprintf' => array( $val['id'] ) ) );
|
||||
}
|
||||
|
||||
if ( isset( $val['type'] ) )
|
||||
{
|
||||
if ( $val['type'] === 'new' )
|
||||
{
|
||||
try
|
||||
{
|
||||
$invoice = \IPS\Theme::i()->getTemplate('invoices', 'nexus')->link( \IPS\nexus\Invoice::load( $val['invoice_id'] ), TRUE );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
$invoice = \IPS\Member::loggedIn()->language()->addToStack('invoice_number', FALSE, array( 'sprintf' => array( $val['id'] ) ) );
|
||||
}
|
||||
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'history_shipping_new', FALSE, array( 'htmlsprintf' => array( $shipment, $invoice ) ) );
|
||||
}
|
||||
elseif ( $val['type'] === 'canc' )
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'history_shipping_canc', FALSE, array( 'htmlsprintf' => array( $shipment, $byStaff ) ) );
|
||||
}
|
||||
}
|
||||
elseif ( isset( $val['deleted'] ) and $val['deleted'] )
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'history_shipping_deleted', FALSE, array( 'htmlsprintf' => array( $shipment, $byStaff ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'history_shipping_ship', FALSE, array( 'htmlsprintf' => array( $shipment, $byStaff ) ) );
|
||||
}
|
||||
break;
|
||||
|
||||
case 'purchase':
|
||||
try
|
||||
{
|
||||
$purchase = \IPS\Theme::i()->getTemplate('purchases', 'nexus')->link( \IPS\nexus\Purchase::load( $val['id'] ), $val['type'] === 'change' );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
$purchase = $val['name'];
|
||||
}
|
||||
|
||||
switch ( $val['type'] )
|
||||
{
|
||||
case 'new':
|
||||
case 'renew':
|
||||
try
|
||||
{
|
||||
$invoice = \IPS\Theme::i()->getTemplate('invoices', 'nexus')->link( \IPS\nexus\Invoice::load( $val['invoice_id'] ), TRUE );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
$invoice = \IPS\Member::loggedIn()->language()->addToStack('invoice_number', FALSE, array( 'sprintf' => array( $val['invoice_id'] ) ) );
|
||||
}
|
||||
|
||||
if ( $val['type'] === 'new' )
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'history_purchase_created', FALSE, array( 'htmlsprintf' => array( $purchase, $invoice ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'history_purchase_renewed', FALSE, array( 'htmlsprintf' => array( $purchase, $invoice ) ) );
|
||||
}
|
||||
break;
|
||||
|
||||
case 'info':
|
||||
if ( isset( $val['info'] ) )
|
||||
{
|
||||
switch ( $val['info'] )
|
||||
{
|
||||
case 'change_renewals':
|
||||
/* A bug in an older version logged this wrong... */
|
||||
if ( !isset( $val['to']['currency'] ) )
|
||||
{
|
||||
foreach ( $val['to']['cost'] as $currency => $amount )
|
||||
{
|
||||
$to = new \IPS\nexus\Purchase\RenewalTerm( new \IPS\nexus\Money( $amount['amount'], $currency ), new \DateInterval( 'P' . $val['to']['term'] . mb_strtoupper( $val['to']['unit'] ) ) );
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* This is the correct way */
|
||||
else
|
||||
{
|
||||
$to = new \IPS\nexus\Purchase\RenewalTerm( new \IPS\nexus\Money( $val['to']['cost'], $val['to']['currency'] ), new \DateInterval( 'P' . $val['to']['term']['term'] . mb_strtoupper( $val['to']['term']['unit'] ) ) );
|
||||
}
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'history_purchase_renewals_changed', FALSE, array( 'htmlsprintf' => array( $purchase, ( isset( $val['system'] ) and $val['system'] ) ? '' : $byStaff, $to ) ) );
|
||||
|
||||
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 ) ) );
|
||||
}
|
||||
}
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'history_purchase_edited', FALSE, array( 'htmlsprintf' => array( $purchase, ( isset( $val['system'] ) and $val['system'] ) ? '' : $byStaff ) ) );
|
||||
|
||||
case 'transfer_from':
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'history_purchase_transfer_from', FALSE, array( 'htmlsprintf' => array( $purchase, \IPS\Theme::i()->getTemplate('global', 'nexus')->userLink( \IPS\nexus\Customer::load( $val['to'] ) ), $byStaff ) ) );
|
||||
case 'transfer_to':
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'history_purchase_transfer_to', FALSE, array( 'htmlsprintf' => array( $purchase, \IPS\Theme::i()->getTemplate('global', 'nexus')->userLink( \IPS\nexus\Customer::load( $val['from'] ) ), $byStaff ) ) );
|
||||
|
||||
case 'cancel':
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'history_purchase_canceled', FALSE, array( 'htmlsprintf' => array( $purchase, $byStaff ) ) );
|
||||
case 'uncancel':
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'history_purchase_reactivated', FALSE, array( 'htmlsprintf' => array( $purchase, $byStaff ) ) );
|
||||
|
||||
case 'delete':
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'history_purchase_deleted', FALSE, array( 'htmlsprintf' => array( $purchase, $byStaff ) ) );
|
||||
|
||||
case 'expire':
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'history_purchase_expired', FALSE, array( 'htmlsprintf' => array( $purchase ) ) );
|
||||
|
||||
case 'change':
|
||||
$by = ( isset( $val['system'] ) and $val['system'] ) ? '' : $byCustomer;
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'history_purchase_changed', FALSE, array( 'htmlsprintf' => array( $purchase, $val['old'], $val['name'], $by ) ) );
|
||||
|
||||
case 'group':
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'history_purchase_grouped', FALSE, array( 'htmlsprintf' => array( $purchase, $byStaff ) ) );
|
||||
case 'ungroup':
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'history_purchase_ungrouped', FALSE, array( 'htmlsprintf' => array( $purchase, $byStaff ) ) );
|
||||
}
|
||||
break;
|
||||
|
||||
case 'comission':
|
||||
|
||||
switch ( $val['type'] )
|
||||
{
|
||||
case 'purchase':
|
||||
case 'purchase_refund':
|
||||
try
|
||||
{
|
||||
$purchase = \IPS\Theme::i()->getTemplate('purchases', 'nexus')->link( \IPS\nexus\Purchase::load( $val['id'] ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
$purchase = $val['name'];
|
||||
}
|
||||
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( "history_commission_{$val['type']}", FALSE, array( 'htmlsprintf' => array( new \IPS\nexus\Money( $val['amount'], $val['currency'] ), $purchase ) ) );
|
||||
|
||||
case 'invoice':
|
||||
try
|
||||
{
|
||||
$invoice = \IPS\Theme::i()->getTemplate('invoices', 'nexus')->link( \IPS\nexus\Invoice::load( $val['invoice_id'] ), TRUE );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
$invoice = \IPS\Member::loggedIn()->language()->addToStack('invoice_number', FALSE, array( 'sprintf' => array( $val['invoice_id'] ) ) );
|
||||
}
|
||||
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'history_commission_invoice', FALSE, array( 'htmlsprintf' => array( new \IPS\nexus\Money( $val['amount'], $val['currency'] ), $invoice ) ) );
|
||||
|
||||
case 'bought':
|
||||
try
|
||||
{
|
||||
$invoice = \IPS\Theme::i()->getTemplate('invoices', 'nexus')->link( \IPS\nexus\Invoice::load( $val['invoice_id'] ), TRUE );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
$invoice = \IPS\Member::loggedIn()->language()->addToStack( 'invoice_number', FALSE, array( 'sprintf' => array( $val['invoice_id'] ) ) );
|
||||
}
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'history_commission_bought', FALSE, array( 'htmlsprintf' => array( new \IPS\nexus\Money( $val['new_amount'], $val['currency'] ), $invoice, new \IPS\nexus\Money( $val['amount'], $val['currency'] ) ) ) );
|
||||
|
||||
case 'manual':
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'history_commission_manual', FALSE, array( 'sprintf' => array( $byStaff, new \IPS\nexus\Money( $val['new'], $val['currency'] ), new \IPS\nexus\Money( $val['old'], $val['currency'] ) ) ) );
|
||||
}
|
||||
|
||||
case 'giftvoucher':
|
||||
|
||||
$currency = isset( $val['currency'] ) ? $val['currency'] : \IPS\nexus\Customer::load( $val['by'] )->defaultCurrency();
|
||||
switch ( $val['type'] )
|
||||
{
|
||||
case 'used':
|
||||
return
|
||||
\IPS\Member::loggedIn()->language()->addToStack( 'history_giftvoucher_used', FALSE, array( 'htmlsprintf' => array(
|
||||
new \IPS\nexus\Money( $val['amount'], $currency ),
|
||||
$val['code'],
|
||||
\IPS\Theme::i()->getTemplate('global', 'nexus')->userLink( \IPS\nexus\Customer::load( $val['by'] ) )
|
||||
) ) );
|
||||
break;
|
||||
|
||||
case 'redeemed':
|
||||
return
|
||||
\IPS\Member::loggedIn()->language()->addToStack( 'history_giftvoucher_redeemed', FALSE, array( 'htmlsprintf' => array(
|
||||
new \IPS\nexus\Money( $val['amount'], $currency ),
|
||||
$val['code'],
|
||||
\IPS\Theme::i()->getTemplate('global', 'nexus')->userLink( \IPS\nexus\Customer::load( $val['ps_member'] ) ),
|
||||
new \IPS\nexus\Money( $val['newCreditAmount'], $currency )
|
||||
) ) );
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'info':
|
||||
$changes = array( \IPS\Member::loggedIn()->language()->addToStack('history_info_change', FALSE, array( 'sprintf' => array( $byCustomer ?: $byStaff ) ) ) );
|
||||
|
||||
if ( isset( $val['name'] ) )
|
||||
{
|
||||
$name = is_array( $val['name'] ) ? implode( ' ', array_values( $val['name'] ) ) : $val['name'];
|
||||
$changes[] = \IPS\Member::loggedIn()->language()->addToStack('history_name_changed_from', FALSE, array( 'sprintf' => array( $name ) ) );
|
||||
}
|
||||
|
||||
if ( isset( $val['email'] ) )
|
||||
{
|
||||
$changes[] = \IPS\Member::loggedIn()->language()->addToStack('history_email_changed_from', FALSE, array( 'sprintf' => array( $val['email'] ) ) );
|
||||
}
|
||||
|
||||
if ( isset( $val['password'] ) )
|
||||
{
|
||||
$changes[] = \IPS\Member::loggedIn()->language()->addToStack('history_password_changed');
|
||||
}
|
||||
|
||||
if ( isset( $val['other'] ) )
|
||||
{
|
||||
foreach ( $val['other'] as $change )
|
||||
{
|
||||
if ( isset( $change['old'] ) )
|
||||
{
|
||||
$changes[] = \IPS\Member::loggedIn()->language()->addToStack('history_field_changed_from', FALSE, array( 'sprintf' => array( \IPS\Member::loggedIn()->language()->addToStack( $change['name'] ), $change['old'], $change['value'] ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
$changes[] = \IPS\Member::loggedIn()->language()->addToStack('history_field_changed', FALSE, array( 'sprintf' => array( \IPS\Member::loggedIn()->language()->addToStack( $change['name'] ), $change['value'] ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return implode( '<br>', $changes );
|
||||
|
||||
case 'address':
|
||||
switch ( $val['type'] )
|
||||
{
|
||||
case 'add':
|
||||
return \IPS\Member::loggedIn()->language()->addToStack('history_address_add', FALSE, array( 'sprintf' => array( (string) \IPS\GeoLocation::buildFromJson( $val['details'] ), $byCustomer ) ) );
|
||||
case 'edit':
|
||||
return \IPS\Member::loggedIn()->language()->addToStack('history_address_edit', FALSE, array( 'sprintf' => array( (string) \IPS\GeoLocation::buildFromJson( $val['old'] ), (string) \IPS\GeoLocation::buildFromJson( $val['new'] ), $byCustomer ) ) );
|
||||
case 'primary_billing':
|
||||
return \IPS\Member::loggedIn()->language()->addToStack('history_address_primary_billing', FALSE, array( 'sprintf' => array( (string) \IPS\GeoLocation::buildFromJson( $val['details'] ), $byCustomer ) ) );
|
||||
case 'primary_shipping':
|
||||
return \IPS\Member::loggedIn()->language()->addToStack('history_address_primary_shipping', FALSE, array( 'sprintf' => array( (string) \IPS\GeoLocation::buildFromJson( $val['details'] ), $byCustomer ) ) );
|
||||
case 'delete':
|
||||
return \IPS\Member::loggedIn()->language()->addToStack('history_address_delete', FALSE, array( 'sprintf' => array( (string) \IPS\GeoLocation::buildFromJson( $val['details'] ), $byCustomer ) ) );
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case 'card':
|
||||
switch ( $val['type'] )
|
||||
{
|
||||
case 'add':
|
||||
return \IPS\Member::loggedIn()->language()->addToStack('history_card_add', FALSE, array( 'sprintf' => array( $val['number'], $byCustomer ) ) );
|
||||
case 'delete':
|
||||
return \IPS\Member::loggedIn()->language()->addToStack('history_card_delete', FALSE, array( 'sprintf' => array( $val['number'], $byCustomer ) ) );
|
||||
}
|
||||
break;
|
||||
|
||||
case 'alternative':
|
||||
|
||||
$altContact = \IPS\nexus\Customer::load( $val['alt_id'] );
|
||||
$altContact = $altContact->member_id ? $altContact->link() : $val['alt_name'];
|
||||
|
||||
switch ( $val['type'] )
|
||||
{
|
||||
case 'add':
|
||||
return \IPS\Member::loggedIn()->language()->addToStack('history_altcontact_add', FALSE, array( 'htmlsprintf' => array( $altContact, $byCustomer ) ) );
|
||||
case 'edit':
|
||||
return \IPS\Member::loggedIn()->language()->addToStack('history_altcontact_edit', FALSE, array( 'htmlsprintf' => array( $altContact, $byCustomer ) ) );
|
||||
case 'delete':
|
||||
return \IPS\Member::loggedIn()->language()->addToStack('history_altcontact_delete', FALSE, array( 'htmlsprintf' => array( $altContact, $byCustomer ) ) );
|
||||
}
|
||||
break;
|
||||
|
||||
case 'payout':
|
||||
|
||||
try
|
||||
{
|
||||
if ( !isset( $val['payout_id'] ) )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
$payout = \IPS\Theme::i()->getTemplate('payouts', 'nexus')->link( \IPS\nexus\Payout::load( $val['payout_id'] ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
if ( isset( $va['currency'] ) )
|
||||
{
|
||||
$payout = new \IPS\nexus\Money( $val['amount'], $val['currency'] );
|
||||
}
|
||||
else
|
||||
{
|
||||
$payout = $val['amount'];
|
||||
}
|
||||
}
|
||||
|
||||
switch ( $val['type'] )
|
||||
{
|
||||
case 'autoprocess':
|
||||
return \IPS\Member::loggedIn()->language()->addToStack('history_payout_autoprocess', FALSE, array( 'htmlsprintf' => array( $payout ) ) );
|
||||
case 'request':
|
||||
return \IPS\Member::loggedIn()->language()->addToStack('history_payout_request', FALSE, array( 'htmlsprintf' => array( $payout ) ) );
|
||||
case 'cancel':
|
||||
return \IPS\Member::loggedIn()->language()->addToStack('history_payout_cancel', FALSE, array( 'htmlsprintf' => array( $payout, $byCustomer ?: $byStaff ) ) );
|
||||
case 'processed':
|
||||
return \IPS\Member::loggedIn()->language()->addToStack('history_payout_processed', FALSE, array( 'htmlsprintf' => array( $payout, $byStaff ) ) );
|
||||
case 'dismissed':
|
||||
return \IPS\Member::loggedIn()->language()->addToStack('history_payout_dismissed', FALSE, array( 'htmlsprintf' => array( $payout, $byStaff ) ) );
|
||||
}
|
||||
break;
|
||||
|
||||
case 'lkey':
|
||||
|
||||
try
|
||||
{
|
||||
$purchase = \IPS\Theme::i()->getTemplate('purchases', 'nexus')->link( \IPS\nexus\Purchase::load( $val['ps_id'] ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
if ( isset( $val['ps_name'] ) )
|
||||
{
|
||||
$purchase = $val['ps_name'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$purchase = \IPS\Member::loggedIn()->language()->addToStack( 'purchase_number', FALSE, array( 'sprintf' => array( $val['ps_id'] ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
switch ( $val['type'] )
|
||||
{
|
||||
case 'activated':
|
||||
return \IPS\Member::loggedIn()->language()->addToStack('history_lkey_activated', FALSE, array( 'htmlsprintf' => array( $purchase ) ) );
|
||||
case 'reset':
|
||||
return \IPS\Member::loggedIn()->language()->addToStack('history_lkey_reset', FALSE, array( 'htmlsprintf' => array( $purchase, $byStaff, $val['new'], $val['key'] ) ) );
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'download':
|
||||
switch ( $val['type'] )
|
||||
{
|
||||
case 'idm':
|
||||
try
|
||||
{
|
||||
$options = array( 'htmlsprintf' => array( \IPS\Theme::i()->getTemplate( 'customers', 'nexus' )->downloadsLink( \IPS\downloads\File::load( $val['id'] ) ) ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
$options = array( 'sprintf' => array( $val['name'] ) );
|
||||
}
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'history_download', FALSE, $options );
|
||||
case 'attach':
|
||||
|
||||
$file = \IPS\Theme::i()->getTemplate( 'editor', 'core', 'global' )->attachedFile( \IPS\Settings::i()->base_url . "applications/core/interface/file/attachment.php?id=" . $val['id'], $val['name'], FALSE );
|
||||
if ( isset( $val['ps_id'] ) and $val['ps_id'] )
|
||||
{
|
||||
try
|
||||
{
|
||||
$options = array( 'htmlsprintf' => array( $file, \IPS\Theme::i()->getTemplate('purchases', 'nexus')->link( \IPS\nexus\Purchase::load( $val['ps_id'] ) ) ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
$options = array( 'htmlsprintf' => array( $file, htmlentities( $val['ps_name'], ENT_QUOTES | \IPS\HTMLENTITIES, 'UTF-8', FALSE ) ) );
|
||||
}
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'history_download_with_purchase', FALSE, $options );
|
||||
}
|
||||
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'history_download', FALSE, array( 'htmlsprintf' => $file ) );
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
Whitespace-only changes.
Reference in new issue
Block a user