[768] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
| 3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
| 4 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
[1932] | 5 | // | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net | |
---|
[768] | 6 | // +-----------------------------------------------------------------------+ |
---|
[1926] | 7 | // | file : $Id: user_list.php 2201 2008-01-30 22:07:07Z rub $ |
---|
[768] | 8 | // | last update : $Date: 2008-01-30 22:07:07 +0000 (Wed, 30 Jan 2008) $ |
---|
| 9 | // | last modifier : $Author: rub $ |
---|
| 10 | // | revision : $Revision: 2201 $ |
---|
| 11 | // +-----------------------------------------------------------------------+ |
---|
| 12 | // | This program is free software; you can redistribute it and/or modify | |
---|
| 13 | // | it under the terms of the GNU General Public License as published by | |
---|
| 14 | // | the Free Software Foundation | |
---|
| 15 | // | | |
---|
| 16 | // | This program is distributed in the hope that it will be useful, but | |
---|
| 17 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
| 18 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
| 19 | // | General Public License for more details. | |
---|
| 20 | // | | |
---|
| 21 | // | You should have received a copy of the GNU General Public License | |
---|
| 22 | // | along with this program; if not, write to the Free Software | |
---|
| 23 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
| 24 | // | USA. | |
---|
| 25 | // +-----------------------------------------------------------------------+ |
---|
| 26 | |
---|
| 27 | /** |
---|
| 28 | * Add users and manage users list |
---|
| 29 | */ |
---|
| 30 | |
---|
| 31 | // +-----------------------------------------------------------------------+ |
---|
[880] | 32 | // | functions | |
---|
| 33 | // +-----------------------------------------------------------------------+ |
---|
| 34 | |
---|
| 35 | /** |
---|
| 36 | * returns a list of users depending on page filters (in $_GET) |
---|
| 37 | * |
---|
| 38 | * Each user comes with his related informations : id, username, mail |
---|
| 39 | * address, list of groups. |
---|
| 40 | * |
---|
| 41 | * @return array |
---|
| 42 | */ |
---|
| 43 | function get_filtered_user_list() |
---|
| 44 | { |
---|
| 45 | global $conf, $page; |
---|
| 46 | |
---|
| 47 | $users = array(); |
---|
[1620] | 48 | |
---|
[880] | 49 | // filter |
---|
| 50 | $filter = array(); |
---|
[1620] | 51 | |
---|
[880] | 52 | if (isset($_GET['username']) and !empty($_GET['username'])) |
---|
| 53 | { |
---|
| 54 | $username = str_replace('*', '%', $_GET['username']); |
---|
| 55 | if (function_exists('mysql_real_escape_string')) |
---|
| 56 | { |
---|
| 57 | $filter['username'] = mysql_real_escape_string($username); |
---|
| 58 | } |
---|
| 59 | else |
---|
| 60 | { |
---|
| 61 | $filter['username'] = mysql_escape_string($username); |
---|
| 62 | } |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | if (isset($_GET['group']) |
---|
| 66 | and -1 != $_GET['group'] |
---|
| 67 | and is_numeric($_GET['group'])) |
---|
| 68 | { |
---|
| 69 | $filter['group'] = $_GET['group']; |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | if (isset($_GET['status']) |
---|
| 73 | and in_array($_GET['status'], get_enums(USER_INFOS_TABLE, 'status'))) |
---|
| 74 | { |
---|
| 75 | $filter['status'] = $_GET['status']; |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | // how to order the list? |
---|
| 79 | $order_by = 'id'; |
---|
| 80 | if (isset($_GET['order_by']) |
---|
| 81 | and in_array($_GET['order_by'], array_keys($page['order_by_items']))) |
---|
| 82 | { |
---|
| 83 | $order_by = $_GET['order_by']; |
---|
| 84 | } |
---|
[1620] | 85 | |
---|
[880] | 86 | $direction = 'ASC'; |
---|
| 87 | if (isset($_GET['direction']) |
---|
| 88 | and in_array($_GET['direction'], array_keys($page['direction_items']))) |
---|
| 89 | { |
---|
| 90 | $direction = strtoupper($_GET['direction']); |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | // search users depending on filters and order |
---|
| 94 | $query = ' |
---|
| 95 | SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id, |
---|
| 96 | u.'.$conf['user_fields']['username'].' AS username, |
---|
| 97 | u.'.$conf['user_fields']['email'].' AS email, |
---|
[1079] | 98 | ui.status, |
---|
[1085] | 99 | ui.adviser, |
---|
[2084] | 100 | ui.enabled_high, |
---|
| 101 | ui.level |
---|
[880] | 102 | FROM '.USERS_TABLE.' AS u |
---|
| 103 | INNER JOIN '.USER_INFOS_TABLE.' AS ui |
---|
| 104 | ON u.'.$conf['user_fields']['id'].' = ui.user_id |
---|
| 105 | LEFT JOIN '.USER_GROUP_TABLE.' AS ug |
---|
| 106 | ON u.'.$conf['user_fields']['id'].' = ug.user_id |
---|
[1930] | 107 | WHERE u.'.$conf['user_fields']['id'].' > 0'; |
---|
[880] | 108 | if (isset($filter['username'])) |
---|
| 109 | { |
---|
| 110 | $query.= ' |
---|
| 111 | AND u.'.$conf['user_fields']['username'].' LIKE \''.$filter['username'].'\''; |
---|
| 112 | } |
---|
| 113 | if (isset($filter['group'])) |
---|
| 114 | { |
---|
| 115 | $query.= ' |
---|
| 116 | AND ug.group_id = '.$filter['group']; |
---|
| 117 | } |
---|
| 118 | if (isset($filter['status'])) |
---|
| 119 | { |
---|
| 120 | $query.= ' |
---|
| 121 | AND ui.status = \''.$filter['status']."'"; |
---|
| 122 | } |
---|
| 123 | $query.= ' |
---|
| 124 | ORDER BY '.$order_by.' '.$direction.' |
---|
| 125 | ;'; |
---|
| 126 | |
---|
| 127 | $result = pwg_query($query); |
---|
| 128 | while ($row = mysql_fetch_array($result)) |
---|
| 129 | { |
---|
| 130 | $user = $row; |
---|
| 131 | $user['groups'] = array(); |
---|
| 132 | |
---|
| 133 | array_push($users, $user); |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | // add group lists |
---|
| 137 | $user_ids = array(); |
---|
| 138 | foreach ($users as $i => $user) |
---|
| 139 | { |
---|
| 140 | $user_ids[$i] = $user['id']; |
---|
| 141 | } |
---|
| 142 | $user_nums = array_flip($user_ids); |
---|
[1620] | 143 | |
---|
[880] | 144 | if (count($user_ids) > 0) |
---|
| 145 | { |
---|
| 146 | $query = ' |
---|
| 147 | SELECT user_id, group_id |
---|
| 148 | FROM '.USER_GROUP_TABLE.' |
---|
| 149 | WHERE user_id IN ('.implode(',', $user_ids).') |
---|
| 150 | ;'; |
---|
| 151 | $result = pwg_query($query); |
---|
| 152 | while ($row = mysql_fetch_array($result)) |
---|
| 153 | { |
---|
| 154 | array_push( |
---|
| 155 | $users[$user_nums[$row['user_id']]]['groups'], |
---|
| 156 | $row['group_id'] |
---|
| 157 | ); |
---|
| 158 | } |
---|
| 159 | } |
---|
[1620] | 160 | |
---|
[880] | 161 | return $users; |
---|
| 162 | } |
---|
| 163 | |
---|
| 164 | // +-----------------------------------------------------------------------+ |
---|
[768] | 165 | // | initialization | |
---|
| 166 | // +-----------------------------------------------------------------------+ |
---|
| 167 | |
---|
| 168 | if (!defined('PHPWG_ROOT_PATH')) |
---|
| 169 | { |
---|
| 170 | die('Hacking attempt!'); |
---|
| 171 | } |
---|
| 172 | |
---|
[1072] | 173 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
| 174 | |
---|
| 175 | // +-----------------------------------------------------------------------+ |
---|
| 176 | // | Check Access and exit when user status is not ok | |
---|
| 177 | // +-----------------------------------------------------------------------+ |
---|
| 178 | check_status(ACCESS_ADMINISTRATOR); |
---|
| 179 | |
---|
[880] | 180 | $page['order_by_items'] = array( |
---|
[2201] | 181 | 'id' => l10n('registration_date'), |
---|
| 182 | 'username' => l10n('Username'), |
---|
[2090] | 183 | 'level' => l10n('Privacy level'), |
---|
| 184 | 'language' => l10n('language'), |
---|
[880] | 185 | ); |
---|
| 186 | |
---|
| 187 | $page['direction_items'] = array( |
---|
[2201] | 188 | 'asc' => l10n('ascending'), |
---|
| 189 | 'desc' => l10n('descending') |
---|
[880] | 190 | ); |
---|
| 191 | |
---|
[768] | 192 | // +-----------------------------------------------------------------------+ |
---|
| 193 | // | add a user | |
---|
| 194 | // +-----------------------------------------------------------------------+ |
---|
| 195 | |
---|
| 196 | if (isset($_POST['submit_add'])) |
---|
| 197 | { |
---|
[1753] | 198 | $page['errors'] = register_user( |
---|
[2178] | 199 | $_POST['login'], $_POST['password'], $_POST['email'], false); |
---|
[906] | 200 | |
---|
| 201 | if (count($page['errors']) == 0) |
---|
| 202 | { |
---|
| 203 | array_push( |
---|
| 204 | $page['infos'], |
---|
| 205 | sprintf( |
---|
| 206 | l10n('user "%s" added'), |
---|
| 207 | $_POST['login'] |
---|
| 208 | ) |
---|
| 209 | ); |
---|
| 210 | } |
---|
[768] | 211 | } |
---|
| 212 | |
---|
| 213 | // +-----------------------------------------------------------------------+ |
---|
[914] | 214 | // | user list | |
---|
| 215 | // +-----------------------------------------------------------------------+ |
---|
| 216 | |
---|
| 217 | $page['filtered_users'] = get_filtered_user_list(); |
---|
| 218 | |
---|
| 219 | // +-----------------------------------------------------------------------+ |
---|
[858] | 220 | // | selected users | |
---|
[787] | 221 | // +-----------------------------------------------------------------------+ |
---|
| 222 | |
---|
[858] | 223 | if (isset($_POST['delete']) or isset($_POST['pref_submit'])) |
---|
[787] | 224 | { |
---|
| 225 | $collection = array(); |
---|
[1620] | 226 | |
---|
[787] | 227 | switch ($_POST['target']) |
---|
| 228 | { |
---|
| 229 | case 'all' : |
---|
| 230 | { |
---|
[880] | 231 | foreach($page['filtered_users'] as $local_user) |
---|
| 232 | { |
---|
| 233 | array_push($collection, $local_user['id']); |
---|
| 234 | } |
---|
[787] | 235 | break; |
---|
| 236 | } |
---|
| 237 | case 'selection' : |
---|
| 238 | { |
---|
[805] | 239 | if (isset($_POST['selection'])) |
---|
| 240 | { |
---|
| 241 | $collection = $_POST['selection']; |
---|
| 242 | } |
---|
[787] | 243 | break; |
---|
| 244 | } |
---|
| 245 | } |
---|
| 246 | |
---|
[858] | 247 | if (count($collection) == 0) |
---|
[787] | 248 | { |
---|
[858] | 249 | array_push($page['errors'], l10n('Select at least one user')); |
---|
| 250 | } |
---|
| 251 | } |
---|
| 252 | |
---|
| 253 | // +-----------------------------------------------------------------------+ |
---|
| 254 | // | delete users | |
---|
| 255 | // +-----------------------------------------------------------------------+ |
---|
| 256 | if (isset($_POST['delete']) and count($collection) > 0) |
---|
| 257 | { |
---|
[2024] | 258 | if (in_array($conf['guest_id'], $collection)) |
---|
| 259 | { |
---|
| 260 | array_push($page['errors'], l10n('Guest cannot be deleted')); |
---|
| 261 | } |
---|
[2084] | 262 | if (($conf['guest_id'] != $conf['default_user_id']) and |
---|
[2024] | 263 | in_array($conf['default_user_id'], $collection)) |
---|
| 264 | { |
---|
| 265 | array_push($page['errors'], l10n('Default user cannot be deleted')); |
---|
| 266 | } |
---|
[858] | 267 | if (in_array($conf['webmaster_id'], $collection)) |
---|
| 268 | { |
---|
| 269 | array_push($page['errors'], l10n('Webmaster cannot be deleted')); |
---|
| 270 | } |
---|
[2024] | 271 | if (in_array($user['id'], $collection)) |
---|
[1489] | 272 | { |
---|
| 273 | array_push($page['errors'], l10n('You cannot delete your account')); |
---|
| 274 | } |
---|
[2024] | 275 | |
---|
| 276 | if (count($page['errors']) == 0) |
---|
[858] | 277 | { |
---|
| 278 | if (isset($_POST['confirm_deletion']) and 1 == $_POST['confirm_deletion']) |
---|
[805] | 279 | { |
---|
[858] | 280 | foreach ($collection as $user_id) |
---|
| 281 | { |
---|
| 282 | delete_user($user_id); |
---|
| 283 | } |
---|
| 284 | array_push( |
---|
| 285 | $page['infos'], |
---|
[1932] | 286 | l10n_dec( |
---|
| 287 | '%d user deleted', '%d users deleted', |
---|
[1620] | 288 | count($collection) |
---|
[858] | 289 | ) |
---|
| 290 | ); |
---|
[998] | 291 | foreach ($page['filtered_users'] as $filter_key => $filter_user) |
---|
| 292 | { |
---|
[1079] | 293 | if (in_array($filter_user['id'], $collection)) |
---|
| 294 | { |
---|
| 295 | unset($page['filtered_users'][$filter_key]); |
---|
| 296 | } |
---|
[998] | 297 | } |
---|
[858] | 298 | } |
---|
| 299 | else |
---|
| 300 | { |
---|
| 301 | array_push($page['errors'], l10n('You need to confirm deletion')); |
---|
| 302 | } |
---|
| 303 | } |
---|
| 304 | } |
---|
[787] | 305 | |
---|
[858] | 306 | // +-----------------------------------------------------------------------+ |
---|
| 307 | // | preferences form submission | |
---|
| 308 | // +-----------------------------------------------------------------------+ |
---|
| 309 | |
---|
| 310 | if (isset($_POST['pref_submit']) and count($collection) > 0) |
---|
| 311 | { |
---|
| 312 | if (-1 != $_POST['associate']) |
---|
| 313 | { |
---|
| 314 | $datas = array(); |
---|
[1620] | 315 | |
---|
[858] | 316 | $query = ' |
---|
[787] | 317 | SELECT user_id |
---|
| 318 | FROM '.USER_GROUP_TABLE.' |
---|
| 319 | WHERE group_id = '.$_POST['associate'].' |
---|
| 320 | ;'; |
---|
[858] | 321 | $associated = array_from_query($query, 'user_id'); |
---|
[1620] | 322 | |
---|
[858] | 323 | $associable = array_diff($collection, $associated); |
---|
[1620] | 324 | |
---|
[858] | 325 | if (count($associable) > 0) |
---|
| 326 | { |
---|
| 327 | foreach ($associable as $item) |
---|
[805] | 328 | { |
---|
[858] | 329 | array_push($datas, |
---|
| 330 | array('group_id'=>$_POST['associate'], |
---|
| 331 | 'user_id'=>$item)); |
---|
| 332 | } |
---|
[1620] | 333 | |
---|
[858] | 334 | mass_inserts(USER_GROUP_TABLE, |
---|
| 335 | array('group_id', 'user_id'), |
---|
| 336 | $datas); |
---|
[787] | 337 | } |
---|
[858] | 338 | } |
---|
[1620] | 339 | |
---|
[858] | 340 | if (-1 != $_POST['dissociate']) |
---|
| 341 | { |
---|
| 342 | $query = ' |
---|
[787] | 343 | DELETE FROM '.USER_GROUP_TABLE.' |
---|
| 344 | WHERE group_id = '.$_POST['dissociate'].' |
---|
| 345 | AND user_id IN ('.implode(',', $collection).') |
---|
| 346 | '; |
---|
[858] | 347 | pwg_query($query); |
---|
| 348 | } |
---|
[1620] | 349 | |
---|
[858] | 350 | // properties to set for the collection (a user list) |
---|
| 351 | $datas = array(); |
---|
| 352 | $dbfields = array('primary' => array('user_id'), 'update' => array()); |
---|
[1620] | 353 | |
---|
[858] | 354 | $formfields = |
---|
| 355 | array('nb_image_line', 'nb_line_page', 'template', 'language', |
---|
| 356 | 'recent_period', 'maxwidth', 'expand', 'show_nb_comments', |
---|
[2084] | 357 | 'show_nb_hits', 'maxheight', 'status', 'enabled_high', |
---|
| 358 | 'level'); |
---|
[1620] | 359 | |
---|
[2084] | 360 | $true_false_fields = array('expand', 'show_nb_comments', |
---|
[1763] | 361 | 'show_nb_hits', 'enabled_high'); |
---|
[1170] | 362 | if ($conf['allow_adviser']) |
---|
| 363 | { |
---|
| 364 | array_push($formfields, 'adviser'); |
---|
| 365 | array_push($true_false_fields, 'adviser'); |
---|
| 366 | } |
---|
[1620] | 367 | |
---|
[858] | 368 | foreach ($formfields as $formfield) |
---|
| 369 | { |
---|
| 370 | // special for true/false fields |
---|
| 371 | if (in_array($formfield, $true_false_fields)) |
---|
| 372 | { |
---|
| 373 | $test = $formfield; |
---|
[805] | 374 | } |
---|
[858] | 375 | else |
---|
| 376 | { |
---|
| 377 | $test = $formfield.'_action'; |
---|
| 378 | } |
---|
[1620] | 379 | |
---|
[858] | 380 | if ($_POST[$test] != 'leave') |
---|
[787] | 381 | { |
---|
[858] | 382 | array_push($dbfields['update'], $formfield); |
---|
[787] | 383 | } |
---|
[858] | 384 | } |
---|
[1620] | 385 | |
---|
[858] | 386 | // updating elements is useful only if needed... |
---|
| 387 | if (count($dbfields['update']) > 0) |
---|
| 388 | { |
---|
| 389 | $datas = array(); |
---|
[1620] | 390 | |
---|
[858] | 391 | foreach ($collection as $user_id) |
---|
[787] | 392 | { |
---|
[858] | 393 | $data = array(); |
---|
| 394 | $data['user_id'] = $user_id; |
---|
[1620] | 395 | |
---|
[858] | 396 | // TODO : verify if submited values are semanticaly correct |
---|
| 397 | foreach ($dbfields['update'] as $dbfield) |
---|
[787] | 398 | { |
---|
[858] | 399 | // if the action is 'unset', the key won't be in row and |
---|
| 400 | // mass_updates function will set this field to NULL |
---|
| 401 | if (in_array($dbfield, $true_false_fields) |
---|
| 402 | or 'set' == $_POST[$dbfield.'_action']) |
---|
[787] | 403 | { |
---|
[858] | 404 | $data[$dbfield] = $_POST[$dbfield]; |
---|
[787] | 405 | } |
---|
| 406 | } |
---|
[1085] | 407 | |
---|
[2024] | 408 | // special users checks |
---|
| 409 | if |
---|
| 410 | ( |
---|
| 411 | ($conf['webmaster_id'] == $user_id) or |
---|
| 412 | ($conf['guest_id'] == $user_id) or |
---|
| 413 | ($conf['default_user_id'] == $user_id) |
---|
| 414 | ) |
---|
[858] | 415 | { |
---|
[2024] | 416 | // status must not be changed |
---|
| 417 | if (isset($data['status'])) |
---|
| 418 | { |
---|
| 419 | if ($conf['webmaster_id'] == $user_id) |
---|
| 420 | { |
---|
| 421 | $data['status'] = 'webmaster'; |
---|
| 422 | } |
---|
| 423 | else |
---|
| 424 | { |
---|
| 425 | $data['status'] = 'guest'; |
---|
| 426 | } |
---|
| 427 | } |
---|
[1085] | 428 | |
---|
[2024] | 429 | // could not be adivser |
---|
| 430 | if (isset($data['adviser'])) |
---|
| 431 | { |
---|
| 432 | $data['adviser'] = 'false'; |
---|
| 433 | } |
---|
[1085] | 434 | } |
---|
| 435 | |
---|
[858] | 436 | array_push($datas, $data); |
---|
| 437 | } |
---|
[1620] | 438 | |
---|
[858] | 439 | mass_updates(USER_INFOS_TABLE, $dbfields, $datas); |
---|
[787] | 440 | } |
---|
[931] | 441 | |
---|
| 442 | redirect( |
---|
| 443 | PHPWG_ROOT_PATH. |
---|
| 444 | 'admin.php'. |
---|
[2089] | 445 | get_query_string_diff(array(), false) |
---|
[931] | 446 | ); |
---|
[787] | 447 | } |
---|
| 448 | |
---|
| 449 | // +-----------------------------------------------------------------------+ |
---|
| 450 | // | groups list | |
---|
| 451 | // +-----------------------------------------------------------------------+ |
---|
| 452 | |
---|
| 453 | $groups = array(); |
---|
| 454 | |
---|
| 455 | $query = ' |
---|
| 456 | SELECT id, name |
---|
| 457 | FROM '.GROUPS_TABLE.' |
---|
[1960] | 458 | ORDER BY name ASC |
---|
[787] | 459 | ;'; |
---|
| 460 | $result = pwg_query($query); |
---|
| 461 | |
---|
| 462 | while ($row = mysql_fetch_array($result)) |
---|
| 463 | { |
---|
| 464 | $groups[$row['id']] = $row['name']; |
---|
| 465 | } |
---|
| 466 | |
---|
| 467 | // +-----------------------------------------------------------------------+ |
---|
[768] | 468 | // | template init | |
---|
| 469 | // +-----------------------------------------------------------------------+ |
---|
| 470 | |
---|
| 471 | $template->set_filenames(array('user_list'=>'admin/user_list.tpl')); |
---|
| 472 | |
---|
[1004] | 473 | $base_url = PHPWG_ROOT_PATH.'admin.php?page=user_list'; |
---|
[768] | 474 | |
---|
| 475 | if (isset($_GET['start']) and is_numeric($_GET['start'])) |
---|
| 476 | { |
---|
| 477 | $start = $_GET['start']; |
---|
| 478 | } |
---|
| 479 | else |
---|
| 480 | { |
---|
| 481 | $start = 0; |
---|
| 482 | } |
---|
| 483 | |
---|
| 484 | $template->assign_vars( |
---|
| 485 | array( |
---|
[1250] | 486 | 'U_HELP' => PHPWG_ROOT_PATH.'popuphelp.php?page=user_list', |
---|
[1620] | 487 | |
---|
[768] | 488 | 'F_ADD_ACTION' => $base_url, |
---|
[1696] | 489 | 'F_USERNAME' => @htmlentities($_GET['username']), |
---|
[768] | 490 | 'F_FILTER_ACTION' => PHPWG_ROOT_PATH.'admin.php' |
---|
| 491 | )); |
---|
| 492 | |
---|
| 493 | if (isset($_GET['id'])) |
---|
| 494 | { |
---|
| 495 | $template->assign_block_vars('session', array('ID' => $_GET['id'])); |
---|
| 496 | } |
---|
| 497 | |
---|
[1087] | 498 | // Hide radio-button if not allow to assign adviser |
---|
| 499 | if ($conf['allow_adviser']) |
---|
| 500 | { |
---|
| 501 | $template->assign_block_vars('adviser', array()); |
---|
| 502 | } |
---|
| 503 | |
---|
[880] | 504 | foreach ($page['order_by_items'] as $item => $label) |
---|
[768] | 505 | { |
---|
| 506 | $selected = (isset($_GET['order_by']) and $_GET['order_by'] == $item) ? |
---|
| 507 | 'selected="selected"' : ''; |
---|
| 508 | $template->assign_block_vars( |
---|
| 509 | 'order_by', |
---|
| 510 | array( |
---|
| 511 | 'VALUE' => $item, |
---|
| 512 | 'CONTENT' => $label, |
---|
| 513 | 'SELECTED' => $selected |
---|
| 514 | )); |
---|
| 515 | } |
---|
| 516 | |
---|
[880] | 517 | foreach ($page['direction_items'] as $item => $label) |
---|
[768] | 518 | { |
---|
| 519 | $selected = (isset($_GET['direction']) and $_GET['direction'] == $item) ? |
---|
| 520 | 'selected="selected"' : ''; |
---|
| 521 | $template->assign_block_vars( |
---|
| 522 | 'direction', |
---|
| 523 | array( |
---|
| 524 | 'VALUE' => $item, |
---|
| 525 | 'CONTENT' => $label, |
---|
[776] | 526 | 'SELECTED' => $selected |
---|
[768] | 527 | )); |
---|
| 528 | } |
---|
| 529 | |
---|
[776] | 530 | $blockname = 'group_option'; |
---|
| 531 | |
---|
| 532 | $template->assign_block_vars( |
---|
| 533 | $blockname, |
---|
| 534 | array( |
---|
| 535 | 'VALUE'=> -1, |
---|
| 536 | 'CONTENT' => '------------', |
---|
| 537 | 'SELECTED' => '' |
---|
| 538 | )); |
---|
| 539 | |
---|
[787] | 540 | foreach ($groups as $group_id => $group_name) |
---|
[776] | 541 | { |
---|
[787] | 542 | $selected = (isset($_GET['group']) and $_GET['group'] == $group_id) ? |
---|
[776] | 543 | 'selected="selected"' : ''; |
---|
| 544 | $template->assign_block_vars( |
---|
| 545 | $blockname, |
---|
| 546 | array( |
---|
[787] | 547 | 'VALUE' => $group_id, |
---|
| 548 | 'CONTENT' => $group_name, |
---|
[776] | 549 | 'SELECTED' => $selected |
---|
| 550 | )); |
---|
| 551 | } |
---|
| 552 | |
---|
[777] | 553 | $blockname = 'status_option'; |
---|
| 554 | |
---|
| 555 | $template->assign_block_vars( |
---|
| 556 | $blockname, |
---|
| 557 | array( |
---|
| 558 | 'VALUE'=> -1, |
---|
| 559 | 'CONTENT' => '------------', |
---|
| 560 | 'SELECTED' => '' |
---|
| 561 | )); |
---|
| 562 | |
---|
[808] | 563 | foreach (get_enums(USER_INFOS_TABLE, 'status') as $status) |
---|
[777] | 564 | { |
---|
| 565 | $selected = (isset($_GET['status']) and $_GET['status'] == $status) ? |
---|
| 566 | 'selected="selected"' : ''; |
---|
| 567 | $template->assign_block_vars( |
---|
| 568 | $blockname, |
---|
| 569 | array( |
---|
| 570 | 'VALUE' => $status, |
---|
[2201] | 571 | 'CONTENT' => l10n('user_status_'.$status), |
---|
[777] | 572 | 'SELECTED' => $selected |
---|
| 573 | )); |
---|
| 574 | } |
---|
| 575 | |
---|
[787] | 576 | if (isset($_POST['pref_submit'])) |
---|
| 577 | { |
---|
| 578 | // echo '<pre>'; print_r($_POST); echo '</pre>'; |
---|
| 579 | $template->assign_vars( |
---|
| 580 | array( |
---|
[1170] | 581 | 'ADVISER_YES' => 'true' == (isset($_POST['adviser']) and $_POST['adviser']) ? 'checked="checked"' : '', |
---|
| 582 | 'ADVISER_NO' => 'false' == (isset($_POST['adviser']) and $_POST['adviser']) ? 'checked="checked"' : '', |
---|
[787] | 583 | 'NB_IMAGE_LINE' => $_POST['nb_image_line'], |
---|
| 584 | 'NB_LINE_PAGE' => $_POST['nb_line_page'], |
---|
| 585 | 'MAXWIDTH' => $_POST['maxwidth'], |
---|
| 586 | 'MAXHEIGHT' => $_POST['maxheight'], |
---|
| 587 | 'RECENT_PERIOD' => $_POST['recent_period'], |
---|
| 588 | 'EXPAND_YES' => 'true' == $_POST['expand'] ? 'checked="checked"' : '', |
---|
| 589 | 'EXPAND_NO' => 'false' == $_POST['expand'] ? 'checked="checked"' : '', |
---|
| 590 | 'SHOW_NB_COMMENTS_YES' => |
---|
| 591 | 'true' == $_POST['show_nb_comments'] ? 'checked="checked"' : '', |
---|
| 592 | 'SHOW_NB_COMMENTS_NO' => |
---|
[1085] | 593 | 'false' == $_POST['show_nb_comments'] ? 'checked="checked"' : '', |
---|
[1763] | 594 | 'SHOW_NB_HITS_YES' => |
---|
| 595 | 'true' == $_POST['show_nb_hits'] ? 'checked="checked"' : '', |
---|
| 596 | 'SHOW_NB_HITS_NO' => |
---|
| 597 | 'false' == $_POST['show_nb_hits'] ? 'checked="checked"' : '', |
---|
[1085] | 598 | 'ENABLED_HIGH_YES' => 'true' == $_POST['enabled_high'] ? 'checked="checked"' : '', |
---|
| 599 | 'ENABLED_HIGH_NO' => 'false' == $_POST['enabled_high'] ? 'checked="checked"' : '', |
---|
[787] | 600 | )); |
---|
| 601 | } |
---|
| 602 | else |
---|
| 603 | { |
---|
[1926] | 604 | $default_user = get_default_user_info(true); |
---|
[787] | 605 | $template->assign_vars( |
---|
| 606 | array( |
---|
[1926] | 607 | 'NB_IMAGE_LINE' => $default_user['nb_image_line'], |
---|
| 608 | 'NB_LINE_PAGE' => $default_user['nb_line_page'], |
---|
| 609 | 'MAXWIDTH' => $default_user['maxwidth'], |
---|
| 610 | 'MAXHEIGHT' => $default_user['maxheight'], |
---|
| 611 | 'RECENT_PERIOD' => $default_user['recent_period'], |
---|
[787] | 612 | )); |
---|
| 613 | } |
---|
| 614 | |
---|
| 615 | $blockname = 'template_option'; |
---|
| 616 | |
---|
[1048] | 617 | foreach (get_pwg_themes() as $pwg_template) |
---|
[787] | 618 | { |
---|
| 619 | if (isset($_POST['pref_submit'])) |
---|
| 620 | { |
---|
| 621 | $selected = $_POST['template']==$pwg_template ? 'selected="selected"' : ''; |
---|
| 622 | } |
---|
[1926] | 623 | else if (get_default_template() == $pwg_template) |
---|
[787] | 624 | { |
---|
| 625 | $selected = 'selected="selected"'; |
---|
| 626 | } |
---|
| 627 | else |
---|
| 628 | { |
---|
| 629 | $selected = ''; |
---|
| 630 | } |
---|
[1620] | 631 | |
---|
[787] | 632 | $template->assign_block_vars( |
---|
| 633 | $blockname, |
---|
| 634 | array( |
---|
| 635 | 'VALUE'=> $pwg_template, |
---|
| 636 | 'CONTENT' => $pwg_template, |
---|
| 637 | 'SELECTED' => $selected |
---|
| 638 | )); |
---|
| 639 | } |
---|
| 640 | |
---|
| 641 | $blockname = 'language_option'; |
---|
| 642 | |
---|
| 643 | foreach (get_languages() as $language_code => $language_name) |
---|
| 644 | { |
---|
| 645 | if (isset($_POST['pref_submit'])) |
---|
| 646 | { |
---|
| 647 | $selected = $_POST['language']==$language_code ? 'selected="selected"':''; |
---|
| 648 | } |
---|
[1926] | 649 | else if (get_default_language() == $language_code) |
---|
[787] | 650 | { |
---|
| 651 | $selected = 'selected="selected"'; |
---|
| 652 | } |
---|
| 653 | else |
---|
| 654 | { |
---|
| 655 | $selected = ''; |
---|
| 656 | } |
---|
[1620] | 657 | |
---|
[787] | 658 | $template->assign_block_vars( |
---|
| 659 | $blockname, |
---|
| 660 | array( |
---|
| 661 | 'VALUE'=> $language_code, |
---|
| 662 | 'CONTENT' => $language_name, |
---|
| 663 | 'SELECTED' => $selected |
---|
| 664 | )); |
---|
| 665 | } |
---|
| 666 | |
---|
| 667 | $blockname = 'pref_status_option'; |
---|
| 668 | |
---|
[808] | 669 | foreach (get_enums(USER_INFOS_TABLE, 'status') as $status) |
---|
[787] | 670 | { |
---|
| 671 | if (isset($_POST['pref_submit'])) |
---|
| 672 | { |
---|
| 673 | $selected = $_POST['status'] == $status ? 'selected="selected"' : ''; |
---|
| 674 | } |
---|
[1070] | 675 | else if ('normal' == $status) |
---|
[787] | 676 | { |
---|
| 677 | $selected = 'selected="selected"'; |
---|
| 678 | } |
---|
| 679 | else |
---|
| 680 | { |
---|
| 681 | $selected = ''; |
---|
| 682 | } |
---|
[1085] | 683 | |
---|
| 684 | // Only status <= can be assign |
---|
| 685 | if (is_autorize_status(get_access_type_status($status))) |
---|
| 686 | { |
---|
| 687 | $template->assign_block_vars( |
---|
| 688 | $blockname, |
---|
| 689 | array( |
---|
| 690 | 'VALUE' => $status, |
---|
[2201] | 691 | 'CONTENT' => l10n('user_status_'.$status), |
---|
[1085] | 692 | 'SELECTED' => $selected |
---|
| 693 | )); |
---|
| 694 | } |
---|
[787] | 695 | } |
---|
| 696 | |
---|
| 697 | // associate |
---|
| 698 | $blockname = 'associate_option'; |
---|
| 699 | |
---|
| 700 | $template->assign_block_vars( |
---|
| 701 | $blockname, |
---|
| 702 | array( |
---|
| 703 | 'VALUE'=> -1, |
---|
| 704 | 'CONTENT' => '------------', |
---|
| 705 | 'SELECTED' => '' |
---|
| 706 | )); |
---|
| 707 | |
---|
| 708 | foreach ($groups as $group_id => $group_name) |
---|
| 709 | { |
---|
| 710 | if (isset($_POST['pref_submit'])) |
---|
| 711 | { |
---|
| 712 | $selected = $_POST['associate'] == $group_id ? 'selected="selected"' : ''; |
---|
| 713 | } |
---|
| 714 | else |
---|
| 715 | { |
---|
| 716 | $selected = ''; |
---|
| 717 | } |
---|
[1620] | 718 | |
---|
[787] | 719 | $template->assign_block_vars( |
---|
| 720 | $blockname, |
---|
| 721 | array( |
---|
| 722 | 'VALUE' => $group_id, |
---|
| 723 | 'CONTENT' => $group_name, |
---|
| 724 | 'SELECTED' => $selected |
---|
| 725 | )); |
---|
| 726 | } |
---|
| 727 | |
---|
| 728 | // dissociate |
---|
| 729 | $blockname = 'dissociate_option'; |
---|
| 730 | |
---|
| 731 | $template->assign_block_vars( |
---|
| 732 | $blockname, |
---|
| 733 | array( |
---|
| 734 | 'VALUE'=> -1, |
---|
| 735 | 'CONTENT' => '------------', |
---|
| 736 | 'SELECTED' => '' |
---|
| 737 | )); |
---|
| 738 | |
---|
| 739 | foreach ($groups as $group_id => $group_name) |
---|
| 740 | { |
---|
| 741 | if (isset($_POST['pref_submit'])) |
---|
| 742 | { |
---|
| 743 | $selected = $_POST['dissociate'] == $group_id ? 'selected="selected"' : ''; |
---|
| 744 | } |
---|
| 745 | else |
---|
| 746 | { |
---|
| 747 | $selected = ''; |
---|
| 748 | } |
---|
[1620] | 749 | |
---|
[787] | 750 | $template->assign_block_vars( |
---|
| 751 | $blockname, |
---|
| 752 | array( |
---|
| 753 | 'VALUE' => $group_id, |
---|
| 754 | 'CONTENT' => $group_name, |
---|
| 755 | 'SELECTED' => $selected |
---|
| 756 | )); |
---|
| 757 | } |
---|
| 758 | |
---|
[2084] | 759 | // user level options |
---|
| 760 | $blockname = 'level_option'; |
---|
| 761 | foreach ($conf['available_permission_levels'] as $level) |
---|
| 762 | { |
---|
| 763 | $template->assign_block_vars( |
---|
| 764 | $blockname, |
---|
| 765 | array( |
---|
| 766 | 'VALUE' => $level, |
---|
| 767 | 'CONTENT' => l10n( sprintf('Level %d', $level) ), |
---|
| 768 | 'SELECTED' => $level==$default_user['level'] ? 'selected="selected"' : '', |
---|
| 769 | )); |
---|
| 770 | } |
---|
| 771 | |
---|
[768] | 772 | // +-----------------------------------------------------------------------+ |
---|
| 773 | // | navigation bar | |
---|
| 774 | // +-----------------------------------------------------------------------+ |
---|
| 775 | |
---|
| 776 | $url = PHPWG_ROOT_PATH.'admin.php'.get_query_string_diff(array('start')); |
---|
| 777 | |
---|
[880] | 778 | $navbar = create_navigation_bar( |
---|
| 779 | $url, |
---|
| 780 | count($page['filtered_users']), |
---|
| 781 | $start, |
---|
[1084] | 782 | $conf['users_page'] |
---|
[880] | 783 | ); |
---|
[768] | 784 | |
---|
| 785 | $template->assign_vars(array('NAVBAR' => $navbar)); |
---|
| 786 | |
---|
| 787 | // +-----------------------------------------------------------------------+ |
---|
| 788 | // | user list | |
---|
| 789 | // +-----------------------------------------------------------------------+ |
---|
| 790 | |
---|
[1753] | 791 | $profile_url = get_root_url().'admin.php?page=profile&user_id='; |
---|
| 792 | $perm_url = get_root_url().'admin.php?page=user_perm&user_id='; |
---|
[768] | 793 | |
---|
[2041] | 794 | $visible_user_list = array(); |
---|
[880] | 795 | foreach ($page['filtered_users'] as $num => $local_user) |
---|
[768] | 796 | { |
---|
[880] | 797 | // simulate LIMIT $start, $conf['users_page'] |
---|
| 798 | if ($num < $start) |
---|
| 799 | { |
---|
| 800 | continue; |
---|
| 801 | } |
---|
| 802 | if ($num >= $start + $conf['users_page']) |
---|
| 803 | { |
---|
| 804 | break; |
---|
| 805 | } |
---|
[768] | 806 | |
---|
[2041] | 807 | $visible_user_list[] = $local_user; |
---|
| 808 | } |
---|
| 809 | |
---|
| 810 | $visible_user_list = trigger_event('loc_visible_user_list', $visible_user_list); |
---|
| 811 | |
---|
| 812 | foreach ($visible_user_list as $num => $local_user) |
---|
| 813 | { |
---|
[880] | 814 | $groups_string = preg_replace( |
---|
| 815 | '/(\d+)/e', |
---|
| 816 | "\$groups['$1']", |
---|
| 817 | implode( |
---|
| 818 | ', ', |
---|
| 819 | $local_user['groups'] |
---|
| 820 | ) |
---|
| 821 | ); |
---|
[768] | 822 | |
---|
[880] | 823 | if (isset($_POST['pref_submit']) |
---|
| 824 | and isset($_POST['selection']) |
---|
| 825 | and in_array($local_user['id'], $_POST['selection'])) |
---|
[768] | 826 | { |
---|
[880] | 827 | $checked = 'checked="checked"'; |
---|
[768] | 828 | } |
---|
[880] | 829 | else |
---|
[768] | 830 | { |
---|
[880] | 831 | $checked = ''; |
---|
| 832 | } |
---|
[1087] | 833 | |
---|
[2084] | 834 | $properties = array(); |
---|
[2090] | 835 | if ( $local_user['level'] != 0 ) |
---|
| 836 | { |
---|
| 837 | $properties[] = l10n( sprintf('Level %d', $local_user['level']) ); |
---|
| 838 | } |
---|
[2084] | 839 | $properties[] = |
---|
| 840 | (isset($local_user['enabled_high']) and ($local_user['enabled_high'] == 'true')) |
---|
[2201] | 841 | ? l10n('is_high_enabled') : l10n('is_high_disabled'); |
---|
[2084] | 842 | |
---|
[880] | 843 | $template->assign_block_vars( |
---|
| 844 | 'user', |
---|
| 845 | array( |
---|
| 846 | 'CLASS' => ($num % 2 == 1) ? 'row2' : 'row1', |
---|
| 847 | 'ID' => $local_user['id'], |
---|
| 848 | 'CHECKED' => $checked, |
---|
[1753] | 849 | 'U_PROFILE' => $profile_url.$local_user['id'], |
---|
[1004] | 850 | 'U_PERM' => $perm_url.$local_user['id'], |
---|
[1930] | 851 | 'USERNAME' => $local_user['username'] |
---|
| 852 | .($local_user['id'] == $conf['guest_id'] |
---|
| 853 | ? '<BR />['.l10n('is_the_guest').']' : '') |
---|
| 854 | .($local_user['id'] == $conf['default_user_id'] |
---|
| 855 | ? '<BR />['.l10n('is_the_default').']' : ''), |
---|
[2201] | 856 | 'STATUS' => l10n('user_status_'. |
---|
| 857 | $local_user['status']).(($local_user['adviser'] == 'true') |
---|
[1930] | 858 | ? '<BR />['.l10n('adviser').']' : ''), |
---|
[1462] | 859 | 'EMAIL' => get_email_address_as_display_text($local_user['email']), |
---|
[1079] | 860 | 'GROUPS' => $groups_string, |
---|
[2090] | 861 | 'PROPERTIES' => implode( ', ', $properties), |
---|
[880] | 862 | ) |
---|
| 863 | ); |
---|
[2041] | 864 | trigger_action('loc_assign_block_var_local_user_list', $local_user); |
---|
[768] | 865 | } |
---|
| 866 | |
---|
| 867 | // +-----------------------------------------------------------------------+ |
---|
| 868 | // | html code display | |
---|
| 869 | // +-----------------------------------------------------------------------+ |
---|
| 870 | |
---|
| 871 | $template->assign_var_from_handle('ADMIN_CONTENT', 'user_list'); |
---|
| 872 | ?> |
---|