@@ -264,7 +264,8 @@ function confirmation(name) {
264264
265265$ display = 'none ' ;
266266if (isset ($ _POST ['roles ' ]) && is_array ($ _POST ['roles ' ])) {
267- $ display = in_array ('ROLE_TEACHER ' , $ _POST ['roles ' ]) || in_array ('ROLE_SESSION_MANAGER ' , $ _POST ['roles ' ]) ? 'block ' : 'none ' ;
267+ $ norm = array_map ('api_normalize_role_code ' , $ _POST ['roles ' ]);
268+ $ display = (in_array ('ROLE_TEACHER ' , $ norm , true ) || in_array ('ROLE_SESSION_MANAGER ' , $ norm , true )) ? 'block ' : 'none ' ;
268269}
269270
270271// Platform admin
@@ -398,9 +399,22 @@ function confirmation(name) {
398399 $ user_data ['expiration_date ' ] = api_get_local_time ($ expiration_date );
399400 }
400401}
401- $ availableRoles = array_keys (api_get_roles ());
402- $ userRoles = array_intersect ($ userObj ->getRoles (), $ availableRoles );
403- $ user_data ['roles ' ] = $ userRoles ;
402+
403+ $ roleOptions = api_get_roles ();
404+ $ optionKeyByCanon = [];
405+ foreach ($ roleOptions as $ optKey => $ label ) {
406+ $ optionKeyByCanon [api_normalize_role_code ((string ) $ optKey )] = $ optKey ;
407+ }
408+
409+ $ userCanonRoles = array_map ('api_normalize_role_code ' , (array ) $ userObj ->getRoles ());
410+ $ selectedOptionKeys = [];
411+ foreach ($ userCanonRoles as $ canon ) {
412+ if (isset ($ optionKeyByCanon [$ canon ])) {
413+ $ selectedOptionKeys [] = $ optionKeyByCanon [$ canon ];
414+ }
415+ }
416+
417+ $ user_data ['roles ' ] = array_values (array_unique ($ selectedOptionKeys ));
404418$ form ->setDefaults ($ user_data );
405419
406420$ error_drh = false ;
0 commit comments