forked from mantisbt/mantisbt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
adm_config_page.php
303 lines (275 loc) · 9.03 KB
/
adm_config_page.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
<?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/>.
/**
* Mantis Configuration. View, edit, update a configuration option.
* @package MantisBT
* @copyright Copyright 2000 - 2002 Kenzaburo Ito - [email protected]
* @copyright Copyright 2002 MantisBT Team - [email protected]
* @link http://www.mantisbt.org
*
* @uses core.php
* @uses access_api
* @uses config_api
* @uses constant_inc.php
* @uses error_api
* @uses form_api
* @uses gpc_api
* @uses helper_api
* @uses lang_api
* @uses layout_api
* @uses print_api
* @uses string_api
* @uses user_api
*/
require_once( 'core.php' );
require_api( 'access_api.php' );
require_api( 'config_api.php' );
require_api( 'constant_inc.php' );
require_api( 'error_api.php' );
require_api( 'form_api.php' );
require_api( 'gpc_api.php' );
require_api( 'helper_api.php' );
require_api( 'lang_api.php' );
require_api( 'layout_api.php' );
require_api( 'print_api.php' );
require_api( 'string_api.php' );
require_api( 'user_api.php' );
access_ensure_global_level( config_get( 'view_configuration_threshold' ) );
$t_has_write_access = access_has_global_level( config_get( 'set_configuration_threshold' ) );
layout_page_header( lang_get( 'configuration_report' ) );
layout_page_begin( 'manage_overview_page.php' );
print_manage_menu( PAGE_CONFIG_DEFAULT );
print_manage_config_menu( 'adm_config_report.php' );
# Get request values
$f_edit_user_id = gpc_get_int( 'user_id', ALL_USERS );
$f_edit_project_id = gpc_get_int( 'project_id', ALL_PROJECTS );
$f_edit_option = gpc_get_string( 'config_option', null );
$f_edit_action = gpc_get_string( 'action', MANAGE_CONFIG_ACTION_VIEW );
# Ensure we exclusively use one of the defined, valid actions (XSS protection)
$t_valid_actions = array(
MANAGE_CONFIG_ACTION_CREATE,
MANAGE_CONFIG_ACTION_CLONE,
MANAGE_CONFIG_ACTION_EDIT,
MANAGE_CONFIG_ACTION_VIEW
);
$t_edit_action = in_array( $f_edit_action, $t_valid_actions )
? $f_edit_action
: MANAGE_CONFIG_ACTION_CREATE;
# if not creating a new option, the option name is required
if( MANAGE_CONFIG_ACTION_CREATE != $t_edit_action && null == $f_edit_option ) {
error_parameters( 'config_option' );
trigger_error( ERROR_EMPTY_FIELD, ERROR );
}
# see if the user can modify configuration options
$t_modify = MANAGE_CONFIG_ACTION_VIEW != $t_edit_action
&& $t_has_write_access
&& config_can_delete( $f_edit_option );
# if can't modify, switch antion to "view"
if( !$t_modify ) {
$t_edit_action = MANAGE_CONFIG_ACTION_VIEW;
}
$t_action_label = lang_get( 'set_configuration_option_action_' . $t_edit_action );
if( MANAGE_CONFIG_ACTION_CREATE != $t_edit_action ) {
# retrieve existing config data from database for this option
$t_query = new DbQuery( 'SELECT * FROM {config} WHERE config_id = :config AND user_id = :user AND project_id = :project' );
$t_query->bind_values( array(
'config' => $f_edit_option,
'user' => $f_edit_user_id,
'project' => $f_edit_project_id
) );
$t_config_row = $t_query->fetch();
if( !$t_config_row ) {
# this error will be triggered if the exact config combination does not exist in database
error_parameters( $f_edit_option );
trigger_error( ERROR_CONFIG_OPT_NOT_FOUND, ERROR );
}
$t_option_user_id = (int)$t_config_row['user_id'];
$t_option_project_id = (int)$t_config_row['project_id'];
$t_option_id = $t_config_row['config_id'];
$t_option_type = $t_config_row['type'];
$t_option_value = $t_config_row['value'];
} else {
# action is MANAGE_CONFIG_ACTION_CREATE
# prepare new or default values
$t_option_user_id = $f_edit_user_id;
$t_option_project_id = $f_edit_project_id;
$t_option_id = $f_edit_option ?? '';
$t_option_type = CONFIG_TYPE_DEFAULT;
$t_option_value = '';
if( '' != $t_option_id ) {
# if an option has been provided,
# make sure that configuration option specified is a valid one.
$t_not_found_value = '***CONFIG OPTION NOT FOUND***';
if( config_get( $t_option_id, $t_not_found_value ) === $t_not_found_value ) {
error_parameters( $t_option_id );
trigger_error( ERROR_CONFIG_OPT_NOT_FOUND, ERROR );
}
}
}
?>
<div class="col-md-12 col-xs-12">
<div class="space-10"></div>
<div id="config-edit-div">
<form id="config_set_form" method="post" action="<?php echo ( $t_modify? 'adm_config_set.php' : '' ) ?>">
<!-- Title -->
<div class="widget-box widget-color-blue2">
<div class="widget-header widget-header-small">
<h4 class="widget-title lighter">
<?php print_icon( 'fa-sliders', 'ace-icon' ); ?>
<?php echo $t_action_label; ?>
</h4>
</div>
<div class="widget-body">
<div class="widget-main no-padding">
<div id="config-edit-div" class="form-container">
<div class="table-responsive">
<table class="table table-bordered table-condensed table-striped">
<fieldset>
<?php
if( $t_modify ) {
echo form_security_field( 'adm_config_set' );
}
?>
<!-- Username -->
<tr>
<td class="category">
<?php echo lang_get( 'username' ) ?>
</td>
<td>
<?php
if( $t_modify ) {
?>
<select id="config-user-id" name="user_id" class="input-sm">
<option value="<?php echo ALL_USERS; ?>"
<?php check_selected( $t_option_user_id, ALL_USERS ) ?>>
<?php echo lang_get( 'all_users' ); ?>
</option>
<?php print_user_option_list( $t_option_user_id ) ?>
</select>
<input type="hidden" name="original_user_id" value="<?php echo $t_option_user_id; ?>" />
<?php
} else {
$t_username = ALL_USERS == $t_option_user_id ? lang_get( 'all_users' ) : user_get_name( $t_option_user_id );
echo string_display_line( $t_username );
}
?>
</td>
</tr>
<!-- Project -->
<tr>
<td class="category">
<?php echo lang_get( 'project_name' ) ?>
</td>
<td>
<?php
if( $t_modify ) {
?>
<select id="config-project-id" name="project_id" class="input-sm">
<option value="<?php echo ALL_PROJECTS; ?>"
<?php check_selected( $t_option_project_id, ALL_PROJECTS ); ?>>
<?php echo lang_get( 'all_projects' ); ?>
</option>
<?php print_project_option_list( $t_option_project_id, false ) ?>
</select>
<input type="hidden" name="original_project_id" value="<?php echo $t_option_project_id; ?>" />
<?php
} else {
echo string_display_line( project_get_name( $t_option_project_id ) );
}
?>
</td>
</tr>
<!-- Config option name -->
<tr>
<td class="category">
<?php echo lang_get( 'configuration_option' ) ?>
</td>
<td>
<?php
$c_option_id = string_display_line( $t_option_id );
if( $t_modify ) {
?>
<input type="text" name="config_option" class="input-sm"
value="<?php echo $c_option_id ?>"
size="64" maxlength="64" />
<input type="hidden" name="original_config_option" value="<?php echo $c_option_id; ?>" />
<?php
} else {
echo $c_option_id;
}
?>
</td>
</tr>
<!-- Option type -->
<tr>
<td class="category">
<?php echo lang_get( 'configuration_option_type' ) ?>
</td>
<td>
<?php
if( $t_modify ) {
?>
<select id="config-type" name="type" class="input-sm">
<?php print_option_list_from_array( config_get_types(), $t_option_type ); ?>
</select>
<?php
} else {
echo string_display_line( config_get_type_string( $t_option_type ) );
}
?>
</td>
</tr>
<!-- Option Value -->
<tr>
<td class="category">
<?php echo lang_get( 'configuration_option_value' ) ?>
</td>
<td>
<?php
if( $t_modify ) {
?>
<textarea class="form-control" name="value" cols="80" rows="10"><?php
echo config_get_value_as_string( $t_option_type, $t_option_value, false );
?></textarea>
<?php
} else {
echo config_get_value_as_string( $t_option_type, $t_option_value, true );
}
?>
</td>
</tr>
</fieldset>
</table>
</div>
</div>
<div class="widget-toolbox padding-4 clearfix">
<?php
if( $t_modify ) {
?>
<input type="hidden" name="action" value="<?php echo $t_edit_action; ?>" />
<input type="submit" name="config_set" class="btn btn-primary btn-white btn-round"
value="<?php echo $t_action_label; ?>"/>
<?php
}
?>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
<?php
layout_page_end();