Fix #11417: Allow EVENT_MENU_MAIN plugin events to return null
[mantis/radio.git] / adm_config_set.php
blob006fd569b27d3765cb5cc9f9efe028bd99488cd6
1 <?php
2 # MantisBT - A PHP based bugtracking system
4 # MantisBT is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 2 of the License, or
7 # (at your option) any later version.
9 # MantisBT is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with MantisBT. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * This page stores the reported bug
20 * @package MantisBT
21 * @copyright Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
22 * @copyright Copyright (C) 2002 - 2010 MantisBT Team - mantisbt-dev@lists.sourceforge.net
23 * @link http://www.mantisbt.org
25 * @uses core.php
26 * @uses access_api.php
27 * @uses config_api.php
28 * @uses constant_inc.php
29 * @uses error_api.php
30 * @uses form_api.php
31 * @uses gpc_api.php
32 * @uses print_api.php
33 * @uses project_api.php
34 * @uses utility_api.php
37 require_once( 'core.php' );
38 require_api( 'access_api.php' );
39 require_api( 'config_api.php' );
40 require_api( 'constant_inc.php' );
41 require_api( 'error_api.php' );
42 require_api( 'form_api.php' );
43 require_api( 'gpc_api.php' );
44 require_api( 'print_api.php' );
45 require_api( 'project_api.php' );
46 require_api( 'utility_api.php' );
48 form_security_validate( 'adm_config_set' );
50 $f_user_id = gpc_get_int( 'user_id' );
51 $f_project_id = gpc_get_int( 'project_id' );
52 $f_config_option = gpc_get_string( 'config_option' );
53 $f_type = gpc_get_string( 'type' );
54 $f_value = gpc_get_string( 'value' );
56 if ( is_blank( $f_config_option ) ) {
57 error_parameters( 'config_option' );
58 trigger_error( ERROR_EMPTY_FIELD, ERROR );
61 access_ensure_global_level( config_get( 'set_configuration_threshold' ) );
63 if ( $f_project_id != ALL_PROJECTS ) {
64 project_ensure_exists( $f_project_id );
67 # make sure that configuration option specified is a valid one.
68 $t_not_found_value = '***CONFIG OPTION NOT FOUND***';
69 if ( config_get_global( $f_config_option, $t_not_found_value ) === $t_not_found_value ) {
70 error_parameters( $f_config_option );
71 trigger_error( ERROR_CONFIG_OPT_NOT_FOUND, ERROR );
74 # make sure that configuration option specified can be stored in the database
75 if ( !config_can_set_in_database( $f_config_option ) ) {
76 error_parameters( $f_config_option );
77 trigger_error( ERROR_CONFIG_OPT_CANT_BE_SET_IN_DB, ERROR );
80 if ( $f_type === 'default' ) {
81 $t_config_global_value = config_get_global( $f_config_option );
82 if ( is_string( $t_config_global_value ) ) {
83 $t_type = 'string';
84 } else if ( is_int( $t_config_global_value ) ) {
85 $t_type = 'integer';
86 } else { # note that we consider bool and float as complex. We use ON/OFF for bools which map to numeric.
87 $t_type = 'complex';
89 } else {
90 $t_type = $f_type;
93 if ( $t_type === 'string' ) {
94 $t_value = $f_value;
95 } else if ( $t_type === 'integer' ) {
96 $t_value = (integer)$f_value;
97 } else {
98 # We support these kind of variables here:
99 # 1. constant values (like the ON/OFF switches): they are defined as constants mapping to numeric values
100 # 2. simple arrays with the form: array( a, b, c, d )
101 # 3. associative arrays with the form: array( a=>1, b=>2, c=>3, d=>4 )
102 $t_full_string = trim( $f_value );
103 if ( preg_match('/array[\s]*\((.*)\)/', $t_full_string, $t_match ) === 1 ) {
104 // we have an array here
105 $t_values = explode( ',', trim( $t_match[1] ) );
106 foreach ( $t_values as $key => $value ) {
107 $t_split = explode( '=>', $value, 2 );
108 if ( count( $t_split ) == 2 ) {
109 // associative array
110 $t_new_key = constant_replace( trim( $t_split[0] ) );
111 $t_new_value = constant_replace( trim( $t_split[1] ) );
112 $t_value[ $t_new_key ] = $t_new_value;
113 } else {
114 // regular array
115 $t_value[ $key ] = constant_replace( trim( $value ) );
118 } else {
119 // scalar value
120 $t_value = constant_replace( trim( $t_full_string ) );
124 config_set( $f_config_option, $t_value, $f_user_id, $f_project_id );
126 form_security_purge( 'adm_config_set' );
128 print_successful_redirect( 'adm_config_report.php' );
132 * Check if the passed string is a constant and return its value
134 function constant_replace( $p_name ) {
135 $t_result = $p_name;
136 if ( is_string( $p_name ) && defined( $p_name ) ) {
137 // we have a constant
138 $t_result = constant( $p_name );
140 return $t_result;