Changeset 3 for branches/rsr.v5.1.dev/web/punbb/userlist.php
- Timestamp:
- Nov 14, 2011, 11:17:15 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/rsr.v5.1.dev/web/punbb/userlist.php
r1 r3 1 1 <?php 2 /***********************************************************************3 2 4 Copyright (C) 2002-2005 Rickard Andersson (rickard@punbb.org) 3 /** 4 * Copyright (C) 2008-2011 FluxBB 5 * based on code by Rickard Andersson copyright (C) 2002-2008 PunBB 6 * License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher 7 */ 5 8 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', './'); 9 define('PUN_ROOT', dirname(__FILE__).'/'); 27 10 require PUN_ROOT.'include/common.php'; 28 11 … … 30 13 if ($pun_user['g_read_board'] == '0') 31 14 message($lang_common['No view']); 32 15 else if ($pun_user['g_view_users'] == '0') 16 message($lang_common['No permission']); 33 17 34 18 // Load the userlist.php language file … … 40 24 41 25 // 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;26 $show_post_count = ($pun_config['o_show_post_count'] == '1' || $pun_user['is_admmod']) ? true : false; 43 27 44 $username = (isset($_GET['username']) && $pun_user['g_search_users'] == '1') ? $_GET['username']: '';45 $show_group = (!isset($_GET['show_group']) || intval($_GET['show_group']) < -1 && intval($_GET['show_group']) > 2) ? -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']);28 $username = isset($_GET['username']) && $pun_user['g_search_users'] == '1' ? pun_trim($_GET['username']) : ''; 29 $show_group = isset($_GET['show_group']) ? intval($_GET['show_group']) : -1; 30 $sort_by = isset($_GET['sort_by']) && (in_array($_GET['sort_by'], array('username', 'registered')) || ($_GET['sort_by'] == 'num_posts' && $show_post_count)) ? $_GET['sort_by'] : 'username'; 31 $sort_dir = isset($_GET['sort_dir']) && $_GET['sort_dir'] == 'DESC' ? 'DESC' : 'ASC'; 48 32 33 // Create any SQL for the WHERE clause 34 $where_sql = array(); 35 $like_command = ($db_type == 'pgsql') ? 'ILIKE' : 'LIKE'; 49 36 50 $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_common['User list']; 37 if ($username != '') 38 $where_sql[] = 'u.username '.$like_command.' \''.$db->escape(str_replace('*', '%', $username)).'\''; 39 if ($show_group > -1) 40 $where_sql[] = 'u.group_id='.$show_group; 41 42 // Fetch user count 43 $result = $db->query('SELECT COUNT(id) FROM '.$db->prefix.'users AS u WHERE u.id>1 AND u.group_id!='.PUN_UNVERIFIED.(!empty($where_sql) ? ' AND '.implode(' AND ', $where_sql) : '')) or error('Unable to fetch user list count', __FILE__, __LINE__, $db->error()); 44 $num_users = $db->result($result); 45 46 // Determine the user offset (based on $_GET['p']) 47 $num_pages = ceil($num_users / 50); 48 49 $p = (!isset($_GET['p']) || $_GET['p'] <= 1 || $_GET['p'] > $num_pages) ? 1 : intval($_GET['p']); 50 $start_from = 50 * ($p - 1); 51 52 $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_common['User list']); 51 53 if ($pun_user['g_search_users'] == '1') 52 54 $focus_element = array('userlist', 'username'); 53 55 56 // Generate paging links 57 $paging_links = '<span class="pages-label">'.$lang_common['Pages'].' </span>'.paginate($num_pages, $p, 'userlist.php?username='.urlencode($username).'&show_group='.$show_group.'&sort_by='.$sort_by.'&sort_dir='.$sort_dir); 58 59 54 60 define('PUN_ALLOW_INDEX', 1); 61 define('PUN_ACTIVE_PAGE', 'userlist'); 55 62 require PUN_ROOT.'header.php'; 56 63 … … 59 66 <h2><span><?php echo $lang_search['User search'] ?></span></h2> 60 67 <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>68 <form id="userlist" method="get" action="userlist.php"> 69 <div class="inform"> 70 <fieldset> 71 <legend><?php echo $lang_ul['User find legend'] ?></legend> 72 <div class="infldset"> 73 <?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> 74 <?php endif; ?> <label class="conl"><?php echo $lang_ul['User group']."\n" ?> 75 <br /><select name="show_group"> 76 <option value="-1"<?php if ($show_group == -1) echo ' selected="selected"' ?>><?php echo $lang_ul['All users'] ?></option> 70 77 <?php 71 78 72 $result = $db->query('SELECT g_id, g_title FROM '.$db->prefix.'groups WHERE g_id!='.PUN_GUEST.' ORDER BY g_id') or error(' Impossible de retrouver la liste des groupes utilisateurs', __FILE__, __LINE__, $db->error());79 $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 80 74 81 while ($cur_group = $db->fetch_assoc($result)) 75 82 { 76 83 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";84 echo "\t\t\t\t\t\t\t".'<option value="'.$cur_group['g_id'].'" selected="selected">'.pun_htmlspecialchars($cur_group['g_title']).'</option>'."\n"; 78 85 else 79 echo "\t\t\t\t\t\t ".'<option value="'.$cur_group['g_id'].'">'.pun_htmlspecialchars($cur_group['g_title']).'</option>'."\n";86 echo "\t\t\t\t\t\t\t".'<option value="'.$cur_group['g_id'].'">'.pun_htmlspecialchars($cur_group['g_title']).'</option>'."\n"; 80 87 } 81 88 82 89 ?> 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>90 </select> 91 <br /></label> 92 <label class="conl"><?php echo $lang_search['Sort by']."\n" ?> 93 <br /><select name="sort_by"> 94 <option value="username"<?php if ($sort_by == 'username') echo ' selected="selected"' ?>><?php echo $lang_common['Username'] ?></option> 95 <option value="registered"<?php if ($sort_by == 'registered') echo ' selected="selected"' ?>><?php echo $lang_common['Registered'] ?></option> 96 <?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> 97 <?php endif; ?> </select> 98 <br /></label> 99 <label class="conl"><?php echo $lang_search['Sort order']."\n" ?> 100 <br /><select name="sort_dir"> 101 <option value="ASC"<?php if ($sort_dir == 'ASC') echo ' selected="selected"' ?>><?php echo $lang_search['Ascending'] ?></option> 102 <option value="DESC"<?php if ($sort_dir == 'DESC') echo ' selected="selected"' ?>><?php echo $lang_search['Descending'] ?></option> 103 </select> 104 <br /></label> 105 <p class="clearb"><?php echo ($pun_user['g_search_users'] == '1' ? $lang_ul['User search info'].' ' : '').$lang_ul['User sort info']; ?></p> 106 </div> 107 </fieldset> 108 </div> 109 <p class="buttons"><input type="submit" name="search" value="<?php echo $lang_common['Submit'] ?>" accesskey="s" /></p> 110 </form> 104 111 </div> 105 112 </div> 106 <?php107 113 108 109 // Create any SQL for the WHERE clause110 $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 count119 $result = $db->query('SELECT COUNT(id) FROM '.$db->prefix.'users AS u'.(!empty($where_sql) ? ' WHERE u.id>1 AND '.implode(' AND ', $where_sql) : '')) or error('Impossible de retrouver le nombre total de membres', __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 links130 $paging_links = $lang_common['Pages'].': '.paginate($num_pages, $p, 'userlist.php?username='.urlencode($username).'&show_group='.$show_group.'&sort_by='.$sort_by.'&sort_dir='.strtoupper($sort_dir));131 132 133 ?>134 114 <div class="linkst"> 135 115 <div class="inbox"> 136 116 <p class="pagelink"><?php echo $paging_links ?></p> 117 <div class="clearer"></div> 137 118 </div> 138 119 </div> … … 142 123 <div class="box"> 143 124 <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>125 <table cellspacing="0"> 126 <thead> 127 <tr> 128 <th class="tcl" scope="col"><?php echo $lang_common['Username'] ?></th> 129 <th class="tc2" scope="col"><?php echo $lang_common['Title'] ?></th> 130 <?php if ($show_post_count): ?> <th class="tc3" scope="col"><?php echo $lang_common['Posts'] ?></th> 131 <?php endif; ?> <th class="tcr" scope="col"><?php echo $lang_common['Registered'] ?></th> 132 </tr> 133 </thead> 134 <tbody> 154 135 <?php 155 136 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.' LIMIT '.$start_from.', 50') or error('Impossible de retrouver la liste des membres', __FILE__, __LINE__, $db->error()); 137 // Retrieve a list of user IDs, LIMIT is (really) expensive so we only fetch the IDs here then later fetch the remaining data 138 $result = $db->query('SELECT u.id FROM '.$db->prefix.'users AS u WHERE u.id>1 AND u.group_id!='.PUN_UNVERIFIED.(!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 IDs', __FILE__, __LINE__, $db->error()); 139 158 140 if ($db->num_rows($result)) 159 141 { 142 $user_ids = array(); 143 for ($i = 0;$cur_user_id = $db->result($result, $i);$i++) 144 $user_ids[] = $cur_user_id; 145 146 // Grab the users 147 $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 IN('.implode(',', $user_ids).') ORDER BY '.$sort_by.' '.$sort_dir.', u.id ASC') or error('Unable to fetch user list', __FILE__, __LINE__, $db->error()); 148 160 149 while ($user_data = $db->fetch_assoc($result)) 161 150 { … … 166 155 <td class="tcl"><?php echo '<a href="profile.php?id='.$user_data['id'].'">'.pun_htmlspecialchars($user_data['username']).'</a>' ?></td> 167 156 <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>157 <?php if ($show_post_count): ?> <td class="tc3"><?php echo forum_number_format($user_data['num_posts']) ?></td> 169 158 <?php endif; ?> 170 159 <td class="tcr"><?php echo format_time($user_data['registered'], true) ?></td> … … 187 176 <div class="inbox"> 188 177 <p class="pagelink"><?php echo $paging_links ?></p> 178 <div class="clearer"></div> 189 179 </div> 190 180 </div>
Note: See TracChangeset
for help on using the changeset viewer.