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,190 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Addresses
|
||||
* @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 06 May 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\front\clients;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Addresses
|
||||
*/
|
||||
class _addresses extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
if ( !\IPS\Member::loggedIn()->member_id )
|
||||
{
|
||||
\IPS\Output::i()->error( 'no_module_permission_guest', '2X235/1', 403, '' );
|
||||
}
|
||||
|
||||
if ( mb_strtolower( $_SERVER['REQUEST_METHOD'] ) == 'get' and \IPS\Settings::i()->nexus_https and \IPS\Request::i()->url()->data['scheme'] !== 'https' )
|
||||
{
|
||||
\IPS\Output::i()->redirect( new \IPS\Http\Url( preg_replace( '/^http:/', 'https:', \IPS\Request::i()->url() ) ) );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'clients.css', 'nexus' ) );
|
||||
\IPS\Output::i()->breadcrumb[] = array( \IPS\Http\Url::internal( 'app=nexus&module=clients&controller=addresses', 'front', 'clientsaddresses', array(), \IPS\Settings::i()->nexus_https ), \IPS\Member::loggedIn()->language()->addToStack('client_addresses') );
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('client_addresses');
|
||||
\IPS\Output::i()->sidebar['enabled'] = FALSE;
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* View List
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
$addresses = new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_customer_addresses', array( 'member=?', \IPS\Member::loggedIn()->member_id ) ), 'IPS\nexus\Customer\Address' );
|
||||
|
||||
$shippingAddress = NULL;
|
||||
$billingAddress = NULL;
|
||||
$otherAddresses = array();
|
||||
|
||||
foreach ( $addresses as $address )
|
||||
{
|
||||
if( $address->primary_billing )
|
||||
{
|
||||
$billingAddress = $address;
|
||||
}
|
||||
|
||||
if( $address->primary_shipping )
|
||||
{
|
||||
$shippingAddress = $address;
|
||||
}
|
||||
|
||||
if( !$address->primary_shipping && !$address->primary_billing )
|
||||
{
|
||||
$otherAddresses[] = $address;
|
||||
}
|
||||
}
|
||||
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('clients')->template( \IPS\Theme::i()->getTemplate('clients')->addresses( $billingAddress, $shippingAddress, $otherAddresses ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add/Edit
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function form()
|
||||
{
|
||||
$existing = NULL;
|
||||
if ( isset( \IPS\Request::i()->id ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$existing = \IPS\nexus\Customer\Address::load( \IPS\Request::i()->id );
|
||||
if ( $existing->member->member_id != \IPS\Member::loggedIn()->member_id )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
$existing = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->add( new \IPS\Helpers\Form\Address( 'address', $existing ? $existing->address : NULL, TRUE ) );
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
if ( !$existing )
|
||||
{
|
||||
$existing = new \IPS\nexus\Customer\Address;
|
||||
$existing->member = \IPS\Member::loggedIn();
|
||||
$existing->primary_billing = !\IPS\Db::i()->select( 'count(*)', 'nexus_customer_addresses', array( 'member=? AND primary_billing=1', \IPS\Member::loggedIn()->member_id ) )->first();
|
||||
$existing->primary_shipping = !\IPS\Db::i()->select( 'count(*)', 'nexus_customer_addresses', array( 'member=? AND primary_shipping=1', \IPS\Member::loggedIn()->member_id ) )->first();
|
||||
|
||||
\IPS\nexus\Customer::loggedIn()->log( 'address', array( 'type' => 'add', 'details' => json_encode( $values['address'] ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\nexus\Customer::loggedIn()->log( 'address', array( 'type' => 'edit', 'new' => json_encode( $values['address'] ), 'old' => json_encode( $existing->address ) ) );
|
||||
}
|
||||
|
||||
$existing->address = $values['address'];
|
||||
$existing->save();
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=nexus&module=clients&controller=addresses', 'front', 'clientsaddresses', array(), \IPS\Settings::i()->nexus_https ) );
|
||||
}
|
||||
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
{
|
||||
$form->class = 'ipsForm_vertical ipsForm_noLabels';
|
||||
\IPS\Output::i()->sendOutput( $form->customTemplate( array( call_user_func_array( array( \IPS\Theme::i(), 'getTemplate' ), array( 'forms', 'core' ) ), 'popupTemplate' ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('clients')->template( $form );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make Primary
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function primary()
|
||||
{
|
||||
try
|
||||
{
|
||||
$address = \IPS\nexus\Customer\Address::load( \IPS\Request::i()->id );
|
||||
if ( $address->member->member_id == \IPS\Member::loggedIn()->member_id )
|
||||
{
|
||||
$field = \IPS\Request::i()->primary === 'billing' ? 'primary_billing' : 'primary_shipping';
|
||||
\IPS\Db::i()->update( 'nexus_customer_addresses', array( $field => 0 ), array( 'member=?', \IPS\Member::loggedIn()->member_id ) );
|
||||
$address->$field = TRUE;
|
||||
$address->save();
|
||||
|
||||
\IPS\nexus\Customer::loggedIn()->log( 'address', array( 'type' => ( \IPS\Request::i()->primary === 'billing' ? 'primary_billing' : 'primary_shipping' ), 'details' => json_encode( $address->address ) ) );
|
||||
}
|
||||
}
|
||||
catch ( \OutOfRangeException $e ) {}
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=nexus&module=clients&controller=addresses', 'front', 'clientsaddresses', array(), \IPS\Settings::i()->nexus_https ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function delete()
|
||||
{
|
||||
try
|
||||
{
|
||||
$address = \IPS\nexus\Customer\Address::load( \IPS\Request::i()->id );
|
||||
if ( $address->member->member_id == \IPS\Member::loggedIn()->member_id )
|
||||
{
|
||||
$address->delete();
|
||||
\IPS\nexus\Customer::loggedIn()->log( 'address', array( 'type' => 'delete', 'details' => json_encode( $address->address ) ) );
|
||||
}
|
||||
}
|
||||
catch ( \OutOfRangeException $e ) {}
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=nexus&module=clients&controller=addresses', 'front', 'clientsaddresses', array(), \IPS\Settings::i()->nexus_https ) );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Alternative Contacts
|
||||
* @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 08 May 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\front\clients;
|
||||
|
||||
/* 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 Contacts
|
||||
*/
|
||||
class _alternatives extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
if ( !\IPS\Member::loggedIn()->member_id )
|
||||
{
|
||||
\IPS\Output::i()->error( 'no_module_permission_guest', '2X237/1', 403, '' );
|
||||
}
|
||||
|
||||
if ( mb_strtolower( $_SERVER['REQUEST_METHOD'] ) == 'get' and \IPS\Settings::i()->nexus_https and \IPS\Request::i()->url()->data['scheme'] !== 'https' )
|
||||
{
|
||||
\IPS\Output::i()->redirect( new \IPS\Http\Url( preg_replace( '/^http:/', 'https:', \IPS\Request::i()->url() ) ) );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'clients.css', 'nexus' ) );
|
||||
\IPS\Output::i()->breadcrumb[] = array( \IPS\Http\Url::internal( 'app=nexus&module=clients&controller=alternatives', 'front', 'clientsalternatives', array(), \IPS\Settings::i()->nexus_https ), \IPS\Member::loggedIn()->language()->addToStack('client_alternatives') );
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('client_alternatives');
|
||||
\IPS\Output::i()->sidebar['enabled'] = FALSE;
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* View List
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
foreach ( \IPS\nexus\Customer::loggedIn()->alternativeContacts() as $contact )
|
||||
{
|
||||
$contact->alt_id;
|
||||
}
|
||||
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('clients')->template( \IPS\Theme::i()->getTemplate('clients')->alternatives() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add/Edit
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function form()
|
||||
{
|
||||
$existing = NULL;
|
||||
if ( isset( \IPS\Request::i()->id ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$existing = \IPS\nexus\Customer\AlternativeContact::constructFromData( \IPS\Db::i()->select( '*', 'nexus_alternate_contacts', array( 'main_id=? AND alt_id=?', \IPS\nexus\Customer::loggedIn()->member_id, \IPS\Request::i()->id ) )->first() );
|
||||
}
|
||||
catch ( \UnderflowException $e ) {}
|
||||
}
|
||||
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->class = 'ipsForm_vertical';
|
||||
if ( !$existing )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\Email( 'altcontact_email', NULL, TRUE, array(), function( $val )
|
||||
{
|
||||
$member = \IPS\Member::load( $val, 'email' );
|
||||
if ( !$member->member_id )
|
||||
{
|
||||
throw new \DomainException('altcontact_email_error');
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
\IPS\Db::i()->select( '*', 'nexus_alternate_contacts', array( 'main_id=? AND alt_id=?', \IPS\nexus\Customer::loggedIn()->member_id, $member->member_id ) )->first();
|
||||
throw new \DomainException('altcontact_already_exists');
|
||||
}
|
||||
catch ( \UnderflowException $e ) {}
|
||||
} ) );
|
||||
}
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'altcontact_purchases', $existing ? iterator_to_array( $existing->purchases ) : NULL, FALSE, array( 'class' => 'IPS\nexus\Purchase', 'forceOwner' => \IPS\Member::loggedIn(), 'multiple' => TRUE ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Checkbox( 'altcontact_support', $existing ? $existing->support : FALSE ) );
|
||||
$form->add( new \IPS\Helpers\Form\Checkbox( 'altcontact_billing', $existing ? $existing->billing : FALSE ) );
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
if ( $existing )
|
||||
{
|
||||
$altContact = $existing;
|
||||
\IPS\nexus\Customer::loggedIn()->log( 'alternative', array( 'type' => 'edit', 'alt_id' => $altContact->alt_id->member_id, 'alt_name' => $altContact->alt_id->name, 'purchases' => json_encode( $values['altcontact_purchases'] ? $values['altcontact_purchases'] : array() ), 'billing' => $values['altcontact_billing'], 'support' => $values['altcontact_support'] ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
$altContact = new \IPS\nexus\Customer\AlternativeContact;
|
||||
$altContact->main_id = \IPS\nexus\Customer::loggedIn();
|
||||
$altContact->alt_id = \IPS\Member::load( $values['altcontact_email'], 'email' );
|
||||
\IPS\nexus\Customer::loggedIn()->log( 'alternative', array( 'type' => 'add', 'alt_id' => $altContact->alt_id->member_id, 'alt_name' => $altContact->alt_id->name, 'purchases' => json_encode( $values['altcontact_purchases'] ? $values['altcontact_purchases'] : array() ), 'billing' => $values['altcontact_billing'], 'support' => $values['altcontact_support'] ) );
|
||||
}
|
||||
$altContact->purchases = $values['altcontact_purchases'] ? $values['altcontact_purchases'] : array();
|
||||
$altContact->billing = $values['altcontact_billing'];
|
||||
$altContact->support = $values['altcontact_support'];
|
||||
$altContact->save();
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=nexus&module=clients&controller=alternatives', 'front', 'clientsalternatives', array(), \IPS\Settings::i()->nexus_https ) );
|
||||
}
|
||||
|
||||
if( \IPS\Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->sendOutput( $form->customTemplate( array( call_user_func_array( array( \IPS\Theme::i(), 'getTemplate' ), array( 'forms', 'core' ) ), 'popupTemplate' ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('clients')->template( $form );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function delete()
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
|
||||
try
|
||||
{
|
||||
$contact = \IPS\nexus\Customer\AlternativeContact::constructFromData( \IPS\Db::i()->select( '*', 'nexus_alternate_contacts', array( 'main_id=? AND alt_id=?', \IPS\nexus\Customer::loggedIn()->member_id, \IPS\Request::i()->id ) )->first() );
|
||||
$contact->delete();
|
||||
\IPS\nexus\Customer::loggedIn()->log( 'alternative', array( 'type' => 'delete', 'alt_id' => $contact->alt_id->member_id, 'alt_name' => $contact->alt_id->name ) );
|
||||
}
|
||||
catch ( \UnderflowException $e ) {}
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=nexus&module=clients&controller=alternatives', 'front', 'clientsalternatives', array(), \IPS\Settings::i()->nexus_https ) );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Cards
|
||||
* @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 08 May 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\front\clients;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cards
|
||||
*/
|
||||
class _cards extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
if ( !\IPS\Member::loggedIn()->member_id )
|
||||
{
|
||||
\IPS\Output::i()->error( 'no_module_permission_guest', '2X236/1', 403, '' );
|
||||
}
|
||||
|
||||
if ( mb_strtolower( $_SERVER['REQUEST_METHOD'] ) == 'get' and \IPS\Settings::i()->nexus_https and \IPS\Request::i()->url()->data['scheme'] !== 'https' )
|
||||
{
|
||||
\IPS\Output::i()->redirect( new \IPS\Http\Url( preg_replace( '/^http:/', 'https:', \IPS\Request::i()->url() ) ) );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'clients.css', 'nexus' ) );
|
||||
\IPS\Output::i()->breadcrumb[] = array( \IPS\Http\Url::internal( 'app=nexus&module=clients&controller=cards', 'front', 'clientscards', array(), \IPS\Settings::i()->nexus_https ), \IPS\Member::loggedIn()->language()->addToStack('client_cards') );
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('client_cards');
|
||||
\IPS\Output::i()->sidebar['enabled'] = FALSE;
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* View List
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
$cards = array();
|
||||
foreach ( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_customer_cards', array( 'card_member=?', \IPS\nexus\Customer::loggedIn()->member_id ) ), 'IPS\nexus\Customer\CreditCard' ) as $card )
|
||||
{
|
||||
try
|
||||
{
|
||||
$cardData = $card->card;
|
||||
$cards[ $card->id ] = array(
|
||||
'id' => $card->id,
|
||||
'card_type' => $cardData->type,
|
||||
'card_number' => $cardData->lastFour,
|
||||
'card_expire' => str_pad( $cardData->expMonth , 2, '0', STR_PAD_LEFT ). '/' . $cardData->expYear
|
||||
);
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
}
|
||||
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('clients')->template( \IPS\Theme::i()->getTemplate('clients')->cards( $cards ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$form = \IPS\nexus\Customer\CreditCard::create( \IPS\nexus\Customer::loggedIn() );
|
||||
if ( $form instanceof \IPS\nexus\Customer\CreditCard )
|
||||
{
|
||||
\IPS\nexus\Customer::loggedIn()->log( 'card', array( 'type' => 'add', 'number' => $form->card->lastFour ) );
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=nexus&module=clients&controller=cards', 'front', 'clientscards', array(), \IPS\Settings::i()->nexus_https ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('clients')->template( $form );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
try
|
||||
{
|
||||
$card = \IPS\nexus\Customer\CreditCard::load( \IPS\Request::i()->id );
|
||||
if ( $card->member->member_id === \IPS\nexus\Customer::loggedIn()->member_id )
|
||||
{
|
||||
$card->delete();
|
||||
\IPS\nexus\Customer::loggedIn()->log( 'card', array( 'type' => 'delete', 'number' => $card->card->lastFour ) );
|
||||
}
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=nexus&module=clients&controller=cards', 'front', 'clientscards', array(), \IPS\Settings::i()->nexus_https ) );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,436 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Account Credit
|
||||
* @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 08 May 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\front\clients;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Account Credit
|
||||
*/
|
||||
class _credit extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
if ( !\IPS\Member::loggedIn()->member_id )
|
||||
{
|
||||
\IPS\Output::i()->error( 'no_module_permission_guest', '2X239/1', 403, '' );
|
||||
}
|
||||
|
||||
if ( mb_strtolower( $_SERVER['REQUEST_METHOD'] ) == 'get' and \IPS\Settings::i()->nexus_https and \IPS\Request::i()->url()->data['scheme'] !== 'https' )
|
||||
{
|
||||
\IPS\Output::i()->redirect( new \IPS\Http\Url( preg_replace( '/^http:/', 'https:', \IPS\Request::i()->url() ) ) );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'clients.css', 'nexus' ) );
|
||||
\IPS\Output::i()->breadcrumb[] = array( \IPS\Http\Url::internal( 'app=nexus&module=clients&controller=credit', 'front', 'clientscredit', array(), \IPS\Settings::i()->nexus_https ), \IPS\Member::loggedIn()->language()->addToStack('client_credit') );
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('client_credit');
|
||||
\IPS\Output::i()->sidebar['enabled'] = FALSE;
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* View
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
/* Get Balance(s) */
|
||||
$balance = array_filter( \IPS\nexus\Customer::loggedIn()->cm_credits, function( $val )
|
||||
{
|
||||
return $val->amount;
|
||||
} );
|
||||
|
||||
/* Pending Withdrawls */
|
||||
$perPage = 10;
|
||||
$page = isset( \IPS\Request::i()->page ) ? intval( \IPS\Request::i()->page ) : 1;
|
||||
|
||||
if( $page < 1 )
|
||||
{
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$pastWithdrawalsSelect = \IPS\Db::i()->select( '*', 'nexus_payouts', array( 'po_member=?', \IPS\nexus\Customer::loggedIn()->member_id ), 'po_date DESC', array( ( $page - 1 ) * $perPage, $perPage ), NULL, NULL, \IPS\Db::SELECT_SQL_CALC_FOUND_ROWS );
|
||||
$pastWithdrawalsPagination = \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->pagination(
|
||||
\IPS\Http\Url::internal( 'app=nexus&module=clients&controller=credit', 'front', 'clientscredit', array(), \IPS\Settings::i()->nexus_https ),
|
||||
ceil( $pastWithdrawalsSelect->count( TRUE ) / $perPage ),
|
||||
$page,
|
||||
$perPage
|
||||
);
|
||||
$pastWithdrawals = new \IPS\Patterns\ActiveRecordIterator( $pastWithdrawalsSelect, 'IPS\nexus\Payout' );
|
||||
|
||||
/* Can we withdraw? */
|
||||
$canWithdraw = FALSE;
|
||||
$withdrawOptions = json_decode( \IPS\Settings::i()->nexus_payout, TRUE );
|
||||
if ( count( $withdrawOptions ) )
|
||||
{
|
||||
foreach ( \IPS\nexus\Money::currencies() as $currency )
|
||||
{
|
||||
if ( isset( $balance[ $currency ] ) )
|
||||
{
|
||||
$canWithdraw = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Can we topup? */
|
||||
$canTopup = FALSE;
|
||||
if ( \IPS\Settings::i()->nexus_min_topup )
|
||||
{
|
||||
$minimumTopupAmounts = ( \IPS\Settings::i()->nexus_min_topup and \IPS\Settings::i()->nexus_min_topup !== '*' ) ? json_decode( \IPS\Settings::i()->nexus_min_topup, TRUE ) : NULL;
|
||||
$maximumBalanceAmounts = ( \IPS\Settings::i()->nexus_max_credit and \IPS\Settings::i()->nexus_max_credit !== '*' ) ? json_decode( \IPS\Settings::i()->nexus_max_credit, TRUE ) : NULL;
|
||||
|
||||
$maximums = array();
|
||||
foreach ( array_merge( array( \IPS\nexus\Customer::loggedIn() ), iterator_to_array( \IPS\nexus\Customer::loggedIn()->parentContacts( array('billing=1') ) ) ) as $account )
|
||||
{
|
||||
if ( $account instanceof \IPS\nexus\Customer\AlternativeContact )
|
||||
{
|
||||
$account = $account->main_id;
|
||||
}
|
||||
|
||||
foreach ( $account->cm_credits as $value )
|
||||
{
|
||||
$max = $maximumBalanceAmounts ? ( $maximumBalanceAmounts[ $value->currency ]['amount'] - $value->amount ) : NULL;
|
||||
if ( is_null( $max ) or $max > 0 )
|
||||
{
|
||||
$canTopup = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('clients')->template( \IPS\Theme::i()->getTemplate('clients')->credit( $balance, $pastWithdrawals, $pastWithdrawalsPagination, $canWithdraw, $canTopup ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Withdraw
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function withdraw()
|
||||
{
|
||||
$withdrawForm = NULL;
|
||||
$withdrawOptions = json_decode( \IPS\Settings::i()->nexus_payout, TRUE );
|
||||
if ( count( $withdrawOptions ) )
|
||||
{
|
||||
$withdrawForm = new \IPS\Helpers\Form( 'withdraw', 'withdraw_credit' );
|
||||
|
||||
$minimumWithdrawalsAmounts = ( \IPS\Settings::i()->nexus_payout_min and \IPS\Settings::i()->nexus_payout_min !== '*' ) ? json_decode( \IPS\Settings::i()->nexus_payout_min, TRUE ) : NULL;
|
||||
|
||||
$balance = array_filter( \IPS\nexus\Customer::loggedIn()->cm_credits, function( $val )
|
||||
{
|
||||
return $val->amount;
|
||||
} );
|
||||
|
||||
$currencyOptions = array();
|
||||
if ( count( $balance ) > 1 )
|
||||
{
|
||||
$currencyToggles = array();
|
||||
foreach ( \IPS\nexus\Money::currencies() as $currency )
|
||||
{
|
||||
if ( isset( $balance[ $currency ] ) )
|
||||
{
|
||||
$currencyOptions[ $currency ] = $currency;
|
||||
$currencyToggles[ $currency ] = array( 'withdraw_amount_' . $currency );
|
||||
}
|
||||
}
|
||||
|
||||
$withdrawForm->add( new \IPS\Helpers\Form\Radio( 'withdraw_currency', NULL, TRUE, array( 'options' => $currencyOptions, 'toggles' => $currencyToggles ) ) );
|
||||
}
|
||||
|
||||
$canWithdraw = FALSE;
|
||||
foreach ( \IPS\nexus\Money::currencies() as $currency )
|
||||
{
|
||||
if ( !isset( $balance[ $currency ] ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$min = $minimumWithdrawalsAmounts ? ( $minimumWithdrawalsAmounts[ $currency ]['amount'] ) : NULL;
|
||||
$max = $balance[ $currency ]->amount;
|
||||
|
||||
$field = new \IPS\Helpers\Form\Number( 'withdraw_amount_' . $currency, $max, count( $currencyOptions ) ? NULL : TRUE, array( 'min' => $min, 'max' => $max, 'decimals' => TRUE ), count( $currencyOptions ) ? NULL : function( $val ) use ( $currency )
|
||||
{
|
||||
if ( !$val and \IPS\Request::i()->withdraw_currency === $currency )
|
||||
{
|
||||
throw new \DomainException('form_required');
|
||||
}
|
||||
}, NULL, $currency, 'withdraw_amount_' . $currency );
|
||||
$field->label = \IPS\Member::loggedIn()->language()->addToStack('withdraw_amount');
|
||||
$withdrawForm->add( $field );
|
||||
|
||||
$canWithdraw = TRUE;
|
||||
}
|
||||
|
||||
if ( $canWithdraw )
|
||||
{
|
||||
$options = array();
|
||||
$toggles = array();
|
||||
$fields = array();
|
||||
foreach ( $withdrawOptions as $k => $settings )
|
||||
{
|
||||
$options[ $k ] = $k === 'Manual' ? $settings['name'] : 'withdraw__' . $k;
|
||||
$toggles[ $k ] = array();
|
||||
$class = 'IPS\nexus\Gateway\\' . $k . '\Payout';
|
||||
foreach ( $class::form() as $field )
|
||||
{
|
||||
if ( !$field->htmlId )
|
||||
{
|
||||
$field->htmlId = $field->name;
|
||||
$toggles[ $k ][] = $field->htmlId;
|
||||
}
|
||||
$fields[] = $field;
|
||||
}
|
||||
}
|
||||
|
||||
if ( count( $withdrawOptions ) > 1 )
|
||||
{
|
||||
$withdrawForm->add( new \IPS\Helpers\Form\Radio( 'withdraw_method', NULL, TRUE, array( 'options' => $options, 'toggles' => $toggles ) ) );
|
||||
}
|
||||
|
||||
foreach ( $fields as $field )
|
||||
{
|
||||
$withdrawForm->add( $field );
|
||||
}
|
||||
if ( $values = $withdrawForm->values() )
|
||||
{
|
||||
$currencies = array_keys( $balance );
|
||||
$currency = count( $currencyOptions ) ? $values['withdraw_currency'] : array_pop( $currencies );
|
||||
|
||||
$withdrawMethods = array_keys( $options );
|
||||
if ( count( $withdrawMethods ) === 1 )
|
||||
{
|
||||
$key = array_pop( $withdrawMethods );
|
||||
$class = 'IPS\nexus\Gateway\\' . $key . '\Payout';
|
||||
}
|
||||
else
|
||||
{
|
||||
$class = 'IPS\nexus\Gateway\\' . $values['withdraw_method'] . '\Payout';
|
||||
}
|
||||
|
||||
$payout = new $class;
|
||||
$payout->amount = new \IPS\nexus\Money( $values[ 'withdraw_amount_' . $currency ], $currency );
|
||||
$payout->member = \IPS\nexus\Customer::loggedIn();
|
||||
try
|
||||
{
|
||||
$payout->data = $payout->getData( $values );
|
||||
}
|
||||
catch ( \DomainException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( $e->getMessage(), '1X239/2', 403, '' );
|
||||
}
|
||||
$payout->ip = \IPS\Request::i()->ipAddress();
|
||||
$payout->save();
|
||||
|
||||
$credits = \IPS\nexus\Customer::loggedIn()->cm_credits;
|
||||
$credits[ $currency ]->amount -= $values[ 'withdraw_amount_' . $currency ];
|
||||
\IPS\nexus\Customer::loggedIn()->cm_credits = $credits;
|
||||
\IPS\nexus\Customer::loggedIn()->save();
|
||||
|
||||
if ( !\IPS\Settings::i()->nexus_payout_approve and !$payout::$requiresApproval )
|
||||
{
|
||||
try
|
||||
{
|
||||
$payout->process();
|
||||
\IPS\nexus\Customer::loggedIn()->log( 'payout', array( 'type' => 'autoprocess', 'amount' => $values[ 'withdraw_amount_' . $currency ], 'currency' => $currency, 'payout_id' => $payout->id ) );
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=nexus&module=clients&controller=credit&withdraw=success', 'front', 'clientscredit', array(), \IPS\Settings::i()->nexus_https ) );
|
||||
}
|
||||
catch ( \Exception $e ) {}
|
||||
}
|
||||
|
||||
\IPS\nexus\Customer::loggedIn()->log( 'payout', array( 'type' => 'request', 'amount' => $values[ 'withdraw_amount_' . $currency ], 'currency' => $currency, 'payout_id' => $payout->id ) );
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=nexus&module=clients&controller=credit&withdraw=pending', 'front', 'clientscredit', array(), \IPS\Settings::i()->nexus_https ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$withdrawForm = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !$withdrawForm )
|
||||
{
|
||||
\IPS\Output::i()->error( 'no_module_permission', '2X239/3', 403, '' );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->output = $withdrawForm->customTemplate( array( call_user_func_array( array( \IPS\Theme::i(), 'getTemplate' ), array( 'forms', 'core' ) ), 'popupTemplate' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Topup
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function topup()
|
||||
{
|
||||
$topupForm = NULL;
|
||||
if ( \IPS\Settings::i()->nexus_min_topup )
|
||||
{
|
||||
$minimumTopupAmounts = ( \IPS\Settings::i()->nexus_min_topup and \IPS\Settings::i()->nexus_min_topup !== '*' ) ? json_decode( \IPS\Settings::i()->nexus_min_topup, TRUE ) : NULL;
|
||||
$maximumBalanceAmounts = ( \IPS\Settings::i()->nexus_max_credit and \IPS\Settings::i()->nexus_max_credit !== '*' ) ? json_decode( \IPS\Settings::i()->nexus_max_credit, TRUE ) : NULL;
|
||||
|
||||
$maximums = array();
|
||||
foreach ( array_merge( array( \IPS\nexus\Customer::loggedIn() ), iterator_to_array( \IPS\nexus\Customer::loggedIn()->parentContacts( array('billing=1') ) ) ) as $account )
|
||||
{
|
||||
if ( $account instanceof \IPS\nexus\Customer\AlternativeContact )
|
||||
{
|
||||
$account = $account->main_id;
|
||||
}
|
||||
|
||||
foreach ( $account->cm_credits as $value )
|
||||
{
|
||||
$max = $maximumBalanceAmounts ? ( $maximumBalanceAmounts[ $value->currency ]['amount'] - $value->amount ) : NULL;
|
||||
if ( is_null( $max ) or $max > 0 )
|
||||
{
|
||||
$maximums[ $account->member_id ][ $value->currency ] = $max;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( count( $maximums ) )
|
||||
{
|
||||
$topupForm = new \IPS\Helpers\Form( 'topup', 'checkout' );
|
||||
|
||||
$accountOptions = array();
|
||||
foreach ( $maximums as $accountId => $data )
|
||||
{
|
||||
$currency = NULL;
|
||||
if ( count( $data ) === 1 )
|
||||
{
|
||||
$currencies = array_keys( $data );
|
||||
$currency = array_pop( $currencies );
|
||||
}
|
||||
|
||||
$accountOptions[ $accountId ] = $accountId === \IPS\nexus\Customer::loggedIn()->id ? \IPS\nexus\Customer::loggedIn()->language()->addToStack( 'my_account', FALSE, array( 'sprintf' => array( \IPS\nexus\Customer::loggedIn()->cm_name ) ) ) : \IPS\nexus\Customer::load( $accountId )->cm_name;
|
||||
$accountOptionToggles[ $accountId ] = ( count( $data ) > 1 ) ? array( 'topup_currency_' . $accountId ) : array( 'topup_amount_' . $accountId . '_' . $currency );
|
||||
}
|
||||
$topupForm->add( new \IPS\Helpers\Form\Radio( 'topup_account', NULL, TRUE, array( 'options' => $accountOptions, 'parse' => 'none', 'toggles' => $accountOptionToggles ) ) );
|
||||
|
||||
foreach ( $maximums as $accountId => $data )
|
||||
{
|
||||
if ( count( $data ) > 1 )
|
||||
{
|
||||
$currencyToggles = array();
|
||||
foreach ( $data as $currency => $maximum )
|
||||
{
|
||||
$currencyToggles[ $currency ] = array( 'topup_amount_' . $accountId . '_' . $currency );
|
||||
}
|
||||
|
||||
$field = new \IPS\Helpers\Form\Radio( 'topup_currency_' . $accountId, NULL, NULL, array( 'options' => array_combine( array_keys( $data ), array_keys( $data ) ), 'toggles' => $currencyToggles ), NULL, NULL, NULL, 'topup_currency_' . $accountId );
|
||||
$field->label = \IPS\Member::loggedIn()->language()->addToStack( 'topup_currency' );
|
||||
$topupForm->add( $field );
|
||||
}
|
||||
|
||||
foreach ( $data as $currency => $maximum )
|
||||
{
|
||||
$min = $minimumTopupAmounts ? ( $minimumTopupAmounts[ $currency ]['amount'] ) : 0.01;
|
||||
|
||||
$field = new \IPS\Helpers\Form\Number( 'topup_amount_' . $accountId . '_' . $currency, NULL, NULL, array( 'decimals' => TRUE ), function( $val ) use ( $currency, $accountOptions, $accountId, $data, $min, $maximum )
|
||||
{
|
||||
if ( count( $accountOptions ) === 1 or \IPS\Request::i()->topup_account == $accountId )
|
||||
{
|
||||
$key = "topup_currency_{$accountId}";
|
||||
if ( count( $data ) === 1 or \IPS\Request::i()->$key == $currency )
|
||||
{
|
||||
if ( !$val )
|
||||
{
|
||||
throw new \DomainException('form_required');
|
||||
}
|
||||
elseif ( !is_null( $min ) and $val < $min )
|
||||
{
|
||||
throw new \DomainException( \IPS\Member::loggedIn()->language()->addToStack( 'form_number_min', FALSE, array( 'sprintf' => array( $min ) ) ) );
|
||||
}
|
||||
elseif ( $maximum and $val > $maximum )
|
||||
{
|
||||
throw new \DomainException( \IPS\Member::loggedIn()->language()->addToStack( 'form_number_max', FALSE, array( 'sprintf' => array( $maximum ) ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}, NULL, $currency, 'topup_amount_' . $accountId . '_' . $currency );
|
||||
$field->label = \IPS\Member::loggedIn()->language()->addToStack('topup_amount');
|
||||
$topupForm->add( $field );
|
||||
}
|
||||
}
|
||||
|
||||
if ( $values = $topupForm->values() )
|
||||
{
|
||||
$account = isset( $values['topup_account'] ) ? \IPS\nexus\Customer::load( $values['topup_account'] ) : \IPS\nexus\Customer::loggedIn();
|
||||
if ( isset( $values[ 'topup_currency_' . $account->member_id ] ) )
|
||||
{
|
||||
$currency = $values[ 'topup_currency_' . $account->member_id ];
|
||||
}
|
||||
else
|
||||
{
|
||||
$currencies = array_keys( $maximums[ $account->member_id ] );
|
||||
$currency = array_pop( $currencies );
|
||||
}
|
||||
|
||||
$invoice = new \IPS\nexus\Invoice;
|
||||
$invoice->member = $account;
|
||||
$invoice->currency = $currency;
|
||||
$invoice->return_uri = 'app=nexus&module=clients&controller=credit';
|
||||
$invoice->addItem( new \IPS\nexus\extensions\nexus\Item\AccountCreditIncrease( \IPS\nexus\Customer::loggedIn()->language()->get('account_credit'), new \IPS\nexus\Money( $values["topup_amount_{$account->member_id}_{$currency}"], $currency ) ) );
|
||||
\IPS\Output::i()->redirect( $invoice->checkoutUrl() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( !$topupForm )
|
||||
{
|
||||
\IPS\Output::i()->error( 'no_module_permission', '2X239/4', 403, '' );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->output = $topupForm->customTemplate( array( call_user_func_array( array( \IPS\Theme::i(), 'getTemplate' ), array( 'forms', 'core' ) ), 'popupTemplate' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel Pending Payout
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function cancel()
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
|
||||
try
|
||||
{
|
||||
$payout = \IPS\nexus\Payout::load( \IPS\Request::i()->id );
|
||||
if ( $payout->member->member_id === \IPS\nexus\Customer::loggedIn()->member_id and $payout->status === $payout::STATUS_PENDING )
|
||||
{
|
||||
$payout->status = $payout::STATUS_CANCELED;
|
||||
$payout->save();
|
||||
|
||||
$credits = $payout->member->cm_credits;
|
||||
$credits[ $payout->amount->currency ]->amount += $payout->amount->amount;
|
||||
$payout->member->cm_credits = $credits;
|
||||
$payout->member->save();
|
||||
|
||||
\IPS\nexus\Customer::loggedIn()->log( 'payout', array( 'type' => 'cancel', 'amount' => $payout->amount->amount, 'currency' => $payout->amount->currency, 'payout_id' => $payout->id ) );
|
||||
}
|
||||
}
|
||||
catch ( \OutOfRangeException $e ) { }
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=nexus&module=clients&controller=credit', 'front', 'clientscredit', array(), \IPS\Settings::i()->nexus_https ) );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Donations
|
||||
* @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 17 Jun 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\front\clients;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Donations
|
||||
*/
|
||||
class _donations extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
if ( mb_strtolower( $_SERVER['REQUEST_METHOD'] ) == 'get' and \IPS\Settings::i()->nexus_https and \IPS\Request::i()->url()->data['scheme'] !== 'https' )
|
||||
{
|
||||
\IPS\Output::i()->redirect( new \IPS\Http\Url( preg_replace( '/^http:/', 'https:', \IPS\Request::i()->url() ) ) );
|
||||
}
|
||||
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* View List
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
if ( isset( \IPS\Request::i()->id ) )
|
||||
{
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=nexus&module=clients&controller=donations', 'front', 'clientsdonations', array(), \IPS\Settings::i()->nexus_https ) );
|
||||
}
|
||||
}
|
||||
|
||||
\IPS\Output::i()->breadcrumb[] = array( \IPS\Http\Url::internal( 'app=nexus&module=clients&controller=donations', 'front', 'clientsdonations', array(), \IPS\Settings::i()->nexus_https ), \IPS\Member::loggedIn()->language()->addToStack('client_donations') );
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('client_donations');
|
||||
\IPS\Output::i()->sidebar['enabled'] = FALSE;
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'donations.css' ) );
|
||||
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('clients')->template( \IPS\Theme::i()->getTemplate('clients')->donations() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Make Donation
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function donate()
|
||||
{
|
||||
try
|
||||
{
|
||||
$goal = \IPS\nexus\Donation\Goal::load( \IPS\Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X238/1', 404, '' );
|
||||
}
|
||||
|
||||
$form = new \IPS\Helpers\Form( 'donate', 'donate' );
|
||||
$form->class = 'ipsForm_vertical';
|
||||
if ( !isset( \IPS\Request::i()->noDesc ) and $desc = \IPS\Member::loggedIn()->language()->get("nexus_donategoal_{$goal->id}_desc") )
|
||||
{
|
||||
$form->addMessage( $desc, '', FALSE );
|
||||
}
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'donate_amount', 0, TRUE, array( 'decimals' => TRUE, 'min' => 0.01 ), NULL, NULL, $goal->currency ) );
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
$item = new \IPS\nexus\extensions\nexus\Item\Donation( \IPS\Member::loggedIn()->language()->get( 'nexus_donategoal_' . $goal->_id ), new \IPS\nexus\Money( $values['donate_amount'], $goal->currency ) );
|
||||
$item->id = $goal->_id;
|
||||
|
||||
$invoice = new \IPS\nexus\Invoice;
|
||||
$invoice->member = \IPS\nexus\Customer::loggedIn();
|
||||
$invoice->currency = $goal->currency;
|
||||
$invoice->addItem( $item );
|
||||
$invoice->return_uri = 'app=nexus&module=clients&controller=donations&thanks=1';
|
||||
$invoice->save();
|
||||
|
||||
\IPS\Output::i()->redirect( $invoice->checkoutUrl() );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->title = $goal->_title;
|
||||
\IPS\Output::i()->output = $form->customTemplate( array( call_user_func_array( array( \IPS\Theme::i(), 'getTemplate' ), array( 'forms', 'core' ) ), 'popupTemplate' ) );
|
||||
}
|
||||
}
|
||||
Whitespace-only changes.
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Custom Fields
|
||||
* @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 08 Sep 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\front\clients;
|
||||
|
||||
/* 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 Fields
|
||||
*/
|
||||
class _info extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
if ( !\IPS\Member::loggedIn()->member_id )
|
||||
{
|
||||
\IPS\Output::i()->error( 'no_module_permission_guest', '2X242/1', 403, '' );
|
||||
}
|
||||
|
||||
if ( mb_strtolower( $_SERVER['REQUEST_METHOD'] ) == 'get' and \IPS\Settings::i()->nexus_https and \IPS\Request::i()->url()->data['scheme'] !== 'https' )
|
||||
{
|
||||
\IPS\Output::i()->redirect( new \IPS\Http\Url( preg_replace( '/^http:/', 'https:', \IPS\Request::i()->url() ) ) );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->breadcrumb[] = array( \IPS\Http\Url::internal( 'app=nexus&module=clients&controller=info', 'front', 'clientsinfo', array(), \IPS\Settings::i()->nexus_https ), \IPS\Member::loggedIn()->language()->addToStack('client_info') );
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('client_info');
|
||||
\IPS\Output::i()->sidebar['enabled'] = FALSE;
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit Info
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
$form = new \IPS\Helpers\Form;
|
||||
foreach ( \IPS\nexus\Customer\CustomField::roots() as $field )
|
||||
{
|
||||
$column = $field->column;
|
||||
$form->add( $field->buildHelper( \IPS\nexus\Customer::loggedIn()->$column ) );
|
||||
}
|
||||
|
||||
if ( $values = $form->values( TRUE ) )
|
||||
{
|
||||
$changes = array();
|
||||
foreach ( \IPS\nexus\Customer\CustomField::roots() as $field )
|
||||
{
|
||||
$column = $field->column;
|
||||
if ( \IPS\nexus\Customer::loggedIn()->$column != $values["nexus_ccfield_{$field->id}"] )
|
||||
{
|
||||
$changes[] = array( 'name' => 'nexus_ccfield_' . $field->id, 'value' => $values["nexus_ccfield_{$field->id}"], 'old' => \IPS\nexus\Customer::loggedIn()->$column );
|
||||
\IPS\nexus\Customer::loggedIn()->$column = $values["nexus_ccfield_{$field->id}"];
|
||||
}
|
||||
|
||||
if ( $field->type === 'Editor' )
|
||||
{
|
||||
$field->claimAttachments( \IPS\nexus\Customer::loggedIn()->member_id );
|
||||
}
|
||||
}
|
||||
if ( !empty( $changes ) )
|
||||
{
|
||||
\IPS\nexus\Customer::loggedIn()->log( 'info', array( 'other' => $changes ) );
|
||||
}
|
||||
\IPS\nexus\Customer::loggedIn()->save();
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=nexus&module=clients&controller=info', 'front', 'clientsinfo', array(), \IPS\Settings::i()->nexus_https ) );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('clients')->template( \IPS\Theme::i()->getTemplate('clients')->info( $form ) );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Invoices
|
||||
* @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 06 May 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\front\clients;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoices
|
||||
*/
|
||||
class _invoices extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
if ( !\IPS\Member::loggedIn()->member_id )
|
||||
{
|
||||
\IPS\Output::i()->error( 'no_module_permission_guest', '2X215/3', 403, '' );
|
||||
}
|
||||
|
||||
if ( mb_strtolower( $_SERVER['REQUEST_METHOD'] ) == 'get' and \IPS\Settings::i()->nexus_https and \IPS\Request::i()->url()->data['scheme'] !== 'https' )
|
||||
{
|
||||
\IPS\Output::i()->redirect( new \IPS\Http\Url( preg_replace( '/^http:/', 'https:', \IPS\Request::i()->url() ) ) );
|
||||
}
|
||||
|
||||
/* Load Invoice */
|
||||
if ( isset( \IPS\Request::i()->id ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$this->invoice = \IPS\nexus\Invoice::loadAndCheckPerms( \IPS\Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X215/1', 404, '' );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->breadcrumb[] = array( \IPS\Http\Url::internal( 'app=nexus&module=clients&controller=invoices', 'front', 'clientsinvoices', array(), \IPS\Settings::i()->nexus_https ), \IPS\Member::loggedIn()->language()->addToStack('client_invoices') );
|
||||
\IPS\Output::i()->breadcrumb[] = array( $this->invoice->url(), $this->invoice->title );
|
||||
\IPS\Output::i()->title = $this->invoice->title;
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('client_invoices');
|
||||
if ( isset( \IPS\Request::i()->do ) )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X215/2', 403, '' );
|
||||
}
|
||||
}
|
||||
|
||||
/* Execute */
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'clients.css', 'nexus' ) );
|
||||
\IPS\Output::i()->sidebar['enabled'] = FALSE;
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* View List
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
$where = array( 'i_member=?', \IPS\Member::loggedIn()->member_id );
|
||||
$parentContacts = \IPS\nexus\Customer::loggedIn()->parentContacts( array( 'billing=1' ) );
|
||||
if ( count( $parentContacts ) )
|
||||
{
|
||||
$or = array();
|
||||
foreach ( array_keys( iterator_to_array( $parentContacts ) ) as $id )
|
||||
{
|
||||
$where[0] .= ' OR i_member=?';
|
||||
$where[] = $id;
|
||||
}
|
||||
}
|
||||
|
||||
$invoices = new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_invoices', $where, 'i_date DESC' ), 'IPS\nexus\Invoice' );
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('clients')->template( \IPS\Theme::i()->getTemplate('clients')->invoices( $invoices ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* View
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function view()
|
||||
{
|
||||
$shipments = $this->invoice->shipments();
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('clients')->template( \IPS\Theme::i()->getTemplate('clients')->invoice( $this->invoice ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* PO Number
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function poNumber()
|
||||
{
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->class = 'ipsForm_vertical ipsForm_noLabels';
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'invoice_po_number', $this->invoice->po, FALSE, array( 'maxLength' => 255 ) ) );
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
$this->invoice->po = $values['invoice_po_number'];
|
||||
$this->invoice->save();
|
||||
\IPS\Output::i()->redirect( $this->invoice->url() );
|
||||
}
|
||||
\IPS\Output::i()->output = $form->customTemplate( array( call_user_func_array( array( \IPS\Theme::i(), 'getTemplate' ), array( 'forms', 'core' ) ), 'popupTemplate' ) );;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function notes()
|
||||
{
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->class = 'ipsForm_vertical ipsForm_noLabels';
|
||||
$form->add( new \IPS\Helpers\Form\TextArea( 'invoice_notes', $this->invoice->notes ) );
|
||||
\IPS\Member::loggedIn()->language()->words['invoice_notes_desc'] = '';
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
$this->invoice->notes = $values['invoice_notes'];
|
||||
$this->invoice->save();
|
||||
\IPS\Output::i()->redirect( $this->invoice->url() );
|
||||
}
|
||||
\IPS\Output::i()->output = $form->customTemplate( array( call_user_func_array( array( \IPS\Theme::i(), 'getTemplate' ), array( 'forms', 'core' ) ), 'popupTemplate' ) );;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function printout()
|
||||
{
|
||||
$output = \IPS\Theme::i()->getTemplate( 'invoices', 'nexus', 'global' )->printInvoice( $this->invoice, $this->invoice->summary() );
|
||||
\IPS\Output::i()->title = 'I' . $this->invoice->id;
|
||||
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate( 'global', 'core' )->blankTemplate( $output ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function cancel()
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
$this->invoice->status = \IPS\nexus\invoice::STATUS_CANCELED;
|
||||
$this->invoice->save();
|
||||
|
||||
foreach ( $this->invoice->items as $k => $item )
|
||||
{
|
||||
$item->onInvoiceCancel( $this->invoice );
|
||||
}
|
||||
|
||||
$this->invoice->member->log( 'invoice', array( 'type' => 'status', 'new' => 'canc', 'id' => $this->invoice->id, 'title' => $this->invoice->title ) );
|
||||
\IPS\Output::i()->redirect( $this->invoice->url() );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Network Status
|
||||
* @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 Sep 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\front\clients;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Network Status
|
||||
*/
|
||||
class _networkStatus extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* View
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
if ( !\IPS\Settings::i()->network_status )
|
||||
{
|
||||
\IPS\Output::i()->error( 'no_module_permission', '2X246/1', 403, '' );
|
||||
}
|
||||
|
||||
if ( \IPS\Settings::i()->network_status == 2 )
|
||||
{
|
||||
$servers = \IPS\nexus\Hosting\Server::roots( NULL, NULL, array( 'server_monitor<>?', '' ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
$servers = \IPS\nexus\Hosting\Server::roots( NULL, NULL, array( 'server_monitor<>? AND server_monitor_fails>0', '' ) );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('network_status');
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('clients')->networkStatus( $servers );
|
||||
|
||||
unset( \IPS\Output::i()->breadcrumb['module'] );
|
||||
\IPS\Output::i()->breadcrumb[] = array( NULL, \IPS\Member::loggedIn()->language()->addToStack('network_status') );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,240 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Purchases
|
||||
* @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 06 May 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\front\clients;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Purchases
|
||||
*/
|
||||
class _purchases extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
if ( !\IPS\Member::loggedIn()->member_id )
|
||||
{
|
||||
\IPS\Output::i()->error( 'no_module_permission_guest', '2X212/6', 403, '' );
|
||||
}
|
||||
|
||||
if ( mb_strtolower( $_SERVER['REQUEST_METHOD'] ) == 'get' and \IPS\Settings::i()->nexus_https and \IPS\Request::i()->url()->data['scheme'] !== 'https' )
|
||||
{
|
||||
\IPS\Output::i()->redirect( new \IPS\Http\Url( preg_replace( '/^http:/', 'https:', \IPS\Request::i()->url() ) ) );
|
||||
}
|
||||
|
||||
/* Purchases breadcrumb */
|
||||
\IPS\Output::i()->breadcrumb[] = array( \IPS\Http\Url::internal( 'app=nexus&module=clients&controller=purchases', 'front', 'clientspurchases', array(), \IPS\Settings::i()->nexus_https ), \IPS\Member::loggedIn()->language()->addToStack('client_purchases') );
|
||||
|
||||
/* Load Purchase */
|
||||
if ( isset( \IPS\Request::i()->id ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$this->purchase = \IPS\nexus\Purchase::load( \IPS\Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X212/1', 404, '' );
|
||||
}
|
||||
if ( !$this->purchase->canView() )
|
||||
{
|
||||
\IPS\Output::i()->error( 'no_module_permission', '2X212/2', 403, '' );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->breadcrumb[] = array( $this->purchase->url(), $this->purchase->name );
|
||||
\IPS\Output::i()->title = $this->purchase->name;
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('client_purchases');
|
||||
if ( isset( \IPS\Request::i()->do ) )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X212/3', 403, '' );
|
||||
}
|
||||
}
|
||||
|
||||
/* Execute */
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'clients.css', 'nexus' ) );
|
||||
\IPS\Output::i()->sidebar['enabled'] = FALSE;
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* View List
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
$where = array( array( 'ps_member=?', \IPS\Member::loggedIn()->member_id ) );
|
||||
$parentContacts = \IPS\nexus\Customer::loggedIn()->parentContacts();
|
||||
if ( count( $parentContacts ) )
|
||||
{
|
||||
$or = array();
|
||||
foreach ( $parentContacts as $contact )
|
||||
{
|
||||
$where[0][0] .= ' OR ' . \IPS\Db::i()->in( 'ps_id', $contact->purchaseIds() );
|
||||
}
|
||||
}
|
||||
$where[] = array( 'ps_show=1' );
|
||||
|
||||
$purchases = array();
|
||||
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_purchases', $where ), 'IPS\nexus\Purchase' ) as $purchase )
|
||||
{
|
||||
$purchases[ $purchase->parent ][ $purchase->id ] = $purchase;
|
||||
}
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('clients')->template( \IPS\Theme::i()->getTemplate('clients')->purchases( $purchases ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* View
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function view()
|
||||
{
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('clients')->template( \IPS\Theme::i()->getTemplate('clients')->purchase( $this->purchase ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Extra
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function extra()
|
||||
{
|
||||
if ( $output = $this->purchase->clientAreaAction() )
|
||||
{
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->output = $output;
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('clients')->template( $output );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->redirect( $this->purchase->url() );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Renew
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function renew()
|
||||
{
|
||||
$cycles = $this->purchase->canRenewUntil( NULL, TRUE );
|
||||
if ( $cycles === FALSE )
|
||||
{
|
||||
\IPS\Output::i()->error( 'you_cannot_renew', '2X212/4', 403, '' );
|
||||
}
|
||||
elseif ( $cycles === 1 )
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
}
|
||||
|
||||
$term = $this->purchase->renewals->getTerm();
|
||||
if ( $term['term'] > 1 )
|
||||
{
|
||||
$suffix = '× ' . $this->purchase->renewals->getTermUnit();
|
||||
}
|
||||
else
|
||||
{
|
||||
switch( $term['unit'] )
|
||||
{
|
||||
case 'd':
|
||||
$suffix = \IPS\Member::loggedIn()->language()->addToStack('days');
|
||||
break;
|
||||
case 'm':
|
||||
$suffix = \IPS\Member::loggedIn()->language()->addToStack('months');
|
||||
break;
|
||||
case 'y':
|
||||
$suffix = \IPS\Member::loggedIn()->language()->addToStack('years');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->class = 'ipsForm_vertical';
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'renew_for', 1, TRUE, array( 'min' => 1, 'max' => $cycles === TRUE ? NULL : $cycles ), NULL, NULL, $suffix ) );
|
||||
if( $values = $form->values() or $cycles === 1 )
|
||||
{
|
||||
if ( $pendingInvoice = $this->purchase->invoice_pending )
|
||||
{
|
||||
if ( count( $pendingInvoice->items ) === 1 )
|
||||
{
|
||||
foreach ( $pendingInvoice->items as $item )
|
||||
{
|
||||
if ( $item instanceof \IPS\nexus\Invoice\Item\Renewal and $item->id === $this->purchase->id and $item->quantity === ( $cycles === 1 ? 1 : $values['renew_for'] ) )
|
||||
{
|
||||
\IPS\Output::i()->redirect( $pendingInvoice->checkoutUrl() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$pendingInvoice->status = $pendingInvoice::STATUS_CANCELED;
|
||||
$pendingInvoice->save();
|
||||
$pendingInvoice->member->log( 'invoice', array( 'type' => 'status', 'new' => 'canc', 'id' => $pendingInvoice->id, 'title' => $pendingInvoice->title ) );
|
||||
}
|
||||
|
||||
$invoice = new \IPS\nexus\Invoice;
|
||||
$invoice->member = \IPS\nexus\Customer::loggedIn();
|
||||
$invoice->currency = $this->purchase->renewals->cost->currency;
|
||||
$invoice->addItem( \IPS\nexus\Invoice\Item\Renewal::create( $this->purchase, $cycles === 1 ? 1 : $values['renew_for'] ) );
|
||||
$invoice->save();
|
||||
|
||||
$this->purchase->invoice_pending = $invoice;
|
||||
$this->purchase->save();
|
||||
|
||||
\IPS\Output::i()->redirect( $invoice->checkoutUrl() );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('clients')->template( $form );
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function cancel()
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
|
||||
if ( !$this->purchase->canCancel() )
|
||||
{
|
||||
\IPS\Output::i()->error( 'you_cannot_cancel', '2X212/5', 403, '' );
|
||||
}
|
||||
|
||||
$this->purchase->member->log( 'purchase', array( 'type' => 'info', 'id' => $this->purchase->id, 'name' => $this->purchase->name, 'info' => 'remove_renewals' ) );
|
||||
|
||||
$this->purchase->renewals = NULL;
|
||||
$this->purchase->can_reactivate = TRUE;
|
||||
$this->purchase->save();
|
||||
|
||||
\IPS\Output::i()->redirect( $this->purchase->url() );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Referrals
|
||||
* @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 15 Aug 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\front\clients;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Referrals
|
||||
*/
|
||||
class _referrals extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
if ( mb_strtolower( $_SERVER['REQUEST_METHOD'] ) == 'get' and \IPS\Settings::i()->nexus_https and \IPS\Request::i()->url()->data['scheme'] !== 'https' )
|
||||
{
|
||||
\IPS\Output::i()->redirect( new \IPS\Http\Url( preg_replace( '/^http:/', 'https:', \IPS\Request::i()->url() ) ) );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'clients.css', 'nexus' ) );
|
||||
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'front_clients.js', 'nexus', 'front' ) );
|
||||
\IPS\Output::i()->sidebar['enabled'] = FALSE;
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* View List
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
\IPS\Output::i()->breadcrumb[] = array( \IPS\Http\Url::internal( 'app=nexus&module=clients&controller=referrals', 'front', 'clientsreferrals', array(), \IPS\Settings::i()->nexus_https ), \IPS\Member::loggedIn()->language()->addToStack('client_referrals') );
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('client_referrals');
|
||||
\IPS\Output::i()->sidebar['enabled'] = FALSE;
|
||||
|
||||
$url = \IPS\Http\Url::internal( 'app=nexus&module=promotion&controller=referral&id=' . \IPS\Member::loggedIn()->member_id, 'front', 'referral' );
|
||||
if ( isset( \IPS\Request::i()->target ) )
|
||||
{
|
||||
$url = $url->setQueryString( 'direct', base64_encode( \IPS\Request::i()->target ) );
|
||||
}
|
||||
|
||||
$rules = new \IPS\nexus\CommissionRule\Iterator( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_referral_rules' ), 'IPS\nexus\CommissionRule' ), \IPS\Member::loggedIn() );
|
||||
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('clients')->template( \IPS\Theme::i()->getTemplate('clients')->referrals( $url, $rules ) );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user