From d52502795d97f464c41cac86edf0f6395715c013 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Thu, 19 Sep 2013 16:58:39 +0200 Subject: [PATCH] Adding user_name_order setting does not work in 1.9 + fixing the user list order see BT#6535 --- main/admin/access_url_edit_users_to_url.php | 119 ++++++++------------ main/inc/lib/internationalization.lib.php | 35 +++++- 2 files changed, 80 insertions(+), 74 deletions(-) diff --git a/main/admin/access_url_edit_users_to_url.php b/main/admin/access_url_edit_users_to_url.php index 826d08a061..b2b298c200 100644 --- a/main/admin/access_url_edit_users_to_url.php +++ b/main/admin/access_url_edit_users_to_url.php @@ -116,7 +116,7 @@ if ($_POST['form_sent']) { foreach ($result['users_added'] as $user) { $user_info = api_get_user_info($user); if (!empty($user_info)) { - $user_added_list[] = $i . '. ' . api_get_person_name($user_info['firstname'], $user_info['lastname']); + $user_added_list[] = $i . '. ' . api_get_person_name($user_info['firstname'], $user_info['lastname'], null, null, null, null, $user_info['username']); $i++; } } @@ -174,7 +174,7 @@ if ($ajax_search) { $sessionUsersList[$user['user_id']] = $user; } } - $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname, username' : ' ORDER BY lastname, firstname, username'; + $order_clause = api_sort_by_first_name() ? ' ORDER BY username, firstname, lastname' : ' ORDER BY username, lastname, firstname'; $sql = "SELECT u.user_id, lastname, firstname, username FROM $tbl_user u WHERE status <> " . ANONYMOUS . " " . $order_clause; @@ -188,7 +188,6 @@ if ($ajax_search) { } } - if ($add_type == 'multiple') { $link_add_type_unique = '' . get_lang('SessionAddTypeUnique') . ''; $link_add_type_multiple = get_lang('SessionAddTypeMultiple'); @@ -196,7 +195,6 @@ if ($add_type == 'multiple') { $link_add_type_unique = get_lang('SessionAddTypeUnique'); $link_add_type_multiple = '' . get_lang('SessionAddTypeMultiple') . ''; } - $url_list = UrlManager::get_url_data(); ?> @@ -232,19 +230,19 @@ $url_list = UrlManager::get_url_data(); - + @@ -259,77 +257,61 @@ $url_list = UrlManager::get_url_data(); - - - - -

- - -
- - - + + +
+ + +
- - - - -

- - + + + + +

+ +






- ' . get_lang('AddUsersToURL') . ''; - else - echo ''; - ?> + ' . get_lang('AddUsersToURL') . ''; + } else { + echo ''; + } + ?>
@@ -422,7 +404,6 @@ function makepost(select){ } --> - - initial implementation. * @author Ivan Tcholakov */ -function api_get_person_name($first_name, $last_name, $title = null, $format = null, $language = null, $encoding = null) { +function api_get_person_name($first_name, $last_name, $title = null, $format = null, $language = null, $encoding = null, $username = null) { static $valid = array(); if (empty($format)) { $format = PERSON_NAME_COMMON_CONVENTION; @@ -1051,6 +1051,10 @@ function api_get_person_name($first_name, $last_name, $title = null, $format = n switch ($format) { case PERSON_NAME_COMMON_CONVENTION: $valid[$format][$language] = _api_get_person_name_convention($language, 'format'); + $usernameOrderFromDatabase = api_get_setting('user_name_order'); + if (isset($usernameOrderFromDatabase) && !empty($usernameOrderFromDatabase)) { + $valid[$format][$language] = $usernameOrderFromDatabase; + } break; case PERSON_NAME_WESTERN_ORDER: $valid[$format][$language] = '%t %f %l'; @@ -1069,11 +1073,26 @@ function api_get_person_name($first_name, $last_name, $title = null, $format = n $valid[$format][$language] = _api_validate_person_name_format($format); } } + $format = $valid[$format][$language]; - $person_name = str_replace(array('%f', '%l', '%t'), array($first_name, $last_name, $title), $format); - if (strpos($format, '%F') !== false || strpos($format, '%L') !== false || strpos($format, '%T') !== false) { - $person_name = str_replace(array('%F', '%L', '%T'), array(api_strtoupper($first_name, $encoding), api_strtoupper($last_name, $encoding), api_strtoupper($title, $encoding)), $person_name); - } + + $keywords = array('%firstname', '%f', '%F', '%lastname', '%l', '%L', '%title', '%t', '%T', '%username', '%u', '%U'); + + $values = array( + $first_name, + $first_name, + api_strtoupper($first_name, $encoding), + $last_name, + $last_name, + api_strtoupper($last_name, $encoding), + $title, + $title, + api_strtoupper($title, $encoding), + $username, + $username, + api_strtoupper($username, $encoding), + ); + $person_name = str_replace($keywords, $values, $format); return _api_clean_person_name($person_name); } @@ -1112,6 +1131,11 @@ function api_is_western_name_order($format = null, $language = null) { * @author Ivan Tcholakov */ function api_sort_by_first_name($language = null) { + $userNameSortBy = api_get_setting('user_name_sort_by'); + if (!empty($userNameSortBy) && in_array($userNameSortBy, array('firstname', 'lastname'))) { + return $userNameSortBy == 'firstname' ? true : false; + } + static $sort_by_first_name = array(); $language_is_supported = api_is_language_supported($language); @@ -1121,6 +1145,7 @@ function api_sort_by_first_name($language = null) { if (!isset($sort_by_first_name[$language])) { $sort_by_first_name[$language] = _api_get_person_name_convention($language, 'sort_by'); } + return $sort_by_first_name[$language]; }