diff --git a/main/exercice/exercice_submit.php b/main/exercice/exercice_submit.php index f074d6a13e..2015f09694 100755 --- a/main/exercice/exercice_submit.php +++ b/main/exercice/exercice_submit.php @@ -25,6 +25,8 @@ require_once 'question.class.php'; require_once 'answer.class.php'; require_once 'exercise.lib.php'; + + // debug var. Set to 0 to hide all debug display. Set to 1 to display debug messages. $debug = 1; @@ -32,6 +34,7 @@ $debug = 1; $language_file = 'exercice'; require_once '../inc/global.inc.php'; + $this_section = SECTION_COURSES; // Notice for unauthorized people. @@ -323,7 +326,7 @@ if ($_configuration['live_exercise_tracking'] && $objExercise->type == ONE_PER_P // if the user has submitted the form -if ($formSent) { +if ($formSent && isset($_POST)) { if ($debug > 0) { error_log('$formSent was set'); } // Initializing @@ -371,7 +374,7 @@ if ($formSent) { $choice = $exerciseResult[$questionId]; if (isset($exe_id)) { //Manage the question and answer attempts - $objExercise->manage_answer($exe_id, $questionId, $choice,'exercise_show'); + $objExercise->manage_answer($exe_id, $questionId, $choice,'exercise_show', true, false,false); } //END of saving and qualifying } diff --git a/main/exercice/exercise.class.php b/main/exercice/exercise.class.php index 1ac46e1990..3029d138d1 100755 --- a/main/exercice/exercise.class.php +++ b/main/exercice/exercise.class.php @@ -16,6 +16,8 @@ define('EXERCISE_FEEDBACK_TYPE_END',0); define('EXERCISE_FEEDBACK_TYPE_DIRECT',1); define('EXERCISE_FEEDBACK_TYPE_EXAM',2); +require_once '../inc/lib/exercise_show_functions.lib.php'; + if(!class_exists('Exercise')): class Exercise { @@ -1638,9 +1640,13 @@ class Exercise { * @param int the choice the user selected * @param string function is called from 'exercise_show' or 'exercise_result' */ - function manage_answer($exeId, $questionId, $choice, $from = 'exercise_show') { + function manage_answer($exeId, $questionId, $choice, $from = 'exercise_show', $saved_results = true, $from_database = false, $show_result = true) { global $_configuration; - $exeId = intval($exeId); + + $exeId = intval($exeId); + $TBL_TRACK_ATTEMPT = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); + $table_ans = Database::get_course_table(TABLE_QUIZ_ANSWER); + // Creates a temporary Question object $objQuestionTmp = Question :: read($questionId); @@ -1649,7 +1655,8 @@ class Exercise { $questionDescription = $objQuestionTmp->selectDescription(); $questionWeighting = $objQuestionTmp->selectWeighting(); $answerType = $objQuestionTmp->selectType(); - $quesId = $objQuestionTmp->selectId(); //added by priya saini + $quesId = $objQuestionTmp->selectId(); + $totalWeighting = 0; $totalScore = 0; @@ -1668,7 +1675,7 @@ class Exercise { $nbrAnswers = 1; } $user_answer = ''; - $table_ans = Database::get_course_table(TABLE_QUIZ_ANSWER); + // Get answer list for matching $sql_answer = 'SELECT id, answer FROM '.$table_ans.' WHERE question_id="'.Database::escape_string($questionId).'" '; @@ -1679,48 +1686,108 @@ class Exercise { } $real_answers = array(); + + for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) { - $answer = $objAnswerTmp->selectAnswer($answerId); - $answerComment = $objAnswerTmp->selectComment($answerId); - $answerCorrect = $objAnswerTmp->isCorrect($answerId); - $answerWeighting = $objAnswerTmp->selectWeighting($answerId); - $numAnswer=$objAnswerTmp->selectAutoId($answerId); + $answer = $objAnswerTmp->selectAnswer($answerId); + $answerComment = $objAnswerTmp->selectComment($answerId); + $answerCorrect = $objAnswerTmp->isCorrect($answerId); + $answerWeighting = $objAnswerTmp->selectWeighting($answerId); + $numAnswer = $objAnswerTmp->selectAutoId($answerId); + switch ($answerType) { // for unique answer case UNIQUE_ANSWER : - $studentChoice=($choice == $numAnswer)?1:0; - if ($studentChoice) { - $questionScore+=$answerWeighting; - $totalScore+=$answerWeighting; - } + if ($from_database) { + $queryans = "select answer from ".$TBL_TRACK_ATTEMPT." where exe_id = '".$exeId."' and question_id= '".$questionId."'"; + $resultans = Database::query($queryans); + $choice = Database::result($resultans,0,"answer"); + + $numAnswer=$objAnswerTmp->selectAutoId($answerId); + + $studentChoice=($choice == $numAnswer)?1:0; + if ($studentChoice) { + $questionScore+=$answerWeighting; + $totalScore+=$answerWeighting; + } + } else { + $studentChoice=($choice == $numAnswer)?1:0; + if ($studentChoice) { + $questionScore+=$answerWeighting; + $totalScore+=$answerWeighting; + } + } break; // for multiple answers - case MULTIPLE_ANSWER : - $studentChoice=$choice[$numAnswer]; - if ($studentChoice) { - $questionScore+=$answerWeighting; - $totalScore+=$answerWeighting; - } - break; - case MULTIPLE_ANSWER_COMBINATION: - $studentChoice=$choice[$numAnswer]; - if ($answerCorrect == 1) { + case MULTIPLE_ANSWER : + if ($from_database) { + $choice=array(); + $queryans = "SELECT * FROM ".$TBL_TRACK_ATTEMPT." where exe_id = '".$exeId."' and question_id= '".$questionId."'"; + $resultans = Database::query($queryans); + while ($row = Database::fetch_array($resultans)) { + $ind = $row['answer']; + $choice[$ind] = 1; + } + + $numAnswer=$objAnswerTmp->selectAutoId($answerId); + $studentChoice=$choice[$numAnswer]; if ($studentChoice) { - $real_answers[$answerId] = true; - } else { - $real_answers[$answerId] = false; + $questionScore+=$answerWeighting; + $totalScore+=$answerWeighting; } - } else { + } else { + $studentChoice=$choice[$numAnswer]; if ($studentChoice) { - $real_answers[$answerId] = false; + $questionScore+=$answerWeighting; + $totalScore+=$answerWeighting; + } + } + break; + case MULTIPLE_ANSWER_COMBINATION: + if ($from_database) { + + $queryans = "SELECT * from ".$TBL_TRACK_ATTEMPT." where exe_id = '".$exeId."' and question_id= '".$questionId."'"; + $resultans = Database::query($queryans); + while ($row = Database::fetch_array($resultans)) { + $ind = $row['answer']; + $choice[$ind] = 1; + } + $numAnswer=$objAnswerTmp->selectAutoId($answerId); + $studentChoice=$choice[$numAnswer]; + + if ($answerCorrect == 1) { + if ($studentChoice) { + $real_answers[$answerId] = true; + } else { + $real_answers[$answerId] = false; + } } else { - $real_answers[$answerId] = true; + if ($studentChoice) { + $real_answers[$answerId] = false; + } else { + $real_answers[$answerId] = true; + } + } + } else { + $studentChoice=$choice[$numAnswer]; + if ($answerCorrect == 1) { + if ($studentChoice) { + $real_answers[$answerId] = true; + } else { + $real_answers[$answerId] = false; + } + } else { + if ($studentChoice) { + $real_answers[$answerId] = false; + } else { + $real_answers[$answerId] = true; + } } - } - $final_answer = true; - foreach($real_answers as $my_answer) { - if (!$my_answer) { - $final_answer = false; + $final_answer = true; + foreach($real_answers as $my_answer) { + if (!$my_answer) { + $final_answer = false; + } } } break; @@ -1731,24 +1798,19 @@ class Exercise { // number 1 before the "@" means that is a switchable fill in blank question // [A] B [C] D [E] F::10,10,10@ or [A] B [C] D [E] F::10,10,10 // means that is a normal fill blank question - // first we explode the "::" $pre_array = explode('::', $answer); - // is switchable fill blank or not $last = count($pre_array) - 1; $is_set_switchable = explode('@', $pre_array[$last]); - $switchable_answer_set = false; if (isset ($is_set_switchable[1]) && $is_set_switchable[1] == 1) { $switchable_answer_set = true; } - $answer = ''; for ($k = 0; $k < $last; $k++) { $answer .= $pre_array[$k]; } - // splits weightings that are joined with a comma $answerWeighting = explode(',', $is_set_switchable[0]); @@ -1770,7 +1832,6 @@ class Exercise { */ $answer = ''; $j = 0; - //initialise answer tags $user_tags = array (); $correct_tags = array (); @@ -1800,8 +1861,26 @@ class Exercise { // adds the end of the text $answer .= $temp; break; - } - $choice[$j] = trim($choice[$j]); + } + if ($from_database) { + $queryfill = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT." WHERE exe_id = '".Database::escape_string($exeId)."' AND question_id= '".Database::escape_string($questionId)."'"; + $resfill = Database::query($queryfill); + $str = Database::result($resfill,0,'answer'); + + preg_match_all('#\[([^[]*)\]#', $str, $arr); + $str = str_replace('\r\n', '', $str); + $choice = $arr[1]; + + $tmp=strrpos($choice[$j],' / '); + $choice[$j]=api_substr($choice[$j],0,$tmp); + $choice[$j]=trim($choice[$j]); + + //Needed to let characters ' and " to work as part of an answer + $choice[$j] = stripslashes($choice[$j]); + } else { + $choice[$j] = trim($choice[$j]); + } + $user_tags[] = api_strtolower($choice[$j]); //put the contents of the [] answer tag into correct_tags[] $correct_tags[] = api_strtolower(api_substr($temp, 0, $pos)); @@ -1809,7 +1888,6 @@ class Exercise { $temp = api_substr($temp, $pos +1); //$answer .= ']'; } - $answer = ''; $real_correct_tags = $correct_tags; $chosen_list = array (); @@ -1818,7 +1896,6 @@ class Exercise { if ($i == 0) { $answer .= $real_text[0]; } - if (!$switchable_answer_set) { //needed to parse ' and " characters $user_tags[$i] = stripslashes($user_tags[$i]); @@ -1866,43 +1943,129 @@ class Exercise { $answer .= $real_text[$i +1]; } } - break; // for free answer case FREE_ANSWER : - $studentChoice = $choice; - if ($studentChoice) { - //Score is at -1 because the question has'nt been corected - $questionScore = -1; - $totalScore += 0; - } - break; - // for matching - case MATCHING : - $numAnswer=$objAnswerTmp->selectAutoId($answerId); - if ($answerCorrect) { - if ($answerCorrect == $choice[$numAnswer]) { - $questionScore+=$answerWeighting; - $totalScore+=$answerWeighting; - $user_answer = ''.$answer_matching[$choice[$numAnswer]].''; + if ($from_database) { + $query = "SELECT answer, marks FROM ".$TBL_TRACK_ATTEMPT." WHERE exe_id = '".Database::escape_string($exeId)."' AND question_id= '".Database::escape_string($questionId)."'"; + $resq = Database::query($query); + $choice = Database::result($resq,0,'answer'); + $choice = str_replace('\r\n', '', $choice); + $choice = stripslashes($choice); + + $questionScore = Database::result($resq,0,"marks"); + if ($questionScore==-1) { + $totalScore+=0; } else { - $user_answer = ''.$answer_matching[$choice[$numAnswer]].''; - } - $matching[$numAnswer] = $choice[$numAnswer]; + $totalScore+=$questionScore; + } + $arrques[] = $questionName; + $arrans[] = $choice; + } else { + $studentChoice = $choice; + if ($studentChoice) { + //@todo verify this--> set to -1 because the question has'nt been corrected + $questionScore = -1; + $totalScore += 0; + } } break; + // for matching + case MATCHING : + if ($from_database) { + $sql_answer = 'SELECT id, answer FROM '.$table_ans.' WHERE question_id="'.Database::escape_string($questionId).'" AND correct=0'; + $res_answer = Database::query($sql_answer); + // getting the real answer + $real_list =array(); + while ($real_answer = Database::fetch_array($res_answer)) { + $real_list[$real_answer['id']]= $real_answer['answer']; + } + + $sql_select_answer = 'SELECT id, answer, correct, id_auto FROM '.$table_ans.' + WHERE question_id="'.Database::escape_string($questionId).'" AND correct <> 0 ORDER BY id_auto'; + + $res_answers = Database::query($sql_select_answer); + if ($show_result) { + echo ''; + echo ''; + echo ' + + + '; + echo ''; + } + $questionScore = 0; + + while ($a_answers = Database::fetch_array($res_answers)) { + $i_answer_id = $a_answers['id']; //3 + $s_answer_label = $a_answers['answer']; // your daddy - your mother + $i_answer_correct_answer = $a_answers['correct']; //1 - 2 + $i_answer_id_auto = $a_answers['id_auto']; // 3 - 4 + + $sql_user_answer = "SELECT answer FROM $TBL_TRACK_ATTEMPT + WHERE exe_id = '$exeId' AND question_id = '$questionId' AND position='$i_answer_id_auto'"; + + $res_user_answer = Database::query($sql_user_answer); + + if (Database::num_rows($res_user_answer)>0 ) { + $s_user_answer = Database::result($res_user_answer,0,0); // rich - good looking + } else { + $s_user_answer = 0; + } + $i_answerWeighting=$objAnswerTmp->selectWeighting($i_answer_id); + $user_answer = ''; + if (!empty($s_user_answer)) { + if ($s_user_answer == $i_answer_correct_answer) { + $questionScore += $i_answerWeighting; + $totalScore += $i_answerWeighting; + $user_answer = ''.$real_list[$i_answer_correct_answer].''; + } else { + $user_answer = ''.$real_list[$s_user_answer].''; + } + } + if ($show_result) { + echo ''; + echo ''; + echo ''; + } + } + break(2); //break the switch and the for condition + } else { + $numAnswer=$objAnswerTmp->selectAutoId($answerId); + if ($answerCorrect) { + if ($answerCorrect == $choice[$numAnswer]) { + $questionScore+=$answerWeighting; + $totalScore+=$answerWeighting; + $user_answer = ''.$answer_matching[$choice[$numAnswer]].''; + } else { + $user_answer = ''.$answer_matching[$choice[$numAnswer]].''; + } + $matching[$numAnswer] = $choice[$numAnswer]; + } + break; + } + // for hotspot with no order case HOT_SPOT : - $studentChoice = $choice[$answerId]; - if ($studentChoice) { - $questionScore += $answerWeighting; - $totalScore += $answerWeighting; + if ($from_database) { + if ($show_result) { + $TBL_TRACK_HOTSPOT = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTSPOT); + $query = "select hotspot_correct from ".$TBL_TRACK_HOTSPOT." where hotspot_exe_id = '".Database::escape_string($exeId)."' and hotspot_question_id= '".Database::escape_string($questionId)."' AND hotspot_answer_id='".Database::escape_string($answerId)."'"; + $resq=Database::query($query); + $studentChoice = Database::result($resq,0,"hotspot_correct"); + } + } else { + $studentChoice = $choice[$answerId]; + if ($studentChoice) { + $questionScore += $answerWeighting; + $totalScore += $answerWeighting; + } } break; - // for hotspot with fixed order + // @todo never added to chamilo + //for hotspot with fixed order case HOT_SPOT_ORDER : $studentChoice = $choice['order'][$answerId]; - if ($studentChoice == $answerId) { $questionScore += $answerWeighting; $totalScore += $answerWeighting; @@ -1911,12 +2074,83 @@ class Exercise { $studentChoice = false; } break; - } // end switch Answertype + } // end switch Answertype - if ($from == 'exercise_result') { - global $origin; + global $origin; + + if ($show_result) { + if ($from == 'exercise_result') { + //display answers (if not matching type, or if the answer is correct) + if ($answerType != MATCHING || $answerCorrect) { + if ($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER || $answerType == MULTIPLE_ANSWER_COMBINATION) { + if ($origin!='learnpath') { + ExerciseShowFunctions::display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,0,0,0); + } + } elseif($answerType == FILL_IN_BLANKS) { + if ($origin!='learnpath') { + ExerciseShowFunctions::display_fill_in_blanks_answer($answer,0,0); + } + } elseif($answerType == FREE_ANSWER) { + // to store the details of open questions in an array to be used in mail + $arrques[] = $questionName; + $arrans[] = $choice; + if($origin != 'learnpath') { + ExerciseShowFunctions::display_free_answer($choice,0,0); + } + } elseif($answerType == HOT_SPOT) { + exit; + if ($origin != 'learnpath') { + ExerciseShowFunctions::display_hotspot_answer($answerId, $answer, $studentChoice, $answerComment); + } + } elseif($answerType == HOT_SPOT_ORDER) { + ExerciseShowFunctions::display_hotspot_order_answer($answerId, $answer, $studentChoice, $answerComment); + } elseif($answerType==MATCHING) { + if ($origin != 'learnpath') { + echo ''; + echo ''; + echo ''; + } + } + } + } else { + switch($answerType) { + case UNIQUE_ANSWER : + case MULTIPLE_ANSWER : + case MULTIPLE_ANSWER_COMBINATION : + if ($answerId==1) { + ExerciseShowFunctions::display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$exeId,$questionId,$answerId); + } else { + ExerciseShowFunctions::display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$exeId,$questionId,""); + } + break; + case FILL_IN_BLANKS: + echo ''; + break; + case FREE_ANSWER: + echo ' + + +
 
'.get_lang('ElementList').' '.get_lang('CorrespondsTo').'
 
'.$s_answer_label.''.$user_answer.' / '.$real_list[$i_answer_correct_answer].'
'.text_filter($answer_matching[$answerId]).''.text_filter($user_answer).' / '.text_filter($answer_matching[$answerCorrect]).'
'; + ExerciseShowFunctions::display_fill_in_blanks_answer($answer,$exeId,$questionId); + echo '
'.ExerciseShowFunctions::display_free_answer($choice, $exeId, $questionId).'
'; + break; + case HOT_SPOT: + //ExerciseShowFunctions::display_hotspot_answer($answerId, $answer, $studentChoice, $answerComment); + break; + case HOT_SPOT_ORDER: + ExerciseShowFunctions::display_hotspot_order_answer($answerId, $answer, $studentChoice, $answerComment); + break; + case MATCHING: + if ($origin != 'learnpath') { + echo ''; + echo ''.text_filter($answer_matching[$answerId]).''.text_filter($user_answer).' / '.text_filter($answer_matching[$answerCorrect]).''; + echo ''; + } + break; + } + } //display answers (if not matching type, or if the answer is correct) - if ($answerType != MATCHING || $answerCorrect) { + /* if ($answerType != MATCHING || $answerCorrect) { if ($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER || $answerType == MULTIPLE_ANSWER_COMBINATION) { if ($origin!='learnpath') { ExerciseShowFunctions::display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,0,0,0); @@ -1945,22 +2179,33 @@ class Exercise { echo ''; } } - } - } + }*/ + } } // end for that loops over all answers of the current question // destruction of Answer + if ($answerType == HOT_SPOT) { + $queryfree = "select marks from ".$TBL_TRACK_ATTEMPT." where exe_id = '".Database::escape_string($exeId)."' and question_id= '".Database::escape_string($questionId)."'"; + $resfree = Database::query($queryfree); + $questionScore= Database::result($resfree,0,"marks"); + } + + $final_answer = true; + foreach($real_answers as $my_answer) { + if (!$my_answer) { + $final_answer = false; + } + } //we add the total score after dealing with the answers - if ($answerType == MULTIPLE_ANSWER_COMBINATION) { + if ($answerType == MULTIPLE_ANSWER_COMBINATION) { if ($final_answer) { //getting only the first score where we save the weight of all the question $answerWeighting=$objAnswerTmp->selectWeighting(1); $questionScore+=$answerWeighting; $totalScore+=$answerWeighting; } - } - + } if ($from == 'exercise_result') { global $colspan; @@ -1968,7 +2213,7 @@ class Exercise { // TODO Change this, because it is wrong to show the user some results that haven't been stored in the database yet if ($answerType == HOT_SPOT || $answerType == HOT_SPOT_ORDER) { // We made an extra table for the answers - if($origin != 'learnpath') { + if($origin != 'learnpath') { echo ''; echo ' '; @@ -1980,16 +2225,17 @@ class Exercise { '; } } - ?> - + if($origin != 'learnpath') { ?> - type == ALL_ON_ONE_PAGE) { + if($questionScore==-1){ + echo get_lang('Score').": 0 /".float_format($questionWeighting); + } else { + echo get_lang('Score').": ".float_format($questionScore,1)."/".float_format($questionWeighting,1); + } } ?>

@@ -2003,11 +2249,11 @@ class Exercise { $i++; $totalWeighting += $questionWeighting; - //added by priya saini // Store results directly in the database // For all in one page exercises, the results will be // stored by exercise_results.php (using the session) - if ($_configuration['tracking_enabled']) { + + if ($saved_results) { if (empty ($choice)) { $choice = 0; } @@ -2053,13 +2299,132 @@ class Exercise { } } - if ($from == 'exercise_show') { + if ($saved_results) { $stat_table = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); $sql_update = 'UPDATE ' . $stat_table . ' SET exe_result = exe_result + ' . (int) $totalScore . ',exe_weighting = exe_weighting + ' . (int) $totalWeighting . ' WHERE exe_id = ' . $exeId; Database::query($sql_update); - } + } return array('score'=>$questionScore, 'weight'=>$questionWeighting); } //End function + + + + + function send_notification($arrques, $arrans, $to) { + global $courseName, $exerciseTitle, $url_email; + require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php'; + $user_info = UserManager::get_user_info_by_id(api_get_user_id()); + + if (api_get_course_setting('email_alert_manager_on_new_quiz') != 1 ) { + return ''; + } + + $mycharset = api_get_system_encoding(); + $msg = ' + + '; + if(count($arrques)>0) { + $msg .= ' +

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

+

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

+ + + + + + + + + + + + + + + + +

  '.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 .= ' +

'.get_lang('ExerciseAttempted').'
+

+ + + + + + + + + + + + '.(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)); + } + } } endif; ?> \ No newline at end of file diff --git a/main/exercice/exercise.lib.php b/main/exercice/exercise.lib.php index 958ccde47c..fc58f52043 100755 --- a/main/exercice/exercise.lib.php +++ b/main/exercice/exercise.lib.php @@ -145,71 +145,8 @@ function showQuestion($questionId, $onlyAnswers = false, $origin = false, $curre // because [] is parsed here we follow this procedure: $answer = text_filter($answer); - /* // Deprecated code - // 1. find everything between the [tex] and [/tex] tags - $startlocations = api_strpos($answer,'[tex]'); - $endlocations = api_strpos($answer,'[/tex]'); - - if ($startlocations !== false && $endlocations !== false) { - $texstring = api_substr($answer,$startlocations,$endlocations-$startlocations+6); - // 2. replace this by {texcode} - $answer = str_replace($texstring,'{texcode}',$answer); - } - */ - - // 3. do the normal matching parsing - // replaces [blank] by an input field - //getting the matches $answer = api_ereg_replace('\[[^]]+\]','',($answer)); - - // Change input size - /* - preg_match_all('/\[[^]]+]/',$answer,$matches); - $answer=ereg_replace('\[[^]]+\]','',($answer)); - - // 4. resize the input - - - foreach($matches[0] as $match) { - $answer_len = strlen($match)-2; - //we will only replace 1 item - // echo implode("replace term", explode("search term", "input", $limit)); - if ($answer_len <= 5) { - $answer = (implode("5", explode("@@", $answer, 2))); - } elseif($answer_len <= 10) { - $answer = (implode("10", explode("@@", $answer, 2))); - } elseif($answer_len <= 20) { - $answer = (implode("20", explode("@@", $answer, 2))); - } elseif($answer_len <= 30) { - $answer = (implode("30", explode("@@", $answer, 2))); - } elseif($answer_len <= 40) { - $answer = (implode("45", explode("@@", $answer, 2))); - } elseif($answer_len <= 50) { - $answer = (implode("60", explode("@@", $answer, 2))); - } elseif($answer_len <= 60) { - $answer = (implode("70", explode("@@", $answer, 2))); - } elseif($answer_len <= 70) { - $answer = (implode("80", explode("@@", $answer, 2))); - } elseif($answer_len <= 80) { - $answer = (implode("90", explode("@@", $answer, 2))); - } elseif($answer_len <= 90) { - $answer = (implode("100", explode("@@", $answer, 2))); - } elseif($answer_len <= 100) { - $answer = (implode("110", explode("@@", $answer, 2))); - } elseif($answer_len > 100 ) { - $answer = (implode("120", explode("@@", $answer, 2))); - } - } - - */ - - /* // Deprecated code - // 5. replace the {texcode by the api_pare_tex parsed code} - $texstring = api_parse_tex($texstring); - $answer=str_replace("{texcode}",$texstring,$answer); - */ - } // Unique answer @@ -356,12 +293,12 @@ function showQuestion($questionId, $onlyAnswers = false, $origin = false, $curre } elseif ($answerType == HOT_SPOT) { // Question is of type HOT_SPOT - $questionName=$objQuestionTmp->selectTitle(); - $questionDescription=$objQuestionTmp->selectDescription(); + $questionName = $objQuestionTmp->selectTitle(); + $questionDescription = $objQuestionTmp->selectDescription(); // Get the answers, make a list - $objAnswerTmp=new Answer($questionId); - $nbrAnswers=$objAnswerTmp->selectNbrAnswers(); + $objAnswerTmp = new Answer($questionId); + $nbrAnswers = $objAnswerTmp->selectNbrAnswers(); // get answers of hotpost $answers_hotspot = array(); @@ -396,6 +333,7 @@ function showQuestion($questionId, $onlyAnswers = false, $origin = false, $curre $canClick = isset($_GET['editQuestion']) ? '0' : (isset($_GET['modifyAnswers']) ? '0' : '1'); //$tes = isset($_GET['modifyAnswers']) ? '0' : '1'; //echo $tes; + $s .= '