@@ -441,7 +441,7 @@ function confirmation(name) {
441441 $ lastname = $ user ['lastname ' ];
442442 $ firstname = $ user ['firstname ' ];
443443 $ password = $ user ['password ' ];
444- $ auth_source = $ user ['auth_source ' ] ?? $ userInfo ['auth_source ' ];
444+ $ auth_source = $ user ['auth_source ' ] ?? ( $ userInfo ['auth_source ' ] ?? []) ;
445445 $ official_code = $ user ['official_code ' ];
446446 $ email = $ user ['email ' ];
447447 $ phone = $ user ['phone ' ];
@@ -474,6 +474,50 @@ function confirmation(name) {
474474
475475 $ template = $ user ['email_template_option ' ] ?? [];
476476
477+ $ incompatible = false ;
478+ $ conflicts = [];
479+ $ oldStatus = $ userObj ->getStatus ();
480+ $ newStatus = (int ) $ user ['status ' ];
481+ if ($ oldStatus !== $ newStatus ) {
482+ $ isNowStudent = $ newStatus === STUDENT ;
483+ if ($ isNowStudent ) {
484+ $ courseTeacherCount = $ userObj ->getCourses ()->count ();
485+ $ coachSessions = $ userObj ->getSessionsAsGeneralCoach ();
486+ $ adminSessions = $ userObj ->getSessionsAsAdmin ();
487+
488+ if ($ courseTeacherCount > 0 ) {
489+ $ conflicts [] = get_lang ('User is teacher in some courses ' );
490+ }
491+
492+ if (!empty ($ coachSessions )) {
493+ $ conflicts [] = get_lang ('User is general coach in some sessions ' );
494+ }
495+
496+ if (!empty ($ adminSessions )) {
497+ $ conflicts [] = get_lang ('User is session admin in some sessions ' );
498+ }
499+
500+ if (!empty ($ conflicts )) {
501+ $ incompatible = true ;
502+ }
503+ }
504+ }
505+ if ($ incompatible ) {
506+ $ conflictMessage = Display::return_message (
507+ get_lang ('Role change denied due to incompatible current assignments: ' ).'<br>- ' .implode ('<br>- ' , $ conflicts ),
508+ 'error ' ,
509+ false
510+ );
511+
512+ $ content = $ conflictMessage ;
513+ $ content .= $ form ->returnForm ();
514+
515+ $ tpl = new Template ($ tool_name );
516+ $ tpl ->assign ('content ' , $ content );
517+ $ tpl ->display_one_col_template ();
518+ exit ;
519+ }
520+
477521 UserManager::update_user (
478522 $ user_id ,
479523 $ firstname ,
0 commit comments