From 69bb1657857d835e111d50db6f789743740270c4 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Thu, 7 Jan 2010 12:37:22 -0500 Subject: [PATCH] Send email when student answer an exercise --- main/exercice/exercise_result.php | 170 ++++++++++++++++++------------ main/exercice/exercise_show.php | 166 ++++++++++++++++++++++++++++- 2 files changed, 267 insertions(+), 69 deletions(-) diff --git a/main/exercice/exercise_result.php b/main/exercice/exercise_result.php index 8d899fb0c0..0ffbff6228 100644 --- a/main/exercice/exercise_result.php +++ b/main/exercice/exercise_result.php @@ -126,11 +126,13 @@ if($_configuration['live_exercise_tracking']) define('ENABLED_LIVE_EXERCISE_TRAC if($_configuration['live_exercise_tracking'] == true && $exerciseType == 1){ $_configuration['live_exercise_tracking'] = false; } +$arrques = array(); +$arrans = array(); // set admin name as person who sends the results e-mail (lacks policy about whom should really send the results) $main_user_table = Database :: get_main_table(TABLE_MAIN_USER); $main_admin_table = Database :: get_main_table(TABLE_MAIN_ADMIN); -$courseName = $_SESSION['_course']['name']; + $query = "SELECT user_id FROM $main_admin_table LIMIT 1"; //get all admins from admin table $admin_id = Database::result(Database::query($query),0,"user_id"); $uinfo = api_get_user_info($admin_id); @@ -859,36 +861,8 @@ foreach ($questionList as $questionId) { $arrques[] = $questionName; $arrans[] = $choice; - $firstName = $_SESSION['_user']['firstName']; - $lastName = $_SESSION['_user']['lastName']; - $mail = $_SESSION['_user']['mail']; - $coursecode = $_SESSION['_course']['id']; - $to = ''; - $teachers = array(); - if(api_get_setting('use_session_mode')=='true' && !empty($_SESSION['id_session'])) - { - $teachers = CourseManager::get_coach_list_from_course_code($coursecode,$_SESSION['id_session']); - } - else - { - $teachers = CourseManager::get_teacher_list_from_course_code($coursecode); - } - $num = count($teachers); - if($num>1) - { - $to = array(); - foreach($teachers as $teacher) - { - $to[] = $teacher['email']; - } - }elseif($num>0){ - foreach($teachers as $teacher) - { - $to = $teacher['email']; - } - }else{ - //this is a problem (it means that there is no admin for this course) - } + + if($origin != 'learnpath') { display_free_answer($choice); } @@ -1091,6 +1065,44 @@ if ($origin != 'learnpath') { echo ''; } + + +// Email configuration settings +require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php'; +$user_info = UserManager::get_user_info_by_id(api_get_user_id()); + +$firstName = $user_info['firstname']; +$lastName = $user_info['lastname']; +$mail = $user_info['email']; +$coursecode = api_get_course_id(); +$courseName = $_SESSION['_course']['name']; + +$to = ''; +$teachers = array(); +if(api_get_setting('use_session_mode')=='true' && !empty($_SESSION['id_session'])) { + $teachers = CourseManager::get_coach_list_from_course_code($coursecode,$_SESSION['id_session']); +} else { + $teachers = CourseManager::get_teacher_list_from_course_code($coursecode); +} + +$num = count($teachers); +if($num>1) { + $to = array(); + foreach($teachers as $teacher) { + $to[] = $teacher['email']; + } +}elseif($num>0){ + foreach($teachers as $teacher) { + $to = $teacher['email']; + } +} else { + //this is a problem (it means that there is no admin for this course) +} + + +//------ +if ($origin != 'learnpath') + if(count($arrques)>0) { $mycharset = api_get_setting('platform_charset'); $msg = ' @@ -1100,7 +1112,7 @@ if(count($arrques)>0) {

'.get_lang('OpenQuestionsAttempted').' :

-

'.get_lang('AttemptDetails').' : >
+

'.get_lang('AttemptDetails').' :

@@ -1121,6 +1133,7 @@ if(count($arrques)>0) {


'.get_lang('OpenQuestionsAttemptedAre').' :

'; + for($i=0;$i '; - $msg1= str_replace("#exercise#",$exerciseTitle,$msg); $msg= str_replace("#firstName#",$firstName,$msg1); $msg1= str_replace("#lastName#",$lastName,$msg); @@ -1141,46 +1153,68 @@ if(count($arrques)>0) { $msg1= str_replace("#i#",$i,$msg); $msg= str_replace("#course#",$courseName,$msg1); } - $msg.='
#answer#

- '.get_lang('ClickToCommentAndGiveFeedback').',
- #url#
'; - - $msg1= str_replace("#url#",$url,$msg); - $mail_content = $msg1; - $student_name = api_get_person_name($_SESSION['_user']['firstName'], $_SESSION['_user']['lastName']); - $subject = get_lang('OpenQuestionsAttempted'); - - /*$from = api_get_setting('noreply_email_address'); - if($from == '') { - if(isset($_SESSION['id_session']) && $_SESSION['id_session'] != ''){ - $sql = 'SELECT user.email,user.lastname,user.firstname FROM '.TABLE_MAIN_SESSION.' as session, '.TABLE_MAIN_USER.' as user - WHERE session.id_coach = user.user_id - AND session.id = "'.Database::escape_string($_SESSION['id_session']).'" - '; - $result=Database::query($sql,__FILE__,__LINE__); - $from = Database::result($result,0,'email'); - $from_name = api_get_person_name(Database::result($result,0,'firstname'), Database::result($result,0,'lastname'), null, PERSON_NAME_EMAIL_ADDRESS); - } else { - $array = explode(' ',$_SESSION['_course']['titular']); - $firstname = $array[1]; - $lastname = $array[0]; - $sql = 'SELECT email,lastname,firstname FROM '.TABLE_MAIN_USER.' - WHERE firstname = "'.Database::escape_string($firstname).'" - AND lastname = "'.Database::escape_string($lastname).'" - '; - $result=Database::query($sql,__FILE__,__LINE__); - $from = Database::result($result,0,'email'); - $from_name = api_get_person_name(Database::result($result,0,'firstname'), Database::result($result,0,'lastname'), null, PERSON_NAME_EMAIL_ADDRESS); - } - } - api_mail_html($student_name, $to, $subject, $mail_content, $from_name, $from, array('encoding'=>$mycharset,'charset'=>$mycharset)); - */ + + $msg.='
+ '.get_lang('ClickToCommentAndGiveFeedback').',
+ #url#
'; + + $msg1= str_replace("#url#",$url,$msg); + $mail_content = $msg1; $sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS); $email_admin = api_get_setting('emailAdministrator'); $subject = get_lang('OpenQuestionsAttempted'); - $result = api_mail_html('', $to, $subject, $mail_content, $sender_name, $email_admin, array('charset'=>$mycharset)); + if (api_get_course_setting('email_alert_manager_on_new_quiz') == 1 ) { + $result = api_mail_html('', $to, $subject, $mail_content, $sender_name, $email_admin, array('charset'=>$mycharset)); + } +} else { + $mycharset = api_get_setting('platform_charset'); + $msg = ' + + '; + $msg .= ' + + + + + + + + + + + + + '.(api_is_western_name_order() ? '' : '').' + + + + +

  '.get_lang('CourseName').'

#course#

  '.get_lang('TestAttempted').'#exercise#
  '.get_lang('StudentName').'#firstName# #lastName##lastName# #firstName#
  '.get_lang('StudentEmail').' #mail#
'; + + $msg= str_replace("#exercise#",$exerciseTitle,$msg); + $msg= str_replace("#firstName#",$firstName,$msg); + $msg= str_replace("#lastName#",$lastName,$msg); + $msg= str_replace("#mail#",$mail,$msg); + $msg= str_replace("#course#",$courseName,$msg); + + $msg.='
+ '.get_lang('ClickToCommentAndGiveFeedback').',
+ #url#
'; + + + $msg= str_replace("#url#",$url,$msg); + $mail_content = $msg; + + $sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS); + $email_admin = api_get_setting('emailAdministrator'); + + $subject = get_lang('ExerciseAttempted'); + if (api_get_course_setting('email_alert_manager_on_new_quiz') == 1 ) { + $result = api_mail_html('', $to, $subject, $mail_content, $sender_name, $email_admin, array('charset'=>$mycharset)); + } } + ?> diff --git a/main/exercice/exercise_show.php b/main/exercice/exercise_show.php index abc5a217e9..7ddebc3fc2 100644 --- a/main/exercice/exercise_show.php +++ b/main/exercice/exercise_show.php @@ -400,6 +400,34 @@ function display_hotspot_answer($answerId, $answer, $studentChoice, $answerComme ============================================================================== */ +// Email configuration settings + +$coursecode = api_get_course_id(); +$courseName = $_SESSION['_course']['name']; + +$to = ''; +$teachers = array(); +if(api_get_setting('use_session_mode')=='true' && !empty($_SESSION['id_session'])) { + $teachers = CourseManager::get_coach_list_from_course_code($coursecode,$_SESSION['id_session']); +} else { + $teachers = CourseManager::get_teacher_list_from_course_code($coursecode); +} + +$num = count($teachers); +if($num>1) { + $to = array(); + foreach($teachers as $teacher) { + $to[] = $teacher['email']; + } +} elseif ($num>0){ + foreach($teachers as $teacher) { + $to = $teacher['email']; + } +} else { + //this is a problem (it means that there is no admin for this course) +} + + ?> @@ -502,6 +530,8 @@ if ($show_results == true ) { $i=$totalScore=$totalWeighting=0; if($debug>0){echo "ExerciseResult: "; var_dump($exerciseResult); echo "QuestionList: ";var_dump($questionList);} +$arrques = array(); +$arrans = array(); if ($show_results) { $questionList = array(); @@ -826,6 +856,10 @@ if ($show_results) { } else { $totalScore+=$questionScore; } + + $arrques[] = $questionName; + $arrans[] = $choice; + echo ' @@ -1101,10 +1135,13 @@ if ($origin=='student_progress') {?> } if ($origin != 'learnpath') { + $url_email = api_get_path(WEB_CODE_PATH).'exercice/exercice.php?'.api_get_cidreq().'&show=result'; + //we are not in learnpath tool Display::display_footer(); } else { - + $url_email = api_get_path(WEB_CODE_PATH).'mySpace/lp_tracking.php?course='.api_get_course_id().'&origin=tracking_course&lp_id='.$learnpath_id.'&student_id='.api_get_user_id(); + if (!isset($_GET['fb_type'])) { $lp_mode = $_SESSION['lp_mode']; $url = '../newscorm/lp_controller.php?cidReq='.api_get_course_id().'&action=view&lp_id='.$learnpath_id.'&lp_item_id='.$learnpath_item_id.'&exeId='.$exeId.'&fb_type='.$feedback_type; @@ -1115,12 +1152,139 @@ if ($origin != 'learnpath') { echo ''."\n"; echo ''; } else { + if (!$is_allowedToEdit) { + send_notification($arrques, $arrans, $to); + } Display::display_normal_message(get_lang('ExerciseFinished').' '.get_lang('ToContinueUseMenu')); + } +} + +if (!$is_allowedToEdit) { + if ($origin != 'learnpath') { + send_notification($arrques, $arrans, $to); } } + //destroying the session api_session_unregister('questionList'); unset ($questionList); api_session_unregister('exerciseResult'); unset ($exerciseResult); + +function send_notification($arrques, $arrans, $to) { + global $courseName, $exerciseTitle, $url_email; + + if (api_get_course_setting('email_alert_manager_on_new_quiz') != 1 ) { + return ''; + } + + require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php'; + require_once(api_get_path(LIBRARY_PATH).'mail.lib.inc.php'); + $user_info = UserManager::get_user_info_by_id(api_get_user_id()); + + $mycharset = api_get_setting('platform_charset'); + $msg = ' + + '; + if(count($arrques)>0) { + $msg .= ' +

'.get_lang('OpenQuestionsAttempted').' : +

+

'.get_lang('AttemptDetails').' :
+

+
'.display_free_answer($choice, $id, $questionId).'
+ + + + + + + + + + + + + + + +

  '.get_lang('CourseName').'

#course#

  '.get_lang('TestAttempted').'#exercise#
  '.get_lang('StudentName').'#firstName# #lastName#
  '.get_lang('StudentEmail').' #mail#
+


'.get_lang('OpenQuestionsAttemptedAre').' :

+ '; + + for($i=0;$i + + + + + + '; + + $msg1= str_replace("#exercise#",$exerciseTitle,$msg); + $msg= str_replace("#firstName#",$user_info['firstname'],$msg1); + $msg1= str_replace("#lastName#",$user_info['lastname'],$msg); + $msg= str_replace("#mail#",$user_info['email'],$msg1); + $msg1= str_replace("#questionName#",$arrques[$i],$msg); + $msg= str_replace("#answer#",$arrans[$i],$msg1); + $msg1= str_replace("#i#",$i,$msg); + $msg= str_replace("#course#",$courseName,$msg1); + } + $msg.='
#questionName#
  '.get_lang('Answer').' #answer#

+ '.get_lang('ClickToCommentAndGiveFeedback').',
+ #url#
'; + + $msg1= str_replace("#url#",$url_email,$msg); + $mail_content = $msg1; + + $subject = get_lang('OpenQuestionsAttempted'); + + + $sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS); + $email_admin = api_get_setting('emailAdministrator'); + + $result = api_mail_html('', $to, $subject, $mail_content, $sender_name, $email_admin, array('charset'=>$mycharset)); + } else { + + $msg .= ' + + + + + + + + + + + + '.(api_is_western_name_order() ? '' : '').' + + + + +

  '.get_lang('CourseName').'

#course#

  '.get_lang('TestAttempted').'#exercise#
  '.get_lang('StudentName').'#firstName# #lastName##lastName# #firstName#
  '.get_lang('StudentEmail').' #mail#
'; + + $msg= str_replace("#exercise#",$exerciseTitle,$msg); + $msg= str_replace("#firstName#",$user_info['firstname'],$msg); + $msg= str_replace("#lastName#",$user_info['lastname'],$msg); + $msg= str_replace("#mail#",$user_info['email'],$msg); + $msg= str_replace("#course#",$courseName,$msg); + + $msg.='
+ '.get_lang('ClickToCommentAndGiveFeedback').',
+ #url#
'; + + $msg= str_replace("#url#",$url_email,$msg); + $mail_content = $msg; + + $sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS); + $email_admin = api_get_setting('emailAdministrator'); + + $subject = get_lang('ExerciseAttempted'); + $result = api_mail_html('', $to, $subject, $mail_content, $sender_name, $email_admin, array('charset'=>$mycharset)); + } +} \ No newline at end of file