From bd6d2d0a217247c42f6b1083d1d2f4783ae3cad8 Mon Sep 17 00:00:00 2001 From: plegall Date: Mon, 25 Apr 2005 21:35:10 +0000 Subject: - profile.php is no longer used for listing users : admin/user_list.php comes back (as in 1.3 branch) - user list updated : ability to filter list on username git-svn-id: http://piwigo.org/svn/trunk@768 68402e56-0260-453c-a942-63ccdbb3a9ee --- admin/user_list.php | 246 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 246 insertions(+) create mode 100644 admin/user_list.php (limited to 'admin') diff --git a/admin/user_list.php b/admin/user_list.php new file mode 100644 index 000000000..8e50f9c02 --- /dev/null +++ b/admin/user_list.php @@ -0,0 +1,246 @@ +set_filenames(array('user_list'=>'admin/user_list.tpl')); + +$base_url = add_session_id(PHPWG_ROOT_PATH.'admin.php?page=user_list'); + +$conf['users_page'] = 20; + +if (isset($_GET['start']) and is_numeric($_GET['start'])) +{ + $start = $_GET['start']; +} +else +{ + $start = 0; +} + +$template->assign_vars( + array( + 'L_AUTH_USER'=>$lang['permuser_only_private'], + 'L_GROUP_ADD_USER' => $lang['group_add_user'], + 'L_SUBMIT'=>$lang['submit'], + 'L_STATUS'=>$lang['user_status'], + 'L_USERNAME' => $lang['login'], + 'L_PASSWORD' => $lang['password'], + 'L_EMAIL' => $lang['mail_address'], + 'L_ORDER_BY' => $lang['order_by'], + 'L_ACTIONS' => $lang['actions'], + 'L_PERMISSIONS' => $lang['permissions'], + 'L_USERS_LIST' => $lang['title_liste_users'], + + 'F_ADD_ACTION' => $base_url, + 'F_USERNAME' => @$_GET['username'], + 'F_FILTER_ACTION' => PHPWG_ROOT_PATH.'admin.php' + )); + +if (isset($_GET['id'])) +{ + $template->assign_block_vars('session', array('ID' => $_GET['id'])); +} + +$order_by_items = array('id' => $lang['registration_date'], + 'username' => $lang['login']); + +foreach ($order_by_items as $item => $label) +{ + $selected = (isset($_GET['order_by']) and $_GET['order_by'] == $item) ? + 'selected="selected"' : ''; + $template->assign_block_vars( + 'order_by', + array( + 'VALUE' => $item, + 'CONTENT' => $label, + 'SELECTED' => $selected + )); +} + +$direction_items = array('asc' => $lang['ascending'], + 'desc' => $lang['descending']); + +foreach ($direction_items as $item => $label) +{ + $selected = (isset($_GET['direction']) and $_GET['direction'] == $item) ? + 'selected="selected"' : ''; + $template->assign_block_vars( + 'direction', + array( + 'VALUE' => $item, + 'CONTENT' => $label, + 'SELECTED' => $selected + )); +} + +// +-----------------------------------------------------------------------+ +// | filter | +// +-----------------------------------------------------------------------+ + +$username = !empty($_GET['username']) ? $_GET['username'] : '%'; +$username = str_replace('*', '%', $username); +if (function_exists('mysql_real_escape_string')) +{ + $username = mysql_real_escape_string($username); +} +else +{ + $username = mysql_escape_string($username); +} +$username = !empty($username) ? $username : '%'; + +// +-----------------------------------------------------------------------+ +// | navigation bar | +// +-----------------------------------------------------------------------+ + +$query = ' +SELECT count(*) + FROM '.USERS_TABLE.' + WHERE id != 2 + AND username LIKE \''.$username.'\' +;'; +list($counter) = mysql_fetch_row(pwg_query($query)); + +$url = PHPWG_ROOT_PATH.'admin.php'.get_query_string_diff(array('start')); + +$navbar = create_navigation_bar($url, + $counter, + $start, + $conf['users_page'], + ''); + +$template->assign_vars(array('NAVBAR' => $navbar)); + +// +-----------------------------------------------------------------------+ +// | user list | +// +-----------------------------------------------------------------------+ + +$profile_url = PHPWG_ROOT_PATH.'admin.php?page=profile&user_id='; +$perm_url = PHPWG_ROOT_PATH.'admin.php?page=user_perm&user_id='; + +$users = array(); +$user_ids = array(); +$groups_content = array(); + +$order_by = 'id'; +if (isset($_GET['order_by']) + and in_array($_GET['order_by'], array_keys($order_by_items))) +{ + $order_by = $_GET['order_by']; +} + +$direction = 'ASC'; +if (isset($_GET['direction']) + and in_array($_GET['direction'], array_keys($direction_items))) +{ + $direction = strtoupper($_GET['direction']); +} + +$query = ' +SELECT id, username, mail_address, status + FROM '.USERS_TABLE.' + WHERE id != 2 + AND username LIKE \''.$username.'\' + ORDER BY '.$order_by.' '.$direction.' + LIMIT '.$start.', '.$conf['users_page'].' +;'; +$result = pwg_query($query); +while ($row = mysql_fetch_array($result)) +{ + array_push($users, $row); + array_push($user_ids, $row['id']); + $user_groups[$row['id']] = array(); +} + +if (count($user_ids) > 0) +{ + $query = ' +SELECT user_id, group_id, name + FROM '.USER_GROUP_TABLE.' INNER JOIN '.GROUPS_TABLE.' ON group_id = id + WHERE user_id IN ('.implode(',', $user_ids).') +;'; + $result = pwg_query($query); + while ($row = mysql_fetch_array($result)) + { + $groups_content[$row['group_id']] = $row['name']; + array_push($user_groups[$row['user_id']], $row['group_id']); + } + + foreach ($users as $item) + { + $groups = preg_replace('/(\d+)/e', + "\$groups_content['$1']", + implode(', ', $user_groups[$item['id']])); + + $template->assign_block_vars( + 'user', + array( + 'U_MOD'=>add_session_id($profile_url.$item['id']), + 'U_PERM'=>add_session_id($perm_url.$item['id']), + 'USERNAME'=>$item['username'], + 'STATUS'=>$lang['user_status_'.$item['status']], + 'EMAIL'=>isset($item['mail_address']) ? $item['mail_address'] : '', + 'GROUPS'=>$groups + )); + } +} + +// +-----------------------------------------------------------------------+ +// | html code display | +// +-----------------------------------------------------------------------+ + +$template->assign_var_from_handle('ADMIN_CONTENT', 'user_list'); +?> -- cgit v1.2.3