Version 4.5.0

This commit is contained in:
Neo committed 2025-12-19 05:51:58 -08:00
1 parent 1a0c7fd3c2
commit f79dcf067a
3791 files changed
+248032 -76372

No files matched your search

@@ -12,7 +12,7 @@
namespace IPS\nexus\modules\admin\support;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -23,6 +23,11 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
*/
class _requests extends \IPS\Dispatcher\Controller
{
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
/**
* Execute
*
@@ -51,7 +56,7 @@ class _requests extends \IPS\Dispatcher\Controller
protected function manage()
{
/* Can we access anything? */
if ( !count( \IPS\nexus\Support\Department::departmentsWithPermission() ) )
if ( !\count( \IPS\nexus\Support\Department::departmentsWithPermission() ) )
{
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'support', 'departments_manage' ) )
{
@@ -62,55 +67,83 @@ class _requests extends \IPS\Dispatcher\Controller
\IPS\Output::i()->error( 'err_no_departments_with_perm2', '1X261/2', 403, '' );
}
}
/* Permissions */
$where = array();
$where[] = array( "( dpt_staff='*' OR " . \IPS\Db::i()->findInSet( 'dpt_staff', \IPS\nexus\Support\Department::staffDepartmentPerms() ) . ')' );
/* Get my stream */
$stream = NULL;
if ( isset( \IPS\Request::i()->cookie['support_stream'] ) or isset( \IPS\Request::i()->stream ) or isset( \IPS\Request::i()->member ) )
/* Get stream - can set new... */
if ( ( isset( \IPS\Request::i()->stream ) and \IPS\Request::i()->stream !== 'custom' ) or isset( \IPS\Request::i()->member ) or isset( \IPS\Request::i()->email ) )
{
if ( isset( \IPS\Request::i()->member ) )
\IPS\Session::i()->csrfCheck();
/* Specific stream */
if ( isset( \IPS\Request::i()->stream ) )
{
try
{
$customer = \IPS\nexus\Customer::load( \IPS\Request::i()->member );
$stream = \IPS\nexus\Support\Stream::customer( $customer );
$stream->temporary = TRUE;
$stream->owner = \IPS\Member::loggedIn()->member_id;
$stream->save();
\IPS\Request::i()->setCookie( 'support_stream', $stream->id, \IPS\DateTime::create()->add( new \DateInterval( 'P1Y') ), FALSE );
\IPS\Db::i()->delete( 'nexus_support_streams', array( 'stream_owner=? AND stream_temporary=1 AND stream_id<>?', \IPS\Member::loggedIn()->member_id, $stream->id ) );
$stream = \IPS\nexus\Support\Stream::load( \IPS\Request::i()->stream );
}
catch ( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'node_error', '2X261/4', 404, '' );
}
}
/* Temporary stream */
else
{
$streamId = isset( \IPS\Request::i()->stream ) ? \IPS\Request::i()->stream : \IPS\Request::i()->cookie['support_stream'];
try
if( isset( \IPS\Request::i()->member ) )
{
$stream = \IPS\nexus\Support\Stream::load( $streamId );
if ( isset( \IPS\Request::i()->stream ) )
{
\IPS\Request::i()->setCookie( 'support_stream', $streamId, \IPS\DateTime::create()->add( new \DateInterval( 'P1Y') ), FALSE );
\IPS\Db::i()->delete( 'nexus_support_streams', array( 'stream_owner=? AND stream_temporary=1 AND stream_id<>?', \IPS\Member::loggedIn()->member_id, $streamId ) );
}
$customer = \IPS\nexus\Customer::load( \IPS\Request::i()->member );
}
catch ( \OutOfRangeException $e ) { }
else
{
$customer = \IPS\nexus\Customer::constructFromData( array( 'email' => \IPS\Request::i()->email ) );
}
$stream = \IPS\nexus\Support\Stream::customer( $customer );
$stream->temporary = TRUE;
$stream->owner = \IPS\Member::loggedIn()->member_id;
$stream->save();
}
/* Set the cookie */
\IPS\Request::i()->setCookie( 'support_stream', $stream->id, \IPS\DateTime::create()->add( new \DateInterval( 'P1Y') ), FALSE );
/* Delete previously stored temporary streams */
$where = array(
array( 'stream_owner=?', \IPS\Member::loggedIn()->member_id ),
array( 'stream_temporary=?', 1 )
);
if ( !\in_array( $stream->id, array( 'open', 'assigned', 'tracked' ) ) )
{
$where[] = array( 'stream_id<>?', $stream->id );
}
\IPS\Db::i()->delete( 'nexus_support_streams', $where );
/* If this isn't an AJAX request, redirect to it to stop the CSRF key hanging around in the address bar */
if ( !\IPS\Request::i()->isAjax() )
{
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=support&controller=requests' ) );
}
}
$stream = $stream ?: \IPS\nexus\Support\Stream::load('open');
/* ... or use preferred stream */
elseif ( isset( \IPS\Request::i()->cookie['support_stream'] ) )
{
try
{
$stream = \IPS\nexus\Support\Stream::load( \IPS\Request::i()->cookie['support_stream'] );
}
catch ( \OutOfRangeException $e )
{
$stream = \IPS\nexus\Support\Stream::load('open');
}
}
/* ... or just use the default */
else
{
$stream = \IPS\nexus\Support\Stream::load('open');
}
/* Are we grouping by department? */
if ( isset( \IPS\Request::i()->groupByDepartment ) )
{
\IPS\Session::i()->csrfCheck();
if ( \IPS\Request::i()->groupByDepartment )
{
\IPS\Request::i()->setCookie( 'support_dpt_group', 1, \IPS\DateTime::create()->add( new \DateInterval( 'P1Y') ), FALSE );
@@ -119,21 +152,40 @@ class _requests extends \IPS\Dispatcher\Controller
{
\IPS\Request::i()->setCookie( 'support_dpt_group', 0, \IPS\DateTime::create()->add( new \DateInterval( 'P1Y') ), FALSE );
}
if ( !\IPS\Request::i()->isAjax() )
{
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=support&controller=requests' ) );
}
}
$groupByDepartment = ( isset( \IPS\Request::i()->cookie['support_dpt_group'] ) and \IPS\Request::i()->cookie['support_dpt_group'] );
/* What's our order? */
if ( \IPS\Request::i()->sortBy )
{
\IPS\Session::i()->csrfCheck();
\IPS\Request::i()->setCookie( 'support_sort', \IPS\Request::i()->sortBy, \IPS\DateTime::create()->add( new \DateInterval( 'P1Y') ), FALSE );
if ( !\IPS\Request::i()->isAjax() )
{
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=support&controller=requests' ) );
}
}
if ( \IPS\Request::i()->sortDir )
{
\IPS\Session::i()->csrfCheck();
\IPS\Request::i()->setCookie( 'support_order', \IPS\Request::i()->sortDir, \IPS\DateTime::create()->add( new \DateInterval( 'P1Y') ), FALSE );
if ( !\IPS\Request::i()->isAjax() )
{
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=support&controller=requests' ) );
}
}
if ( isset( \IPS\Request::i()->honorSeverities ) )
{
\IPS\Session::i()->csrfCheck();
\IPS\Request::i()->setCookie( 'support_honor_severities', \IPS\Request::i()->honorSeverities, \IPS\DateTime::create()->add( new \DateInterval( 'P1Y') ), FALSE );
if ( !\IPS\Request::i()->isAjax() )
{
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=support&controller=requests' ) );
}
}
$order = array();
if ( $groupByDepartment )
@@ -146,8 +198,8 @@ class _requests extends \IPS\Dispatcher\Controller
{
$order[] = 'sev_position ASC';
}
$sortBy = ( isset( \IPS\Request::i()->cookie['support_sort'] ) and in_array( \IPS\Request::i()->cookie['support_sort'], array( 'r_started', 'r_last_new_reply', 'r_last_reply', 'r_last_staff_reply' ) ) ) ? \IPS\Request::i()->cookie['support_sort'] : 'r_last_new_reply';
$sortDir = ( isset( \IPS\Request::i()->cookie['support_order'] ) and in_array( \IPS\Request::i()->cookie['support_order'], array( 'ASC', 'DESC' ) ) ) ? \IPS\Request::i()->cookie['support_order'] : 'ASC';
$sortBy = ( isset( \IPS\Request::i()->cookie['support_sort'] ) and \in_array( \IPS\Request::i()->cookie['support_sort'], array( 'r_started', 'r_last_new_reply', 'r_last_reply', 'r_last_staff_reply' ) ) ) ? \IPS\Request::i()->cookie['support_sort'] : 'r_last_new_reply';
$sortDir = ( isset( \IPS\Request::i()->cookie['support_order'] ) and \in_array( \IPS\Request::i()->cookie['support_order'], array( 'ASC', 'DESC' ) ) ) ? \IPS\Request::i()->cookie['support_order'] : 'ASC';
$order[] = $sortBy . ' ' . $sortDir;
$order = implode( ', ', $order );
@@ -155,7 +207,7 @@ class _requests extends \IPS\Dispatcher\Controller
$perPage = 25;
$count = $stream->count( \IPS\Member::loggedIn() );
$numberOfPages = ceil( $count / $perPage );
$page = ( isset( \IPS\Request::i()->page ) and \IPS\Request::i()->page <= $numberOfPages ) ? intval( \IPS\Request::i()->page ) : 1;
$page = ( isset( \IPS\Request::i()->page ) and \IPS\Request::i()->page <= $numberOfPages ) ? \intval( \IPS\Request::i()->page ) : 1;
$results = $stream->results( \IPS\Member::loggedIn(), $order, $page, $perPage );
$pagination = \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->pagination( \IPS\Http\Url::internal('app=nexus&module=support&controller=requests'), $numberOfPages, $page, $perPage );
@@ -172,14 +224,14 @@ class _requests extends \IPS\Dispatcher\Controller
{
\IPS\Db::i()->delete( 'nexus_support_streams', array( 'stream_owner=? AND stream_temporary=1', \IPS\Member::loggedIn()->member_id ) );
$stream = \IPS\nexus\Support\Stream::createFromForm( $values );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=support&controller=requests&stream=') . $stream->id );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=nexus&module=support&controller=requests&stream=' . $stream->id )->csrf() );
}
else
{
\IPS\Request::i()->setCookie( 'support_stream', $values['stream'], \IPS\DateTime::create()->add( new \DateInterval( 'P1Y') ), FALSE );
}
}
$form = $form->customTemplate( array( call_user_func_array( array( \IPS\Theme::i(), 'getTemplate' ), array( 'support' ) ), 'filterForm' ) );
$form = $form->customTemplate( array( \IPS\Theme::i()->getTemplate( 'support' ), 'filterForm' ) );
/* Display */
if ( \IPS\Request::i()->isAjax() )
@@ -230,7 +282,7 @@ class _requests extends \IPS\Dispatcher\Controller
protected function filters()
{
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__nexus_support_requests');
\IPS\Output::i()->output = \IPS\nexus\Support\Stream::load('open')->form( NULL, \IPS\Http\Url::internal('app=nexus&module=support&controller=requests') )->customTemplate( array( call_user_func_array( array( \IPS\Theme::i(), 'getTemplate' ), array( 'support' ) ), 'filterForm' ) );
\IPS\Output::i()->output = \IPS\nexus\Support\Stream::load('open')->form( NULL, \IPS\Http\Url::internal('app=nexus&module=support&controller=requests') )->customTemplate( array( \IPS\Theme::i()->getTemplate( 'support' ), 'filterForm' ) );
}
/**
@@ -242,6 +294,7 @@ class _requests extends \IPS\Dispatcher\Controller
{
if ( isset( \IPS\Request::i()->stream_title ) )
{
\IPS\Session::i()->csrfCheck();
\IPS\Db::i()->update( 'nexus_support_streams', array(
'stream_title' => \IPS\Request::i()->stream_title,
'stream_temporary' => 0
@@ -293,11 +346,11 @@ class _requests extends \IPS\Dispatcher\Controller
$stream->title = $values['stream_title'];
$stream->updateFromForm( $values );
$stream->save();
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=nexus&module=support&controller=requests&stream=' . $stream->id ) );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=nexus&module=support&controller=requests&stream=' . $stream->id )->csrf() );
}
}
\IPS\Output::i()->output = $form->customTemplate( array( call_user_func_array( array( \IPS\Theme::i(), 'getTemplate' ), array( 'support' ) ), 'filterForm' ) );
\IPS\Output::i()->output = $form->customTemplate( array( \IPS\Theme::i()->getTemplate( 'support' ), 'filterForm' ) );
}
/**
@@ -437,10 +490,11 @@ class _requests extends \IPS\Dispatcher\Controller
}
$form->add( new \IPS\Helpers\Form\Editor( 'nexus_default_support_content', $preferences ? $preferences['content'] : NULL, FALSE, array( 'app' => 'nexus', 'key' => 'Support', 'autoSaveKey' => 'default_content', 'tags' => array(
'{customer_first_name}' => \IPS\Member::loggedIn()->language()->addToStack('customer_first_name'),
'{customer_last_name}' => \IPS\Member::loggedIn()->language()->addToStack('customer_first_name'),
'{customer_last_name}' => \IPS\Member::loggedIn()->language()->addToStack('customer_last_name'),
'{customer_full_name}' => \IPS\Member::loggedIn()->language()->addToStack('customer_full_name'),
'{department_name}' => \IPS\Member::loggedIn()->language()->addToStack('department_name'),
'{department_email}' => \IPS\Member::loggedIn()->language()->addToStack('department_email'),
'{default_content}' => \IPS\Member::loggedIn()->language()->addToStack('default_content'),
) ) ) );
$form->add( new \IPS\Helpers\Form\Select( 'nexus_default_support_action', $preferences ? $preferences['action'] : '', FALSE, array( 'options' => array(
'' => 'reply_remember_last',
@@ -499,7 +553,7 @@ class _requests extends \IPS\Dispatcher\Controller
foreach ( $types as $k => $t )
{
if ( $values[ $k ] === 0 or count( $values[ $k ] ) )
if ( $values[ $k ] === 0 or \count( $values[ $k ] ) )
{
\IPS\Db::i()->insert( 'nexus_support_notify', array(
'staff_id' => \IPS\Member::loggedIn()->member_id,
@@ -585,7 +639,7 @@ class _requests extends \IPS\Dispatcher\Controller
/* Stock Actions */
$stockActions = \IPS\nexus\Support\StockAction::roots();
if ( count( $stockActions ) )
if ( \count( $stockActions ) )
{
$steps['stock_action'] = function( $data ) use ( $stockActions, $url )
{
@@ -651,12 +705,12 @@ class _requests extends \IPS\Dispatcher\Controller
/* Custom Fields */
$customFields = \IPS\nexus\Support\CustomField::roots();
if ( count( $customFields ) )
if ( \count( $customFields ) )
{
$steps['custom_support_fields'] = function( $data ) use ( $url )
{
$customFields = \IPS\nexus\Support\CustomField::roots( NULL, NULL, array( "sf_departments='*' OR " . \IPS\Db::i()->findInSet( 'sf_departments', array( $data['department'] ) ) ) );
if ( count( $customFields ) )
if ( \count( $customFields ) )
{
$form = new \IPS\Helpers\Form( 'custom_fields', 'continue', $url->setQueryString( '_step', 'custom_support_fields' ) );
foreach ( $customFields as $field )
@@ -692,21 +746,22 @@ class _requests extends \IPS\Dispatcher\Controller
$owner = isset( $data['member'] ) ? \IPS\nexus\Customer::load( $data['member'] ) : NULL;
$defaultContent = \IPS\Db::i()->select( 'content', 'nexus_support_staff_preferences', array( 'staff_id=?', \IPS\Member::loggedIn()->member_id ) )->first();
$defaultContent = str_replace(
array( '{customer_first_name}', '{customer_last_name}', '{customer_full_name}', '{department_name}', '{department_email}' ),
$defaultContent = $defaultContent ? str_replace(
array( '{customer_first_name}', '{customer_last_name}', '{customer_full_name}', '{department_name}', '{department_email}', '{default_content}' ),
array(
$owner ? $owner->cm_first_name : '',
$owner ? $owner->cm_last_name : '',
$owner ? $owner->cm_name : $data['email'],
$department->_title,
$department->email
$department->email,
$stockAction ? $stockAction->message : ''
),
$defaultContent
);
) : ( $stockAction ? $stockAction->message : '' );
}
catch ( \UnderflowException $e )
{
$defaultContent = NULL;
$defaultContent = $stockAction ? $stockAction->message : NULL;
}
$form = new \IPS\Helpers\Form( 'your_message', 'save', $url->setQueryString( '_step', 'your_message' ) );
@@ -714,7 +769,7 @@ class _requests extends \IPS\Dispatcher\Controller
$form->add( new \IPS\Helpers\Form\Email( 'to', isset( $data['member'] ) ? \IPS\Member::load( $data['member'] )->email : $data['email'], NULL, array(), NULL, NULL, NULL, 'support_create_to' ) );
$form->add( new \IPS\Helpers\Form\Text( 'cc', array(), FALSE, array( 'autocomplete' => array( 'unique' => TRUE, 'forceLower' => TRUE ) ), array( 'IPS\nexus\Support\Request', '_validateEmail' ), NULL, NULL, 'support_create_cc' ) );
$form->add( new \IPS\Helpers\Form\Text( 'bcc', array(), FALSE, array( 'autocomplete' => array( 'unique' => TRUE, 'forceLower' => TRUE ) ), array( 'IPS\nexus\Support\Request', '_validateEmail' ), NULL, NULL, 'support_create_bcc' ) );
$form->add( new \IPS\Helpers\Form\Editor( 'message', $stockAction ? $stockAction->message : $defaultContent, TRUE, array( 'app' => 'nexus', 'key' => 'Support', 'autoSaveKey' => "new-req-message", 'defaultIfNoAutoSave' => TRUE ) ) );
$form->add( new \IPS\Helpers\Form\Editor( 'message', $defaultContent, TRUE, array( 'app' => 'nexus', 'key' => 'Support', 'autoSaveKey' => "new-req-message", 'defaultIfNoAutoSave' => TRUE ) ) );
if ( $values = $form->values() )
{
$request = new \IPS\nexus\Support\Request;
@@ -856,7 +911,7 @@ class _requests extends \IPS\Dispatcher\Controller
/* Display */
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('create_support_request');
\IPS\Output::i()->output = new \IPS\Helpers\Wizard( $steps, $url, TRUE, $initialData );
\IPS\Output::i()->output = (string) new \IPS\Helpers\Wizard( $steps, $url, TRUE, $initialData );
}
/**
@@ -891,7 +946,7 @@ class _requests extends \IPS\Dispatcher\Controller
$yesterday = $yesterday->sub( new \DateInterval('P1D') );
/* What page are we on? */
$page = isset( \IPS\Request::i()->page ) ? intval( \IPS\Request::i()->page ) : 1;
$page = isset( \IPS\Request::i()->page ) ? \intval( \IPS\Request::i()->page ) : 1;
$perPage = 25;
/* Get our replies */
@@ -906,7 +961,7 @@ class _requests extends \IPS\Dispatcher\Controller
array( ( $page - 1 ) * $perPage, $perPage ),
NULL,
NULL,
\IPS\Db::SELECT_SQL_CALC_FOUND_ROWS + \IPS\Db::SELECT_MULTIDIMENSIONAL_JOINS
\IPS\Db::SELECT_MULTIDIMENSIONAL_JOINS
)
->join( 'nexus_support_requests', 'r_id=reply_request' )
->join( 'nexus_support_departments', 'dpt_id=r_department' )
@@ -915,7 +970,11 @@ class _requests extends \IPS\Dispatcher\Controller
);
/* Work out pagination */
$count = $replies->count( TRUE );
$count = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_support_replies', $replyWhere )
->join( 'nexus_support_requests', 'r_id=reply_request' )
->join( 'nexus_support_departments', 'dpt_id=r_department' )
->join( 'nexus_support_ratings', 'reply_id=rating_reply' )
->first();
$numberOfPages = ceil( $count / $perPage );
$pagination = \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->pagination( \IPS\Http\Url::internal( 'app=nexus&module=support&controller=requests&do=history&date=' . $date->getTimestamp() ), $numberOfPages, $page, $perPage );