diff --git a/adm_config_report.php b/adm_config_report.php index b8efae10ad..22948e6789 100644 --- a/adm_config_report.php +++ b/adm_config_report.php @@ -56,6 +56,7 @@ $t_read_write_access = access_has_global_level( config_get( 'set_configuration_threshold' ) ); +require_js( 'adm_config_report.js' ); layout_page_header( lang_get( 'configuration_report' ) ); layout_page_begin( 'manage_overview_page.php' ); @@ -85,56 +86,6 @@ function get_config_type( $p_type ) { } } -/** - * Display a given config value appropriately - * @param integer $p_type Configuration type id. - * @param mixed $p_value Configuration value. - * @param boolean $p_for_display Whether to pass the value via string attribute for web browser display. - * @return void - */ -function print_config_value_as_string( $p_type, $p_value, $p_for_display = true ) { - $t_corrupted = false; - - switch( $p_type ) { - case CONFIG_TYPE_DEFAULT: - return; - case CONFIG_TYPE_FLOAT: - echo (float)$p_value; - return; - case CONFIG_TYPE_INT: - echo (integer)$p_value; - return; - case CONFIG_TYPE_STRING: - $t_value = string_html_specialchars( config_eval( $p_value ) ); - if( $p_for_display ) { - $t_value = '

\'' . string_nl2br( $t_value ) . '\'

'; - } - echo $t_value; - return; - case CONFIG_TYPE_COMPLEX: - $t_value = @json_decode( $p_value, true ); - if( $t_value === false ) { - $t_corrupted = true; - } - break; - default: - $t_value = config_eval( $p_value ); - break; - } - - if( $t_corrupted ) { - $t_output = $p_for_display ? lang_get( 'configuration_corrupted' ) : ''; - } else { - $t_output = var_export( $t_value, true ); - } - - if( $p_for_display ) { - echo '
' . string_attribute( $t_output ) . '
'; - } else { - echo string_attribute( $t_output ); - } -} - /** * Generate an html option list for the given array * @param array $p_array Array. @@ -446,6 +397,17 @@ function check_config_value( $p_config ) { while( $t_row = $t_config_query->fetch() ) { extract( $t_row, EXTR_PREFIX_ALL, 'v' ); + if( CONFIG_TYPE_COMPLEX == $v_type ) { + $t_html_value = '
' + . '[' . lang_get( 'show_content' ) . ']' + . '' + . '
' + . '
'; + } else { + $t_html_value = config_get_value_as_string( $v_type, $v_value ); + } + ?> @@ -455,7 +417,7 @@ function check_config_value( $p_config ) { - + diff --git a/api/rest/restcore/internal_rest.php b/api/rest/restcore/internal_rest.php index 58e2a83044..0cb724d9c6 100644 --- a/api/rest/restcore/internal_rest.php +++ b/api/rest/restcore/internal_rest.php @@ -29,6 +29,7 @@ */ $g_app->group('/internal', function() use ( $g_app ) { $g_app->any( '/autocomplete', 'rest_internal_autocomplete' ); + $g_app->any( '/config_display', 'rest_internal_config_display' ); }); /** @@ -62,3 +63,36 @@ function rest_internal_autocomplete( \Slim\Http\Request $p_request, \Slim\Http\R return $p_response->withStatus( HTTP_STATUS_SUCCESS )->withJson( $t_matches ); } + +function rest_internal_config_display( \Slim\Http\Request $p_request, \Slim\Http\Response $p_response, array $p_args ) { + $t_config_id = $p_request->getParam( 'config_id' ); + $t_user_id = $p_request->getParam( 'user_id' ); + $t_project_id = $p_request->getParam( 'project_id' ); + + if( !access_has_global_level( config_get( 'view_configuration_threshold' ), auth_get_current_user_id() ) ) { + return $p_response->withStatus( HTTP_STATUS_FORBIDDEN ); + } + if( null === $t_user_id || null === $t_project_id || null === $t_config_id ) { + $t_message = "Missing parameters"; + return $p_response->withStatus( HTTP_STATUS_BAD_REQUEST, $t_message ); + } + + $t_sql = 'SELECT config_id, user_id, project_id, type, value, access_reqd FROM {config}' + . ' WHERE user_id = :user_id AND project_id = :project_id AND config_id = :config_id'; + $t_params = array( + 'user_id' => $t_user_id, + 'project_id' => $t_project_id, + 'config_id' => $t_config_id + ); + $t_query = new DbQuery( $t_sql, $t_params ); + $t_row = $t_query->fetch(); + + if( !$t_row ) { + $t_message = "Requested option/project/user doesn't exist"; + return $p_response->withStatus( HTTP_STATUS_NOT_FOUND, $t_message ); + } + + $t_output = config_get_value_as_string( $t_row['type'], $t_row['value'], true ); + + return $p_response->withStatus( HTTP_STATUS_SUCCESS )->write( $t_output ); +} \ No newline at end of file diff --git a/core/config_api.php b/core/config_api.php index a9d6b6333d..a4d57d64ab 100644 --- a/core/config_api.php +++ b/core/config_api.php @@ -738,4 +738,51 @@ function config_cache_all() { $g_cache_config[$t_config][$t_user][$t_project] = $t_row['type'] . ';' . $t_row['value']; $g_cache_config_access[$t_config][$t_user][$t_project] = $t_row['access_reqd']; } +} + +/** + * Display a given config value appropriately + * @param integer $p_type Configuration type id. + * @param mixed $p_value Configuration value. + * @param boolean $p_for_display Whether to pass the value via string attribute for web browser display. + * @return void + */ +function config_get_value_as_string( $p_type, $p_value, $p_for_display = true ) { + $t_corrupted = false; + + switch( $p_type ) { + case CONFIG_TYPE_DEFAULT: + return ''; + case CONFIG_TYPE_FLOAT: + return (string)(float)$p_value; + case CONFIG_TYPE_INT: + return (string)(integer)$p_value; + case CONFIG_TYPE_STRING: + $t_value = string_html_specialchars( config_eval( $p_value ) ); + if( $p_for_display ) { + $t_value = '

\'' . string_nl2br( $t_value ) . '\'

'; + } + return $t_value; + case CONFIG_TYPE_COMPLEX: + $t_value = @json_decode( $p_value, true ); + if( $t_value === false ) { + $t_corrupted = true; + } + break; + default: + $t_value = config_eval( $p_value ); + break; + } + + if( $t_corrupted ) { + $t_output = $p_for_display ? lang_get( 'configuration_corrupted' ) : ''; + } else { + $t_output = var_export( $t_value, true ); + } + + if( $p_for_display ) { + return '
' . string_attribute( $t_output ) . '
'; + } else { + return string_attribute( $t_output ); + } } \ No newline at end of file diff --git a/js/adm_config_report.js b/js/adm_config_report.js new file mode 100644 index 0000000000..c5d80ef61d --- /dev/null +++ b/js/adm_config_report.js @@ -0,0 +1,49 @@ +/* +# Mantis - a php based bugtracking system + +# Copyright 2000 - 2002 Kenzaburo Ito - kenito@300baud.org +# Copyright 2002 MantisBT Team - mantisbt-dev@lists.sourceforge.net + +# Mantis is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# Mantis is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Mantis. If not, see . + */ + +$(document).ready( function() { + $('.adm_config_expand .expand_hide').hide().removeClass('hidden'); + $('.adm_config_expand .expand_hide .toggle') + .click(function(event) { + event.preventDefault(); + var container = $(this).closest('.adm_config_expand'); + container.find('.expand_hide').hide(); + container.find('.expand_show').show(); + container.find('.expand_content').hide(); + }); + $('.adm_config_expand .expand_show .toggle') + .click(function(event) { + event.preventDefault(); + var container = $(this).closest('.adm_config_expand'); + container.find('.expand_hide').show(); + container.find('.expand_show').hide(); + // Load contents if not already done and display + var content = container.find('.expand_content'); + if (content[0].childElementCount == 0) { + var req_data = { + 'config_id': container.data('config_id'), + 'project_id': container.data('project_id'), + 'user_id': container.data('user_id') + }; + content.load('api/rest/internal/config_display',req_data); + } + content.show(); + }); +}); \ No newline at end of file