Skip to content

Commit

Permalink
Add filter in Manage Users page to show/hide disabled users
Browse files Browse the repository at this point in the history
This is a port of the following 1.2.x commits:

   - a21374a,

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.

   - 129a8e5

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.

   - e28fa43

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 #11726, #14216
  • Loading branch information
dregad committed May 6, 2012
1 parent e1a5388 commit 93eb540
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 65 deletions.
4 changes: 2 additions & 2 deletions core/print_api.php
Expand Up @@ -1097,7 +1097,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
Expand All @@ -1112,7 +1112,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 ) {
Expand Down
1 change: 1 addition & 0 deletions lang/strings_english.txt
Expand Up @@ -681,6 +681,7 @@ If you requested this verification, visit the following URL to change your passw
'never_logged_in_title' => 'Never Logged In',
'prune_accounts' => 'Prune Accounts',
'hide_inactive' => 'Hide Inactive',
'show_disabled' => 'Show Disabled',
'manage_accounts_title' => 'Manage Accounts',
'p' => 'p',
'date_created' => 'Date Created',
Expand Down
136 changes: 73 additions & 63 deletions manage_user_page.php
Expand Up @@ -58,12 +58,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( 'user' );
$t_cookie_name = config_get( 'manage_cookie' );
Expand All @@ -77,37 +78,43 @@
$c_sort = addslashes($f_sort);
}

if ($f_dir == 'ASC') {
$c_dir = 'ASC';
} else {
$c_dir = 'DESC';
}
$c_dir = ( $f_dir == 'ASC' ) ? 'ASC' : 'DESC';

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;
# 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;

# 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, sort by, and dir
# 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];
}
}

Expand Down Expand Up @@ -167,6 +174,14 @@
echo '<span class="current-filter">' . $t_caption . '</span>';
} else {
echo '<a' . $t_title . ' href="manage_user_page.php?sort=' . $c_sort . '&amp;dir=' . $c_dir . '&amp;save=1' . $t_hide_filter . '&amp;filter=' . $t_prefix . '">' . $t_caption . '</a>';

This comment has been minimized.

Copy link
@atrol

atrol Jul 9, 2012

Member

$t_hide_filter is undefined

/*
*
print_manage_user_sort_link( 'manage_user_page.php',
$t_caption,
$c_sort,
$c_dir, null, $c_hide_inactive, $t_prefix, $c_show_disabled
);
*/
}
echo '</li>';
}
Expand All @@ -193,17 +208,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'];
Expand All @@ -225,21 +245,24 @@
}


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 );
}
$user_count = db_num_rows( $result );

?>
<div id="manage-user-div" class="form-container">
<h2><?php echo lang_get( 'manage_accounts_title' ) ?></h2> [<?php echo $total_user_count ?>]
Expand All @@ -252,45 +275,32 @@
<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( (int)$c_hide_inactive, 1 ); ?> /> <?php echo lang_get( 'hide_inactive' ) ?>
<input type="checkbox" name="showdisabled" value="1" <?php check_checked( (int)$c_show_disabled, 1 ); ?> /> <?php echo lang_get( 'show_disabled' ) ?>
<input type="submit" class="button" value="<?php echo lang_get( 'filter_button' ) ?>" />
</fieldset>
</form>

<table cellspacing="1" cellpadding="5" border="1">
<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();
Expand All @@ -316,7 +326,7 @@
<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
if ( $u_protected ) {
echo " $t_lock_image";
Expand All @@ -332,7 +342,7 @@
<div class="pager-links">
<?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 . "&amp;sort=$c_sort&amp;dir=$c_dir");
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 . "&amp;sort=$c_sort&amp;dir=$c_dir");
?>
</div>
</div>
Expand Down

0 comments on commit 93eb540

Please sign in to comment.