Source for file exercise_result.php
Documentation is available at exercise_result.php
DOKEOS - elearning and course management software
For a full list of contributors, see documentation/credits.html
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
See "documentation/licence.html" more details.
B-1030 Brussels - Belgium
* This script gets informations from the script "exercise_submit.php",
* through the session, and calculates the score of the student for
* Then it shows the results on the screen.
* @package dokeos.exercise
* @author Olivier Brouckaert, main author
* @author Roan Embrechts, some refactoring
* @version $Id: exercise_result.php 15438 2008-05-27 06:46:30Z elixir_inter $
* @todo split more code up in functions, move functions to library?
==============================================================================
==============================================================================
include('exercise.class.php');
include('question.class.php');
include('answer.class.php');
if($_GET['origin']== 'learnpath')
require_once ('../newscorm/learnpath.class.php');
require_once ('../newscorm/learnpathItem.class.php');
require_once ('../newscorm/scorm.class.php');
require_once ('../newscorm/scormItem.class.php');
require_once ('../newscorm/aicc.class.php');
require_once ('../newscorm/aiccItem.class.php');
// name of the language file that needs to be included
$language_file= 'exercice';
include('../inc/global.inc.php');
/* ------------ ACCESS RIGHTS ------------ */
// notice for unauthorized people.
include_once(api_get_path(LIBRARY_PATH). 'events.lib.inc.php');
include_once(api_get_path(LIBRARY_PATH). 'mail.lib.inc.php');
include_once(api_get_path(LIBRARY_PATH). 'course.lib.php');
// Database table definitions
//temp values to move to AWACS
$dsp_percent = false; //false to display total score as absolute values
//debug param. 0: no display - 1: debug display
if($debug> 0){echo str_repeat(' ',0). 'Entered exercise_result.php'. "<br />\n";var_dump($_POST);}
// general parameters passed via POST/GET
if ( empty ( $origin ) ) {
$origin = $_REQUEST['origin'];
if ( empty ( $learnpath_id ) ) {
if ( empty ( $learnpath_item_id ) ) {
if ( empty ( $formSent ) ) {
$formSent = $_REQUEST['formSent'];
if ( empty ( $exerciseResult ) ) {
$exerciseResult = $_SESSION['exerciseResult'];
if ( empty ( $questionId ) ) {
$questionId = $_REQUEST['questionId'];
if ( empty ( $choice ) ) {
$choice = $_REQUEST['choice'];
if ( empty ( $questionNum ) ) {
if ( empty ( $nbrQuestions ) ) {
if ( empty ( $questionList ) ) {
$questionList = $_SESSION['questionList'];
if ( empty ( $objExercise ) ) {
$objExercise = $_SESSION['objExercise'];
$courseName = $_SESSION['_course']['name'];
$query = "select user_id from $main_admin_table";
$from_name = $uinfo['firstname']. ' '. $uinfo['lastname'];
$str = $_SERVER['REQUEST_URI'];
//$url = $_SERVER['SERVER_NAME'].'/'.$arr[1].'/';
// if the above variables are empty or incorrect, stops the script
header('Location: exercice.php');
$exerciseTitle= $objExercise->selectTitle();
$exerciseDescription= $objExercise->selectDescription();
$interbreadcrumb[]= array("url" => "exercice.php","name" => get_lang('Exercices'));
if ($origin != 'learnpath')
//so we are not in learnpath tool
$charset = 'ISO-8859-15';
header('Content-Type: text/html; charset='. $charset);
if(empty($document_language))
//if there was no valid iso-code, use the english one
$document_language = 'en';
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang=" <?php echo $document_language; ?>" lang=" <?php echo $document_language; ?>">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
if($objExercise->results_disabled)
==============================================================================
==============================================================================
<td width="5%" align="center">
<img src="../img/ <?php echo ($answerType == UNIQUE_ANSWER)? 'radio': 'checkbox'; echo $studentChoice? '_on': '_off'; ?>.gif"
<td width="5%" align="center">
<img src="../img/ <?php echo ($answerType == UNIQUE_ANSWER)? 'radio': 'checkbox'; echo $answerCorrect? '_on': '_off'; ?>.gif"
<td width="45%" style="border-bottom: 1px solid #4171B5;">
<td width="45%" style="border-bottom: 1px solid #4171B5;">
<?php echo nl2br($answer); ?>
<?php echo get_lang('notCorrectedYet');?>
//global $hotspot_colors;
$hotspot_colors = array("", // $i starts from 1 on next loop (ugly fix)
<div style="float:left; padding-left:5px;">
<div style="display:inline; float:left; width:80px;"> <?php echo $answer ?></div>
<div style="height:11px; width:11px; background-color: <?php echo $hotspot_colors[$answerId]; ?>; display:inline; float:left; margin-top:3px;"></div>
<td valign="top"> <?php echo $answerId; ?></td>
<?php $studentChoice = ($studentChoice)? get_lang('Correct'): get_lang('Fault'); echo $studentChoice; ?>
==============================================================================
==============================================================================
<h3> <?php echo $exerciseTitle ?>: <?php echo get_lang("Result"); ?></h3>
<?php echo $exerciseDescription; ?>
<form method="get" action="exercice.php">
<input type="hidden" name="origin" value=" <?php echo $origin; ?>" />
<input type="hidden" name="learnpath_id" value=" <?php echo $learnpath_id; ?>" />
<input type="hidden" name="learnpath_item_id" value=" <?php echo $learnpath_item_id; ?>" />
$i= $totalScore= $totalWeighting= 0;
if($debug> 0){echo "ExerciseResult: "; var_dump($exerciseResult); echo "QuestionList: ";var_dump($questionList);}
$sql = "select max(exe_Id) as id from ". $TBL_TRACK_EXERCICES;
foreach($questionList as $questionId)
// gets the student choice for this question
$choice= $exerciseResult[$questionId];
// creates a temporary Question object
$questionName= $objQuestionTmp->selectTitle();
$questionDescription= $objQuestionTmp->selectDescription();
$questionWeighting= $objQuestionTmp->selectWeighting();
$answerType= $objQuestionTmp->selectType();
$quesId = $objQuestionTmp->selectId(); //added by priya saini
// destruction of the Question object
<table width="100%" border="0" cellpadding="3" cellspacing="2">
<td colspan=" <?php echo $colspan; ?>">
<?php echo get_lang("Question"). ' '. ($counter). ' : '. $questionName; ?>
<td colspan=" <?php echo $colspan; ?>">
<?php echo $questionDescription; ?>
<td width="5%" valign="top" align="center" nowrap="nowrap">
<i> <?php echo get_lang("Choice"); ?></i>
<td width="5%" valign="top" nowrap="nowrap">
<i> <?php echo get_lang("ExpectedChoice"); ?></i>
<td width="45%" valign="top">
<i> <?php echo get_lang("Answer"); ?></i>
<td width="45%" valign="top">
<i> <?php echo get_lang("Comment"); ?></i>
<i> <?php echo get_lang("Answer"); ?></i>
<i> <?php echo get_lang("Answer"); ?></i>
<td width="45%" valign="top">
<i> <?php echo get_lang("Comment"); ?></i>
<td valign="top" colspan="2">
<table width="556" border="0">
<td width="40%" valign="top">
<i> <?php echo get_lang("CorrectAnswer"); ?></i><br /><br />
<td width="15%" valign="top">
<i> <?php echo get_lang("ClickNumber"); ?></i><br /><br />
<td width="20%" valign="top">
<i> <?php echo get_lang('HotspotHit'); ?></i><br /><br />
<td width="25%" valign="top">
<i> <?php echo get_lang("Comment"); ?></i><br /><br />
<i> <?php echo get_lang("ElementList"); ?></i>
<i> <?php echo get_lang("CorrespondsTo"); ?></i>
// construction of the Answer object
$objAnswerTmp= new Answer($questionId);
$nbrAnswers= $objAnswerTmp->selectNbrAnswers();
for($answerId= 1;$answerId <= $nbrAnswers;$answerId++ )
$answer= $objAnswerTmp->selectAnswer($answerId);
$answerComment= $objAnswerTmp->selectComment($answerId);
$answerCorrect= $objAnswerTmp->isCorrect($answerId);
$answerWeighting= $objAnswerTmp->selectWeighting($answerId);
$studentChoice= ($choice == $answerId)? 1: 0;
$questionScore+= $answerWeighting;
$totalScore+= $answerWeighting;
$studentChoice= $choice[$answerId];
$questionScore+= $answerWeighting;
$totalScore+= $answerWeighting;
// for fill in the blanks
case FILL_IN_BLANKS : // splits text and weightings that are joined with the character '::'
list ($answer,$answerWeighting)= explode('::',$answer);
// splits weightings that are joined with a comma
$answerWeighting= explode(',',$answerWeighting);
// we save the answer because it will be modified
// 1. find everything between the [tex] and [/tex] tags
$startlocations= strpos($temp,'[tex]');
$endlocations= strpos($temp,'[/tex]');
if($startlocations !== false && $endlocations !== false)
$texstring= substr($temp,$startlocations,$endlocations- $startlocations+ 6);
// 2. replace this by {texcode}
// the loop will stop at the end of the text
// quits the loop if there are no more blanks
if(($pos = strpos($temp,'[')) === false)
// adds the end of the text
// adds the piece of text that is before the blank and ended by [
$answer.= substr($temp,0,$pos+ 1);
// quits the loop if there are no more blanks
if(($pos = strpos($temp,']')) === false)
// adds the end of the text
$choice[$j]= trim($choice[$j]);
// if the word entered by the student IS the same as the one defined by the professor
// gives the related weighting to the student
$questionScore+= $answerWeighting[$j];
// increments total score
$totalScore+= $answerWeighting[$j];
// adds the word in green at the end of the string
// else if the word entered by the student IS NOT the same as the one defined by the professor
elseif(!empty($choice[$j]))
// adds the word in red at the end of the string, and strikes it
$answer.= '<font color="red"><s>'. stripslashes($choice[$j]). '</s></font>';
// adds a tabulation if no word has been typed by the student
$answer.= ' ';
// adds the correct word, followed by ] to close the blank
$answer.= ' / <font color="green"><b>'. substr($temp,0,$pos). '</b></font>]';
//Score is at -1 because the question has'nt been corected
if($answerCorrect == $choice[$answerId])
$questionScore+= $answerWeighting;
$totalScore+= $answerWeighting;
$choice[$answerId]= $matching[$choice[$answerId]];
elseif(!$choice[$answerId])
$choice[$answerId]= ' ';
$choice[$answerId]= '<font color="red"><s>'. $matching[$choice[$answerId]]. '</s></font>';
$matching[$answerId]= $answer;
// for hotspot with no order
case HOT_SPOT : $studentChoice= $choice[$answerId];
$questionScore+= $answerWeighting;
$totalScore+= $answerWeighting;
// for hotspot with fixed order
if($studentChoice == $answerId)
$questionScore+= $answerWeighting;
$totalScore+= $answerWeighting;
} // end switch Answertype
if($answerType != MATCHING || $answerCorrect)
// to store the details of open questions in an array to be used in mail
$arrques[] = $questionName;
$firstName = $_SESSION['_user']['firstName'];
$lastName = $_SESSION['_user']['lastName'];
$mail = $_SESSION['_user']['mail'];
$coursecode = $_SESSION['_course']['id'];
if(api_get_setting('use_session_mode')== 'true' && !empty($_SESSION['id_session']))
foreach($teachers as $teacher)
$to[] = $teacher['email'];
foreach($teachers as $teacher)
//this is a problem (it means that there is no admin for this course)
$sql = "INSERT INTO $tbl_track_e_hotspot (`hotspot_user_id` , `hotspot_course_code` , `hotspot_exe_id` , `hotspot_question_id` , `hotspot_answer_id` , `hotspot_correct` , `hotspot_coordinate` )
VALUES ('". $_user['user_id']. "', '". $_course['id']. "', '$exeId', '$questionId', '$answerId', '$studentChoice', '". $_SESSION['exerciseResultCoordinates'][$questionId][$answerId]. "')";
display_hotspot_order_answer($answerId, $answer, $studentChoice, $answerComment);
<?php echo $choice[$answerId]; ?> / <font color="green"><b>
$matching[$answerCorrect]= api_parse_tex($matching[$answerCorrect]);
echo $matching[$answerCorrect]; ?></b></font>
} // end for that loops over all answers of the current question
// We made an extra table for the answers
echo "</table></td></tr>";
<i> <?php echo get_lang('Hotspot'); ?></i><br /><br />
<object type="application/x-shockwave-flash" data="../plugin/hotspot/hotspot_solution.swf?modifyAnswers= <?php echo $questionId ?>&exe_id=&from_db=0" width="556" height="421">
<param name="movie" value="../plugin/hotspot/hotspot_solution.swf?modifyAnswers= <?php echo $questionId ?>&exe_id=&from_db=0" />
<td colspan=" <?php echo $colspan; ?>" align="left">
echo get_lang('Score'). " : 0/$questionWeighting";
echo get_lang('Score'). " : $questionScore/$questionWeighting";
$totalWeighting+= $questionWeighting;
if($_configuration['tracking_enabled'])
for ($i= 0;$i< sizeof($reply);$i++ )
for ($i= 0;$i< sizeof($choice);$i++ ,$j++ )
if (preg_match_all ('#<font color="red"><s>([0-9a-z ]*)</s></font>#', $val, $arr1))
$sql = "select position from $table_ans where question_id=$questionId and answer='$val' AND correct=0";
$sql = "select id from $table_ans where question_id=$questionId and position=$choice";
} // end huge foreach() block that loops over all questions
<table width="100%" border="0" cellpadding="3" cellspacing="2">
<b> <?php echo get_lang('YourTotalScore'). " ";
if($dsp_percent == true){
echo number_format(($totalScore/ $totalWeighting)* 100,1,'.',''). "%";
echo $totalScore. "/". $totalWeighting;
if ($origin != 'learnpath')
<input type="submit" value=" <?php echo get_lang('Finish'); ?>" />
==============================================================================
==============================================================================
if($_configuration['tracking_enabled'])
//include(api_get_path(LIBRARY_PATH).'events.lib.inc.php');
event_exercice($objExercise->selectId(),$totalScore,$totalWeighting,$answer,$question_id);
if($objExercise->results_disabled)
if ($origin != 'learnpath')
//we are not in learnpath tool
//record the results in the learning path, using the SCORM interface (API)
echo '<script language="javascript" type="text/javascript">window.parent.API.void_save_asset('. $totalScore. ','. $totalWeighting. ');</script>'. "\n";
if ($send_email && count($arrques)> 0)
<meta content="text/html; charset='. $mycharset. '" http-equiv="content-type">';
<p>'. get_lang('OpenQuestionsAttempted'). ' :
<p>'. get_lang('AttemptDetails'). ' : ><br />
<table width="730" height="136" border="0" cellpadding="3" cellspacing="3">
<td width="229" valign="top"><h2> '. get_lang('CourseName'). '</h2></td>
<td width="469" valign="top"><h2>#course#</h2></td>
<td width="229" valign="top" class="outerframe"> '. get_lang('TestAttempted'). '</span></td>
<td width="469" valign="top" class="outerframe">#exercise#</td>
<td valign="top"> <span class="style10">'. get_lang('StudentName'). '</span></td>
<td valign="top" >#firstName# #lastName#</td>
<td valign="top" > '. get_lang('StudentEmail'). ' </td>
<td valign="top"> #mail#</td>
<p><br />'. get_lang('OpenQuestionsAttemptedAre'). ' :</p>
<table width="730" height="136" border="0" cellpadding="3" cellspacing="3">';
for($i= 0;$i< sizeof($arrques);$i++ )
<td width="220" valign="top" bgcolor="#E5EDF8"> <span class="style10">'. get_lang('Question'). '</span></td>
<td width="473" valign="top" bgcolor="#F3F3F3"><span class="style16"> #questionName#</span></td>
<td width="220" valign="top" bgcolor="#E5EDF8"> <span class="style10">'. get_lang('Answer'). ' </span></td>
<td valign="top" bgcolor="#F3F3F3"><span class="style16"> #answer#</span></td>
$msg1= str_replace("#questionName#",$arrques[$i],$msg);
<span class="style16">'. get_lang('ClickToCommentAndGiveFeedback'). ',<br />
<a href="#url#">#url#</a></span></body></html>';
$student_name = $_SESSION['_user']['firstName']. ' '. $_SESSION['_user']['lastName'];
$subject = get_lang('OpenQuestionsAttempted');
api_mail_html($student_name, $to, $subject, $mail_content, $from_name, $from, array('encoding'=> $mycharset,'charset'=> $mycharset));
|