2525
2626// setting the name of the tool
2727$ tool_name = get_lang ('SubscribeUsersToClass ' );
28+ $ showAllStudentByDefault = api_get_configuration_value ('usergroup_add_user_show_all_student_by_default ' );
2829
2930$ htmlHeadXtra [] = '
3031<script>
3536 });
3637});
3738
39+ function activeUsers(originalUrl) {
40+ var searchValue = document.getElementById("first_letter_user").value;
41+ window.location.href = originalUrl + "&firstLetterUser=" + encodeURIComponent(searchValue);
42+ }
43+
3844function add_user_to_session (code, content) {
3945 document.getElementById("user_to_add").value = "";
4046 document.getElementById("ajax_list_users_single").innerHTML = "";
@@ -87,7 +93,7 @@ function change_select(reset) {
8793 if (reset) {
8894 document.formulaire["first_letter_user"].value = "";
8995
90- if ( ' .(api_get_configuration_value ( ' usergroup_add_user_show_all_student_by_default ' ) ? 0 : 1 ).') {
96+ if ( ' .($ showAllStudentByDefault ? 0 : 1 ).') {
9197 document.formulaire["form_sent"].value = "1";
9298
9399 return;
@@ -129,10 +135,10 @@ function change_select(reset) {
129135
130136$ first_letter_user = '' ;
131137
132- if (isset ($ _POST ['form_sent ' ]) && $ _POST ['form_sent ' ]) {
138+ if (( isset ($ _POST ['form_sent ' ]) && $ _POST ['form_sent ' ]) || isset ( $ _REQUEST [ ' firstLetterUser ' ]) ) {
133139 $ form_sent = $ _POST ['form_sent ' ];
134140 $ elements_posted = $ _POST ['elements_in_name ' ] ?? null ;
135- $ first_letter_user = $ _POST ['firstLetterUser ' ];
141+ $ first_letter_user = Security:: remove_XSS ( $ _REQUEST ['firstLetterUser ' ]) ;
136142
137143 if (!is_array ($ elements_posted )) {
138144 $ elements_posted = [];
@@ -247,7 +253,9 @@ function change_select(reset) {
247253}
248254
249255$ activeUser = isset ($ _REQUEST ['active_users ' ]) ? (int ) $ _REQUEST ['active_users ' ] : null ;
250- $ conditions ['active ' ] = $ activeUser ;
256+ if (1 === $ activeUser ) {
257+ $ conditions ['active ' ] = $ activeUser ;
258+ }
251259
252260$ filterData = [];
253261if ($ searchForm ->validate ()) {
@@ -268,7 +276,7 @@ function change_select(reset) {
268276foreach ($ list_in as $ listedUserId ) {
269277 $ userInfo = api_get_user_info ($ listedUserId );
270278
271- if (isset ( $ activeUser) && (( int ) $ activeUser != $ userInfo ['active ' ])) {
279+ if (1 === $ activeUser && empty ( $ userInfo ['active ' ])) {
272280 $ hideElementsIn [] = $ listedUserId ;
273281 continue ;
274282 }
@@ -279,9 +287,7 @@ function change_select(reset) {
279287$ user_with_any_group = !empty ($ _REQUEST ['user_with_any_group ' ]);
280288$ user_list = [];
281289
282- if (!empty ($ conditions )) {
283- $ user_list = UserManager::getUserListLike ($ conditions , $ order , true , 'OR ' );
284- }
290+ $ user_list = UserManager::getUserListLike ($ conditions , $ order , true , 'OR ' );
285291
286292if ($ user_with_any_group ) {
287293 $ new_user_list = [];
@@ -306,17 +312,16 @@ function change_select(reset) {
306312 continue ;
307313 }
308314
309- if (isset ($ activeUser ) && ((int ) $ activeUser != $ item ['active ' ])) {
310- continue ;
311- }
312-
313315 if (!in_array ($ item ['user_id ' ], $ list_in )) {
314316 $ elements_not_in [$ item ['user_id ' ]] = formatCompleteName ($ item , $ orderListByOfficialCode );
315317 }
316318 }
317319}
318320
319- if (api_get_configuration_value ('usergroup_add_user_show_all_student_by_default ' )
321+ if (!$ showAllStudentByDefault && !isset ($ _POST ['firstLetterUser ' ]) && !isset ($ _REQUEST ['active_users ' ])) {
322+ $ elements_not_in = [];
323+ }
324+ if ($ showAllStudentByDefault
320325 && empty ($ elements_not_in )
321326 && empty ($ first_letter_user )
322327) {
@@ -362,13 +367,13 @@ function formatCompleteName(array $userInfo, bool $orderListByOfficialCode): str
362367echo '<a href=" ' .api_get_self ().'?id= ' .$ id .'&action=export"> ' .
363368 Display::return_icon ('export_csv.png ' , get_lang ('Export ' ), [], ICON_SIZE_MEDIUM ).'</a> ' ;
364369
365- $ newUrl = api_get_self (). ' ?id= ' . $ id . ' &active_users=1 ' ;
366- $ buttonLabel = get_lang ( ' OnlyShowActiveUsers ' ) ;
367- if ( $ activeUser ) {
368- $ buttonLabel = get_lang ( 'ShowAllUsers ' ) ;
369- $ newUrl = api_get_self (). ' ?id= ' . $ id ;
370- }
371- echo '<a href=" ' . htmlspecialchars ($ newUrl ) . '" class="btn btn-default"> ' . $ buttonLabel . '</a> ' ;
370+ $ isActiveUser = ! empty ( $ activeUser ) ;
371+ $ activeUsersParam = $ isActiveUser ? ' 0 ' : ' 1 ' ;
372+ $ newUrl = api_get_self () . ' ?id= ' . $ id . ' &active_users= ' . $ activeUsersParam ;
373+ $ buttonLabelKey = $ isActiveUser ? 'ShowAllUsers ' : ' OnlyShowActiveUsers ' ;
374+ $ buttonLabel = get_lang ( $ buttonLabelKey ) ;
375+
376+ echo '<a href="#" onclick="activeUsers( \'' . htmlspecialchars ($ newUrl ) . '\' ); return false; " class="btn btn-default"> ' . $ buttonLabel . '</a> ' ;
372377
373378echo '</div> ' ;
374379
0 commit comments