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