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,7 +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 ) ) {
290+ if (!(! $ showAllStudentByDefault && ! isset ( $ _POST [ ' firstLetterUser ' ]) && ! isset ( $ _REQUEST [ ' active_users ' ])) && ! $ user_with_any_group ) {
283291 $ user_list = UserManager::getUserListLike ($ conditions , $ order , true , 'OR ' );
284292}
285293
@@ -306,17 +314,16 @@ function change_select(reset) {
306314 continue ;
307315 }
308316
309- if (isset ($ activeUser ) && ((int ) $ activeUser != $ item ['active ' ])) {
310- continue ;
311- }
312-
313317 if (!in_array ($ item ['user_id ' ], $ list_in )) {
314318 $ elements_not_in [$ item ['user_id ' ]] = formatCompleteName ($ item , $ orderListByOfficialCode );
315319 }
316320 }
317321}
318322
319- if (api_get_configuration_value ('usergroup_add_user_show_all_student_by_default ' )
323+ if (!$ showAllStudentByDefault && !isset ($ _POST ['firstLetterUser ' ]) && !isset ($ _REQUEST ['active_users ' ])) {
324+ $ elements_not_in = [];
325+ }
326+ if ($ showAllStudentByDefault
320327 && empty ($ elements_not_in )
321328 && empty ($ first_letter_user )
322329) {
@@ -362,13 +369,13 @@ function formatCompleteName(array $userInfo, bool $orderListByOfficialCode): str
362369echo '<a href=" ' .api_get_self ().'?id= ' .$ id .'&action=export"> ' .
363370 Display::return_icon ('export_csv.png ' , get_lang ('Export ' ), [], ICON_SIZE_MEDIUM ).'</a> ' ;
364371
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> ' ;
372+ $ isActiveUser = ! empty ( $ activeUser ) ;
373+ $ activeUsersParam = $ isActiveUser ? ' 0 ' : ' 1 ' ;
374+ $ newUrl = api_get_self () . ' ?id= ' . $ id . ' &active_users= ' . $ activeUsersParam ;
375+ $ buttonLabelKey = $ isActiveUser ? 'ShowAllUsers ' : ' OnlyShowActiveUsers ' ;
376+ $ buttonLabel = get_lang ( $ buttonLabelKey ) ;
377+
378+ echo '<a href="#" onclick="activeUsers( \'' . htmlspecialchars ($ newUrl ) . '\' ); return false; " class="btn btn-default"> ' . $ buttonLabel . '</a> ' ;
372379
373380echo '</div> ' ;
374381
0 commit comments