Skip to content

Commit

Permalink
Issue #14559: improve adm_report_config.php filter
Browse files Browse the repository at this point in the history
The following changes were made

- revised UI to make it more similar to the issues filter
- make use of existing constants and language strings
- filter defaults to All Users / All Projects / All options which avoids
  performance issues in installations having a large number of entries
  in the config table (workaround for issue #13680)
- filter form uses post instead of get method
- comply to coding guidelines
  • Loading branch information
dregad committed Dec 14, 2012
1 parent f8a81a3 commit 259f95c
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 64 deletions.
140 changes: 78 additions & 62 deletions adm_config_report.php
Expand Up @@ -88,90 +88,92 @@ function print_config_value_as_string( $p_type, $p_value ) {
echo '</pre>';
}

$t_config_table = db_get_table( 'mantis_config_table' );
function print_option_list_from_array( $p_array, $p_filter_value ) {
foreach( $p_array as $t_key => $t_value ) {
echo "<option value='$t_key'";
check_selected( $p_filter_value, $t_key );
echo ">$t_value</option>\n";
}
}

# Get filter values
$t_filter_user_value = gpc_get_int( 'filter_user_id', ALL_USERS );
$t_filter_project_value = gpc_get_int( 'filter_project_id', ALL_PROJECTS );
$t_filter_config_value = gpc_get_string( 'filter_config_id', META_FILTER_NONE );

# Apply filters
$t_config_table = db_get_table( 'mantis_config_table' );
$t_user_table = db_get_table( 'mantis_user_table' );
$t_project_table = db_get_table( 'mantis_project_table' );
# Get users in db with specific configs
$query = "SELECT DISTINCT user_id, ut.realname as username, ut.username as idrh
FROM $t_config_table as ct
JOIN $t_user_table as ut
ON ut.id=ct.user_id
ORDER BY username";
$t_result = db_query_bound($query);
FROM $t_config_table as ct
JOIN $t_user_table as ut ON ut.id = ct.user_id
ORDER BY username";
$t_result = db_query_bound( $query );
$t_users_list = array();
$t_users_list[-1] = '<i>'.lang_get("none_filter").'</i>';
$t_users_list[ALL_USERS] = lang_get("all_users");
$t_users_list[META_FILTER_NONE] = '[' . lang_get( 'any' ) . ']';
$t_users_list[ALL_USERS] = lang_get( 'all_users' );
while ( $row = db_fetch_array( $t_result ) ) {
extract( $row, EXTR_PREFIX_ALL, 'v' );
$t_users_list[$v_user_id] = "$v_username ($v_idrh)";
}

# Get projects in db with specific configs
$query = "SELECT DISTINCT project_id, pt.name as project_name
FROM $t_config_table as ct
JOIN $t_project_table as pt
ON pt.id=ct.project_id
WHERE project_id!=0
ORDER BY project_name";
$t_result = db_query_bound($query);
FROM $t_config_table as ct
JOIN $t_project_table as pt ON pt.id = ct.project_id
WHERE project_id!=0
ORDER BY project_name";
$t_result = db_query_bound( $query );
$t_projects_list = array();
$t_projects_list[-1] = '<i>'.lang_get("none_filter").'</i>';
$t_projects_list[ALL_PROJECTS] = lang_get("all_projects");
$t_projects_list[META_FILTER_NONE] = '[' . lang_get( 'any' ) . ']';
$t_projects_list[ALL_PROJECTS] = lang_get( 'all_projects' );
while ( $row = db_fetch_array( $t_result ) ) {
extract( $row, EXTR_PREFIX_ALL, 'v' );
$t_projects_list[$v_project_id] = $v_project_name;
}

# Get config listused in db
# Get config list used in db
$query = "SELECT DISTINCT config_id
FROM $t_config_table
ORDER BY config_id";
$t_result = db_query_bound($query);
FROM $t_config_table
ORDER BY config_id";
$t_result = db_query_bound( $query );
$t_configs_list = array();
$t_configs_list[-1] = '<i>'.lang_get("none_filter").'</i>';
$t_configs_list[META_FILTER_NONE] = '[' . lang_get( 'any' ) . ']';
while ( $row = db_fetch_array( $t_result ) ) {
extract( $row, EXTR_PREFIX_ALL, 'v' );
$t_configs_list[$v_config_id] = $v_config_id;
}

function print_option_list_from_array($array,$filter_value){
foreach ($array as $key => $value){
if($filter_value == $key){
$selected = " selected='selected' " ;
}else{
$selected ="";
}
echo "<option value='$key' $selected>$value</option>\n";
}

}

$t_filter_user_value = gpc_get_int('filter_user_id',-1);
$t_filter_project_value = gpc_get_int('filter_project_id',-1);
$t_filter_config_value = gpc_get_string('filter_config_id',-1);

$where = '';
if($t_filter_user_value != -1){
$where .= " AND user_id=$t_filter_user_value ";
$t_where = '';
if( $t_filter_user_value != META_FILTER_NONE ) {
$t_where .= " AND user_id = $t_filter_user_value ";
}
if($t_filter_project_value != -1){
$where .= " AND project_id=$t_filter_project_value ";
if( $t_filter_project_value != META_FILTER_NONE ) {
$t_where .= " AND project_id = $t_filter_project_value ";
}
if($t_filter_config_value != -1){
$where .= " AND config_id='$t_filter_config_value' ";
if( $t_filter_config_value != META_FILTER_NONE ) {
$t_where .= " AND config_id = '$t_filter_config_value' ";
}
if($where!=''){
$where = " WHERE 1=1 ".$where;
if( $t_where != '' ) {
$t_where = " WHERE 1=1 " . $t_where;
}

$query = "SELECT config_id, user_id, project_id, type, value, access_reqd FROM $t_config_table $where ORDER BY user_id, project_id, config_id ";
$query = "SELECT config_id, user_id, project_id, type, value, access_reqd
FROM $t_config_table
$t_where
ORDER BY user_id, project_id, config_id ";
$result = db_query_bound( $query );
?>

<br />
<div align="center">
<form action="" name="form_filter">

<!-- FILTER FORM -->
<form name="filter_form" method="post">
<?php # CSRF protection not required here - form does not result in modifications ?>

<table class="width100" cellspacing="1">
<!-- Title -->
<tr>
Expand All @@ -180,42 +182,52 @@ function print_option_list_from_array($array,$filter_value){
</td>
</tr>

<tr class="row-category" style="width:30%;">
<td class="center">
<?php echo lang_get( 'username' );?> : <br />
<select name="filter_user_id" style="width:200px;">
<tr class="row-category2">
<td class="small-caption">
<?php echo lang_get( 'username' ); ?>: <br />
</td>
<td class="small-caption">
<?php echo lang_get( 'project_name' ); ?>: <br />
</td>
<td class="small-caption">
<?php echo lang_get( 'configuration_option' ); ?>: <br />
</td>
</tr>

<tr class="row-1">
<td>
<select name="filter_user_id">
<?php
print_option_list_from_array($t_users_list, $t_filter_user_value);
print_option_list_from_array( $t_users_list, $t_filter_user_value );
?>
</select>
</td>
<td class="center" style="width:30%;">
<?php echo lang_get( 'project_name' );?> : <br />
<select name="filter_project_id" style="width:200px;">
<td>
<select name="filter_project_id">
<?php
print_option_list_from_array($t_projects_list, $t_filter_project_value);
print_option_list_from_array( $t_projects_list, $t_filter_project_value );
?>
</select>
</td>
<td class="center" style="width:40%;">
<?php echo lang_get( 'configuration_option' );?> : <br />
<select name="filter_config_id" style="width:200px;">
<td>
<select name="filter_config_id">
<?php
print_option_list_from_array($t_configs_list, $t_filter_config_value);
print_option_list_from_array( $t_configs_list, $t_filter_config_value );
?>
</select>
</td>
</tr>
<tr>
<td colspan="3">
<input type="submit" value="<?php echo lang_get('filter_button');?>"/>
<input type="submit" class="button-small" value="<?php echo lang_get( 'filter_button' )?>" />
</td>
</tr>
</table>
</form>

<br />

<!-- CONFIGURATIONS LIST -->
<table class="width100" cellspacing="1">

<!-- Title -->
Expand Down Expand Up @@ -286,11 +298,15 @@ function print_option_list_from_array($array,$filter_value){
} # end for loop
?>
</table>


<?php
if ( access_has_global_level( config_get('set_configuration_threshold' ) ) ) {
?>
<br />

<!-- Config Set Form -->

<form method="post" action="adm_config_set.php">
<?php echo form_security_field( 'adm_config_set' ) ?>
<table class="width100" cellspacing="1">
Expand Down
1 change: 0 additions & 1 deletion lang/strings_english.txt
Expand Up @@ -851,7 +851,6 @@ $s_all_users = 'All Users';
$s_set_configuration_option = 'Set Configuration Option';
$s_delete_config_sure_msg = 'Are you sure you wish to delete this configuration option?';
$s_configuration_corrupted = 'The configuration in the database is corrupted.';
$s_none_filter = 'No filter';

# manage_plugin_page.php
$s_plugin = 'Plugin';
Expand Down
1 change: 0 additions & 1 deletion lang/strings_french.txt
Expand Up @@ -1255,4 +1255,3 @@ $s_month_september = 'septembre';
$s_month_october = 'octobre';
$s_month_november = 'novembre';
$s_month_december = 'décembre';
$s_none_filter = 'Aucun filtre';

0 comments on commit 259f95c

Please sign in to comment.