Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mantisbt/mantisbt
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: e526350
Choose a base ref
...
head repository: mantisbt/mantisbt
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: e28fa43
Choose a head ref
  • 3 commits
  • 3 files changed
  • 1 contributor

Commits on May 6, 2012

  1. Add filter in Manage Users page to show/hide disabled users

    Original patch written by David Newcomb.
    
    Fixed issue with new filter not specified on the multi-page navigation
    links. Also made minor cosmetic changes: whitespace, coding guidelines.
    
    Fixes #11726
    dregad committed May 6, 2012
    Copy the full SHA
    a21374a View commit details
  2. Code cleanup in Manage User page

    Simplify code by using a for loop to print the column headers instead of
    manually building the table cells one by one. Note that this actually
    changes the label of the 'Protected' column from the padlock icon to a
    text description.
    
    Rename 'hide' variable to 'hide_inactive'. With the addition of the new
    filter option 'show_disabled', using just 'hide' was potentially
    confusing.
    dregad committed May 6, 2012

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    129a8e5 View commit details
  3. The filter in managed_user_page.php is not persistent

    The filter values stored in the cookie whenever the criteria change,
    were restored to the form variables instead of the sanitized ($c_)
    variables, and were therefore not taken into account when building the
    page.
    
    Fixes #14216
    dregad committed May 6, 2012
    Copy the full SHA
    e28fa43 View commit details
Showing with 85 additions and 91 deletions.
  1. +2 −2 core/print_api.php
  2. +1 −0 lang/strings_english.txt
  3. +82 −89 manage_user_page.php
4 changes: 2 additions & 2 deletions core/print_api.php
Original file line number Diff line number Diff line change
@@ -1237,7 +1237,7 @@ function print_view_bug_sort_link( $p_string, $p_sort_field, $p_sort, $p_dir, $p
}
}

function print_manage_user_sort_link( $p_page, $p_string, $p_field, $p_dir, $p_sort_by, $p_hide = 0, $p_filter = ALL ) {
function print_manage_user_sort_link( $p_page, $p_string, $p_field, $p_dir, $p_sort_by, $p_hide_inactive = 0, $p_filter = ALL, $p_show_disabled = 0 ) {
if( $p_sort_by == $p_field ) {

# If this is the selected field flip the order
@@ -1252,7 +1252,7 @@ function print_manage_user_sort_link( $p_page, $p_string, $p_field, $p_dir, $p_s
}

$t_field = rawurlencode( $p_field );
print_link( "$p_page?sort=$t_field&dir=$t_dir&save=1&hide=$p_hide&filter=$p_filter", $p_string );
print_link( "$p_page?sort=$t_field&dir=$t_dir&save=1&hideinactive=$p_hide_inactive&showdisabled=$p_show_disabled&filter=$p_filter", $p_string );
}

function print_manage_project_sort_link( $p_page, $p_string, $p_field, $p_dir, $p_sort_by ) {
1 change: 1 addition & 0 deletions lang/strings_english.txt
Original file line number Diff line number Diff line change
@@ -767,6 +767,7 @@ $s_1_week_title = '1 Week';
$s_never_logged_in_title = 'Never Logged In';
$s_prune_accounts = 'Prune Accounts';
$s_hide_inactive = 'Hide Inactive';
$s_show_disabled = 'Show Disabled';
$s_manage_accounts_title = 'Manage Accounts';
$s_p = 'p';
$s_date_created = 'Date Created';
171 changes: 82 additions & 89 deletions manage_user_page.php
Original file line number Diff line number Diff line change
@@ -31,12 +31,13 @@

access_ensure_global_level( config_get( 'manage_user_threshold' ) );

$f_sort = gpc_get_string( 'sort', 'username' );
$f_dir = gpc_get_string( 'dir', 'ASC' );
$f_hide = gpc_get_bool( 'hide' );
$f_save = gpc_get_bool( 'save' );
$f_filter = utf8_strtoupper( gpc_get_string( 'filter', config_get( 'default_manage_user_prefix' ) ) );
$f_page_number = gpc_get_int( 'page_number', 1 );
$f_sort = gpc_get_string( 'sort', 'username' );
$f_dir = gpc_get_string( 'dir', 'ASC' );
$f_hide_inactive = gpc_get_bool( 'hideinactive' );
$f_show_disabled = gpc_get_bool( 'showdisabled' );
$f_save = gpc_get_bool( 'save' );
$f_filter = utf8_strtoupper( gpc_get_string( 'filter', config_get( 'default_manage_user_prefix' ) ) );
$f_page_number = gpc_get_int( 'page_number', 1 );

$t_user_table = db_get_table( 'mantis_user_table' );
$t_cookie_name = config_get( 'manage_cookie' );
@@ -45,42 +46,48 @@

# Clean up the form variables
if ( !db_field_exists( $f_sort, $t_user_table ) ) {
$c_sort = 'username';
} else {
$c_sort = addslashes($f_sort);
}

if ($f_dir == 'ASC') {
$c_dir = 'ASC';
$c_sort = 'username';
} else {
$c_dir = 'DESC';
$c_sort = addslashes( $f_sort );
}

if ($f_hide == 0) { # a 0 will turn it off
$c_hide = 0;
} else { # anything else (including 'on') will turn it on
$c_hide = 1;
}
$t_hide_filter = '&hide=' . $c_hide;
$c_dir = ( $f_dir == 'ASC' ) ? 'ASC' : 'DESC';

# 0 = show inactive users, anything else = hide them
$c_hide_inactive = ( $f_hide_inactive == 0 ) ? 0 : 1;
$t_hide_inactive_filter = '&hideinactive=' . $c_hide_inactive;

# set cookie values for hide, sort by, and dir
# 0 = hide disabled users, anything else = show them
$c_show_disabled = ( $f_show_disabled == 0 ) ? 0 : 1;
$t_show_disabled_filter = '&showdisabled=' . $c_show_disabled;

# set cookie values for hide inactive, sort by, dir and show disabled
if ( $f_save ) {
$t_manage_string = $c_hide.':'.$c_sort.':'.$c_dir;
$t_manage_string = $c_hide_inactive.':'.$c_sort.':'.$c_dir.':'.$c_show_disabled;
gpc_set_cookie( $t_cookie_name, $t_manage_string, true );
} else if ( !is_blank( gpc_get_cookie( $t_cookie_name, '' ) ) ) {
$t_manage_arr = explode( ':', gpc_get_cookie( $t_cookie_name ) );
$f_hide = $t_manage_arr[0];

# Hide Inactive
$c_hide_inactive = $t_manage_arr[0];

# Sort field
if ( isset( $t_manage_arr[1] ) ) {
$f_sort = $t_manage_arr[1];
$c_sort = $t_manage_arr[1];
} else {
$f_sort = 'username';
$c_sort = 'username';
}

# Sort order
if ( isset( $t_manage_arr[2] ) ) {
$f_dir = $t_manage_arr[2];
$c_dir = $t_manage_arr[2];
} else {
$f_dir = 'DESC';
$c_dir = 'DESC';
}

# Show Disabled
if ( isset( $t_manage_arr[3] ) ) {
$c_show_disabled = $t_manage_arr[3];
}
}

@@ -132,7 +139,11 @@
$c_filter = $f_filter;
echo "<strong>$t_caption</strong>";
} else {
print_link( "manage_user_page.php?sort=$c_sort&dir=$c_dir&save=1$t_hide_filter&filter=$t_prefix", $t_caption );
print_manage_user_sort_link( 'manage_user_page.php',
$t_caption,
$c_sort,
$c_dir, null, $c_hide_inactive, $t_prefix, $c_show_disabled
);
}

if ( $t_prefix === 'UNUSED' ) {
@@ -164,17 +175,22 @@

# Get the user data in $c_sort order
$result = '';
if ( 0 == $c_hide ) {

$t_show_disabled_cond = ( 1 == $c_show_disabled ? '' : ' AND enabled = 1' );

if ( 0 == $c_hide_inactive ) {
$query = "SELECT count(*) as usercnt
FROM $t_user_table
WHERE $t_where";
WHERE $t_where
$t_show_disabled_cond";
$result = db_query_bound($query, $t_where_params);
$row = db_fetch_array( $result );
$total_user_count = $row['usercnt'];
} else {
$query = "SELECT count(*) as usercnt
FROM $t_user_table
WHERE $t_where AND " . db_helper_compare_days("" . db_now() . "","last_visit","< $days_old");
WHERE $t_where AND " . db_helper_compare_days("" . db_now() . "","last_visit","< $days_old")
. $t_show_disabled_cond;
$result = db_query_bound($query, $t_where_params);
$row = db_fetch_array( $result );
$total_user_count = $row['usercnt'];
@@ -196,17 +212,19 @@
}


if ( 0 == $c_hide ) {
if ( 0 == $c_hide_inactive ) {
$query = "SELECT *
FROM $t_user_table
WHERE $t_where
$t_show_disabled_cond
ORDER BY $c_sort $c_dir";
$result = db_query_bound($query, $t_where_params, $p_per_page, $t_offset);
} else {

$query = "SELECT *
FROM $t_user_table
WHERE $t_where AND " . db_helper_compare_days( "" . db_now() . "", "last_visit", "< $days_old" ) . "
$t_show_disabled_cond
ORDER BY $c_sort $c_dir";
$result = db_query_bound($query, $t_where_params, $p_per_page, $t_offset );
}
@@ -228,61 +246,34 @@
<input type="hidden" name="dir" value="<?php echo $c_dir ?>" />
<input type="hidden" name="save" value="1" />
<input type="hidden" name="filter" value="<?php echo $c_filter ?>" />
<input type="checkbox" name="hide" value="1" <?php check_checked( $c_hide, 1 ); ?> /> <?php echo lang_get( 'hide_inactive' ) ?>
<input type="checkbox" name="hideinactive" value="1" <?php check_checked( $c_hide_inactive, 1 ); ?> /> <?php echo lang_get( 'hide_inactive' ) ?>
<input type="checkbox" name="showdisabled" value="1" <?php check_checked( $c_show_disabled, 1 ); ?> /> <?php echo lang_get( 'show_disabled' ) ?>
<input type="submit" class="button" value="<?php echo lang_get( 'filter_button' ) ?>" />
</form>
</td>
</tr>

<tr class="row-category">
<td>
<?php
print_manage_user_sort_link( 'manage_user_page.php', lang_get( 'username' ), 'username', $c_dir, $c_sort, $c_hide, $c_filter );
print_sort_icon( $c_dir, $c_sort, 'username' );
?>
</td>
<td>
<?php
print_manage_user_sort_link( 'manage_user_page.php', lang_get( 'realname' ), 'realname', $c_dir, $c_sort, $c_hide, $c_filter );
print_sort_icon( $c_dir, $c_sort, 'realname' );
?>
</td>
<td>
<?php
print_manage_user_sort_link( 'manage_user_page.php', lang_get( 'email' ), 'email', $c_dir, $c_sort, $c_hide, $c_filter );
print_sort_icon( $c_dir, $c_sort, 'email' );
?>
</td>
<td>
<?php
print_manage_user_sort_link( 'manage_user_page.php', lang_get( 'access_level' ), 'access_level', $c_dir, $c_sort, $c_hide, $c_filter );
print_sort_icon( $c_dir, $c_sort, 'access_level' );
?>
</td>
<td>
<?php
print_manage_user_sort_link( 'manage_user_page.php', lang_get( 'enabled' ), 'enabled', $c_dir, $c_sort, $c_hide, $c_filter );
print_sort_icon( $c_dir, $c_sort, 'enabled' );
?>
</td>
<td>
<?php
print_manage_user_sort_link( 'manage_user_page.php', $t_lock_image, 'protected', $c_dir, $c_sort, $c_hide, $c_filter );
print_sort_icon( $c_dir, $c_sort, 'protected' );
?>
</td>
<td>
<?php
print_manage_user_sort_link( 'manage_user_page.php', lang_get( 'date_created' ), 'date_created', $c_dir, $c_sort, $c_hide, $c_filter );
print_sort_icon( $c_dir, $c_sort, 'date_created' );
?>
</td>
<td>
<?php
print_manage_user_sort_link( 'manage_user_page.php', lang_get( 'last_visit' ), 'last_visit', $c_dir, $c_sort, $c_hide, $c_filter );
print_sort_icon( $c_dir, $c_sort, 'last_visit' );
?>
</td>
<?php
# Print column headers with sort links
$t_columns = array(
'username', 'realname', 'email', 'access_level',
'enabled', 'protected', 'date_created', 'last_visit'
);

foreach( $t_columns as $t_col ) {
echo "\t<td>";
print_manage_user_sort_link( 'manage_user_page.php',
lang_get( $t_col ),
$t_col,
$c_dir, $c_sort, $c_hide_inactive, $c_filter, $c_show_disabled
);
print_sort_icon( $c_dir, $c_sort, $t_col );
echo "</td>\n";
}
?>
</tr>

<?php
$t_date_format = config_get( 'normal_date_format' );
$t_access_level = Array();
@@ -313,30 +304,32 @@
<td><?php echo string_display_line( $u_realname ) ?></td>
<td><?php print_email_link( $u_email, $u_email ) ?></td>
<td><?php echo $t_access_level[$u_access_level] ?></td>
<td><?php echo trans_bool( $u_enabled ) ?></td>
<td class="center"><?php echo trans_bool( $u_enabled ) ?></td>
<td class="center">
<?php
<?php
if ( $u_protected ) {
echo " $t_lock_image";
} else {
echo '&#160;';
}
?>
</td>
?>
</td>
<td><?php echo $u_date_created ?></td>
<td><?php echo $u_last_visit ?></td>
</tr>
<?php
} # end for
# -- Page number links --

# -- Page number links --
?>
<tr>
<td class="right" colspan="8">
<span class="small">
<?php
/* @todo hack - pass in the hide inactive filter via cheating the actual filter value */
print_page_links( 'manage_user_page.php', 1, $t_page_count, (int)$f_page_number, $c_filter . $t_hide_filter . "&sort=$c_sort&dir=$c_dir");
/* @todo hack - pass in the page filter via cheating the actual filter value */
print_page_links( 'manage_user_page.php', 1, $t_page_count, (int)$f_page_number,
$c_filter . $t_hide_inactive_filter . $t_show_disabled_filter . "&sort=$c_sort&dir=$c_dir"
);
?>
</span>
</td>