Browse Source

When correcting an exercise email notification now is optional see #5439

Julio Montoya 12 years ago
parent
commit
bf9c016a39
2 changed files with 26 additions and 25 deletions
  1. 23 24
      main/exercice/exercise_report.php
  2. 3 1
      main/exercice/exercise_show.php

+ 23 - 24
main/exercice/exercise_report.php

@@ -110,17 +110,15 @@ if ($_REQUEST['comments'] == 'update' && ($is_allowedToEdit || $is_tutor) && $_G
     }
     $test              = $track_exercise_info['title'];
     $student_id        = $track_exercise_info['exe_user_id'];
-
     $session_id        = $track_exercise_info['session_id'];
     $lp_id             = $track_exercise_info['orig_lp_id'];
     //$lp_item_id        = $track_exercise_info['orig_lp_item_id'];
     $lp_item_view_id   = $track_exercise_info['orig_lp_item_view_id'];
+    
+    $course_info = api_get_course_info();
 
     // Teacher data
-    $teacher_info      = api_get_user_info(api_get_user_id());
-    $user_info         = api_get_user_info($student_id);
-    $student_email     = $user_info['mail'];
-    $from              = $teacher_info['mail'];
+    $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) . 'exercice/exercise_report.php?' . api_get_cidreq() . '&id_session='.$session_id.'&exerciseId='.$exercise_id;
@@ -159,7 +157,7 @@ if ($_REQUEST['comments'] == 'update' && ($is_allowedToEdit || $is_tutor) && $_G
         $result =Database::query($sql);
         Database::result($result,0,"question");
 
-        $query = "UPDATE $TBL_TRACK_ATTEMPT SET marks = '$my_marks',teacher_comment = '$my_comments' WHERE question_id = ".$my_questionid." AND exe_id=".$id;
+        $query = "UPDATE $TBL_TRACK_ATTEMPT SET marks = '$my_marks', teacher_comment = '$my_comments' WHERE question_id = ".$my_questionid." AND exe_id=".$id;
         Database::query($query);
 
         //Saving results in the track recording table
@@ -177,26 +175,27 @@ if ($_REQUEST['comments'] == 'update' && ($is_allowedToEdit || $is_tutor) && $_G
 
     $totquery = "UPDATE $TBL_TRACK_EXERCICES SET exe_result = '".floatval($tot)."' WHERE exe_id = ".$id;
     Database::query($totquery);
+    
+    if (isset($_POST['send_notification'])) {
+        //@todo move this somewhere else
+        $subject = get_lang('ExamSheetVCC');
+
+        $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') . ' <a href="#url#">#url#</a><br />';
+        }
 
-    //@todo move this somewhere else
-    $subject = get_lang('ExamSheetVCC');
-
-    $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') . ' <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);
+        MessageManager::send_message_simple($student_id, $subject, $message, api_get_user_id());
     }
-
-    $message .= '<p>'.get_lang('Regards').'</p>';
-    $message .= $from_name;
-
-    $message = str_replace("#test#", Security::remove_XSS($test), $message);
-    $message = str_replace("#url#", $url, $message);
-
-    @api_mail_html($student_email, $student_email, $subject, $message, $from_name, $from, array('charset'=>api_get_system_encoding()));
+    
 
     //Updating LP score here
     if (in_array($origin, array ('tracking_course','user_course','correct_exercise_in_lp'))) {

+ 3 - 1
main/exercice/exercise_show.php

@@ -655,8 +655,10 @@ if ($is_allowedToEdit && $locked == false && !api_is_drh()) {
 		echo ' <form name="myform" id="myform" action="exercise_report.php?exerciseId='.$exercise_id.'&filter=1&comments=update&exeid='.$id.'" method="post">';
 	}
 	if ($origin !='learnpath' && $origin!='student_progress') {
+        
+        echo '<label><input type= "checkbox" name="send_notification"> '.get_lang('SendEmail').'</label>';
 		?>
-		<button type="submit" class="save" value="<?php echo get_lang('Ok'); ?>" onclick="getFCK('<?php echo $strids; ?>','<?php echo $marksid; ?>');">
+		<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>