[768] | 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: 2007-01-25 02:18:56 +0000 (Thu, 25 Jan 2007) $ |
---|
| 10 | // | last modifier : $Author: rvelices $ |
---|
| 11 | // | revision : $Revision: 1753 $ |
---|
| 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 | // +-----------------------------------------------------------------------+ |
---|
[880] | 33 | // | functions | |
---|
| 34 | // +-----------------------------------------------------------------------+ |
---|
| 35 | |
---|
| 36 | /** |
---|
| 37 | * returns a list of users depending on page filters (in $_GET) |
---|
| 38 | * |
---|
| 39 | * Each user comes with his related informations : id, username, mail |
---|
| 40 | * address, list of groups. |
---|
| 41 | * |
---|
| 42 | * @return array |
---|
| 43 | */ |
---|
| 44 | function get_filtered_user_list() |
---|
| 45 | { |
---|
| 46 | global $conf, $page; |
---|
| 47 | |
---|
| 48 | $users = array(); |
---|
[1620] | 49 | |
---|
[880] | 50 | // filter |
---|
| 51 | $filter = array(); |
---|
[1620] | 52 | |
---|
[880] | 53 | if (isset($_GET['username']) and !empty($_GET['username'])) |
---|
| 54 | { |
---|
| 55 | $username = str_replace('*', '%', $_GET['username']); |
---|
| 56 | if (function_exists('mysql_real_escape_string')) |
---|
| 57 | { |
---|
| 58 | $filter['username'] = mysql_real_escape_string($username); |
---|
| 59 | } |
---|
| 60 | else |
---|
| 61 | { |
---|
| 62 | $filter['username'] = mysql_escape_string($username); |
---|
| 63 | } |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | if (isset($_GET['group']) |
---|
| 67 | and -1 != $_GET['group'] |
---|
| 68 | and is_numeric($_GET['group'])) |
---|
| 69 | { |
---|
| 70 | $filter['group'] = $_GET['group']; |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | if (isset($_GET['status']) |
---|
| 74 | and in_array($_GET['status'], get_enums(USER_INFOS_TABLE, 'status'))) |
---|
| 75 | { |
---|
| 76 | $filter['status'] = $_GET['status']; |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | // how to order the list? |
---|
| 80 | $order_by = 'id'; |
---|
| 81 | if (isset($_GET['order_by']) |
---|
| 82 | and in_array($_GET['order_by'], array_keys($page['order_by_items']))) |
---|
| 83 | { |
---|
| 84 | $order_by = $_GET['order_by']; |
---|
| 85 | } |
---|
[1620] | 86 | |
---|
[880] | 87 | $direction = 'ASC'; |
---|
| 88 | if (isset($_GET['direction']) |
---|
| 89 | and in_array($_GET['direction'], array_keys($page['direction_items']))) |
---|
| 90 | { |
---|
| 91 | $direction = strtoupper($_GET['direction']); |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | // search users depending on filters and order |
---|
| 95 | $query = ' |
---|
| 96 | SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id, |
---|
| 97 | u.'.$conf['user_fields']['username'].' AS username, |
---|
| 98 | u.'.$conf['user_fields']['email'].' AS email, |
---|
[1079] | 99 | ui.status, |
---|
[1085] | 100 | ui.adviser, |
---|
[1079] | 101 | ui.enabled_high |
---|
[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 |
---|
| 107 | WHERE u.'.$conf['user_fields']['id'].' != '.$conf['guest_id']; |
---|
| 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( |
---|
| 181 | 'id' => $lang['registration_date'], |
---|
| 182 | 'username' => $lang['Username'] |
---|
| 183 | ); |
---|
| 184 | |
---|
| 185 | $page['direction_items'] = array( |
---|
| 186 | 'asc' => $lang['ascending'], |
---|
| 187 | 'desc' => $lang['descending'] |
---|
| 188 | ); |
---|
| 189 | |
---|
[768] | 190 | // +-----------------------------------------------------------------------+ |
---|
| 191 | // | add a user | |
---|
| 192 | // +-----------------------------------------------------------------------+ |
---|
| 193 | |
---|
| 194 | if (isset($_POST['submit_add'])) |
---|
| 195 | { |
---|
[1753] | 196 | $page['errors'] = register_user( |
---|
| 197 | $_POST['login'], $_POST['password'], $_POST['email']); |
---|
[906] | 198 | |
---|
| 199 | if (count($page['errors']) == 0) |
---|
| 200 | { |
---|
| 201 | array_push( |
---|
| 202 | $page['infos'], |
---|
| 203 | sprintf( |
---|
| 204 | l10n('user "%s" added'), |
---|
| 205 | $_POST['login'] |
---|
| 206 | ) |
---|
| 207 | ); |
---|
| 208 | } |
---|
[768] | 209 | } |
---|
| 210 | |
---|
| 211 | // +-----------------------------------------------------------------------+ |
---|
[914] | 212 | // | user list | |
---|
| 213 | // +-----------------------------------------------------------------------+ |
---|
| 214 | |
---|
| 215 | $page['filtered_users'] = get_filtered_user_list(); |
---|
| 216 | |
---|
| 217 | // +-----------------------------------------------------------------------+ |
---|
[858] | 218 | // | selected users | |
---|
[787] | 219 | // +-----------------------------------------------------------------------+ |
---|
| 220 | |
---|
[858] | 221 | if (isset($_POST['delete']) or isset($_POST['pref_submit'])) |
---|
[787] | 222 | { |
---|
| 223 | $collection = array(); |
---|
[1620] | 224 | |
---|
[787] | 225 | switch ($_POST['target']) |
---|
| 226 | { |
---|
| 227 | case 'all' : |
---|
| 228 | { |
---|
[880] | 229 | foreach($page['filtered_users'] as $local_user) |
---|
| 230 | { |
---|
| 231 | array_push($collection, $local_user['id']); |
---|
| 232 | } |
---|
[787] | 233 | break; |
---|
| 234 | } |
---|
| 235 | case 'selection' : |
---|
| 236 | { |
---|
[805] | 237 | if (isset($_POST['selection'])) |
---|
| 238 | { |
---|
| 239 | $collection = $_POST['selection']; |
---|
| 240 | } |
---|
[787] | 241 | break; |
---|
| 242 | } |
---|
| 243 | } |
---|
| 244 | |
---|
[858] | 245 | if (count($collection) == 0) |
---|
[787] | 246 | { |
---|
[858] | 247 | array_push($page['errors'], l10n('Select at least one user')); |
---|
| 248 | } |
---|
| 249 | } |
---|
| 250 | |
---|
| 251 | // +-----------------------------------------------------------------------+ |
---|
| 252 | // | delete users | |
---|
| 253 | // +-----------------------------------------------------------------------+ |
---|
| 254 | if (isset($_POST['delete']) and count($collection) > 0) |
---|
| 255 | { |
---|
| 256 | if (in_array($conf['webmaster_id'], $collection)) |
---|
| 257 | { |
---|
| 258 | array_push($page['errors'], l10n('Webmaster cannot be deleted')); |
---|
| 259 | } |
---|
[1489] | 260 | elseif (in_array($user['id'], $collection)) |
---|
| 261 | { |
---|
| 262 | array_push($page['errors'], l10n('You cannot delete your account')); |
---|
| 263 | } |
---|
[858] | 264 | else |
---|
| 265 | { |
---|
| 266 | if (isset($_POST['confirm_deletion']) and 1 == $_POST['confirm_deletion']) |
---|
[805] | 267 | { |
---|
[858] | 268 | foreach ($collection as $user_id) |
---|
| 269 | { |
---|
| 270 | delete_user($user_id); |
---|
| 271 | } |
---|
| 272 | array_push( |
---|
| 273 | $page['infos'], |
---|
| 274 | sprintf( |
---|
| 275 | l10n('%d users deleted'), |
---|
[1620] | 276 | count($collection) |
---|
[858] | 277 | ) |
---|
| 278 | ); |
---|
[998] | 279 | foreach ($page['filtered_users'] as $filter_key => $filter_user) |
---|
| 280 | { |
---|
[1079] | 281 | if (in_array($filter_user['id'], $collection)) |
---|
| 282 | { |
---|
| 283 | unset($page['filtered_users'][$filter_key]); |
---|
| 284 | } |
---|
[998] | 285 | } |
---|
[858] | 286 | } |
---|
| 287 | else |
---|
| 288 | { |
---|
| 289 | array_push($page['errors'], l10n('You need to confirm deletion')); |
---|
| 290 | } |
---|
| 291 | } |
---|
| 292 | } |
---|
[787] | 293 | |
---|
[858] | 294 | // +-----------------------------------------------------------------------+ |
---|
| 295 | // | preferences form submission | |
---|
| 296 | // +-----------------------------------------------------------------------+ |
---|
| 297 | |
---|
| 298 | if (isset($_POST['pref_submit']) and count($collection) > 0) |
---|
| 299 | { |
---|
| 300 | if (-1 != $_POST['associate']) |
---|
| 301 | { |
---|
| 302 | $datas = array(); |
---|
[1620] | 303 | |
---|
[858] | 304 | $query = ' |
---|
[787] | 305 | SELECT user_id |
---|
| 306 | FROM '.USER_GROUP_TABLE.' |
---|
| 307 | WHERE group_id = '.$_POST['associate'].' |
---|
| 308 | ;'; |
---|
[858] | 309 | $associated = array_from_query($query, 'user_id'); |
---|
[1620] | 310 | |
---|
[858] | 311 | $associable = array_diff($collection, $associated); |
---|
[1620] | 312 | |
---|
[858] | 313 | if (count($associable) > 0) |
---|
| 314 | { |
---|
| 315 | foreach ($associable as $item) |
---|
[805] | 316 | { |
---|
[858] | 317 | array_push($datas, |
---|
| 318 | array('group_id'=>$_POST['associate'], |
---|
| 319 | 'user_id'=>$item)); |
---|
| 320 | } |
---|
[1620] | 321 | |
---|
[858] | 322 | mass_inserts(USER_GROUP_TABLE, |
---|
| 323 | array('group_id', 'user_id'), |
---|
| 324 | $datas); |
---|
[787] | 325 | } |
---|
[858] | 326 | } |
---|
[1620] | 327 | |
---|
[858] | 328 | if (-1 != $_POST['dissociate']) |
---|
| 329 | { |
---|
| 330 | $query = ' |
---|
[787] | 331 | DELETE FROM '.USER_GROUP_TABLE.' |
---|
| 332 | WHERE group_id = '.$_POST['dissociate'].' |
---|
| 333 | AND user_id IN ('.implode(',', $collection).') |
---|
| 334 | '; |
---|
[858] | 335 | pwg_query($query); |
---|
| 336 | } |
---|
[1620] | 337 | |
---|
[858] | 338 | // properties to set for the collection (a user list) |
---|
| 339 | $datas = array(); |
---|
| 340 | $dbfields = array('primary' => array('user_id'), 'update' => array()); |
---|
[1620] | 341 | |
---|
[858] | 342 | $formfields = |
---|
| 343 | array('nb_image_line', 'nb_line_page', 'template', 'language', |
---|
| 344 | 'recent_period', 'maxwidth', 'expand', 'show_nb_comments', |
---|
[1170] | 345 | 'maxheight', 'status', 'enabled_high'); |
---|
[1620] | 346 | |
---|
[1170] | 347 | $true_false_fields = array('expand', 'show_nb_comments', 'enabled_high'); |
---|
| 348 | if ($conf['allow_adviser']) |
---|
| 349 | { |
---|
| 350 | array_push($formfields, 'adviser'); |
---|
| 351 | array_push($true_false_fields, 'adviser'); |
---|
| 352 | } |
---|
[1620] | 353 | |
---|
[858] | 354 | foreach ($formfields as $formfield) |
---|
| 355 | { |
---|
| 356 | // special for true/false fields |
---|
| 357 | if (in_array($formfield, $true_false_fields)) |
---|
| 358 | { |
---|
| 359 | $test = $formfield; |
---|
[805] | 360 | } |
---|
[858] | 361 | else |
---|
| 362 | { |
---|
| 363 | $test = $formfield.'_action'; |
---|
| 364 | } |
---|
[1620] | 365 | |
---|
[858] | 366 | if ($_POST[$test] != 'leave') |
---|
[787] | 367 | { |
---|
[858] | 368 | array_push($dbfields['update'], $formfield); |
---|
[787] | 369 | } |
---|
[858] | 370 | } |
---|
[1620] | 371 | |
---|
[858] | 372 | // updating elements is useful only if needed... |
---|
| 373 | if (count($dbfields['update']) > 0) |
---|
| 374 | { |
---|
| 375 | $datas = array(); |
---|
[1620] | 376 | |
---|
[858] | 377 | foreach ($collection as $user_id) |
---|
[787] | 378 | { |
---|
[858] | 379 | $data = array(); |
---|
| 380 | $data['user_id'] = $user_id; |
---|
[1620] | 381 | |
---|
[858] | 382 | // TODO : verify if submited values are semanticaly correct |
---|
| 383 | foreach ($dbfields['update'] as $dbfield) |
---|
[787] | 384 | { |
---|
[858] | 385 | // if the action is 'unset', the key won't be in row and |
---|
| 386 | // mass_updates function will set this field to NULL |
---|
| 387 | if (in_array($dbfield, $true_false_fields) |
---|
| 388 | or 'set' == $_POST[$dbfield.'_action']) |
---|
[787] | 389 | { |
---|
[858] | 390 | $data[$dbfield] = $_POST[$dbfield]; |
---|
[787] | 391 | } |
---|
| 392 | } |
---|
[1085] | 393 | |
---|
[858] | 394 | // Webmaster status must not be changed |
---|
| 395 | if ($conf['webmaster_id'] == $user_id and isset($data['status'])) |
---|
| 396 | { |
---|
[1070] | 397 | $data['status'] = 'webmaster'; |
---|
[858] | 398 | } |
---|
[1085] | 399 | |
---|
| 400 | // Webmaster and guest adviser must not be changed |
---|
| 401 | if ((($conf['webmaster_id'] == $user_id) or ($conf['guest_id'] == $user_id)) and isset($data['adviser'])) |
---|
| 402 | { |
---|
| 403 | $data['adviser'] = 'false'; |
---|
| 404 | } |
---|
| 405 | |
---|
[858] | 406 | array_push($datas, $data); |
---|
| 407 | } |
---|
[1620] | 408 | |
---|
[858] | 409 | mass_updates(USER_INFOS_TABLE, $dbfields, $datas); |
---|
[787] | 410 | } |
---|
[931] | 411 | |
---|
| 412 | redirect( |
---|
| 413 | PHPWG_ROOT_PATH. |
---|
| 414 | 'admin.php'. |
---|
| 415 | get_query_string_diff( |
---|
| 416 | array( |
---|
| 417 | 'start' |
---|
| 418 | ) |
---|
| 419 | ) |
---|
| 420 | ); |
---|
[787] | 421 | } |
---|
| 422 | |
---|
| 423 | // +-----------------------------------------------------------------------+ |
---|
| 424 | // | groups list | |
---|
| 425 | // +-----------------------------------------------------------------------+ |
---|
| 426 | |
---|
| 427 | $groups = array(); |
---|
| 428 | |
---|
| 429 | $query = ' |
---|
| 430 | SELECT id, name |
---|
| 431 | FROM '.GROUPS_TABLE.' |
---|
| 432 | ;'; |
---|
| 433 | $result = pwg_query($query); |
---|
| 434 | |
---|
| 435 | while ($row = mysql_fetch_array($result)) |
---|
| 436 | { |
---|
| 437 | $groups[$row['id']] = $row['name']; |
---|
| 438 | } |
---|
| 439 | |
---|
| 440 | // +-----------------------------------------------------------------------+ |
---|
[768] | 441 | // | template init | |
---|
| 442 | // +-----------------------------------------------------------------------+ |
---|
| 443 | |
---|
| 444 | $template->set_filenames(array('user_list'=>'admin/user_list.tpl')); |
---|
| 445 | |
---|
[1004] | 446 | $base_url = PHPWG_ROOT_PATH.'admin.php?page=user_list'; |
---|
[768] | 447 | |
---|
| 448 | if (isset($_GET['start']) and is_numeric($_GET['start'])) |
---|
| 449 | { |
---|
| 450 | $start = $_GET['start']; |
---|
| 451 | } |
---|
| 452 | else |
---|
| 453 | { |
---|
| 454 | $start = 0; |
---|
| 455 | } |
---|
| 456 | |
---|
| 457 | $template->assign_vars( |
---|
| 458 | array( |
---|
[1250] | 459 | 'U_HELP' => PHPWG_ROOT_PATH.'popuphelp.php?page=user_list', |
---|
[1620] | 460 | |
---|
[768] | 461 | 'F_ADD_ACTION' => $base_url, |
---|
[1696] | 462 | 'F_USERNAME' => @htmlentities($_GET['username']), |
---|
[768] | 463 | 'F_FILTER_ACTION' => PHPWG_ROOT_PATH.'admin.php' |
---|
| 464 | )); |
---|
| 465 | |
---|
| 466 | if (isset($_GET['id'])) |
---|
| 467 | { |
---|
| 468 | $template->assign_block_vars('session', array('ID' => $_GET['id'])); |
---|
| 469 | } |
---|
| 470 | |
---|
[1087] | 471 | // Hide radio-button if not allow to assign adviser |
---|
| 472 | if ($conf['allow_adviser']) |
---|
| 473 | { |
---|
| 474 | $template->assign_block_vars('adviser', array()); |
---|
| 475 | } |
---|
| 476 | |
---|
[880] | 477 | foreach ($page['order_by_items'] as $item => $label) |
---|
[768] | 478 | { |
---|
| 479 | $selected = (isset($_GET['order_by']) and $_GET['order_by'] == $item) ? |
---|
| 480 | 'selected="selected"' : ''; |
---|
| 481 | $template->assign_block_vars( |
---|
| 482 | 'order_by', |
---|
| 483 | array( |
---|
| 484 | 'VALUE' => $item, |
---|
| 485 | 'CONTENT' => $label, |
---|
| 486 | 'SELECTED' => $selected |
---|
| 487 | )); |
---|
| 488 | } |
---|
| 489 | |
---|
[880] | 490 | foreach ($page['direction_items'] as $item => $label) |
---|
[768] | 491 | { |
---|
| 492 | $selected = (isset($_GET['direction']) and $_GET['direction'] == $item) ? |
---|
| 493 | 'selected="selected"' : ''; |
---|
| 494 | $template->assign_block_vars( |
---|
| 495 | 'direction', |
---|
| 496 | array( |
---|
| 497 | 'VALUE' => $item, |
---|
| 498 | 'CONTENT' => $label, |
---|
[776] | 499 | 'SELECTED' => $selected |
---|
[768] | 500 | )); |
---|
| 501 | } |
---|
| 502 | |
---|
[776] | 503 | $blockname = 'group_option'; |
---|
| 504 | |
---|
| 505 | $template->assign_block_vars( |
---|
| 506 | $blockname, |
---|
| 507 | array( |
---|
| 508 | 'VALUE'=> -1, |
---|
| 509 | 'CONTENT' => '------------', |
---|
| 510 | 'SELECTED' => '' |
---|
| 511 | )); |
---|
| 512 | |
---|
[787] | 513 | foreach ($groups as $group_id => $group_name) |
---|
[776] | 514 | { |
---|
[787] | 515 | $selected = (isset($_GET['group']) and $_GET['group'] == $group_id) ? |
---|
[776] | 516 | 'selected="selected"' : ''; |
---|
| 517 | $template->assign_block_vars( |
---|
| 518 | $blockname, |
---|
| 519 | array( |
---|
[787] | 520 | 'VALUE' => $group_id, |
---|
| 521 | 'CONTENT' => $group_name, |
---|
[776] | 522 | 'SELECTED' => $selected |
---|
| 523 | )); |
---|
| 524 | } |
---|
| 525 | |
---|
[777] | 526 | $blockname = 'status_option'; |
---|
| 527 | |
---|
| 528 | $template->assign_block_vars( |
---|
| 529 | $blockname, |
---|
| 530 | array( |
---|
| 531 | 'VALUE'=> -1, |
---|
| 532 | 'CONTENT' => '------------', |
---|
| 533 | 'SELECTED' => '' |
---|
| 534 | )); |
---|
| 535 | |
---|
[808] | 536 | foreach (get_enums(USER_INFOS_TABLE, 'status') as $status) |
---|
[777] | 537 | { |
---|
| 538 | $selected = (isset($_GET['status']) and $_GET['status'] == $status) ? |
---|
| 539 | 'selected="selected"' : ''; |
---|
| 540 | $template->assign_block_vars( |
---|
| 541 | $blockname, |
---|
| 542 | array( |
---|
| 543 | 'VALUE' => $status, |
---|
| 544 | 'CONTENT' => $lang['user_status_'.$status], |
---|
| 545 | 'SELECTED' => $selected |
---|
| 546 | )); |
---|
| 547 | } |
---|
| 548 | |
---|
[787] | 549 | // --- |
---|
| 550 | // $user['template'] = $conf['default_template']; |
---|
| 551 | // $user['nb_image_line'] = $conf['nb_image_line']; |
---|
| 552 | // $user['nb_line_page'] = $conf['nb_line_page']; |
---|
| 553 | // $user['language'] = $conf['default_language']; |
---|
| 554 | // $user['maxwidth'] = $conf['default_maxwidth']; |
---|
| 555 | // $user['maxheight'] = $conf['default_maxheight']; |
---|
| 556 | // $user['recent_period'] = $conf['recent_period']; |
---|
| 557 | // $user['expand'] = $conf['auto_expand']; |
---|
| 558 | // $user['show_nb_comments'] = $conf['show_nb_comments']; |
---|
| 559 | // --- |
---|
| 560 | |
---|
| 561 | if (isset($_POST['pref_submit'])) |
---|
| 562 | { |
---|
| 563 | // echo '<pre>'; print_r($_POST); echo '</pre>'; |
---|
| 564 | $template->assign_vars( |
---|
| 565 | array( |
---|
[1170] | 566 | 'ADVISER_YES' => 'true' == (isset($_POST['adviser']) and $_POST['adviser']) ? 'checked="checked"' : '', |
---|
| 567 | 'ADVISER_NO' => 'false' == (isset($_POST['adviser']) and $_POST['adviser']) ? 'checked="checked"' : '', |
---|
[787] | 568 | 'NB_IMAGE_LINE' => $_POST['nb_image_line'], |
---|
| 569 | 'NB_LINE_PAGE' => $_POST['nb_line_page'], |
---|
| 570 | 'MAXWIDTH' => $_POST['maxwidth'], |
---|
| 571 | 'MAXHEIGHT' => $_POST['maxheight'], |
---|
| 572 | 'RECENT_PERIOD' => $_POST['recent_period'], |
---|
| 573 | 'EXPAND_YES' => 'true' == $_POST['expand'] ? 'checked="checked"' : '', |
---|
| 574 | 'EXPAND_NO' => 'false' == $_POST['expand'] ? 'checked="checked"' : '', |
---|
| 575 | 'SHOW_NB_COMMENTS_YES' => |
---|
| 576 | 'true' == $_POST['show_nb_comments'] ? 'checked="checked"' : '', |
---|
| 577 | 'SHOW_NB_COMMENTS_NO' => |
---|
[1085] | 578 | 'false' == $_POST['show_nb_comments'] ? 'checked="checked"' : '', |
---|
| 579 | 'ENABLED_HIGH_YES' => 'true' == $_POST['enabled_high'] ? 'checked="checked"' : '', |
---|
| 580 | 'ENABLED_HIGH_NO' => 'false' == $_POST['enabled_high'] ? 'checked="checked"' : '', |
---|
[787] | 581 | )); |
---|
| 582 | } |
---|
| 583 | else |
---|
| 584 | { |
---|
| 585 | $template->assign_vars( |
---|
| 586 | array( |
---|
| 587 | 'NB_IMAGE_LINE' => $conf['nb_image_line'], |
---|
| 588 | 'NB_LINE_PAGE' => $conf['nb_line_page'], |
---|
| 589 | 'MAXWIDTH' => @$conf['default_maxwidth'], |
---|
| 590 | 'MAXHEIGHT' => @$conf['default_maxheight'], |
---|
| 591 | 'RECENT_PERIOD' => $conf['recent_period'], |
---|
| 592 | )); |
---|
| 593 | } |
---|
| 594 | |
---|
| 595 | $blockname = 'template_option'; |
---|
| 596 | |
---|
[1048] | 597 | foreach (get_pwg_themes() as $pwg_template) |
---|
[787] | 598 | { |
---|
| 599 | if (isset($_POST['pref_submit'])) |
---|
| 600 | { |
---|
| 601 | $selected = $_POST['template']==$pwg_template ? 'selected="selected"' : ''; |
---|
| 602 | } |
---|
| 603 | else if ($conf['default_template'] == $pwg_template) |
---|
| 604 | { |
---|
| 605 | $selected = 'selected="selected"'; |
---|
| 606 | } |
---|
| 607 | else |
---|
| 608 | { |
---|
| 609 | $selected = ''; |
---|
| 610 | } |
---|
[1620] | 611 | |
---|
[787] | 612 | $template->assign_block_vars( |
---|
| 613 | $blockname, |
---|
| 614 | array( |
---|
| 615 | 'VALUE'=> $pwg_template, |
---|
| 616 | 'CONTENT' => $pwg_template, |
---|
| 617 | 'SELECTED' => $selected |
---|
| 618 | )); |
---|
| 619 | } |
---|
| 620 | |
---|
| 621 | $blockname = 'language_option'; |
---|
| 622 | |
---|
| 623 | foreach (get_languages() as $language_code => $language_name) |
---|
| 624 | { |
---|
| 625 | if (isset($_POST['pref_submit'])) |
---|
| 626 | { |
---|
| 627 | $selected = $_POST['language']==$language_code ? 'selected="selected"':''; |
---|
| 628 | } |
---|
| 629 | else if ($conf['default_language'] == $language_code) |
---|
| 630 | { |
---|
| 631 | $selected = 'selected="selected"'; |
---|
| 632 | } |
---|
| 633 | else |
---|
| 634 | { |
---|
| 635 | $selected = ''; |
---|
| 636 | } |
---|
[1620] | 637 | |
---|
[787] | 638 | $template->assign_block_vars( |
---|
| 639 | $blockname, |
---|
| 640 | array( |
---|
| 641 | 'VALUE'=> $language_code, |
---|
| 642 | 'CONTENT' => $language_name, |
---|
| 643 | 'SELECTED' => $selected |
---|
| 644 | )); |
---|
| 645 | } |
---|
| 646 | |
---|
| 647 | $blockname = 'pref_status_option'; |
---|
| 648 | |
---|
[808] | 649 | foreach (get_enums(USER_INFOS_TABLE, 'status') as $status) |
---|
[787] | 650 | { |
---|
| 651 | if (isset($_POST['pref_submit'])) |
---|
| 652 | { |
---|
| 653 | $selected = $_POST['status'] == $status ? 'selected="selected"' : ''; |
---|
| 654 | } |
---|
[1070] | 655 | else if ('normal' == $status) |
---|
[787] | 656 | { |
---|
| 657 | $selected = 'selected="selected"'; |
---|
| 658 | } |
---|
| 659 | else |
---|
| 660 | { |
---|
| 661 | $selected = ''; |
---|
| 662 | } |
---|
[1085] | 663 | |
---|
| 664 | // Only status <= can be assign |
---|
| 665 | if (is_autorize_status(get_access_type_status($status))) |
---|
| 666 | { |
---|
| 667 | $template->assign_block_vars( |
---|
| 668 | $blockname, |
---|
| 669 | array( |
---|
| 670 | 'VALUE' => $status, |
---|
| 671 | 'CONTENT' => $lang['user_status_'.$status], |
---|
| 672 | 'SELECTED' => $selected |
---|
| 673 | )); |
---|
| 674 | } |
---|
[787] | 675 | } |
---|
| 676 | |
---|
| 677 | // associate |
---|
| 678 | $blockname = 'associate_option'; |
---|
| 679 | |
---|
| 680 | $template->assign_block_vars( |
---|
| 681 | $blockname, |
---|
| 682 | array( |
---|
| 683 | 'VALUE'=> -1, |
---|
| 684 | 'CONTENT' => '------------', |
---|
| 685 | 'SELECTED' => '' |
---|
| 686 | )); |
---|
| 687 | |
---|
| 688 | foreach ($groups as $group_id => $group_name) |
---|
| 689 | { |
---|
| 690 | if (isset($_POST['pref_submit'])) |
---|
| 691 | { |
---|
| 692 | $selected = $_POST['associate'] == $group_id ? 'selected="selected"' : ''; |
---|
| 693 | } |
---|
| 694 | else |
---|
| 695 | { |
---|
| 696 | $selected = ''; |
---|
| 697 | } |
---|
[1620] | 698 | |
---|
[787] | 699 | $template->assign_block_vars( |
---|
| 700 | $blockname, |
---|
| 701 | array( |
---|
| 702 | 'VALUE' => $group_id, |
---|
| 703 | 'CONTENT' => $group_name, |
---|
| 704 | 'SELECTED' => $selected |
---|
| 705 | )); |
---|
| 706 | } |
---|
| 707 | |
---|
| 708 | // dissociate |
---|
| 709 | $blockname = 'dissociate_option'; |
---|
| 710 | |
---|
| 711 | $template->assign_block_vars( |
---|
| 712 | $blockname, |
---|
| 713 | array( |
---|
| 714 | 'VALUE'=> -1, |
---|
| 715 | 'CONTENT' => '------------', |
---|
| 716 | 'SELECTED' => '' |
---|
| 717 | )); |
---|
| 718 | |
---|
| 719 | foreach ($groups as $group_id => $group_name) |
---|
| 720 | { |
---|
| 721 | if (isset($_POST['pref_submit'])) |
---|
| 722 | { |
---|
| 723 | $selected = $_POST['dissociate'] == $group_id ? 'selected="selected"' : ''; |
---|
| 724 | } |
---|
| 725 | else |
---|
| 726 | { |
---|
| 727 | $selected = ''; |
---|
| 728 | } |
---|
[1620] | 729 | |
---|
[787] | 730 | $template->assign_block_vars( |
---|
| 731 | $blockname, |
---|
| 732 | array( |
---|
| 733 | 'VALUE' => $group_id, |
---|
| 734 | 'CONTENT' => $group_name, |
---|
| 735 | 'SELECTED' => $selected |
---|
| 736 | )); |
---|
| 737 | } |
---|
| 738 | |
---|
[768] | 739 | // +-----------------------------------------------------------------------+ |
---|
| 740 | // | navigation bar | |
---|
| 741 | // +-----------------------------------------------------------------------+ |
---|
| 742 | |
---|
| 743 | $url = PHPWG_ROOT_PATH.'admin.php'.get_query_string_diff(array('start')); |
---|
| 744 | |
---|
[880] | 745 | $navbar = create_navigation_bar( |
---|
| 746 | $url, |
---|
| 747 | count($page['filtered_users']), |
---|
| 748 | $start, |
---|
[1084] | 749 | $conf['users_page'] |
---|
[880] | 750 | ); |
---|
[768] | 751 | |
---|
| 752 | $template->assign_vars(array('NAVBAR' => $navbar)); |
---|
| 753 | |
---|
| 754 | // +-----------------------------------------------------------------------+ |
---|
| 755 | // | user list | |
---|
| 756 | // +-----------------------------------------------------------------------+ |
---|
| 757 | |
---|
[1753] | 758 | $profile_url = get_root_url().'admin.php?page=profile&user_id='; |
---|
| 759 | $perm_url = get_root_url().'admin.php?page=user_perm&user_id='; |
---|
[768] | 760 | |
---|
[880] | 761 | foreach ($page['filtered_users'] as $num => $local_user) |
---|
[768] | 762 | { |
---|
[880] | 763 | // simulate LIMIT $start, $conf['users_page'] |
---|
| 764 | if ($num < $start) |
---|
| 765 | { |
---|
| 766 | continue; |
---|
| 767 | } |
---|
| 768 | if ($num >= $start + $conf['users_page']) |
---|
| 769 | { |
---|
| 770 | break; |
---|
| 771 | } |
---|
[768] | 772 | |
---|
[880] | 773 | $groups_string = preg_replace( |
---|
| 774 | '/(\d+)/e', |
---|
| 775 | "\$groups['$1']", |
---|
| 776 | implode( |
---|
| 777 | ', ', |
---|
| 778 | $local_user['groups'] |
---|
| 779 | ) |
---|
| 780 | ); |
---|
[768] | 781 | |
---|
[880] | 782 | if (isset($_POST['pref_submit']) |
---|
| 783 | and isset($_POST['selection']) |
---|
| 784 | and in_array($local_user['id'], $_POST['selection'])) |
---|
[768] | 785 | { |
---|
[880] | 786 | $checked = 'checked="checked"'; |
---|
[768] | 787 | } |
---|
[880] | 788 | else |
---|
[768] | 789 | { |
---|
[880] | 790 | $checked = ''; |
---|
| 791 | } |
---|
[1087] | 792 | |
---|
[880] | 793 | $template->assign_block_vars( |
---|
| 794 | 'user', |
---|
| 795 | array( |
---|
| 796 | 'CLASS' => ($num % 2 == 1) ? 'row2' : 'row1', |
---|
| 797 | 'ID' => $local_user['id'], |
---|
| 798 | 'CHECKED' => $checked, |
---|
[1753] | 799 | 'U_PROFILE' => $profile_url.$local_user['id'], |
---|
[1004] | 800 | 'U_PERM' => $perm_url.$local_user['id'], |
---|
[880] | 801 | 'USERNAME' => $local_user['username'], |
---|
[1085] | 802 | 'STATUS' => $lang['user_status_'.$local_user['status']].(($local_user['adviser'] == 'true') ? ' ['.$lang['adviser'].']' : ''), |
---|
[1462] | 803 | 'EMAIL' => get_email_address_as_display_text($local_user['email']), |
---|
[1079] | 804 | 'GROUPS' => $groups_string, |
---|
| 805 | 'PROPERTIES' => (isset($local_user['enabled_high']) and ($local_user['enabled_high'] == 'true')) ? $lang['is_high_enabled'] : $lang['is_high_disabled'] |
---|
[880] | 806 | ) |
---|
| 807 | ); |
---|
[768] | 808 | } |
---|
| 809 | |
---|
| 810 | // +-----------------------------------------------------------------------+ |
---|
| 811 | // | html code display | |
---|
| 812 | // +-----------------------------------------------------------------------+ |
---|
| 813 | |
---|
| 814 | $template->assign_var_from_handle('ADMIN_CONTENT', 'user_list'); |
---|
| 815 | ?> |
---|