display_users.php
7.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<?php
namespace Tz\WordPress\Tools\UserManager;
use Tz, Tz\Common;
use Tz\WordPress\CBV;
use Tz\WordPress\CBV\CEHours;
use Tz\WordPress\CBV\Events;
use Tz\WordPress\UAM;
use Tz\WordPress\Tools, Tz\WordPress\Tools\UserDetails as UD;
use Tz\WordPress\Tools\Notifications;
use Exception, StdClass;
use WP_User;
ini_set('display_errors', 1);
$records_per_page = 20;
$filter_role = isset($_GET['role']) ? $_GET['role'] : null;
$pagenum = isset($_GET['pagenum']) ? $_GET['pagenum'] : 1;
$search = isset($_GET['search_criteria']) ? $_GET['search_criteria'] : null;
$rows = get_users($filter_role, 0, 0, true, $search);
$last = ceil($rows/$records_per_page);
if ($last < 1) {
$last = 1;
}
if ($pagenum < 1) {
$pagenum = 1;
} elseif ($pagenum > $last) {
$pagenum = $last;
}
$site_users = get_users($filter_role, $pagenum, $records_per_page, false, $search);
if ($filter_role) {
$url = $_SERVER['PHP_SELF']."?page=cbv_users&role=$filter_role&pagenum=";
} elseif ($search) {
$url = $_SERVER['PHP_SELF']."?page=cbv_users&search_criteria=$search&pagenum=";
} else {
$url = $_SERVER['PHP_SELF']."?page=cbv_users&pagenum=";
}
// Pager section
$loop_test = 0;
$loop_initial = 0;
$show_ellipsis_limit = 7;
$ellipsis_before = '';
$ellipsis_after = '';
$ellipsis_common = '...';
$tag = '[pagenum]';
$template = '<a href="' . $url . $tag . '">' . $tag . '</a>';
$template_with_class = '<a href="' . $url . $tag . '" class="active">' . $tag . '</a>';
$prev_link = ($pagenum == 1) ? '' : ' <a href="' . $url . ($pagenum - 1) . '"><</a> ';
$next_link = ($pagenum == $last) ? '' : ' <a href="' . $url . ($pagenum + 1) . '">></a> ';
$first_link = ' <a href="' . $url . '1"><<</a> ';
$last_link = ' <a href="' . $url . $last . '">>></a> ';
$pager = '';
// Style: 1...5 6 7...100
if ($last > 1) {
$pager = ' | Pages: ';
// Set options
// ...31 32 33...
if ($last > $show_ellipsis_limit) {
// 1 2 3 4...last
if ($pagenum > 0 && $pagenum < 4) {
$loop_initial = 2;
$loop_test = 5;
$ellipsis_after = $ellipsis_common;
// 4 5 6...last
} elseif ($pagenum > 3 && $pagenum < ($last - 1)) {
$loop_initial = $pagenum - 1;
$loop_test = $pagenum + 2;
$ellipsis_before = $ellipsis_common;
// This is to eliminate the $ellipsis when we're on the 3rd last page
if ($pagenum < ($last - 2)) {
$ellipsis_after = $ellipsis_common;
}
// 8 9 10(last)
} else {
$loop_initial = $pagenum - 2;
$loop_test = $last;
$ellipsis_before = $ellipsis_common;
}
// 1 2 3 4 5 6 7
} else {
$loop_initial = 2;
$loop_test = $last;
}
// Now start building html
// Start with 'First' link, then previous page link
if ($last > $show_ellipsis_limit && $pagenum != 1) {
$pager .= $first_link . $prev_link;
}
// Set active template to highlight page 1 if that's what we're on
if ($pagenum == 1) {
$pager .= str_ireplace($tag, 1, $template_with_class);
} else {
$pager .= str_ireplace($tag, 1, $template);
}
// Implement middle loops
$pager .= $ellipsis_before;
for ($i = $loop_initial; $i < $loop_test; $i++) {
if ($pagenum == $i) {
$pager .= str_ireplace($tag, $i, $template_with_class);
} else {
$pager .= str_ireplace($tag, $i, $template);
}
}
$pager .= $ellipsis_after;
// Set active template to highlight page 1 if that's what we're on
if ($pagenum == $last) {
$pager .= str_ireplace($tag, $last, $template_with_class);
} else {
$pager .= str_ireplace($tag, $last, $template);
}
// Finish with next page link, then 'Last' link
if ($last > $show_ellipsis_limit && $pagenum != $last) {
$pager .= $next_link;
$pager .= $last_link;
}
}
?>
<div id="" class="wrap">
<div id="icon-users" class="icon32"><br /></div>
<h2>CBV User Manager <a href="/wp-admin/admin.php?page=cbv_users_create" class="button add-new-h2">Add New</a></h2>
<p style="display:none;">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam iaculis convallis nisi eu dignissim. Quisque malesuada augue in mi blandit at blandit tortor sollicitudin. Cras at justo mi, vel mollis est. Donec orci erat, blandit varius vehicula vitae, volutpat at lorem. Etiam tincidunt bibendum ante, non tincidunt purus faucibus sed. Suspendisse eget facilisis tellus. Nulla imperdiet leo placerat diam sollicitudin nec mattis neque mattis. Cras id lacus tellus. Phasellus volutpat vehicula porttitor. Praesent erat felis, pharetra mollis egestas sit amet, rhoncus eget nisl. Morbi interdum sapien vitae nibh pharetra scelerisque. Mauris porta accumsan velit ac aliquam. Sed sit amet dictum felis. Fusce tempus vulputate nulla, quis tincidunt velit mattis eu.</p>
<div class="users-role-bar">
<?php if (isset($_GET['search_criteria'])):?>
<div style="margin-bottom:10px;display:block;"><strong>Searched for: </strong> <?php echo strip_tags($_GET['search_criteria']); ?> <a href="/wp-admin/admin.php?page=cbv_users" class="button">Clear Search</a></div>
<?php else: ?>
<strong>Filter</strong>:
<?php $users = count_users(); ?>
<a href="/wp-admin/admin.php?page=cbv_users" <?php echo (!isset($_GET['role']) ? "class='active'" : ""); ?>>All</a>
<?php
if (isset($users['avail_roles'])) {
foreach($users['avail_roles'] as $role=>$counted) {
print ' | <a href="/wp-admin/admin.php?page=cbv_users&role='.$role.'" '.( (isset($_GET['role']) && $_GET['role']==$role) ? "class='active'" : "").'>'.ucwords($role).'</a>';
}
}
?>
<form method="GET" action="<?php echo $_SERVER['PHP_SELF']."?page=cbv_users"; ?>"><input type="hidden" name="page" value="cbv_users" /><div style="margin-top:3px;display:block;"><em>or</em> <strong>Search</strong>: <input type="text" name="search_criteria" value="" /><input type="submit" value="Go" /></div></form>
<?php endif;?>
</div>
<div class="TzPaginateResults">
<?php
echo "Users: $rows ";
echo $pager;
?>
</div>
<div style="clear:both"></div>
<table cellspacing="0" class="widefat post fixed">
<thead>
<tr>
<th scope="col" class="manage-column">Name</th>
<th scope="col" width="180" class="manage-column">Username</th>
<th scope="col" width="250" class="manage-column">Email</th>
<th scope="col" width="200" class="manage-column">Role</th>
<th scope="col" width="100" class="manage-column">Status</th>
<th scope="col" width="100" class="manage-column"> </th>
</tr>
</thead>
<tbody>
<?php
foreach($site_users as $user):
?>
<tr>
<td><a href="/wp-admin/admin.php?page=cbv_users&action=edit&uid=<?php echo $user['uid']?>"><?php echo $user['last_name'].', '.$user['first_name']?></a></td>
<td><a href="/wp-admin/admin.php?page=cbv_users&action=edit&uid=<?php echo $user['uid']?>"><?php echo $user['user_login']?></a></td>
<td><?php echo $user['email']?></td>
<td><?php echo $user['role']?></td>
<td><?php echo ucwords($user['status']);?></td>
<td><a href="/wp-admin/admin-ajax.php?ajax=yes&action=build_user_remove&uid=<?php echo $user['uid'];?>" class="remove-user" rel="<?php echo $user['uid'];?>">Remove User</a></td>
</tr>
<?php endforeach; ?>
</body>
</table>
<div class="TzPaginateResults" style="margin-top:10px;">
<?php
echo "Users: $rows ";
echo $pager;
?>
</div>
<div style="clear:both;"></div>
</div>
<script src="<?php echo Tools\url('../UserManager.js', __FILE__);?>" type="text/javascript"></script>