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