Browse Source

Merge branch 'yoselyn.6909' of github.com:ycastillo/chamilo-lms into ycastillo-yoselyn.6909

Yannick Warnier 11 years ago
parent
commit
6b120389f5
2 changed files with 72 additions and 3 deletions
  1. 69 3
      main/exercice/exercise.class.php
  2. 3 0
      main/exercice/exercise.lib.php

+ 69 - 3
main/exercice/exercise.class.php

@@ -3351,6 +3351,72 @@ class Exercise {
         );
         return $return_array;
     }
+    /**
+     * Sends a notification when a user ends an examn
+     *
+     */
+    function send_mail_notification_for_exam($question_list_answers, $origin, $exe_id) {
+        if (api_get_course_setting('email_alert_manager_on_new_quiz') != 1 ) {
+            return null;
+        }
+        // Email configuration settings
+        $courseCode     = api_get_course_id();
+        $courseInfo    = api_get_course_info($courseCode);
+
+        $url_email = api_get_path(WEB_CODE_PATH).'exercice/exercise_show.php?'.api_get_cidreq().'&id_session='.api_get_session_id().'&id='.$exe_id.'&action=qualify';
+        $user_info = UserManager::get_user_info_by_id(api_get_user_id());
+
+        $msg = '<p>'.get_lang('ExerciseAttempted').' :</p>
+                    <p>'.get_lang('AttemptDetails').' : </p>
+                    <table class="data_table">
+                        <tr>
+                            <td><h3>'.get_lang('CourseName').'</h3></td>
+                            <td><h3>#course#</h3></td>
+                        </tr>
+                        <tr>
+                            <td>'.get_lang('TestAttempted').'</span></td>
+                            <td>#exercise#</td>
+                        </tr>
+                        <tr>
+                            <td>'.get_lang('StudentName').'</td>
+                            <td>#firstName# #lastName#</td>
+                        </tr>
+                        <tr>
+                            <td>'.get_lang('StudentEmail').'</td>
+                            <td>#email#</td>
+                        </tr>
+                    </table>';
+        $open_question_list = null;
+        
+        $msg    = str_replace("#email#",       $user_info['email'],$msg);       
+        $msg1   = str_replace("#exercise#",    $this->exercise, $msg);
+        $msg    = str_replace("#firstName#",   $user_info['firstname'],$msg1);
+        $msg1   = str_replace("#lastName#",    $user_info['lastname'],$msg);
+        
+        $msg    = str_replace("#course#",      $courseInfo['name'],$msg1);
+
+        if ($origin != 'learnpath') {
+            $msg.= get_lang('ClickToCommentAndGiveFeedback').', <br />
+                        <a href="#url#">#url#</a>';
+        }
+        $msg1 = str_replace("#url#", $url_email, $msg);
+        $mail_content = $msg1;
+        $subject = get_lang('ExerciseAttempted');
+         
+        $teachers = array();
+        if (api_get_session_id()) {
+            $teachers = CourseManager::get_coach_list_from_course_code($coursecode, api_get_session_id());
+        } else {
+            $teachers = CourseManager::get_teacher_list_from_course_code($coursecode);
+        }
+         
+        if (!empty($teachers)) {
+            foreach ($teachers as $user_id => $teacher_data) {
+                MessageManager::send_message_simple($user_id, $subject, $mail_content);
+            }
+        }
+        
+    }
 
     /**
      * Sends a notification when a user ends an examn
@@ -3406,10 +3472,10 @@ class Exercise {
         }
 
         if (!empty($open_question_list)) {
-            $msg .=  '<p><br />'.get_lang('OpenQuestionsAttemptedAre').' :</p>
+            $msg .= '<p><br />'.get_lang('OpenQuestionsAttemptedAre').' :</p>
                     <table width="730" height="136" border="0" cellpadding="3" cellspacing="3">';
             $msg .= $open_question_list;
-            $msg.='</table><br />';
+            $msg .= '</table><br />';
 
 
             $msg1   = str_replace("#exercise#",    $this->exercise, $msg);
@@ -3419,7 +3485,7 @@ class Exercise {
             $msg    = str_replace("#course#",      $course_info['name'],$msg1);
 
             if ($origin != 'learnpath') {
-                $msg.= get_lang('ClickToCommentAndGiveFeedback').', <br />
+                $msg .= get_lang('ClickToCommentAndGiveFeedback').', <br />
                             <a href="#url#">#url#</a>';
             }
             $msg1 = str_replace("#url#", $url_email, $msg);

+ 3 - 0
main/exercice/exercise.lib.php

@@ -2404,6 +2404,9 @@ function display_question_list_by_attempt($objExercise, $exe_id, $save_user_resu
 
         // Send notification ..
         if (!api_is_allowed_to_edit(null,true)) {
+            if (api_get_course_setting('email_alert_manager_on_new_quiz') == 1 ) {
+                $objExercise->send_mail_notification_for_exam($question_list_answers, $origin, $exe_id);
+            }
             $objExercise->send_notification_for_open_questions($question_list_answers, $origin, $exe_id);
             $objExercise->send_notification_for_oral_questions($question_list_answers, $origin, $exe_id);
         }