diff --git a/main/exercise/exercise_report.php b/main/exercise/exercise_report.php index a185c69fb7..56166e470a 100755 --- a/main/exercise/exercise_report.php +++ b/main/exercise/exercise_report.php @@ -139,17 +139,8 @@ if (isset($_REQUEST['comments']) && $lp_id = $track_exercise_info['orig_lp_id']; $lp_item_view_id = $track_exercise_info['orig_lp_item_view_id']; $exerciseId = $track_exercise_info['exe_exo_id']; - $course_info = api_get_course_info(); - // Teacher data - $teacher_info = api_get_user_info(api_get_user_id()); - $from_name = api_get_person_name( - $teacher_info['firstname'], - $teacher_info['lastname'], - null, - PERSON_NAME_EMAIL_ADDRESS - ); $url = api_get_path(WEB_CODE_PATH).'exercise/result.php?id='.$track_exercise_info['exe_id'].'&'.api_get_cidreq().'&show_headers=1&id_session='.$session_id; $my_post_info = array(); @@ -222,20 +213,16 @@ if (isset($_REQUEST['comments']) && if (isset($_POST['send_notification'])) { //@todo move this somewhere else $subject = get_lang('ExamSheetVCC'); + /*$message = ExerciseLib::getEmailNotification( + api_get_user_id(), + $course_info, + $test, + $lp_id, + $url + );*/ - $message = '

'.get_lang('DearStudentEmailIntroduction').'

'.get_lang('AttemptVCC'); - $message .= '

'.get_lang('CourseName').'

'.Security::remove_XSS($course_info['name']).''; - $message .= '

'.get_lang('Exercise').'

'.Security::remove_XSS($test); - - // Only for exercises not in a LP - if ($lp_id == 0) { - $message .= '

'.get_lang('ClickLinkToViewComment').'
#url#
'; - } + $message = isset($_POST['notification_content']) ? $_POST['notification_content'] : ''; - $message .= '

'.get_lang('Regards').'

'; - $message .= $from_name; - $message = str_replace("#test#", Security::remove_XSS($test), $message); - $message = str_replace("#url#", $url, $message); MessageManager::send_message_simple( $student_id, $subject, diff --git a/main/exercise/exercise_show.php b/main/exercise/exercise_show.php index 0382e9d422..1ae508f877 100755 --- a/main/exercise/exercise_show.php +++ b/main/exercise/exercise_show.php @@ -166,6 +166,10 @@ if ($origin != 'learnpath') { document.getElementById(comment).style.display = 'none'; } + function openEmailWrapper() { + $('#email_content_wrapper').toggle(); + } + function getFCK(vals, marksid) { var f = document.getElementById('myform'); @@ -849,7 +853,7 @@ if ($isFeedbackAllowed) { } } -if ($isFeedbackAllowed) { +if ($isFeedbackAllowed && $origin != 'learnpath' && $origin != 'student_progress') { if (in_array($origin, array('tracking_course', 'user_course', 'correct_exercise_in_lp'))) { $formUrl = api_get_path(WEB_CODE_PATH) . 'exercise/exercise_report.php?' . api_get_cidreq() . '&'; $formUrl .= http_build_query([ @@ -863,12 +867,12 @@ if ($isFeedbackAllowed) { ]); $formUrl .= $fromlink; - echo '
'; - echo ''; - echo ''; - echo ''; - echo ' '; - echo ' '; + $emailForm = new FormValidator('myform', 'post', $formUrl, '', ['id' => 'myform']); + $emailForm->addHidden('lp_item_id', $learnpath_id); + $emailForm->addHidden('lp_item_view_id', $lp_item_view_id); + $emailForm->addHidden('student_id', $student_id); + $emailForm->addHidden('total_score', $totalScore); + $emailForm->addHidden('my_exe_exo_id', $exercise_id); } else { $formUrl = api_get_path(WEB_CODE_PATH) . 'exercise/exercise_report.php?' . api_get_cidreq() . '&'; $formUrl .= http_build_query([ @@ -878,20 +882,45 @@ if ($isFeedbackAllowed) { 'exeid' => $id ]); - echo ' '; + $emailForm = new FormValidator('myform', 'post', $formUrl, '', ['id' => 'myform']); } - if ($origin != 'learnpath' && $origin != 'student_progress') { - echo ''; - ?> -
- -
- addCheckBox( + 'send_notification', + get_lang('SendEmail'), + get_lang('SendEmail'), + ['onclick' => 'openEmailWrapper();'] + ); + $emailForm->addHtml(''); + + $url = api_get_path(WEB_CODE_PATH).'exercise/result.php?id='.$track_exercise_info['exe_id'].'&'.api_get_cidreq().'&show_headers=1&id_session='.api_get_session_id(); + + $content = ExerciseLib::getEmailNotification( + api_get_user_id(), + api_get_course_info(), + $track_exercise_info['title'], + $track_exercise_info['orig_lp_id'], + $url + ); + + $emailForm->setDefaults(['notification_content' => $content]); + + + $emailForm->addButtonSend( + get_lang('CorrectTest'), + 'submit', + false, + ['onclick' => "getFCK('$strids', '$marksid')"] + ); + + echo $emailForm->returnForm(); + } //Came from lpstats in a lp diff --git a/main/inc/lib/exercise.lib.php b/main/inc/lib/exercise.lib.php index 8b48189760..91d95bfcb3 100644 --- a/main/inc/lib/exercise.lib.php +++ b/main/inc/lib/exercise.lib.php @@ -3876,4 +3876,41 @@ HOTSPOT; } return $limits[0]; } + + /** + * @param int $senderId + * @param array $course_info + * @param string $test + * @param int $lp_id + * @param string $url + * + * @return string + */ + public static function getEmailNotification($senderId, $course_info, $test, $lp_id, $url) + { + $teacher_info = api_get_user_info($senderId); + + $from_name = api_get_person_name( + $teacher_info['firstname'], + $teacher_info['lastname'], + null, + PERSON_NAME_EMAIL_ADDRESS + ); + + $message = '

'.get_lang('DearStudentEmailIntroduction').'

'.get_lang('AttemptVCC'); + $message .= '

'.get_lang('CourseName').'

'.Security::remove_XSS($course_info['name']).''; + $message .= '

'.get_lang('Exercise').'

'.Security::remove_XSS($test); + + // Only for exercises not in a LP + if ($lp_id == 0) { + $message .= '

'.get_lang('ClickLinkToViewComment').'
#url#
'; + } + + $message .= '

'.get_lang('Regards').'

'; + $message .= $from_name; + $message = str_replace("#test#", Security::remove_XSS($test), $message); + $message = str_replace("#url#", $url, $message); + + return $message; + } }