Group: Improve filter by lastname when adding users - refs BT#19736

pull/4189/head
Angel Fernando Quiroz Campos 4 years ago
parent 9128008e26
commit a0baf8993c
  1. 2
      app/Resources/public/css/base.css
  2. 84
      main/admin/add_users_to_usergroup.php

@ -4576,7 +4576,7 @@ i.size-32.icon-new-work {
} }
.multiple_select_header { .multiple_select_header {
height: 35px; min-height: 35px;
margin-bottom: 15px; margin-bottom: 15px;
} }

@ -11,7 +11,7 @@ require_once __DIR__.'/../inc/global.inc.php';
$this_section = SECTION_PLATFORM_ADMIN; $this_section = SECTION_PLATFORM_ADMIN;
$id = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0; $id = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0;
$relation = isset($_REQUEST['relation']) ? (int) $_REQUEST['relation'] : ''; $relation = isset($_REQUEST['relation']) ? (int) $_REQUEST['relation'] : 0;
$usergroup = new UserGroup(); $usergroup = new UserGroup();
$groupInfo = $usergroup->get($id); $groupInfo = $usergroup->get($id);
$usergroup->protectScript($groupInfo); $usergroup->protectScript($groupInfo);
@ -73,7 +73,10 @@ function checked_in_no_group(checked)
document.formulaire.submit(); document.formulaire.submit();
} }
function change_select(val) { function change_select(reset) {
if (reset) {
document.formulaire["first_letter_user"].value = "";
}
$("#user_with_any_group_id").attr("checked", false); $("#user_with_any_group_id").attr("checked", false);
document.formulaire.form_sent.value="2"; document.formulaire.form_sent.value="2";
document.formulaire.submit(); document.formulaire.submit();
@ -218,7 +221,7 @@ if ($orderListByOfficialCode === 'true') {
} }
$conditions = []; $conditions = [];
if (!empty($first_letter_user)) { if (!empty($first_letter_user) && strlen($first_letter_user) >= 3) {
$conditions['lastname'] = $first_letter_user; $conditions['lastname'] = $first_letter_user;
} }
@ -234,45 +237,29 @@ if (!empty($filters) && !empty($filterData)) {
} }
$elements_not_in = $elements_in = []; $elements_not_in = $elements_in = [];
$complete_user_list = UserManager::getUserListLike([], $order, false, 'AND');
if (!empty($complete_user_list)) { foreach ($list_in as $listedUserId) {
foreach ($complete_user_list as $item) { $userInfo = api_get_user_info($listedUserId);
if ($use_extra_fields) {
if (!in_array($item['user_id'], $final_result)) {
continue;
}
}
// Avoid anonymous users $person_name = $userInfo['complete_name_with_username']." {$userInfo['official_code']}";
if ($item['status'] == 6) {
continue;
}
if (in_array($item['user_id'], $list_in)) {
$officialCode = !empty($item['official_code']) ? ' - '.$item['official_code'] : null;
$person_name = api_get_person_name(
$item['firstname'],
$item['lastname']
).' ('.$item['username'].') '.$officialCode;
$orderListByOfficialCode = api_get_setting('order_user_list_by_official_code');
if ($orderListByOfficialCode === 'true') { if ($orderListByOfficialCode === 'true') {
$officialCode = !empty($item['official_code']) ? $item['official_code'].' - ' : '? - '; $officialCode = !empty($userInfo['official_code']) ? $userInfo['official_code'].' - ' : '? - ';
$person_name = $officialCode.api_get_person_name(
$item['firstname'],
$item['lastname']
).' ('.$item['username'].') ';
}
$elements_in[$item['user_id']] = $person_name; $person_name = $officialCode.$userInfo['complete_name_with_username'];
}
} }
$elements_in[$listedUserId] = $person_name;
} }
$user_with_any_group = isset($_REQUEST['user_with_any_group']) && !empty($_REQUEST['user_with_any_group']) ? true : false; $user_with_any_group = isset($_REQUEST['user_with_any_group']) && !empty($_REQUEST['user_with_any_group']) ? true : false;
if ($user_with_any_group) { $user_list = [];
if (!empty($conditions)) {
$user_list = UserManager::getUserListLike($conditions, $order, true, 'AND'); $user_list = UserManager::getUserListLike($conditions, $order, true, 'AND');
}
if ($user_with_any_group) {
$new_user_list = []; $new_user_list = [];
foreach ($user_list as $item) { foreach ($user_list as $item) {
if (!in_array($item['user_id'], $list_all)) { if (!in_array($item['user_id'], $list_all)) {
@ -280,8 +267,6 @@ if ($user_with_any_group) {
} }
} }
$user_list = $new_user_list; $user_list = $new_user_list;
} else {
$user_list = UserManager::getUserListLike($conditions, $order, true, 'AND');
} }
if (!empty($user_list)) { if (!empty($user_list)) {
@ -298,18 +283,11 @@ if (!empty($user_list)) {
} }
$officialCode = !empty($item['official_code']) ? ' - '.$item['official_code'] : null; $officialCode = !empty($item['official_code']) ? ' - '.$item['official_code'] : null;
$person_name = api_get_person_name( $person_name = $item['complete_name_with_username']." $officialCode";
$item['firstname'],
$item['lastname']
).' ('.$item['username'].') '.$officialCode;
$orderListByOfficialCode = api_get_setting('order_user_list_by_official_code');
if ($orderListByOfficialCode === 'true') { if ($orderListByOfficialCode === 'true') {
$officialCode = !empty($item['official_code']) ? $item['official_code'].' - ' : '? - '; $officialCode = !empty($item['official_code']) ? $item['official_code'].' - ' : '? - ';
$person_name = $officialCode.api_get_person_name( $person_name = $officialCode.$item['complete_name_with_username'];
$item['firstname'],
$item['lastname']
).' ('.$item['username'].') ';
} }
if (!in_array($item['user_id'], $list_in)) { if (!in_array($item['user_id'], $list_in)) {
@ -395,13 +373,19 @@ echo Display::input('hidden', 'add_type', null);
<div class="multiple_select_header"> <div class="multiple_select_header">
<b><?php echo get_lang('UsersInPlatform'); ?> :</b> <b><?php echo get_lang('UsersInPlatform'); ?> :</b>
<?php echo get_lang('FirstLetterUser'); ?> : <div class="input-group">
<select id="first_letter_user" name="firstLetterUser" onchange="change_select();"> <input id="first_letter_user" name="firstLetterUser" type="text" class="form-control"
<option value = "%">--</option> value="<?php echo Security::remove_XSS($first_letter_user) ?>"
<?php placeholder="<?php echo get_lang('Search') ?>">
echo Display :: get_alphabet_options($first_letter_user); <span class="input-group-btn">
?> <button class="btn btn-default" type="button" onclick="change_select();">
</select> <?php echo get_lang('Filter') ?>
</button>
<button class="btn btn-default" type="button" onclick="change_select(true);">
<?php echo get_lang('Reset') ?>
</button>
</span>
</div>
</div> </div>
<?php <?php
echo Display::select( echo Display::select(

Loading…
Cancel
Save