This repository has been archived by the owner on Nov 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 92
/
users_list.php
154 lines (98 loc) · 3.8 KB
/
users_list.php
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
<?php
/**
* MASTER LOGIN SYSTEM
* @author Mihai Ionut Vilcu ([email protected])
* June 2013
*
*/
include "inc/init.php";
include 'lib/pagination.class.php';
$page->title = "Users of ". $set->site_name;
$presets->setActive("userslist"); // we highlight the home link
$content = ''; // will store the html code for users list
if(!isset($_GET['page']))
$page_number = 1;
$sort_name = array("id", "name");
// sorting
if(!isset($_GET['sort']) || !in_array($_GET['sort'], array(0,1))) // check if it's a valid sort option
$sort = 0;
else
$sort = (int)$_GET['sort'];
if(!isset($_GET['sort_type']) || !in_array($_GET['sort_type'], array(0,1)))
$sort_type = 0;
else
$sort_type = (int)$_GET['sort_type'];
if($sort == 1) {
$order_by = "`username` ". (!$sort_type ? "ASC" : "DESC");
} else {
$order_by = "`userid` ". (!$sort_type ? "ASC" : "DESC");
}
$show_sort_options = '';
foreach ($sort_name as $k => $v) {
if($k != $sort)
$show_sort_options .= "<li><a href='?sort=$k'>Sort by $v</a></li>";
}
// search
$where = '';
if(isset($_GET['q']))
$where = $db->parse("WHERE `username` LIKE ?s", '%'.$_GET['q'].'%');
if($total_results = $db->getRow("SELECT COUNT(*) as count FROM `".MLS_PREFIX."users` ?p", $where)->count) {
// pagination
if(!isset($page_number))
$page_number = (int)$_GET['page'] <= 0 ? 1 : (int)$_GET['page']; // grab the page number
$perpage = 10; // number of elements perpage
if($page_number > ceil($total_results/$perpage))
$page_number = ceil($total_results/$perpage);
$start = ($page_number - 1) * $perpage;
$data = $db->getAll("SELECT * FROM `".MLS_PREFIX."users` ?p ORDER BY ?p LIMIT ?i,?i", $where, $order_by, $start, $perpage);
$pagination = new pagination($total_results, $page_number, $perpage);
foreach($data as $u) {
$content .= "<li class='span5 clearfix'>
<div class='thumbnail clearfix'>
<a href='$set->url/profile.php?u=$u->userid'><img src='".$user->getAvatar($u->userid)."' width='80' alt='".$options->html($u->username)."' class='pull-left clearfix' style='margin-right:10px'>
<div class='caption' class='pull-left'>
<h4>
<a href='$set->url/profile.php?u=$u->userid'>".$user->showName($u->userid)."</a>
</h4>
<small><b>Last seen: </b> ".$options->tsince($u->lastactive)."</small>
</div>
</div>
</li>";
}
} else
$page->error = "No results were found !";
include 'header.php';
echo "
<div class='container'>
<h3 class='pull-left'>Users on ".$set->site_name."</h3>
<form class='form-search' action='?'>
<div class='input-append pull-right'>
<input class='span2 search-query' name='q' type='text' ".( isset($_GET['q']) ? "value='".$options->html($_GET['q'])."'" : "" )." placeholder='Search...'/>
<button type='submit' class='btn'><i class='icon-search'></i></button>
".$options->queryString("hidden", array("q","page"))."
</div>
</form>
<div class='clearfix'></div>
<div class='btn-group pull-right'>
<a class='btn btn' href='?sort=$sort&sort_type=".(!$sort_type ? 1 : 0)."'><i class='icon-chevron-".(!$sort_type ? 'up' : 'down')."'></i> Sort by ".$sort_name[$sort]."</a>
<a class='btn btn dropdown-toggle' data-toggle='dropdown' href='#'><span class='caret'></span></a>
<ul class='dropdown-menu'>
$show_sort_options
</ul>
</div>
<div class='clearfix'></div>";
if(isset($data))
echo "<small>Showing ".($start+1)."-".($start+count($data))." out of ".$total_results."</small><hr>";
else
echo "<hr>";
if(isset($page->error))
$options->error($page->error);
else if(isset($page->success))
$options->success($page->success);
echo "
<ul class='thumbnails'>
$content
</ul>
".(isset($pagination) ? $pagination->pages : "" )."
</div>";
include 'footer.php';