View Issue Details

IDProjectCategoryView StatusLast Update
0007586mantisbtcustomizationpublic2014-12-22 08:23
Reportervreck Assigned Todregad  
PrioritynormalSeverityfeatureReproducibilityalways
Status closedResolutionfixed 
Product Version1.1.0a1 
Target Version1.2.13Fixed in Version1.2.13 
Summary0007586: generic configuration editor cannot 'EDIT' an option
Description

The generic configuration feature is a really nice feature.
But it would be even nicer if the options could be edited/modified.
Currently the only way to modify an option is to DELETE it and Re-create it...
Which is quite tedious when "tuning" the configuration of a Mantis server.

TagsNo tags attached.
Attached Files
mantisbt_7586_rev1.patch (4,345 bytes)   
? adm_config_edit.php
Index: adm_config_report.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/adm_config_report.php,v
retrieving revision 1.9
diff -u -r1.9 adm_config_report.php
--- adm_config_report.php	1 Apr 2007 06:30:24 -0000	1.9
+++ adm_config_report.php	8 Aug 2007 22:30:48 -0000
@@ -126,6 +126,7 @@
 				<?php
 					if ( config_can_delete( $v_config_id ) ) {
 						print_button( 'adm_config_delete.php?user_id=' . $v_user_id . '&amp;project_id=' . $v_project_id . '&amp;config_option=' . $v_config_id, lang_get( 'delete_link' ) );
+						print_button( 'adm_config_edit.php?user_id=' . $v_user_id . '&amp;project_id=' . $v_project_id . '&amp;config_option=' . $v_config_id, lang_get( 'edit_link' ) );
 					} else {
 						echo '&nbsp;';
 					}
Index: core/config_api.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/core/config_api.php,v
retrieving revision 1.39
diff -u -r1.39 config_api.php
--- core/config_api.php	25 Jul 2007 23:39:44 -0000	1.39
+++ core/config_api.php	8 Aug 2007 22:45:04 -0000
@@ -148,6 +148,95 @@
 			return $p_default;
 		}
 	}
+	
+	# ------------------
+	# Retrieves the type of a config value
+	function config_get_type( $p_option, $p_user = null, $p_project = null )
+	{
+		global $g_cache_config, $g_cache_config_access, $g_cache_db_table_exists, $g_cache_filled;
+
+		# bypass table lookup for certain options
+		$t_bypass_lookup = !config_can_set_in_database( $p_option );
+
+		if ( ! $t_bypass_lookup ) {
+			$t_config_table = config_get_global( 'mantis_config_table' );
+			if ( ! $g_cache_db_table_exists ) {
+				$g_cache_db_table_exists = ( TRUE === db_is_connected() ) &&
+					db_table_exists( $t_config_table );
+			}
+
+			if ( $g_cache_db_table_exists ) {
+
+				# prepare the user's list
+				$t_users = array();
+				if ( null === $p_user ) {
+					$t_users[] = auth_is_user_authenticated() ? auth_get_current_user_id() : ALL_USERS;
+				} else {
+					$t_users[] = $p_user;
+				}
+				if ( ! in_array( ALL_USERS, $t_users ) ) {
+					$t_users[] = ALL_USERS;
+				}
+
+				# prepare the projects list
+				$t_projects = array();
+				if ( ( null === $p_project )  ) {
+					$t_projects[] = auth_is_user_authenticated() ? helper_get_current_project() : ALL_PROJECTS;
+				} else {
+					$t_projects[] = $p_project;
+				}
+				if ( ! in_array( ALL_PROJECTS, $t_projects ) ) {
+					$t_projects[] = ALL_PROJECTS;
+				}
+				
+				if ( ! $g_cache_filled ) {
+					
+					$query = "SELECT config_id, user_id, project_id, type, value, access_reqd FROM $t_config_table";
+					$result = db_query( $query );
+					while ( false <> ( $row = db_fetch_array( $result ) ) ) {
+						$t_config = $row['config_id'];
+						$t_user = $row['user_id'];
+						$t_project = $row['project_id'];
+						$g_cache_config[$t_config][$t_user][$t_project] = $row['type'] . ';' . $row['value'];
+						$g_cache_config_access[$t_config][$t_user][$t_project] = $row['access_reqd'];
+					}
+					$g_cache_filled = true;
+				}
+
+				if( isset( $g_cache_config[$p_option] ) ) {
+				    $t_found = false;
+				    reset( $t_users );
+				    while ( ( list( , $t_user ) = each( $t_users ) ) && ! $t_found ) {
+					   reset( $t_projects );
+					   while ( ( list( , $t_project ) = each( $t_projects ) ) && ! $t_found ) {
+					       if ( isset( $g_cache_config[$p_option][$t_user][$t_project] ) ) {
+    							$t_value = $g_cache_config[$p_option][$t_user][$t_project];
+    							$t_found = true;
+    						}
+    					}
+    				}
+				
+    				if ( $t_found ) {
+    					list( $t_type, $t_raw_value ) = explode( ';', $t_value, 2 );
+
+    					switch ( $t_type ) {
+    						case CONFIG_TYPE_INT:
+    							$t_value = (int) $t_raw_value;
+    							break;
+    						case CONFIG_TYPE_COMPLEX:
+    							$t_value = unserialize( $t_raw_value );
+    							break;
+    						case CONFIG_TYPE_STRING:
+    						default:
+    							$t_value = config_eval( $t_raw_value );
+    					}
+    					return $t_type;
+    				}
+    			}
+			}
+		}
+		return CONFIG_TYPE_STRING;
+	}
 
 	# ------------------
 	# Retrieves the access level needed to change a config value
mantisbt_7586_rev1.patch (4,345 bytes)   
adm_config_edit.php (4,933 bytes)   
<?php
    # Mantis - a php based bugtracking system
    # Copyright (C) 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
    # Copyright (C) 2002 - 2006  Mantis Team   - mantisbt-dev@lists.sourceforge.net
    # This program is distributed under the terms and conditions of the GPL
    # See the README and LICENSE files for details

    # --------------------------------------------------------
    # $Id:  $
    # --------------------------------------------------------

    require_once( 'core.php' );

    $t_core_path = config_get( 'core_path' );

	$f_user_id = gpc_get_int( 'user_id' );
	$f_project_id = gpc_get_int( 'project_id' );
	$f_config_option = gpc_get_string( 'config_option' );

	if ( $f_project_id == ALL_PROJECTS ) {
		access_ensure_global_level( config_get('set_configuration_threshold' ) );
	} else {
		access_ensure_project_level( config_get('set_configuration_threshold' ), $f_project_id );
	}
	
	$t_config_value = config_get( $f_config_option, null, $f_user_id, $f_project_id );
	$t_config_type = get_config_type( config_get_type( $f_config_option, $f_user_id, $f_project_id ) );
	
    html_page_top1( lang_get( 'configuration_report' ) );
    html_page_top2();

    function get_config_type( $p_type ) {
        switch( $p_type ) {
            case CONFIG_TYPE_INT:
                return "integer";
            case CONFIG_TYPE_COMPLEX:
                return "complex";
            case CONFIG_TYPE_STRING:
            default:
                return "string";
        }
    }

    function print_config_value_as_string( $p_type, $p_value ) {
        switch( $p_type ) {
            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_nl2br( string_html_specialchars( "'$t_value'" ) );
                return;
            case CONFIG_TYPE_COMPLEX:
                $t_value = unserialize( $p_value );
                break;
            default:
                $t_value = config_eval( $p_value );
                break;
        }
        
        echo '<pre>';
        if ( function_exists( 'var_export' ) ) {
            var_export( $t_value );
        } else {
            print_r( $t_value );
        }
        echo '</pre>';
    }

?>
<div align="center">
<br />
<!-- Config Set Form -->
<table class="width100" cellspacing="1">

<!-- Title -->
<tr>
    <td class="form-title" colspan="2">
        <?php echo lang_get( 'set_configuration_option' ) ?>
    </td>
</tr>
        <form method="post" action="adm_config_set.php">
<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_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_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" <?php check_selected( 'default', $t_config_type); ?>>default</option>
            <option value="string" <?php check_selected( 'string', $t_config_type); ?>>string</option>
            <option value="integer" <?php check_selected( 'integer', $t_config_type); ?>>integer</option>
            <option value="complex" <?php check_selected( 'complex', $t_config_type); ?>>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 echo $t_config_value; ?></textarea>
    </td>
</tr>
<tr>
    <td colspan="2">
            <input type="submit" name="config_set" class="button" value="<?php echo lang_get( 'set_configuration_option' ) ?>" />
    </td>
</tr>
        </form>
</table>
</div>
<?php
    html_page_bottom1( __FILE__ );
?>
adm_config_edit.php (4,933 bytes)   
adm_config_edit2.php (5,070 bytes)   
<?php
    # Mantis - a php based bugtracking system
    # Copyright (C) 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
    # Copyright (C) 2002 - 2006  Mantis Team   - mantisbt-dev@lists.sourceforge.net
    # This program is distributed under the terms and conditions of the GPL
    # See the README and LICENSE files for details

    # --------------------------------------------------------
    # $Id:  $
    # --------------------------------------------------------

    require_once( 'core.php' );

    $t_core_path = config_get( 'core_path' );

	$f_user_id = gpc_get_int( 'user_id' );
	$f_project_id = gpc_get_int( 'project_id' );
	$f_config_option = gpc_get_string( 'config_option' );

	if ( $f_project_id == ALL_PROJECTS ) {
		access_ensure_global_level( config_get('set_configuration_threshold' ) );
	} else {
		access_ensure_project_level( config_get('set_configuration_threshold' ), $f_project_id );
	}
	
	$t_config_value = config_get( $f_config_option, null, $f_user_id, $f_project_id );
	$t_config_type = get_config_type( config_get_type( $f_config_option, $f_user_id, $f_project_id ) );
	
    html_page_top1( lang_get( 'configuration_report' ) );
    html_page_top2();

    function get_config_type( $p_type ) {
        switch( $p_type ) {
            case CONFIG_TYPE_INT:
                return "integer";
            case CONFIG_TYPE_COMPLEX:
                return "complex";
            case CONFIG_TYPE_STRING:
            default:
                return "string";
        }
    }

    function print_config_value_as_string( $p_type, $p_value ) {
        switch( $p_type ) {
            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_nl2br( string_html_specialchars( "'$t_value'" ) );
                return;
            case CONFIG_TYPE_COMPLEX:
                $t_value = unserialize( $p_value );
                break;
            default:
                $t_value = config_eval( $p_value );
                break;
        }
        
        echo '<pre>';
        if ( function_exists( 'var_export' ) ) {
            var_export( $t_value );
        } else {
            print_r( $t_value );
        }
        echo '</pre>';
    }

?>
<div align="center">
<br />
<!-- Config Set Form -->
<table class="width100" cellspacing="1">

<!-- Title -->
<tr>
    <td class="form-title" colspan="2">
        <?php echo lang_get( 'set_configuration_option' ) ?>
    </td>
</tr>
        <form method="post" action="adm_config_set.php">
<tr <?php echo helper_alternate_class() ?> valign="top">
    <td>
        <?php echo lang_get( 'username' ) ?>
    </td>
    <td>
    	<input type="hidden" name="user_id" value="<?php echo $f_user_id; ?>" />
        <?php
			if ( $f_user_id == ALL_USERS ) {
				echo "All Users" ;
			} else {
				$t_user = user_cache_row( $f_user_id );
				echo $t_user['username'] ;
			}
       	?>
    </td>
</tr>
<tr <?php echo helper_alternate_class() ?> valign="top">
    <td>
        <?php echo lang_get( 'project_name' ) ?>
    </td>
    <td>
    	<input type="hidden" name="project_id" value="<?php echo $f_project_id; ?>" />
        <?php
			if ( $f_project_id == ALL_PROJECTS ) {
				echo "All Projects" ;
			} else {
	        	$t_project = project_cache_row( $f_project_id );
	        	echo $t_project['name'];
	        }
        ?>
    </td>
</tr>
<tr <?php echo helper_alternate_class() ?> valign="top">
    <td>
        <?php echo lang_get( 'configuration_option' ) ?>
    </td>
    <td>
        <input type="hidden" name="config_option" value="<?php echo $f_config_option; ?>" />
        <?php echo $f_config_option; ?>
    </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" <?php check_selected( 'default', $t_config_type); ?>>default</option>
            <option value="string" <?php check_selected( 'string', $t_config_type); ?>>string</option>
            <option value="integer" <?php check_selected( 'integer', $t_config_type); ?>>integer</option>
            <option value="complex" <?php check_selected( 'complex', $t_config_type); ?>>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 echo $t_config_value; ?></textarea>
    </td>
</tr>
<tr>
    <td colspan="2">
            <input type="submit" name="config_set" class="button" value="<?php echo lang_get( 'set_configuration_option' ) ?>" />
    </td>
</tr>
        </form>
</table>
</div>
<?php
    html_page_bottom1( __FILE__ );
?>
adm_config_edit2.php (5,070 bytes)   

Relationships

related to 0015721 closedgrangeway Functionality to consider porting to master-2.0.x 
has duplicate 0013382 closeddregad Make configuration options editable in adm_config_report 
related to 0015592 closeddregad APPLICATION ERROR # 0 when editing configuration options 

Activities

roleary

roleary

2007-08-08 18:50

reporter   ~0015371

Patch to implement the Config Edit functionality. Had to create a new function in config_api.php to return the 'type' (config_get_type()). It's pretty messy, but I wasn't able to find another way to do it.

  • O
roleary

roleary

2007-08-08 19:23

reporter   ~0015373

Use the new adm_config_edit2.php file (but rename it to remove the number 2). The original allowed you to edit project, user, and config name. BUT, obviously you shouldn't be able to edit those fields. So this resolves that.

  • O
thraxisp

thraxisp

2007-08-09 20:55

reporter   ~0015391

From IRC:

thraxisp: ok. I'm not sure you need config_get_type. The type is determined by the data content (see config_set).
thraxisp: line 27 of adm_config_edit.php doesn't seem correct.
thraxisp: adm_config_edit.php should probably be called adm_config_edit_page.php (displayed page files usually end in _page).
roleary: line 27: gets the type as a string (inner function returns the type as constant, outer converts it to a string)
thraxisp: The function names confused me.
roleary: yeah. after i wrote that line, i knew they would confuse somebody
roleary: the type thing is weird though. i never noticed until now
roleary: if i create a configuration option with type "string", but put the number 10 into the value, it comes out typed as an integer
roleary: because of the config_set, like you said
roleary: strange
roleary: so the only time the drop-down is used, is in setting the value in the adm_config_set page.
roleary: which makes for some weird behavior with this patch. if you edit an 'integer' value, and only change the 'type' to 'string', it keeps being saved as an 'integer'
thraxisp: php makes numbers and strings interchangeable.
roleary: i wonder, what's the purpose of the 'type' drop-down in the first place, if the value being stored is based on the type of the value entered?
roleary: i'll think on this 'type' thing for a while. i think you're right though, i dont need the config_get_type function
thraxisp: If you need it, just cache the type when the values are read from the database.

dregad

dregad

2012-12-16 04:50

developer   ~0034548

User kaese proposed an alternative patch to fix this issue in 0013382

dregad

dregad

2012-12-28 19:00

developer   ~0034635

Editing of existing config options stored in db should be fixed in https://github.com/dregad/mantisbt/tree/manage-config, testing and feedback would be appreciated.

grangeway

grangeway

2013-04-05 17:56

reporter   ~0036070

Marking as 'acknowledged' not resolved/closed to track that change gets ported to master-2.0.x branch

Related Changesets

MantisBT: master-1.2.x 8890b218

2012-12-15 02:17

dregad


Details Diff
Make it possible to edit config options in adm_config_report.php

Use CONFIG_TYPE_xxx constants instead of magic strings to define the
type of config value to process.

Added code for FLOAT type which was previously handled through COMPLEX.

Improve handling of INT (and FLOAT) by calling constant_replace(),
allowing user to specify a defined constant instead of a numeric value.

Fixes 0007586
Affected Issues
0007586
mod - adm_config_report.php Diff File
mod - adm_config_set.php Diff File
mod - core/constant_inc.php Diff File
mod - core/print_api.php Diff File

MantisBT: master 57f57409

2013-03-08 11:01

dregad


Details Diff
Make it possible to edit config options in adm_config_report.php

Use CONFIG_TYPE_xxx constants instead of magic strings to define the
type of config value to process.

Added code for FLOAT type which was previously handled through COMPLEX.

Improve handling of INT (and FLOAT) by calling constant_replace(),
allowing user to specify a defined constant instead of a numeric value.

The 'Username', 'Project Name' and 'Configuration Option' fields in the
'Set Configuration Option' form are preset to the corresponding value
from the filter or defaulting to ALL_USERS, ALL_PROJECTS and blank
respectively if the filter is not defined or set to '[any]'. This allows
easier definition of related config, e.g. for a given project or user.

Port of 1.2.x commits
- 8890b218892d56947e6ffe300d0186b1450d0481
- 8b426cfc6c6ea7149beeafb352fa390dbf8c4624
- 5858a659efe12743b4360da11e9320c7f6ac6e82

Fixes 0007586, 0015416
Affected Issues
0007586, 0015416
mod - adm_config_report.php Diff File
mod - adm_config_set.php Diff File
mod - core/constant_inc.php Diff File
mod - core/print_api.php Diff File