diff --git a/main/auth/inscription.php b/main/auth/inscription.php index 657de85929..4e9542ee86 100755 --- a/main/auth/inscription.php +++ b/main/auth/inscription.php @@ -893,13 +893,7 @@ if ($form->validate()) { if (isset($values['legal_accept_type'])) { $cond_array = explode(':', $values['legal_accept_type']); if (!empty($cond_array[0]) && !empty($cond_array[1])) { - $time = time(); - $conditionToSave = (int) $cond_array[0].':'.(int) $cond_array[1].':'.$time; - UserManager::update_extra_field_value( - $user_id, - 'legal_accept', - $conditionToSave - ); + $conditionToSave = (int) $cond_array[0].':'.(int) $cond_array[1].':'.time(); Event::addEvent( LOG_TERM_CONDITION_ACCEPTED, @@ -908,29 +902,7 @@ if ($form->validate()) { api_get_utc_datetime() ); - $bossList = UserManager::getStudentBossList($user_id); - if (!empty($bossList)) { - $bossList = array_column($bossList, 'boss_id'); - $currentUserInfo = api_get_user_info($user_id); - foreach ($bossList as $bossId) { - $subjectEmail = sprintf( - get_lang('UserXSignedTheAgreement'), - $currentUserInfo['complete_name'] - ); - $contentEmail = sprintf( - get_lang('UserXSignedTheAgreementTheY'), - $currentUserInfo['complete_name'], - api_get_local_time($time) - ); - - MessageManager::send_message_simple( - $bossId, - $subjectEmail, - $contentEmail, - $user_id - ); - } - } + LegalManager::sendEmailToUserBoss($user_id, $conditionToSave); } } $values = api_get_user_info($user_id); diff --git a/main/inc/lib/legal.lib.php b/main/inc/lib/legal.lib.php index 097486f8f0..c52da1e9c4 100755 --- a/main/inc/lib/legal.lib.php +++ b/main/inc/lib/legal.lib.php @@ -455,4 +455,33 @@ class LegalManager 'privacy_terms_profiling' => 'profiling', ]; } + + public static function sendEmailToUserBoss($userId, $conditionToSave) + { + UserManager::update_extra_field_value($userId, 'legal_accept', $conditionToSave); + + $bossList = UserManager::getStudentBossList($userId); + + if (empty($bossList)) { + return; + } + + $bossList = array_column($bossList, 'boss_id'); + + $currentUserInfo = api_get_user_info($userId); + + foreach ($bossList as $bossId) { + $subjectEmail = sprintf( + get_lang('UserXSignedTheAgreement'), + $currentUserInfo['complete_name'] + ); + $contentEmail = sprintf( + get_lang('UserXSignedTheAgreementTheY'), + $currentUserInfo['complete_name'], + api_get_local_time() + ); + + MessageManager::send_message_simple($bossId, $subjectEmail, $contentEmail, $userId); + } + } } diff --git a/main/social/personal_data.php b/main/social/personal_data.php index 89511ea73a..9109a2ed34 100755 --- a/main/social/personal_data.php +++ b/main/social/personal_data.php @@ -63,11 +63,6 @@ switch ($action) { } $legalAcceptType = $terms['version'].':'.$terms['language_id'].':'.time(); - UserManager::update_extra_field_value( - $userId, - 'legal_accept', - $legalAcceptType - ); Event::addEvent( LOG_TERM_CONDITION_ACCEPTED, @@ -76,29 +71,8 @@ switch ($action) { api_get_utc_datetime() ); - $bossList = UserManager::getStudentBossList($userId); - if (!empty($bossList)) { - $bossList = array_column($bossList, 'boss_id'); - $currentUserInfo = api_get_user_info($userId); - foreach ($bossList as $bossId) { - $subjectEmail = sprintf( - get_lang('UserXSignedTheAgreement'), - $currentUserInfo['complete_name'] - ); - $contentEmail = sprintf( - get_lang('UserXSignedTheAgreementTheDateY'), - $currentUserInfo['complete_name'], - api_get_local_time($time) - ); - - MessageManager::send_message_simple( - $bossId, - $subjectEmail, - $contentEmail, - $user_id - ); - } - } + LegalManager::sendEmailToUserBoss($userId, $legalAcceptType); + Display::addFlash(Display::return_message(get_lang('Saved'))); header('Location: '.api_get_self()); exit;