View Issue Details

IDProjectCategoryView StatusLast Update
0013382mantisbtpreferencespublic2012-12-30 09:19
Reporterkaese Assigned Todregad  
PrioritylowSeverityfeatureReproducibilityN/A
Status closedResolutionduplicate 
Product Version1.2.8 
Summary0013382: Make configuration options editable in adm_config_report
Description

Currently it's not possible to edit database configuration options in adm_config_report.php. They can only delete and readded.

The attached patch enables INTEGER and STRING-type configurations to be edited:

  • add adm_config_edit.php, edit page
  • modify adm_config_report.php, add modify link for INTEGER and STRING type
  • update core/config_api.php, new function config_can_edit
  • update lang/strings_english.txt

COMPLEX-type options are currently not supported (maybe will wait for 0013298)

Any feedback is welcome.

TagsNo tags attached.
Attached Files
adm_config_editable.diff (8,809 bytes)   
diff -Naur mantis/adm_config_edit.php mantis-test/adm_config_edit.php
--- mantis/adm_config_edit.php	1970-01-01 01:00:00.000000000 +0100
+++ mantis-test/adm_config_edit.php	2011-10-06 09:28:55.000000000 +0200
@@ -0,0 +1,176 @@
+<?php
+# MantisBT - a php based bugtracking system
+
+# MantisBT 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.
+#
+# MantisBT 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 MantisBT.  If not, see <http://www.gnu.org/licenses/>.
+
+	/**
+	 * @package MantisBT
+	 * @copyright Copyright (C) 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
+	 * @copyright Copyright (C) 2002 - 2011  MantisBT Team - mantisbt-dev@lists.sourceforge.net
+	 * @link http://www.mantisbt.org
+	 */
+	 /**
+	  * MantisBT Core API's
+	  */
+	require_once( 'core.php' );
+
+	access_ensure_project_level( config_get( 'set_configuration_threshold' ) );
+
+	html_page_top( lang_get( 'configuration_report' ) );
+
+	print_manage_menu( 'adm_config_report.php' );
+	print_manage_config_menu( 'adm_config_report.php' );
+
+	function print_config_value_as_string( $p_type, $p_value ) {
+		$t_corrupted = false;
+
+		switch( $p_type ) {
+			case CONFIG_TYPE_FLOAT:
+				$t_value = (float)$p_value;
+				echo $t_value;
+				return;
+			case CONFIG_TYPE_INT:
+				$t_value = (integer)$p_value;
+				echo $t_value;
+				return;
+			case CONFIG_TYPE_STRING:
+				$t_value = config_eval( $p_value );
+				echo string_html_specialchars( "$t_value" );
+				return;
+			case CONFIG_TYPE_COMPLEX:
+				$t_value = @unserialize( $p_value );
+				if ( $t_value === false ) {
+					$t_corrupted = true;
+				}
+				break;
+			default:
+				$t_value = config_eval( $p_value );
+				break;
+		}
+
+		if ( $t_corrupted ) {
+			echo lang_get( 'configuration_corrupted' );
+		} else {
+			if ( function_exists( 'var_export' ) ) {
+				var_export( $t_value );
+			} else {
+				print_r( $t_value );
+			}
+		}
+
+	}
+
+	$f_config_user_id = gpc_get_int( 'user_id' );
+	$f_config_project_id = gpc_get_int( 'project_id' );
+	$f_config_option = gpc_get_string( 'config_option' );
+
+	$t_config_table = db_get_table( 'mantis_config_table' );
+	$query = "SELECT type, value, access_reqd FROM $t_config_table
+			WHERE config_id = " . db_param() . " AND
+				project_id = " . db_param() . " AND
+				user_id = " . db_param();
+	$result = db_query_bound( $query, Array( $f_config_option, $f_config_project_id, $f_config_user_id ) );
+
+	# make sure that configuration option specified is found in database
+	if ( db_num_rows( $result ) != 1 ) {
+		$t_not_found_value = '***CONFIG OPTION NOT FOUND***';
+		error_parameters( $f_config_option );
+		trigger_error( ERROR_CONFIG_OPT_NOT_FOUND, ERROR );
+	}
+
+	$row = db_fetch_array( $result );
+
+	$t_config_type_id = $row['type'];
+	$t_config_value = $row['value'];
+
+?>
+<br />
+<div align="center">
+<!-- Config Edit Form -->
+<form name="edit_config_form" method="post" action="adm_config_set.php">
+<?php echo form_security_field( 'adm_config_set' ) ?>
+<table class="width75" cellspacing="1">
+
+<!-- Title -->
+<tr>
+	<td class="form-title" colspan="2">
+		<?php echo lang_get( 'edit_configuration_option' ) ?>
+	</td>
+</tr>
+<tr <?php echo helper_alternate_class() ?> valign="top">
+	<td>
+		<?php echo lang_get( 'username' ) ?>
+	</td>
+	<td>
+		<select name="user_id">
+			<option value="0" selected="selected"><?php echo lang_get( 'all_users' ); ?></option>
+			<?php print_user_option_list( $f_config_user_id ) ?>
+		</select>
+	</td>
+</tr>
+<tr <?php echo helper_alternate_class() ?> valign="top">
+	<td>
+		<?php echo lang_get( 'project_name' ) ?>
+	</td>
+	<td>
+		<select name="project_id">
+			<option value="0" selected="selected"><?php echo lang_get( 'all_projects' ); ?></option>
+			<?php print_project_option_list( $f_config_project_id, false ) ?>
+		</select>
+	</td>
+</tr>
+<tr <?php echo helper_alternate_class() ?> valign="top">
+	<td>
+		<?php echo lang_get( 'configuration_option' ) ?>
+	</td>
+	<td>
+			<input type="text" name="config_option" value="<?php echo $f_config_option ?>" size="64" maxlength="64"/>
+	</td>
+</tr>
+<tr <?php echo helper_alternate_class() ?> valign="top">
+	<td>
+		<?php echo lang_get( 'configuration_option_type' ) ?>
+	</td>
+	<td>
+		<select name="type">
+			<option value="default">default</option>
+			<option value="string" <?php check_selected( CONFIG_TYPE_STRING, $t_config_type_id ) ?>>string</option>
+			<option value="integer" <?php check_selected( CONFIG_TYPE_INT, $t_config_type_id ) ?>>integer</option>
+			<option value="complex" <?php check_selected( CONFIG_TYPE_COMPLEX, $t_config_type_id ) ?>>complex</option>
+		</select>
+	</td>
+</tr>
+<tr <?php echo helper_alternate_class() ?> valign="top">
+	<td>
+		<?php echo lang_get( 'configuration_option_value' ) ?>
+	</td>
+	<td>
+			<textarea name="value" cols="80" rows="10"><?php print_config_value_as_string( $t_config_type_id, $t_config_value ); ?></textarea>
+	</td>
+</tr>
+<tr>
+	<td colspan="2" class="center">
+			<input type="submit" name="config_set" class="button" value="<?php echo lang_get( 'set_configuration_option' ) ?>" />
+			</form>
+			<?php
+				if ( config_can_delete( $v_config_id ) ) {
+					print_button( "adm_config_delete.php?user_id=$f_config_user_id&project_id=$f_config_project_id&config_option=$f_config_option", lang_get( 'delete_link' ) );
+				}
+			?>
+	</td>
+</tr>
+</table>
+</div>
+<?php
+	html_page_bottom();
diff -Naur mantis/adm_config_report.php mantis-test/adm_config_report.php
--- mantis/adm_config_report.php	2011-07-26 15:49:10.000000000 +0200
+++ mantis-test/adm_config_report.php	2011-10-06 08:59:06.000000000 +0200
@@ -152,9 +152,18 @@
 			</td>
 			<td class="center">
 				<?php
-					if ( config_can_delete( $v_config_id ) ) {
+					$t_config_can_delete = config_can_delete( $v_config_id );
+					$t_config_can_edit = config_can_edit( $v_config_id );
+
+					if ( $t_config_can_delete ) {
 						print_button( "adm_config_delete.php?user_id=$v_user_id&project_id=$v_project_id&config_option=$v_config_id", lang_get( 'delete_link' ) );
-					} else {
+					}
+					/* Only make stings und integers editable */
+					if ( $t_config_can_edit && ( $v_type == CONFIG_TYPE_STRING || $v_type == CONFIG_TYPE_INT ) ) {
+						print_button( "adm_config_edit.php?user_id=$v_user_id&project_id=$v_project_id&config_option=$v_config_id", lang_get( 'edit_link' ) );
+					}
+
+					if ( !$t_config_can_delete && !$t_config_can_edit ) {
 						echo '&#160;';
 					}
 				?>
diff -Naur mantis/core/config_api.php mantis-test/core/config_api.php
--- mantis/core/config_api.php	2011-07-26 15:49:10.000000000 +0200
+++ mantis-test/core/config_api.php	2011-10-05 16:45:21.000000000 +0200
@@ -435,6 +435,12 @@
 }
 
 # ------------------
+# Checks if the specific configuration option can be edited in the database.
+function config_can_edit( $p_option ) {
+	return( utf8_strtolower( $p_option ) != 'database_version' );
+}
+
+# ------------------
 # delete the config entry
 function config_delete( $p_option, $p_user = ALL_USERS, $p_project = ALL_PROJECTS ) {
 	global $g_cache_config, $g_cache_config_access;
diff -Naur mantis/lang/strings_english.txt mantis-test/lang/strings_english.txt
--- mantis/lang/strings_english.txt	2011-07-26 15:49:10.000000000 +0200
+++ mantis-test/lang/strings_english.txt	2011-10-05 17:21:04.000000000 +0200
@@ -841,6 +841,7 @@
 $s_configuration_option_value = 'Value';
 $s_all_users = 'All Users';
 $s_set_configuration_option = 'Set Configuration Option';
+$s_edit_configuration_option = 'Edit Configuration Option';
 $s_delete_config_sure_msg = 'Are you sure you wish to delete this configuration option?';
 $s_configuration_corrupted = 'The configuration in the database is corrupted.';
 
diff -Naur mantis/lang/strings_german.txt mantis-test/lang/strings_german.txt
--- mantis/lang/strings_german.txt	2011-07-26 15:49:10.000000000 +0200
+++ mantis-test/lang/strings_german.txt	2011-10-05 17:23:01.000000000 +0200
@@ -696,6 +696,7 @@
 $s_configuration_option_value = 'Wert';
 $s_all_users = 'Alle Benutzer';
 $s_set_configuration_option = 'Speichere Konfigurations-Option';
+$s_edit_configuration_option = 'Bearbeite Konfigurations-Option';
 $s_delete_config_sure_msg = 'Sind Sie sicher, dass Sie diese Konfigurationsoption löschen möchten?';
 $s_configuration_corrupted = 'Ungültige Konfiguration in der Datenbank';
 $s_plugin = 'Plugin';
adm_config_editable.diff (8,809 bytes)   

Relationships

duplicate of 0007586 closeddregad generic configuration editor cannot 'EDIT' an option 
related to 0013298 closeddregad commas and multi-dimensional arrays in adm_config_set 

Activities

rombert

rombert

2011-10-15 06:39

reporter   ~0029969

Thank you for the report and suggested fix. Would you consider submitting pull requests for this functionality? This would greatly increase the speed of including these changes in MantisBT.

Ideally you would submit pull requests for both the master and master-1.2.x branches at https://github.com/mantisbt/mantisbt .