Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -12,155 +12,173 @@
|
||||
namespace IPS\nexus\modules\front\clients;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use DomainException;
|
||||
use IPS\Db;
|
||||
use IPS\Dispatcher\Controller;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\Checkbox;
|
||||
use IPS\Helpers\Form\Email;
|
||||
use IPS\Helpers\Form\Node;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Member;
|
||||
use IPS\MFA\MFAHandler;
|
||||
use IPS\nexus\Customer;
|
||||
use IPS\nexus\Customer\AlternativeContact;
|
||||
use IPS\Output;
|
||||
use IPS\Request;
|
||||
use IPS\Session;
|
||||
use IPS\Theme;
|
||||
use UnderflowException;
|
||||
use function defined;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alternative Contacts
|
||||
*/
|
||||
class _alternatives extends \IPS\Dispatcher\Controller
|
||||
class alternatives extends Controller
|
||||
{
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
public function execute() : void
|
||||
{
|
||||
if ( !\IPS\Member::loggedIn()->member_id )
|
||||
if ( !Member::loggedIn()->member_id )
|
||||
{
|
||||
\IPS\Output::i()->error( 'no_module_permission_guest', '2X237/1', 403, '' );
|
||||
Output::i()->error( 'no_module_permission_guest', '2X237/1', 403, '' );
|
||||
}
|
||||
|
||||
\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' ), \IPS\Member::loggedIn()->language()->addToStack('client_alternatives') );
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('client_alternatives');
|
||||
\IPS\Output::i()->sidebar['enabled'] = FALSE;
|
||||
|
||||
if ( $output = \IPS\MFA\MFAHandler::accessToArea( 'nexus', 'Alternatives', \IPS\Http\Url::internal( 'app=nexus&module=clients&controller=alternatives', 'front', 'clientsalternatives' ) ) )
|
||||
|
||||
Output::i()->cssFiles = array_merge( Output::i()->cssFiles, Theme::i()->css( 'clients.css', 'nexus' ) );
|
||||
Output::i()->breadcrumb[] = array( Url::internal( 'app=nexus&module=clients&controller=alternatives', 'front', 'clientsalternatives' ), Member::loggedIn()->language()->addToStack('client_alternatives') );
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack('client_alternatives');
|
||||
Output::i()->sidebar['enabled'] = FALSE;
|
||||
|
||||
if ( $output = MFAHandler::accessToArea( 'nexus', 'Alternatives', Url::internal( 'app=nexus&module=clients&controller=alternatives', 'front', 'clientsalternatives' ) ) )
|
||||
{
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('clients')->alternatives( TRUE ) . $output;
|
||||
Output::i()->output = Theme::i()->getTemplate('clients')->alternatives( TRUE ) . $output;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* View List
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
protected function manage() : void
|
||||
{
|
||||
foreach ( \IPS\nexus\Customer::loggedIn()->alternativeContacts() as $contact )
|
||||
foreach ( Customer::loggedIn()->alternativeContacts() as $contact )
|
||||
{
|
||||
$contact->alt_id;
|
||||
}
|
||||
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('clients')->alternatives();
|
||||
|
||||
Output::i()->output = Theme::i()->getTemplate('clients')->alternatives();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add/Edit
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function form()
|
||||
protected function form() : void
|
||||
{
|
||||
$existing = NULL;
|
||||
if ( isset( \IPS\Request::i()->id ) )
|
||||
if ( isset( 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() );
|
||||
$existing = AlternativeContact::constructFromData( Db::i()->select( '*', 'nexus_alternate_contacts', array( 'main_id=? AND alt_id=?', Customer::loggedIn()->member_id, Request::i()->id ) )->first() );
|
||||
}
|
||||
catch ( \UnderflowException $e ) {}
|
||||
catch ( UnderflowException ) {}
|
||||
}
|
||||
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->class = 'ipsForm_vertical';
|
||||
|
||||
$form = new Form;
|
||||
$form->class = 'ipsForm--vertical ipsForm--edit-alernatives';
|
||||
if ( !$existing )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\Email( 'altcontact_email', NULL, TRUE, array(), function( $val )
|
||||
$form->add( new Email( 'altcontact_email', NULL, TRUE, array(), function( $val )
|
||||
{
|
||||
if( \IPS\Member::loggedIn()->email == $val )
|
||||
if( Member::loggedIn()->email == $val )
|
||||
{
|
||||
throw new \DomainException('altcontact_email_self');
|
||||
throw new DomainException('altcontact_email_self');
|
||||
}
|
||||
|
||||
$member = \IPS\Member::load( $val, 'email' );
|
||||
$member = Member::load( $val, 'email' );
|
||||
if ( !$member->member_id )
|
||||
{
|
||||
throw new \DomainException('altcontact_email_error');
|
||||
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');
|
||||
Db::i()->select( '*', 'nexus_alternate_contacts', array( 'main_id=? AND alt_id=?', Customer::loggedIn()->member_id, $member->member_id ) )->first();
|
||||
throw new DomainException('altcontact_already_exists');
|
||||
}
|
||||
catch ( \UnderflowException $e ) {}
|
||||
catch ( UnderflowException ) {}
|
||||
} ) );
|
||||
}
|
||||
$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 ) );
|
||||
$form->add( new Node( 'altcontact_purchases', $existing ? iterator_to_array( $existing->purchases ) : NULL, FALSE, array( 'class' => 'IPS\nexus\Purchase', 'forceOwner' => Member::loggedIn(), 'multiple' => TRUE ) ) );
|
||||
$form->add( new 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'] ) );
|
||||
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'] ?: array() ), 'billing' => $values['altcontact_billing'] ) );
|
||||
}
|
||||
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 = new AlternativeContact;
|
||||
$altContact->main_id = Customer::loggedIn();
|
||||
$altContact->alt_id = Member::load( $values['altcontact_email'], 'email' );
|
||||
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'] ?: array() ), 'billing' => $values['altcontact_billing'] ) );
|
||||
}
|
||||
$altContact->purchases = $values['altcontact_purchases'] ? $values['altcontact_purchases'] : array();
|
||||
$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' ) );
|
||||
|
||||
Output::i()->redirect( Url::internal( 'app=nexus&module=clients&controller=alternatives', 'front', 'clientsalternatives' ) );
|
||||
}
|
||||
|
||||
if( \IPS\Request::i()->isAjax() )
|
||||
if( Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->sendOutput( $form->customTemplate( array( \IPS\Theme::i()->getTemplate( 'forms', 'core' ), 'popupTemplate' ) ) );
|
||||
Output::i()->sendOutput( $form->customTemplate( array( Theme::i()->getTemplate( 'forms', 'core' ), 'popupTemplate' ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->output = $form;
|
||||
}
|
||||
Output::i()->output = $form;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function delete()
|
||||
protected function delete() : void
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
|
||||
Session::i()->csrfCheck();
|
||||
|
||||
/* Make sure the user confirmed the deletion */
|
||||
\IPS\Request::i()->confirmedDelete();
|
||||
|
||||
Request::i()->confirmedDelete();
|
||||
|
||||
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 = AlternativeContact::constructFromData( Db::i()->select( '*', 'nexus_alternate_contacts', array( 'main_id=? AND alt_id=?', Customer::loggedIn()->member_id, 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 ) );
|
||||
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' ) );
|
||||
catch (UnderflowException ) {}
|
||||
|
||||
Output::i()->redirect( Url::internal( 'app=nexus&module=clients&controller=alternatives', 'front', 'clientsalternatives' ) );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user