1<?php
2# MantisBT - A PHP based bugtracking system
3
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.
8#
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.
13#
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/>.
16
17/**
18 * Manage configuration for workflow Config
19 *
20 * @package MantisBT
21 * @copyright Copyright 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
22 * @copyright Copyright 2002  MantisBT Team - mantisbt-dev@lists.sourceforge.net
23 * @link http://www.mantisbt.org
24 *
25 * @uses core.php
26 * @uses access_api.php
27 * @uses authentication_api.php
28 * @uses config_api.php
29 * @uses constant_inc.php
30 * @uses form_api.php
31 * @uses helper_api.php
32 * @uses html_api.php
33 * @uses lang_api.php
34 * @uses print_api.php
35 * @uses project_api.php
36 * @uses string_api.php
37 * @uses user_api.php
38 */
39
40require_once( 'core.php' );
41require_api( 'access_api.php' );
42require_api( 'authentication_api.php' );
43require_api( 'config_api.php' );
44require_api( 'constant_inc.php' );
45require_api( 'form_api.php' );
46require_api( 'helper_api.php' );
47require_api( 'html_api.php' );
48require_api( 'lang_api.php' );
49require_api( 'print_api.php' );
50require_api( 'project_api.php' );
51require_api( 'string_api.php' );
52require_api( 'user_api.php' );
53
54auth_reauthenticate();
55
56layout_page_header( lang_get( 'manage_threshold_config' ) );
57
58layout_page_begin( 'manage_overview_page.php' );
59
60print_manage_menu( PAGE_CONFIG_DEFAULT );
61print_manage_config_menu( 'manage_config_work_threshold_page.php' );
62
63$g_user = auth_get_current_user_id();
64$g_project_id = helper_get_current_project();
65$t_show_submit = false;
66
67$g_access_levels = MantisEnum::getAssocArrayIndexedByValues( config_get( 'access_levels_enum_string' ) );
68$g_overrides = array();
69
70/**
71 * Set overrides
72 * @param string $p_config Configuration value.
73 * @return void
74 */
75function set_overrides( $p_config ) {
76	global $g_overrides;
77	if( !in_array( $p_config, $g_overrides ) ) {
78		$g_overrides[] = $p_config;
79	}
80}
81
82/**
83 * Section header
84 * @param string $p_section_name Section name.
85 * @return void
86 */
87function get_section_begin_mcwt( $p_section_name ) {
88	global $g_access_levels;
89
90	echo '<div class="space-10"></div>';
91	echo '<div class="widget-box widget-color-blue2">';
92	echo '   <div class="widget-header widget-header-small">';
93	echo '        <h4 class="widget-title lighter uppercase">';
94	print_icon( 'fa-sliders', 'ace-icon' );
95	echo $p_section_name;
96	echo '       </h4>';
97	echo '   </div>';
98	echo '   <div class="widget-body">';
99	echo '   <div class="widget-main no-padding">';
100	echo '       <div class="table-responsive">';
101	echo '<table class="table table-striped table-bordered table-condensed">';
102	echo '<thead>';
103	echo '<tr>';
104	echo '<th class="bold" width="40%" rowspan="2">' . lang_get( 'perm_rpt_capability' ) . '</th>';
105	echo '<th class="bold" style="text-align:center"  width="40%" colspan="' . count( $g_access_levels ) . '">' . lang_get( 'allowed_access_levels' ) . '</th>';
106	echo '<th class="bold" style="text-align:center" rowspan="2">&#160;' . lang_get( 'alter_level' ) . '&#160;</th>';
107	echo '</tr><tr>';
108	foreach( $g_access_levels as $t_access_level => $t_access_label ) {
109		echo '<th class="bold" style="text-align:center">&#160;' . MantisEnum::getLabel( lang_get( 'access_levels_enum_string' ), $t_access_level ) . '&#160;</th>';
110	}
111	echo '</tr>' . "\n";
112	echo '</thead>';
113	echo '<tbody>';
114}
115
116/**
117 * Defines the cell's background color and sets the overrides
118 * @param string  $p_threshold    Configuration option.
119 * @param string  $p_file         System default value.
120 * @param string  $p_global       All projects value.
121 * @param string  $p_project      Current project value.
122 * @param boolean $p_set_override If true, will define an override if needed.
123 * @return string HTML tag attribute for background color override
124 */
125function set_color( $p_threshold, $p_file, $p_global, $p_project, $p_set_override ) {
126	global $g_project_id;
127
128	$t_color = '';
129
130	# all projects override
131	if( $p_global != $p_file ) {
132		$t_color = 'color-global';
133		if( $p_set_override && ALL_PROJECTS == $g_project_id ) {
134			set_overrides( $p_threshold );
135		}
136	}
137
138	# project overrides
139	if( $p_project != $p_global ) {
140		$t_color = 'color-project';
141		if( $p_set_override && ALL_PROJECTS != $g_project_id ) {
142			set_overrides( $p_threshold );
143		}
144	}
145
146	return $t_color;
147}
148
149/**
150 * Prints selection list or value of who is allowed to change the capability
151 * @param string  $p_threshold  Capability.
152 * @param boolean $p_can_change If true, prints a selection list otherwise just display value.
153 * @return void
154 */
155function print_who_can_change( $p_threshold, $p_can_change ) {
156	static $s_file_access = null;
157
158	if( is_null( $s_file_access ) ) {
159		$t_file_access = config_get_global( 'admin_site_threshold' );
160	}
161	$t_global_access = config_get_access( $p_threshold, ALL_USERS, ALL_PROJECTS );
162	$t_project_access = config_get_access( $p_threshold );
163
164	$t_color = set_color( $p_threshold, $t_file_access, $t_global_access, $t_project_access, $p_can_change );
165
166	echo '<td class="' . $t_color . '">';
167	if( $p_can_change ) {
168		echo '<select name="access_' . $p_threshold . '" class="input-sm">';
169		print_enum_string_option_list( 'access_levels', $t_project_access );
170		echo '</select>';
171	} else {
172		echo MantisEnum::getLabel( lang_get( 'access_levels_enum_string' ), $t_project_access ) . '&#160;';
173	}
174	echo "</td>\n";
175}
176
177/**
178 * Get row
179 * @param string  $p_caption           Caption.
180 * @param string  $p_threshold         Threshold.
181 * @param boolean $p_all_projects_only All projects only.
182 * @return void
183 */
184function get_capability_row( $p_caption, $p_threshold, $p_all_projects_only = false ) {
185	global $g_user, $g_project_id, $t_show_submit, $g_access_levels;
186
187	$t_file = config_get_global( $p_threshold );
188	if( !is_array( $t_file ) ) {
189		$t_file_exp = array();
190		foreach( $g_access_levels as $t_access_level => $t_label ) {
191			if( $t_access_level >= $t_file ) {
192				$t_file_exp[] = $t_access_level;
193			}
194		}
195	} else {
196		$t_file_exp = $t_file;
197	}
198
199	$t_global = config_get( $p_threshold, null, ALL_USERS, ALL_PROJECTS );
200	if( !is_array( $t_global ) ) {
201		$t_global_exp = array();
202		foreach( $g_access_levels as $t_access_level => $t_label ) {
203			if( $t_access_level >= $t_global ) {
204				$t_global_exp[] = $t_access_level;
205			}
206		}
207	} else {
208		$t_global_exp = $t_global;
209	}
210
211	$t_project = config_get( $p_threshold );
212	if( !is_array( $t_project ) ) {
213		$t_project_exp = array();
214		foreach( $g_access_levels as $t_access_level => $t_label ) {
215			if( $t_access_level >= $t_project ) {
216				$t_project_exp[] = $t_access_level;
217			}
218		}
219	} else {
220		$t_project_exp = $t_project;
221	}
222
223	$t_can_change = access_has_project_level( config_get_access( $p_threshold ), $g_project_id, $g_user )
224			  && ( ( ALL_PROJECTS == $g_project_id ) || !$p_all_projects_only );
225
226	echo "<tr>\n";
227
228	# Access levels
229	echo '  <td>', string_display( $p_caption ),
230			'<input type="hidden" name="flag_exists_' . $p_threshold . '[]" value="1" />',
231			"</td>\n";
232	foreach( $g_access_levels as $t_access_level => $t_access_label ) {
233		$t_file = in_array( $t_access_level, $t_file_exp );
234		$t_global = in_array( $t_access_level, $t_global_exp );
235		$t_project = in_array( $t_access_level, $t_project_exp );
236
237		$t_color = set_color( $p_threshold, $t_file, $t_global, $t_project, $t_can_change );
238
239		if( $t_can_change ) {
240			$t_checked = $t_project ? 'checked="checked"' : '';
241			$t_value = '<label><input type="checkbox" class="ace" name="flag_thres_' . $p_threshold .
242				'[]" value="' . $t_access_level . '" ' . $t_checked . ' /><span class="lbl"></span></label>';
243			$t_show_submit = true;
244		} else {
245			if( $t_project ) {
246				$t_value = icon_get( 'fa-check', 'fa-lg blue' );
247			} else {
248				$t_value = '&#160;';
249			}
250		}
251		echo '  <td class="center ' . $t_color . '">' . $t_value . "</td>\n";
252	}
253
254	print_who_can_change( $p_threshold, $t_can_change );
255
256	echo "</tr>\n";
257}
258
259/**
260 * Get boolean row
261 * @param string  $p_caption           Caption.
262 * @param string  $p_threshold         Threshold.
263 * @param boolean $p_all_projects_only All projects only.
264 * @return void
265 */
266function get_capability_boolean( $p_caption, $p_threshold, $p_all_projects_only = false ) {
267	global $g_user, $g_project_id, $t_show_submit, $g_access_levels;
268
269	$t_file = config_get_global( $p_threshold );
270	$t_global = config_get( $p_threshold, null, ALL_USERS, ALL_PROJECTS );
271	$t_project = config_get( $p_threshold );
272
273	$t_can_change = access_has_project_level( config_get_access( $p_threshold ), $g_project_id, $g_user )
274			  && ( ( ALL_PROJECTS == $g_project_id ) || !$p_all_projects_only );
275
276	echo "<tr>\n\t<td>", string_display_line( $p_caption ),
277			'<input type="hidden" name="flag_exists_' . $p_threshold . '[]" value="1" />',
278			"</td>\n";
279
280	# Value
281	$t_color = set_color( $p_threshold, $t_file, $t_global, $t_project, $t_can_change );
282	if( $t_can_change ) {
283		$t_checked = ( ON == config_get( $p_threshold ) ) ? 'checked="checked"' : '';
284		$t_value = '<label><input type="checkbox" class="ace" name="flag_' . $p_threshold . '" value="1" ' .
285			$t_checked . ' /><span class="lbl"></span></label>';
286		$t_show_submit = true;
287	} else {
288		if( ON == config_get( $p_threshold ) ) {
289			$t_value = icon_get( 'fa-check', 'fa-lg blue' );
290		} else {
291			$t_value = '&#160;';
292		}
293	}
294	echo "\t" . '<td class="center ' . $t_color . '">' . $t_value . '</td>' . "\n\t"
295		. '<td class="left" colspan="' . ( count( $g_access_levels ) - 1 ). '"></td>';
296
297	print_who_can_change( $p_threshold, $t_can_change );
298
299	echo '</tr>' . "\n";
300}
301
302/**
303 * Get enumeration row
304 * @param string  $p_caption           Caption.
305 * @param string  $p_threshold         Threshold.
306 * @param string  $p_enum              Enumeration.
307 * @param boolean $p_all_projects_only All projects only.
308 * @return void
309 */
310function get_capability_enum( $p_caption, $p_threshold, $p_enum, $p_all_projects_only = false ) {
311	global $g_user, $g_project_id, $t_show_submit, $g_access_levels;
312
313	$t_file = config_get_global( $p_threshold );
314	$t_global = config_get( $p_threshold, null, ALL_USERS, ALL_PROJECTS );
315	$t_project = config_get( $p_threshold );
316
317	$t_can_change = access_has_project_level( config_get_access( $p_threshold ), $g_project_id, $g_user )
318			  && ( ( ALL_PROJECTS == $g_project_id ) || !$p_all_projects_only );
319
320	echo '<tr>' . "\n";
321	echo "\t" . '<td>' . string_display_line( $p_caption ) . '</td>' . "\n";
322
323	# Value
324	$t_color = set_color( $p_threshold, $t_file, $t_global, $t_project, $t_can_change );
325	echo "\t" . '<td class="left ' . $t_color . '" colspan="3">';
326	if( $t_can_change ) {
327		echo '<select name="flag_' . $p_threshold . '" class="input-sm">';
328		print_enum_string_option_list( $p_enum, config_get( $p_threshold ) );
329		echo '</select>';
330		$t_show_submit = true;
331	} else {
332		$t_value = MantisEnum::getLabel( lang_get( $p_enum . '_enum_string' ), config_get( $p_threshold ) ) . '&#160;';
333		echo $t_value;
334	}
335	echo '</td>' . "\n\t" . '<td colspan="' . ( count( $g_access_levels ) - 3 ) . '"></td>' . "\n";
336
337	print_who_can_change( $p_threshold, $t_can_change );
338
339	echo '</tr>' . "\n";
340}
341
342/**
343 * Print section end
344 * @return void
345 */
346function get_section_end() {
347	echo '</tbody></table></div>' . "\n";
348	echo '</div></div></div> ' . "\n";
349	echo '<div class="space-10"></div>';
350}
351
352
353echo '<br />' . "\n";
354
355if( ALL_PROJECTS == $g_project_id ) {
356	$t_project_title = lang_get( 'config_all_projects' );
357} else {
358	$t_project_title = sprintf( lang_get( 'config_project' ), string_display_line( project_get_name( $g_project_id ) ) );
359}
360
361echo '<div class="col-md-12 col-xs-12">' . "\n";
362echo '<div class="well">' . "\n";
363echo '<p class="bold">' . icon_get( 'fa-info-circle' ) . " $t_project_title</p>\n";
364echo '<p>' . lang_get( 'colour_coding' ) . '<br />';
365if( ALL_PROJECTS <> $g_project_id ) {
366	echo '<span class="color-project">' . lang_get( 'colour_project' ) .'</span><br />';
367}
368echo '<span class="color-global">' . lang_get( 'colour_global' ) . '</span></p>';
369echo '</div>' . "\n";
370
371echo '<form id="mail_config_action" method="post" action="manage_config_work_threshold_set.php">' . "\n";
372echo form_security_field( 'manage_config_work_threshold_set' );
373
374# Issues
375get_section_begin_mcwt( lang_get( 'issues' ) );
376get_capability_row( lang_get( 'report_issue' ), 'report_bug_threshold' );
377get_capability_enum( lang_get( 'submit_status' ), 'bug_submit_status', 'status' );
378get_capability_row( lang_get( 'update_issue' ), 'update_bug_threshold' );
379get_capability_boolean( lang_get( 'allow_reporter_close' ), 'allow_reporter_close' );
380get_capability_row( lang_get( 'monitor_issue' ), 'monitor_bug_threshold' );
381get_capability_row( lang_get( 'handle_issue' ), 'handle_bug_threshold' );
382get_capability_row( lang_get( 'assign_issue' ), 'update_bug_assign_threshold' );
383get_capability_row( lang_get( 'move_issue' ), 'move_bug_threshold', true );
384get_capability_row( lang_get( 'delete_issue' ), 'delete_bug_threshold' );
385get_capability_row( lang_get( 'reopen_issue' ), 'reopen_bug_threshold' );
386get_capability_boolean( lang_get( 'allow_reporter_reopen' ), 'allow_reporter_reopen' );
387get_capability_enum( lang_get( 'reopen_status' ), 'bug_reopen_status', 'status' );
388get_capability_enum( lang_get( 'reopen_resolution' ), 'bug_reopen_resolution', 'resolution' );
389get_capability_enum( lang_get( 'resolved_status' ), 'bug_resolved_status_threshold', 'status' );
390get_capability_enum( lang_get( 'readonly_status' ), 'bug_readonly_status_threshold', 'status' );
391get_capability_row( lang_get( 'update_readonly_issues' ), 'update_readonly_bug_threshold' );
392get_capability_row( lang_get( 'update_issue_status' ), 'update_bug_status_threshold' );
393get_capability_row( lang_get( 'view_private_issues' ), 'private_bug_threshold' );
394get_capability_row( lang_get( 'set_view_status' ), 'set_view_status_threshold' );
395get_capability_row( lang_get( 'update_view_status' ), 'change_view_status_threshold' );
396get_capability_row( lang_get( 'view_issue_revisions' ), 'bug_revision_view_threshold' );
397get_capability_row( lang_get( 'drop_issue_revisions' ), 'bug_revision_drop_threshold' );
398get_capability_row( lang_get( 'set_sticky' ), 'set_bug_sticky_threshold' );
399get_capability_row( lang_get( 'show_list_of_users_monitoring_issue' ), 'show_monitor_list_threshold' );
400get_capability_row( lang_get( 'add_users_monitoring_issue' ), 'monitor_add_others_bug_threshold' );
401get_capability_row( lang_get( 'remove_users_monitoring_issue' ), 'monitor_delete_others_bug_threshold' );
402get_capability_boolean( lang_get( 'set_status_assigned' ), 'auto_set_status_to_assigned' );
403get_capability_enum( lang_get( 'assigned_status' ), 'bug_assigned_status', 'status' );
404if( ON == config_get( 'limit_reporters', null, ALL_USERS, ALL_PROJECTS ) ) {
405	get_capability_boolean( lang_get( 'limit_access' ), 'limit_reporters', true );
406} else {
407	get_capability_row( lang_get( 'limit_view_unless_threshold_option' ), 'limit_view_unless_threshold' );
408}
409get_section_end();
410
411# Notes
412get_section_begin_mcwt( lang_get( 'notes' ) );
413get_capability_row( lang_get( 'add_notes' ), 'add_bugnote_threshold' );
414get_capability_row( lang_get( 'edit_others_bugnotes' ), 'update_bugnote_threshold' );
415get_capability_row( lang_get( 'edit_own_bugnotes' ), 'bugnote_user_edit_threshold' );
416get_capability_row( lang_get( 'delete_others_bugnotes' ), 'delete_bugnote_threshold' );
417get_capability_row( lang_get( 'delete_own_bugnotes' ), 'bugnote_user_delete_threshold' );
418get_capability_row( lang_get( 'view_private_notes' ), 'private_bugnote_threshold' );
419get_capability_row( lang_get( 'change_view_state_own_bugnotes' ), 'bugnote_user_change_view_state_threshold' );
420get_section_end();
421
422# Tags
423get_section_begin_mcwt( lang_get( 'tags' ) );
424get_capability_row( lang_get( 'view_tags' ), 'tag_view_threshold' );
425get_capability_row( lang_get( 'attach_tags' ), 'tag_attach_threshold' );
426get_capability_row( lang_get( 'detach_tags' ), 'tag_detach_threshold' );
427get_capability_row( lang_get( 'detach_own_tags' ), 'tag_detach_own_threshold' );
428get_capability_row( lang_get( 'create_new_tags' ), 'tag_create_threshold' );
429get_capability_row( lang_get( 'edit_tags' ), 'tag_edit_threshold' );
430get_capability_row( lang_get( 'edit_own_tags' ), 'tag_edit_own_threshold' );
431get_section_end();
432
433# Attachments
434if( config_get( 'allow_file_upload' ) == ON ) {
435	get_section_begin_mcwt( lang_get( 'attachments' ) );
436	get_capability_row( lang_get( 'view_list_of_attachments' ), 'view_attachments_threshold' );
437	get_capability_row( lang_get( 'download_attachments' ), 'download_attachments_threshold' );
438	get_capability_row( lang_get( 'delete_attachments' ), 'delete_attachments_threshold' );
439	get_capability_row( lang_get( 'upload_issue_attachments' ), 'upload_bug_file_threshold' );
440	get_section_end();
441}
442
443# Others
444get_section_begin_mcwt( lang_get( 'others' ) );
445get_capability_row( lang_get( 'view' ) . ' ' . lang_get( 'changelog_link' ), 'view_changelog_threshold' );
446get_capability_row( lang_get( 'view' ) . ' ' . lang_get( 'roadmap_link' ), 'roadmap_view_threshold' );
447get_capability_row( lang_get( 'view' ) . ' ' . lang_get( 'summary_link' ), 'view_summary_threshold' );
448get_capability_row( lang_get( 'view' ) . ' ' . lang_get( 'assigned_to' ), 'view_handler_threshold' );
449get_capability_row( lang_get( 'view' ) . ' ' . lang_get( 'bug_history' ), 'view_history_threshold' );
450get_capability_row( lang_get( 'send_reminders' ), 'bug_reminder_threshold' );
451get_capability_row( lang_get( 'receive_reminders' ), 'reminder_receive_threshold' );
452get_section_end();
453
454
455if( $t_show_submit ) {
456	echo '<input type="submit" class="btn btn-primary btn-white btn-round" value="' . lang_get( 'change_configuration' ) . '" />' . "\n";
457}
458
459echo '</form>' . "\n";
460
461if( $t_show_submit && ( 0 < count( $g_overrides ) ) ) {
462	echo '<div class="pull-right"><form id="threshold_config_action" method="post" action="manage_config_revert.php">' . "\n";
463	echo form_security_field( 'manage_config_revert' );
464	echo '<input name="revert" type="hidden" value="' . implode( ',', $g_overrides ) . '"></input>';
465	echo '<input name="project" type="hidden" value="' . $g_project_id . '"></input>';
466	echo '<input name="return" type="hidden" value="' . string_attribute( form_action_self() ) .'"></input>';
467	echo '<input type="submit" class="btn btn-primary btn-sm btn-white btn-round" value="';
468	if( ALL_PROJECTS == $g_project_id ) {
469		echo lang_get( 'revert_to_system' );
470	} else {
471		echo lang_get( 'revert_to_all_project' );
472	}
473	echo '" />' . "\n";
474	echo '</form></div>' . "\n";
475}
476echo '</div>';
477layout_page_end();
478