[768] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
[2297] | 3 | // | Piwigo - a PHP based picture gallery | |
---|
| 4 | // +-----------------------------------------------------------------------+ |
---|
[3046] | 5 | // | Copyright(C) 2008-2009 Piwigo Team http://piwigo.org | |
---|
[2297] | 6 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
| 7 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
| 8 | // +-----------------------------------------------------------------------+ |
---|
| 9 | // | This program is free software; you can redistribute it and/or modify | |
---|
| 10 | // | it under the terms of the GNU General Public License as published by | |
---|
| 11 | // | the Free Software Foundation | |
---|
| 12 | // | | |
---|
| 13 | // | This program 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 GNU | |
---|
| 16 | // | 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, MA 02111-1307, | |
---|
| 21 | // | USA. | |
---|
| 22 | // +-----------------------------------------------------------------------+ |
---|
[768] | 23 | |
---|
| 24 | /** |
---|
| 25 | * Add users and manage users list |
---|
| 26 | */ |
---|
| 27 | |
---|
| 28 | // +-----------------------------------------------------------------------+ |
---|
[880] | 29 | // | functions | |
---|
| 30 | // +-----------------------------------------------------------------------+ |
---|
| 31 | |
---|
| 32 | /** |
---|
| 33 | * returns a list of users depending on page filters (in $_GET) |
---|
| 34 | * |
---|
| 35 | * Each user comes with his related informations : id, username, mail |
---|
| 36 | * address, list of groups. |
---|
| 37 | * |
---|
| 38 | * @return array |
---|
| 39 | */ |
---|
| 40 | function get_filtered_user_list() |
---|
| 41 | { |
---|
| 42 | global $conf, $page; |
---|
| 43 | |
---|
| 44 | $users = array(); |
---|
[1620] | 45 | |
---|
[880] | 46 | // filter |
---|
| 47 | $filter = array(); |
---|
[1620] | 48 | |
---|
[880] | 49 | if (isset($_GET['username']) and !empty($_GET['username'])) |
---|
| 50 | { |
---|
| 51 | $username = str_replace('*', '%', $_GET['username']); |
---|
[2753] | 52 | $filter['username'] = mysql_real_escape_string($username); |
---|
[880] | 53 | } |
---|
| 54 | |
---|
| 55 | if (isset($_GET['group']) |
---|
| 56 | and -1 != $_GET['group'] |
---|
| 57 | and is_numeric($_GET['group'])) |
---|
| 58 | { |
---|
| 59 | $filter['group'] = $_GET['group']; |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | if (isset($_GET['status']) |
---|
| 63 | and in_array($_GET['status'], get_enums(USER_INFOS_TABLE, 'status'))) |
---|
| 64 | { |
---|
| 65 | $filter['status'] = $_GET['status']; |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | // how to order the list? |
---|
| 69 | $order_by = 'id'; |
---|
| 70 | if (isset($_GET['order_by']) |
---|
| 71 | and in_array($_GET['order_by'], array_keys($page['order_by_items']))) |
---|
| 72 | { |
---|
| 73 | $order_by = $_GET['order_by']; |
---|
| 74 | } |
---|
[1620] | 75 | |
---|
[880] | 76 | $direction = 'ASC'; |
---|
| 77 | if (isset($_GET['direction']) |
---|
| 78 | and in_array($_GET['direction'], array_keys($page['direction_items']))) |
---|
| 79 | { |
---|
| 80 | $direction = strtoupper($_GET['direction']); |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | // search users depending on filters and order |
---|
| 84 | $query = ' |
---|
| 85 | SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id, |
---|
| 86 | u.'.$conf['user_fields']['username'].' AS username, |
---|
| 87 | u.'.$conf['user_fields']['email'].' AS email, |
---|
[1079] | 88 | ui.status, |
---|
[1085] | 89 | ui.adviser, |
---|
[2084] | 90 | ui.enabled_high, |
---|
| 91 | ui.level |
---|
[880] | 92 | FROM '.USERS_TABLE.' AS u |
---|
| 93 | INNER JOIN '.USER_INFOS_TABLE.' AS ui |
---|
| 94 | ON u.'.$conf['user_fields']['id'].' = ui.user_id |
---|
| 95 | LEFT JOIN '.USER_GROUP_TABLE.' AS ug |
---|
| 96 | ON u.'.$conf['user_fields']['id'].' = ug.user_id |
---|
[1930] | 97 | WHERE u.'.$conf['user_fields']['id'].' > 0'; |
---|
[880] | 98 | if (isset($filter['username'])) |
---|
| 99 | { |
---|
| 100 | $query.= ' |
---|
| 101 | AND u.'.$conf['user_fields']['username'].' LIKE \''.$filter['username'].'\''; |
---|
| 102 | } |
---|
| 103 | if (isset($filter['group'])) |
---|
| 104 | { |
---|
| 105 | $query.= ' |
---|
| 106 | AND ug.group_id = '.$filter['group']; |
---|
| 107 | } |
---|
| 108 | if (isset($filter['status'])) |
---|
| 109 | { |
---|
| 110 | $query.= ' |
---|
| 111 | AND ui.status = \''.$filter['status']."'"; |
---|
| 112 | } |
---|
| 113 | $query.= ' |
---|
| 114 | ORDER BY '.$order_by.' '.$direction.' |
---|
| 115 | ;'; |
---|
| 116 | |
---|
| 117 | $result = pwg_query($query); |
---|
| 118 | while ($row = mysql_fetch_array($result)) |
---|
| 119 | { |
---|
| 120 | $user = $row; |
---|
| 121 | $user['groups'] = array(); |
---|
| 122 | |
---|
| 123 | array_push($users, $user); |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | // add group lists |
---|
| 127 | $user_ids = array(); |
---|
| 128 | foreach ($users as $i => $user) |
---|
| 129 | { |
---|
| 130 | $user_ids[$i] = $user['id']; |
---|
| 131 | } |
---|
| 132 | $user_nums = array_flip($user_ids); |
---|
[1620] | 133 | |
---|
[880] | 134 | if (count($user_ids) > 0) |
---|
| 135 | { |
---|
| 136 | $query = ' |
---|
| 137 | SELECT user_id, group_id |
---|
| 138 | FROM '.USER_GROUP_TABLE.' |
---|
| 139 | WHERE user_id IN ('.implode(',', $user_ids).') |
---|
| 140 | ;'; |
---|
| 141 | $result = pwg_query($query); |
---|
| 142 | while ($row = mysql_fetch_array($result)) |
---|
| 143 | { |
---|
| 144 | array_push( |
---|
| 145 | $users[$user_nums[$row['user_id']]]['groups'], |
---|
| 146 | $row['group_id'] |
---|
| 147 | ); |
---|
| 148 | } |
---|
| 149 | } |
---|
[1620] | 150 | |
---|
[880] | 151 | return $users; |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | // +-----------------------------------------------------------------------+ |
---|
[768] | 155 | // | initialization | |
---|
| 156 | // +-----------------------------------------------------------------------+ |
---|
| 157 | |
---|
| 158 | if (!defined('PHPWG_ROOT_PATH')) |
---|
| 159 | { |
---|
| 160 | die('Hacking attempt!'); |
---|
| 161 | } |
---|
| 162 | |
---|
[1072] | 163 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
| 164 | |
---|
| 165 | // +-----------------------------------------------------------------------+ |
---|
| 166 | // | Check Access and exit when user status is not ok | |
---|
| 167 | // +-----------------------------------------------------------------------+ |
---|
| 168 | check_status(ACCESS_ADMINISTRATOR); |
---|
| 169 | |
---|
[880] | 170 | $page['order_by_items'] = array( |
---|
[2201] | 171 | 'id' => l10n('registration_date'), |
---|
| 172 | 'username' => l10n('Username'), |
---|
[2090] | 173 | 'level' => l10n('Privacy level'), |
---|
| 174 | 'language' => l10n('language'), |
---|
[880] | 175 | ); |
---|
| 176 | |
---|
| 177 | $page['direction_items'] = array( |
---|
[2201] | 178 | 'asc' => l10n('ascending'), |
---|
| 179 | 'desc' => l10n('descending') |
---|
[880] | 180 | ); |
---|
| 181 | |
---|
[768] | 182 | // +-----------------------------------------------------------------------+ |
---|
| 183 | // | add a user | |
---|
| 184 | // +-----------------------------------------------------------------------+ |
---|
| 185 | |
---|
[3945] | 186 | // Check for config_default var - If True : Using double password type else single password type |
---|
| 187 | // This feature is discussed on Piwigo's english forum |
---|
| 188 | if ($conf['double_password_type_in_admin'] == true) |
---|
[768] | 189 | { |
---|
[4009] | 190 | if (isset($_POST['submit_add'])) |
---|
| 191 | { |
---|
| 192 | if(empty($_POST['password'])) |
---|
| 193 | { |
---|
| 194 | array_push($page['errors'], l10n('Password is missing')); |
---|
| 195 | } |
---|
| 196 | else if(empty($_POST['password_conf'])) |
---|
| 197 | { |
---|
| 198 | array_push($page['errors'], l10n('Password confirmation is missing')); |
---|
| 199 | } |
---|
| 200 | else if(empty($_POST['email'])) |
---|
| 201 | { |
---|
| 202 | array_push($page['errors'], l10n('Email address is missing')); |
---|
| 203 | } |
---|
| 204 | else if ($_POST['password'] != $_POST['password_conf']) |
---|
| 205 | { |
---|
| 206 | array_push($page['errors'], l10n('Password confirmation error')); |
---|
| 207 | } |
---|
| 208 | else |
---|
| 209 | { |
---|
| 210 | $page['errors'] = register_user( |
---|
| 211 | $_POST['login'], $_POST['password'], $_POST['email'], false); |
---|
[906] | 212 | |
---|
[4009] | 213 | if (count($page['errors']) == 0) |
---|
| 214 | { |
---|
| 215 | array_push( |
---|
| 216 | $page['infos'], |
---|
| 217 | sprintf( |
---|
| 218 | l10n('user "%s" added'), |
---|
| 219 | $_POST['login'] |
---|
| 220 | ) |
---|
| 221 | ); |
---|
| 222 | } |
---|
| 223 | } |
---|
| 224 | } |
---|
[3945] | 225 | } |
---|
| 226 | else if ($conf['double_password_type_in_admin'] == false) |
---|
| 227 | { |
---|
[4009] | 228 | if (isset($_POST['submit_add'])) |
---|
| 229 | { |
---|
| 230 | $page['errors'] = register_user( |
---|
| 231 | $_POST['login'], $_POST['password'], $_POST['email'], false); |
---|
[3945] | 232 | |
---|
[4009] | 233 | if (count($page['errors']) == 0) |
---|
| 234 | { |
---|
| 235 | array_push( |
---|
| 236 | $page['infos'], |
---|
| 237 | sprintf( |
---|
| 238 | l10n('user "%s" added'), |
---|
| 239 | $_POST['login'] |
---|
| 240 | ) |
---|
| 241 | ); |
---|
| 242 | } |
---|
[906] | 243 | } |
---|
[768] | 244 | } |
---|
| 245 | |
---|
| 246 | // +-----------------------------------------------------------------------+ |
---|
[914] | 247 | // | user list | |
---|
| 248 | // +-----------------------------------------------------------------------+ |
---|
| 249 | |
---|
| 250 | $page['filtered_users'] = get_filtered_user_list(); |
---|
| 251 | |
---|
| 252 | // +-----------------------------------------------------------------------+ |
---|
[858] | 253 | // | selected users | |
---|
[787] | 254 | // +-----------------------------------------------------------------------+ |
---|
| 255 | |
---|
[858] | 256 | if (isset($_POST['delete']) or isset($_POST['pref_submit'])) |
---|
[787] | 257 | { |
---|
| 258 | $collection = array(); |
---|
[1620] | 259 | |
---|
[787] | 260 | switch ($_POST['target']) |
---|
| 261 | { |
---|
| 262 | case 'all' : |
---|
| 263 | { |
---|
[880] | 264 | foreach($page['filtered_users'] as $local_user) |
---|
| 265 | { |
---|
| 266 | array_push($collection, $local_user['id']); |
---|
| 267 | } |
---|
[787] | 268 | break; |
---|
| 269 | } |
---|
| 270 | case 'selection' : |
---|
| 271 | { |
---|
[805] | 272 | if (isset($_POST['selection'])) |
---|
| 273 | { |
---|
| 274 | $collection = $_POST['selection']; |
---|
| 275 | } |
---|
[787] | 276 | break; |
---|
| 277 | } |
---|
| 278 | } |
---|
| 279 | |
---|
[858] | 280 | if (count($collection) == 0) |
---|
[787] | 281 | { |
---|
[858] | 282 | array_push($page['errors'], l10n('Select at least one user')); |
---|
| 283 | } |
---|
| 284 | } |
---|
| 285 | |
---|
| 286 | // +-----------------------------------------------------------------------+ |
---|
| 287 | // | delete users | |
---|
| 288 | // +-----------------------------------------------------------------------+ |
---|
| 289 | if (isset($_POST['delete']) and count($collection) > 0) |
---|
| 290 | { |
---|
[2024] | 291 | if (in_array($conf['guest_id'], $collection)) |
---|
| 292 | { |
---|
| 293 | array_push($page['errors'], l10n('Guest cannot be deleted')); |
---|
| 294 | } |
---|
[2084] | 295 | if (($conf['guest_id'] != $conf['default_user_id']) and |
---|
[2024] | 296 | in_array($conf['default_user_id'], $collection)) |
---|
| 297 | { |
---|
| 298 | array_push($page['errors'], l10n('Default user cannot be deleted')); |
---|
| 299 | } |
---|
[858] | 300 | if (in_array($conf['webmaster_id'], $collection)) |
---|
| 301 | { |
---|
| 302 | array_push($page['errors'], l10n('Webmaster cannot be deleted')); |
---|
| 303 | } |
---|
[2024] | 304 | if (in_array($user['id'], $collection)) |
---|
[1489] | 305 | { |
---|
| 306 | array_push($page['errors'], l10n('You cannot delete your account')); |
---|
| 307 | } |
---|
[2024] | 308 | |
---|
| 309 | if (count($page['errors']) == 0) |
---|
[858] | 310 | { |
---|
| 311 | if (isset($_POST['confirm_deletion']) and 1 == $_POST['confirm_deletion']) |
---|
[805] | 312 | { |
---|
[858] | 313 | foreach ($collection as $user_id) |
---|
| 314 | { |
---|
| 315 | delete_user($user_id); |
---|
| 316 | } |
---|
| 317 | array_push( |
---|
| 318 | $page['infos'], |
---|
[1932] | 319 | l10n_dec( |
---|
| 320 | '%d user deleted', '%d users deleted', |
---|
[1620] | 321 | count($collection) |
---|
[858] | 322 | ) |
---|
| 323 | ); |
---|
[998] | 324 | foreach ($page['filtered_users'] as $filter_key => $filter_user) |
---|
| 325 | { |
---|
[1079] | 326 | if (in_array($filter_user['id'], $collection)) |
---|
| 327 | { |
---|
| 328 | unset($page['filtered_users'][$filter_key]); |
---|
| 329 | } |
---|
[998] | 330 | } |
---|
[858] | 331 | } |
---|
| 332 | else |
---|
| 333 | { |
---|
| 334 | array_push($page['errors'], l10n('You need to confirm deletion')); |
---|
| 335 | } |
---|
| 336 | } |
---|
| 337 | } |
---|
[787] | 338 | |
---|
[858] | 339 | // +-----------------------------------------------------------------------+ |
---|
| 340 | // | preferences form submission | |
---|
| 341 | // +-----------------------------------------------------------------------+ |
---|
| 342 | |
---|
| 343 | if (isset($_POST['pref_submit']) and count($collection) > 0) |
---|
| 344 | { |
---|
| 345 | if (-1 != $_POST['associate']) |
---|
| 346 | { |
---|
| 347 | $datas = array(); |
---|
[1620] | 348 | |
---|
[858] | 349 | $query = ' |
---|
[787] | 350 | SELECT user_id |
---|
| 351 | FROM '.USER_GROUP_TABLE.' |
---|
| 352 | WHERE group_id = '.$_POST['associate'].' |
---|
| 353 | ;'; |
---|
[858] | 354 | $associated = array_from_query($query, 'user_id'); |
---|
[1620] | 355 | |
---|
[858] | 356 | $associable = array_diff($collection, $associated); |
---|
[1620] | 357 | |
---|
[858] | 358 | if (count($associable) > 0) |
---|
| 359 | { |
---|
| 360 | foreach ($associable as $item) |
---|
[805] | 361 | { |
---|
[858] | 362 | array_push($datas, |
---|
| 363 | array('group_id'=>$_POST['associate'], |
---|
| 364 | 'user_id'=>$item)); |
---|
| 365 | } |
---|
[1620] | 366 | |
---|
[858] | 367 | mass_inserts(USER_GROUP_TABLE, |
---|
| 368 | array('group_id', 'user_id'), |
---|
| 369 | $datas); |
---|
[787] | 370 | } |
---|
[858] | 371 | } |
---|
[1620] | 372 | |
---|
[858] | 373 | if (-1 != $_POST['dissociate']) |
---|
| 374 | { |
---|
| 375 | $query = ' |
---|
[787] | 376 | DELETE FROM '.USER_GROUP_TABLE.' |
---|
| 377 | WHERE group_id = '.$_POST['dissociate'].' |
---|
| 378 | AND user_id IN ('.implode(',', $collection).') |
---|
| 379 | '; |
---|
[858] | 380 | pwg_query($query); |
---|
| 381 | } |
---|
[1620] | 382 | |
---|
[858] | 383 | // properties to set for the collection (a user list) |
---|
| 384 | $datas = array(); |
---|
| 385 | $dbfields = array('primary' => array('user_id'), 'update' => array()); |
---|
[1620] | 386 | |
---|
[858] | 387 | $formfields = |
---|
| 388 | array('nb_image_line', 'nb_line_page', 'template', 'language', |
---|
| 389 | 'recent_period', 'maxwidth', 'expand', 'show_nb_comments', |
---|
[2084] | 390 | 'show_nb_hits', 'maxheight', 'status', 'enabled_high', |
---|
| 391 | 'level'); |
---|
[1620] | 392 | |
---|
[2084] | 393 | $true_false_fields = array('expand', 'show_nb_comments', |
---|
[1763] | 394 | 'show_nb_hits', 'enabled_high'); |
---|
[1170] | 395 | if ($conf['allow_adviser']) |
---|
| 396 | { |
---|
| 397 | array_push($formfields, 'adviser'); |
---|
| 398 | array_push($true_false_fields, 'adviser'); |
---|
| 399 | } |
---|
[1620] | 400 | |
---|
[858] | 401 | foreach ($formfields as $formfield) |
---|
| 402 | { |
---|
| 403 | // special for true/false fields |
---|
| 404 | if (in_array($formfield, $true_false_fields)) |
---|
| 405 | { |
---|
| 406 | $test = $formfield; |
---|
[805] | 407 | } |
---|
[858] | 408 | else |
---|
| 409 | { |
---|
| 410 | $test = $formfield.'_action'; |
---|
| 411 | } |
---|
[1620] | 412 | |
---|
[858] | 413 | if ($_POST[$test] != 'leave') |
---|
[787] | 414 | { |
---|
[858] | 415 | array_push($dbfields['update'], $formfield); |
---|
[787] | 416 | } |
---|
[858] | 417 | } |
---|
[1620] | 418 | |
---|
[858] | 419 | // updating elements is useful only if needed... |
---|
| 420 | if (count($dbfields['update']) > 0) |
---|
| 421 | { |
---|
| 422 | $datas = array(); |
---|
[1620] | 423 | |
---|
[858] | 424 | foreach ($collection as $user_id) |
---|
[787] | 425 | { |
---|
[858] | 426 | $data = array(); |
---|
| 427 | $data['user_id'] = $user_id; |
---|
[1620] | 428 | |
---|
[858] | 429 | // TODO : verify if submited values are semanticaly correct |
---|
| 430 | foreach ($dbfields['update'] as $dbfield) |
---|
[787] | 431 | { |
---|
[858] | 432 | // if the action is 'unset', the key won't be in row and |
---|
| 433 | // mass_updates function will set this field to NULL |
---|
| 434 | if (in_array($dbfield, $true_false_fields) |
---|
| 435 | or 'set' == $_POST[$dbfield.'_action']) |
---|
[787] | 436 | { |
---|
[858] | 437 | $data[$dbfield] = $_POST[$dbfield]; |
---|
[787] | 438 | } |
---|
| 439 | } |
---|
[1085] | 440 | |
---|
[2024] | 441 | // special users checks |
---|
| 442 | if |
---|
| 443 | ( |
---|
| 444 | ($conf['webmaster_id'] == $user_id) or |
---|
| 445 | ($conf['guest_id'] == $user_id) or |
---|
| 446 | ($conf['default_user_id'] == $user_id) |
---|
| 447 | ) |
---|
[858] | 448 | { |
---|
[2024] | 449 | // status must not be changed |
---|
| 450 | if (isset($data['status'])) |
---|
| 451 | { |
---|
| 452 | if ($conf['webmaster_id'] == $user_id) |
---|
| 453 | { |
---|
| 454 | $data['status'] = 'webmaster'; |
---|
| 455 | } |
---|
| 456 | else |
---|
| 457 | { |
---|
| 458 | $data['status'] = 'guest'; |
---|
| 459 | } |
---|
| 460 | } |
---|
[1085] | 461 | |
---|
[2024] | 462 | // could not be adivser |
---|
| 463 | if (isset($data['adviser'])) |
---|
| 464 | { |
---|
| 465 | $data['adviser'] = 'false'; |
---|
| 466 | } |
---|
[1085] | 467 | } |
---|
| 468 | |
---|
[858] | 469 | array_push($datas, $data); |
---|
| 470 | } |
---|
[1620] | 471 | |
---|
[858] | 472 | mass_updates(USER_INFOS_TABLE, $dbfields, $datas); |
---|
[787] | 473 | } |
---|
[931] | 474 | |
---|
| 475 | redirect( |
---|
[2286] | 476 | get_root_url(). |
---|
[931] | 477 | 'admin.php'. |
---|
[2089] | 478 | get_query_string_diff(array(), false) |
---|
[931] | 479 | ); |
---|
[787] | 480 | } |
---|
| 481 | |
---|
| 482 | // +-----------------------------------------------------------------------+ |
---|
| 483 | // | groups list | |
---|
| 484 | // +-----------------------------------------------------------------------+ |
---|
| 485 | |
---|
[2253] | 486 | $groups[-1] = '------------'; |
---|
[787] | 487 | |
---|
| 488 | $query = ' |
---|
| 489 | SELECT id, name |
---|
| 490 | FROM '.GROUPS_TABLE.' |
---|
[1960] | 491 | ORDER BY name ASC |
---|
[787] | 492 | ;'; |
---|
| 493 | $result = pwg_query($query); |
---|
| 494 | |
---|
| 495 | while ($row = mysql_fetch_array($result)) |
---|
| 496 | { |
---|
| 497 | $groups[$row['id']] = $row['name']; |
---|
| 498 | } |
---|
| 499 | |
---|
| 500 | // +-----------------------------------------------------------------------+ |
---|
[768] | 501 | // | template init | |
---|
| 502 | // +-----------------------------------------------------------------------+ |
---|
| 503 | |
---|
[2530] | 504 | $template->set_filenames(array('user_list'=>'user_list.tpl')); |
---|
[768] | 505 | |
---|
[1004] | 506 | $base_url = PHPWG_ROOT_PATH.'admin.php?page=user_list'; |
---|
[768] | 507 | |
---|
| 508 | if (isset($_GET['start']) and is_numeric($_GET['start'])) |
---|
| 509 | { |
---|
| 510 | $start = $_GET['start']; |
---|
| 511 | } |
---|
| 512 | else |
---|
| 513 | { |
---|
| 514 | $start = 0; |
---|
| 515 | } |
---|
| 516 | |
---|
[2253] | 517 | $template->assign( |
---|
[768] | 518 | array( |
---|
[2286] | 519 | 'U_HELP' => get_root_url().'popuphelp.php?page=user_list', |
---|
[1620] | 520 | |
---|
[768] | 521 | 'F_ADD_ACTION' => $base_url, |
---|
[1696] | 522 | 'F_USERNAME' => @htmlentities($_GET['username']), |
---|
[2286] | 523 | 'F_FILTER_ACTION' => get_root_url().'admin.php' |
---|
[768] | 524 | )); |
---|
| 525 | |
---|
[1087] | 526 | // Hide radio-button if not allow to assign adviser |
---|
| 527 | if ($conf['allow_adviser']) |
---|
| 528 | { |
---|
[2253] | 529 | $template->assign('adviser', true); |
---|
[1087] | 530 | } |
---|
| 531 | |
---|
[3945] | 532 | // Display or Hide double password type |
---|
[4069] | 533 | $template->assign('Double_Password', $conf['double_password_type_in_admin'] ); |
---|
[3945] | 534 | |
---|
[2253] | 535 | // Filter status options |
---|
| 536 | $status_options[-1] = '------------'; |
---|
| 537 | foreach (get_enums(USER_INFOS_TABLE, 'status') as $status) |
---|
[768] | 538 | { |
---|
[2253] | 539 | $status_options[$status] = l10n('user_status_'.$status); |
---|
[768] | 540 | } |
---|
[2253] | 541 | $template->assign('status_options', $status_options); |
---|
| 542 | $template->assign('status_selected', |
---|
| 543 | isset($_GET['status']) ? $_GET['status'] : ''); |
---|
[768] | 544 | |
---|
[2253] | 545 | // Filter group options |
---|
| 546 | $template->assign('group_options', $groups); |
---|
| 547 | $template->assign('group_selected', |
---|
| 548 | isset($_GET['group']) ? $_GET['group'] : ''); |
---|
[768] | 549 | |
---|
[2253] | 550 | // Filter order options |
---|
| 551 | $template->assign('order_options', $page['order_by_items']); |
---|
| 552 | $template->assign('order_selected', |
---|
| 553 | isset($_GET['order_by']) ? $_GET['order_by'] : ''); |
---|
[776] | 554 | |
---|
[2253] | 555 | // Filter direction options |
---|
| 556 | $template->assign('direction_options', $page['direction_items']); |
---|
| 557 | $template->assign('direction_selected', |
---|
| 558 | isset($_GET['direction']) ? $_GET['direction'] : ''); |
---|
[776] | 559 | |
---|
| 560 | |
---|
[787] | 561 | if (isset($_POST['pref_submit'])) |
---|
| 562 | { |
---|
[2253] | 563 | $template->assign( |
---|
[787] | 564 | array( |
---|
| 565 | 'NB_IMAGE_LINE' => $_POST['nb_image_line'], |
---|
| 566 | 'NB_LINE_PAGE' => $_POST['nb_line_page'], |
---|
| 567 | 'MAXWIDTH' => $_POST['maxwidth'], |
---|
| 568 | 'MAXHEIGHT' => $_POST['maxheight'], |
---|
| 569 | 'RECENT_PERIOD' => $_POST['recent_period'], |
---|
| 570 | )); |
---|
| 571 | } |
---|
| 572 | else |
---|
| 573 | { |
---|
[1926] | 574 | $default_user = get_default_user_info(true); |
---|
[2253] | 575 | $template->assign( |
---|
[787] | 576 | array( |
---|
[1926] | 577 | 'NB_IMAGE_LINE' => $default_user['nb_image_line'], |
---|
| 578 | 'NB_LINE_PAGE' => $default_user['nb_line_page'], |
---|
| 579 | 'MAXWIDTH' => $default_user['maxwidth'], |
---|
| 580 | 'MAXHEIGHT' => $default_user['maxheight'], |
---|
| 581 | 'RECENT_PERIOD' => $default_user['recent_period'], |
---|
[787] | 582 | )); |
---|
| 583 | } |
---|
| 584 | |
---|
[2253] | 585 | // Template Options |
---|
| 586 | $template->assign('template_options', get_pwg_themes()); |
---|
[4069] | 587 | $template->assign('template_selected', |
---|
[2253] | 588 | isset($_POST['pref_submit']) ? $_POST['template'] : get_default_template()); |
---|
[787] | 589 | |
---|
[2253] | 590 | // Language options |
---|
| 591 | $template->assign('language_options', get_languages()); |
---|
[4069] | 592 | $template->assign('language_selected', |
---|
[2253] | 593 | isset($_POST['pref_submit']) ? $_POST['language'] : get_default_language()); |
---|
[1620] | 594 | |
---|
[2253] | 595 | // Status options |
---|
[808] | 596 | foreach (get_enums(USER_INFOS_TABLE, 'status') as $status) |
---|
[787] | 597 | { |
---|
[1085] | 598 | // Only status <= can be assign |
---|
| 599 | if (is_autorize_status(get_access_type_status($status))) |
---|
| 600 | { |
---|
[2253] | 601 | $pref_status_options[$status] = l10n('user_status_'.$status); |
---|
[1085] | 602 | } |
---|
[787] | 603 | } |
---|
[2253] | 604 | $template->assign('pref_status_options', $pref_status_options); |
---|
[4069] | 605 | $template->assign('pref_status_selected', |
---|
[2253] | 606 | isset($_POST['pref_submit']) ? $_POST['status'] : 'normal'); |
---|
[787] | 607 | |
---|
[2253] | 608 | // associate and dissociate options |
---|
| 609 | $template->assign('association_options', $groups); |
---|
| 610 | $template->assign('associate_selected', |
---|
| 611 | isset($_POST['pref_submit']) ? $_POST['associate'] : ''); |
---|
| 612 | $template->assign('dissociate_selected', |
---|
| 613 | isset($_POST['pref_submit']) ? $_POST['dissociate'] : ''); |
---|
[787] | 614 | |
---|
| 615 | |
---|
[2084] | 616 | // user level options |
---|
| 617 | foreach ($conf['available_permission_levels'] as $level) |
---|
| 618 | { |
---|
[2253] | 619 | $level_options[$level] = l10n(sprintf('Level %d', $level)); |
---|
[2084] | 620 | } |
---|
[2253] | 621 | $template->assign('level_options', $level_options); |
---|
[4069] | 622 | $template->assign('level_selected', |
---|
[2253] | 623 | isset($_POST['pref_submit']) ? $_POST['level'] : $default_user['level']); |
---|
[2084] | 624 | |
---|
[768] | 625 | // +-----------------------------------------------------------------------+ |
---|
| 626 | // | navigation bar | |
---|
| 627 | // +-----------------------------------------------------------------------+ |
---|
| 628 | |
---|
| 629 | $url = PHPWG_ROOT_PATH.'admin.php'.get_query_string_diff(array('start')); |
---|
| 630 | |
---|
[880] | 631 | $navbar = create_navigation_bar( |
---|
| 632 | $url, |
---|
| 633 | count($page['filtered_users']), |
---|
| 634 | $start, |
---|
[1084] | 635 | $conf['users_page'] |
---|
[880] | 636 | ); |
---|
[768] | 637 | |
---|
[2253] | 638 | $template->assign('NAVBAR', $navbar); |
---|
[768] | 639 | |
---|
| 640 | // +-----------------------------------------------------------------------+ |
---|
| 641 | // | user list | |
---|
| 642 | // +-----------------------------------------------------------------------+ |
---|
| 643 | |
---|
[1753] | 644 | $profile_url = get_root_url().'admin.php?page=profile&user_id='; |
---|
| 645 | $perm_url = get_root_url().'admin.php?page=user_perm&user_id='; |
---|
[768] | 646 | |
---|
[2041] | 647 | $visible_user_list = array(); |
---|
[880] | 648 | foreach ($page['filtered_users'] as $num => $local_user) |
---|
[768] | 649 | { |
---|
[880] | 650 | // simulate LIMIT $start, $conf['users_page'] |
---|
| 651 | if ($num < $start) |
---|
| 652 | { |
---|
| 653 | continue; |
---|
| 654 | } |
---|
| 655 | if ($num >= $start + $conf['users_page']) |
---|
| 656 | { |
---|
| 657 | break; |
---|
| 658 | } |
---|
[768] | 659 | |
---|
[2041] | 660 | $visible_user_list[] = $local_user; |
---|
| 661 | } |
---|
| 662 | |
---|
[4069] | 663 | // allow plugins to fill template var plugin_user_list_column_titles and |
---|
[2286] | 664 | // plugin_columns/plugin_actions for each user in the list |
---|
[2041] | 665 | $visible_user_list = trigger_event('loc_visible_user_list', $visible_user_list); |
---|
| 666 | |
---|
[2286] | 667 | foreach ($visible_user_list as $local_user) |
---|
[2041] | 668 | { |
---|
[880] | 669 | $groups_string = preg_replace( |
---|
| 670 | '/(\d+)/e', |
---|
| 671 | "\$groups['$1']", |
---|
| 672 | implode( |
---|
| 673 | ', ', |
---|
| 674 | $local_user['groups'] |
---|
| 675 | ) |
---|
| 676 | ); |
---|
[768] | 677 | |
---|
[880] | 678 | if (isset($_POST['pref_submit']) |
---|
| 679 | and isset($_POST['selection']) |
---|
| 680 | and in_array($local_user['id'], $_POST['selection'])) |
---|
[768] | 681 | { |
---|
[880] | 682 | $checked = 'checked="checked"'; |
---|
[768] | 683 | } |
---|
[880] | 684 | else |
---|
[768] | 685 | { |
---|
[880] | 686 | $checked = ''; |
---|
| 687 | } |
---|
[1087] | 688 | |
---|
[2084] | 689 | $properties = array(); |
---|
[2090] | 690 | if ( $local_user['level'] != 0 ) |
---|
| 691 | { |
---|
| 692 | $properties[] = l10n( sprintf('Level %d', $local_user['level']) ); |
---|
| 693 | } |
---|
[2084] | 694 | $properties[] = |
---|
| 695 | (isset($local_user['enabled_high']) and ($local_user['enabled_high'] == 'true')) |
---|
[2201] | 696 | ? l10n('is_high_enabled') : l10n('is_high_disabled'); |
---|
[2084] | 697 | |
---|
[2253] | 698 | $template->append( |
---|
| 699 | 'users', |
---|
[880] | 700 | array( |
---|
| 701 | 'ID' => $local_user['id'], |
---|
| 702 | 'CHECKED' => $checked, |
---|
[1753] | 703 | 'U_PROFILE' => $profile_url.$local_user['id'], |
---|
[1004] | 704 | 'U_PERM' => $perm_url.$local_user['id'], |
---|
[1930] | 705 | 'USERNAME' => $local_user['username'] |
---|
| 706 | .($local_user['id'] == $conf['guest_id'] |
---|
[3945] | 707 | ? '<br>['.l10n('is_the_guest').']' : '') |
---|
[1930] | 708 | .($local_user['id'] == $conf['default_user_id'] |
---|
[3945] | 709 | ? '<br>['.l10n('is_the_default').']' : ''), |
---|
[2201] | 710 | 'STATUS' => l10n('user_status_'. |
---|
| 711 | $local_user['status']).(($local_user['adviser'] == 'true') |
---|
[3945] | 712 | ? '<br>['.l10n('adviser').']' : ''), |
---|
[1462] | 713 | 'EMAIL' => get_email_address_as_display_text($local_user['email']), |
---|
[1079] | 714 | 'GROUPS' => $groups_string, |
---|
[2090] | 715 | 'PROPERTIES' => implode( ', ', $properties), |
---|
[2286] | 716 | 'plugin_columns' => isset($local_user['plugin_columns']) ? $local_user['plugin_columns'] : array(), |
---|
| 717 | 'plugin_actions' => isset($local_user['plugin_actions']) ? $local_user['plugin_actions'] : array(), |
---|
[880] | 718 | ) |
---|
| 719 | ); |
---|
[768] | 720 | } |
---|
| 721 | |
---|
| 722 | // +-----------------------------------------------------------------------+ |
---|
| 723 | // | html code display | |
---|
| 724 | // +-----------------------------------------------------------------------+ |
---|
| 725 | |
---|
| 726 | $template->assign_var_from_handle('ADMIN_CONTENT', 'user_list'); |
---|
| 727 | ?> |
---|