<?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__ );
?>