Version 4.7.13
This commit is contained in:
1 parent
fd22d99e69
commit
7124a02564
954 files changed
+29277
-59308
No files matched your search
@@ -10,6 +10,8 @@
|
||||
|
||||
namespace IPS\Helpers\Chart;
|
||||
|
||||
use IPS\Member;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
@@ -107,6 +109,16 @@ abstract class _Dynamic extends \IPS\Helpers\Chart
|
||||
*/
|
||||
public $showIntervals = TRUE;
|
||||
|
||||
/**
|
||||
* @brief Allow user to adjust date range
|
||||
*/
|
||||
public $showDateRange = TRUE;
|
||||
|
||||
/**
|
||||
* @brief Show save button
|
||||
*/
|
||||
public $showSave = TRUE;
|
||||
|
||||
/**
|
||||
* @brief If a warning about timezones needs to be shown
|
||||
*/
|
||||
@@ -367,48 +379,80 @@ abstract class _Dynamic extends \IPS\Helpers\Chart
|
||||
{
|
||||
try
|
||||
{
|
||||
/* If we have filters, we can save them */
|
||||
if( \count( $this->availableFilters ) > 0 or $this->customFiltersForm )
|
||||
{
|
||||
/* Generate a form so we can save our filters as a new saved chart */
|
||||
$this->form = new \IPS\Helpers\Form;
|
||||
$this->form->class = 'ipsForm_vertical';
|
||||
/* Generate a form so we can save our filters as a new saved chart */
|
||||
$this->form = new \IPS\Helpers\Form;
|
||||
$this->form->class = 'ipsForm_vertical';
|
||||
|
||||
if ( $this->customFiltersForm )
|
||||
if ( $this->customFiltersForm )
|
||||
{
|
||||
if ( $customValues = $this->getCustomFiltersForm()->values( TRUE ) )
|
||||
{
|
||||
if ( $customValues = $this->getCustomFiltersForm()->values( TRUE ) )
|
||||
foreach( $customValues as $key => $value )
|
||||
{
|
||||
foreach( $customValues as $key => $value )
|
||||
{
|
||||
$this->form->hiddenValues['customform_' . $key ] = $value;
|
||||
}
|
||||
$this->form->hiddenValues['customform_' . $key ] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* If we have a sub selector from a node form, add on the identifier and pass off to the form to show the ajax */
|
||||
if ( \IPS\Request::i()->_nodeSelectName )
|
||||
/* If we have a sub selector from a node form, add on the identifier and pass off to the form to show the ajax */
|
||||
if ( \IPS\Request::i()->_nodeSelectName )
|
||||
{
|
||||
\IPS\Request::i()->_nodeSelectName = $this->identifier . \IPS\Request::i()->_nodeSelectName;
|
||||
return (string) $this->getCustomFiltersForm();
|
||||
}
|
||||
|
||||
/* We have an existing chart ID */
|
||||
if( isset( \IPS\Request::i()->chartId ) AND \IPS\Request::i()->chartId != '_default' )
|
||||
{
|
||||
$title = '';
|
||||
|
||||
foreach( $this->loadAvailableChartTabs() as $chart )
|
||||
{
|
||||
\IPS\Request::i()->_nodeSelectName = $this->identifier . \IPS\Request::i()->_nodeSelectName;
|
||||
return (string) $this->getCustomFiltersForm();
|
||||
if( $chart['chart_id'] == \IPS\Request::i()->chartId )
|
||||
{
|
||||
$title = $chart['chart_title'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* We have an existing chart ID */
|
||||
if( isset( \IPS\Request::i()->chartId ) AND \IPS\Request::i()->chartId != '_default' )
|
||||
$custom = array();
|
||||
$chartFilters = ( isset( \IPS\Request::i()->chartFilters ) and \IPS\Request::i()->chartFilters ) ? \IPS\Request::i()->chartFilters : array();
|
||||
$this->timescale = $chart['chart_timescale'] ?? 'monthly';
|
||||
|
||||
foreach( \IPS\Request::i() as $key => $value )
|
||||
{
|
||||
$title = '';
|
||||
|
||||
foreach( $this->loadAvailableChartTabs() as $chart )
|
||||
if ( \mb_substr( $key, 0, 11 ) === 'customform_' )
|
||||
{
|
||||
if( $chart['chart_id'] == \IPS\Request::i()->chartId )
|
||||
{
|
||||
$title = $chart['chart_title'];
|
||||
break;
|
||||
}
|
||||
$custom[ preg_replace( '#' . $this->identifier . '#', '', $key ) ] = $value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$this->form->add( new \IPS\Helpers\Form\Text( 'custom_chart_title', $title, TRUE ) );
|
||||
|
||||
if( $values = $this->form->values() )
|
||||
{
|
||||
\IPS\Db::i()->update( 'core_saved_charts', array( 'chart_title' => $values['custom_chart_title'] ), array( 'chart_id=? AND chart_member=?', \IPS\Request::i()->chartId, \IPS\Member::loggedIn()->member_id ) );
|
||||
|
||||
/* And then return the output we need */
|
||||
\IPS\Output::i()->json( array(
|
||||
'title' => $values['custom_chart_title']
|
||||
) );
|
||||
}
|
||||
|
||||
/* And we want to save our filter updates */
|
||||
if( isset( \IPS\Request::i()->saveFilters ) )
|
||||
{
|
||||
\IPS\Db::i()->update( 'core_saved_charts', array( 'chart_configuration' => json_encode( array_merge( $chartFilters, $custom ) ), 'chart_timescale' => \IPS\Request::i()->timescale ?? $this->timescale ?? 'monthly' ), array( 'chart_id=? AND chart_member=?', \IPS\Request::i()->chartId, \IPS\Member::loggedIn()->member_id ) );
|
||||
}
|
||||
}
|
||||
/* We are not viewing a saved chart */
|
||||
else
|
||||
{
|
||||
$this->form->add( new \IPS\Helpers\Form\Text( 'custom_chart_title', NULL, TRUE ) );
|
||||
|
||||
if( $values = $this->form->values() )
|
||||
{
|
||||
$custom = array();
|
||||
$chartFilters = ( isset( \IPS\Request::i()->chartFilters ) and \IPS\Request::i()->chartFilters ) ? \IPS\Request::i()->chartFilters : array();
|
||||
|
||||
foreach( \IPS\Request::i() as $key => $value )
|
||||
{
|
||||
if ( \mb_substr( $key, 0, 11 ) === 'customform_' )
|
||||
@@ -417,74 +461,40 @@ abstract class _Dynamic extends \IPS\Helpers\Chart
|
||||
}
|
||||
}
|
||||
|
||||
$this->form->add( new \IPS\Helpers\Form\Text( 'custom_chart_title', $title, TRUE ) );
|
||||
$chartFilters = ( isset( \IPS\Request::i()->chartFilters ) and \IPS\Request::i()->chartFilters ) ? \IPS\Request::i()->chartFilters : array();
|
||||
|
||||
/* Store the new chart */
|
||||
$id = \IPS\Db::i()->insert( 'core_saved_charts', array(
|
||||
'chart_member' => \IPS\Member::loggedIn()->member_id,
|
||||
'chart_controller' => \IPS\Request::i()->app . '_' . \IPS\Request::i()->module . '_' . \IPS\Request::i()->controller . ( \IPS\Request::i()->tab ? '_' . \IPS\Request::i()->tab : '' ),
|
||||
'chart_configuration' => json_encode( array_merge( $chartFilters, $custom ) ),
|
||||
'chart_timescale' => \IPS\Request::i()->timescale ?? $this->timescale ?? 'monthly',
|
||||
'chart_title' => $values['custom_chart_title'],
|
||||
) );
|
||||
|
||||
if( $values = $this->form->values() )
|
||||
{
|
||||
\IPS\Db::i()->update( 'core_saved_charts', array( 'chart_title' => $values['custom_chart_title'] ), array( 'chart_id=? AND chart_member=?', \IPS\Request::i()->chartId, \IPS\Member::loggedIn()->member_id ) );
|
||||
/* Set some input parameters */
|
||||
$this->url = $this->url->setQueryString( 'chartId', $id );
|
||||
\IPS\Request::i()->chartId = $id;
|
||||
\IPS\Request::i()->filters = array( $this->identifier => \IPS\Request::i()->chartFilters );
|
||||
|
||||
/* And then return the output we need */
|
||||
\IPS\Output::i()->json( array(
|
||||
'title' => $values['custom_chart_title']
|
||||
) );
|
||||
}
|
||||
|
||||
/* And we want to save our filter updates */
|
||||
if( isset( \IPS\Request::i()->saveFilters ) )
|
||||
{
|
||||
\IPS\Db::i()->update( 'core_saved_charts', array( 'chart_configuration' => json_encode( array_merge( $chartFilters, $custom ) ) ), array( 'chart_id=? AND chart_member=?', \IPS\Request::i()->chartId, \IPS\Member::loggedIn()->member_id ) );
|
||||
}
|
||||
}
|
||||
/* We are not viewing a saved chart */
|
||||
else
|
||||
{
|
||||
$this->form->add( new \IPS\Helpers\Form\Text( 'custom_chart_title', NULL, TRUE ) );
|
||||
$this->currentFilters = \IPS\Request::i()->filters;
|
||||
|
||||
if( $values = $this->form->values() )
|
||||
if ( isset( \IPS\Request::i()->filters[ $this->identifier ] ) )
|
||||
{
|
||||
$custom = array();
|
||||
foreach( \IPS\Request::i() as $key => $value )
|
||||
{
|
||||
if ( \mb_substr( $key, 0, 11 ) === 'customform_' )
|
||||
{
|
||||
$custom[ preg_replace( '#' . $this->identifier . '#', '', $key ) ] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$chartFilters = ( isset( \IPS\Request::i()->chartFilters ) and \IPS\Request::i()->chartFilters ) ? \IPS\Request::i()->chartFilters : array();
|
||||
|
||||
/* Store the new chart */
|
||||
$id = \IPS\Db::i()->insert( 'core_saved_charts', array(
|
||||
'chart_member' => \IPS\Member::loggedIn()->member_id,
|
||||
'chart_controller' => \IPS\Request::i()->app . '_' . \IPS\Request::i()->module . '_' . \IPS\Request::i()->controller . ( \IPS\Request::i()->tab ? '_' . \IPS\Request::i()->tab : '' ),
|
||||
'chart_configuration' => json_encode( array_merge( $chartFilters, $custom ) ),
|
||||
'chart_title' => $values['custom_chart_title'],
|
||||
) );
|
||||
|
||||
/* Set some input parameters */
|
||||
$this->url = $this->url->setQueryString( 'chartId', $id );
|
||||
\IPS\Request::i()->chartId = $id;
|
||||
\IPS\Request::i()->filters = array( $this->identifier => \IPS\Request::i()->chartFilters );
|
||||
|
||||
$this->currentFilters = \IPS\Request::i()->filters;
|
||||
|
||||
if ( isset( \IPS\Request::i()->filters[ $this->identifier ] ) )
|
||||
{
|
||||
$this->url = $this->url->setQueryString( 'filters', array( $this->identifier => $this->currentFilters ) );
|
||||
}
|
||||
|
||||
/* Reset form, since template looks for it and it should not be set for a saved chart */
|
||||
$this->form = new \IPS\Helpers\Form;
|
||||
$this->form->class = 'ipsForm_vertical';
|
||||
$this->form->add( new \IPS\Helpers\Form\Text( 'custom_chart_title', $values['custom_chart_title'], TRUE ) );
|
||||
|
||||
/* And then return the output we need */
|
||||
\IPS\Output::i()->json( array(
|
||||
'tabHref' => $this->url->stripQueryString( 'filters' ),
|
||||
'chartId' => $id,
|
||||
'tabId' => md5( $this->url->acpQueryString() ),
|
||||
) );
|
||||
$this->url = $this->url->setQueryString( 'filters', array( $this->identifier => $this->currentFilters ) );
|
||||
}
|
||||
|
||||
/* Reset form, since template looks for it and it should not be set for a saved chart */
|
||||
$this->form = new \IPS\Helpers\Form;
|
||||
$this->form->class = 'ipsForm_vertical';
|
||||
$this->form->add( new \IPS\Helpers\Form\Text( 'custom_chart_title', $values['custom_chart_title'], TRUE ) );
|
||||
|
||||
/* And then return the output we need */
|
||||
\IPS\Output::i()->json( array(
|
||||
'tabHref' => $this->url->stripQueryString( 'filters' ),
|
||||
'chartId' => $id,
|
||||
'tabId' => md5( $this->url->acpQueryString() ),
|
||||
) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -507,8 +517,14 @@ abstract class _Dynamic extends \IPS\Helpers\Chart
|
||||
else
|
||||
{
|
||||
$chartOutput = \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->dynamicChart( $this, $output );
|
||||
|
||||
/* If we're not showing filter tabs, just return here. */
|
||||
if ( !$this->showFilterTabs )
|
||||
{
|
||||
return $chartOutput;
|
||||
}
|
||||
|
||||
if( ( \count( $this->availableFilters ) > 0 or $this->customFiltersForm ) AND ( !\IPS\Request::i()->isAjax() OR ( \IPS\Request::i()->tab AND !\IPS\Request::i()->chartId ) ) )
|
||||
if( !\IPS\Request::i()->isAjax() OR ( \IPS\Request::i()->tab AND !\IPS\Request::i()->chartId ) )
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate( 'global', 'core' )->tabs( $this->getChartTabs(), ( isset( \IPS\Request::i()->chartId ) ) ? \IPS\Request::i()->chartId : NULL, $chartOutput, $this->url, 'chartId', 'ipsTabs_small ipsTabs_contained' );
|
||||
}
|
||||
@@ -527,11 +543,21 @@ abstract class _Dynamic extends \IPS\Helpers\Chart
|
||||
\IPS\IPS::exceptionHandler( $e );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Show filter tabs
|
||||
*/
|
||||
public $showFilterTabs = TRUE;
|
||||
|
||||
/**
|
||||
* @brief Cached tab data
|
||||
*/
|
||||
protected $availableChartTabs = NULL;
|
||||
|
||||
/**
|
||||
* @Brief Extension
|
||||
*/
|
||||
public $extension = NULL;
|
||||
|
||||
/**
|
||||
* Retrieve tabs based on saved charts
|
||||
@@ -559,11 +585,31 @@ abstract class _Dynamic extends \IPS\Helpers\Chart
|
||||
{
|
||||
if( $this->availableChartTabs === NULL )
|
||||
{
|
||||
$this->availableChartTabs = iterator_to_array( \IPS\Db::i()->select( '*', 'core_saved_charts', array( 'chart_member=? AND chart_controller=?', \IPS\Member::loggedIn()->member_id, \IPS\Request::i()->app . '_' . \IPS\Request::i()->module . '_' . \IPS\Request::i()->controller . ( \IPS\Request::i()->tab ? '_' . \IPS\Request::i()->tab : '' ) ) ) );
|
||||
if ( $this->extension !== NULL )
|
||||
{
|
||||
$this->availableChartTabs = iterator_to_array( \IPS\Db::i()->select( '*', 'core_saved_charts', array( 'chart_member=? AND chart_controller=?', \IPS\Member::loggedIn()->member_id, $this->extension->controller ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->availableChartTabs = iterator_to_array( \IPS\Db::i()->select( '*', 'core_saved_charts', array( 'chart_member=? AND chart_controller=?', \IPS\Member::loggedIn()->member_id, \IPS\Request::i()->app . '_' . \IPS\Request::i()->module . '_' . \IPS\Request::i()->controller . ( \IPS\Request::i()->tab ? '_' . \IPS\Request::i()->tab : '' ) ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
return $this->availableChartTabs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set extension
|
||||
*
|
||||
* @param \IPS\core\Statistics\Chart $ext Extension
|
||||
* @return void
|
||||
*/
|
||||
public function setExtension( \IPS\core\Statistics\Chart $ext )
|
||||
{
|
||||
$this->extension = $ext;
|
||||
|
||||
$this->availableChartTabs = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flip URL Filter
|
||||
@@ -685,10 +731,22 @@ abstract class _Dynamic extends \IPS\Helpers\Chart
|
||||
{
|
||||
$rawHeaders = $this->headers;
|
||||
}
|
||||
|
||||
|
||||
/* Ok this is a very horrible hack to get the language hashes converted into the real names and in a format
|
||||
that we can then reparse later. */
|
||||
$uglyHack = '';
|
||||
foreach( $rawHeaders AS $data )
|
||||
{
|
||||
$headers[] = $data['label'];
|
||||
$uglyHack .= str_replace( "\n", " ", $data['label'] ) . "\n";
|
||||
}
|
||||
|
||||
/* This really is awful */
|
||||
Member::loggedIn()->language()->parseOutputForDisplay( $uglyHack );
|
||||
|
||||
foreach( explode( "\n", trim( $uglyHack ) ) as $label )
|
||||
{
|
||||
/* Now we have the true string, eg: News, Now! instead of a language hash, eg: 77e90423a7642378a1590420cd66a465 so fputcsv can escape it correctly */
|
||||
$headers[] = $label;
|
||||
}
|
||||
fputcsv( $fh, $headers );
|
||||
|
||||
|
||||
Reference in new issue
Block a user