Skip to content

Commit 93eb540

Browse files
committedMay 6, 2012
Add filter in Manage Users page to show/hide disabled users
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
1 parent e1a5388 commit 93eb540

File tree

3 files changed

+76
-65
lines changed

3 files changed

+76
-65
lines changed
 

‎core/print_api.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,7 @@ function print_view_bug_sort_link( $p_string, $p_sort_field, $p_sort, $p_dir, $p
10971097
}
10981098
}
10991099

1100-
function print_manage_user_sort_link( $p_page, $p_string, $p_field, $p_dir, $p_sort_by, $p_hide = 0, $p_filter = ALL ) {
1100+
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 ) {
11011101
if( $p_sort_by == $p_field ) {
11021102

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

11141114
$t_field = rawurlencode( $p_field );
1115-
print_link( "$p_page?sort=$t_field&dir=$t_dir&save=1&hide=$p_hide&filter=$p_filter", $p_string );
1115+
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 );
11161116
}
11171117

11181118
function print_manage_project_sort_link( $p_page, $p_string, $p_field, $p_dir, $p_sort_by ) {

‎lang/strings_english.txt

+1
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,7 @@ If you requested this verification, visit the following URL to change your passw
681681
'never_logged_in_title' => 'Never Logged In',
682682
'prune_accounts' => 'Prune Accounts',
683683
'hide_inactive' => 'Hide Inactive',
684+
'show_disabled' => 'Show Disabled',
684685
'manage_accounts_title' => 'Manage Accounts',
685686
'p' => 'p',
686687
'date_created' => 'Date Created',

‎manage_user_page.php

+73-63
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,13 @@
5858

5959
access_ensure_global_level( config_get( 'manage_user_threshold' ) );
6060

61-
$f_sort = gpc_get_string( 'sort', 'username' );
62-
$f_dir = gpc_get_string( 'dir', 'ASC' );
63-
$f_hide = gpc_get_bool( 'hide' );
64-
$f_save = gpc_get_bool( 'save' );
65-
$f_filter = utf8_strtoupper( gpc_get_string( 'filter', config_get( 'default_manage_user_prefix' ) ) );
66-
$f_page_number = gpc_get_int( 'page_number', 1 );
61+
$f_sort = gpc_get_string( 'sort', 'username' );
62+
$f_dir = gpc_get_string( 'dir', 'ASC' );
63+
$f_hide_inactive = gpc_get_bool( 'hideinactive' );
64+
$f_show_disabled = gpc_get_bool( 'showdisabled' );
65+
$f_save = gpc_get_bool( 'save' );
66+
$f_filter = utf8_strtoupper( gpc_get_string( 'filter', config_get( 'default_manage_user_prefix' ) ) );
67+
$f_page_number = gpc_get_int( 'page_number', 1 );
6768

6869
$t_user_table = db_get_table( 'user' );
6970
$t_cookie_name = config_get( 'manage_cookie' );
@@ -77,37 +78,43 @@
7778
$c_sort = addslashes($f_sort);
7879
}
7980

80-
if ($f_dir == 'ASC') {
81-
$c_dir = 'ASC';
82-
} else {
83-
$c_dir = 'DESC';
84-
}
81+
$c_dir = ( $f_dir == 'ASC' ) ? 'ASC' : 'DESC';
8582

86-
if ($f_hide == 0) { # a 0 will turn it off
87-
$c_hide = 0;
88-
} else { # anything else (including 'on') will turn it on
89-
$c_hide = 1;
90-
}
91-
$t_hide_filter = '&hide=' . $c_hide;
83+
# 0 = show inactive users, anything else = hide them
84+
$c_hide_inactive = ( $f_hide_inactive == 0 ) ? 0 : 1;
85+
$t_hide_inactive_filter = '&hideinactive=' . $c_hide_inactive;
86+
87+
# 0 = hide disabled users, anything else = show them
88+
$c_show_disabled = ( $f_show_disabled == 0 ) ? 0 : 1;
89+
$t_show_disabled_filter = '&showdisabled=' . $c_show_disabled;
9290

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

98+
# Hide Inactive
99+
$c_hide_inactive = $t_manage_arr[0];
100+
101+
# Sort field
101102
if ( isset( $t_manage_arr[1] ) ) {
102-
$f_sort = $t_manage_arr[1];
103+
$c_sort = $t_manage_arr[1];
103104
} else {
104-
$f_sort = 'username';
105+
$c_sort = 'username';
105106
}
106107

108+
# Sort order
107109
if ( isset( $t_manage_arr[2] ) ) {
108-
$f_dir = $t_manage_arr[2];
110+
$c_dir = $t_manage_arr[2];
109111
} else {
110-
$f_dir = 'DESC';
112+
$c_dir = 'DESC';
113+
}
114+
115+
# Show Disabled
116+
if ( isset( $t_manage_arr[3] ) ) {
117+
$c_show_disabled = $t_manage_arr[3];
111118
}
112119
}
113120

@@ -167,6 +174,14 @@
167174
echo '<span class="current-filter">' . $t_caption . '</span>';
168175
} else {
169176
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>';
Has a conversation. Original line has a conversation.
177+
/*
178+
*
179+
print_manage_user_sort_link( 'manage_user_page.php',
180+
$t_caption,
181+
$c_sort,
182+
$c_dir, null, $c_hide_inactive, $t_prefix, $c_show_disabled
183+
);
184+
*/
170185
}
171186
echo '</li>';
172187
}
@@ -193,17 +208,22 @@
193208

194209
# Get the user data in $c_sort order
195210
$result = '';
196-
if ( 0 == $c_hide ) {
211+
212+
$t_show_disabled_cond = ( 1 == $c_show_disabled ? '' : ' AND enabled = 1' );
213+
214+
if ( 0 == $c_hide_inactive ) {
197215
$query = "SELECT count(*) as usercnt
198216
FROM $t_user_table
199-
WHERE $t_where";
217+
WHERE $t_where
218+
$t_show_disabled_cond";
200219
$result = db_query_bound($query, $t_where_params);
201220
$row = db_fetch_array( $result );
202221
$total_user_count = $row['usercnt'];
203222
} else {
204223
$query = "SELECT count(*) as usercnt
205224
FROM $t_user_table
206-
WHERE $t_where AND " . db_helper_compare_days("" . db_now() . "","last_visit","< $days_old");
225+
WHERE $t_where AND " . db_helper_compare_days("" . db_now() . "","last_visit","< $days_old")
226+
. $t_show_disabled_cond;
207227
$result = db_query_bound($query, $t_where_params);
208228
$row = db_fetch_array( $result );
209229
$total_user_count = $row['usercnt'];
@@ -225,21 +245,24 @@
225245
}
226246

227247

228-
if ( 0 == $c_hide ) {
248+
if ( 0 == $c_hide_inactive ) {
229249
$query = "SELECT *
230250
FROM $t_user_table
231251
WHERE $t_where
252+
$t_show_disabled_cond
232253
ORDER BY $c_sort $c_dir";
233254
$result = db_query_bound($query, $t_where_params, $p_per_page, $t_offset);
234255
} else {
235256

236257
$query = "SELECT *
237258
FROM $t_user_table
238259
WHERE $t_where AND " . db_helper_compare_days( "" . db_now() . "", "last_visit", "< $days_old" ) . "
260+
$t_show_disabled_cond
239261
ORDER BY $c_sort $c_dir";
240262
$result = db_query_bound($query, $t_where_params, $p_per_page, $t_offset );
241263
}
242264
$user_count = db_num_rows( $result );
265+
243266
?>
244267
<div id="manage-user-div" class="form-container">
245268
<h2><?php echo lang_get( 'manage_accounts_title' ) ?></h2> [<?php echo $total_user_count ?>]
@@ -252,45 +275,32 @@
252275
<input type="hidden" name="dir" value="<?php echo $c_dir ?>" />
253276
<input type="hidden" name="save" value="1" />
254277
<input type="hidden" name="filter" value="<?php echo $c_filter ?>" />
255-
<input type="checkbox" name="hide" value="1" <?php check_checked( $c_hide, 1 ); ?> /> <?php echo lang_get( 'hide_inactive' ) ?>
278+
<input type="checkbox" name="hideinactive" value="1" <?php check_checked( (int)$c_hide_inactive, 1 ); ?> /> <?php echo lang_get( 'hide_inactive' ) ?>
279+
<input type="checkbox" name="showdisabled" value="1" <?php check_checked( (int)$c_show_disabled, 1 ); ?> /> <?php echo lang_get( 'show_disabled' ) ?>
256280
<input type="submit" class="button" value="<?php echo lang_get( 'filter_button' ) ?>" />
257281
</fieldset>
258282
</form>
259283

260284
<table cellspacing="1" cellpadding="5" border="1">
261285
<tr class="row-category">
262-
<td><?php
263-
print_manage_user_sort_link( 'manage_user_page.php', lang_get( 'username' ), 'username', $c_dir, $c_sort, $c_hide, $c_filter );
264-
print_sort_icon( $c_dir, $c_sort, 'username' ); ?>
265-
</td>
266-
<td><?php
267-
print_manage_user_sort_link( 'manage_user_page.php', lang_get( 'realname' ), 'realname', $c_dir, $c_sort, $c_hide, $c_filter );
268-
print_sort_icon( $c_dir, $c_sort, 'realname' ); ?>
269-
</td>
270-
<td><?php
271-
print_manage_user_sort_link( 'manage_user_page.php', lang_get( 'email' ), 'email', $c_dir, $c_sort, $c_hide, $c_filter );
272-
print_sort_icon( $c_dir, $c_sort, 'email' ); ?>
273-
</td>
274-
<td><?php
275-
print_manage_user_sort_link( 'manage_user_page.php', lang_get( 'access_level' ), 'access_level', $c_dir, $c_sort, $c_hide, $c_filter );
276-
print_sort_icon( $c_dir, $c_sort, 'access_level' ); ?>
277-
</td>
278-
<td><?php
279-
print_manage_user_sort_link( 'manage_user_page.php', lang_get( 'enabled' ), 'enabled', $c_dir, $c_sort, $c_hide, $c_filter );
280-
print_sort_icon( $c_dir, $c_sort, 'enabled' ); ?>
281-
</td>
282-
<td><?php
283-
print_manage_user_sort_link( 'manage_user_page.php', $t_lock_image, 'protected', $c_dir, $c_sort, $c_hide, $c_filter );
284-
print_sort_icon( $c_dir, $c_sort, 'protected' ); ?>
285-
</td>
286-
<td><?php
287-
print_manage_user_sort_link( 'manage_user_page.php', lang_get( 'date_created' ), 'date_created', $c_dir, $c_sort, $c_hide, $c_filter );
288-
print_sort_icon( $c_dir, $c_sort, 'date_created' ); ?>
289-
</td>
290-
<td><?php
291-
print_manage_user_sort_link( 'manage_user_page.php', lang_get( 'last_visit' ), 'last_visit', $c_dir, $c_sort, $c_hide, $c_filter );
292-
print_sort_icon( $c_dir, $c_sort, 'last_visit' ); ?>
293-
</td>
286+
<?php
287+
# Print column headers with sort links
288+
$t_columns = array(
289+
'username', 'realname', 'email', 'access_level',
290+
'enabled', 'protected', 'date_created', 'last_visit'
291+
);
292+
293+
foreach( $t_columns as $t_col ) {
294+
echo "\t<td>";
295+
print_manage_user_sort_link( 'manage_user_page.php',
296+
lang_get( $t_col ),
297+
$t_col,
298+
$c_dir, $c_sort, $c_hide_inactive, $c_filter, $c_show_disabled
299+
);
300+
print_sort_icon( $c_dir, $c_sort, $t_col );
301+
echo "</td>\n";
302+
}
303+
?>
294304
</tr><?php
295305
$t_date_format = config_get( 'normal_date_format' );
296306
$t_access_level = Array();
@@ -316,7 +326,7 @@
316326
<td><?php echo string_display_line( $u_realname ) ?></td>
317327
<td><?php print_email_link( $u_email, $u_email ) ?></td>
318328
<td><?php echo $t_access_level[$u_access_level] ?></td>
319-
<td><?php echo trans_bool( $u_enabled ) ?></td>
329+
<td class="center"><?php echo trans_bool( $u_enabled ) ?></td>
320330
<td class="center"><?php
321331
if ( $u_protected ) {
322332
echo " $t_lock_image";
@@ -332,7 +342,7 @@
332342
<div class="pager-links">
333343
<?php
334344
/* @todo hack - pass in the hide inactive filter via cheating the actual filter value */
335-
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");
345+
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");
336346
?>
337347
</div>
338348
</div>

0 commit comments

Comments
 (0)
Please sign in to comment.