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,53 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Comission Rules
|
||||
* @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
|
||||
* @since 15 Aug 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\admin\customers;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Comission Rules
|
||||
*/
|
||||
class _commissionrules extends \IPS\Node\Controller
|
||||
{
|
||||
/**
|
||||
* Node Class
|
||||
*/
|
||||
protected $nodeClass = 'IPS\nexus\CommissionRule';
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'commission_rules_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function manage()
|
||||
{
|
||||
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'forms', 'core' )->blurb( 'commission_rules_blurb', TRUE, TRUE );
|
||||
return parent::manage();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief 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
|
||||
* @since 12 May 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\admin\customers;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* fields
|
||||
*/
|
||||
class _fields extends \IPS\Node\Controller
|
||||
{
|
||||
/**
|
||||
* Node Class
|
||||
*/
|
||||
protected $nodeClass = 'IPS\nexus\Customer\CustomField';
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'customer_fields_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
}
|
||||
Whitespace-only changes.
@@ -0,0 +1,480 @@
|
||||
<?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 11 Feb 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\admin\customers;
|
||||
|
||||
/* 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
|
||||
{
|
||||
/**
|
||||
* View
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'purchases_view' );
|
||||
|
||||
if ( \IPS\Request::i()->do !== 'findHostingAccount' )
|
||||
{
|
||||
try
|
||||
{
|
||||
$this->purchase = \IPS\nexus\Purchase::load( \IPS\Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X195/2', 404, '' );
|
||||
}
|
||||
|
||||
|
||||
\IPS\Output::i()->title = $this->purchase->name . " (#{$this->purchase->id})";
|
||||
}
|
||||
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'purchases.css', 'nexus', 'admin' ) );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* View
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function view()
|
||||
{
|
||||
/* Popup view */
|
||||
if ( \IPS\Request::i()->isAjax() and isset( \IPS\Request::i()->hovercard ) )
|
||||
{
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'purchases' )->hovercard( $this->purchase );
|
||||
return;
|
||||
}
|
||||
|
||||
/* Create children tree */
|
||||
$children = \IPS\nexus\Purchase::tree( $this->purchase->acpUrl(), array(), "p{$this->purchase->id}", $this->purchase, FALSE );
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->output = $children;
|
||||
return;
|
||||
}
|
||||
|
||||
/* Create associated invoices table */
|
||||
try
|
||||
{
|
||||
$originalInvoice = $this->purchase->original_invoice;
|
||||
$invoices = \IPS\nexus\Invoice::table( array( array( 'i_id=? OR ' . \IPS\Db::i()->findInSet( 'i_renewal_ids', array( $this->purchase->id ) ), $originalInvoice->id ) ), $this->purchase->acpUrl(), "p.{$this->purchase->id}" );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
$invoices = \IPS\nexus\Invoice::table( array( array( \IPS\Db::i()->findInSet( 'i_renewal_ids', array( $this->purchase->id ) ) ) ), $this->purchase->acpUrl(), "p.{$this->purchase->id}" );
|
||||
}
|
||||
$invoices->filters = array(
|
||||
'paid' => array( 'i_status=?', \IPS\nexus\Invoice::STATUS_PAID )
|
||||
);
|
||||
$invoices->advancedSearch = array(
|
||||
'i_status' => array( \IPS\Helpers\Table\SEARCH_SELECT, array( 'options' => \IPS\nexus\Invoice::statuses(), 'multiple' => TRUE ) ),
|
||||
'i_total' => \IPS\Helpers\Table\SEARCH_NUMERIC,
|
||||
'i_date' => \IPS\Helpers\Table\SEARCH_DATE_RANGE,
|
||||
);
|
||||
|
||||
/* Custom Fields */
|
||||
$customFields = array();
|
||||
foreach ( $this->purchase->custom_fields as $k => $v )
|
||||
{
|
||||
try
|
||||
{
|
||||
$customFields[ $k ] = \IPS\nexus\Package\CustomField::load( $k )->displayValue( $v );
|
||||
}
|
||||
catch ( \OutOfRangeException $e ) { }
|
||||
}
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->sidebar['actions'] = $this->purchase->buttons();
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'purchases' )->view( $this->purchase, $children, $invoices, $customFields );
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function edit()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'purchases_edit' );
|
||||
|
||||
/* Work stuff out */
|
||||
$renewals = $this->purchase->renewals ?: NULL;
|
||||
$groupedChildren = array();
|
||||
if ( $renewals and \IPS\Db::i()->select( 'COUNT(*)', 'nexus_purchases', array( 'ps_parent=? AND ps_grouped_renewals<>?', $this->purchase->id, '' ) )->first() )
|
||||
{
|
||||
$costPerDay = $this->purchase->renewals->costPerDay()->amount;
|
||||
foreach ( $this->purchase->children() as $child )
|
||||
{
|
||||
if ( $child->grouped_renewals )
|
||||
{
|
||||
$groupedChildren[] = $child;
|
||||
$childGroupedRenewals = $child->grouped_renewals;
|
||||
$childGroupedRenewalTerm = new \IPS\nexus\Purchase\RenewalTerm( new \IPS\nexus\Money( $childGroupedRenewals['price'], $this->purchase->renewals->cost->currency ), new \DateInterval( 'P' . $childGroupedRenewals['term'] . mb_strtoupper( $childGroupedRenewals['unit'] ) ) );
|
||||
$costPerDay -= $childGroupedRenewalTerm->costPerDay()->amount;
|
||||
}
|
||||
}
|
||||
$renewals = new \IPS\nexus\Purchase\RenewalTerm( new \IPS\nexus\Money( $costPerDay * $renewals->days(), $this->purchase->renewals->cost->currency ), $renewals->interval );
|
||||
}
|
||||
|
||||
/* Build form */
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$this->purchase->acpEdit( $form, $renewals );
|
||||
|
||||
/* Handle submissions */
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
/* Ungroup children */
|
||||
foreach ( $groupedChildren as $child )
|
||||
{
|
||||
$child->ungroupFromParent();
|
||||
}
|
||||
|
||||
/* Update purchase */
|
||||
$this->purchase->acpEditSave( $values );
|
||||
|
||||
/* Regroup children */
|
||||
foreach ( $groupedChildren as $child )
|
||||
{
|
||||
$child->groupWithParent();
|
||||
}
|
||||
|
||||
/* Log */
|
||||
$this->purchase->member->log( 'purchase', array( 'type' => 'info', 'id' => $this->purchase->id, 'name' => $this->purchase->name ) );
|
||||
|
||||
/* Redirect */
|
||||
$this->_redirect();
|
||||
}
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->output = $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transfer
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function transfer()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'purchases_transfer' );
|
||||
if ( $this->purchase->grouped_renewals )
|
||||
{
|
||||
\IPS\Output::i()->error( 'not_with_grouped', '2X195/6', 403, '' );
|
||||
}
|
||||
|
||||
/* Build form */
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->add( new \IPS\Helpers\Form\Member( 'ps_member', NULL, TRUE ) );
|
||||
|
||||
/* Handle submissions */
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
/* Transfer */
|
||||
$previousOwner = $this->purchase->member;
|
||||
$this->purchase->transfer( $values['ps_member'] );
|
||||
|
||||
/* Log */
|
||||
$previousOwner->log( 'purchase', array( 'type' => 'transfer_from', 'id' => $this->purchase->id, 'name' => $this->purchase->name, 'to' => $values['ps_member']->member_id ) );
|
||||
$this->purchase->member->log( 'purchase', array( 'type' => 'transfer_to', 'id' => $this->purchase->id, 'name' => $this->purchase->name, 'from' => $previousOwner->member_id ) );
|
||||
|
||||
/* Redirect */
|
||||
$this->_redirect();
|
||||
}
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->output = $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renew
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function renew()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'purchases_edit', 'nexus', 'payments' );
|
||||
if ( $this->purchase->grouped_renewals )
|
||||
{
|
||||
\IPS\Output::i()->error( 'not_with_grouped', '2X195/7', 403, '' );
|
||||
}
|
||||
|
||||
/* If this purchase has renewal term, we cannot generate a renewal invoice */
|
||||
if ( !$this->purchase->renewals )
|
||||
{
|
||||
\IPS\Output::i()->error( 'purchase_no_renew', '2X195/3', 403, '' );
|
||||
}
|
||||
if ( !$this->purchase->expire )
|
||||
{
|
||||
\IPS\Output::i()->error( 'purchase_no_expire', '1X195/C', 403, '' );
|
||||
}
|
||||
|
||||
/* Build form */
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$cycles = $this->purchase->canRenewUntil( NULL, TRUE, TRUE );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'renew_cycles', 1, TRUE, array( 'min' => 1, 'max' => ( $cycles === TRUE ? NULL : $cycles ) ) ) );
|
||||
|
||||
/* Handle submissions */
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
/* Generate Invoice */
|
||||
$invoice = new \IPS\nexus\Invoice;
|
||||
$invoice->currency = $this->purchase->renewal_currency;
|
||||
$invoice->member = $this->purchase->member;
|
||||
$invoice->addItem( \IPS\nexus\Invoice\Item\Renewal::create( $this->purchase, $values['renew_cycles'] ) );
|
||||
$invoice->save();
|
||||
$invoice->sendNotification();
|
||||
|
||||
/* Update the purchase */
|
||||
$this->purchase->invoice_pending = $invoice;
|
||||
$this->purchase->save();
|
||||
|
||||
/* Take us to that invoice */
|
||||
\IPS\Output::i()->redirect( $invoice->acpUrl() );
|
||||
}
|
||||
|
||||
/* If this purchase already has an unpaid renewal invoice, display a warning */
|
||||
if ( $this->purchase->invoice_pending )
|
||||
{
|
||||
/* Which will be a proper warning if that invoice is still pending */
|
||||
if ( $this->purchase->invoice_pending->status === \IPS\nexus\Invoice::STATUS_PENDING )
|
||||
{
|
||||
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'global', 'core' )->message( \IPS\Member::loggedIn()->language()->addToStack('warn_renew_invoice_pending', FALSE, array( 'sprintf' => array( $this->purchase->invoice_pending->acpUrl() ) ) ), 'warning', NULL, FALSE, TRUE );
|
||||
}
|
||||
/* Or just informational if it is canceled or expired */
|
||||
elseif ( $this->purchase->invoice_pending->status !== \IPS\nexus\Invoice::STATUS_PAID )
|
||||
{
|
||||
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'global', 'core' )->message( \IPS\Member::loggedIn()->language()->addToStack('info_renew_invoice_pending', FALSE, array( 'sprintf' => array( $this->purchase->invoice_pending->acpUrl() ) ) ), 'information', NULL, FALSE, TRUE );
|
||||
}
|
||||
}
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->output .= $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function cancel()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'purchases_cancel' );
|
||||
if ( $this->purchase->grouped_renewals )
|
||||
{
|
||||
\IPS\Output::i()->error( 'not_with_grouped', '2X195/8', 403, '' );
|
||||
}
|
||||
|
||||
/* What options are available for cancelling? */
|
||||
$options = array();
|
||||
if ( $this->purchase->renewals )
|
||||
{
|
||||
$options['no_renew'] = 'cancel_type_no_renew';
|
||||
}
|
||||
$options['cancel'] = 'cancel_type_cancel';
|
||||
|
||||
/* Build form */
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'cancel_type', 'no_renew', FALSE, array(
|
||||
'options' => $options,
|
||||
) ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'ps_can_reactivate', FALSE ) );
|
||||
|
||||
/* Handle submissions */
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
/* Update purchase and log */
|
||||
if ( $values['cancel_type'] === 'no_renew' )
|
||||
{
|
||||
$this->purchase->renewals = NULL;
|
||||
$this->purchase->member->log( 'purchase', array( 'type' => 'info', 'id' => $this->purchase->id, 'name' => $this->purchase->name, 'info' => 'remove_renewals' ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->purchase->cancelled = TRUE;
|
||||
$this->purchase->member->log( 'purchase', array( 'type' => 'cancel', 'id' => $this->purchase->id, 'name' => $this->purchase->name ) );
|
||||
}
|
||||
$this->purchase->can_reactivate = $values['ps_can_reactivate'];
|
||||
$this->purchase->save();
|
||||
|
||||
/* Redirect */
|
||||
$this->_redirect();
|
||||
}
|
||||
|
||||
/* Display form */
|
||||
\IPS\Output::i()->output = $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reactivate
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function reactivate()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'purchases_cancel' );
|
||||
if ( $this->purchase->grouped_renewals )
|
||||
{
|
||||
\IPS\Output::i()->error( 'not_with_grouped', '2X195/9', 403, '' );
|
||||
}
|
||||
|
||||
$this->purchase->cancelled = FALSE;
|
||||
$this->purchase->save();
|
||||
$this->purchase->member->log( 'purchase', array( 'type' => 'uncancel', 'id' => $this->purchase->id, 'name' => $this->purchase->name ) );
|
||||
|
||||
$this->_redirect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function delete()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'purchases_delete' );
|
||||
|
||||
if ( $this->purchase->grouped_renewals )
|
||||
{
|
||||
\IPS\Output::i()->error( 'not_with_grouped', '2X195/A', 403, '' );
|
||||
}
|
||||
|
||||
$this->purchase->member->log( 'purchase', array( 'type' => 'delete', 'id' => $this->purchase->id, 'name' => $this->purchase->name ) );
|
||||
$this->purchase->delete();
|
||||
|
||||
\IPS\Output::i()->redirect( $this->purchase->member->acpUrl() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Extra
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function extra()
|
||||
{
|
||||
if ( $output = $this->purchase->acpAction() )
|
||||
{
|
||||
\IPS\Output::i()->output = $output;
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->redirect( $this->purchase->acpUrl() );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Group
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function group()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'purchases_edit' );
|
||||
try
|
||||
{
|
||||
$this->purchase->groupWithParent();
|
||||
$this->purchase->member->log( 'purchase', array( 'type' => 'group', 'id' => $this->purchase->id, 'name' => $this->purchase->name ) );
|
||||
}
|
||||
catch ( \LogicException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'grouperr_' . $e->getMessage(), '1X195/4', 403, '' );
|
||||
}
|
||||
$this->_redirect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Ungroup
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function ungroup()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'purchases_edit' );
|
||||
try
|
||||
{
|
||||
$this->purchase->ungroupFromParent();
|
||||
$this->purchase->member->log( 'purchase', array( 'type' => 'ungroup', 'id' => $this->purchase->id, 'name' => $this->purchase->name ) );
|
||||
}
|
||||
catch ( \LogicException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( '', '1X195/5', 403, '' );
|
||||
}
|
||||
$this->_redirect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _redirect()
|
||||
{
|
||||
if ( isset( \IPS\Request::i()->r ) )
|
||||
{
|
||||
switch ( mb_substr( \IPS\Request::i()->r, 0, 1 ) )
|
||||
{
|
||||
case 'p':
|
||||
try
|
||||
{
|
||||
\IPS\Output::i()->redirect( \IPS\nexus\Purchase::load( $this->purchase->parent )->acpUrl() );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->redirect( $this->purchase->member->acpUrl() );
|
||||
}
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
\IPS\Output::i()->redirect( $this->purchase->acpUrl() );
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
\IPS\Output::i()->redirect( $this->purchase->member->acpUrl() );
|
||||
break;
|
||||
|
||||
case 's':
|
||||
\IPS\Output::i()->redirect( \IPS\nexus\Support\Request::load( mb_substr( \IPS\Request::i()->r, 2 ) )->acpUrl() );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
\IPS\Output::i()->redirect( $this->purchase->acpUrl() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Find Hosting Account
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function findHostingAccount()
|
||||
{
|
||||
try
|
||||
{
|
||||
\IPS\Output::i()->redirect( \IPS\nexus\Purchase::load( \IPS\Db::i()->select( 'ps_id', 'nexus_hosting_accounts', array( 'account_username=?', \IPS\Request::i()->username ) )->first() )->acpUrl() );
|
||||
}
|
||||
catch ( \UnderflowException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X195/B', 404, '' );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief referralbanners
|
||||
* @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
|
||||
* @since 18 Aug 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\admin\customers;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* referralbanners
|
||||
*/
|
||||
class _referralbanners extends \IPS\Node\Controller
|
||||
{
|
||||
/**
|
||||
* Node Class
|
||||
*/
|
||||
protected $nodeClass = 'IPS\nexus\ReferralBanner';
|
||||
|
||||
/**
|
||||
* Title can contain HTML?
|
||||
*/
|
||||
public $_titleHtml = TRUE;
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'referralbanners_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function manage()
|
||||
{
|
||||
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'forms', 'core' )->blurb( 'referral_banners_blurb', TRUE, TRUE );
|
||||
return parent::manage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Form
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function form()
|
||||
{
|
||||
parent::form();
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('referral_banners');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?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\admin\customers;
|
||||
|
||||
/* 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
|
||||
{
|
||||
/**
|
||||
* Call
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __call( $method, $args )
|
||||
{
|
||||
$tabs = array();
|
||||
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'referrals_manage' ) )
|
||||
{
|
||||
$tabs['refersettings'] = 'settings';
|
||||
}
|
||||
if( \IPS\Settings::i()->cm_ref_on and \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'referrals_commission_rules' ) )
|
||||
{
|
||||
$tabs['commissionrules'] = 'commission_rules';
|
||||
}
|
||||
if( \IPS\Settings::i()->cm_ref_on and \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'referrals_banners' ) )
|
||||
{
|
||||
$tabs['referralbanners'] = 'referral_banners';
|
||||
}
|
||||
if ( isset( \IPS\Request::i()->tab ) and isset( $tabs[ \IPS\Request::i()->tab ] ) )
|
||||
{
|
||||
$activeTab = \IPS\Request::i()->tab;
|
||||
}
|
||||
else
|
||||
{
|
||||
$_tabs = array_keys( $tabs ) ;
|
||||
$activeTab = array_shift( $_tabs );
|
||||
}
|
||||
|
||||
$classname = 'IPS\nexus\modules\admin\customers\\' . $activeTab;
|
||||
$class = new $classname;
|
||||
$class->url = \IPS\Http\Url::internal("app=nexus&module=customers&controller=referrals&tab={$activeTab}");
|
||||
$class->execute();
|
||||
|
||||
if ( $method !== 'manage' or \IPS\Request::i()->isAjax() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__nexus_customers_referrals');
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->tabs( $tabs, $activeTab, \IPS\Output::i()->output, \IPS\Http\Url::internal( "app=nexus&module=customers&controller=referrals" ) );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Referral Settings
|
||||
* @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\admin\customers;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Referral Settings
|
||||
*/
|
||||
class _refersettings extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* Manage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$tabsKey = md5( \IPS\Http\Url::internal("app=nexus&module=customers&controller=referrals") );
|
||||
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'cm_ref_on', \IPS\Settings::i()->cm_ref_on, FALSE, array( 'togglesOn' => array( 'nexus_com_rules' ) ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'nexus_com_rules', \IPS\Settings::i()->nexus_com_rules, FALSE, array( 'togglesOff' => array( 'nexus_com_rules_alt' ) ), NULL, NULL, NULL, 'nexus_com_rules' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Translatable( 'nexus_com_rules_alt', NULL, FALSE, array( 'app' => 'nexus', 'key' => 'nexus_com_rules_val', 'editor' => array( 'app' => 'core', 'key' => 'Admin', 'autoSaveKey' => 'nexus_com_rules_alt', 'attachIds' => array( NULL, NULL, 'nexus_com_rules_alt' ) ) ), NULL, NULL, NULL, 'nexus_com_rules_alt' ) );
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
\IPS\Lang::saveCustom( 'nexus', 'nexus_com_rules_val', $values['nexus_com_rules_alt'] );
|
||||
unset( $values['nexus_com_rules_alt'] );
|
||||
|
||||
$form->saveAsSettings( $values );
|
||||
|
||||
/* Clear guest page caches */
|
||||
\IPS\Data\Cache::i()->clearAll();
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=customers&controller=referrals') );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->output = $form;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Customer Search
|
||||
* @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 May 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\admin\customers;
|
||||
|
||||
/* 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 Search
|
||||
*/
|
||||
class _search extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'customers_view' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* View Customers
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
$table = new \IPS\Helpers\Table\Db( 'nexus_customers', \IPS\Http\Url::internal('app=nexus&module=customers&controller=search') );
|
||||
$table->langPrefix = 'customerTable_';
|
||||
$table->joins = array(
|
||||
array(
|
||||
'select' => 'core_members.*',
|
||||
'from' => 'core_members',
|
||||
'where' => 'core_members.member_id=nexus_customers.member_id'
|
||||
),
|
||||
array(
|
||||
'select' => 'address',
|
||||
'from' => 'nexus_customer_addresses',
|
||||
'where' => 'nexus_customer_addresses.member=nexus_customers.member_id AND primary_billing=1'
|
||||
)
|
||||
);
|
||||
$table->include = array( 'photo', 'cm_last_name', 'cm_first_name', 'email', 'address' );
|
||||
$table->parsers = array(
|
||||
'photo' => function( $val, $row )
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate('customers')->rowPhoto( \IPS\Member::constructFromData( $row ) );
|
||||
},
|
||||
'address' => function( $val )
|
||||
{
|
||||
return \IPS\GeoLocation::buildFromJson( $val );
|
||||
}
|
||||
);
|
||||
$table->noSort = array( 'photo', 'address' );
|
||||
$table->quickSearch = 'email';
|
||||
|
||||
$table->advancedSearch = array(
|
||||
'cm_first_name' => \IPS\Helpers\Table\SEARCH_CONTAINS_TEXT,
|
||||
'cm_last_name' => \IPS\Helpers\Table\SEARCH_CONTAINS_TEXT,
|
||||
'email' => \IPS\Helpers\Table\SEARCH_CONTAINS_TEXT,
|
||||
'name' => \IPS\Helpers\Table\SEARCH_CONTAINS_TEXT
|
||||
);
|
||||
foreach ( \IPS\nexus\Customer\CustomField::roots() as $field )
|
||||
{
|
||||
switch ( $field->type )
|
||||
{
|
||||
case 'Checkbox':
|
||||
case 'YesNo':
|
||||
$table->advancedSearch[ $field->column ] = \IPS\Helpers\Table\SEARCH_BOOL;
|
||||
break;
|
||||
|
||||
case 'CheckboxSet':
|
||||
case 'Select':
|
||||
case 'Radio':
|
||||
$table->advancedSearch[ $field->column ] = array( \IPS\Helpers\Table\SEARCH_SELECT, array( 'options' => json_decode( $field->extra ), 'multiple' => $field->multiple ) );
|
||||
break;
|
||||
|
||||
case 'Date':
|
||||
$table->advancedSearch[ $field->column ] = \IPS\Helpers\Table\SEARCH_DATE_RANGE;
|
||||
break;
|
||||
|
||||
case 'Member':
|
||||
$table->advancedSearch[ $field->column ] = array( \IPS\Helpers\Table\SEARCH_MEMBER, array( 'multiple' => $field->multiple ) );
|
||||
break;
|
||||
|
||||
case 'Number':
|
||||
$table->advancedSearch[ $field->column ] = \IPS\Helpers\Table\SEARCH_NUMERIC;
|
||||
break;
|
||||
|
||||
default:
|
||||
$table->advancedSearch[ $field->column ] = \IPS\Helpers\Table\SEARCH_CONTAINS_TEXT;
|
||||
break;
|
||||
}
|
||||
|
||||
\IPS\Member::loggedIn()->language()->words[ 'customerTable_field_' . $field->id ] = $field->_title;
|
||||
|
||||
$table->parsers[ $field->column ] = array( $field, 'displayValue' );
|
||||
}
|
||||
|
||||
$table->rowButtons = function( $row )
|
||||
{
|
||||
return array(
|
||||
'view' => array(
|
||||
'icon' => 'search',
|
||||
'title' => 'view',
|
||||
'link' => \IPS\Http\Url::internal("app=nexus&module=customers&controller=view&id={$row['member_id']}"),
|
||||
),
|
||||
);
|
||||
};
|
||||
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__nexus_customers');
|
||||
\IPS\Output::i()->output = (string) $table;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,235 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Hosting Server Errors
|
||||
* @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 Aug 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\admin\hosting;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hosting Server Errors
|
||||
*/
|
||||
class _errors extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'errors_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
/* Create the table */
|
||||
$table = new \IPS\Helpers\Table\Db( 'nexus_hosting_errors', \IPS\Http\Url::internal( 'app=nexus&module=hosting&controller=errors' ) );
|
||||
$table->include = array( 'e_time', 'e_server', 'e_account', 'e_function', 'e_message' );
|
||||
$table->langPrefix = 'hosting_';
|
||||
if ( !$table->sortBy )
|
||||
{
|
||||
$table->sortBy = 'e_time';
|
||||
$table->sortDirection = 'asc';
|
||||
}
|
||||
|
||||
/* Parsers */
|
||||
$table->parsers = array(
|
||||
'e_time' => function( $val )
|
||||
{
|
||||
return \IPS\DateTime::ts( $val );
|
||||
},
|
||||
'e_server' => function( $val )
|
||||
{
|
||||
try
|
||||
{
|
||||
return \IPS\nexus\Hosting\Server::load( $val )->hostname;
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
return '';
|
||||
}
|
||||
},
|
||||
'e_function' => function ( $val, $row )
|
||||
{
|
||||
$details = json_decode( $row['e_extra'], TRUE );
|
||||
if ( isset( $details['function'] ) )
|
||||
{
|
||||
return $details['function'];
|
||||
}
|
||||
return '';
|
||||
},
|
||||
'e_account' => function ( $val, $row )
|
||||
{
|
||||
$details = json_decode( $row['e_extra'], TRUE );
|
||||
$username = NULL;
|
||||
if ( isset( $details['params']['user'] ) )
|
||||
{
|
||||
$username = $details['params']['user'];
|
||||
}
|
||||
if ( isset( $details['params']['username'] ) )
|
||||
{
|
||||
$username = $details['params']['username'];
|
||||
}
|
||||
if ( $username )
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate('hosting')->accountLink( $username );
|
||||
}
|
||||
return '';
|
||||
},
|
||||
'e_message' => function( $val )
|
||||
{
|
||||
if ( \IPS\Member::loggedIn()->language()->checkKeyExists( 'hosting_ex_' . $val ) )
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'hosting_ex_' . $val );
|
||||
}
|
||||
else
|
||||
{
|
||||
return $val;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
/* Buttons */
|
||||
$table->rowButtons = function( $row )
|
||||
{
|
||||
return array(
|
||||
'view' => array(
|
||||
'icon' => 'search',
|
||||
'title' => 'view',
|
||||
'link' => \IPS\Http\Url::internal( 'app=nexus&module=hosting&controller=errors&do=view&id=' . $row['e_id'] ),
|
||||
'data' => array( 'ipsDialog' => '' )
|
||||
),
|
||||
'retry' => array(
|
||||
'icon' => 'refresh',
|
||||
'title' => 'retry',
|
||||
'link' => \IPS\Http\Url::internal( 'app=nexus&module=hosting&controller=errors&do=retry&id=' . $row['e_id'] )
|
||||
),
|
||||
'delete'=> array(
|
||||
'icon' => 'times-circle',
|
||||
'title' => 'delete',
|
||||
'link' => \IPS\Http\Url::internal( 'app=nexus&module=hosting&controller=errors&do=delete&id=' . $row['e_id'] ),
|
||||
'data' => array( 'delete' => '' )
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->sidebar['actions'][] = array(
|
||||
'icon' => 'envelope',
|
||||
'title' => 'notifications',
|
||||
'link' => \IPS\Http\Url::internal( "app=nexus&module=hosting&controller=errors&do=settings" ),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('notifications') )
|
||||
);
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__nexus_hosting_errors');
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'forms', 'core' )->blurb( 'hosting_errors_blurb' ) . (string) $table;
|
||||
}
|
||||
|
||||
/**
|
||||
* View
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function view()
|
||||
{
|
||||
try
|
||||
{
|
||||
$log = \IPS\Db::i()->select( '*', 'nexus_hosting_errors', array( 'e_id=?', \IPS\Request::i()->id ) )->first();
|
||||
}
|
||||
catch ( \UnderflowException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X244/2', 404, '' );
|
||||
}
|
||||
|
||||
$details = json_decode( $log['e_extra'], TRUE );
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->definitionTable( $details['params'], NULL, FALSE );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retry
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function retry()
|
||||
{
|
||||
try
|
||||
{
|
||||
$log = \IPS\Db::i()->select( '*', 'nexus_hosting_errors', array( 'e_id=?', \IPS\Request::i()->id ) )->first();
|
||||
}
|
||||
catch ( \UnderflowException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X244/3', 404, '' );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
\IPS\nexus\Hosting\Server::load( $log['e_server'] )->retryError( json_decode( $log['e_extra'], TRUE ) );
|
||||
\IPS\Db::i()->delete( 'nexus_hosting_errors', array( 'e_id=?', \IPS\Request::i()->id ) );
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=hosting&controller=errors'), 'hosrting_error_retry_done' );
|
||||
}
|
||||
catch ( \UnderflowException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( $e->getMessage(), '3X244/4', 500, '' );
|
||||
}
|
||||
catch ( \IPS\nexus\Hosting\Exception $e )
|
||||
{
|
||||
$message = $e->getMessage();
|
||||
if ( \IPS\Member::loggedIn()->language()->checkKeyExists( 'hosting_ex_' . $message ) )
|
||||
{
|
||||
$message = \IPS\Member::loggedIn()->language()->addToStack( 'hosting_ex_' . $message );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->error( $message, '1X244/1', 503, '' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
\IPS\Db::i()->delete( 'nexus_hosting_errors', array( 'e_id=?', \IPS\Request::i()->id ) );
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=hosting&controller=errors'), 'deleted' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function settings()
|
||||
{
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->add( new \IPS\Helpers\Form\Stack( 'nexus_hosting_error_emails', explode( ',', \IPS\Settings::i()->nexus_hosting_error_emails ), FALSE, array( 'stackFieldType' => 'Email' ) ) );
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
$values['nexus_hosting_error_emails'] = implode( ',', $values['nexus_hosting_error_emails'] );
|
||||
$form->saveAsSettings( $values );
|
||||
\IPS\Session::i()->log( 'acplogs__host_err_settings' );
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=hosting&controller=errors'), 'saved' );
|
||||
}
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__nexus_hosting_errors');
|
||||
\IPS\Output::i()->output = $form;
|
||||
}
|
||||
}
|
||||
Whitespace-only changes.
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Monitoring Settings
|
||||
* @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 07 Aug 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\admin\hosting;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Monitoring Settings
|
||||
*/
|
||||
class _monitoring extends \IPS\Node\Controller
|
||||
{
|
||||
/**
|
||||
* Node Class
|
||||
*/
|
||||
protected $nodeClass = 'IPS\nexus\Hosting\EOM';
|
||||
|
||||
/**
|
||||
* Manage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
/* Init Tabs */
|
||||
$tabs = array();
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'hosting', 'monitoring_settings' ) )
|
||||
{
|
||||
$tabs['settings'] = 'settings';
|
||||
}
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'hosting', 'monitoring_eom_view' ) )
|
||||
{
|
||||
$tabs['eom'] = 'expected_output_monitoring';
|
||||
}
|
||||
$keys = array_keys( $tabs );
|
||||
$activeTab = ( isset( \IPS\Request::i()->tab ) and array_key_exists( \IPS\Request::i()->tab, $tabs ) ) ? \IPS\Request::i()->tab : array_shift( $keys );
|
||||
|
||||
/* Work out contents */
|
||||
$activeTabContents = NULL;
|
||||
switch ( $activeTab )
|
||||
{
|
||||
/* Settings */
|
||||
case 'settings':
|
||||
|
||||
/* Build Form */
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->addHeader('monitoring_header');
|
||||
$form->addMessage('monitoring_blurb');
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'monitoring_on', \IPS\Settings::i()->monitoring_script, FALSE, array( 'togglesOn' => array( 'monitoring_script', 'monitoring_alert', 'monitoring_from', 'monitoring_backup', 'monitoring_allowed_fails', 'monitoring_panic', 'form_header_network_status_header', 'network_status' ) ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Url( 'monitoring_script', \IPS\Settings::i()->monitoring_script, NULL, array( 'placeholder' => 'http://www.example.com/monitor_master.php' ), NULL, NULL, NULL, 'monitoring_script' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Url( 'monitoring_backup', \IPS\Settings::i()->monitoring_backup, FALSE, array( 'placeholder' => 'http://backup.example.com/monitor_master.php' ), NULL, NULL, NULL, 'monitoring_backup' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Stack( 'monitoring_alert', explode( ',', \IPS\Settings::i()->monitoring_alert ), NULL, array(), NULL, NULL, NULL, 'monitoring_alert' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Email( 'monitoring_from', \IPS\Settings::i()->monitoring_from ?: \IPS\Settings::i()->email_out, NULL, array(), NULL, NULL, NULL, 'monitoring_from' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'monitoring_allowed_fails', \IPS\Settings::i()->monitoring_allowed_fails, FALSE, array(), NULL, NULL, NULL, 'monitoring_allowed_fails' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'monitoring_panic', \IPS\Settings::i()->monitoring_panic, FALSE, array(), NULL, NULL, NULL, 'monitoring_panic' ) );
|
||||
$form->addHeader('network_status_header');
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'network_status', \IPS\Settings::i()->network_status, FALSE, array( 'options' => array( 2 => 'network_status_2', 1 => 'network_status_1', 0 => 'network_status_0' ), 'toggles' => array( 2 => array( 'network_status_text' ), 1 => array( 'network_status_text' ) ) ), NULL, NULL, NULL, 'network_status' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Translatable( 'network_status_text', NULL, FALSE, array( 'app' => 'nexus', 'key' => 'network_status_text_val', 'editor' => array( 'app' => 'nexus', 'key' => 'Admin', 'autoSaveKey' => 'network_status_text', 'attachIds' => array( NULL, NULL, 'network_status_text' ) ) ), NULL, NULL, NULL, 'network_status_text' ) );
|
||||
|
||||
/* Handle submissions */
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
if ( !$values['monitoring_on'] )
|
||||
{
|
||||
$values['monitoring_script'] = '';
|
||||
\IPS\DB::i()->update( 'core_tasks', array( 'enabled' => 0 ), "`key`='monitor'" );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\DB::i()->update( 'core_tasks', array( 'enabled' => 1 ), "`key`='monitor'" );
|
||||
}
|
||||
unset( $values['monitoring_on'] );
|
||||
|
||||
$values['monitoring_alert'] = implode( ',', $values['monitoring_alert'] );
|
||||
|
||||
\IPS\Lang::saveCustom( 'nexus', 'network_status_text_val', $values['network_status_text'] );
|
||||
unset( $values['network_status_text'] );
|
||||
|
||||
$form->saveAsSettings( $values );
|
||||
|
||||
\IPS\Session::i()->log( 'acplogs__host_mon_settings' );
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=nexus&module=hosting&controller=monitoring&tab=settings' ), 'saved' );
|
||||
}
|
||||
|
||||
/* Display */
|
||||
$activeTabContents = (string) $form;
|
||||
break;
|
||||
|
||||
/* EOM */
|
||||
case 'eom':
|
||||
parent::manage();
|
||||
$activeTabContents = \IPS\Theme::i()->getTemplate('forms', 'core')->blurb( 'eom_blurb', TRUE, TRUE ) . \IPS\Output::i()->output;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Display */
|
||||
if( \IPS\Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->output = $activeTabContents;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__nexus_hosting_monitoring');
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->tabs( $tabs, $activeTab, $activeTabContents, \IPS\Http\Url::internal( "app=nexus&module=hosting&controller=monitoring" ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Download Master Monitoring Script
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function downloadMaster()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'monitoring_settings' );
|
||||
\IPS\Output::i()->sendOutput( file_get_contents( \IPS\ROOT_PATH . '/applications/nexus/data/monitoring/master.txt' ), 200, 'text/plain', array( 'Content-Disposition' => 'attachment; filename=monitor_master.php' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Download Remote Monitoring Script
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function downloadRemote()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'monitoring_settings' );
|
||||
\IPS\Output::i()->sendOutput( file_get_contents( \IPS\ROOT_PATH . '/applications/nexus/data/monitoring/remote.txt' ), 200, 'text/plain', array( 'Content-Disposition' => 'attachment; filename=monitor_remote.php' ) );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Hosting Queues
|
||||
* @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 Aug 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\admin\hosting;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hosting Queues
|
||||
*/
|
||||
class _queues extends \IPS\Node\Controller
|
||||
{
|
||||
/**
|
||||
* Node Class
|
||||
*/
|
||||
protected $nodeClass = 'IPS\nexus\Hosting\Queue';
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'queues_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function manage()
|
||||
{
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'forms', 'core' )->blurb( 'hosting_queues_blurb' );
|
||||
return parent::manage();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,476 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Hosting Servers
|
||||
* @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 Aug 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\admin\hosting;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hosting Servers
|
||||
*/
|
||||
class _servers extends \IPS\Node\Controller
|
||||
{
|
||||
/**
|
||||
* Node Class
|
||||
*/
|
||||
protected $nodeClass = 'IPS\nexus\Hosting\Server';
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'servers_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function manage()
|
||||
{
|
||||
/* Initiate the table */
|
||||
$table = new \IPS\Helpers\Table\Db( 'nexus_hosting_servers', \IPS\Http\Url::internal('app=nexus&module=hosting&controller=servers') );
|
||||
if ( \IPS\Settings::i()->monitoring_script )
|
||||
{
|
||||
$table->include = array( 'server_monitor_icon', 'server_hostname', 'server_ip', 'server_num_accounts', 'server_cost', 'server_income' );
|
||||
$table->widths = array( 'server_monitor_icon' => 5 );
|
||||
$table->noSort = array( 'server_monitor_icon' );
|
||||
}
|
||||
else
|
||||
{
|
||||
$table->include = array( 'server_hostname', 'server_ip', 'server_num_accounts', 'server_cost', 'server_income' );
|
||||
}
|
||||
$table->sortBy = $table->sortBy ?: 'server_hostname';
|
||||
$table->quickSearch = 'server_hostname';
|
||||
|
||||
/* Buttons */
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'hosting', 'servers_add' ) )
|
||||
{
|
||||
$table->rootButtons = array(
|
||||
'add' => array(
|
||||
'title' => 'add',
|
||||
'icon' => 'plus',
|
||||
'link' => \IPS\Http\Url::internal('app=nexus&module=hosting&controller=servers&do=form')
|
||||
)
|
||||
);
|
||||
}
|
||||
$table->rowButtons = function( $row )
|
||||
{
|
||||
$return = array();
|
||||
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'hosting', 'servers_audit' ) )
|
||||
{
|
||||
$return['list'] = array(
|
||||
'title' => 'view_accounts',
|
||||
'icon' => 'search',
|
||||
'link' => \IPS\Http\Url::internal( 'app=nexus&module=hosting&controller=servers&do=view&id=' . $row['server_id'] )
|
||||
);
|
||||
}
|
||||
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'hosting', 'servers_edit' ) )
|
||||
{
|
||||
$return['edit'] = array(
|
||||
'title' => 'edit',
|
||||
'icon' => 'pencil',
|
||||
'link' => \IPS\Http\Url::internal( 'app=nexus&module=hosting&controller=servers&do=form&id=' . $row['server_id'] )
|
||||
);
|
||||
}
|
||||
|
||||
if ( !$row['server_dedicated'] and \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'hosting', 'servers_reboot' ) )
|
||||
{
|
||||
$return['reboot'] = array(
|
||||
'title' => 'reboot',
|
||||
'icon' => 'refresh',
|
||||
'link' => \IPS\Http\Url::internal( 'app=nexus&module=hosting&controller=servers&do=reboot&id=' . $row['server_id'] )
|
||||
);
|
||||
}
|
||||
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'hosting', 'servers_delete' ) )
|
||||
{
|
||||
$return['delete'] = array(
|
||||
'title' => 'delete',
|
||||
'icon' => 'times-circle',
|
||||
'link' => \IPS\Http\Url::internal( 'app=nexus&module=hosting&controller=servers&do=delete&id=' . $row['server_id'] ),
|
||||
'data' => array( 'delete' => '' )
|
||||
);
|
||||
}
|
||||
|
||||
return $return;
|
||||
};
|
||||
|
||||
/* Work out the monthly income for each server */
|
||||
$serverIncomes = array();
|
||||
foreach ( array(
|
||||
'd' => ( 365 / 12 ),
|
||||
'w' => ( 365 / 12 / 7 ),
|
||||
'm' => 1,
|
||||
'y' => ( 1 / 12 ),
|
||||
) as $key => $multiplier )
|
||||
{
|
||||
foreach (
|
||||
\IPS\Db::i()->select(
|
||||
'account_server, ps_renewal_currency, SUM( ps_renewal_price / ps_renewals ) * ' . $multiplier . ' AS amount',
|
||||
'nexus_hosting_accounts',
|
||||
array( 'account_exists=1 AND ps_renewal_unit=?', $key ),
|
||||
NULL,
|
||||
NULL,
|
||||
array( 'account_server', 'ps_renewal_currency' )
|
||||
)->join( 'nexus_purchases', 'nexus_hosting_accounts.ps_id=nexus_purchases.ps_id' )
|
||||
as $row
|
||||
)
|
||||
{
|
||||
if ( !isset( $serverIncomes[ $row['account_server'] ][ $row['ps_renewal_currency'] ] ) )
|
||||
{
|
||||
$serverIncomes[ $row['account_server'] ][ $row['ps_renewal_currency'] ] = 0;
|
||||
}
|
||||
|
||||
$serverIncomes[ $row['account_server'] ][ $row['ps_renewal_currency'] ] += $row['amount'];
|
||||
}
|
||||
}
|
||||
|
||||
/* Parse the columns */
|
||||
$currencies = \IPS\nexus\Money::currencies();
|
||||
$costCurrency = array_shift( $currencies );
|
||||
$table->parsers = array(
|
||||
'server_monitor_icon' => function( $val, $row )
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate('hosting')->serverStatus( $row );
|
||||
},
|
||||
'server_num_accounts' => function( $val, $row )
|
||||
{
|
||||
if ( $row['server_dedicated'] )
|
||||
{
|
||||
try
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate('purchases')->link( \IPS\nexus\Purchase::load( $row['server_dedicated'] ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
return '-';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return \IPS\Db::i()->select( 'COUNT(*)', 'nexus_hosting_accounts', array( 'account_server=? AND account_exists=1', $row['server_id'] ) )->first() . ( $row['server_max_accounts'] ? ( ' / ' . $row['server_max_accounts'] ) : '' );
|
||||
}
|
||||
},
|
||||
'server_cost' => function ( $val ) use ( $costCurrency )
|
||||
{
|
||||
return new \IPS\nexus\Money( $val, $costCurrency );
|
||||
},
|
||||
'server_income' => function( $val, $row ) use ( $serverIncomes, $costCurrency )
|
||||
{
|
||||
if ( $row['server_dedicated'] )
|
||||
{
|
||||
try
|
||||
{
|
||||
$purchase = \IPS\nexus\Purchase::load( $row['server_dedicated'] );
|
||||
|
||||
$months = 0;
|
||||
$months += ( $purchase->renewals->interval->y / 12 );
|
||||
$months += ( $purchase->renewals->interval->m );
|
||||
$months += ( $purchase->renewals->interval->d * ( 365 / 12 ) );
|
||||
|
||||
return new \IPS\nexus\Money( $purchase->renewals->cost->amount * $months, $purchase->renewals->cost->currency );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
return '-';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$return = array();
|
||||
if ( isset( $serverIncomes[ $row['server_id'] ] ) )
|
||||
{
|
||||
foreach ( $serverIncomes[ $row['server_id'] ] as $currency => $amount )
|
||||
{
|
||||
$return[] = new \IPS\nexus\Money( $amount, $currency );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return new \IPS\nexus\Money( 0, $costCurrency );
|
||||
}
|
||||
return implode( '<br>', $return );
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
/* Add filters for the queues */
|
||||
foreach ( \IPS\nexus\Hosting\Queue::queues() as $queue )
|
||||
{
|
||||
$table->filters[ $queue->name ] = \IPS\Db::i()->findInSet( 'server_queues', array( $queue->id ) );
|
||||
}
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->sidebar['actions'][] = array(
|
||||
'icon' => 'check-circle',
|
||||
'title' => 'hserv_audit',
|
||||
'link' => \IPS\Http\Url::internal( "app=nexus&module=hosting&controller=servers&do=audit" ),
|
||||
);
|
||||
\IPS\Output::i()->output = (string) $table;
|
||||
}
|
||||
|
||||
/**
|
||||
* View accounts
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function view()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'servers_audit' );
|
||||
|
||||
try
|
||||
{
|
||||
$server = \IPS\nexus\Hosting\Server::load( \IPS\Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X243/3', 403, '' );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->title = $server->hostname;
|
||||
\IPS\Output::i()->output = call_user_func_array( array( \IPS\Theme::i()->getTemplate( 'hosting' ), 'viewAccounts' ), $this->_audit( $server ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Reboot a server
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function reboot()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'servers_reboot' );
|
||||
|
||||
try
|
||||
{
|
||||
\IPS\nexus\Hosting\Server::load( \IPS\Request::i()->id )->reboot();
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X243/1', 404, '' );
|
||||
}
|
||||
catch ( \IPS\nexus\Hosting\Exception $e )
|
||||
{
|
||||
\IPS\Output::i()->error( $e->getMessage(), '3X243/2', 500, '' );
|
||||
}
|
||||
|
||||
\IPS\Session::i()->log( 'acplogs__server_reboot', array( $server->hostname => FALSE ) );
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=hosting&controller=servers'), 'rebooting' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Audit all servers
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function audit()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'servers_audit' );
|
||||
|
||||
$self = $this;
|
||||
|
||||
\IPS\Output::i()->output = new \IPS\Helpers\MultipleRedirect(
|
||||
\IPS\Http\Url::internal('app=nexus&module=hosting&controller=servers&do=audit'),
|
||||
function( $data ) use ( $self )
|
||||
{
|
||||
if ( $data === 0 )
|
||||
{
|
||||
$_SESSION['serverAudit'] = array();
|
||||
$data = array( 'offset' => 0, 'bad' => array() );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$select = \IPS\Db::i()->select( '*', 'nexus_hosting_servers', array(), 'server_hostname', array( $data['offset'], 1 ) );
|
||||
$server = \IPS\nexus\Hosting\Server::constructFromData( $select->first() );
|
||||
|
||||
$results = $self->_audit( $server );
|
||||
foreach ( array( 1, 2, 3, 6, 7, 8 ) as $i )
|
||||
{
|
||||
if ( !empty( $results[ $i ] ) )
|
||||
{
|
||||
$data['bad'][ $server->id ] = $server->hostname;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$data['offset']++;
|
||||
return array( $data, \IPS\Member::loggedIn()->language()->get('hserv_audit_running'), 100 / $select->count(TRUE) * $data['offset'] );
|
||||
}
|
||||
catch ( \UnderflowException $e )
|
||||
{
|
||||
$_SESSION['serverAudit'] = $data['bad'];
|
||||
return NULL;
|
||||
}
|
||||
},
|
||||
function()
|
||||
{
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=hosting&controller=servers&do=auditResults') );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Audit all servers
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function auditResults()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'servers_audit' );
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'hosting' )->audit( $_SESSION['serverAudit'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Audit a server
|
||||
*
|
||||
* @param \IPS\nexus\Hosting\Server $server
|
||||
* @return array
|
||||
*/
|
||||
protected function _audit( \IPS\nexus\Hosting\Server $server )
|
||||
{
|
||||
/* Get accounts from server */
|
||||
try
|
||||
{
|
||||
$serverAccounts = $server->listAccounts();
|
||||
}
|
||||
catch ( \IPS\nexus\Hosting\Exception $e )
|
||||
{
|
||||
\IPS\Output::i()->error( $e->getMessage(), '3X243/4', 403, '' );
|
||||
}
|
||||
|
||||
/* Init */
|
||||
$notPresentOnServer = array();
|
||||
$notPresentInDb = array();
|
||||
$domainsDontMatch = array();
|
||||
$expiredButnotSuspended = array();
|
||||
$diskSpaceAllocated = 0;
|
||||
$diskSpaceInUse = 0;
|
||||
$accounts = array();
|
||||
$suspendedButNotExpired = array();
|
||||
$doesNotResolveCorrectly= array();
|
||||
|
||||
/* Get accounts in the database */
|
||||
foreach ( \IPS\Db::i()->select( 'nexus_hosting_accounts.*, nexus_purchases.ps_active', 'nexus_hosting_accounts', array( 'account_server=?', $server->id ), 'account_username' )->join( 'nexus_purchases', 'nexus_hosting_accounts.ps_id=nexus_purchases.ps_id' ) as $row )
|
||||
{
|
||||
/* If we don't think it exists, check if it does */
|
||||
if ( !$row['account_exists'] )
|
||||
{
|
||||
if ( isset( $serverAccounts[ $row['account_username'] ] ) )
|
||||
{
|
||||
$row['account_exists'] = 1;
|
||||
\IPS\Db::i()->update( 'nexus_hosting_accounts', array( 'account_exists' => 1 ), "ps_id={$row['ps_id']}" );
|
||||
}
|
||||
}
|
||||
|
||||
// Now check it
|
||||
if ( $row['account_exists'] )
|
||||
{
|
||||
// Is it in there?
|
||||
if ( isset( $serverAccounts[ $row['account_username'] ] ) )
|
||||
{
|
||||
$accounts[] = array_merge( $row, $serverAccounts[ $row['account_username'] ] );
|
||||
|
||||
// Does the domain match?
|
||||
if ( $serverAccounts[ $row['account_username'] ]['domain'] != $row['account_domain'] )
|
||||
{
|
||||
$row['domain'] = $serverAccounts[ $row['account_username'] ]['domain'];
|
||||
$domainsDontMatch[] = $row;
|
||||
}
|
||||
|
||||
// Does the status match?
|
||||
if ( $row['ps_active'] and !$serverAccounts[ $row['account_username'] ]['active'] )
|
||||
{
|
||||
$suspendedButNotExpired[] = $row;
|
||||
}
|
||||
elseif ( !$row['ps_active'] and $serverAccounts[ $row['account_username'] ]['active'] )
|
||||
{
|
||||
$expiredButnotSuspended[] = $row;
|
||||
}
|
||||
|
||||
// Does it resolve correctly? */
|
||||
if ( gethostbyname( $row['account_domain'] ) !== $server->ip )
|
||||
{
|
||||
$doesNotResolveCorrectly[] = $row;
|
||||
}
|
||||
|
||||
// Get disk use
|
||||
if( $diskSpaceAllocated == -1 or $serverAccounts[ $row['account_username'] ]['disklimit'] == 'unlimited' )
|
||||
{
|
||||
$diskSpaceAllocated = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$diskSpaceAllocated += $serverAccounts[ $row['account_username'] ]['disklimit'];
|
||||
}
|
||||
$diskSpaceInUse += $serverAccounts[ $row['account_username'] ]['diskused'];
|
||||
|
||||
// Note that we have it
|
||||
unset( $serverAccounts[ $row['account_username'] ] );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( !$row['ps_active'] )
|
||||
{
|
||||
\IPS\Db::i()->update( 'nexus_hosting_accounts', array( 'account_exists' => 0 ), "ps_id={$row['ps_id']}" );
|
||||
}
|
||||
else
|
||||
{
|
||||
$notPresentOnServer[] = $row;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$notPresentInDb = $serverAccounts;
|
||||
|
||||
/* Return */
|
||||
return array( $server, $notPresentOnServer, $notPresentInDb, $domainsDontMatch, $diskSpaceAllocated, $diskSpaceInUse, $expiredButnotSuspended, $suspendedButNotExpired, $doesNotResolveCorrectly, $accounts );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add/Edit Form
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function form()
|
||||
{
|
||||
$availableTypes = array();
|
||||
|
||||
foreach ( new \DirectoryIterator( \IPS\ROOT_PATH . '/applications/nexus/sources/Hosting' ) as $file )
|
||||
{
|
||||
if (!$file->isDot() and mb_substr($file, 0, 1) !== '.' and $file->isDir())
|
||||
{
|
||||
$availableTypes[] = (string) $file;
|
||||
}
|
||||
}
|
||||
|
||||
if( isset( \IPS\Request::i()->server_type ) and in_array( \IPS\Request::i()->server_type, $availableTypes ) )
|
||||
{
|
||||
$this->nodeClass = "IPS\\nexus\\Hosting\\" . ucfirst( \IPS\Request::i()->server_type ) . "\\Server";
|
||||
}
|
||||
|
||||
parent::form();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Hosting Settings
|
||||
* @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 Aug 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\admin\hosting;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hosting Settings
|
||||
*/
|
||||
class _settings extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'settings_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
/* Init */
|
||||
$form = new \IPS\Helpers\Form;
|
||||
|
||||
/* Account Management */
|
||||
$form->addTab('hosting_account_management');
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'nexus_hosting_terminate', \IPS\Settings::i()->nexus_hosting_terminate, TRUE, array( 'unlimited' => -1, 'unlimitedLang' => 'forever' ), NULL, NULL, \IPS\Member::loggedIn()->language()->addToStack('days') ) );
|
||||
|
||||
/* Domains */
|
||||
$form->addTab('hosting_settings_domains');
|
||||
$form->addHeader('domain_options');
|
||||
$optionsVal = array();
|
||||
$domainPrices = array();
|
||||
if ( \IPS\Settings::i()->nexus_enom_un and $domainPrices = json_decode( \IPS\Settings::i()->nexus_domain_prices, TRUE ) and count( $domainPrices ) )
|
||||
{
|
||||
$optionsVal[] = 'enom';
|
||||
}
|
||||
if ( \IPS\Settings::i()->nexus_hosting_subdomains )
|
||||
{
|
||||
$optionsVal[] = 'sub';
|
||||
}
|
||||
if ( \IPS\Settings::i()->nexus_hosting_allow_own_domain )
|
||||
{
|
||||
$optionsVal[] = 'own';
|
||||
}
|
||||
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'domain_options', $optionsVal, FALSE, array(
|
||||
'options' => array(
|
||||
'enom' => 'domain_options_enom',
|
||||
'sub' =>'domain_options_sub',
|
||||
'own' => 'domain_options_own'
|
||||
),
|
||||
'toggles' => array(
|
||||
'enom' => array( 'form_header_nexus_domain_prices', 'nexus_domain_prices', 'nexus_domain_tax' ),
|
||||
'sub' => array( 'form_header_nexus_hosting_sub', 'nexus_hosting_subdomains' ),
|
||||
'own' => array()
|
||||
),
|
||||
'disabled' => \IPS\Settings::i()->nexus_enom_un ? array() : array( 'enom' )
|
||||
) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Stack( 'nexus_hosting_nameservers', explode( ',', \IPS\Settings::i()->nexus_hosting_nameservers ), FALSE, array(), NULL, NULL, NULL, 'nexus_hosting_nameservers' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Stack( 'nexus_hosting_subdomains', explode( ',', \IPS\Settings::i()->nexus_hosting_subdomains ), FALSE, array(), NULL, NULL, NULL, 'nexus_hosting_subdomains' ) );
|
||||
$form->addHeader('nexus_domain_prices');
|
||||
$matrix = new \IPS\Helpers\Form\Matrix;
|
||||
$matrix->columns = array(
|
||||
'domain_tld' => array( 'Text' ),
|
||||
'domain_price' => function( $key, $value, $data )
|
||||
{
|
||||
return new \IPS\nexus\Form\Money( $key, $value, FALSE, array() );
|
||||
},
|
||||
);
|
||||
if ( count( $domainPrices ) )
|
||||
{
|
||||
foreach ( $domainPrices as $tld => $prices )
|
||||
{
|
||||
$matrix->rows[] = array( 'domain_tld' => $tld, 'domain_price' => $prices );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$matrix->rows = array( array( 'domain_tld' => 'com', 'domain_price' => NULL ) );
|
||||
}
|
||||
$form->addMatrix( 'nexus_domain_prices', $matrix );
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'nexus_domain_tax', \IPS\Settings::i()->nexus_domain_tax, FALSE, array( 'class' => 'IPS\nexus\Tax', 'zeroVal' => 'do_not_tax' ), NULL, NULL, NULL, 'nexus_domain_tax' ) );
|
||||
|
||||
/* Badwidth */
|
||||
$form->addTab('nexus_hosting_bandwidth');
|
||||
$form->addMessage( 'nexus_hosting_bandwidth_blurb' );
|
||||
$bandwidthMatrix = new \IPS\Helpers\Form\Matrix;
|
||||
$bandwidthMatrix->columns = array(
|
||||
'bandwidth_amount' => array( 'Number' ),
|
||||
'bandwidth_price' => function( $key, $value, $data )
|
||||
{
|
||||
return new \IPS\nexus\Form\Money( $key, $value, FALSE, array() );
|
||||
},
|
||||
);
|
||||
$bandwidthPrices = json_decode( \IPS\Settings::i()->nexus_hosting_bandwidth, TRUE );
|
||||
if ( count( $bandwidthPrices ) )
|
||||
{
|
||||
foreach ( $bandwidthPrices as $amount => $prices )
|
||||
{
|
||||
$bandwidthMatrix->rows[] = array( 'bandwidth_amount' => $amount, 'bandwidth_price' => $prices );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$bandwidthMatrix->rows = array();
|
||||
}
|
||||
$form->addMatrix( 'nexus_hosting_bandwidth', $bandwidthMatrix );
|
||||
|
||||
/* Handle Submissions */
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
$domainPrices = array();
|
||||
if ( in_array( 'enom', $values['domain_options'] ) )
|
||||
{
|
||||
foreach ( $values['nexus_domain_prices'] as $option )
|
||||
{
|
||||
if ( $option['domain_tld'] )
|
||||
{
|
||||
$domainPrices[ $option['domain_tld'] ] = $option['domain_price'];
|
||||
}
|
||||
}
|
||||
}
|
||||
$values['nexus_domain_prices'] = json_encode( $domainPrices );
|
||||
$values['nexus_hosting_allow_own_domain'] = in_array( 'own', $values['domain_options'] );
|
||||
|
||||
$values['nexus_hosting_nameservers'] = implode( ',', $values['nexus_hosting_nameservers'] );
|
||||
$values['nexus_hosting_subdomains'] = in_array( 'sub', $values['domain_options'] ) ? implode( ',', $values['nexus_hosting_subdomains'] ) : '';
|
||||
|
||||
\IPS\DB::i()->update( 'core_tasks', array( 'enabled' => (bool) $values['nexus_hosting_terminate'] ), "`key`='terminateHosting'" );
|
||||
|
||||
$bandwidthPrices = array();
|
||||
foreach ( $values['nexus_hosting_bandwidth'] as $option )
|
||||
{
|
||||
if ( $option['bandwidth_amount'] )
|
||||
{
|
||||
$bandwidthPrices[ $option['bandwidth_amount'] ] = $option['bandwidth_price'];
|
||||
}
|
||||
}
|
||||
$values['nexus_hosting_bandwidth'] = json_encode( $bandwidthPrices );
|
||||
|
||||
unset( $values['domain_options'] );
|
||||
$form->saveAsSettings( $values );
|
||||
|
||||
\IPS\Session::i()->log( 'acplogs__hosting_settings' );
|
||||
}
|
||||
|
||||
/* Display */
|
||||
if ( !\IPS\Settings::i()->nexus_enom_un )
|
||||
{
|
||||
\IPS\Member::loggedIn()->language()->words['domain_options_enom_desc'] = \IPS\Member::loggedIn()->language()->get( 'domain_options_enom_dis' );
|
||||
}
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('hosting_settings');
|
||||
\IPS\Output::i()->output = $form;
|
||||
}
|
||||
}
|
||||
Whitespace-only changes.
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Checkout Settings
|
||||
* @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 28 Mar 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\admin\payments;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checkout Settings
|
||||
*/
|
||||
class _checkoutsettings extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'checkout_settings' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function manage()
|
||||
{
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->addHeader( 'checkout_settings' );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'nexus_https', \IPS\Settings::i()->nexus_https, FALSE, array(), function( $val )
|
||||
{
|
||||
if ( $val )
|
||||
{
|
||||
try
|
||||
{
|
||||
\IPS\Http\Url::internal( '', 'front', NULL, array(), TRUE )->request()->get();
|
||||
}
|
||||
catch ( \IPS\Http\Request\Exception $e )
|
||||
{
|
||||
throw new \DomainException('nexus_https_err');
|
||||
}
|
||||
}
|
||||
} ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'nexus_split_payments_on', \IPS\Settings::i()->nexus_split_payments != -1, FALSE, array( 'togglesOn' => array( 'nexus_split_payments' ) ) ) );
|
||||
$form->add( new \IPS\nexus\Form\Money( 'nexus_split_payments', \IPS\Settings::i()->nexus_split_payments ?: '*', FALSE, array( 'unlimitedLang' => 'no_restriction' ), NULL, NULL, NULL, 'nexus_split_payments' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'nexus_tac', \IPS\Settings::i()->nexus_tac, FALSE, array(
|
||||
'options' => array(
|
||||
'none' => 'nexus_tac_none',
|
||||
'button' => 'nexus_tac_button',
|
||||
'checkbox' => 'nexus_tac_checkbox'
|
||||
),
|
||||
'toggles' => array(
|
||||
'button' => array( 'nexus_tac_link' ),
|
||||
'checkbox' => array( 'nexus_tac_link' )
|
||||
)
|
||||
) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Url( 'nexus_tac_link', \IPS\Settings::i()->nexus_tac_link, FALSE, array(), NULL, NULL, NULL, 'nexus_tac_link' ) );
|
||||
$form->addHeader( 'nexus_checkreg' );
|
||||
$form->addMessage( 'nexus_checkreg_desc' );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'nexus_checkreg_usernames', \IPS\Settings::i()->nexus_checkreg_usernames ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'nexus_checkreg_captcha', \IPS\Settings::i()->nexus_checkreg_captcha ) );
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
$values['nexus_split_payments'] = $values['nexus_split_payments_on'] ? ( $values['nexus_split_payments'] == '*' ? 0 : json_encode( $values['nexus_split_payments'] ) ) : -1;
|
||||
$form->saveAsSettings( $values );
|
||||
|
||||
\IPS\Session::i()->log( 'acplogs__checkout_settings' );
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=nexus&module=payments&controller=paymentsettings&tab=checkoutsettings' ) );
|
||||
}
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('checkout_settings');
|
||||
\IPS\Output::i()->output = $form;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Currencies
|
||||
* @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 26 Mar 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\admin\payments;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Currencies
|
||||
*/
|
||||
class _currencies extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'currencies_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function manage()
|
||||
{
|
||||
$languages = \IPS\Lang::languages();
|
||||
|
||||
$matrix = new \IPS\Helpers\Form\Matrix;
|
||||
$matrix->langPrefix = 'currency_';
|
||||
$matrix->columns = array(
|
||||
'code' => function( $key, $value, $data )
|
||||
{
|
||||
return new \IPS\Helpers\Form\Text( $key, $value, FALSE, array( 'minLength' => 3, 'maxLength' => 3, 'placeholder' => 'USD' ) );
|
||||
},
|
||||
'default' => function( $key, $value, $data ) use ( $languages )
|
||||
{
|
||||
if ( count( $languages ) === 1 )
|
||||
{
|
||||
return new \IPS\Helpers\Form\Checkbox( $key, $value );
|
||||
}
|
||||
else
|
||||
{
|
||||
$options = array();
|
||||
foreach ( $languages as $k => $v )
|
||||
{
|
||||
$options[ $v->id ] = $v->_title;
|
||||
}
|
||||
|
||||
return new \IPS\Helpers\Form\Select( $key, $value, FALSE, array( 'options' => $options, 'multiple' => TRUE ) );
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
$warnings = '';
|
||||
if ( $currencies = json_decode( \IPS\Settings::i()->nexus_currency, TRUE ) )
|
||||
{
|
||||
foreach ( $currencies as $code => $defaults )
|
||||
{
|
||||
$matrix->rows[] = array(
|
||||
'code' => $code,
|
||||
'default' => $defaults
|
||||
);
|
||||
|
||||
if ( !in_array( $code, array( 'AED', 'AFN', 'ALL', 'AMD', 'ANG', 'AOA', 'ARS', 'AUD', 'AWG', 'AZN', 'BAM', 'BBD', 'BDT', 'BGN', 'BHD', 'BIF', 'BMD', 'BND', 'BOB', 'BRL', 'BSD', 'BTN', 'BWP', 'BYR', 'BZD', 'CAD', 'CDF', 'CHF', 'CLP', 'CNY', 'COP', 'CRC', 'CUC', 'CUP', 'CVE', 'CZK', 'DJF', 'DKK', 'DOP', 'DZD', 'EGP', 'ERN', 'ETB', 'EUR', 'FJD', 'FKP', 'GBP', 'GEL', 'GGP', 'GHS', 'GIP', 'GMD', 'GNF', 'GTQ', 'GYD', 'HKD', 'HNL', 'HRK', 'HTG', 'HUF', 'IDR', 'ILS', 'IMP', 'INR', 'IQD', 'IRR', 'ISK', 'JEP', 'JMD', 'JOD', 'JPY', 'KES', 'KGS', 'KHR', 'KMF', 'KPW', 'KRW', 'KWD', 'KYD', 'KZT', 'LAK', 'LBP', 'LKR', 'LRD', 'LSL', 'LYD', 'MAD', 'MDL', 'MGA', 'MKD', 'MMK', 'MNT', 'MOP', 'MRO', 'MUR', 'MVR', 'MWK', 'MXN', 'MYR', 'MZN', 'NAD', 'NGN', 'NIO', 'NOK', 'NPR', 'NZD', 'OMR', 'PAB', 'PEN', 'PGK', 'PHP', 'PKR', 'PLN', 'PYG', 'QAR', 'RON', 'RSD', 'RUB', 'RWF', 'SAR', 'SBD', 'SCR', 'SDG', 'SEK', 'SGD', 'SHP', 'SLL', 'SOS', 'SPL*', 'SRD', 'STD', 'SVC', 'SYP', 'SZL', 'THB', 'TJS', 'TMT', 'TND', 'TOP', 'TRY', 'TTD', 'TVD', 'TWD', 'TZS', 'UAH', 'UGX', 'USD', 'UYU', 'UZS', 'VEF', 'VND', 'VUV', 'WST', 'XAF', 'XCD', 'XDR', 'XOF', 'XPF', 'YER', 'ZAR', 'ZMW', 'ZWD' ) ) )
|
||||
{
|
||||
$warnings .= \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->message( \IPS\Member::loggedIn()->language()->addToStack( 'currency_code_invalid', FALSE, array( 'sprintf' => array( $code ) ) ), 'warning' );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$matrix->rows[] = array(
|
||||
'code' => \IPS\Settings::i()->nexus_currency,
|
||||
'default' => count( $languages ) === 1 ? TRUE : array_keys( $languages )
|
||||
);
|
||||
}
|
||||
|
||||
if ( $values = $matrix->values() )
|
||||
{
|
||||
$save = array();
|
||||
|
||||
foreach ( $values as $data )
|
||||
{
|
||||
if ( $data['code'] )
|
||||
{
|
||||
$save[ $data['code'] ] = ( count( $languages ) === 1 ) ? ( $data['default'] ? array_keys( $languages ) : array() ) : $data['default'];
|
||||
}
|
||||
}
|
||||
|
||||
\IPS\Db::i()->update( 'core_sys_conf_settings', array( 'conf_value' => json_encode( $save ) ), array( 'conf_key=?', 'nexus_currency' ) );
|
||||
\IPS\Settings::i()->nexus_currency = json_encode( $save );
|
||||
unset( \IPS\Data\Store::i()->settings );
|
||||
|
||||
\IPS\Session::i()->log( 'acplogs__currencies' );
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=nexus&module=payments&controller=paymentsettings&tab=currencies' ) );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->output = $matrix . $warnings;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?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
|
||||
* @since 05 May 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\admin\payments;
|
||||
|
||||
/* 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 _donationgoals extends \IPS\Node\Controller
|
||||
{
|
||||
/**
|
||||
* Node Class
|
||||
*/
|
||||
protected $nodeClass = 'IPS\nexus\Donation\Goal';
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'donationgoals_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
<?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
|
||||
* @since 17 Jun 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\admin\payments;
|
||||
|
||||
/* 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()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'donations_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* View Donations
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'donationgoals_manage' ) )
|
||||
{
|
||||
\IPS\Output::i()->sidebar['actions'][] = array(
|
||||
'icon' => 'cog',
|
||||
'title' => 'donation_goals',
|
||||
'link' => \IPS\Http\Url::internal( "app=nexus&module=payments&controller=donationgoals" )
|
||||
);
|
||||
}
|
||||
|
||||
$table = new \IPS\Helpers\Table\Db( 'nexus_donate_logs', \IPS\Http\Url::internal('app=nexus&module=payments&controller=donations') );
|
||||
|
||||
$table->include = array( 'dl_goal', 'dl_amount', 'dl_member', 'dl_invoice', 'dl_date' );
|
||||
$table->parsers = array(
|
||||
'dl_goal' => function( $val )
|
||||
{
|
||||
try
|
||||
{
|
||||
return \IPS\nexus\Donation\Goal::load( $val )->_title;
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
},
|
||||
'dl_member' => function ( $val )
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate('global')->userLink( \IPS\Member::load( $val ) );
|
||||
},
|
||||
'dl_amount' => function( $val, $row )
|
||||
{
|
||||
try
|
||||
{
|
||||
return (string) new \IPS\nexus\Money( $val, \IPS\nexus\Donation\Goal::load( $row['dl_goal'] )->currency );
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
{
|
||||
return $val;
|
||||
}
|
||||
},
|
||||
'dl_invoice' => function( $val )
|
||||
{
|
||||
try
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate('invoices')->link( \IPS\nexus\Invoice::load( $val ), TRUE );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
return '';
|
||||
}
|
||||
},
|
||||
'dl_date' => function( $val )
|
||||
{
|
||||
return \IPS\DateTime::ts( $val );
|
||||
}
|
||||
);
|
||||
|
||||
foreach ( \IPS\nexus\Donation\Goal::roots() as $goal )
|
||||
{
|
||||
$table->filters[ "nexus_donategoal_{$goal->_id}" ] = "dl_goal={$goal->_id}";
|
||||
}
|
||||
$table->advancedSearch = array(
|
||||
'dl_goal' => array( \IPS\Helpers\Table\SEARCH_NODE, array( 'class' => '\IPS\nexus\Donation\Goal' ) ),
|
||||
'dl_member' => \IPS\Helpers\Table\SEARCH_MEMBER,
|
||||
'dl_amount' => \IPS\Helpers\Table\SEARCH_NUMERIC,
|
||||
'dl_date' => \IPS\Helpers\Table\SEARCH_DATE_RANGE,
|
||||
);
|
||||
|
||||
\IPS\Output::i()->output = (string) $table;
|
||||
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__nexus_payments_donations');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Notification Copy Settings
|
||||
* @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 19 Aug 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\admin\payments;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notification Copy Settings
|
||||
*/
|
||||
class _emails extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'email_copies_setting' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function manage()
|
||||
{
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'nexus_notify_copy_types', explode( ',', \IPS\Settings::i()->nexus_notify_copy_types ), FALSE, array( 'options' => array(
|
||||
'invoice_warn' => 'nexus_notify_copy_invoice_warn',
|
||||
'new_invoice' => 'nexus_notify_copy_new_invoice',
|
||||
'payment_received' => 'nexus_notify_copy_payment_received',
|
||||
'payment_waiting' => 'nexus_notify_copy_payment_waiting',
|
||||
'payment_held' => 'nexus_notify_copy_payment_held',
|
||||
'payment_failed' => 'nexus_notify_copy_payment_failed',
|
||||
'payment_refunded' => 'nexus_notify_copy_payment_refunded',
|
||||
'commission_earned' => 'nexus_notify_copy_commission_earned',
|
||||
) ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Stack( 'nexus_notify_copy_email', explode( ',', \IPS\Settings::i()->nexus_notify_copy_email ) ) );
|
||||
|
||||
if ( $form->values() )
|
||||
{
|
||||
$form->saveAsSettings();
|
||||
|
||||
\IPS\Session::i()->log( 'acplogs__email_copies_setting' );
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=nexus&module=payments&controller=paymentsettings&tab=emails' ), 'saved' );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->output = $form;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Anti-Fraud Rules
|
||||
* @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 Mar 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\admin\payments;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Anti-Fraud Rules
|
||||
*/
|
||||
class _fraud extends \IPS\Node\Controller
|
||||
{
|
||||
/**
|
||||
* Node Class
|
||||
*/
|
||||
protected $nodeClass = 'IPS\nexus\Fraud\Rule';
|
||||
|
||||
/**
|
||||
* Description can contain HTML?
|
||||
*/
|
||||
public $_descriptionHtml = TRUE;
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'fraud_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function manage()
|
||||
{
|
||||
foreach ( \IPS\nexus\Fraud\Rule::roots() as $rule )
|
||||
{
|
||||
foreach ( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_fraud_rules', array( 'f_order>?', $rule->order ) ), 'IPS\nexus\Fraud\Rule' ) as $otherRule )
|
||||
{
|
||||
if ( $rule->isSubsetOf( $otherRule ) )
|
||||
{
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->message( \IPS\Member::loggedIn()->language()->addToStack('fraud_rule_conflict', FALSE, array( 'sprintf' => array( $rule->name, $otherRule->name ) ) ), 'warning', NULL, FALSE );
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
parent::manage();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Payment Gateways
|
||||
* @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 10 Feb 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\admin\payments;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Payment Gateways
|
||||
*/
|
||||
class _gateways extends \IPS\Node\Controller
|
||||
{
|
||||
/**
|
||||
* Node Class
|
||||
*/
|
||||
protected $nodeClass = 'IPS\nexus\Gateway';
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'gateways_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Root Buttons
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function _getRootButtons()
|
||||
{
|
||||
$buttons = parent::_getRootButtons();
|
||||
|
||||
if ( isset( $buttons['add'] ) )
|
||||
{
|
||||
$buttons['add']['link'] = $buttons['add']['link']->setQueryString( '_new', TRUE );
|
||||
}
|
||||
|
||||
return $buttons;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add/Edit Form
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function form()
|
||||
{
|
||||
if ( \IPS\Request::i()->id )
|
||||
{
|
||||
return parent::form();
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( \IPS\IN_DEV )
|
||||
{
|
||||
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'plupload/moxie.js', 'core', 'interface' ) );
|
||||
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'plupload/plupload.dev.js', 'core', 'interface' ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'plupload/plupload.full.min.js', 'core', 'interface' ) );
|
||||
}
|
||||
\IPS\Output::i()->output = new \IPS\Helpers\Wizard( array(
|
||||
'gateways_gateway' => function( $data )
|
||||
{
|
||||
$options = array();
|
||||
foreach ( new \DirectoryIterator( \IPS\ROOT_PATH . '/applications/nexus/sources/Gateway' ) as $file )
|
||||
{
|
||||
if ( $file->isDir() and !$file->isDot() )
|
||||
{
|
||||
if ( ( (string) $file === 'Test' and !\IPS\NEXUS_TEST_GATEWAYS ) or (string) $file === 'SagePay' )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
$options[ (string) $file ] = 'gateway__' . $file;
|
||||
}
|
||||
}
|
||||
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'gateways_gateway', TRUE, NULL, array( 'options' => $options ) ) );
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
return array( 'gateway' => $values['gateways_gateway'] );
|
||||
}
|
||||
return $form;
|
||||
},
|
||||
'gateways_details' => function( $data )
|
||||
{
|
||||
$form = new \IPS\Helpers\Form('gw');
|
||||
$form->add( new \IPS\Helpers\Form\Translatable( 'paymethod_name', \IPS\Member::loggedIn()->language()->addToStack( 'gateway__' . $data['gateway'] ), TRUE ) );
|
||||
$class = 'IPS\nexus\Gateway\\' . $data['gateway'];
|
||||
$obj = new $class;
|
||||
$obj->gateway = $data['gateway'];
|
||||
$obj->active = TRUE;
|
||||
$obj->settings( $form );
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
|
||||
$settings = array();
|
||||
foreach ( $values as $k => $v )
|
||||
{
|
||||
if ( $k !== 'paymethod_name' )
|
||||
{
|
||||
$settings[ mb_substr( $k, mb_strlen( $data['gateway'] ) + 1 ) ] = $v;
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
$settings = $obj->testSettings( $settings );
|
||||
}
|
||||
catch ( \InvalidArgumentException $e )
|
||||
{
|
||||
$form->error = $e->getMessage();
|
||||
return $form;
|
||||
}
|
||||
$obj->settings = json_encode( $settings );
|
||||
$obj->save();
|
||||
\IPS\Lang::saveCustom( 'nexus', "nexus_paymethod_{$obj->id}", $values['paymethod_name'] );
|
||||
|
||||
$values = $obj->formatFormValues( $values );
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=payments&controller=paymentsettings&tab=gateways') );
|
||||
}
|
||||
return $form;
|
||||
}
|
||||
), \IPS\Http\Url::internal('app=nexus&module=payments&controller=paymentsettings&tab=gateways&do=form') );
|
||||
}
|
||||
}
|
||||
}
|
||||
Whitespace-only changes.
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Invoice Timeline
|
||||
* @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 19 Jun 2015
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\admin\payments;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoice Timeline
|
||||
*/
|
||||
class _invoiceTimeline extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* Manage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'invoiceTimeline.css', 'nexus', 'admin' ) );
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('invoices')->invoiceTimeline();
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Payment Settings
|
||||
* @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 26 Mar 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\admin\payments;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Payment Settings
|
||||
*/
|
||||
class _paymentsettings extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* Call
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __call( $method, $args )
|
||||
{
|
||||
$tabs = array();
|
||||
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'currencies_manage' ) )
|
||||
{
|
||||
$tabs['currencies'] = 'currencies';
|
||||
}
|
||||
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'gateways_manage' ) )
|
||||
{
|
||||
$tabs['gateways'] = 'payment_methods';
|
||||
}
|
||||
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'tax_manage' ) )
|
||||
{
|
||||
$tabs['tax'] = 'tax_rates';
|
||||
}
|
||||
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'checkout_settings' ) )
|
||||
{
|
||||
$tabs['checkoutsettings'] = 'checkout_settings';
|
||||
}
|
||||
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'fraud_manage' ) )
|
||||
{
|
||||
$tabs['fraud'] = 'anti_fraud_rules';
|
||||
}
|
||||
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'transaction_review_settings' ) )
|
||||
{
|
||||
$tabs['review'] = 'transaction_review';
|
||||
}
|
||||
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'email_copies_setting' ) )
|
||||
{
|
||||
$tabs['emails'] = 'notification_copies';
|
||||
}
|
||||
|
||||
if ( isset( \IPS\Request::i()->tab ) and isset( $tabs[ \IPS\Request::i()->tab ] ) )
|
||||
{
|
||||
$activeTab = \IPS\Request::i()->tab;
|
||||
}
|
||||
else
|
||||
{
|
||||
$_tabs = array_keys( $tabs ) ;
|
||||
$activeTab = array_shift( $_tabs );
|
||||
}
|
||||
|
||||
$classname = 'IPS\nexus\modules\admin\payments\\' . $activeTab;
|
||||
$class = new $classname;
|
||||
$class->url = \IPS\Http\Url::internal("app=nexus&module=payments&controller=paymentsettings&tab={$activeTab}");
|
||||
$class->execute();
|
||||
|
||||
if ( $method !== 'manage' or \IPS\Request::i()->isAjax() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('payment_settings');
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->tabs( $tabs, $activeTab, \IPS\Output::i()->output, \IPS\Http\Url::internal( "app=nexus&module=payments&controller=paymentsettings" ) );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,384 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Payouts
|
||||
* @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 07 Apr 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\admin\payments;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Payouts
|
||||
*/
|
||||
class _payouts extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'payouts_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Payout Requests
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
/* Redirect to settings if we haven't set it up */
|
||||
if ( !\IPS\Settings::i()->nexus_payout )
|
||||
{
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=nexus&module=payments&controller=payouts&do=settings' ) );
|
||||
}
|
||||
|
||||
/* Build table */
|
||||
$table = \IPS\nexus\Payout::table( array(), \IPS\Http\Url::internal('app=nexus&module=payments&controller=payouts') );
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__nexus_payments_payouts');
|
||||
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'payouts_settings' ) )
|
||||
{
|
||||
\IPS\Output::i()->sidebar['actions'] = array(
|
||||
'settings' => array(
|
||||
'icon' => 'cog',
|
||||
'title' => 'account_credit_settings',
|
||||
'link' => \IPS\Http\Url::internal( 'app=nexus&module=payments&controller=payouts&do=settings' )
|
||||
),
|
||||
);
|
||||
|
||||
foreach ( \IPS\Db::i()->select( 'po_gateway', 'nexus_payouts', array( 'po_status=?', \IPS\nexus\Payout::STATUS_PENDING ), NULL, NULL, 'po_gateway' ) as $gateway )
|
||||
{
|
||||
$classname = 'IPS\nexus\Gateway\\' . $gateway . '\Payout';
|
||||
if ( class_exists( $classname ) and method_exists( $classname, 'massProcess' ) )
|
||||
{
|
||||
\IPS\Output::i()->sidebar['actions'][] = array(
|
||||
'icon' => 'check',
|
||||
'title' => \IPS\Member::loggedIn()->language()->addToStack( 'account_credit_mass_payout', TRUE, array( 'sprintf' => array( \IPS\Member::loggedIn()->language()->addToStack( 'payout__admin_' . $gateway ) ) ) ),
|
||||
'link' => \IPS\Http\Url::internal( 'app=nexus&module=payments&controller=payouts&do=massprocess&gateway=' . $gateway )
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
\IPS\Output::i()->output = (string) $table;
|
||||
}
|
||||
|
||||
/**
|
||||
* View
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function view()
|
||||
{
|
||||
try
|
||||
{
|
||||
$payout = \IPS\nexus\Payout::load( \IPS\Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X200/2', 404, '' );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->sidebar['actions'] = $payout->buttons( 'v' );
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'payout_number', FALSE, array( 'sprintf' => array( $payout->id ) ) );
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('payouts')->view( $payout );
|
||||
}
|
||||
|
||||
/**
|
||||
* Approve
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function process()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'payouts_process' );
|
||||
|
||||
try
|
||||
{
|
||||
$payout = \IPS\nexus\Payout::load( \IPS\Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X200/3', 404, '' );
|
||||
}
|
||||
|
||||
if ( $payout->status !== $payout::STATUS_PENDING )
|
||||
{
|
||||
\IPS\Output::i()->error( 'err_payout_not_pending', '1X200/4', 403, '' );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$payout->process();
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
{
|
||||
\IPS\Output::i()->error( $e->getMessage(), '1X200/1', 500, '' );
|
||||
}
|
||||
|
||||
$payout->status = $payout::STATUS_COMPLETE;
|
||||
$payout->processed_by = \IPS\Member::loggedIn();
|
||||
$payout->save();
|
||||
\IPS\Session::i()->log( 'acplogs__payout_processed', array( $payout->id => FALSE ) );
|
||||
$payout->member->log( 'payout', array( 'type' => 'processed', 'amount' => $payout->amount->amount, 'currency' => $payout->amount->currency, 'payout_id' => $payout->id ) );
|
||||
|
||||
\IPS\Email::buildFromTemplate( 'nexus', 'payoutComplete', array( $payout ) )->send( $payout->member );
|
||||
|
||||
$this->_redirect( $payout );
|
||||
}
|
||||
|
||||
/**
|
||||
* Mass Approve
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function massprocess()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'payouts_process' );
|
||||
|
||||
$classname = 'IPS\nexus\Gateway\\' . \IPS\Request::i()->gateway . '\Payout';
|
||||
if ( !class_exists( $classname ) or !method_exists( $classname, 'massProcess' ) )
|
||||
{
|
||||
\IPS\Output::i()->error( 'generic_error', '2X200/8', 403, '' );
|
||||
}
|
||||
|
||||
$payouts = new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_payouts', array( 'po_status=? AND po_gateway=?', \IPS\nexus\Payout::STATUS_PENDING, \IPS\Request::i()->gateway ) ), $classname );
|
||||
|
||||
try
|
||||
{
|
||||
$classname::massProcess( $payouts );
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
{
|
||||
\IPS\Output::i()->error( $e->getMessage(), '1X200/9', 403, '' );
|
||||
}
|
||||
|
||||
foreach ( $payouts as $payout )
|
||||
{
|
||||
$payout->status = $payout::STATUS_COMPLETE;
|
||||
$payout->completed = new \IPS\DateTime;
|
||||
$payout->processed_by = \IPS\Member::loggedIn();
|
||||
$payout->save();
|
||||
\IPS\Session::i()->log( 'acplogs__payout_processed', array( $payout->id => FALSE ) );
|
||||
$payout->member->log( 'payout', array( 'type' => 'processed', 'amount' => $payout->amount->amount, 'currency' => $payout->amount->currency, 'payout_id' => $payout->id ) );
|
||||
|
||||
\IPS\Email::buildFromTemplate( 'nexus', 'payoutComplete', array( $payout ) )->send( $payout->member );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=payments&controller=payouts') );
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function cancel()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'payouts_cancel' );
|
||||
|
||||
try
|
||||
{
|
||||
$payout = \IPS\nexus\Payout::load( \IPS\Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X200/6', 404, '' );
|
||||
}
|
||||
|
||||
if ( $payout->status !== $payout::STATUS_PENDING )
|
||||
{
|
||||
\IPS\Output::i()->error( 'err_payout_not_pending', '1X200/5', 403, '' );
|
||||
}
|
||||
|
||||
$payout->status = $payout::STATUS_CANCELED;
|
||||
$payout->completed = new \IPS\DateTime;
|
||||
$payout->processed_by = \IPS\Member::loggedIn();
|
||||
$payout->save();
|
||||
\IPS\Session::i()->log( 'acplogs__payout_cancelled', array( $payout->id => FALSE ) );
|
||||
$payout->member->log( 'payout', array( 'type' => 'cancel', 'amount' => $payout->amount->amount, 'currency' => $payout->amount->currency, 'payout_id' => $payout->id ) );
|
||||
|
||||
if ( \IPS\Request::i()->prompt )
|
||||
{
|
||||
$credits = $payout->member->cm_credits;
|
||||
$credits[ $payout->currency ]->amount += $payout->amount->amount;
|
||||
$payout->member->cm_credits = $credits;
|
||||
$payout->member->save();
|
||||
}
|
||||
|
||||
$this->_redirect( $payout );
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function delete()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'payouts_delete' );
|
||||
|
||||
try
|
||||
{
|
||||
$payout = \IPS\nexus\Payout::load( \IPS\Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X200/7', 404, '' );
|
||||
}
|
||||
|
||||
$payout->delete();
|
||||
\IPS\Session::i()->log( 'acplogs__payout_deleted', array( $payout->id => FALSE ) );
|
||||
$payout->member->log( 'payout', array( 'type' => 'dismissed', 'amount' => $payout->amount->amount, 'currency' => $payout->amount->currency, 'payout_id' => $payout->id ) );
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=payments&controller=payouts') );
|
||||
}
|
||||
|
||||
/**
|
||||
* Payout Settings
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function settings()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'payouts_settings' );
|
||||
|
||||
$options = array();
|
||||
$toggles = array();
|
||||
$fields = array();
|
||||
foreach ( new \DirectoryIterator( \IPS\ROOT_PATH . '/applications/nexus/sources/Gateway' ) as $file )
|
||||
{
|
||||
if ( $file->isDir() and !$file->isDot() and file_exists( \IPS\ROOT_PATH . '/applications/nexus/sources/Gateway/' . $file . '/Payout.php' ) )
|
||||
{
|
||||
$options[ (string) $file ] = 'payout__admin_' . $file;
|
||||
$toggles[ (string) $file ] = array( 'form_header_payout_settings' );
|
||||
|
||||
$class = 'IPS\nexus\Gateway\\' . (string) $file . '\\Payout';
|
||||
foreach ( $class::settings() as $field )
|
||||
{
|
||||
if ( !$field->htmlId )
|
||||
{
|
||||
$field->htmlId = md5(uniqid());
|
||||
}
|
||||
|
||||
$fields[] = $field;
|
||||
$toggles[ (string) $file ][] = $field->htmlId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$groups = array();
|
||||
foreach ( \IPS\Member\Group::groups( TRUE, FALSE ) as $group )
|
||||
{
|
||||
$groups[ $group->g_id ] = $group->name;
|
||||
}
|
||||
|
||||
$settings = \IPS\Settings::i()->nexus_payout ? json_decode( \IPS\Settings::i()->nexus_payout, TRUE ) : array();
|
||||
$settings = is_array( $settings ) ? array_keys( $settings ) : array();
|
||||
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->addMessage('payout_description');
|
||||
$form->addHeader('commission_settings');
|
||||
$form->add( new \IPS\Helpers\Form\Select( 'nexus_no_commission', explode( ',', \IPS\Settings::i()->nexus_no_commission ), FALSE, array( 'multiple' => TRUE, 'options' => $groups ) ) );
|
||||
$form->addHeader('withdrawal_methods');
|
||||
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'nexus_payout', $settings, FALSE, array( 'options' => $options, 'toggles' => $toggles ) ) );
|
||||
foreach ( $fields as $field )
|
||||
{
|
||||
$form->add( $field );
|
||||
}
|
||||
$form->addHeader('payout_settings');
|
||||
$form->add( new \IPS\nexus\Form\Money( 'nexus_payout_min', \IPS\Settings::i()->nexus_payout_min ? json_decode( \IPS\Settings::i()->nexus_payout_min, TRUE ) : '*', FALSE, array( 'unlimitedLang' => 'no_restriction' ), NULL, NULL, NULL, 'nexus_payout_min' ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'nexus_payout_approve', \IPS\Settings::i()->nexus_payout_approve, FALSE, array(), NULL, NULL, NULL, 'nexus_payout_approve' ) );
|
||||
$form->addHeader('topup_settings');
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'allow_topups', \IPS\Settings::i()->nexus_min_topup, FALSE, array( 'togglesOn' => array( 'nexus_min_topup', 'nexus_max_credit' ) ) ) );
|
||||
$form->add( new \IPS\nexus\Form\Money( 'nexus_min_topup', \IPS\Settings::i()->nexus_min_topup ?: '*', FALSE, array( 'unlimitedLang' => 'no_restriction' ), NULL, NULL, NULL, 'nexus_min_topup' ) );
|
||||
$form->add( new \IPS\nexus\Form\Money( 'nexus_max_credit', \IPS\Settings::i()->nexus_max_credit ?: '*', FALSE, array( 'unlimitedLang' => 'no_restriction' ), NULL, NULL, NULL, 'nexus_max_credit' ) );
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
$payoutSettings = array();
|
||||
foreach ( $values['nexus_payout'] as $k )
|
||||
{
|
||||
$payoutSettings[ $k ] = array();
|
||||
foreach ( $values as $l => $v )
|
||||
{
|
||||
if ( mb_substr( $l, 0, mb_strlen( $k ) ) === mb_strtolower( $k ) )
|
||||
{
|
||||
$payoutSettings[ $k ][ mb_substr( $l, mb_strlen( $k ) + 1 ) ] = $v;
|
||||
unset( $values[ $l ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$values['nexus_payout'] = json_encode( $payoutSettings );
|
||||
$values['nexus_payout_min'] = is_array( $values['nexus_payout_min'] ) ? json_encode( $values['nexus_payout_min'] ) : '*';
|
||||
|
||||
if ( $values['allow_topups'] )
|
||||
{
|
||||
$values['nexus_min_topup'] = $values['nexus_min_topup'] == '*' ? '*' : json_encode( $values['nexus_min_topup'] );
|
||||
$values['nexus_max_credit'] = $values['nexus_max_credit'] == '*' ? '*' : json_encode( $values['nexus_max_credit'] );
|
||||
}
|
||||
else
|
||||
{
|
||||
$values['nexus_min_topup'] = '';
|
||||
$values['nexus_max_credit'] = '';
|
||||
}
|
||||
unset( $values['allow_topups'] );
|
||||
|
||||
$values['nexus_no_commission'] = implode( ',', $values['nexus_no_commission'] );
|
||||
|
||||
$form->saveAsSettings( $values );
|
||||
\IPS\Session::i()->log( 'acplogs__payout_settings' );
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=payments&controller=payouts'), 'saved' );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('account_credit_settings');
|
||||
\IPS\Output::i()->output = $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect
|
||||
*
|
||||
* @param \IPS\nexus\Payout $payout The payout
|
||||
* @return void
|
||||
*/
|
||||
protected function _redirect( \IPS\nexus\Payout $payout )
|
||||
{
|
||||
if ( isset( \IPS\Request::i()->r ) )
|
||||
{
|
||||
switch ( mb_substr( \IPS\Request::i()->r, 0, 1 ) )
|
||||
{
|
||||
case 'v':
|
||||
\IPS\Output::i()->redirect( $payout->acpUrl() );
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
\IPS\Output::i()->redirect( $payout->member->acpUrl() );
|
||||
break;
|
||||
|
||||
case 't':
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=payments&controller=payouts')->setQueryString( 'filter', \IPS\Request::i()->filter ) );
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
\IPS\Output::i()->redirect( $payout->acpUrl() );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Transaction Review
|
||||
* @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 26 Mar 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\admin\payments;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transaction Review
|
||||
*/
|
||||
class _review extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'transaction_review_settings' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function manage()
|
||||
{
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'nexus_revw_sa_on', \IPS\Settings::i()->nexus_revw_sa != -1, FALSE, array( 'togglesOn' => array( 'nexus_revw_sa' ) ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'nexus_revw_sa', \IPS\Settings::i()->nexus_revw_sa ?: 0, FALSE, array( 'class' => 'IPS\nexus\Support\StockAction', 'zeroVal' => 'do_not_suggest_stock_action' ), NULL, NULL, NULL, 'nexus_revw_sa' ) );
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
if ( !$values['nexus_revw_sa_on'] )
|
||||
{
|
||||
$values['nexus_revw_sa'] = -1;
|
||||
}
|
||||
elseif ( $values['nexus_revw_sa'] )
|
||||
{
|
||||
$values['nexus_revw_sa'] = $values['nexus_revw_sa']->id;
|
||||
}
|
||||
unset( $values['nexus_revw_sa_on'] );
|
||||
|
||||
$form->saveAsSettings( $values );
|
||||
|
||||
\IPS\Session::i()->log( 'acplogs__transaction_review_settings' );
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=nexus&module=payments&controller=paymentsettings&tab=review' ), 'saved' );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->output = $form;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,711 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Shipments
|
||||
* @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 20 Mar 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\admin\payments;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shipments
|
||||
*/
|
||||
class _shipping extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'shiporders_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
/* Create the table */
|
||||
$table = new \IPS\Helpers\Table\Db( 'nexus_ship_orders', \IPS\Http\Url::internal( 'app=nexus&module=payments&controller=shipping' ) );
|
||||
$table->sortBy = $table->sortBy ?: 'o_date';
|
||||
|
||||
/* Format Columns */
|
||||
$table->include = array( 'o_status', 'o_method', 'o_invoice', 'o_date' );
|
||||
$table->parsers = array(
|
||||
'o_status' => function( $val )
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate('shiporders')->status( $val );
|
||||
},
|
||||
'o_method' => function( $val, $row )
|
||||
{
|
||||
if ( $row['o_api_service'] )
|
||||
{
|
||||
return $row['o_api_service'];
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return \IPS\nexus\Shipping\FlatRate::load( $val )->_title;
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
{
|
||||
return '';
|
||||
}
|
||||
},
|
||||
'o_invoice' => function( $val )
|
||||
{
|
||||
try
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate('invoices')->link( \IPS\nexus\Invoice::load( $val ) );
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
{
|
||||
return '';
|
||||
}
|
||||
},
|
||||
'o_date' => function( $val )
|
||||
{
|
||||
return (string) \IPS\DateTime::ts( $val );
|
||||
}
|
||||
);
|
||||
|
||||
/* Filters */
|
||||
$table->filters = array(
|
||||
'sstatus_pend' => array( 'o_status=?', 'pend' ),
|
||||
);
|
||||
|
||||
/* Search */
|
||||
$methods = array();
|
||||
foreach( \IPS\nexus\Shipping\FlatRate::roots() as $method )
|
||||
{
|
||||
$methods[ $method->id ] = $method->_title;
|
||||
}
|
||||
$table->advancedSearch = array(
|
||||
'o_status' => array( \IPS\Helpers\Table\SEARCH_SELECT, array( 'options' => array(
|
||||
\IPS\nexus\Shipping\Order::STATUS_SHIPPED => 'sstatus_done',
|
||||
\IPS\nexus\Shipping\Order::STATUS_PENDING => 'sstatus_pend',
|
||||
\IPS\nexus\Shipping\Order::STATUS_CANCELED => 'sstatus_canc',
|
||||
), 'multiple' => TRUE ) ),
|
||||
'o_method' => array( \IPS\Helpers\Table\SEARCH_SELECT, array( 'options' => $methods, 'multiple' => TRUE ) ),
|
||||
'o_date' => \IPS\Helpers\Table\SEARCH_DATE_RANGE,
|
||||
'o_shipped_date'=> \IPS\Helpers\Table\SEARCH_DATE_RANGE,
|
||||
'o_tracknumber' => \IPS\Helpers\Table\SEARCH_CONTAINS_TEXT,
|
||||
);
|
||||
$table->quickSearch = 'o_tracknumber';
|
||||
|
||||
/* Buttons */
|
||||
$table->rowButtons = function( $row )
|
||||
{
|
||||
return array_merge( array(
|
||||
'view' => array(
|
||||
'icon' => 'search',
|
||||
'title' => 'shipment_view',
|
||||
'link' => \IPS\Http\Url::internal( "app=nexus&module=payments&controller=shipping&do=view&id={$row['o_id']}" )
|
||||
)
|
||||
), \IPS\nexus\Shipping\Order::constructFromData( $row )->buttons( 't' ) );
|
||||
};
|
||||
|
||||
/* Settings Button */
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'shipmethods_manage' ) )
|
||||
{
|
||||
\IPS\Output::i()->sidebar['actions']['settings'] = array(
|
||||
'title' => 'shipping_rates',
|
||||
'icon' => 'cog',
|
||||
'link' => \IPS\Http\Url::internal('app=nexus&module=payments&controller=shippingrates'),
|
||||
);
|
||||
}
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('shipping');
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->block( 'title', (string) $table );
|
||||
}
|
||||
|
||||
/**
|
||||
* View
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function view()
|
||||
{
|
||||
/* Load */
|
||||
try
|
||||
{
|
||||
$shipment = \IPS\nexus\Shipping\Order::load( \IPS\Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X193/1', 404, '' );
|
||||
}
|
||||
|
||||
$easyPost = NULL;
|
||||
if ( \IPS\Settings::i()->easypost_api_key )
|
||||
{
|
||||
$extra = json_decode( $shipment->extra, TRUE );
|
||||
if ( isset( $extra['shipment'] ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$easyPost = \IPS\Http\Url::external( 'https://api.easypost.com/v2/shipments/' . $extra['shipment'] )->request()->login( \IPS\Settings::i()->easypost_api_key, '' )->get()->decodeJson();
|
||||
}
|
||||
catch ( \IPS\Http\Request\Exception $e ) { }
|
||||
}
|
||||
}
|
||||
|
||||
/* Add Buttons */
|
||||
\IPS\Output::i()->sidebar['actions'] = $shipment->buttons( 'v' );
|
||||
|
||||
/* Output */
|
||||
\IPS\Output::i()->title = $shipment->method ? \IPS\Member::loggedIn()->language()->addToStack( 'shipment_number_with_method', FALSE, array( 'sprintf' => array( $shipment->id, $shipment->method->_title ) ) ) : \IPS\Member::loggedIn()->language()->addToStack( 'shipment_number', FALSE, array( 'sprintf' => array( $shipment->id ) ) );
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'shiporders' )->view( $shipment, $easyPost );
|
||||
}
|
||||
|
||||
/**
|
||||
* Ship
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function ship()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'shiporders_edit' );
|
||||
|
||||
/* Load */
|
||||
try
|
||||
{
|
||||
$shipment = \IPS\nexus\Shipping\Order::load( \IPS\Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X193/2', 404, '' );
|
||||
}
|
||||
|
||||
/* Build Form */
|
||||
$form = new \IPS\Helpers\Form( 'form', 'shipment_ship' );
|
||||
if ( \IPS\Settings::i()->easypost_api_key )
|
||||
{
|
||||
/* Calculate stuff */
|
||||
$weightInOz = 0;
|
||||
$lengthInInches = 0;
|
||||
$widthInInches = 0;
|
||||
$heightInInches = 0;
|
||||
foreach ( $shipment->items as $item )
|
||||
{
|
||||
$weight = new \IPS\nexus\Shipping\Weight( $item['weight']['kilograms'] );
|
||||
$weightInOz += ( $weight->float('oz') * $item['quantity'] );
|
||||
|
||||
foreach ( array( 'length', 'width', 'height' ) as $k )
|
||||
{
|
||||
$dim = new \IPS\nexus\Shipping\Length( $item[ $k ]['metres'] );
|
||||
$v = "{$k}InInches";
|
||||
$$v += ( $dim->float('in') * $item['quantity'] );
|
||||
}
|
||||
}
|
||||
|
||||
/* Method */
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'shipment_ship_method', 'easypost', TRUE, array(
|
||||
'options' => array( 'easypost' => 'shipment_ship_easypost', 'manual' => 'shipment_ship_manual' ),
|
||||
'toggles' => array(
|
||||
'easypost' => array( 'form_header_easypost_package_header', 'easypost_package', 'easypost_package_weight', 'form_header_easypost_customs_header', 'easypost_customs_details' ),
|
||||
'manual' => array( 'o_tracknumber', 'tracking_url' )
|
||||
)
|
||||
) ) );
|
||||
|
||||
/* Parcel */
|
||||
$form->addHeader( 'easypost_package_header' );
|
||||
$form->add( new \IPS\Helpers\Form\Select( 'easypost_package', 'custom', NULL, array(
|
||||
'options' => array(
|
||||
'custom' => 'easypost_package_custom',
|
||||
'easypost_package_usps' => array(
|
||||
'Card' => 'easypost_package_usps_Card',
|
||||
'Letter' => 'easypost_package_usps_Letter',
|
||||
'Flat' => 'easypost_package_usps_Flat',
|
||||
'Parcel' => 'easypost_package_usps_Parcel',
|
||||
'LargeParcel' => 'easypost_package_usps_LargeParcel',
|
||||
'IrregularParcel' => 'easypost_package_usps_IrregularParcel',
|
||||
'FlatRateEnvelope' => 'easypost_package_usps_FlatRateEnvelope',
|
||||
'FlatRateLegalEnvelope' => 'easypost_package_usps_FlatRateLegalEnvelope',
|
||||
'FlatRatePaddedEnvelope' => 'easypost_package_usps_FlatRatePaddedEnvelope',
|
||||
'FlatRateGiftCardEnvelope' => 'easypost_package_usps_FlatRateGiftCardEnvelope',
|
||||
'FlatRateWindowEnvelope' => 'easypost_package_usps_FlatRateWindowEnvelope',
|
||||
'FlatRateCardboardEnvelope' => 'easypost_package_usps_FlatRateCardboardEnvelope',
|
||||
'SmallFlatRateEnvelope' => 'easypost_package_usps_SmallFlatRateEnvelope',
|
||||
'SmallFlatRateBox' => 'easypost_package_usps_SmallFlatRateBox',
|
||||
'MediumFlatRateBox' => 'easypost_package_usps_MediumFlatRateBox',
|
||||
'LargeFlatRateBox' => 'easypost_package_usps_LargeFlatRateBox',
|
||||
'RegionalRateBoxA' => 'easypost_package_usps_RegionalRateBoxA',
|
||||
'RegionalRateBoxB' => 'easypost_package_usps_RegionalRateBoxB',
|
||||
'RegionalRateBoxC' => 'easypost_package_usps_RegionalRateBoxC',
|
||||
'LargeFlatRateBoardGameBox' => 'easypost_package_usps_LargeFlatRateBoardGameBox',
|
||||
),
|
||||
'easypost_package_ups' => array(
|
||||
'UPSLetter' => 'easypost_package_ups_UPSLetter',
|
||||
'UPSExpressBox' => 'easypost_package_ups_UPSExpressBox',
|
||||
'UPS25kgBox' => 'easypost_package_ups_UPS25kgBox',
|
||||
'UPS10kgBox' => 'easypost_package_ups_UPS10kgBox',
|
||||
'Tube' => 'easypost_package_ups_Tube',
|
||||
'Pak' => 'easypost_package_ups_Pak',
|
||||
'Pallet' => 'easypost_package_ups_Pallet',
|
||||
'SmallExpressBox' => 'easypost_package_ups_SmallExpressBox',
|
||||
'MediumExpressBox' => 'easypost_package_ups_MediumExpressBox',
|
||||
'LargeExpressBox' => 'easypost_package_ups_LargeExpressBox',
|
||||
),
|
||||
'easypost_package_fedex' => array(
|
||||
'FedExEnvelope' => 'easypost_package_fedex_FedExEnvelope',
|
||||
'FedExBox' => 'easypost_package_fedex_FedExBox',
|
||||
'FedExPak' => 'easypost_package_fedex_FedExPak',
|
||||
'FedExTube' => 'easypost_package_fedex_FedExTube',
|
||||
'FedEx10kgBox' => 'easypost_package_fedex_FedEx10kgBox',
|
||||
'FedEx25kgBox' => 'easypost_package_fedex_FedEx25kgBox',
|
||||
),
|
||||
),
|
||||
'toggles' => array(
|
||||
'custom' => array( 'easypost_package_length', 'easypost_package_width', 'easypost_package_height' )
|
||||
)
|
||||
), NULL, NULL, NULL, 'easypost_package' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'easypost_package_length', $lengthInInches, NULL, array(), function( $val )
|
||||
{
|
||||
if ( !$val and \IPS\Request::i()->shipment_ship_method == 'easypost' and \IPS\Request::i()->easypost_package == 'custom' )
|
||||
{
|
||||
throw new \DomainException('form_required');
|
||||
}
|
||||
}, NULL, \IPS\Member::loggedIn()->language()->addToStack('inches'), 'easypost_package_length' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'easypost_package_width', $widthInInches, NULL, array(), function( $val )
|
||||
{
|
||||
if ( !$val and \IPS\Request::i()->shipment_ship_method == 'easypost' and \IPS\Request::i()->easypost_package == 'custom' )
|
||||
{
|
||||
throw new \DomainException('form_required');
|
||||
}
|
||||
}, NULL, \IPS\Member::loggedIn()->language()->addToStack('inches'), 'easypost_package_width' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'easypost_package_height', $heightInInches, NULL, array(), function( $val )
|
||||
{
|
||||
if ( !$val and \IPS\Request::i()->shipment_ship_method == 'easypost' and \IPS\Request::i()->easypost_package == 'custom' )
|
||||
{
|
||||
throw new \DomainException('form_required');
|
||||
}
|
||||
}, NULL, \IPS\Member::loggedIn()->language()->addToStack('inches'), 'easypost_package_height' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'easypost_package_weight', $weightInOz, NULL, array( 'decimals' => 1 ), function( $val )
|
||||
{
|
||||
if ( !$val and \IPS\Request::i()->shipment_ship_method == 'easypost' )
|
||||
{
|
||||
throw new \DomainException('form_required');
|
||||
}
|
||||
}, NULL, 'oz', 'easypost_package_weight' ) );
|
||||
|
||||
$matrix = NULL;
|
||||
$fromCountry = \IPS\GeoLocation::buildFromJson( \IPS\Settings::i()->site_address )->country;
|
||||
if ( $fromCountry != $shipment->data['address']['country'] )
|
||||
{
|
||||
$originCountries = array();
|
||||
foreach ( \IPS\GeoLocation::$countries as $code )
|
||||
{
|
||||
$originCountries[ $code ] = 'country-' . $code;
|
||||
}
|
||||
|
||||
$matrix = new \IPS\Helpers\Form\Matrix;
|
||||
$matrix->columns = array(
|
||||
'epc_description' => function( $key, $value, $data )
|
||||
{
|
||||
return new \IPS\Helpers\Form\Text( $key, $value, TRUE );
|
||||
},
|
||||
'epc_quantity' => function( $key, $value, $data )
|
||||
{
|
||||
return new \IPS\Helpers\Form\Number( $key, $value ?: 1, TRUE );
|
||||
},
|
||||
'epc_value' => function( $key, $value, $data )
|
||||
{
|
||||
return new \IPS\Helpers\Form\Number( $key, $value ?: 0, TRUE, array( 'decimals' => TRUE ) );
|
||||
},
|
||||
'epc_weight' => function( $key, $value, $data )
|
||||
{
|
||||
return new \IPS\Helpers\Form\Text( $key, $value ?: 0, TRUE, array( 'decimals' => 1 ) );
|
||||
},
|
||||
'epc_origin' => function( $key, $value, $data ) use ( $originCountries, $fromCountry )
|
||||
{
|
||||
return new \IPS\Helpers\Form\Select( $key, $value ?: $fromCountry, FALSE, array( 'options' => $originCountries ) );
|
||||
},
|
||||
'epc_hs_tarrif' => function( $key, $value, $data )
|
||||
{
|
||||
return new \IPS\Helpers\Form\Text( $key, $value, FALSE, array( 'maxLength' => 6, 'placeholder' => \IPS\Member::loggedIn()->language()->addToStack('optional') ) );
|
||||
},
|
||||
);
|
||||
foreach ( $shipment->items as $item )
|
||||
{
|
||||
$weight = new \IPS\nexus\Shipping\Weight( $item['weight']['kilograms'] );
|
||||
$matrix->rows[] = array(
|
||||
'epc_description' => $item['name'],
|
||||
'epc_quantity' => $item['quantity'],
|
||||
'epc_value' => $item['price']['currency'] === 'USD' ? $item['price']['amount'] : 0,
|
||||
'epc_weight' => round( $weight->float('oz'), 1 )
|
||||
);
|
||||
}
|
||||
|
||||
$form->addHeader( 'easypost_customs_header' );
|
||||
$form->addMatrix( 'easypost_customs_details', $matrix );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'o_tracknumber', NULL, FALSE, array( 'maxLength' => 255 ), NULL, NULL, NULL, 'o_tracknumber' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Url( 'tracking_url', NULL, FALSE, array( 'maxLength' => 255 ), NULL, NULL, NULL, 'tracking_url' ) );
|
||||
|
||||
/* Handle Submissions */
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
/* EasyPost */
|
||||
if ( isset( $values['shipment_ship_method'] ) AND $values['shipment_ship_method'] === 'easypost' )
|
||||
{
|
||||
try
|
||||
{
|
||||
/* Parcel Data */
|
||||
if ( $values['easypost_package'] === 'custom' )
|
||||
{
|
||||
$parcelData = array(
|
||||
'length' => $values['easypost_package_length'],
|
||||
'width' => $values['easypost_package_width'],
|
||||
'height' => $values['easypost_package_height'],
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$parcelData = array( 'predefined_package' => $values['easypost_package'] );
|
||||
}
|
||||
$parcelData['weight'] = $values['easypost_package_weight'];
|
||||
|
||||
/* Customs Info */
|
||||
$customsInfo = NULL;
|
||||
if ( isset( $values['easypost_customs_details'] ) )
|
||||
{
|
||||
$customItems = array();
|
||||
$totalValue = 0;
|
||||
foreach ( $values['easypost_customs_details'] as $customItem )
|
||||
{
|
||||
if ( $customItem['epc_description'] )
|
||||
{
|
||||
$totalValue += $customItem['epc_value'];
|
||||
$customItems[] = array(
|
||||
'description' => $customItem['epc_description'],
|
||||
'quantity' => $customItem['epc_quantity'],
|
||||
'value' => $customItem['epc_value'],
|
||||
'weight' => $customItem['epc_weight'],
|
||||
'hs_tariff_number' => $customItem['epc_hs_tarrif'],
|
||||
'origin_country' => $customItem['epc_origin'],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$customsInfo = array(
|
||||
'eel_pfc' => ( $totalValue < 2500 ) ? 'NOEEI 30.37(a)' : '',
|
||||
'contents_type' => 'merchandise',
|
||||
'customs_items' => $customItems
|
||||
);
|
||||
}
|
||||
|
||||
/* Send API call */
|
||||
$toAddress = $shipment->data['address'];
|
||||
$fromAddress = \IPS\GeoLocation::buildFromJson( \IPS\Settings::i()->site_address );
|
||||
$easyPost = \IPS\Http\Url::external( 'https://api.easypost.com/v2/shipments' )->request()->login( \IPS\Settings::i()->easypost_api_key, '' )->post( array( 'shipment' => array(
|
||||
'to_address' => array(
|
||||
'street1' => array_shift( $toAddress['addressLines'] ),
|
||||
'street2' => count( $toAddress['addressLines'] ) ? implode( ', ', $toAddress['addressLines'] ) : NULL,
|
||||
'city' => $toAddress['city'],
|
||||
'state' => $toAddress['region'],
|
||||
'zip' => $toAddress['postalCode'],
|
||||
'country' => $toAddress['country'],
|
||||
'name' => $shipment->data['cm_first_name'] . ' ' . $shipment->data['cm_last_name'],
|
||||
'phone' => $shipment->data['cm_phone'],
|
||||
'email' => $shipment->invoice->member->email
|
||||
),
|
||||
'from_address' => array(
|
||||
'street1' => array_shift( $fromAddress->addressLines ),
|
||||
'street2' => count( $fromAddress->addressLines ) ? implode( ', ', $fromAddress->addressLines ) : NULL,
|
||||
'city' => $fromAddress->city,
|
||||
'state' => $fromAddress->region,
|
||||
'zip' => $fromAddress->postalCode,
|
||||
'country' => $fromAddress->country,
|
||||
'company' => \IPS\Settings::i()->board_name,
|
||||
'phone' => \IPS\Settings::i()->easypost_phone,
|
||||
'email' => \IPS\Settings::i()->email_in
|
||||
),
|
||||
'parcel' => $parcelData,
|
||||
'customs_info' => $customsInfo
|
||||
) ) )->decodeJson();
|
||||
|
||||
if ( !count( $easyPost['rates'] ) )
|
||||
{
|
||||
\IPS\Output::i()->error( 'err_no_easypost', '1X193/6', 403, '' );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=nexus&module=payments&controller=shipping&do=easypost&id={$easyPost['id']}&shipment={$shipment->id}" ) );
|
||||
}
|
||||
catch ( \IPS\Http\Request\Exception $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'err_err_easypost', '3X193/7', 500, '', array(), $e->getMessage() );
|
||||
}
|
||||
}
|
||||
/* Manual */
|
||||
else
|
||||
{
|
||||
$shipment->status = \IPS\nexus\Shipping\Order::STATUS_SHIPPED;
|
||||
$shipment->shipped_date = new \IPS\DateTime;
|
||||
if ( $values['o_tracknumber'] )
|
||||
{
|
||||
$shipment->tracknumber = $values['o_tracknumber'];
|
||||
}
|
||||
if ( $values['tracking_url'] )
|
||||
{
|
||||
$shipment->service = $values['tracking_url'];
|
||||
}
|
||||
$shipment->save();
|
||||
$shipment->sendNotification();
|
||||
}
|
||||
|
||||
$shipment->invoice->member->log( 'shipping', array( 'id' => $shipment->id ) );
|
||||
$this->_redirect( $shipment );
|
||||
}
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'shipment_number', FALSE, array( 'sprintf' => array( $shipment->id ) ) );
|
||||
\IPS\Output::i()->output = $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* EasyPost
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function easypost()
|
||||
{
|
||||
/* Get Data */
|
||||
try
|
||||
{
|
||||
$easyPost = \IPS\Http\Url::external( 'https://api.easypost.com/v2/shipments/' . \IPS\Request::i()->id )->request()->login( \IPS\Settings::i()->easypost_api_key, '' )->get()->decodeJson();
|
||||
$shipment = \IPS\nexus\Shipping\Order::load( \IPS\Request::i()->shipment );
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'err_err_easypost', '3X193/8', 500, '', array(), $e->getMessage() );
|
||||
}
|
||||
|
||||
/* Gigure out our options */
|
||||
$selected = NULL;
|
||||
$options = array();
|
||||
$descriptions = array();
|
||||
foreach ( $easyPost['rates'] as $rate )
|
||||
{
|
||||
if ( $rate['service'] === $shipment->api_service )
|
||||
{
|
||||
$selected = $rate['id'];
|
||||
}
|
||||
|
||||
$service = '';
|
||||
for ( $i=0; $i<\strlen( $rate['service'] ); $i++ )
|
||||
{
|
||||
if ( \strtoupper( $rate['service'][ $i ] ) === $rate['service'][ $i ] )
|
||||
{
|
||||
$service .= " {$rate['service'][ $i ]}";
|
||||
}
|
||||
else
|
||||
{
|
||||
$service .= $rate['service'][ $i ];
|
||||
}
|
||||
}
|
||||
|
||||
$options[ $rate['id'] ] = $rate['carrier'] . $service . ' - ' . new \IPS\nexus\Money( $rate['rate'], $rate['currency'] );
|
||||
if ( $rate['est_delivery_days'] )
|
||||
{
|
||||
$descriptions[ $rate['id'] ] = \IPS\Member::loggedIn()->language()->addToStack( 'easypost_rates_desc', FALSE, array( 'sprintf' => array( $rate['est_delivery_days'] ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
/* Build form */
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'easypost_rate', $selected, TRUE, array( 'options' => $options, 'descriptions' => $descriptions ) ) );
|
||||
|
||||
/* Handle submissions */
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
try
|
||||
{
|
||||
$response = \IPS\Http\Url::external( 'https://api.easypost.com/v2/shipments/' . \IPS\Request::i()->id . '/buy' )->request()->login( \IPS\Settings::i()->easypost_api_key, '' )->post( array(
|
||||
'rate' => array(
|
||||
'id' => $values['easypost_rate']
|
||||
)
|
||||
) )->decodeJson();
|
||||
|
||||
if ( isset( $response['error'] ) )
|
||||
{
|
||||
\IPS\Output::i()->error( 'err_err_easypost', '3X193/9', 500, '', array(), $response['error'] );
|
||||
}
|
||||
|
||||
$shipment->label = $response['postage_label']['label_url'];
|
||||
$shipment->tracknumber = $response['tracking_code'];
|
||||
$shipment->extra = json_encode( array( 'shipment' => $response['selected_rate']['shipment_id'], 'rate' => $response['selected_rate']['id'] ) );
|
||||
$shipment->status = \IPS\nexus\Shipping\Order::STATUS_SHIPPED;
|
||||
$shipment->shipped_date = new \IPS\DateTime;
|
||||
$shipment->save();
|
||||
$shipment->sendNotification();
|
||||
|
||||
\IPS\Output::i()->redirect( $shipment->acpUrl() );
|
||||
}
|
||||
catch ( \IPS\Http\Request\Exception $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'err_err_easypost', '3X193/A', 500, '', array(), $e->getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
/* How much did the customer pay for shipping? */
|
||||
$invoiceSummary = $shipment->invoice->summary();
|
||||
$otherShipments = count( $shipment->invoice->shipments() ) - 1;
|
||||
$message = $otherShipments ? \IPS\Member::loggedIn()->language()->addToStack( 'shipment_cost_others', FALSE, array( 'sprintf' => array( $invoiceSummary['shippingTotal'], $shipment->invoice->id, $otherShipments ) ) ) : \IPS\Member::loggedIn()->language()->addToStack( 'shipment_cost_noothers', FALSE, array( 'sprintf' => array( $invoiceSummary['shippingTotal'] ) ) );
|
||||
\IPS\Member::loggedIn()->language()->words['easypost_rate_desc'] = $message;
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'shipment_number', FALSE, array( 'sprintf' => array( $shipment->id ) ) );
|
||||
\IPS\Output::i()->output = $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function cancel()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'shiporders_edit' );
|
||||
|
||||
/* Load */
|
||||
try
|
||||
{
|
||||
$shipment = \IPS\nexus\Shipping\Order::load( \IPS\Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X193/4', 404, '' );
|
||||
}
|
||||
|
||||
/* Cancel */
|
||||
$shipment->status = $shipment::STATUS_CANCELED;
|
||||
$shipment->save();
|
||||
|
||||
/* Log */
|
||||
$shipment->invoice->member->log( 'shipping', array( 'id' => $shipment->id, 'type' => 'canc' ) );
|
||||
|
||||
/* Redirect */
|
||||
$this->_redirect( $shipment );
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'shiporders_delete' );
|
||||
|
||||
/* Load */
|
||||
try
|
||||
{
|
||||
$shipment = \IPS\nexus\Shipping\Order::load( \IPS\Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X193/5', 404, '' );
|
||||
}
|
||||
|
||||
/* Delete */
|
||||
$shipment->delete();
|
||||
|
||||
/* Log */
|
||||
$shipment->invoice->member->log( 'shipping', array( 'id' => $shipment->id, 'deleted' => TRUE ) );
|
||||
|
||||
/* Redirect */
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=payments&controller=shipping') );
|
||||
}
|
||||
|
||||
/**
|
||||
* Print
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function printout()
|
||||
{
|
||||
/* Load */
|
||||
try
|
||||
{
|
||||
$shipment = \IPS\nexus\Shipping\Order::load( \IPS\Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X193/3', 404, '' );
|
||||
}
|
||||
$data = $shipment->data;
|
||||
|
||||
if ( \IPS\Request::i()->print === 'apilabel' )
|
||||
{
|
||||
\IPS\Output::i()->sendOutput( $shipment->label, 200, 'application/pdf' );
|
||||
}
|
||||
|
||||
if ( \IPS\Request::i()->print === 'label' )
|
||||
{
|
||||
$output = \IPS\Theme::i()->getTemplate('shiporders')->packingLabel( $shipment );
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'shipping.css', 'nexus' ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
$output = \IPS\Theme::i()->getTemplate('shiporders')->packingSheet( $shipment );
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'shipping.css', 'nexus' ) );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate( 'global', 'core', 'front' )->blankTemplate( $output ), 200, 'text/html', \IPS\Output::i()->httpHeaders );
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect
|
||||
*
|
||||
* @param \IPS\nexus\Shipping\Order $shipment The shipment
|
||||
* @return void
|
||||
*/
|
||||
protected function _redirect( \IPS\nexus\Shipping\Order $shipment )
|
||||
{
|
||||
if ( isset( \IPS\Request::i()->r ) )
|
||||
{
|
||||
switch ( \IPS\Request::i()->r )
|
||||
{
|
||||
case 'v':
|
||||
\IPS\Output::i()->redirect( $shipment->acpUrl() );
|
||||
break;
|
||||
|
||||
case 'i':
|
||||
\IPS\Output::i()->redirect( $shipment->invoice->acpUrl() );
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
\IPS\Output::i()->redirect( $shipment->member->acpUrl() );
|
||||
break;
|
||||
|
||||
case 't':
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=payments&controller=shipping') );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
\IPS\Output::i()->redirect( $transaction->acpUrl() );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Shipping Rates
|
||||
* @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 13 Feb 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\admin\payments;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shipping
|
||||
*/
|
||||
class _shippingrates extends \IPS\Node\Controller
|
||||
{
|
||||
/**
|
||||
* Node Class
|
||||
*/
|
||||
protected $nodeClass = 'IPS\nexus\Shipping\FlatRate';
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'shipping_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Tax Classes
|
||||
* @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 Feb 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\admin\payments;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* tax
|
||||
*/
|
||||
class _tax extends \IPS\Node\Controller
|
||||
{
|
||||
/**
|
||||
* Node Class
|
||||
*/
|
||||
protected $nodeClass = 'IPS\nexus\Tax';
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'tax_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,448 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Transactions
|
||||
* @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\modules\admin\payments;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transactions
|
||||
*/
|
||||
class _transactions extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'transactions_manage' );
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'transaction.css', 'nexus', 'admin' ) );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
/* Create Table */
|
||||
$table = \IPS\nexus\Transaction::table( array(), \IPS\Http\Url::internal( 'app=nexus&module=payments&controller=transactions' ), 't' );
|
||||
$table->filters = array(
|
||||
'tstatus_hold' => array( 't_status=?', 'hold' ),
|
||||
);
|
||||
$table->advancedSearch = array(
|
||||
't_id' => \IPS\Helpers\Table\SEARCH_CONTAINS_TEXT,
|
||||
't_status' => array( \IPS\Helpers\Table\SEARCH_SELECT, array( 'options' => \IPS\nexus\Transaction::statuses(), 'multiple' => TRUE ) ),
|
||||
't_member' => \IPS\Helpers\Table\SEARCH_MEMBER,
|
||||
't_amount' => \IPS\Helpers\Table\SEARCH_NUMERIC,
|
||||
't_method' => array( \IPS\Helpers\Table\SEARCH_NODE, array( 'class' => '\IPS\nexus\Gateway' ) ),
|
||||
't_date' => \IPS\Helpers\Table\SEARCH_DATE_RANGE,
|
||||
);
|
||||
$table->quickSearch = 't_id';
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__nexus_payments_transactions');
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->block( 'title', (string) $table );
|
||||
}
|
||||
|
||||
/**
|
||||
* View
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function view()
|
||||
{
|
||||
/* Load Transaction */
|
||||
try
|
||||
{
|
||||
$transaction = \IPS\nexus\Transaction::load( \IPS\Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X186/8', 404, '' );
|
||||
}
|
||||
|
||||
/* Output */
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'transaction_number', FALSE, array( 'sprintf' => array( $transaction->id ) ) );
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'transactions' )->view( $transaction );
|
||||
}
|
||||
|
||||
/**
|
||||
* Approve
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function approve()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'transactions_edit' );
|
||||
|
||||
/* Load Transaction */
|
||||
try
|
||||
{
|
||||
$transaction = \IPS\nexus\Transaction::load( \IPS\Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X186/9', 404, '' );
|
||||
}
|
||||
$method = $transaction->method;
|
||||
|
||||
/* Can we approve it? */
|
||||
if ( !in_array( $transaction->status, array( \IPS\nexus\Transaction::STATUS_PENDING, \IPS\nexus\Transaction::STATUS_WAITING, \IPS\nexus\Transaction::STATUS_HELD, \IPS\nexus\Transaction::STATUS_REVIEW ) ) )
|
||||
{
|
||||
\IPS\Output::i()->error( 'transaction_status_err', '2X186/A', 403, '' );
|
||||
}
|
||||
|
||||
/* Log it */
|
||||
$transaction->member->log( 'transaction', array(
|
||||
'type' => 'status',
|
||||
'status' => \IPS\nexus\Transaction::STATUS_PAID,
|
||||
'id' => $transaction->id
|
||||
) );
|
||||
|
||||
/* Do it */
|
||||
try
|
||||
{
|
||||
$transaction->capture();
|
||||
$transaction->approve( \IPS\Member::loggedIn() );
|
||||
}
|
||||
catch ( \LogicException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( $e->getMessage(), '3X186/2', 500, '' );
|
||||
}
|
||||
catch ( \RuntimeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'transaction_capture_err', '3X186/3', 500, '' );
|
||||
}
|
||||
|
||||
/* Send Email */
|
||||
$transaction->sendNotification();
|
||||
|
||||
/* Redirect */
|
||||
$this->_redirect( $transaction );
|
||||
}
|
||||
|
||||
/**
|
||||
* Flag for review
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function review()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'transactions_edit' );
|
||||
|
||||
/* Load Transaction */
|
||||
try
|
||||
{
|
||||
$transaction = \IPS\nexus\Transaction::load( \IPS\Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X186/C', 404, '' );
|
||||
}
|
||||
$method = $transaction->method;
|
||||
|
||||
/* Can we flag it? */
|
||||
if ( !in_array( $transaction->status, array( \IPS\nexus\Transaction::STATUS_PENDING, \IPS\nexus\Transaction::STATUS_WAITING, \IPS\nexus\Transaction::STATUS_HELD ) ) )
|
||||
{
|
||||
\IPS\Output::i()->error( 'transaction_status_err', '2X186/B', 403, '' );
|
||||
}
|
||||
|
||||
/* Set it */
|
||||
$extra = $transaction->extra;
|
||||
$extra['history'][] = array( 's' => \IPS\nexus\Transaction::STATUS_REVIEW, 'on' => time(), 'by' => \IPS\Member::loggedIn()->member_id );
|
||||
$transaction->extra = $extra;
|
||||
$transaction->status = \IPS\nexus\Transaction::STATUS_REVIEW;
|
||||
$transaction->save();
|
||||
|
||||
/* Log it */
|
||||
$transaction->member->log( 'transaction', array(
|
||||
'type' => 'status',
|
||||
'status' => \IPS\nexus\Transaction::STATUS_REVIEW,
|
||||
'id' => $transaction->id
|
||||
) );
|
||||
|
||||
/* Create a support request? */
|
||||
if ( \IPS\Settings::i()->nexus_revw_sa != -1 )
|
||||
{
|
||||
$createUrl = \IPS\Http\Url::internal('app=nexus&module=support&controller=requests&do=create');
|
||||
$key = md5( $createUrl );
|
||||
|
||||
if ( \IPS\Settings::i()->nexus_revw_sa )
|
||||
{
|
||||
$_SESSION["wizard-{$key}-data"] = array(
|
||||
'member' => $transaction->member->member_id,
|
||||
'stock_action' => \IPS\Settings::i()->nexus_revw_sa
|
||||
);
|
||||
$_SESSION["wizard-{$key}-step"] = 'request_details';
|
||||
}
|
||||
else
|
||||
{
|
||||
$_SESSION["wizard-{$key}-data"] = array(
|
||||
'member' => $transaction->member->member_id,
|
||||
);
|
||||
if ( count( \IPS\nexus\Support\StockAction::roots() ) )
|
||||
{
|
||||
$_SESSION["wizard-{$key}-step"] = 'stock_action';
|
||||
}
|
||||
else
|
||||
{
|
||||
$_SESSION["wizard-{$key}-step"] = 'request_details';
|
||||
}
|
||||
}
|
||||
|
||||
$_SESSION["wizard-{$key}-data"]['transaction'] = $transaction->id;
|
||||
$_SESSION["wizard-{$key}-data"]['ref'] = isset( \IPS\Request::i()->r ) ? \IPS\Request::i()->r : 'v';
|
||||
|
||||
\IPS\Output::i()->redirect( $createUrl );
|
||||
}
|
||||
|
||||
/* Redirect */
|
||||
$this->_redirect( $transaction );
|
||||
}
|
||||
|
||||
/**
|
||||
* Void
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function void()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'transactions_edit' );
|
||||
|
||||
/* Load Transaction */
|
||||
try
|
||||
{
|
||||
$transaction = \IPS\nexus\Transaction::load( \IPS\Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X186/4', 404, '' );
|
||||
}
|
||||
$method = $transaction->method;
|
||||
|
||||
/* Can we void it? */
|
||||
if ( !in_array( $transaction->status, array( \IPS\nexus\Transaction::STATUS_PENDING, \IPS\nexus\Transaction::STATUS_WAITING ) ) and ( !$transaction->auth or !in_array( $transaction->status, array( \IPS\nexus\Transaction::STATUS_HELD, \IPS\nexus\Transaction::STATUS_REVIEW ) ) ) )
|
||||
{
|
||||
\IPS\Output::i()->error( 'transaction_status_err', '2X186/5', 403, '' );
|
||||
}
|
||||
|
||||
/* Void it */
|
||||
try
|
||||
{
|
||||
$transaction->method->void( $transaction );
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
{
|
||||
if ( !isset( \IPS\Request::i()->override ) )
|
||||
{
|
||||
\IPS\Output::i()->error( \IPS\Member::loggedIn()->language()->addToStack( 'transaction_void_err', FALSE, array( 'sprintf' => array( $transaction->acpUrl()->setQueryString( array( 'do' => 'void', 'override' => 1 ) ) ) ) ), '3X186/6', 500, '', array(), $e->getMessage() );
|
||||
}
|
||||
}
|
||||
$extra = $transaction->extra;
|
||||
$extra['history'][] = array( 's' => \IPS\nexus\Transaction::STATUS_REFUSED, 'on' => time(), 'by' => \IPS\Member::loggedIn()->member_id );
|
||||
$transaction->extra = $extra;
|
||||
$transaction->status = \IPS\nexus\Transaction::STATUS_REFUSED;
|
||||
$transaction->save();
|
||||
|
||||
/* Log it */
|
||||
$transaction->member->log( 'transaction', array(
|
||||
'type' => 'status',
|
||||
'status' => \IPS\nexus\Transaction::STATUS_REFUSED,
|
||||
'id' => $transaction->id
|
||||
) );
|
||||
|
||||
/* Send Email */
|
||||
$transaction->sendNotification();
|
||||
|
||||
/* Redirect */
|
||||
$this->_redirect( $transaction );
|
||||
}
|
||||
|
||||
/**
|
||||
* Refund
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function refund()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'transactions_refund' );
|
||||
|
||||
/* Load Transaction */
|
||||
try
|
||||
{
|
||||
$transaction = \IPS\nexus\Transaction::load( \IPS\Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X186/D', 404, '' );
|
||||
}
|
||||
$method = $transaction->method;
|
||||
|
||||
/* Can we refund it? */
|
||||
if ( !in_array( $transaction->status, array( \IPS\nexus\Transaction::STATUS_PAID, \IPS\nexus\Transaction::STATUS_HELD, \IPS\nexus\Transaction::STATUS_REVIEW, \IPS\nexus\Transaction::STATUS_PART_REFUNDED ) ) )
|
||||
{
|
||||
\IPS\Output::i()->error( 'transaction_status_err', '2X186/E', 403, '' );
|
||||
}
|
||||
|
||||
/* What are the refund methods? */
|
||||
$refundMethods = array();
|
||||
$refundMethodToggles = array( 'credit' => array( 'refund_amount' ) );
|
||||
if ( $method and $method::SUPPORTS_REFUNDS )
|
||||
{
|
||||
$refundMethods['gateway'] = $method->_title;
|
||||
if ( $method::SUPPORTS_PARTIAL_REFUNDS )
|
||||
{
|
||||
$refundMethodToggles['gateway'] = array( 'refund_amount' );
|
||||
}
|
||||
}
|
||||
$refundMethods['credit'] = 'refund_method_credit';
|
||||
$refundMethods['none'] = 'refund_method_none';
|
||||
|
||||
/* Build form */
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'refund_method', ( $method and $method::SUPPORTS_REFUNDS ) ? 'gateway' : 'credit', TRUE, array( 'options' => $refundMethods, 'toggles' => $refundMethodToggles ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'refund_amount', ( $transaction->status === \IPS\nexus\Transaction::STATUS_PART_REFUNDED ? $transaction->amount->amount - $transaction->partial_refund->amount : 0 ), TRUE, array( 'unlimited' => 0, 'unlimitedLang' => \IPS\Member::loggedIn()->language()->addToStack( 'refund_full', FALSE, array( 'sprintf' => array( $transaction->amount ) ) ), 'max' => ( $transaction->amount->amount - $transaction->partial_refund->amount ), 'decimals' => TRUE ), NULL, NULL, $transaction->amount->currency, 'refund_amount' ) );
|
||||
if ( $transaction->invoice->status === \IPS\nexus\Invoice::STATUS_PAID )
|
||||
{
|
||||
$field = new \IPS\Helpers\Form\Radio( 'refund_invoice_status', \IPS\nexus\Invoice::STATUS_PENDING, TRUE, array(
|
||||
'options' => array(
|
||||
\IPS\nexus\Invoice::STATUS_PAID => 'refund_invoice_paid',
|
||||
\IPS\nexus\Invoice::STATUS_PENDING => 'refund_invoice_pending',
|
||||
\IPS\nexus\Invoice::STATUS_CANCELED => 'refund_invoice_canceled',
|
||||
),
|
||||
'toggles' => array(
|
||||
\IPS\nexus\Invoice::STATUS_PENDING => array( 'form_refund_invoice_status_warning' ),
|
||||
\IPS\nexus\Invoice::STATUS_CANCELED => array( 'form_refund_invoice_status_warning' )
|
||||
)
|
||||
) );
|
||||
$field->warningBox = \IPS\Theme::i()->getTemplate('invoices')->unpaidConsequences( $transaction->invoice );
|
||||
$form->add( $field );
|
||||
}
|
||||
|
||||
/* Handle submissions */
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
/* Refund */
|
||||
try
|
||||
{
|
||||
$transaction->refund( $values['refund_method'], $values['refund_amount'] );
|
||||
}
|
||||
catch ( \LogicException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( $e->getMessage(), '1X186/1', 500, '' );
|
||||
}
|
||||
catch ( \RuntimeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'refund_failed', '3X186/7', 500, '' );
|
||||
}
|
||||
|
||||
/* Handle invoice */
|
||||
if ( isset( $values['refund_invoice_status'] ) and $values['refund_invoice_status'] !== \IPS\nexus\Invoice::STATUS_PAID )
|
||||
{
|
||||
$transaction->invoice->markUnpaid( $values['refund_invoice_status'] );
|
||||
|
||||
$transaction->invoice->member->log( 'invoice', array(
|
||||
'type' => 'status',
|
||||
'new' => $values['refund_invoice_status'],
|
||||
'id' => $transaction->invoice->id,
|
||||
'title' => $transaction->invoice->title
|
||||
) );
|
||||
}
|
||||
|
||||
/* Send Email */
|
||||
$transaction->sendNotification();
|
||||
|
||||
/* Redirect */
|
||||
$this->_redirect( $transaction );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'transaction_refund_title', FALSE, array( 'sprintf' => array( $transaction->amount ) ) );
|
||||
\IPS\Output::i()->output = $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'transactions_delete' );
|
||||
|
||||
/* Load Transaction */
|
||||
try
|
||||
{
|
||||
$transaction = \IPS\nexus\Transaction::load( \IPS\Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X186/F', 404, '' );
|
||||
}
|
||||
|
||||
/* Delete */
|
||||
$transaction->delete();
|
||||
|
||||
/* Log it */
|
||||
$transaction->member->log( 'transaction', array(
|
||||
'type' => 'delete',
|
||||
'id' => $transaction->id,
|
||||
'method' => $transaction->method->id
|
||||
) );
|
||||
|
||||
/* Redirect */
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=payments&controller=transactions') );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Redirect
|
||||
*
|
||||
* @param \IPS\nexus\Transaction $transaction The transaction
|
||||
* @return void
|
||||
*/
|
||||
protected function _redirect( \IPS\nexus\Transaction $transaction )
|
||||
{
|
||||
if ( isset( \IPS\Request::i()->r ) )
|
||||
{
|
||||
switch ( \IPS\Request::i()->r )
|
||||
{
|
||||
case 'v':
|
||||
\IPS\Output::i()->redirect( $transaction->acpUrl() );
|
||||
break;
|
||||
|
||||
case 'i':
|
||||
\IPS\Output::i()->redirect( $transaction->invoice->acpUrl() );
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
\IPS\Output::i()->redirect( $transaction->member->acpUrl() );
|
||||
break;
|
||||
|
||||
case 't':
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=payments&controller=transactions') );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
\IPS\Output::i()->redirect( $transaction->acpUrl() );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Income Report
|
||||
* @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 14 Aug 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\admin\reports;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Income Report
|
||||
*/
|
||||
class _income extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'income_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* View Report
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
$tabs['totals'] = 'nexus_report_income_totals';
|
||||
foreach ( \IPS\nexus\Money::currencies() as $currency )
|
||||
{
|
||||
$tabs[ $currency ] = \IPS\Member::loggedIn()->language()->addToStack( 'nexus_report_income_by_method', NULL, array( 'sprintf' => array( $currency ) ) );
|
||||
}
|
||||
|
||||
$activeTab = ( isset( \IPS\Request::i()->tab ) and array_key_exists( \IPS\Request::i()->tab, $tabs ) ) ? \IPS\Request::i()->tab : 'totals';
|
||||
|
||||
$chart = new \IPS\Helpers\Chart\Dynamic(
|
||||
\IPS\Http\Url::internal( 'app=nexus&module=reports&controller=income&tab=' . $activeTab ),
|
||||
'nexus_transactions',
|
||||
't_date',
|
||||
'',
|
||||
array(),
|
||||
'LineChart',
|
||||
'monthly',
|
||||
array( 'start' => 0, 'end' => 0 ),
|
||||
array(),
|
||||
$activeTab
|
||||
);
|
||||
$chart->where[] = array( '( t_status=? OR t_status=? )', \IPS\nexus\Transaction::STATUS_PAID, \IPS\nexus\Transaction::STATUS_PART_REFUNDED );
|
||||
|
||||
if ( $activeTab === 'totals' )
|
||||
{
|
||||
$chart->groupBy = 't_currency';
|
||||
|
||||
foreach ( \IPS\nexus\Money::currencies() as $currency )
|
||||
{
|
||||
$chart->addSeries( $currency, 'number', 'SUM(t_amount)-SUM(t_partial_refund)', TRUE, $currency );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$chart->where[] = array( 't_currency=?', $activeTab );
|
||||
$chart->groupBy = 't_method';
|
||||
$chart->format = $activeTab;
|
||||
|
||||
foreach ( \IPS\nexus\Gateway::roots() as $gateway )
|
||||
{
|
||||
$chart->addSeries( $gateway->_title, 'number', 'SUM(t_amount)-SUM(t_partial_refund)', TRUE, $gateway->id );
|
||||
}
|
||||
}
|
||||
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->output = (string) $chart;
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__nexus_reports_income');
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->tabs( $tabs, $activeTab, (string) $chart, \IPS\Http\Url::internal( "app=nexus&module=reports&controller=income" ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
Whitespace-only changes.
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Markets Report
|
||||
* @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 14 Aug 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\admin\reports;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Markets Report
|
||||
*/
|
||||
class _markets extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'markets_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* View Chart
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
$tabs['count'] = 'nexus_report_count';
|
||||
foreach ( \IPS\nexus\Money::currencies() as $currency )
|
||||
{
|
||||
$tabs[ $currency ] = \IPS\Member::loggedIn()->language()->addToStack( 'nexus_report_income', NULL, array( 'sprintf' => array( $currency ) ) );
|
||||
}
|
||||
|
||||
$activeTab = ( isset( \IPS\Request::i()->tab ) and array_key_exists( \IPS\Request::i()->tab, $tabs ) ) ? \IPS\Request::i()->tab : 'count';
|
||||
|
||||
$chart = new \IPS\Helpers\Chart\Dynamic(
|
||||
\IPS\Http\Url::internal( 'app=nexus&module=reports&controller=markets&tab=' . $activeTab ),
|
||||
'nexus_invoices',
|
||||
'i_paid',
|
||||
'',
|
||||
array(),
|
||||
'GeoChart',
|
||||
'monthly',
|
||||
array( 'start' => 0, 'end' => 0 ),
|
||||
array(),
|
||||
$activeTab
|
||||
);
|
||||
$chart->availableTypes[] = 'GeoChart';
|
||||
$chart->where[] = array( 'i_status=? AND i_billcountry IS NOT NULL', \IPS\nexus\Invoice::STATUS_PAID );
|
||||
if ( $activeTab !== 'count' )
|
||||
{
|
||||
$chart->where[] = array( 'i_currency=?', $activeTab );
|
||||
$chart->format = $activeTab;
|
||||
}
|
||||
$chart->groupBy = 'i_billcountry';
|
||||
|
||||
foreach ( \IPS\GeoLocation::$countries as $countryCode )
|
||||
{
|
||||
$chart->addSeries( \IPS\Member::loggedIn()->language()->get( 'country-' . $countryCode ), 'number', $activeTab === 'count' ? 'COUNT(*)' : 'SUM(i_total)', TRUE, $countryCode );
|
||||
}
|
||||
|
||||
if ( $chart->type === 'GeoChart' )
|
||||
{
|
||||
$chart->options['height'] = 750;
|
||||
$chart->options['keepAspectRatio'] = true;
|
||||
}
|
||||
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->output = (string) $chart;
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__nexus_reports_markets');
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->tabs( $tabs, $activeTab, (string) $chart, \IPS\Http\Url::internal( "app=nexus&module=reports&controller=markets" ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Purchases Reports
|
||||
* @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 14 Aug 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\admin\reports;
|
||||
|
||||
/* 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 Reports
|
||||
*/
|
||||
class _purchases extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'purchases_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* View Chart
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
$chart = new \IPS\Helpers\Chart\Dynamic(
|
||||
\IPS\Http\Url::internal('app=nexus&module=reports&controller=purchases'),
|
||||
'nexus_purchases',
|
||||
'ps_start'
|
||||
);
|
||||
$chart->where[] = array( 'ps_app=? AND ps_type=?', 'nexus', 'package' );
|
||||
$chart->groupBy = 'ps_item_id';
|
||||
|
||||
$packages = array();
|
||||
foreach ( \IPS\Db::i()->select( 'p_id', 'nexus_packages' ) as $packageId )
|
||||
{
|
||||
$packages[ $packageId ] = \IPS\Member::loggedIn()->language()->get( 'nexus_package_' . $packageId );
|
||||
}
|
||||
|
||||
asort( $packages );
|
||||
foreach ( $packages as $id => $name )
|
||||
{
|
||||
$chart->addSeries( $name, 'number', 'COUNT(*)', TRUE, $id );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__nexus_reports_purchases');
|
||||
\IPS\Output::i()->output = (string) $chart;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Coupons
|
||||
* @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 05 May 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\admin\store;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* coupons
|
||||
*/
|
||||
class _coupons extends \IPS\Node\Controller
|
||||
{
|
||||
/**
|
||||
* Node Class
|
||||
*/
|
||||
protected $nodeClass = 'IPS\nexus\Coupon';
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'coupons_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* View Uses
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function viewUses()
|
||||
{
|
||||
try
|
||||
{
|
||||
$coupon = \IPS\nexus\Coupon::load( \IPS\Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X234/1', 404, '' );
|
||||
}
|
||||
|
||||
$data = array();
|
||||
$usedBy = json_decode( $coupon->used_by, TRUE );
|
||||
if ( $usedBy )
|
||||
{
|
||||
foreach ( $usedBy as $member => $uses )
|
||||
{
|
||||
$data[] = array( 'coupon_customer' => $member, 'coupon_uses' => $uses );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$table = new \IPS\Helpers\Table\Custom( $data, \IPS\Http\Url::internal("app=nexus&module=store&controller=coupons&do=viewUses&id={$coupon->id}") );
|
||||
$table->parsers = array(
|
||||
'coupon_customer' => function ( $val )
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate('global')->userLink( \IPS\Member::load( $val ) );
|
||||
}
|
||||
);
|
||||
$table->sortBy = 'coupon_uses';
|
||||
$table->noSort = array( 'coupon_customer' );
|
||||
|
||||
\IPS\Output::i()->title = $coupon->code;
|
||||
\IPS\Output::i()->output = (string) $table;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief 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
|
||||
* @since 01 May 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\admin\store;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* fields
|
||||
*/
|
||||
class _fields extends \IPS\Node\Controller
|
||||
{
|
||||
/**
|
||||
* Node Class
|
||||
*/
|
||||
protected $nodeClass = 'IPS\nexus\Package\CustomField';
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'package_fields_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'forms', 'core' )->blurb( 'custom_package_fields_blurb' );
|
||||
return parent::manage();
|
||||
}
|
||||
}
|
||||
Whitespace-only changes.
@@ -0,0 +1,395 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Packages
|
||||
* @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 29 Apr 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\admin\store;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Packages
|
||||
*/
|
||||
class _packages extends \IPS\Node\Controller
|
||||
{
|
||||
/**
|
||||
* Node Class
|
||||
*/
|
||||
protected $nodeClass = 'IPS\nexus\Package\Group';
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'packages_manage' );
|
||||
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'admin_store.js', 'nexus', 'admin' ) );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Root Buttons
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function _getRootButtons()
|
||||
{
|
||||
$buttons = parent::_getRootButtons();
|
||||
|
||||
if ( isset( $buttons['add'] ) )
|
||||
{
|
||||
$buttons['add']['title'] = 'create_new_group';
|
||||
}
|
||||
|
||||
return $buttons;
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect after save
|
||||
*
|
||||
* @param \IPS\Node\Model $old A clone of the node as it was before or NULL if this is a creation
|
||||
* @param \IPS\Node\Model $node The node now
|
||||
* @return void
|
||||
*/
|
||||
protected function _afterSave( \IPS\Node\Model $old = NULL, \IPS\Node\Model $new )
|
||||
{
|
||||
if ( !( $new instanceof \IPS\nexus\Package ) )
|
||||
{
|
||||
return parent::_afterSave( $old, $new );
|
||||
}
|
||||
|
||||
$changes = array();
|
||||
if ( $old )
|
||||
{
|
||||
foreach ( $new::updateableFields() as $k )
|
||||
{
|
||||
if ( $old->$k != $new->$k )
|
||||
{
|
||||
$changes[ $k ] = $old->$k;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( !empty( $changes ) )
|
||||
{
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->decision( 'product_change_blurb', array(
|
||||
'product_change_blurb_existing' => \IPS\Http\Url::internal( "app=nexus&module=store&controller=packages&do=updateExisting&id={$new->_id}" )->setQueryString( 'changes', json_encode( $changes ) ),
|
||||
'product_change_blurb_new' => $this->url->setQueryString( array( 'root' => ( $new->parent() ? $new->parent()->_id : '' ) ) ),
|
||||
) );
|
||||
}
|
||||
else
|
||||
{
|
||||
return parent::_afterSave( $old, $new );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update Existing Purchases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function updateExisting()
|
||||
{
|
||||
try
|
||||
{
|
||||
$package = \IPS\nexus\Package::load( \IPS\Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X249/1', 404, '' );
|
||||
}
|
||||
|
||||
$changes = json_decode( \IPS\Request::i()->changes, TRUE );
|
||||
|
||||
if ( !isset( \IPS\Request::i()->processing ) )
|
||||
{
|
||||
if ( isset( $changes['renew_options'] ) )
|
||||
{
|
||||
$matrix = new \IPS\Helpers\Form\Matrix( 'matrix', 'continue' );
|
||||
$matrix->manageable = FALSE;
|
||||
|
||||
$newOptions = array( '-' => \IPS\Member::loggedIn()->language()->addToStack('do_not_change') );
|
||||
$existingRenewOptions = json_decode( $package->renew_options, TRUE );
|
||||
|
||||
if( !is_array( $existingRenewOptions ) )
|
||||
{
|
||||
$existingRenewOptions = array();
|
||||
}
|
||||
|
||||
foreach ( $existingRenewOptions as $k => $newOption )
|
||||
{
|
||||
$costs = array();
|
||||
foreach ( $newOption['cost'] as $data )
|
||||
{
|
||||
$costs[] = new \IPS\nexus\Money( $data['amount'], $data['currency'] );
|
||||
}
|
||||
|
||||
switch ( $newOption['unit'] )
|
||||
{
|
||||
case 'd':
|
||||
$term = \IPS\Member::loggedIn()->language()->addToStack('renew_days', FALSE, array( 'pluralize' => array( $newOption['term'] ) ) );
|
||||
break;
|
||||
case 'm':
|
||||
$term = \IPS\Member::loggedIn()->language()->addToStack('renew_months', FALSE, array( 'pluralize' => array( $newOption['term'] ) ) );
|
||||
break;
|
||||
case 'y':
|
||||
$term = \IPS\Member::loggedIn()->language()->addToStack('renew_years', FALSE, array( 'pluralize' => array( $newOption['term'] ) ) );
|
||||
break;
|
||||
}
|
||||
|
||||
$newOptions[ "o{$k}" ] = \IPS\Member::loggedIn()->language()->addToStack( 'renew_option', FALSE, array( 'sprintf' => array( \IPS\Member::loggedIn()->language()->formatList( $costs, \IPS\Member::loggedIn()->language()->get('or_list_format') ), $term ) ) );
|
||||
}
|
||||
$newOptions['z'] = \IPS\Member::loggedIn()->language()->addToStack('remove_renewal_no_expire_leave');
|
||||
$newOptions['y'] = \IPS\Member::loggedIn()->language()->addToStack('remove_renewal_no_expire_reactivate');
|
||||
$newOptions['x'] = \IPS\Member::loggedIn()->language()->addToStack('remove_renewal_expire');
|
||||
$matrix->columns = array(
|
||||
'customers_currently_paying' => function( $key, $value, $data )
|
||||
{
|
||||
return $data[0];
|
||||
},
|
||||
'now_pay' => function( $key, $value, $data ) use ( $newOptions )
|
||||
{
|
||||
return new \IPS\Helpers\Form\Select( $key, $data[1], TRUE, array( 'options' => $newOptions, 'noDefault' => TRUE ) );
|
||||
},
|
||||
);
|
||||
|
||||
foreach ( json_decode( $changes['renew_options'], TRUE ) as $k => $oldOption )
|
||||
{
|
||||
$costs = array();
|
||||
foreach ( $oldOption['cost'] as $data )
|
||||
{
|
||||
$costs[] = new \IPS\nexus\Money( $data['amount'], $data['currency'] );
|
||||
}
|
||||
|
||||
switch ( $oldOption['unit'] )
|
||||
{
|
||||
case 'd':
|
||||
$term = \IPS\Member::loggedIn()->language()->addToStack('renew_days', FALSE, array( 'pluralize' => array( $oldOption['term'] ) ) );
|
||||
break;
|
||||
case 'm':
|
||||
$term = \IPS\Member::loggedIn()->language()->addToStack('renew_months', FALSE, array( 'pluralize' => array( $oldOption['term'] ) ) );
|
||||
break;
|
||||
case 'y':
|
||||
$term = \IPS\Member::loggedIn()->language()->addToStack('renew_years', FALSE, array( 'pluralize' => array( $oldOption['term'] ) ) );
|
||||
break;
|
||||
}
|
||||
|
||||
$matrix->rows[ $k ] = array( \IPS\Member::loggedIn()->language()->addToStack( 'renew_option', FALSE, array( 'sprintf' => array( \IPS\Member::loggedIn()->language()->formatList( $costs, \IPS\Member::loggedIn()->language()->get('or_list_format') ), $term ) ) ), "o{$k}" );
|
||||
}
|
||||
$matrix->rows['x'] = array( 'any_other_amount', '-' );
|
||||
|
||||
if ( $values = $matrix->values() )
|
||||
{
|
||||
$renewOptions = json_decode( $changes['renew_options'], TRUE );
|
||||
$changes['renew_options'] = array();
|
||||
foreach ( $renewOptions as $k => $data )
|
||||
{
|
||||
$changes['renew_options'][] = array( 'old' => $data, 'new' => $values[ $k ]['now_pay'] );
|
||||
}
|
||||
$changes['renew_options'][] = array( 'old' => 'x', 'new' => $values['x']['now_pay'] );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->output = $matrix;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
\IPS\Output::i()->output = new \IPS\Helpers\MultipleRedirect(
|
||||
\IPS\Http\Url::internal( "app=nexus&module=store&controller=packages&do=updateExisting&id=1&changes=secondary_group" )->setQueryString( array(
|
||||
'id' => \IPS\Request::i()->id,
|
||||
'changes' => json_encode( $changes ),
|
||||
'processing'=> 1
|
||||
) ),
|
||||
function( $offset ) use ( $package, $changes )
|
||||
{
|
||||
$select = \IPS\Db::i()->select( '*', 'nexus_purchases', array( "ps_app=? and ps_type=? and ps_item_id=?", 'nexus', 'package', $package->id ), 'ps_id', array( $offset, 1 ), NULL, NULL, \IPS\DB::SELECT_SQL_CALC_FOUND_ROWS );
|
||||
|
||||
try
|
||||
{
|
||||
$purchase = \IPS\nexus\Purchase::constructFromData( $select->first() );
|
||||
$total = $select->count( TRUE );
|
||||
|
||||
$package->updatePurchase( $purchase, $changes );
|
||||
|
||||
return array( ++$offset, \IPS\Member::loggedIn()->language()->get('processing'), 100 / $total * $offset );
|
||||
}
|
||||
catch ( \UnderflowException $e )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
},
|
||||
function() use ( $package )
|
||||
{
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=nexus&module=store&controller=packages" )->setQueryString( array( 'root' => ( $package->parent() ? $package->parent()->_id : '' ) ) ) );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build Product Options Table
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function productoptions()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'packages_edit' );
|
||||
|
||||
if ( !\IPS\Request::i()->fields or !\IPS\Request::i()->package )
|
||||
{
|
||||
\IPS\Output::i()->sendOutput('');
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$package = \IPS\nexus\Package::load( \IPS\Request::i()->package );
|
||||
|
||||
$fields = iterator_to_array( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_package_fields', \IPS\Db::i()->in( 'cf_id', explode( ',', \IPS\Request::i()->fields ) ) ), 'IPS\nexus\Package\CustomField' ) );
|
||||
$allTheOptions = array();
|
||||
foreach ( $fields as $field )
|
||||
{
|
||||
$options = array();
|
||||
foreach ( json_decode( $field->extra, TRUE ) as $option )
|
||||
{
|
||||
$options[] = json_encode( array( $field->id, $option ) );
|
||||
}
|
||||
$allTheOptions[ $field->id ] = $options;
|
||||
}
|
||||
$_rows = $this->arraycartesian( $allTheOptions );
|
||||
|
||||
$rows = array();
|
||||
foreach ( $_rows as $_options )
|
||||
{
|
||||
$options = array();
|
||||
foreach ( $_options as $encoded )
|
||||
{
|
||||
$decoded = json_decode( $encoded, TRUE );
|
||||
$options[ $decoded[0] ] = $decoded[1];
|
||||
}
|
||||
$rows[ json_encode( $options ) ] = $options;
|
||||
}
|
||||
|
||||
$existingValues = iterator_to_array( \IPS\Db::i()->select( '*', 'nexus_product_options', array( 'opt_package=?', $package->id ) )->setKeyField( 'opt_values' ) );
|
||||
|
||||
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate('store')->productOptionsTable( $fields, $rows, $existingValues, \IPS\Request::i()->renews ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->sendOutput( $e->getMessage(), 500 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Little function from the PHP manual comments
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function arraycartesian($_) {
|
||||
if(count($_) == 0)
|
||||
return array(array());
|
||||
foreach($_ as $k=>$a) {
|
||||
unset($_[$k]);
|
||||
break;
|
||||
}
|
||||
$c = $this->arraycartesian($_);
|
||||
$r = array();
|
||||
foreach($a as $v)
|
||||
foreach($c as $p)
|
||||
$r[] = array_merge(array($v), $p);
|
||||
return $r;
|
||||
}
|
||||
|
||||
/**
|
||||
* View Purchases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function view_purchases()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'purchases_view', 'nexus', 'customers' );
|
||||
|
||||
try
|
||||
{
|
||||
$package = \IPS\nexus\Package::load( \IPS\Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X249/2', 404, '' );
|
||||
}
|
||||
|
||||
$table = new \IPS\Helpers\Table\Db( 'nexus_purchases', \IPS\Http\Url::internal( "app=nexus&module=store&controller=packages&do=view_purchases&id={$package->id}" ), array( 'ps_app=? AND ps_type=? AND ps_item_id=?', 'nexus', 'package', $package->id ) );
|
||||
$table->include = array( 'ps_id', 'ps_member', 'purchase_status', 'ps_start', 'ps_expire', 'ps_renewals' );
|
||||
$table->quickSearch = 'ps_id';
|
||||
$table->advancedSearch = array(
|
||||
'ps_member' => \IPS\Helpers\Table\SEARCH_MEMBER,
|
||||
'ps_start' => \IPS\Helpers\Table\SEARCH_DATE_RANGE,
|
||||
'ps_expire' => \IPS\Helpers\Table\SEARCH_DATE_RANGE,
|
||||
);
|
||||
$table->noSort = array( 'purchase_status' );
|
||||
$table->filters = array( 'active' => 'ps_active=1' );
|
||||
$table->parsers = array(
|
||||
'ps_member' => function( $val ) {
|
||||
return \IPS\nexus\Customer::load( $val )->link();
|
||||
},
|
||||
'purchase_status' => function( $val, $row ) {
|
||||
$purchase = \IPS\nexus\Purchase::constructFromData( $row );
|
||||
if ( $purchase->cancelled )
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack('purchase_canceled');
|
||||
}
|
||||
elseif ( !$purchase->active )
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack('purchase_expired');
|
||||
}
|
||||
elseif ( $purchase->grace_period and $purchase->expire->getTimestamp() < time() )
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack('purchase_in_grace_period');
|
||||
}
|
||||
else
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack('purchase_active');
|
||||
}
|
||||
},
|
||||
'ps_start' => function( $val ) {
|
||||
return \IPS\DateTime::ts( $val );
|
||||
},
|
||||
'ps_expire' => function( $val ) {
|
||||
return $val ? \IPS\DateTime::ts( $val ) : '--';
|
||||
},
|
||||
'ps_renewals' => function( $val, $row ) {
|
||||
$purchase = \IPS\nexus\Purchase::constructFromData( $row );
|
||||
return $purchase->grouped_renewals ? \IPS\Member::loggedIn()->language()->addToStack('purchase_grouped') : ( (string) ( $purchase->renewals ?: '--' ) );
|
||||
}
|
||||
);
|
||||
$table->rowButtons = function( $row ) {
|
||||
$purchase = \IPS\nexus\Purchase::constructFromData( $row );
|
||||
return array_merge( array(
|
||||
'view' => array(
|
||||
'link' => $purchase->acpUrl()->setQueryString( 'popup', true ),
|
||||
'title' => 'view',
|
||||
'icon' => 'search',
|
||||
)
|
||||
), $purchase->buttons() );
|
||||
};
|
||||
|
||||
\IPS\Output::i()->title = $package->_title;
|
||||
\IPS\Output::i()->output = $table;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Store Settings
|
||||
* @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 05 May 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\admin\store;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store Settings
|
||||
*/
|
||||
class _settings extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'settings_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
$giftVouchers = array();
|
||||
foreach ( \IPS\Settings::i()->nexus_gift_vouchers ? ( json_decode( \IPS\Settings::i()->nexus_gift_vouchers, TRUE ) ?: array() ) : array() as $voucher )
|
||||
{
|
||||
$amounts = array();
|
||||
foreach ( $voucher as $currency => $amount )
|
||||
{
|
||||
$amounts[ $currency ] = new \IPS\nexus\Money( $amount, $currency );
|
||||
}
|
||||
$giftVouchers[] = $amounts;
|
||||
}
|
||||
|
||||
$groups = array();
|
||||
foreach ( \IPS\Member\Group::groups( FALSE, FALSE ) as $group )
|
||||
{
|
||||
$groups[ $group->g_id ] = $group->name;
|
||||
}
|
||||
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->addTab('nexus_store_display');
|
||||
$form->addHeader('nexus_store_tax');
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'nexus_show_tax', \IPS\Settings::i()->nexus_show_tax ) );
|
||||
$form->add( new \IPS\Helpers\Form\Translatable( 'nexus_tax_explain', NULL, FALSE, array( 'app' => 'nexus', 'key' => 'nexus_tax_explain_val', 'placeholder' => \IPS\Member::loggedIn()->language()->addToStack('nexus_tax_explain_placeholder') ) ) );
|
||||
$form->addHeader( 'nexus_store_index' );
|
||||
$form->add( new \IPS\Helpers\Form\Custom( 'nexus_store_new', explode( ',', \IPS\Settings::i()->nexus_store_new ), FALSE, array(
|
||||
'getHtml' => function( $field )
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate( 'store' )->storeIndexProductsSetting( 'nexus_store_new_field', $field->name, $field->value );
|
||||
}
|
||||
) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Custom( 'nexus_store_popular', explode( ',', \IPS\Settings::i()->nexus_store_popular ), FALSE, array(
|
||||
'getHtml' => function( $field )
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate( 'store' )->storeIndexProductsSetting( 'nexus_store_popular_field', $field->name, $field->value );
|
||||
}
|
||||
) ) );
|
||||
$form->addHeader( 'nexus_stock' );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'nexus_show_stock', \IPS\Settings::i()->nexus_show_stock ) );
|
||||
$form->addTab( 'nexus_purchase_settings' );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'nexus_reg_force', \IPS\Settings::i()->nexus_reg_force, FALSE ) );
|
||||
$form->add( new \IPS\nexus\Form\Money( 'nexus_minimum_order', json_decode( \IPS\Settings::i()->nexus_minimum_order, TRUE ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Select( 'cm_protected', explode( ',', \IPS\Settings::i()->cm_protected ), FALSE, array( 'options' => $groups, 'multiple' => TRUE ) ) );
|
||||
$form->addTab('nexus_gift_vouchers');
|
||||
$form->add( new \IPS\Helpers\Form\Stack( 'nexus_gift_vouchers', $giftVouchers, FALSE, array( 'stackFieldType' => 'IPS\nexus\Form\Money' ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'nexus_gift_vouchers_free', \IPS\Settings::i()->nexus_gift_vouchers_free ) );
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
$giftVouchers = array();
|
||||
foreach ( $values['nexus_gift_vouchers'] as $voucher )
|
||||
{
|
||||
$gvValues = array();
|
||||
foreach ( $voucher as $currency => $amount )
|
||||
{
|
||||
$gvValues[ $currency ] = $amount->amount;
|
||||
}
|
||||
$giftVouchers[] = $gvValues;
|
||||
}
|
||||
$values['nexus_gift_vouchers'] = json_encode( $giftVouchers );
|
||||
|
||||
\IPS\Lang::saveCustom( 'nexus', "nexus_tax_explain_val", $values['nexus_tax_explain'] );
|
||||
unset( $values['nexus_tax_explain'] );
|
||||
|
||||
$values['cm_protected'] = implode( ',', $values['cm_protected'] );
|
||||
$values['nexus_store_popular'] = implode( ',', $values['nexus_store_popular'] );
|
||||
$values['nexus_store_new'] = implode( ',', $values['nexus_store_new'] );
|
||||
|
||||
$values['nexus_minimum_order'] = $values['nexus_minimum_order'] ? json_encode( $values['nexus_minimum_order'] ) : '';
|
||||
|
||||
$form->saveAsSettings( $values );
|
||||
|
||||
/* Clear guest page caches */
|
||||
\IPS\Data\Cache::i()->clearAll();
|
||||
}
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('store_settings');
|
||||
\IPS\Output::i()->output = $form;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Autoresolve Settings
|
||||
* @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 25 Apr 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\admin\support;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Autoresolve Settings
|
||||
*/
|
||||
class _autoresolve extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* Manage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'autoresolve_manage' );
|
||||
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'nexus_autoresolve_on', \IPS\Settings::i()->nexus_autoresolve_days, FALSE, array( 'togglesOn' => array( 'nexus_autoresolve_departments', 'nexus_autoresolve_applicable', 'nexus_autoresolve_days', 'nexus_autoresolve_notify', 'nexus_autoresolve_status' ) ) ) );
|
||||
$form->addSeparator();
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'nexus_autoresolve_departments', \IPS\Settings::i()->nexus_autoresolve_departments === '*' ? 0 : explode( ',', \IPS\Settings::i()->nexus_autoresolve_departments ), FALSE, array( 'class' => 'IPS\nexus\Support\Department', 'multiple' => TRUE, 'zeroVal' => 'any' ), NULL, NULL, NULL, 'nexus_autoresolve_departments' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'nexus_autoresolve_applicable', \IPS\Settings::i()->nexus_autoresolve_applicable, FALSE, array( 'class' => 'IPS\nexus\Support\Status', 'multiple' => TRUE ), NULL, NULL, NULL, 'nexus_autoresolve_applicable' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'nexus_autoresolve_days', \IPS\Settings::i()->nexus_autoresolve_days, FALSE, array(), NULL, NULL, \IPS\Member::loggedIn()->language()->addToStack('days'), 'nexus_autoresolve_days' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'nexus_autoresolve_status', \IPS\Settings::i()->nexus_autoresolve_status, FALSE, array( 'class' => 'IPS\nexus\Support\Status' ), NULL, NULL, NULL, 'nexus_autoresolve_status' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'nexus_autoresolve_notify', \IPS\Settings::i()->nexus_autoresolve_notify, FALSE, array( 'unlimited' => 0, 'unlimitedLang' => 'never' ), NULL, NULL, \IPS\Member::loggedIn()->language()->addToStack('hours_before_resolving'), 'nexus_autoresolve_notify' ) );
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
\IPS\DB::i()->update( 'core_tasks', array( 'enabled' => (int) $values['nexus_autoresolve_on'] ), "`key`='supportAutoresolve'" );
|
||||
|
||||
if ( !$values['nexus_autoresolve_on'] )
|
||||
{
|
||||
$values['nexus_autoresolve_days'] = 0;
|
||||
}
|
||||
unset( $values['nexus_autoresolve_on'] );
|
||||
|
||||
$values['nexus_autoresolve_departments'] = $values['nexus_autoresolve_departments'] ? implode( ',' , array_keys( $values['nexus_autoresolve_departments'] ) ) : '*';
|
||||
$values['nexus_autoresolve_applicable'] = implode( ',', array_keys( $values['nexus_autoresolve_applicable'] ) );
|
||||
$values['nexus_autoresolve_status'] = $values['nexus_autoresolve_status']->id;
|
||||
|
||||
$form->saveAsSettings( $values );
|
||||
\IPS\Session::i()->log( 'acplogs__autoresolve_settings' );
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=support&controller=settings&tab=autoresolve') );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('autoresolve');
|
||||
\IPS\Output::i()->output = $form;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Customer Feedback Settings
|
||||
* @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 23 Apr 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\admin\support;
|
||||
|
||||
/* 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 Feedback Settings
|
||||
*/
|
||||
class _customerfeedback extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* Manage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'customerfeedback_manage' );
|
||||
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'nexus_support_satisfaction', \IPS\Settings::i()->nexus_support_satisfaction ) );
|
||||
|
||||
if ( $form->values() )
|
||||
{
|
||||
$form->saveAsSettings();
|
||||
\IPS\Session::i()->log( 'acplogs__customerfeedback_settings' );
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=nexus&module=support&controller=settings&tab=customerfeedback' ), 'saved' );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->output = $form;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Support Departments
|
||||
* @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 Apr 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\admin\support;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Support Departments
|
||||
*/
|
||||
class _departments extends \IPS\Node\Controller
|
||||
{
|
||||
/**
|
||||
* Node Class
|
||||
*/
|
||||
protected $nodeClass = 'IPS\nexus\Support\Department';
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'departments_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function delete()
|
||||
{
|
||||
try
|
||||
{
|
||||
$node = \IPS\nexus\Support\Department::load( \IPS\Request::i()->id );
|
||||
|
||||
if ( $node->canDelete() and \IPS\Db::i()->select( 'COUNT(*)', 'nexus_support_requests', array( 'r_department=?', $node->id ) ) )
|
||||
{
|
||||
$form = new \IPS\Helpers\Form( 'delete', 'delete' );
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'move_existing_requests_to', NULL, TRUE, array( 'class' => 'IPS\nexus\Support\Department', 'permissionCheck' => function( $_node ) use ( $node )
|
||||
{
|
||||
return $node->id != $_node->id;
|
||||
} ) ) );
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
\IPS\Db::i()->update( 'nexus_support_requests', array( 'r_department' => $values['move_existing_requests_to']->id ), array( 'r_department=?', $node->id ) );
|
||||
\IPS\Request::i()->form_submitted = TRUE;
|
||||
return parent::delete();
|
||||
}
|
||||
|
||||
\IPS\Output::i()->output = $form;
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch ( \OutOfRangeException $e ){}
|
||||
|
||||
return parent::delete();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Support 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 16 Apr 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\admin\support;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Support Custom Fields
|
||||
*/
|
||||
class _fields extends \IPS\Node\Controller
|
||||
{
|
||||
/**
|
||||
* Node Class
|
||||
*/
|
||||
protected $nodeClass = 'IPS\nexus\Support\CustomField';
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'scfields_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,251 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Incoming Email Setup
|
||||
* @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 16 Apr 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\admin\support;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Incoming Email
|
||||
*/
|
||||
class _incomingemail extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'incomingemail_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
$table = new \IPS\Helpers\Table\Db( 'core_incoming_emails', \IPS\Http\Url::internal( 'app=nexus&module=support&controller=settings&tab=incomingemail' ) );
|
||||
$table->include = array( 'rule_criteria_value' );
|
||||
$table->noSort = array( 'rule_criteria_value' );
|
||||
$table->parsers = array(
|
||||
'rule_criteria_value' => function( $val, $row )
|
||||
{
|
||||
$_langCf = 'ie_cf_' . $row['rule_criteria_field'];
|
||||
$_langCt = 'ie_ct_' . $row['rule_criteria_type'];
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( $_langCf ) . ' ' . \IPS\Member::loggedIn()->language()->addToStack( $_langCt ) . ' "' . $val . '"';
|
||||
}
|
||||
);
|
||||
$table->sortBy = $table->sortBy ?: 'rule_added_date';
|
||||
$table->sortDirection = $table->sortDirection ?: 'asc';
|
||||
|
||||
$table->rootButtons = array(
|
||||
'add' => array(
|
||||
'icon' => 'plus',
|
||||
'title' => 'incomingemail_add',
|
||||
'link' => \IPS\Http\Url::internal( 'app=nexus&module=support&controller=settings&tab=incomingemail&do=incomingEmailForm' ),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('incomingemail_add') )
|
||||
)
|
||||
);
|
||||
|
||||
$table->rowButtons = function( $row )
|
||||
{
|
||||
return array(
|
||||
'edit' => array(
|
||||
'icon' => 'pencil',
|
||||
'title' => 'edit',
|
||||
'link' => \IPS\Http\Url::internal( 'app=nexus&module=support&controller=settings&tab=incomingemail&do=incomingEmailForm&id=' ) . $row['rule_id'],
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('edit') )
|
||||
),
|
||||
'delete' => array(
|
||||
'icon' => 'times-circle',
|
||||
'title' => 'delete',
|
||||
'link' => \IPS\Http\Url::internal( 'app=nexus&module=support&controller=settings&tab=incomingemail&do=incomingEmailDelete&id=' ) . $row['rule_id'],
|
||||
'data' => array( 'delete' => '' ),
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
if ( isset( \IPS\Request::i()->type ) )
|
||||
{
|
||||
if ( \IPS\Request::i()->type === 'piping' )
|
||||
{
|
||||
$content = \IPS\Theme::i()->getTemplate('incomingemailsetup')->piping();
|
||||
}
|
||||
elseif ( \IPS\Request::i()->type === 'pop3' )
|
||||
{
|
||||
$content = \IPS\Theme::i()->getTemplate('incomingemailsetup')->pop3( $this->_pop3() );
|
||||
}
|
||||
else
|
||||
{
|
||||
$content = \IPS\Theme::i()->getTemplate('incomingemailsetup')->splash( (string) $table );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$content = NULL;
|
||||
if ( \IPS\Settings::i()->pop3_server )
|
||||
{
|
||||
try
|
||||
{
|
||||
$task = \IPS\Db::i()->select( '*', 'core_tasks', array( 'app=? AND `key`=? AND enabled=1', 'core', 'pop' ) )->first();
|
||||
$pop3Form = $this->_pop3();
|
||||
$pop3Form->addButton( 'disable_pop3', 'link', \IPS\Http\Url::internal( 'app=nexus&module=support&controller=incomingemail&do=disablePop3' ), '', array( 'data-confirm' => '' ) );
|
||||
$content = \IPS\Theme::i()->getTemplate('incomingemailsetup')->usingpop3( $pop3Form, (string) $table );
|
||||
}
|
||||
catch ( \UnderflowException $e ) { }
|
||||
}
|
||||
|
||||
$content = $content ?: \IPS\Theme::i()->getTemplate('incomingemailsetup')->splash( (string) $table );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'admin_support.js', 'nexus', 'admin' ) );
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('incomingemailsetup')->template( $content );
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable POP3
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function disablePop3()
|
||||
{
|
||||
\IPS\Session::i()->log( 'acplogs__pop3_settings' );
|
||||
\IPS\DB::i()->update( 'core_tasks', array( 'enabled' => 0 ), array( 'app=? AND `key`=?', 'core', 'pop' ) );
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=support&controller=settings&tab=incomingemail') );
|
||||
}
|
||||
|
||||
/**
|
||||
* POP3
|
||||
*
|
||||
* @return \IPS\Helpers\Form
|
||||
*/
|
||||
protected function _pop3()
|
||||
{
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'pop3_server', \IPS\Settings::i()->pop3_server, TRUE ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'pop3_port', \IPS\Settings::i()->pop3_port, TRUE ) );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'pop3_user', \IPS\Settings::i()->pop3_user, TRUE ) );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'pop3_password', \IPS\Settings::i()->pop3_password, FALSE ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'pop3_tls', \IPS\Settings::i()->pop3_tls ) );
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
require_once \IPS\ROOT_PATH . '/system/3rd_party/pop3/pop3.class.inc';
|
||||
$pop3 = new \POP3;
|
||||
try
|
||||
{
|
||||
if ( !$pop3->connect( ( $values['pop3_tls'] ? 'ssl://' : '' ) . $values['pop3_server'], $values['pop3_port'] ) )
|
||||
{
|
||||
throw new \DomainException( \IPS\Member::loggedIn()->language()->addToStack('pop3_connect_err') );
|
||||
}
|
||||
|
||||
if ( !$pop3->login( $values['pop3_user'], $values['pop3_password'] ) )
|
||||
{
|
||||
throw new \DomainException( \IPS\Member::loggedIn()->language()->addToStack('pop3_login_err') );
|
||||
}
|
||||
|
||||
$form->saveAsSettings();
|
||||
\IPS\Session::i()->log( 'acplogs__pop3_settings' );
|
||||
\IPS\DB::i()->update( 'core_tasks', array( 'enabled' => 1 ), array( 'app=? AND `key`=?', 'core', 'pop' ) );
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=support&controller=settings&tab=incomingemail') );
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
{
|
||||
$form->error = $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add/Edit Incoming Email Rule Form
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function incomingEmailForm()
|
||||
{
|
||||
/* Load Rule */
|
||||
$rule = NULL;
|
||||
if ( \IPS\Request::i()->id )
|
||||
{
|
||||
try
|
||||
{
|
||||
$rule = \IPS\Db::i()->select( '*', 'core_incoming_emails', array( 'rule_id=?', \IPS\Request::i()->id ) )->first();
|
||||
}
|
||||
catch ( \UnderflowException $e ) { }
|
||||
}
|
||||
|
||||
/* Build form */
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->add( new \IPS\Helpers\Form\Custom( 'rule_criteria_value', array(
|
||||
'criteria_field' => $rule ? $rule['rule_criteria_field'] : '',
|
||||
'criteria_type' => $rule ? $rule['rule_criteria_type'] : '',
|
||||
'criteria_value' => $rule ? $rule['rule_criteria_value'] : ''
|
||||
), FALSE, array( 'getHtml' => function( $element )
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate( 'advancedsettings', 'core' )->ruleCriteriaForm( $element->name, $element->defaultValue['criteria_field'], $element->defaultValue['criteria_type'], $element->defaultValue['criteria_value'] );
|
||||
} ) ) );
|
||||
|
||||
/* Handle submissions */
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
$save = array(
|
||||
'rule_criteria_field' => $values['rule_criteria_value']['criteria_field'],
|
||||
'rule_criteria_type' => $values['rule_criteria_value']['criteria_type'],
|
||||
'rule_criteria_value' => $values['rule_criteria_value']['criteria_value'],
|
||||
'rule_app' => '',
|
||||
);
|
||||
|
||||
if ( $rule )
|
||||
{
|
||||
\IPS\Db::i()->update( 'core_incoming_emails', $save, array( 'rule_id=?', $rule['rule_id'] ) );
|
||||
\IPS\Session::i()->log( 'acplogs__incomingemail_edited' );
|
||||
}
|
||||
else
|
||||
{
|
||||
$save['rule_added_date'] = time();
|
||||
$save['rule_added_by'] = \IPS\Member::loggedIn()->member_id;
|
||||
|
||||
\IPS\Db::i()->insert( 'core_incoming_emails', $save );
|
||||
\IPS\Session::i()->log( 'acplogs__incomingemail_added' );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=nexus&module=support&controller=settings&tab=incomingemail&tab=incomingemail' ), 'saved' );
|
||||
}
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->output = $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete Incoming Email Rule
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function incomingEmailDelete()
|
||||
{
|
||||
\IPS\Db::i()->delete( 'core_incoming_emails', array( 'rule_id=?', \IPS\Request::i()->id ) );
|
||||
\IPS\Session::i()->log( 'acplogs__incomingemail_deleted' );
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=nexus&module=support&controller=settings&tab=incomingemail&tab=incomingemail" ) );
|
||||
}
|
||||
}
|
||||
Whitespace-only changes.
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Outgoing Email Settings
|
||||
* @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 Apr 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\admin\support;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outgoing Email Settings
|
||||
*/
|
||||
class _outgoingemail extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* Manage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'autoresolve_manage' );
|
||||
|
||||
$form = new \IPS\Helpers\Form;
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'nexus_sout_chrome', \IPS\Settings::i()->nexus_sout_chrome, FALSE, array(
|
||||
'options' => array(
|
||||
0 => \IPS\Theme::i()->resource( 'settings/email_no_chrome.png' ),
|
||||
1 => \IPS\Theme::i()->resource( 'settings/email_chrome.png' )
|
||||
),
|
||||
'parse' => 'image',
|
||||
'descriptions' => array(
|
||||
0 => \IPS\Member::loggedIn()->language()->addToStack('nexus_sout_chrome_no'),
|
||||
1 => \IPS\Member::loggedIn()->language()->addToStack('nexus_sout_chrome_yes'),
|
||||
)
|
||||
) ) );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'nexus_sout_from', \IPS\Settings::i()->nexus_sout_from, FALSE, array(
|
||||
'options' => array(
|
||||
'staff' => 'nexus_sout_from_staff',
|
||||
'dpt' => 'nexus_sout_from_department',
|
||||
'other' => 'nexus_sout_from_other',
|
||||
),
|
||||
'userSuppliedInput' => 'other',
|
||||
'toggles' => array(
|
||||
'other' => array( 'other_nexus_sout_from' )
|
||||
)
|
||||
) ) );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'nexus_sout_autoreply', \IPS\Settings::i()->nexus_sout_autoreply ) );
|
||||
|
||||
if ( $form->values() )
|
||||
{
|
||||
$form->saveAsSettings();
|
||||
\IPS\Session::i()->log( 'acplogs__outgoingemail_settings' );
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=nexus&module=support&controller=settings&tab=outgoingemail' ), 'saved' );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->output = $form;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,399 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Support Reports
|
||||
* @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 23 Apr 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\admin\support;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Support Reports
|
||||
*/
|
||||
class _reports extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'reports_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Dashboard
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
/* Tabs */
|
||||
$tabs = array(
|
||||
'overview' => 'overview',
|
||||
'replies' => 'replies',
|
||||
'feedback_ratings' => 'feedback_ratings',
|
||||
'latest_feedback' => 'latest_feedback',
|
||||
);
|
||||
$activeTab = ( isset( \IPS\Request::i()->tab ) and array_key_exists( \IPS\Request::i()->tab, $tabs ) ) ? \IPS\Request::i()->tab : 'staff_productivity';
|
||||
$activeTabContents = '';
|
||||
|
||||
/* Staff Productivity */
|
||||
if ( $activeTab === 'overview' )
|
||||
{
|
||||
/* Build table */
|
||||
$staffProductivityTable = new \IPS\Helpers\Table\Db(
|
||||
'nexus_support_replies',
|
||||
\IPS\Http\Url::internal( 'app=nexus&module=support&controller=reports&act=productivity_table' ),
|
||||
array(
|
||||
array( 'reply_type=?', \IPS\nexus\Support\Reply::REPLY_STAFF ),
|
||||
\IPS\Db::i()->in( 'reply_member', array_keys( \IPS\nexus\Support\Request::staff() ) )
|
||||
),
|
||||
'reply_member'
|
||||
);
|
||||
$staffProductivityTable->langPrefix = 'staff_';
|
||||
$staffProductivityTable->selects = array( 'COUNT(*) AS reply_count' );
|
||||
$staffProductivityTable->include = array( 'name', 'reply_count' );
|
||||
$staffProductivityTable->widths = array( 'name' => 75, 'reply_count' => 25 );
|
||||
$staffProductivityTable->parsers['reply_count'] = function( $val ) { return intval( $val ); };
|
||||
if ( \IPS\Settings::i()->nexus_support_satisfaction )
|
||||
{
|
||||
$staffProductivityTable->joins[] = array(
|
||||
'select' => 'rating_count, rating_average',
|
||||
'from' => \IPS\Db::i()->select( 'rating_reply, COUNT(*) AS rating_count, AVG(rating_rating) AS rating_average', 'nexus_support_ratings' ),
|
||||
'where' => 'rating_reply=reply_id'
|
||||
);
|
||||
|
||||
$staffProductivityTable->include[] = 'rating_average';
|
||||
$staffProductivityTable->widths = array( 'name' => 50, 'reply_count' => 25, 'rating_average' => 25 );
|
||||
$staffProductivityTable->parsers['rating_average'] = function( $val, $row ) {
|
||||
return \IPS\Theme::i()->getTemplate('supportreports')->averageRatingCell( $val, $row['rating_count'] );
|
||||
};
|
||||
}
|
||||
$staffProductivityTable->sortBy = $staffProductivityTable->sortBy ?: 'reply_count';
|
||||
|
||||
/* We need to join the members table for the name */
|
||||
$staffProductivityTable->joins[] = array(
|
||||
'select' => 'name',
|
||||
'from' => 'core_members',
|
||||
'where' => 'member_id=reply_member'
|
||||
);
|
||||
$staffProductivityTable->quickSearch = 'name';
|
||||
|
||||
/* Specify the filters and search options */
|
||||
$staffProductivityTable->filters = array(
|
||||
'last_24_hours' => array( 'reply_date>?', \IPS\DateTime::create()->sub( new \DateInterval( 'P1D' ) )->getTimestamp() ),
|
||||
'last_7_days' => array( 'reply_date>?', \IPS\DateTime::create()->sub( new \DateInterval( 'P7D' ) )->getTimestamp() ),
|
||||
'last_30_days' => array( 'reply_date>?', \IPS\DateTime::create()->sub( new \DateInterval( 'P30D' ) )->getTimestamp() ),
|
||||
);
|
||||
|
||||
/* Buttons for each member */
|
||||
$staffProductivityTable->rowButtons = function( $row )
|
||||
{
|
||||
return array(
|
||||
'report' => array(
|
||||
'icon' => 'search',
|
||||
'title' => 'view_report',
|
||||
'link' => \IPS\Http\Url::internal('app=nexus&module=support&controller=reports&do=staff')->setQueryString( 'id', $row['reply_member'] ),
|
||||
),
|
||||
);
|
||||
};
|
||||
|
||||
$activeTabContents = (string) $staffProductivityTable;
|
||||
}
|
||||
|
||||
/* Replies */
|
||||
elseif ( $activeTab === 'replies' )
|
||||
{
|
||||
$staffRepliesChart = new \IPS\Helpers\Chart\Dynamic( \IPS\Http\Url::internal( 'app=nexus&module=support&controller=reports&tab=replies' ), 'nexus_support_replies', 'reply_date', '',
|
||||
array(
|
||||
'vAxis' => array( 'title' => \IPS\Member::loggedIn()->language()->addToStack('replies_made') ),
|
||||
),
|
||||
'LineChart', 'daily', array( 'start' => \IPS\DateTime::create()->sub( new \DateInterval( 'P1M' ) ), 'end' => 0 )
|
||||
);
|
||||
$staffRepliesChart->where[] = array( 'reply_type=?', \IPS\nexus\Support\Reply::REPLY_STAFF );
|
||||
$staffRepliesChart->groupBy = 'reply_member';
|
||||
foreach( \IPS\nexus\Support\Request::staff() as $id => $name )
|
||||
{
|
||||
$staffRepliesChart->addSeries( $name, 'number', 'COUNT(*)', TRUE, $id );
|
||||
}
|
||||
|
||||
$activeTabContents = (string) $staffRepliesChart;
|
||||
}
|
||||
|
||||
/* Replies */
|
||||
elseif ( $activeTab === 'feedback_ratings' )
|
||||
{
|
||||
$staffRatingsChart = new \IPS\Helpers\Chart\Dynamic( \IPS\Http\Url::internal( 'app=nexus&module=support&controller=reports&tab=feedback_ratings' ), 'nexus_support_ratings', 'rating_date', '',
|
||||
array(
|
||||
'vAxis' => array( 'title' => \IPS\Member::loggedIn()->language()->addToStack('average_rating'), 'viewWindow' => array( 'min' => 0, 'max' => 5 ) ),
|
||||
),
|
||||
'ColumnChart', 'monthly'
|
||||
);
|
||||
$staffRatingsChart->plotZeros = FALSE;
|
||||
$staffRatingsChart->groupBy = 'rating_staff';
|
||||
foreach( \IPS\nexus\Support\Request::staff() as $id => $name )
|
||||
{
|
||||
$staffRatingsChart->addSeries( $name, 'number', 'AVG(rating_rating)', TRUE, $id );
|
||||
}
|
||||
|
||||
$activeTabContents = (string) $staffRatingsChart;
|
||||
}
|
||||
|
||||
/* Latest Feedback */
|
||||
elseif ( $activeTab === 'latest_feedback' )
|
||||
{
|
||||
$table = new \IPS\Helpers\Table\Db( 'nexus_support_ratings', \IPS\Http\Url::internal('app=nexus&module=support&controller=reports&tab=latest_feedback') );
|
||||
$table->joins = array(
|
||||
array(
|
||||
'from' => 'nexus_support_replies',
|
||||
'where' => 'reply_id=rating_reply'
|
||||
),
|
||||
array(
|
||||
'from' => 'nexus_support_requests',
|
||||
'where' => 'r_id=reply_request'
|
||||
)
|
||||
);
|
||||
$table->sortBy = 'rating_date';
|
||||
$table->sortDirection = 'desc';
|
||||
$table->parsers = array(
|
||||
'reply_post' => function( $val )
|
||||
{
|
||||
return $val;
|
||||
}
|
||||
);
|
||||
|
||||
$table->tableTemplate = array( \IPS\Theme::i()->getTemplate('support'), 'latestFeedback' );
|
||||
|
||||
$activeTabContents = (string) $table;
|
||||
}
|
||||
|
||||
/* Display */
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->output = $activeTabContents;
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('performance_reports');
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->tabs( $tabs, $activeTab, $activeTabContents, \IPS\Http\Url::internal( "app=nexus&module=support&controller=reports" ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Staff Report
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function staff()
|
||||
{
|
||||
/* Load */
|
||||
$id = \IPS\Request::i()->id;
|
||||
if ( !array_key_exists( $id, \IPS\nexus\Support\Request::staff() ) )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X207/1', 404, '' );
|
||||
}
|
||||
$staff = \IPS\Member::load( $id );
|
||||
|
||||
/* Tabs */
|
||||
$tabs = array(
|
||||
'productivity' => 'productivity',
|
||||
'latest_replies' => 'latest_replies',
|
||||
'feedback_ratings' => 'feedback_ratings',
|
||||
'latest_feedback' => 'latest_feedback'
|
||||
);
|
||||
$activeTab = ( isset( \IPS\Request::i()->tab ) and array_key_exists( \IPS\Request::i()->tab, $tabs ) ) ? \IPS\Request::i()->tab : 'productivity';
|
||||
$activeTabContents = '';
|
||||
|
||||
/* Daily Productivity */
|
||||
if ( $activeTab === 'productivity' )
|
||||
{
|
||||
/* Date Range */
|
||||
$where = array( array( 'reply_type=?', \IPS\nexus\Support\Reply::REPLY_STAFF ) );
|
||||
$timeframe = isset( \IPS\Request::i()->timeframe ) ? \IPS\Request::i()->timeframe : 'last_30_days';
|
||||
switch ( $timeframe )
|
||||
{
|
||||
case 'last_24_hours':
|
||||
$daysInTimeframe = 1;
|
||||
break;
|
||||
case 'last_7_days':
|
||||
$daysInTimeframe = 7;
|
||||
break;
|
||||
case 'last_30_days':
|
||||
$daysInTimeframe = 30;
|
||||
break;
|
||||
}
|
||||
$where[] = array( 'reply_date>?', \IPS\DateTime::ts( time() )->sub( new \DateInterval( "P{$daysInTimeframe}D" ) )->getTimestamp() );
|
||||
|
||||
/* Init */
|
||||
$numberOfStaffMembers = \IPS\Db::i()->select( 'COUNT(DISTINCT reply_member)', 'nexus_support_replies', $where )->first();
|
||||
$now = \IPS\DateTime::ts( time() );
|
||||
$myOffset = $now->getTimezone()->getOffset( $now ) / 3600;
|
||||
|
||||
/* Group */
|
||||
$span = isset( \IPS\Request::i()->span ) ? \IPS\Request::i()->span : 'day';
|
||||
$group = $span === 'day' ? '%H' : '%w';
|
||||
|
||||
/* Type */
|
||||
$type = isset( \IPS\Request::i()->type ) ? \IPS\Request::i()->type : 'total';
|
||||
|
||||
/* Get average replies by hour for this staff member */
|
||||
$thisStaffMember = array();
|
||||
foreach( \IPS\Db::i()->select( "COUNT(*) AS count, reply_date AS unixtime, DATE_FORMAT( FROM_UNIXTIME( reply_date ), '{$group}' ) AS hour", 'nexus_support_replies', array_merge( $where, array( array( 'reply_member=?', $staff->member_id ) ) ), NULL, NULL, 'hour' ) as $row )
|
||||
{
|
||||
$_group = $span === 'day' ? \IPS\DateTime::ts( $row['unixtime'] )->format('G') : \IPS\DateTime::ts( $row['unixtime'] )->format('w');
|
||||
$thisStaffMember[ $_group ] = round( ( $type === 'average' ) ? ( $row['count'] / $daysInTimeframe ) : $row['count'], 1 );
|
||||
}
|
||||
|
||||
/* Get average replies by hour for all staff members */
|
||||
if ( $numberOfStaffMembers > 1 )
|
||||
{
|
||||
foreach( \IPS\Db::i()->select( "COUNT(*) AS count, reply_date AS unixtime, DATE_FORMAT( FROM_UNIXTIME( reply_date ), '{$group}' ) AS hour", 'nexus_support_replies', $where, NULL, NULL, 'hour' ) as $row )
|
||||
{
|
||||
$_group = $span === 'day' ? \IPS\DateTime::ts( $row['unixtime'] )->format('G') : \IPS\DateTime::ts( $row['unixtime'] )->format('w');
|
||||
$allStaffMembers[ $_group ] = round( ( ( $type === 'average' ) ? ( $row['count'] / $daysInTimeframe ) : $row['count'] ) / $numberOfStaffMembers, 1 );
|
||||
}
|
||||
}
|
||||
|
||||
/* Build Chart */
|
||||
$chart = new \IPS\Helpers\Chart;
|
||||
$chart->addHeader( \IPS\Member::loggedIn()->language()->addToStack('hour'), 'string' );
|
||||
$chart->addHeader( $staff->name, 'number' );
|
||||
if ( $numberOfStaffMembers > 1 )
|
||||
{
|
||||
$chart->addHeader( \IPS\Member::loggedIn()->language()->addToStack('all_staff_average'), 'number' );
|
||||
}
|
||||
if ( $span === 'day' )
|
||||
{
|
||||
foreach ( range( 0 - $myOffset, 23 - $myOffset ) as $hour )
|
||||
{
|
||||
$timestamp = mktime( 0, 0, 0 ) + ( $hour * 3600 );
|
||||
|
||||
if ( $numberOfStaffMembers > 1 )
|
||||
{
|
||||
$chart->addRow( array(
|
||||
\IPS\DateTime::ts( $timestamp )->localeTime( FALSE, FALSE ),
|
||||
isset( $thisStaffMember[ $hour + $myOffset ] ) ? $thisStaffMember[ $hour + $myOffset ] : 0,
|
||||
isset( $allStaffMembers[ $hour + $myOffset ] ) ? $allStaffMembers[ $hour + $myOffset ] : 0
|
||||
) );
|
||||
}
|
||||
else
|
||||
{
|
||||
$chart->addRow( array(
|
||||
\IPS\DateTime::ts( $timestamp )->localeTime( FALSE, FALSE ),
|
||||
isset( $thisStaffMember[ $hour + $myOffset ] ) ? $thisStaffMember[ $hour + $myOffset ] : 0
|
||||
) );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach ( range( 0, 6 ) as $day )
|
||||
{
|
||||
if ( $numberOfStaffMembers > 1 )
|
||||
{
|
||||
$chart->addRow( array(
|
||||
\IPS\Member::loggedIn()->language()->addToStack("weekday_{$day}"),
|
||||
isset( $thisStaffMember[ $day ] ) ? $thisStaffMember[ $day ] : 0,
|
||||
isset( $allStaffMembers[ $day ] ) ? $allStaffMembers[ $day ] : 0
|
||||
) );
|
||||
}
|
||||
else
|
||||
{
|
||||
$chart->addRow( array(
|
||||
\IPS\Member::loggedIn()->language()->addToStack("weekday_{$day}"),
|
||||
isset( $thisStaffMember[ $day ] ) ? $thisStaffMember[ $day ] : 0
|
||||
) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Display */
|
||||
$activeTabContents = \IPS\Theme::i()->getTemplate('supportreports')->timeChart( $chart->render( 'ColumnChart' ), \IPS\Http\Url::internal( "app=nexus&module=support&controller=reports&do=staff&id={$staff->member_id}&tab=productivity" )->setQueryString( array(
|
||||
'span' => $span,
|
||||
'timeframe' => $timeframe,
|
||||
'type' => $type
|
||||
) ) );
|
||||
}
|
||||
|
||||
/* Latest Replies */
|
||||
elseif ( $activeTab === 'latest_replies' )
|
||||
{
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'support.css', 'nexus', 'admin' ) );
|
||||
$table = new \IPS\Helpers\Table\Content( 'IPS\nexus\Support\Reply', \IPS\Http\Url::internal( "app=nexus&module=support&controller=reports&do=staff&id={$staff->member_id}&tab=latest_replies" ), array( array( 'reply_type=? AND reply_member=?', \IPS\nexus\Support\Reply::REPLY_STAFF, $staff->member_id ) ) );
|
||||
$table->tableTemplate = array( \IPS\Theme::i()->getTemplate( 'tables', 'core', 'front' ), 'table' );
|
||||
$table->rowsTemplate = array( \IPS\Theme::i()->getTemplate( 'supportreports' ), 'supportReplyRows' );
|
||||
$table->sortBy = 'reply_date';
|
||||
$activeTabContents = (string) $table;
|
||||
}
|
||||
|
||||
/* Feedback */
|
||||
elseif ( $activeTab === 'feedback_ratings' )
|
||||
{
|
||||
$staffRatingsChart = new \IPS\Helpers\Chart\Dynamic( \IPS\Http\Url::internal( "app=nexus&module=support&controller=reports&do=staff&id={$staff->member_id}&tab=feedback_ratings" ), 'nexus_support_ratings', 'rating_date', '',
|
||||
array(
|
||||
'vAxis' => array( 'title' => \IPS\Member::loggedIn()->language()->addToStack('average_rating'), 'viewWindow' => array( 'min' => 0, 'max' => 5 ) ),
|
||||
'legend' => 'none'
|
||||
),
|
||||
'LineChart', 'monthly'
|
||||
);
|
||||
$staffRatingsChart->plotZeros = FALSE;
|
||||
$staffRatingsChart->addSeries( $staff->name, 'number', 'AVG(rating_rating)', FALSE );
|
||||
|
||||
$activeTabContents = (string) $staffRatingsChart;
|
||||
}
|
||||
|
||||
/* Latest Feedback */
|
||||
elseif ( $activeTab === 'latest_feedback' )
|
||||
{
|
||||
$table = new \IPS\Helpers\Table\Db( 'nexus_support_ratings', \IPS\Http\Url::internal("app=nexus&module=support&controller=reports&do=staff&id={$staff->member_id}&tab=latest_feedback"), array( 'rating_staff=?', $staff->member_id ) );
|
||||
$table->joins = array(
|
||||
array(
|
||||
'from' => 'nexus_support_replies',
|
||||
'where' => 'reply_id=rating_reply'
|
||||
),
|
||||
array(
|
||||
'from' => 'nexus_support_requests',
|
||||
'where' => 'r_id=reply_request'
|
||||
)
|
||||
);
|
||||
$table->sortBy = 'rating_date';
|
||||
$table->sortDirection = 'desc';
|
||||
$table->parsers = array(
|
||||
'reply_post' => function( $val )
|
||||
{
|
||||
return $val;
|
||||
}
|
||||
);
|
||||
|
||||
$table->tableTemplate = array( \IPS\Theme::i()->getTemplate('support'), 'latestFeedback' );
|
||||
|
||||
$activeTabContents = (string) $table;
|
||||
}
|
||||
|
||||
/* Display */
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->output = $activeTabContents;
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->title = $staff->name;
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->tabs( $tabs, $activeTab, $activeTabContents, \IPS\Http\Url::internal( "app=nexus&module=support&controller=reports&do=staff&id={$staff->member_id}" ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,748 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Support Request View
|
||||
* @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 Apr 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\admin\support;
|
||||
use \IPS\nexus\Support;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Support Request View
|
||||
*/
|
||||
class _request extends \IPS\nexus\modules\front\support\view
|
||||
{
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'requests_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* View Item
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
\IPS\Output::i()->breadcrumb[] = array( \IPS\Http\Url::internal('app=nexus&module=support&controller=requests'), \IPS\Member::loggedIn()->language()->addToStack('menu__nexus_support_requests') );
|
||||
parent::manage();
|
||||
|
||||
/* AJAX responders */
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
{
|
||||
/* Popup which has the merge button */
|
||||
if ( isset( \IPS\Request::i()->popup ) )
|
||||
{
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'support' )->requestPopup( $this->request );
|
||||
}
|
||||
/* Stock Action data */
|
||||
elseif( isset( \IPS\Request::i()->stockActionData ) )
|
||||
{
|
||||
if ( \IPS\Request::i()->stockActionData )
|
||||
{
|
||||
try
|
||||
{
|
||||
$action = \IPS\nexus\Support\StockAction::load( \IPS\Request::i()->stockActionData );
|
||||
$data = array();
|
||||
|
||||
if ( $action->department )
|
||||
{
|
||||
$data['department'] = $action->department->id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$data['department'] = $this->request->department->id;
|
||||
}
|
||||
|
||||
if ( $action->status )
|
||||
{
|
||||
$data['status'] = $action->status->id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$data['status'] = \IPS\nexus\Support\Status::load( TRUE, 'status_default_staff' )->id;
|
||||
}
|
||||
|
||||
if ( $action->staff )
|
||||
{
|
||||
$data['assign_to'] = $action->staff->member_id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$data['assign_to'] = $this->request->staff_lock ? ( $this->request->staff ? $this->request->staff->member_id : 0 ) : 0;
|
||||
}
|
||||
|
||||
if ( $action->message )
|
||||
{
|
||||
$data['message'] = $action->message;
|
||||
}
|
||||
|
||||
\IPS\Output::i()->json( $data );
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
{
|
||||
\IPS\Output::i()->json( $e->getMessage(), 500 );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->json( array(
|
||||
'department' => $this->request->department->id,
|
||||
'status' => \IPS\nexus\Support\Status::load( TRUE, 'status_default_staff' )->id,
|
||||
'assign_to' => $this->request->staff_lock ? ( $this->request->staff ? $this->request->staff->member_id : 0 ) : 0
|
||||
) );
|
||||
}
|
||||
}
|
||||
/* Purchase tree */
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->output = \IPS\nexus\Purchase::tree( $this->request->acpUrl(), array(), 's.' . $this->request->id, $this->request->purchase );
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/* Setting Order? */
|
||||
if ( isset( \IPS\Request::i()->order ) )
|
||||
{
|
||||
\IPS\Request::i()->setCookie( 'support_order', \IPS\Request::i()->order, \IPS\DateTime::create()->add( new \DateInterval('P1Y') ) );
|
||||
}
|
||||
|
||||
/* Views */
|
||||
$this->request->setStaffView( \IPS\Member::loggedIn() );
|
||||
|
||||
/* Are we tracking? */
|
||||
try
|
||||
{
|
||||
$trackLang = \IPS\Db::i()->select( 'notify', 'nexus_support_tracker', array( 'member_id=? AND request_id=?', \IPS\Member::loggedIn()->member_id, $this->request->id ) )->first() ? 'tracking_notify' : 'tracking_no_notify';
|
||||
}
|
||||
catch ( \UnderflowException $e )
|
||||
{
|
||||
$trackLang = 'not_tracking';
|
||||
}
|
||||
|
||||
/* Init buttons */
|
||||
\IPS\Output::i()->sidebar['actions'] = array(
|
||||
'status' => array(
|
||||
'icon' => 'tag',
|
||||
'title' => $this->request->status->_title,
|
||||
'menu' => array(),
|
||||
'menuClass' => 'ipsMenu_selectable ipsMenu_narrow',
|
||||
'data' => array( 'controller' => 'nexus.admin.support.metamenu' )
|
||||
),
|
||||
'severity' => array(
|
||||
'icon' => 'exclamation',
|
||||
'title' => $this->request->severity->_title,
|
||||
'menu' => array(),
|
||||
'menuClass' => 'ipsMenu_selectable',
|
||||
'data' => array( 'controller' => 'nexus.admin.support.metamenu' )
|
||||
),
|
||||
'department' => array(
|
||||
'icon' => 'folder',
|
||||
'title' => $this->request->department->_title,
|
||||
'menu' => array(),
|
||||
'menuClass' => 'ipsMenu_selectable ipsMenu_narrow',
|
||||
'data' => array( 'controller' => 'nexus.admin.support.metamenu' )
|
||||
),
|
||||
'staff' => array(
|
||||
'icon' => 'user',
|
||||
'title' => $this->request->staff ? $this->request->staff->name : 'unassigned',
|
||||
'menu' => array(),
|
||||
'menuClass' => 'ipsMenu_selectable',
|
||||
'data' => array( 'controller' => 'nexus.admin.support.metamenu', 'role' => 'staffMenu' ),
|
||||
),
|
||||
'track' => array(
|
||||
'icon' => 'star',
|
||||
'title' => $trackLang,
|
||||
'menu' => array(
|
||||
array(
|
||||
'class' => $trackLang === 'not_tracking' ? 'ipsMenu_itemChecked' : '',
|
||||
'title' => 'not_tracking',
|
||||
'link' => $this->request->acpUrl()->setQueryString( array( 'do' => 'track', 'track' => 0 ) )
|
||||
),
|
||||
array(
|
||||
'class' => $trackLang === 'tracking_no_notify' ? 'ipsMenu_itemChecked' : '',
|
||||
'title' => 'tracking_no_notify',
|
||||
'link' => $this->request->acpUrl()->setQueryString( array( 'do' => 'track', 'track' => 1, 'notify' => 0 ) )
|
||||
),
|
||||
array(
|
||||
'class' => $trackLang === 'tracking_notify' ? 'ipsMenu_itemChecked' : '',
|
||||
'title' => 'tracking_notify',
|
||||
'link' => $this->request->acpUrl()->setQueryString( array( 'do' => 'track', 'track' => 1, 'notify' => 1 ) )
|
||||
)
|
||||
),
|
||||
'menuClass' => 'ipsMenu_selectable',
|
||||
'data' => array( 'controller' => 'nexus.admin.support.metamenu' )
|
||||
)
|
||||
);
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'support', 'requests_delete' ) )
|
||||
{
|
||||
\IPS\Output::i()->sidebar['actions']['delete'] = array(
|
||||
'icon' => 'times-circle',
|
||||
'title' => 'delete',
|
||||
'link' => $this->request->acpUrl()->setQueryString( 'do', 'delete' ),
|
||||
'data' => array( 'confirm' => '' )
|
||||
);
|
||||
}
|
||||
|
||||
/* Populate statuses */
|
||||
foreach ( Support\Status::roots() as $status )
|
||||
{
|
||||
\IPS\Output::i()->sidebar['actions']['status']['menu'][] = array(
|
||||
'class' => $status->id === $this->request->status->id ? 'ipsMenu_itemChecked' : '',
|
||||
'title' => $status->_title,
|
||||
'link' => $this->request->acpUrl()->setQueryString( array( 'do' => 'status', 'status' => $status->id ) )
|
||||
);
|
||||
}
|
||||
|
||||
/* Populate severities */
|
||||
if ( count( Support\Severity::roots() ) < 2 )
|
||||
{
|
||||
unset( \IPS\Output::i()->sidebar['actions']['severity'] );
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach ( Support\Severity::roots() as $severity )
|
||||
{
|
||||
\IPS\Output::i()->sidebar['actions']['severity']['menu'][] = array(
|
||||
'class' => $severity->id === $this->request->severity->id ? 'ipsMenu_itemChecked' : '',
|
||||
'title' => $severity->_title,
|
||||
'link' => $this->request->acpUrl()->setQueryString( array( 'do' => 'severity', 'severity' => $severity->id ) ),
|
||||
'data' => array( 'group' => 'severities' ),
|
||||
);
|
||||
}
|
||||
|
||||
if ( $this->request->member and \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'support', 'requests_block_sev' ) )
|
||||
{
|
||||
\IPS\Output::i()->sidebar['actions']['severity']['menu'][] = array( 'hr' => TRUE );
|
||||
\IPS\Output::i()->sidebar['actions']['severity']['menu'][] = array(
|
||||
'class' => !$this->request->author()->cm_no_sev ? 'ipsMenu_itemChecked' : '',
|
||||
'title' => \IPS\Member::loggedIn()->language()->addToStack( 'cm_no_sev_off', FALSE, array( 'sprintf' => array( $this->request->supportAuthor()->name() ) ) ),
|
||||
'link' => $this->request->acpUrl()->setQueryString( array( 'do' => 'noSev', 'no_sev' => 0 ) ),
|
||||
'data' => array( 'group' => 'no_sev', 'noSet' => 'true' ),
|
||||
);
|
||||
\IPS\Output::i()->sidebar['actions']['severity']['menu'][] = array(
|
||||
'class' => $this->request->author()->cm_no_sev ? 'ipsMenu_itemChecked' : '',
|
||||
'title' => \IPS\Member::loggedIn()->language()->addToStack( 'cm_no_sev_on', FALSE, array( 'sprintf' => array( $this->request->supportAuthor()->name() ) ) ),
|
||||
'link' => $this->request->acpUrl()->setQueryString( array( 'do' => 'noSev', 'no_sev' => 1 ) ),
|
||||
'data' => array( 'group' => 'no_sev', 'noSet' => 'true' ),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/* Populate departments */
|
||||
foreach ( Support\Department::roots() as $department )
|
||||
{
|
||||
\IPS\Output::i()->sidebar['actions']['department']['menu'][] = array(
|
||||
'class' => $department->id === $this->request->department->id ? 'ipsMenu_itemChecked' : '',
|
||||
'title' => $department->_title,
|
||||
'link' => $this->request->acpUrl()->setQueryString( array( 'do' => 'department', 'department' => $department->id ) )
|
||||
);
|
||||
}
|
||||
|
||||
/* Populate staff */
|
||||
foreach ( Support\Request::staff() as $id => $name )
|
||||
{
|
||||
\IPS\Output::i()->sidebar['actions']['staff']['menu'][] = array(
|
||||
'class' => ( $this->request->staff and $id === $this->request->staff->member_id ) ? 'ipsMenu_itemChecked' : '',
|
||||
'title' => $name,
|
||||
'link' => $this->request->acpUrl()->setQueryString( array( 'do' => 'staff', 'staff' => $id ) ),
|
||||
'data' => array( 'group' => 'staff', 'id' => $id ),
|
||||
);
|
||||
}
|
||||
\IPS\Output::i()->sidebar['actions']['staff']['menu'][] = array(
|
||||
'class' => !$this->request->staff ? 'ipsMenu_itemChecked' : '',
|
||||
'title' => 'unassigned',
|
||||
'link' => $this->request->acpUrl()->setQueryString( array( 'do' => 'staff', 'staff' => 0 ) ),
|
||||
'data' => array( 'group' => 'staff', 'id' => 0 ),
|
||||
);
|
||||
\IPS\Output::i()->sidebar['actions']['staff']['menu'][] = array( 'hr' => TRUE );
|
||||
\IPS\Output::i()->sidebar['actions']['staff']['menu'][] = array(
|
||||
'class' => $this->request->staff_lock ? 'ipsMenu_itemChecked' : '',
|
||||
'title' => \IPS\Member::loggedIn()->language()->addToStack( 'request_staff_lock_on' ),
|
||||
'link' => $this->request->acpUrl()->setQueryString( array( 'do' => 'staffLock', 'lock' => 1 ) ),
|
||||
'data' => array( 'group' => 'staff_lock', 'noSet' => 'true' ),
|
||||
);
|
||||
\IPS\Output::i()->sidebar['actions']['staff']['menu'][] = array(
|
||||
'class' => !$this->request->staff_lock ? 'ipsMenu_itemChecked' : '',
|
||||
'title' =>\IPS\Member::loggedIn()->language()->addToStack( 'request_staff_lock_off' ),
|
||||
'link' => $this->request->acpUrl()->setQueryString( array( 'do' => 'staffLock', 'lock' => 0 ) ),
|
||||
'data' => array( 'group' => 'staff_lock', 'noSet' => 'true' ),
|
||||
);
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'request_x', FALSE, array( 'sprintf' => "#{$this->request->id}" ) );
|
||||
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'admin_support.js', 'nexus', 'admin' ) );
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'support.css', 'nexus', 'admin' ) );
|
||||
if ( \IPS\Theme::i()->settings['responsive'] )
|
||||
{
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'support_responsive.css', 'nexus', 'admin' ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pending Response Send/Discard
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function pending()
|
||||
{
|
||||
try
|
||||
{
|
||||
$message = Support\Reply::loadAndCheckPerms( \IPS\Request::i()->response );
|
||||
|
||||
if ( \IPS\Request::i()->send )
|
||||
{
|
||||
$message->sendPending();
|
||||
}
|
||||
else
|
||||
{
|
||||
$message->delete();
|
||||
}
|
||||
|
||||
\IPS\Output::i()->redirect( $message->item()->acpUrl()->setQueryString( array( 'filter' => \IPS\Request::i()->filter, 'sort' => \IPS\Request::i()->sort ) ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X208/1', 404, '' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit Title
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function editTitle()
|
||||
{
|
||||
try
|
||||
{
|
||||
$request = Support\Request::loadAndCheckPerms( \IPS\Request::i()->id );
|
||||
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'support_title', $request->title, TRUE, array( 'maxLength' => 255 ) ) );
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
$request->title = $values['support_title'];
|
||||
$request->save();
|
||||
\IPS\Output::i()->redirect( $request->acpUrl() );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->output = $form;
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X208/2', 404, '' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit Custom Fields
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function cfields()
|
||||
{
|
||||
try
|
||||
{
|
||||
$request = Support\Request::loadAndCheckPerms( \IPS\Request::i()->id );
|
||||
$customFieldValues = $request->cfields;
|
||||
|
||||
$form = new \IPS\Helpers\Form;
|
||||
foreach ( $request->department->customFields() as $field )
|
||||
{
|
||||
$form->add( $field->buildHelper( isset( $customFieldValues[ $field->id ] ) ? $customFieldValues[ $field->id ] : NULL ) );
|
||||
}
|
||||
|
||||
if ( $values = $form->values( TRUE ) )
|
||||
{
|
||||
$save = array();
|
||||
foreach ( $values as $k => $v )
|
||||
{
|
||||
$save[ mb_substr( $k, 13 ) ] = $v;
|
||||
}
|
||||
$request->cfields = $save;
|
||||
$request->save();
|
||||
\IPS\Output::i()->redirect( $request->acpUrl() );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->output = $form;
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X208/3', 404, '' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Status
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function status()
|
||||
{
|
||||
try
|
||||
{
|
||||
/* Init */
|
||||
$return = array();
|
||||
$request = Support\Request::loadAndCheckPerms( \IPS\Request::i()->id );
|
||||
$status = Support\Status::load( \IPS\Request::i()->status );
|
||||
$oldStatus = $request->status;
|
||||
$request->status = $status;
|
||||
|
||||
/* Assign it if we have to */
|
||||
if ( $status->assign )
|
||||
{
|
||||
if ( $request->staff and $request->staff->member_id != \IPS\Member::loggedIn()->member_id )
|
||||
{
|
||||
$return['alert'] = \IPS\Member::loggedIn()->language()->addToStack( 'you_have_stolen_request', FALSE, array( 'sprintf' => array( $request->staff->name ) ) );
|
||||
}
|
||||
$request->staff = \IPS\Member::loggedIn();
|
||||
$return['staff'] = array( 'id' => \IPS\Member::loggedIn()->member_id, 'name' => \IPS\Member::loggedIn()->name );
|
||||
}
|
||||
/* Or set the previous status was "Working", release our assigning */
|
||||
elseif ( $oldStatus->assign and $request->staff )
|
||||
{
|
||||
$request->staff = NULL;
|
||||
$return['staff'] = array( 'id' => 0, 'name' => \IPS\Member::loggedIn()->language()->addToStack('unassigned') );
|
||||
}
|
||||
$request->save();
|
||||
|
||||
/* Log */
|
||||
if ( $status->log )
|
||||
{
|
||||
$request->log( 'status', $oldStatus, $status );
|
||||
}
|
||||
|
||||
/* Return */
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->json( $return );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->redirect( $request->acpUrl() );
|
||||
}
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X208/4', 404, '' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Severity
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function severity()
|
||||
{
|
||||
try
|
||||
{
|
||||
$request = Support\Request::loadAndCheckPerms( \IPS\Request::i()->id );
|
||||
$new = Support\Severity::load( \IPS\Request::i()->severity );
|
||||
$request->log( 'severity', $request->severity, $new );
|
||||
$request->severity = $new;
|
||||
$request->save();
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->json( array() );
|
||||
}
|
||||
\IPS\Output::i()->redirect( $request->acpUrl() );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X208/5', 404, '' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Control member's permission to set severities
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function noSev()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'requests_block_sev' );
|
||||
|
||||
try
|
||||
{
|
||||
$request = Support\Request::loadAndCheckPerms( \IPS\Request::i()->id );
|
||||
$request->author()->cm_no_sev = \IPS\Request::i()->no_sev;
|
||||
$request->author()->save();
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->json( array() );
|
||||
}
|
||||
\IPS\Output::i()->redirect( $request->acpUrl() );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X208/6', 404, '' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Staff Lock
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function staffLock()
|
||||
{
|
||||
try
|
||||
{
|
||||
$request = Support\Request::loadAndCheckPerms( \IPS\Request::i()->id );
|
||||
$request->staff_lock = \IPS\Request::i()->lock;
|
||||
$request->save();
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->json( array( 'assign_to' => ( $request->staff_lock ? ( $request->staff ? $request->staff->member_id : 0 ) : 0 ) ) );
|
||||
}
|
||||
\IPS\Output::i()->redirect( $request->acpUrl() );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X208/7', 404, '' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Department
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function department()
|
||||
{
|
||||
try
|
||||
{
|
||||
$request = Support\Request::loadAndCheckPerms( \IPS\Request::i()->id );
|
||||
$new = Support\Department::load( \IPS\Request::i()->department );
|
||||
$request->log( 'department', $request->department, $new );
|
||||
$request->department = $new;
|
||||
$request->save();
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
{
|
||||
$stockActionOptions = array();
|
||||
$stockActions = array( 0 => '' );
|
||||
foreach ( \IPS\nexus\Support\StockAction::roots( NULL, NULL, "action_show_in='*' OR " . \IPS\Db::i()->findInSet( 'action_show_in', array( $request->department->id ) ) ) as $action )
|
||||
{
|
||||
$stockActions[ $action->id ] = $action->_title;
|
||||
}
|
||||
|
||||
\IPS\Output::i()->json( array( 'department' => \IPS\Request::i()->department, 'stockActions' => $stockActions, 'requiresPurchase' => (bool) $request->department->require_package ) );
|
||||
}
|
||||
\IPS\Output::i()->redirect( $request->acpUrl() );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X208/8', 404, '' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Staff
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function staff()
|
||||
{
|
||||
try
|
||||
{
|
||||
$request = Support\Request::loadAndCheckPerms( \IPS\Request::i()->id );
|
||||
$new = \IPS\Request::i()->staff ? \IPS\Member::load( \IPS\Request::i()->staff ) : NULL;
|
||||
$request->log( 'staff', $request->staff, $new );
|
||||
$request->staff = $new;
|
||||
$request->save();
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->json( array( 'assign_to' => ( $request->staff_lock ? ( $request->staff ? $request->staff->member_id : 0 ) : 0 ) ) );
|
||||
}
|
||||
\IPS\Output::i()->redirect( $request->acpUrl() );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X208/9', 404, '' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Track
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function track()
|
||||
{
|
||||
try
|
||||
{
|
||||
$request = Support\Request::loadAndCheckPerms( \IPS\Request::i()->id );
|
||||
|
||||
if ( \IPS\Request::i()->track )
|
||||
{
|
||||
\IPS\Db::i()->insert( 'nexus_support_tracker', array(
|
||||
'member_id' => \IPS\Member::loggedIn()->member_id,
|
||||
'request_id' => $request->id,
|
||||
'notify' => \IPS\Request::i()->notify
|
||||
), TRUE );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Db::i()->delete( 'nexus_support_tracker', array( 'member_id=? AND request_id=?', \IPS\Member::loggedIn()->member_id, $request->id ) );
|
||||
}
|
||||
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->json( array() );
|
||||
}
|
||||
\IPS\Output::i()->redirect( $request->acpUrl() );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X208/A', 404, '' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Associate
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function associate()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'purchases_view', 'nexus', 'customers' );
|
||||
|
||||
try
|
||||
{
|
||||
$request = Support\Request::loadAndCheckPerms( \IPS\Request::i()->id );
|
||||
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->class = 'ipsForm_vertical ipsForm_noLabels';
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'associated_purchase', $request->purchase, TRUE, array( 'class' => 'IPS\nexus\Purchase', 'forceOwner' => $request->author(), 'zeroVal' => 'none' ) ) );
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
$request->log( 'purchase', $request->purchase, $values['associated_purchase'] ?: NULL );
|
||||
$request->purchase = $values['associated_purchase'] ?: NULL;
|
||||
$request->save();
|
||||
\IPS\Output::i()->redirect( $request->acpUrl() );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->output = $form->customTemplate( array( call_user_func_array( array( \IPS\Theme::i(), 'getTemplate' ), array( 'forms', 'core', 'front' ) ), 'popupTemplate' ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X208/B', 404, '' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function merge()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'requests_merge' );
|
||||
|
||||
try
|
||||
{
|
||||
$request = Support\Request::loadAndCheckPerms( \IPS\Request::i()->id );
|
||||
$request->mergeIn( array( Support\Request::loadAndCheckPerms( \IPS\Request::i()->merge ) ) ) ;
|
||||
\IPS\Output::i()->redirect( $request->acpUrl() );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X208/C', 404, '' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function delete()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'requests_delete' );
|
||||
|
||||
try
|
||||
{
|
||||
$request = Support\Request::loadAndCheckPerms( \IPS\Request::i()->id );
|
||||
$request->delete();
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=nexus&module=support&controller=requests" ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X208/D', 404, '' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete Reply
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function deleteReply()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'requests_reply_delete' );
|
||||
|
||||
try
|
||||
{
|
||||
$reply = Support\Reply::loadAndCheckPerms( \IPS\Request::i()->id );
|
||||
$reply->delete();
|
||||
\IPS\Output::i()->redirect( $reply->item()->acpUrl() );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X208/G', 404, '' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* View Feedback
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function feedback()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'requests_ratings_feedback' );
|
||||
|
||||
try
|
||||
{
|
||||
$reply = \IPS\nexus\Support\Reply::loadAndCheckPerms( \IPS\Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X208/E', 404, '' );
|
||||
}
|
||||
|
||||
$rating = NULL;
|
||||
try
|
||||
{
|
||||
$rating = \IPS\Db::i()->select( '*', 'nexus_support_ratings', array( 'rating_reply=?', $reply->id ) )->first();
|
||||
}
|
||||
catch ( \UnderflowException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X208/F', 404, '' );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'support' )->feedback( $rating );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,588 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Support Requests
|
||||
* @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 Apr 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\admin\support;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Support Requests
|
||||
*/
|
||||
class _requests extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'support.css', 'nexus', 'admin' ) );
|
||||
|
||||
if ( \IPS\Theme::i()->settings['responsive'] )
|
||||
{
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'support_responsive.css', 'nexus', 'admin' ) );
|
||||
}
|
||||
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'requests_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
/* Can we access anything? */
|
||||
if ( !count( \IPS\nexus\Support\Department::departmentsWithPermission() ) )
|
||||
{
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'support', 'departments_manage' ) )
|
||||
{
|
||||
\IPS\Output::i()->error( 'err_no_departments_with_perm1', '1X261/1', 403, '' );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->error( 'err_no_departments_with_perm2', '1X261/2', 403, '' );
|
||||
}
|
||||
}
|
||||
|
||||
/* URL */
|
||||
$url = \IPS\Http\Url::internal( 'app=nexus&module=support&controller=requests' );
|
||||
$customer = NULL;
|
||||
$where = array();
|
||||
if ( isset( \IPS\Request::i()->member ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$customer = \IPS\nexus\Customer::load( \IPS\Request::i()->member );
|
||||
$url = $url->setQueryString( 'member', $customer->member_id );
|
||||
$where[] = array( 'r_member=?', $customer->member_id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e ) { }
|
||||
}
|
||||
|
||||
/* Permissions */
|
||||
$where[] = array( "( dpt_staff='*' OR " . \IPS\Db::i()->findInSet( 'dpt_staff', \IPS\nexus\Support\Department::staffDepartmentPerms() ) . ')' );
|
||||
|
||||
/* Filters */
|
||||
if ( isset( \IPS\Request::i()->assigned ) )
|
||||
{
|
||||
$where[] = array( 'r_staff=?', \IPS\Member::loggedIn()->member_id );
|
||||
}
|
||||
if ( isset( \IPS\Request::i()->tracked ) )
|
||||
{
|
||||
$where[] = array( 'request_id IS NOT NULL' );
|
||||
}
|
||||
if ( isset( \IPS\Request::i()->replied ) )
|
||||
{
|
||||
$where[] = array( 'r_id IN(?)', \IPS\Db::i()->select( 'DISTINCT(reply_request)', 'nexus_support_replies', array( 'reply_member=?', \IPS\Member::loggedIn()->member_id ) ) );
|
||||
}
|
||||
|
||||
/* Departments / Statuses */
|
||||
$myFilters = \IPS\nexus\Support\Request::myFilters();
|
||||
if ( isset( \IPS\Request::i()->departments ) or isset( \IPS\Request::i()->statuses ) )
|
||||
{
|
||||
$newFilters = array( 'departments' => isset( \IPS\Request::i()->departments ) ? explode( ',', \IPS\Request::i()->departments ) : $myFilters['departments'], 'statuses' => isset( \IPS\Request::i()->statuses ) ? explode( ',', \IPS\Request::i()->statuses ) : $myFilters['statuses'] );
|
||||
\IPS\Request::i()->setCookie( 'support_filters', json_encode( $newFilters ), \IPS\DateTime::create()->add( new \DateInterval( 'P1Y' ) ) );
|
||||
$myFilters = \IPS\nexus\Support\Request::myFilters( $newFilters );
|
||||
}
|
||||
$where[] = $myFilters['whereClause'];
|
||||
|
||||
/* Create the table */
|
||||
$table = \IPS\nexus\Support\Request::table( $url, $where );
|
||||
$table->classes[] = 'cNexusSupportTable';
|
||||
$table->tableTemplate = array( \IPS\Theme::i()->getTemplate( 'support', 'nexus', 'admin' ), 'requestTable' );
|
||||
$table->rowsTemplate = array( \IPS\Theme::i()->getTemplate( 'support', 'nexus', 'admin' ), 'requestRows' );
|
||||
|
||||
/* Search */
|
||||
$table->quickSearch = 'r_title';
|
||||
$table->advancedSearch = array(
|
||||
'r_title_or_message'=> array( \IPS\Helpers\Table\SEARCH_CUSTOM, array(
|
||||
'getHtml' => function( $field )
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate( 'forms', 'core', 'global' )->text( $field->name, 'text', $field->value, $field->required );
|
||||
}
|
||||
), function( $v )
|
||||
{
|
||||
return array( 'r_title LIKE ? OR ' . \IPS\Db::i()->in( 'r_id', \IPS\Db::i()->select( 'reply_request', 'nexus_support_replies', array( "MATCH(reply_post) AGAINST (? IN BOOLEAN MODE)", $v ) ) ), '%' . $v . '%' );
|
||||
} ),
|
||||
'r_severity' => array( \IPS\Helpers\Table\SEARCH_NODE, array( 'class' => 'IPS\nexus\Support\Severity', 'multiple' => TRUE ) ),
|
||||
'r_department' => array( \IPS\Helpers\Table\SEARCH_NODE, array( 'class' => 'IPS\nexus\Support\Department', 'multiple' => TRUE ) ),
|
||||
'r_member' => \IPS\Helpers\Table\SEARCH_MEMBER,
|
||||
'r_email' => \IPS\Helpers\Table\SEARCH_CONTAINS_TEXT,
|
||||
'r_replies' => \IPS\Helpers\Table\SEARCH_NUMERIC,
|
||||
'r_started' => \IPS\Helpers\Table\SEARCH_DATE_RANGE,
|
||||
'r_last_new_reply' => \IPS\Helpers\Table\SEARCH_DATE_RANGE,
|
||||
'r_last_reply' => \IPS\Helpers\Table\SEARCH_DATE_RANGE,
|
||||
'r_last_reply_by' => \IPS\Helpers\Table\SEARCH_MEMBER,
|
||||
'r_last_staff_reply'=> \IPS\Helpers\Table\SEARCH_DATE_RANGE,
|
||||
'r_status' => array( \IPS\Helpers\Table\SEARCH_NODE, array( 'class' => 'IPS\nexus\Support\Status', 'multiple' => TRUE ) ),
|
||||
'r_staff' => array( \IPS\Helpers\Table\SEARCH_SELECT, array( 'options' => \IPS\nexus\Support\Request::staff(), 'multiple' => TRUE, 'noDefault' => TRUE ) ),
|
||||
);
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->title = $customer ? \IPS\Member::loggedIn()->language()->addToStack( 'members_support_requests', FALSE, array( 'sprintf' => array( $customer->cm_name ) ) ) : \IPS\Member::loggedIn()->language()->addToStack('menu__nexus_support_requests');
|
||||
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'global', 'core' )->block( 'title', (string) $table );
|
||||
|
||||
/* Create Button */
|
||||
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'support', 'requests_create' ) )
|
||||
{
|
||||
$createUrl = \IPS\Http\Url::internal('app=nexus&module=support&controller=requests&do=create&_new=1');
|
||||
if ( $customer )
|
||||
{
|
||||
$createUrl = $createUrl->setQueryString( 'member', $customer->member_id );
|
||||
}
|
||||
\IPS\Output::i()->sidebar['actions']['create'] = array(
|
||||
'icon' => 'plus',
|
||||
'title' => 'add',
|
||||
'link' => $createUrl,
|
||||
);
|
||||
}
|
||||
|
||||
/* Settings */
|
||||
\IPS\Output::i()->sidebar['actions']['notifications'] = array(
|
||||
'icon' => 'envelope',
|
||||
'title' => 'my_notifications',
|
||||
'link' => \IPS\Http\Url::internal('app=nexus&module=support&controller=requests&do=notifications'),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('my_notifications') )
|
||||
);
|
||||
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'support', 'support_display_settings' ) )
|
||||
{
|
||||
\IPS\Output::i()->sidebar['actions']['settings'] = array(
|
||||
'icon' => 'cog',
|
||||
'title' => 'display_settings',
|
||||
'link' => \IPS\Http\Url::internal('app=nexus&module=support&controller=requests&do=settings'),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('display_settings') )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset my departments
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function resetMyDepartments()
|
||||
{
|
||||
\IPS\Request::i()->setCookie( 'support_filters', '', \IPS\DateTime::create()->sub( new \DateInterval( 'P1D' ) ) );
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=support&controller=requests') );
|
||||
}
|
||||
|
||||
/**
|
||||
* My Notifications
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function notifications()
|
||||
{
|
||||
$types = array( 'support_notify_new' => 'n', 'support_notify_replies' => 'r', 'support_notify_assign' => 'a' );
|
||||
|
||||
$existing = iterator_to_array( \IPS\Db::i()->select( '*', 'nexus_support_notify', array( 'staff_id=?', \IPS\Member::loggedIn()->member_id ) )->setKeyField('type')->setValueField('departments') );
|
||||
|
||||
$myDepartments = array();
|
||||
foreach ( \IPS\nexus\Support\Department::roots( NULL, NULL, array( "dpt_staff='*' OR " . \IPS\Db::i()->findInSet( 'dpt_staff', \IPS\nexus\Support\Department::staffDepartmentPerms() ) ) ) as $dpt )
|
||||
{
|
||||
$myDepartments[ $dpt->id ] = $dpt->_title;
|
||||
}
|
||||
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->addMessage( 'support_notify_blurb' );
|
||||
$form->addHeader('notify_me_when');
|
||||
foreach ( $types as $k => $t )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\Select( $k, isset( $existing[ $t ] ) ? ( $existing[ $t ] === '*' ? 0 : explode( ',', $existing[ $t ] ) ) : NULL, FALSE, array( 'options' => $myDepartments, 'multiple' => TRUE, 'unlimited' => 0, 'unlimitedLang' => 'all' ) ) );
|
||||
}
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
\IPS\Db::i()->delete( 'nexus_support_notify', array( 'staff_id=?', \IPS\Member::loggedIn()->member_id ) );
|
||||
|
||||
foreach ( $types as $k => $t )
|
||||
{
|
||||
if ( $values[ $k ] === 0 or count( $values[ $k ] ) )
|
||||
{
|
||||
\IPS\Db::i()->insert( 'nexus_support_notify', array(
|
||||
'staff_id' => \IPS\Member::loggedIn()->member_id,
|
||||
'type' => $t,
|
||||
'departments' => ( $values[ $k ] === 0 ) ? '*' : implode( ',', $values[ $k ] )
|
||||
) );
|
||||
}
|
||||
}
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal("app=nexus&module=support&controller=requests") );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('my_notifications');
|
||||
\IPS\Output::i()->output = $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display Settings
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function settings()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'support_display_settings' );
|
||||
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->add( new \IPS\Helpers\Form\Custom( 'support_old_highlight', array( \IPS\Settings::i()->support_old_stat, \IPS\Settings::i()->support_old_number ), FALSE, array(
|
||||
'getHtml' => function( $obj )
|
||||
{
|
||||
$number = \IPS\Settings::i()->support_old_number;
|
||||
$numberType = $number ? 'minutes' : 'hours';
|
||||
if ( $number % 1440 === 0 )
|
||||
{
|
||||
$number /= 1440; # Fun fact: that's the first time I've used that operator
|
||||
$numberType = 'days';
|
||||
}
|
||||
elseif ( $number % 60 === 0 )
|
||||
{
|
||||
$number /= 60; # Fun fact: that's the second time I've used that operator
|
||||
$numberType = 'hours';
|
||||
}
|
||||
|
||||
return \IPS\Theme::i()->getTemplate('support')->highlightSetting( $obj->name, $obj->value[0], $number, $numberType );
|
||||
}
|
||||
) ) );
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
$save = array();
|
||||
if ( isset( $values['support_old_highlight'][3] ) )
|
||||
{
|
||||
$save['support_old_number'] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
$save['support_old_stat'] = $values['support_old_highlight'][0];
|
||||
switch ( $values['support_old_highlight'][2] )
|
||||
{
|
||||
case 'minutes':
|
||||
$save['support_old_number'] = $values['support_old_highlight'][1];
|
||||
break;
|
||||
case 'hours':
|
||||
$save['support_old_number'] = $values['support_old_highlight'][1] * 60;
|
||||
break;
|
||||
case 'days':
|
||||
$save['support_old_number'] = $values['support_old_highlight'][1] * 1440;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$form->saveAsSettings( $save );
|
||||
\IPS\Session::i()->log( 'acplogs__support_display_settings' );
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=nexus&module=support&controller=requests' ), 'saved' );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->output = $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function create()
|
||||
{
|
||||
/* Init */
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'requests_create' );
|
||||
$steps = array();
|
||||
|
||||
/* Owner */
|
||||
$steps['request_owner'] = function( $data )
|
||||
{
|
||||
$form = new \IPS\Helpers\Form( 'owner', 'continue' );
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'request_owner_type', 'member', TRUE, array(
|
||||
'options' => array( 'member' => 'request_owner_member', 'email' => 'request_owner_email' ),
|
||||
'toggles' => array( 'member' => array( 'request_owner_member' ), 'email' => array( 'request_owner_email' ) )
|
||||
) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Member( 'request_owner_member', isset( \IPS\Request::i()->member ) ? \IPS\Member::load( \IPS\Request::i()->member ) : NULL, FALSE, array(), NULL, NULL, NULL, 'request_owner_member' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Email( 'request_owner_email', NULL, FALSE, array(), NULL, NULL, NULL, 'request_owner_email' ) );
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
if ( $values['request_owner_type'] === 'member' )
|
||||
{
|
||||
if ( !$values['request_owner_member'] )
|
||||
{
|
||||
$form->error = \IPS\Member::loggedIn()->language()->addToStack('request_owner_req');
|
||||
return (string) $form;
|
||||
}
|
||||
$data['member'] = $values['request_owner_member']->member_id;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( !$values['request_owner_email'] )
|
||||
{
|
||||
$form->error = \IPS\Member::loggedIn()->language()->addToStack('request_owner_req');
|
||||
return (string) $form;
|
||||
}
|
||||
|
||||
$member = \IPS\Member::load( $values['request_owner_email'], 'email' );
|
||||
if ( $member->member_id )
|
||||
{
|
||||
$data['member'] = $member->member_id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$data['email'] = $values['request_owner_email'];
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
return (string) $form;
|
||||
};
|
||||
|
||||
/* Stock Actions */
|
||||
$stockActions = \IPS\nexus\Support\StockAction::roots();
|
||||
if ( count( $stockActions ) )
|
||||
{
|
||||
$steps['stock_action'] = function( $data ) use ( $stockActions )
|
||||
{
|
||||
$options = array( 0 => 'none' );
|
||||
foreach ( $stockActions as $action )
|
||||
{
|
||||
$options[ $action->id ] = $action->_title;
|
||||
}
|
||||
|
||||
$form = new \IPS\Helpers\Form( 'stock_action', 'continue' );
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'stock_action', 0, FALSE, array(
|
||||
'options' => $options
|
||||
) ) );
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
$data['stock_action'] = $values['stock_action'];
|
||||
return $data;
|
||||
}
|
||||
|
||||
return (string) $form;
|
||||
};
|
||||
}
|
||||
|
||||
/* Request Details */
|
||||
$steps['request_details'] = function( $data ) use ( $stockActions )
|
||||
{
|
||||
$stockAction = NULL;
|
||||
if ( isset( $data['stock_action'] ) and isset( $stockActions[ $data['stock_action'] ] ) )
|
||||
{
|
||||
$stockAction = $stockActions[ $data['stock_action'] ];
|
||||
}
|
||||
|
||||
$form = new \IPS\Helpers\Form( 'request_details', 'continue' );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'support_title', NULL, TRUE ) );
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'support_department', $stockAction ? $stockAction->department : NULL, TRUE, array( 'class' => 'IPS\nexus\Support\Department' ) ) );
|
||||
if ( isset( $data['member'] ) )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'support_purchase', 0, FALSE, array( 'class' => 'IPS\nexus\Purchase', 'forceOwner' => \IPS\Member::load( $data['member'] ), 'zeroVal' => 'none' ) ) );
|
||||
}
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'r_status', $stockAction ? $stockAction->status : \IPS\nexus\Support\Status::load( TRUE, 'status_default_staff' ), TRUE, array( 'class' => 'IPS\nexus\Support\Status' ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'support_severity', \IPS\nexus\Support\Severity::load( TRUE, 'sev_default' ), TRUE, array( 'class' => 'IPS\nexus\Support\Severity' ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Select( 'r_staff', 0, FALSE, array( 'options' => array_merge( array( 0 => '' ), \IPS\nexus\Support\Request::staff() ) ) ) );
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
$data['title'] = $values['support_title'];
|
||||
$data['department'] = $values['support_department']->id;
|
||||
if ( isset( $values['support_purchase'] ) and $values['support_purchase'] )
|
||||
{
|
||||
$data['purchase'] = $values['support_purchase']->id;
|
||||
}
|
||||
$data['status'] = $values['r_status']->id;
|
||||
$data['severity'] = $values['support_severity']->id;
|
||||
$data['staff'] = $values['r_staff'];
|
||||
return $data;
|
||||
}
|
||||
return (string) $form;
|
||||
};
|
||||
|
||||
/* Custom Fields */
|
||||
$customFields = \IPS\nexus\Support\CustomField::roots();
|
||||
if ( count( $customFields ) )
|
||||
{
|
||||
$steps['custom_support_fields'] = function( $data )
|
||||
{
|
||||
$customFields = \IPS\nexus\Support\CustomField::roots( NULL, NULL, array( "sf_departments='*' OR " . \IPS\Db::i()->findInSet( 'sf_departments', array( $data['department'] ) ) ) );
|
||||
if ( count( $customFields ) )
|
||||
{
|
||||
$form = new \IPS\Helpers\Form( 'custom_fields', 'continue' );
|
||||
foreach ( $customFields as $field )
|
||||
{
|
||||
$form->add( $field->buildHelper() );
|
||||
}
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
$data['custom_fields'] = $values;
|
||||
return $data;
|
||||
}
|
||||
return (string) $form;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/* Your Message */
|
||||
$steps['your_message'] = function( $data ) use ( $stockActions )
|
||||
{
|
||||
$stockAction = NULL;
|
||||
if ( isset( $data['stock_action'] ) and isset( $stockActions[ $data['stock_action'] ] ) )
|
||||
{
|
||||
$stockAction = $stockActions[ $data['stock_action'] ];
|
||||
}
|
||||
|
||||
$form = new \IPS\Helpers\Form( 'your_message' );
|
||||
$form->add( new \IPS\Helpers\Form\Email( 'to', isset( $data['member'] ) ? \IPS\Member::load( $data['member'] )->email : $data['email'] ) );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'cc', array(), FALSE, array( 'autocomplete' => array( 'unique' => TRUE, 'forceLower' => TRUE ) ), array( 'IPS\nexus\Support\Request', '_validateEmail' ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'bcc', array(), FALSE, array( 'autocomplete' => array( 'unique' => TRUE, 'forceLower' => TRUE ) ), array( 'IPS\nexus\Support\Request', '_validateEmail' ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Editor( 'message', $stockAction ? $stockAction->message : NULL, TRUE, array( 'app' => 'nexus', 'key' => 'Support', 'autoSaveKey' => md5( "new-req-message" ) ) ) );
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
$request = new \IPS\nexus\Support\Request;
|
||||
$request->started = time();
|
||||
$request->title = $data['title'];
|
||||
if ( isset( $data['member'] ) )
|
||||
{
|
||||
$request->member = $data['member'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$request->email = $data['email'];
|
||||
}
|
||||
$request->department = \IPS\nexus\Support\Department::load( $data['department'] );
|
||||
if ( isset( $data['purchase'] ) and $data['purchase'] )
|
||||
{
|
||||
$request->purchase = \IPS\nexus\Purchase::load( $data['purchase'] );
|
||||
}
|
||||
$request->status = \IPS\nexus\Support\Status::load( $data['status'] );
|
||||
$request->severity = \IPS\nexus\Support\Severity::load( $data['severity'] );
|
||||
if ( isset( $data['staff'] ) and $data['staff'] )
|
||||
{
|
||||
$request->staff = \IPS\Member::load( $data['staff'] );
|
||||
}
|
||||
if ( isset( $data['custom_fields'] ) )
|
||||
{
|
||||
$cfields = array();
|
||||
foreach ( $data['custom_fields'] as $k => $v )
|
||||
{
|
||||
$cfields[ mb_substr( $k, 13 ) ] = $v;
|
||||
}
|
||||
$request->cfields = $cfields;
|
||||
}
|
||||
|
||||
$notify = $request->notify;
|
||||
foreach ( $values['cc'] as $cc )
|
||||
{
|
||||
foreach ( $notify as $n )
|
||||
{
|
||||
if ( $n['value'] === $cc )
|
||||
{
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
$notify[] = array( 'type' => 'e', 'value' => $cc );
|
||||
}
|
||||
foreach ( $values['bcc'] as $cc )
|
||||
{
|
||||
foreach ( $notify as $k => $n )
|
||||
{
|
||||
if ( $n['value'] === $cc )
|
||||
{
|
||||
if ( $n['bcc'] )
|
||||
{
|
||||
unset( $notify[ $k ]['bcc'] );
|
||||
}
|
||||
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
$notify[] = array( 'type' => 'e', 'value' => $cc, 'bcc' => 1 );
|
||||
}
|
||||
$request->notify = $notify;
|
||||
$request->last_reply = time();
|
||||
$request->last_new_reply = time();
|
||||
$request->last_staff_reply = time();
|
||||
$request->last_reply_by = \IPS\Member::loggedIn()->member_id;
|
||||
$request->replies = 1;
|
||||
$request->save();
|
||||
|
||||
$reply = new \IPS\nexus\Support\Reply;
|
||||
$reply->request = $request->id;
|
||||
$reply->member = \IPS\Member::loggedIn()->member_id;
|
||||
$reply->type = $reply::REPLY_STAFF;
|
||||
$reply->post = $values['message'];
|
||||
$reply->date = time();
|
||||
$reply->cc = implode( ',', $values['cc'] );
|
||||
$reply->ip_address = \IPS\Request::i()->ipAddress();
|
||||
$reply->bcc = implode( ',', $values['bcc'] );
|
||||
$reply->save();
|
||||
|
||||
$request->processAfterCreate( $reply, $data );
|
||||
$reply->sendCustomerNotifications( $values['to'], $values['cc'], $values['bcc'] );
|
||||
$reply->sendNotifications();
|
||||
|
||||
$url = NULL;
|
||||
if ( isset( $data['ref'] ) and isset( $data['transaction'] ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$transaction = \IPS\nexus\Transaction::load( $data['transaction'] );
|
||||
$extra = $transaction->extra;
|
||||
$extra['sr'] = $transaction->id;
|
||||
$transaction->extra = $extra;
|
||||
$transaction->save();
|
||||
|
||||
switch ( $data['ref'] )
|
||||
{
|
||||
case 'v':
|
||||
\IPS\Output::i()->redirect( $transaction->acpUrl() );
|
||||
break;
|
||||
|
||||
case 'i':
|
||||
\IPS\Output::i()->redirect( $transaction->invoice->acpUrl() );
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
\IPS\Output::i()->redirect( $transaction->member->acpUrl() );
|
||||
break;
|
||||
|
||||
case 't':
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=payments&controller=transactions') );
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch ( \OutOfRangeException $e ) { }
|
||||
}
|
||||
if ( !$url )
|
||||
{
|
||||
$url = $request->canView() ? $request->acpUrl() : \IPS\Http\Url::internal('app=nexus&module=support&controller=requests');
|
||||
}
|
||||
\IPS\Output::i()->redirect( $url, 'request_created' );
|
||||
}
|
||||
|
||||
return $form;
|
||||
};
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('create_support_request');
|
||||
\IPS\Output::i()->output = new \IPS\Helpers\Wizard( $steps, \IPS\Http\Url::internal('app=nexus&module=support&controller=requests&do=create') );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Support Settings
|
||||
* @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 Apr 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\admin\support;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Payment Settings
|
||||
*/
|
||||
class _settings extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* Call
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __call( $method, $args )
|
||||
{
|
||||
$tabs = array();
|
||||
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'support', 'departments_manage' ) )
|
||||
{
|
||||
$tabs['departments'] = 'departments';
|
||||
}
|
||||
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'support', 'stockactions_manage' ) )
|
||||
{
|
||||
$tabs['stockactions'] = 'stock_actions';
|
||||
}
|
||||
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'support', 'scfields_manage' ) )
|
||||
{
|
||||
$tabs['fields'] = 'custom_support_fields';
|
||||
}
|
||||
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'support', 'severities_manage' ) )
|
||||
{
|
||||
$tabs['severities'] = 'severities';
|
||||
}
|
||||
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'support', 'statuses_manage' ) )
|
||||
{
|
||||
$tabs['statuses'] = 'statuses';
|
||||
}
|
||||
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'support', 'autoresolve_manage' ) )
|
||||
{
|
||||
$tabs['autoresolve'] = 'autoresolve';
|
||||
}
|
||||
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'support', 'customerfeedback_manage' ) )
|
||||
{
|
||||
$tabs['customerfeedback'] = 'customer_feedback';
|
||||
}
|
||||
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'support', 'outgoingemail_manage' ) )
|
||||
{
|
||||
$tabs['outgoingemail'] = 'outgoing_emails';
|
||||
}
|
||||
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'support', 'incomingemail_manage' ) )
|
||||
{
|
||||
$tabs['incomingemail'] = 'incoming_emails';
|
||||
}
|
||||
|
||||
if ( isset( \IPS\Request::i()->tab ) and isset( $tabs[ \IPS\Request::i()->tab ] ) )
|
||||
{
|
||||
$activeTab = \IPS\Request::i()->tab;
|
||||
}
|
||||
else
|
||||
{
|
||||
$_tabs = array_keys( $tabs ) ;
|
||||
$activeTab = array_shift( $_tabs );
|
||||
}
|
||||
|
||||
$classname = 'IPS\nexus\modules\admin\support\\' . $activeTab;
|
||||
$class = new $classname;
|
||||
$class->url = \IPS\Http\Url::internal("app=nexus&module=support&controller=settings&tab={$activeTab}");
|
||||
$class->execute();
|
||||
|
||||
if ( $method === 'manage' and \IPS\Member::loggedIn()->language()->checkKeyExists( $tabs[ $activeTab ] . '_blurb' ) )
|
||||
{
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'forms', 'core' )->blurb( $tabs[ $activeTab ] . '_blurb', TRUE, TRUE ) . \IPS\Output::i()->output;
|
||||
}
|
||||
|
||||
if ( $method !== 'manage' or \IPS\Request::i()->isAjax() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('support_settings');
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->tabs( $tabs, $activeTab, \IPS\Output::i()->output, \IPS\Http\Url::internal( "app=nexus&module=support&controller=settings" ) );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief severities
|
||||
* @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
|
||||
* @since 09 Apr 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\admin\support;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* severities
|
||||
*/
|
||||
class _severities extends \IPS\Node\Controller
|
||||
{
|
||||
/**
|
||||
* Node Class
|
||||
*/
|
||||
protected $nodeClass = 'IPS\nexus\Support\Severity';
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'severities_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
parent::manage();
|
||||
|
||||
if ( isset( \IPS\Request::i()->nexus_severities ) )
|
||||
{
|
||||
\IPS\Db::i()->update( 'core_sys_conf_settings', array( 'conf_value' => \IPS\Request::i()->nexus_severities ), array( 'conf_key=?', 'nexus_severities' ) );
|
||||
\IPS\Settings::i()->nexus_severities = \IPS\Request::i()->nexus_severities;
|
||||
unset( \IPS\Data\Store::i()->settings );
|
||||
\IPS\Session::i()->log( 'acplogs__severity_settings' );
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=support&controller=settings&tab=severities') );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('support')->severities( \IPS\Output::i()->output );
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function delete()
|
||||
{
|
||||
try
|
||||
{
|
||||
$node = \IPS\nexus\Support\Severity::load( \IPS\Request::i()->id );
|
||||
if ( $node->default )
|
||||
{
|
||||
\IPS\Output::i()->error( 'cannot_delete_default_severity', '1X211/1', 403, '' );
|
||||
}
|
||||
|
||||
if ( $node->canDelete() )
|
||||
{
|
||||
if ( \IPS\Db::i()->select( 'COUNT(*)', 'nexus_support_requests', array( 'r_severity=?', $node->id ) ) )
|
||||
{
|
||||
$form = new \IPS\Helpers\Form( 'delete', 'delete' );
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'set_existing_requests_to', NULL, TRUE, array( 'class' => 'IPS\nexus\Support\Severity', 'permissionCheck' => function( $_node ) use ( $node )
|
||||
{
|
||||
return $node->id != $_node->id;
|
||||
} ) ) );
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
/* Update */
|
||||
\IPS\Db::i()->update( 'nexus_support_requests', array( 'r_severity' => $values['set_existing_requests_to']->id ), array( 'r_severity=?', $node->id ) );
|
||||
|
||||
/* Delete it */
|
||||
\IPS\Session::i()->log( 'acplog__node_deleted', array( $this->title => TRUE, $node->_logKey => TRUE ) );
|
||||
$node->delete();
|
||||
|
||||
/* Clear out member's cached "Create Menu" contents */
|
||||
\IPS\Member::clearCreateMenu();
|
||||
|
||||
/* Boink */
|
||||
if( \IPS\Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->json( "OK" );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->redirect( $this->url->setQueryString( array( 'root' => ( $node->parent() ? $node->parent()->_id : '' ) ) ), 'deleted' );
|
||||
}
|
||||
}
|
||||
|
||||
\IPS\Output::i()->output = $form;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
return parent::delete();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return parent::delete();
|
||||
}
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
return parent::delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Support Statuses
|
||||
* @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 Apr 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\admin\support;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Support Departments
|
||||
*/
|
||||
class _statuses extends \IPS\Node\Controller
|
||||
{
|
||||
/**
|
||||
* Node Class
|
||||
*/
|
||||
protected $nodeClass = 'IPS\nexus\Support\Status';
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'statuses_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function delete()
|
||||
{
|
||||
try
|
||||
{
|
||||
$node = \IPS\nexus\Support\Status::load( \IPS\Request::i()->id );
|
||||
if ( $node->default_staff or $node->default_member )
|
||||
{
|
||||
\IPS\Output::i()->error( 'cannot_delete_default_status', '1X210/1', 403, '' );
|
||||
}
|
||||
|
||||
if ( $node->canDelete() and \IPS\Db::i()->select( 'COUNT(*)', 'nexus_support_requests', array( 'r_status=?', $node->id ) )->first() )
|
||||
{
|
||||
$form = new \IPS\Helpers\Form( 'delete', 'delete' );
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'set_existing_requests_to', NULL, TRUE, array( 'class' => 'IPS\nexus\Support\Status', 'permissionCheck' => function( $_node ) use ( $node )
|
||||
{
|
||||
return $node->id != $_node->id;
|
||||
} ) ) );
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
\IPS\Db::i()->update( 'nexus_support_requests', array( 'r_status' => $values['set_existing_requests_to']->id ), array( 'r_status=?', $node->id ) );
|
||||
return parent::delete();
|
||||
}
|
||||
|
||||
\IPS\Output::i()->output = $form;
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch ( \OutOfRangeException $e ){}
|
||||
|
||||
return parent::delete();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief stockactions
|
||||
* @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
|
||||
* @since 15 Apr 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\admin\support;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* stockactions
|
||||
*/
|
||||
class _stockactions extends \IPS\Node\Controller
|
||||
{
|
||||
/**
|
||||
* Node Class
|
||||
*/
|
||||
protected $nodeClass = 'IPS\nexus\Support\StockAction';
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'stockactions_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief New Support Request Volumme
|
||||
* @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 25 Apr 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\admin\support;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* volume
|
||||
*/
|
||||
class _volume extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'volume_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* View
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
$chart = new \IPS\Helpers\Chart\Dynamic( \IPS\Http\Url::internal( 'app=nexus&module=support&controller=volume' ), 'nexus_support_requests', 'r_started', '',
|
||||
array(
|
||||
'vAxis' => array( 'title' => \IPS\Member::loggedIn()->language()->addToStack('support_requests_created') ),
|
||||
),
|
||||
'LineChart'
|
||||
);
|
||||
$chart->groupBy = 'r_department';
|
||||
foreach( \IPS\nexus\Support\Department::roots() as $department )
|
||||
{
|
||||
$chart->addSeries( $department->_title, 'number', 'COUNT(*)', TRUE, $department->id );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->output = (string) $chart;
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__nexus_support_volume');
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user