Browse Source

Add custom message notification see BT#12288

jmontoyaa 8 years ago
parent
commit
e01349fca6
3 changed files with 93 additions and 40 deletions
  1. 8 21
      main/exercise/exercise_report.php
  2. 48 19
      main/exercise/exercise_show.php
  3. 37 0
      main/inc/lib/exercise.lib.php

+ 8 - 21
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 = '<p>'.get_lang('DearStudentEmailIntroduction').'</p><p>'.get_lang('AttemptVCC');
-        $message .= '<h3>'.get_lang('CourseName').'</h3><p>'.Security::remove_XSS($course_info['name']).'';
-        $message .= '<h3>'.get_lang('Exercise').'</h3><p>'.Security::remove_XSS($test);
-
-        // Only for exercises not in a LP
-        if ($lp_id == 0) {
-            $message .= '<p>'.get_lang('ClickLinkToViewComment').' <br /><a href="#url#">#url#</a><br />';
-        }
+        $message = isset($_POST['notification_content']) ? $_POST['notification_content'] : '';
 
-        $message .= '<p>'.get_lang('Regards').'</p>';
-        $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,

+ 48 - 19
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 '<form name="myform" id="myform" action="' . $formUrl . '" method="post">';
-        echo '<input type = "hidden" name="lp_item_id"       value="' . $learnpath_id . '">';
-        echo '<input type = "hidden" name="lp_item_view_id"  value="' . $lp_item_view_id . '">';
-        echo '<input type = "hidden" name="student_id"       value="' . $student_id . '">';
-        echo '<input type = "hidden" name="total_score"      value="' . $totalScore . '"> ';
-        echo '<input type = "hidden" name="my_exe_exo_id"    value="' . $exercise_id . '"> ';
+        $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 ' <form name="myform" id="myform" action="' . $formUrl . '" method="post">';
+        $emailForm = new FormValidator('myform', 'post', $formUrl, '', ['id' => 'myform']);
     }
 
-    if ($origin != 'learnpath' && $origin != 'student_progress') {
-        echo '<label><input type= "checkbox" name="send_notification"> ' . get_lang('SendEmail') . '</label>';
-        ?>
-        <br/>
-        <button type="submit" class="btn btn-primary" value="<?php echo get_lang('Ok'); ?>"
-                onclick="getFCK('<?php echo $strids; ?>','<?php echo $marksid; ?>');">
-            <?php echo get_lang('CorrectTest'); ?>
-        </button>
-        </form>
-        <?php
-    }
+    $emailForm->addCheckBox(
+        'send_notification',
+        get_lang('SendEmail'),
+        get_lang('SendEmail'),
+        ['onclick' => 'openEmailWrapper();']
+    );
+    $emailForm->addHtml('<span id="email_content_wrapper" style="display:none">');
+    $emailForm->addHtmlEditor(
+        'notification_content',
+        get_lang('Content'),
+        false
+    );
+    $emailForm->addHtml('</span>');
+
+    $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

+ 37 - 0
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 = '<p>'.get_lang('DearStudentEmailIntroduction').'</p><p>'.get_lang('AttemptVCC');
+        $message .= '<h3>'.get_lang('CourseName').'</h3><p>'.Security::remove_XSS($course_info['name']).'';
+        $message .= '<h3>'.get_lang('Exercise').'</h3><p>'.Security::remove_XSS($test);
+
+        // Only for exercises not in a LP
+        if ($lp_id == 0) {
+            $message .= '<p>'.get_lang('ClickLinkToViewComment').' <br /><a href="#url#">#url#</a><br />';
+        }
+
+        $message .= '<p>'.get_lang('Regards').'</p>';
+        $message .= $from_name;
+        $message = str_replace("#test#", Security::remove_XSS($test), $message);
+        $message = str_replace("#url#", $url, $message);
+
+        return $message;
+    }
 }