read($exercise_id);
}
$feedback_type = $objExercise->feedback_type;
//Only users can see their own results
if (!$is_allowedToEdit) {
if ($student_id != $current_user_id) {
api_not_allowed(true);
}
}
if (isset($_SESSION['gradebook'])) {
$gradebook= Security::remove_XSS($_SESSION['gradebook']);
}
if (!empty($gradebook) && $gradebook=='view') {
$interbreadcrumb[]= array ('url' => '../gradebook/'.$_SESSION['gradebook_dest'],'name' => get_lang('ToolGradebook'));
}
$fromlink = '';
$interbreadcrumb[]= array("url" => "exercice.php?gradebook=$gradebook","name" => get_lang('Exercices'));
$interbreadcrumb[]= array("url" => "overview.php?exerciseId=".$exercise_id.'&id_session='.api_get_session_id(),"name" => $objExercise->name);
$interbreadcrumb[]= array("url" => "#","name" => get_lang('Result'));
$this_section = SECTION_COURSES;
if ($origin != 'learnpath') {
Display::display_header('');
} else {
Display::display_reduced_header();
}
?>
';
Display::display_warning_message(get_lang('ThankYouForPassingTheTest').'
'.(get_lang('BackToExercisesList')).'', false);
echo ' |
';
}
} elseif ($result_disabled == 2) {
$show_results = false;
$show_only_total_score = true;
if ($origin != 'learnpath') {
echo '
';
Display::display_warning_message(get_lang('ThankYouForPassingTheTest'), false);
echo ' |
';
}
}
}
} else {
Display::display_warning_message(get_lang('CantViewResults'));
$show_results = false;
}
if ($origin == 'learnpath' && !isset($_GET['fb_type']) ) {
$show_results = false;
}
if ($show_results || $show_only_total_score) {
$user_info = api_get_user_info($student_id);
//Shows exercise header
echo $objExercise->show_exercise_result_header(api_get_person_name($user_info['firstName'], $user_info['lastName']), api_convert_and_format_date($exercise_date));
}
$i = $totalScore = $totalWeighting = 0;
if($debug>0){error_log("ExerciseResult: ".print_r($exerciseResult,1)); error_log("QuestionList: ".print_r($questionList,1));}
$arrques = array();
$arrans = array();
$user_restriction = $is_allowedToEdit ? '' : "AND user_id=".intval($student_id)." ";
$query = "SELECT attempts.question_id, answer FROM ".$TBL_TRACK_ATTEMPT." as attempts
INNER JOIN ".$TBL_TRACK_EXERCICES." AS stats_exercices ON stats_exercices.exe_id=attempts.exe_id
INNER JOIN ".$TBL_EXERCICE_QUESTION." AS quizz_rel_questions
ON quizz_rel_questions.exercice_id=stats_exercices.exe_exo_id
AND quizz_rel_questions.question_id = attempts.question_id
AND quizz_rel_questions.c_id=".api_get_course_int_id()."
INNER JOIN ".$TBL_QUESTIONS." AS questions
ON questions.id=quizz_rel_questions.question_id
AND questions.c_id = ".api_get_course_int_id()."
WHERE attempts.exe_id='".Database::escape_string($id)."' $user_restriction
GROUP BY quizz_rel_questions.question_order, attempts.question_id";
$result = Database::query($query);
$question_list_from_database = array();
$exerciseResult = array();
while ($row = Database::fetch_array($result)) {
$question_list_from_database[] = $row['question_id'];
$exerciseResult[$row['question_id']] = $row['answer'];
}
//Fixing #2073 Fixing order of questions
if (!empty($track_exercise_info['data_tracking'])) {
$temp_question_list = explode(',', $track_exercise_info['data_tracking']);
//Getting question list from data_tracking
if (!empty($temp_question_list)) {
$questionList = $temp_question_list;
}
//If for some reason data_tracking is empty we select the question list from db
if (empty($questionList)) {
$questionList = $question_list_from_database;
}
} else {
$questionList = $question_list_from_database;
}
// Display the text when finished message if we are on a LP #4227
$end_of_message = $objExercise->selectTextWhenFinished();
if (!empty($end_of_message) && ($origin == 'learnpath')) {
Display::display_normal_message($end_of_message, false);
echo "
";
}
// for each question
$total_weighting = 0;
foreach ($questionList as $questionId) {
$objQuestionTmp = Question::read($questionId);
$total_weighting += $objQuestionTmp->selectWeighting();
}
$counter = 1;
$exercise_content = null;
$media_list = array();
$category_list = array();
foreach ($questionList as $questionId) {
$choice = $exerciseResult[$questionId];
// destruction of the Question object
unset($objQuestionTmp);
// creates a temporary Question object
$objQuestionTmp = Question::read($questionId);
$questionWeighting = $objQuestionTmp->selectWeighting();
$answerType = $objQuestionTmp->selectType();
// Start buffer
ob_start();
/* Use switch
switch ($answerType) {
}*/
if ($answerType == MULTIPLE_ANSWER || $answerType == MULTIPLE_ANSWER_TRUE_FALSE) {
$question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg());
$questionScore = $question_result['score'];
$totalScore += $question_result['score'];
} elseif ($answerType == MULTIPLE_ANSWER_COMBINATION || $answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE) {
$choice = array();
$question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg());
$questionScore = $question_result['score'];
$totalScore += $question_result['score'];
} elseif ($answerType == UNIQUE_ANSWER || $answerType == UNIQUE_ANSWER_NO_OPTION) {
$question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg());
$questionScore = $question_result['score'];
$totalScore += $question_result['score'];
echo '';
} elseif ($answerType == FILL_IN_BLANKS) {
$question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg());
$questionScore = $question_result['score'];
$totalScore += $question_result['score'];
} elseif ($answerType == GLOBAL_MULTIPLE_ANSWER) {
$question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg());
$questionScore = $question_result['score'];
$totalScore += $question_result['score'];
} elseif ($answerType == FREE_ANSWER) {
$answer = $str;
$question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg());
$questionScore = $question_result['score'];
$totalScore += $question_result['score'];
} elseif ($answerType == ORAL_EXPRESSION) {
$answer = $str;
$question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg());
$questionScore = $question_result['score'];
$totalScore += $question_result['score'];
} elseif ($answerType == MATCHING || $answerType == DRAGGABLE) {
$question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg());
$questionScore = $question_result['score'];
$totalScore += $question_result['score'];
} elseif ($answerType == HOT_SPOT) {
if ($show_results) {
echo '
';
}
$question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg());
$questionScore = $question_result['score'];
$totalScore += $question_result['score'];
if ($show_results) {
echo ' |
';
echo '
'.
'
|
';
}
} else if($answerType == HOT_SPOT_DELINEATION) {
$question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg(), 'database');
$questionScore = $question_result['score'];
$totalScore += $question_result['score'];
$final_overlap = $question_result['extra']['final_overlap'];
$final_missing = $question_result['extra']['final_missing'];
$final_excess = $question_result['extra']['final_excess'];
$overlap_color = $question_result['extra']['overlap_color'];
$missing_color = $question_result['extra']['missing_color'];
$excess_color = $question_result['extra']['excess_color'];
$threadhold1 = $question_result['extra']['threadhold1'];
$threadhold2 = $question_result['extra']['threadhold2'];
$threadhold3 = $question_result['extra']['threadhold3'];
if ($show_results) {
if ($overlap_color) {
$overlap_color='green';
} else {
$overlap_color='red';
}
if ($missing_color) {
$missing_color='green';
} else {
$missing_color='red';
}
if ($excess_color) {
$excess_color='green';
} else {
$excess_color='red';
}
if (!is_numeric($final_overlap)) {
$final_overlap = 0;
}
if (!is_numeric($final_missing)) {
$final_missing = 0;
}
if (!is_numeric($final_excess)) {
$final_excess = 0;
}
if ($final_excess>100) {
$final_excess = 100;
}
$table_resume='
|
'.get_lang('Requirements').' |
'.get_lang('YourAnswer').' |
'.get_lang('Overlap').' |
'.get_lang('Min').' '.$threadhold1.' |
'.(($final_overlap < 0)?0:intval($final_overlap)).' |
'.get_lang('Excess').' |
'.get_lang('Max').' '.$threadhold2.' |
'.(($final_excess < 0)?0:intval($final_excess)).' |
'.get_lang('Missing').' |
'.get_lang('Max').' '.$threadhold3.' |
'.(($final_missing < 0)?0:intval($final_missing)).' |
';
if ($answerType!= HOT_SPOT_DELINEATION) {
$item_list=explode('@@',$destination);
//print_R($item_list);
$try = $item_list[0];
$lp = $item_list[1];
$destinationid= $item_list[2];
$url=$item_list[3];
$table_resume='';
} else {
if ($next==0) {
$try = $try_hotspot;
$lp = $lp_hotspot;
$destinationid= $select_question_hotspot;
$url=$url_hotspot;
} else {
//show if no error
//echo 'no error';
$comment=$answerComment=$objAnswerTmp->selectComment($nbrAnswers);
$answerDestination=$objAnswerTmp->selectDestination($nbrAnswers);
}
}
echo ''.get_lang('Feedback').'
';
if ($answerType == HOT_SPOT_DELINEATION) {
if ($organs_at_risk_hit>0) {
$message='
'.get_lang('ResultIs').' '.$result_comment.'
';
$message.=''.get_lang('OARHit').'
';
} else {
$message=''.get_lang('YourDelineation').'
';
$message.=$table_resume;
$message.='
'.get_lang('ResultIs').' '.$result_comment.'
';
}
$message.=''.$comment.'
';
echo $message;
} else {
echo ''.$comment.'
';
}
//showing the score
$queryfree = "select marks from ".$TBL_TRACK_ATTEMPT." WHERE exe_id = '".Database::escape_string($id)."' and question_id= '".Database::escape_string($questionId)."'";
$resfree = Database::query($queryfree);
$questionScore= Database::result($resfree,0,"marks");
$totalScore+=$questionScore;
echo '';
echo '
|
';
}
}
if ($show_results) {
if ($answerType != HOT_SPOT) {
echo '';
}
}
$comnt = null;
if ($show_results) {
if ($is_allowedToEdit && $locked == false && !api_is_drh()) {
$name = "fckdiv".$questionId;
$marksname = "marksName".$questionId;
if (in_array($answerType, array(FREE_ANSWER, ORAL_EXPRESSION))) {
$url_name = get_lang('EditCommentsAndMarks');
} else {
if ($action=='edit') {
$url_name = get_lang('EditIndividualComment');
} else {
$url_name = get_lang('AddComments');
}
}
echo '
';
echo Display::url($url_name, 'javascript://', array('class' => 'btn', 'onclick'=>"showfck('".$name."', '".$marksname."');"));
echo '
';
echo '';
$comnt = trim(get_comments($id,$questionId));
if (empty($comnt)) {
echo '
';
} else {
echo '
'.$comnt.'
';
}
echo '
';
echo '';
$arrid[] = $questionId;
$feedback_form = new FormValidator('frmcomments'.$questionId,'post','');
$feedback_form->addElement('html','
');
$renderer =& $feedback_form->defaultRenderer();
$renderer->setFormTemplate('
');
$renderer->setElementTemplate('
{element}
');
$comnt = get_comments($id, $questionId);
$default = array('comments_'.$questionId => $comnt);
$feedback_form->addElement('html_editor', 'comments_'.$questionId, null, null, array('ToolbarSet' => 'TestAnswerFeedback', 'Width' => '100%', 'Height' => '120'));
$feedback_form->addElement('html','
');
$feedback_form->setDefaults($default);
$feedback_form->display();
echo '
';
} else {
$comnt = get_comments($id, $questionId);
echo '
';
if (!empty($comnt)) {
echo ''.get_lang('Feedback').'';
echo ''.$comnt.'
';
}
}
if ($is_allowedToEdit) {
if (in_array($answerType, array(FREE_ANSWER, ORAL_EXPRESSION))) {
$marksname = "marksName".$questionId;
echo '';
echo '
';
if ($questionScore == -1 ) {
$questionScore = 0;
echo Display::return_message(get_lang('notCorrectedYet'));
}
} else {
$arrmarks[] = $questionId;
echo '
';
}
} else {
if ($questionScore == -1) {
$questionScore = 0;
}
}
}
$my_total_score = $questionScore;
$my_total_weight = $questionWeighting;
$totalWeighting += $questionWeighting;
$category_was_added_for_this_test = false;
if (isset($objQuestionTmp->category) && !empty($objQuestionTmp->category)) {
$category_list[$objQuestionTmp->category]['score'] += $my_total_score;
$category_list[$objQuestionTmp->category]['total'] += $my_total_weight;
$category_was_added_for_this_test = true;
}
if (isset($objQuestionTmp->category_list) && !empty($objQuestionTmp->category_list)) {
foreach($objQuestionTmp->category_list as $category_id) {
$category_list[$category_id]['score'] += $my_total_score;
$category_list[$category_id]['total'] += $my_total_weight;
$category_was_added_for_this_test = true;
}
}
//No category for this question!
if ($category_was_added_for_this_test == false) {
$category_list['none']['score'] += $my_total_score;
$category_list['none']['total'] += $my_total_weight;
}
if ($objExercise->selectPropagateNeg() == 0 && $my_total_score < 0) {
$my_total_score = 0;
}
$score = array();
if ($show_results) {
$score['result'] = get_lang('Score')." : ".show_score($my_total_score, $my_total_weight, false, false);
$score['pass'] = $my_total_score >= $my_total_weight ? true : false;
$score['type'] = $answerType;
$score['score'] = $my_total_score;
$score['weight'] = $my_total_weight;
$score['comments'] = isset($comnt) ? $comnt : null;
}
unset($objAnswerTmp);
$i++;
$contents = ob_get_clean();
$question_content = '';
$show_media = false;
if ($objQuestionTmp->parent_id != 0 && !in_array($objQuestionTmp->parent_id, $media_list)) {
$show_media = true;
$media_list[] = $objQuestionTmp->parent_id;
}
if ($show_results) {
//Shows question title an description
$question_content .= $objQuestionTmp->return_header(null, $counter, $score, $show_media);
// display question category, if any
$question_content .= Testcategory::getCategoryNamesForQuestion($questionId);
}
$counter++;
$question_content .= $contents;
$question_content .= '
';
$exercise_content .= $question_content;
} // end of large foreach on questions
$total_score_text = null;
//Total score
if ($origin!='learnpath' || ($origin == 'learnpath' && isset($_GET['fb_type']))) {
if ($show_results || $show_only_total_score ) {
$total_score_text .= '';
$my_total_score_temp = $totalScore;
if ($objExercise->selectPropagateNeg() == 0 && $my_total_score_temp < 0) {
$my_total_score_temp = 0;
}
$total_score_text .= get_question_ribbon($objExercise, $my_total_score_temp, $totalWeighting, true);
$total_score_text .= '
';
}
}
if (!empty($category_list) && ($show_results || $show_only_total_score)) {
//Adding total
$category_list['total'] = array('score' => $my_total_score_temp, 'total' => $totalWeighting);
echo Testcategory::get_stats_table_by_attempt($objExercise->id, $category_list);
}
echo $total_score_text;
echo $exercise_content;
echo $total_score_text;
if (is_array($arrid) && is_array($arrmarks)) {
$strids = implode(",",$arrid);
$marksid = implode(",",$arrmarks);
}
if ($is_allowedToEdit && $locked == false && !api_is_drh()) {
if (in_array($origin, array('tracking_course','user_course','correct_exercise_in_lp'))) {
echo '
'.$href.'';
//Record the results in the learning path, using the SCORM interface (API)
echo "";
echo '