bug3
[aidenligne_francais_universite.git] / fluxbb / userlist.php
1 <?php
2 /***********************************************************************
3
4 Copyright (C) 2002-2005 Rickard Andersson (rickard@punbb.org)
5
6 This file is part of PunBB.
7
8 PunBB is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published
10 by the Free Software Foundation; either version 2 of the License,
11 or (at your option) any later version.
12
13 PunBB is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 MA 02111-1307 USA
22
23 ************************************************************************/
24
25
26 define('PUN_ROOT', './');
27 require PUN_ROOT.'include/common.php';
28
29
30 if ($pun_user['g_read_board'] == '0')
31 message($lang_common['No view']);
32
33
34 // Load the userlist.php language file
35 require PUN_ROOT.'lang/'.$pun_user['language'].'/userlist.php';
36
37 // Load the search.php language file
38 require PUN_ROOT.'lang/'.$pun_user['language'].'/search.php';
39
40
41 // Determine if we are allowed to view post counts
42 $show_post_count = ($pun_config['o_show_post_count'] == '1' || $pun_user['g_id'] < PUN_GUEST) ? true : false;
43
44 $username = (isset($_GET['username']) && $pun_user['g_search_users'] == '1') ? pun_trim($_GET['username']) : '';
45 $show_group = !isset($_GET['show_group']) ? -1 : intval($_GET['show_group']);
46 $sort_by = (!isset($_GET['sort_by']) || $_GET['sort_by'] != 'username' && $_GET['sort_by'] != 'registered' && ($_GET['sort_by'] != 'num_posts' || !$show_post_count)) ? 'username' : $_GET['sort_by'];
47 $sort_dir = (!isset($_GET['sort_dir']) || $_GET['sort_dir'] != 'ASC' && $_GET['sort_dir'] != 'DESC') ? 'ASC' : strtoupper($_GET['sort_dir']);
48
49
50 $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_common['User list'];
51 if ($pun_user['g_search_users'] == '1')
52 $focus_element = array('userlist', 'username');
53
54 define('PUN_ALLOW_INDEX', 1);
55 require PUN_ROOT.'header.php';
56
57 ?>
58 <div class="blockform">
59 <h2><span><?php echo $lang_search['User search'] ?></span></h2>
60 <div class="box">
61 <form id="userlist" method="get" action="userlist.php">
62 <div class="inform">
63 <fieldset>
64 <legend><?php echo $lang_ul['User find legend'] ?></legend>
65 <div class="infldset">
66 <?php if ($pun_user['g_search_users'] == '1'): ?> <label class="conl"><?php echo $lang_common['Username'] ?><br /><input type="text" name="username" value="<?php echo pun_htmlspecialchars($username) ?>" size="25" maxlength="25" /><br /></label>
67 <?php endif; ?> <label class="conl"><?php echo $lang_ul['User group']."\n" ?>
68 <br /><select name="show_group">
69 <option value="-1"<?php if ($show_group == -1) echo ' selected="selected"' ?>><?php echo $lang_ul['All users'] ?></option>
70 <?php
71
72 $result = $db->query('SELECT g_id, g_title FROM '.$db->prefix.'groups WHERE g_id!='.PUN_GUEST.' ORDER BY g_id') or error('Unable to fetch user group list', __FILE__, __LINE__, $db->error());
73
74 while ($cur_group = $db->fetch_assoc($result))
75 {
76 if ($cur_group['g_id'] == $show_group)
77 echo "\t\t\t\t\t\t".'<option value="'.$cur_group['g_id'].'" selected="selected">'.pun_htmlspecialchars($cur_group['g_title']).'</option>'."\n";
78 else
79 echo "\t\t\t\t\t\t".'<option value="'.$cur_group['g_id'].'">'.pun_htmlspecialchars($cur_group['g_title']).'</option>'."\n";
80 }
81
82 ?>
83 </select>
84 <br /></label>
85 <label class="conl"><?php echo $lang_search['Sort by']."\n" ?>
86 <br /><select name="sort_by">
87 <option value="username"<?php if ($sort_by == 'username') echo ' selected="selected"' ?>><?php echo $lang_common['Username'] ?></option>
88 <option value="registered"<?php if ($sort_by == 'registered') echo ' selected="selected"' ?>><?php echo $lang_common['Registered'] ?></option>
89 <?php if ($show_post_count): ?> <option value="num_posts"<?php if ($sort_by == 'num_posts') echo ' selected="selected"' ?>><?php echo $lang_ul['No of posts'] ?></option>
90 <?php endif; ?> </select>
91 <br /></label>
92 <label class="conl"><?php echo $lang_search['Sort order']."\n" ?>
93 <br /><select name="sort_dir">
94 <option value="ASC"<?php if ($sort_dir == 'ASC') echo ' selected="selected"' ?>><?php echo $lang_search['Ascending'] ?></option>
95 <option value="DESC"<?php if ($sort_dir == 'DESC') echo ' selected="selected"' ?>><?php echo $lang_search['Descending'] ?></option>
96 </select>
97 <br /></label>
98 <p class="clearb"><?php echo $lang_ul['User search info'] ?></p>
99 </div>
100 </fieldset>
101 </div>
102 <p><input type="submit" name="search" value="<?php echo $lang_common['Submit'] ?>" accesskey="s" /></p>
103 </form>
104 </div>
105 </div>
106 <?php
107
108
109 // Create any SQL for the WHERE clause
110 $where_sql = array();
111 $like_command = ($db_type == 'pgsql') ? 'ILIKE' : 'LIKE';
112
113 if ($pun_user['g_search_users'] == '1' && $username != '')
114 $where_sql[] = 'u.username '.$like_command.' \''.$db->escape(str_replace('*', '%', $username)).'\'';
115 if ($show_group > -1)
116 $where_sql[] = 'u.group_id='.$show_group;
117
118 // Fetch user count
119 $result = $db->query('SELECT COUNT(id) FROM '.$db->prefix.'users AS u WHERE u.id>1'.(!empty($where_sql) ? ' AND '.implode(' AND ', $where_sql) : '')) or error('Unable to fetch user list count', __FILE__, __LINE__, $db->error());
120 $num_users = $db->result($result);
121
122
123 // Determine the user offset (based on $_GET['p'])
124 $num_pages = ceil($num_users / 50);
125
126 $p = (!isset($_GET['p']) || $_GET['p'] <= 1 || $_GET['p'] > $num_pages) ? 1 : $_GET['p'];
127 $start_from = 50 * ($p - 1);
128
129 // Generate paging links
130 $paging_links = $lang_common['Pages'].': '.paginate($num_pages, $p, 'userlist.php?username='.urlencode($username).'&amp;show_group='.$show_group.'&amp;sort_by='.$sort_by.'&amp;sort_dir='.strtoupper($sort_dir));
131
132
133 ?>
134 <div class="linkst">
135 <div class="inbox">
136 <p class="pagelink"><?php echo $paging_links ?></p>
137 </div>
138 </div>
139
140 <div id="users1" class="blocktable">
141 <h2><span><?php echo $lang_common['User list'] ?></span></h2>
142 <div class="box">
143 <div class="inbox">
144 <table cellspacing="0">
145 <thead>
146 <tr>
147 <th class="tcl" scope="col"><?php echo $lang_common['Username'] ?></th>
148 <th class="tc2" scope="col"><?php echo $lang_common['Title'] ?></th>
149 <?php if ($show_post_count): ?> <th class="tc3" scope="col"><?php echo $lang_common['Posts'] ?></th>
150 <?php endif; ?> <th class="tcr" scope="col"><?php echo $lang_common['Registered'] ?></th>
151 </tr>
152 </thead>
153 <tbody>
154 <?php
155
156 // Grab the users
157 $result = $db->query('SELECT u.id, u.username, u.title, u.num_posts, u.registered, g.g_id, g.g_user_title FROM '.$db->prefix.'users AS u LEFT JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id WHERE u.id>1'.(!empty($where_sql) ? ' AND '.implode(' AND ', $where_sql) : '').' ORDER BY '.$sort_by.' '.$sort_dir.', u.id ASC LIMIT '.$start_from.', 50') or error('Unable to fetch user list', __FILE__, __LINE__, $db->error());
158 if ($db->num_rows($result))
159 {
160 while ($user_data = $db->fetch_assoc($result))
161 {
162 $user_title_field = get_title($user_data);
163
164 ?>
165 <tr>
166 <td class="tcl"><?php echo '<a href="profile.php?id='.$user_data['id'].'">'.pun_htmlspecialchars($user_data['username']).'</a>' ?></td>
167 <td class="tc2"><?php echo $user_title_field ?></td>
168 <?php if ($show_post_count): ?> <td class="tc3"><?php echo $user_data['num_posts'] ?></td>
169 <?php endif; ?>
170 <td class="tcr"><?php echo format_time($user_data['registered'], true) ?></td>
171 </tr>
172 <?php
173
174 }
175 }
176 else
177 echo "\t\t\t".'<tr>'."\n\t\t\t\t\t".'<td class="tcl" colspan="'.(($show_post_count) ? 4 : 3).'">'.$lang_search['No hits'].'</td></tr>'."\n";
178
179 ?>
180 </tbody>
181 </table>
182 </div>
183 </div>
184 </div>
185
186 <div class="linksb">
187 <div class="inbox">
188 <p class="pagelink"><?php echo $paging_links ?></p>
189 </div>
190 </div>
191 <?php
192
193 require PUN_ROOT.'footer.php';