source: trunk/admin/user_list.php @ 768

Last change on this file since 768 was 768, checked in by plg, 19 years ago
  • profile.php is no longer used for listing users : admin/user_list.php comes back (as in 1.3 branch)
  • user list updated : ability to filter list on username
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.2 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
5// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2005-04-25 21:35:10 +0000 (Mon, 25 Apr 2005) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 768 $
12// +-----------------------------------------------------------------------+
13// | This program is free software; you can redistribute it and/or modify  |
14// | it under the terms of the GNU General Public License as published by  |
15// | the Free Software Foundation                                          |
16// |                                                                       |
17// | This program is distributed in the hope that it will be useful, but   |
18// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
19// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
20// | General Public License for more details.                              |
21// |                                                                       |
22// | You should have received a copy of the GNU General Public License     |
23// | along with this program; if not, write to the Free Software           |
24// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
25// | USA.                                                                  |
26// +-----------------------------------------------------------------------+
27
28/**
29 * Add users and manage users list
30 */
31
32// +-----------------------------------------------------------------------+
33// |                           initialization                              |
34// +-----------------------------------------------------------------------+
35
36if (!defined('PHPWG_ROOT_PATH'))
37{
38  die('Hacking attempt!');
39}
40include_once(PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php');
41
42// +-----------------------------------------------------------------------+
43// |                              add a user                               |
44// +-----------------------------------------------------------------------+
45
46if (isset($_POST['submit_add']))
47{
48  $errors = register_user($_POST['login'],
49                          $_POST['password'],
50                          $_POST['password'],
51                          '');
52}
53
54// +-----------------------------------------------------------------------+
55// |                             template init                             |
56// +-----------------------------------------------------------------------+
57
58$template->set_filenames(array('user_list'=>'admin/user_list.tpl'));
59
60$base_url = add_session_id(PHPWG_ROOT_PATH.'admin.php?page=user_list');
61
62$conf['users_page'] = 20;
63
64if (isset($_GET['start']) and is_numeric($_GET['start']))
65{
66  $start = $_GET['start'];
67}
68else
69{
70  $start = 0;
71}
72
73$template->assign_vars(
74  array(
75    'L_AUTH_USER'=>$lang['permuser_only_private'],
76    'L_GROUP_ADD_USER' => $lang['group_add_user'],
77    'L_SUBMIT'=>$lang['submit'],
78    'L_STATUS'=>$lang['user_status'],
79    'L_USERNAME' => $lang['login'],
80    'L_PASSWORD' => $lang['password'],
81    'L_EMAIL' => $lang['mail_address'],
82    'L_ORDER_BY' => $lang['order_by'],
83    'L_ACTIONS' => $lang['actions'],
84    'L_PERMISSIONS' => $lang['permissions'],
85    'L_USERS_LIST' => $lang['title_liste_users'],
86   
87    'F_ADD_ACTION' => $base_url,
88    'F_USERNAME' => @$_GET['username'],
89    'F_FILTER_ACTION' => PHPWG_ROOT_PATH.'admin.php'
90    ));
91
92if (isset($_GET['id']))
93{
94  $template->assign_block_vars('session', array('ID' => $_GET['id']));
95}
96
97$order_by_items = array('id' => $lang['registration_date'],
98                        'username' => $lang['login']);
99
100foreach ($order_by_items as $item => $label)
101{
102  $selected = (isset($_GET['order_by']) and $_GET['order_by'] == $item) ?
103    'selected="selected"' : '';
104  $template->assign_block_vars(
105    'order_by',
106    array(
107      'VALUE' => $item,
108      'CONTENT' => $label,
109      'SELECTED' => $selected
110      ));
111}
112
113$direction_items = array('asc' => $lang['ascending'],
114                         'desc' => $lang['descending']);
115
116foreach ($direction_items as $item => $label)
117{
118  $selected = (isset($_GET['direction']) and $_GET['direction'] == $item) ?
119    'selected="selected"' : '';
120  $template->assign_block_vars(
121    'direction',
122    array(
123      'VALUE' => $item,
124      'CONTENT' => $label,
125        'SELECTED' => $selected
126      ));
127}
128
129// +-----------------------------------------------------------------------+
130// |                                 filter                                |
131// +-----------------------------------------------------------------------+
132
133$username = !empty($_GET['username']) ? $_GET['username'] : '%';
134$username = str_replace('*', '%', $username);
135if (function_exists('mysql_real_escape_string'))
136{
137  $username = mysql_real_escape_string($username);
138}
139else
140{
141  $username = mysql_escape_string($username);
142}
143$username = !empty($username) ? $username : '%';
144
145// +-----------------------------------------------------------------------+
146// |                            navigation bar                             |
147// +-----------------------------------------------------------------------+
148
149$query = '
150SELECT count(*)
151  FROM '.USERS_TABLE.'
152  WHERE id != 2
153    AND username LIKE \''.$username.'\'
154;';
155list($counter) = mysql_fetch_row(pwg_query($query));
156
157$url = PHPWG_ROOT_PATH.'admin.php'.get_query_string_diff(array('start'));
158
159$navbar = create_navigation_bar($url,
160                                $counter,
161                                $start,
162                                $conf['users_page'],
163                                '');
164
165$template->assign_vars(array('NAVBAR' => $navbar));
166
167// +-----------------------------------------------------------------------+
168// |                               user list                               |
169// +-----------------------------------------------------------------------+
170
171$profile_url = PHPWG_ROOT_PATH.'admin.php?page=profile&amp;user_id=';
172$perm_url = PHPWG_ROOT_PATH.'admin.php?page=user_perm&amp;user_id=';
173
174$users = array();
175$user_ids = array();
176$groups_content = array();
177
178$order_by = 'id';
179if (isset($_GET['order_by'])
180    and in_array($_GET['order_by'], array_keys($order_by_items)))
181{
182  $order_by = $_GET['order_by'];
183}
184
185$direction = 'ASC';
186if (isset($_GET['direction'])
187    and in_array($_GET['direction'], array_keys($direction_items)))
188{
189  $direction = strtoupper($_GET['direction']);
190}
191
192$query = '
193SELECT id, username, mail_address, status
194  FROM '.USERS_TABLE.'
195  WHERE id != 2
196    AND username LIKE \''.$username.'\'
197  ORDER BY '.$order_by.' '.$direction.'
198  LIMIT '.$start.', '.$conf['users_page'].'
199;';
200$result = pwg_query($query);
201while ($row = mysql_fetch_array($result))
202{
203  array_push($users, $row);
204  array_push($user_ids, $row['id']);
205  $user_groups[$row['id']] = array();
206}
207
208if (count($user_ids) > 0)
209{
210  $query = '
211SELECT user_id, group_id, name
212  FROM '.USER_GROUP_TABLE.' INNER JOIN '.GROUPS_TABLE.' ON group_id = id
213  WHERE user_id IN ('.implode(',', $user_ids).')
214;';
215  $result = pwg_query($query);
216  while ($row = mysql_fetch_array($result))
217  {
218    $groups_content[$row['group_id']] = $row['name'];
219    array_push($user_groups[$row['user_id']], $row['group_id']);
220  }
221
222  foreach ($users as $item)
223  {
224    $groups = preg_replace('/(\d+)/e',
225                           "\$groups_content['$1']",
226                           implode(', ', $user_groups[$item['id']]));
227   
228    $template->assign_block_vars(
229      'user',
230      array(
231        'U_MOD'=>add_session_id($profile_url.$item['id']),
232        'U_PERM'=>add_session_id($perm_url.$item['id']),
233        'USERNAME'=>$item['username'],
234        'STATUS'=>$lang['user_status_'.$item['status']],
235        'EMAIL'=>isset($item['mail_address']) ? $item['mail_address'] : '',
236        'GROUPS'=>$groups
237        ));
238  }
239}
240
241// +-----------------------------------------------------------------------+
242// |                           html code display                           |
243// +-----------------------------------------------------------------------+
244
245$template->assign_var_from_handle('ADMIN_CONTENT', 'user_list');
246?>
Note: See TracBrowser for help on using the repository browser.