Source for file exercise_show.php
Documentation is available at exercise_show.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.
Rue des Palais 44 Paleizenstraat
B-1030 Brussels - Belgium
* @package dokeos.exercise
* @version $Id: admin.php 10680 2007-01-11 21:26:23Z pcool $
* @todo remove the debug code and use the general debug library
* @todo use the Database:: functions
* @todo small letters for table variables
// name of the language file that needs to be included
$language_file= array('exercice','tracking');
// including the global dokeos file
include('../inc/global.inc.php');
// including additional libraries
include_once('exercise.class.php');
include_once('question.class.php');
include_once('answer.class.php');
include_once(api_get_path(LIBRARY_PATH). 'formvalidator/FormValidator.class.php');
// Database table definitions
// general parameters passed via POST/GET
$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'];
if($origin== 'user_course')
$interbreadcrumb[] = array ("url" => "../user/user.php?cidReq=". $_GET['course'], "name" => get_lang("Users"));
$interbreadcrumb[] = array("url" => "../mySpace/myStudents.php?student=". $_GET['student']. "&course=". $_course['id']. "&details=true&origin=". $_GET['origin'] , "name" => get_lang("DetailsStudentInCourse"));
else if($origin== 'tracking_course')
$interbreadcrumb[] = array ("url" => "../mySpace/index.php", "name" => get_lang('MySpace'));
$interbreadcrumb[] = array ("url" => "../mySpace/myStudents.php?student=". $_GET['student']. '&details=true&origin='. $origin. '&course='. $_GET['cidReq'], "name" => get_lang("DetailsStudentInCourse"));
else if($origin== 'student_progress')
$interbreadcrumb[] = array ("url" => "../auth/my_progress.php?id_session". $_GET['id_session']. "&course=". $_cid, "name" => get_lang('MyProgress'));
$interbreadcrumb[]= array("url" => "exercice.php","name" => get_lang('Exercices'));
$emailId = $_REQUEST['email'];
$user_name = $_REQUEST['user'];
$test = $_REQUEST['test'];
$marks = $_REQUEST['res'];
<script language="javascript">
function showfck(sid,marksid)
document.getElementById(sid).style.visibility='visible';
document.getElementById(marksid).style.visibility='visible';
function getFCK(vals,marksid){
var f=document.getElementById('myform');
var m_id = marksid.split(',');
for(var i=0;i<m_id.length;i++){
var oHidn = document.createElement("input");
var selname = oHidn.name = "marks_"+m_id[i];
var selid = document.forms['marksform_'+m_id[i]].marks.selectedIndex;
oHidn.value = document.forms['marksform_'+m_id[i]].marks.options[selid].text;
var ids = vals.split(',');
for(var k=0;k<ids.length;k++){
var oHidden = document.createElement("input");
oHidden.name = "comments_"+ids[k];
oEditor = FCKeditorAPI.GetInstance(oHidden.name) ;
oHidden.value = oEditor.GetXHTML(true);
global $TBL_TRACK_ATTEMPT;
$sql = "select teacher_comment from ". $TBL_TRACK_ATTEMPT. " where exe_id=$id and question_id = '$question_id' order by question_id";
<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"
echo $answer; ?><hr style="border-top: 0.5px solid #4171B5;">
<?php echo nl2br($answer); ?>
if(!$is_allowedToEdit) {?>
</td> <?php if(!$is_allowedToEdit) {?>
echo get_lang('notCorrectedYet');
//global $hotspot_colors;
$hotspot_colors = array("", // $i starts from 1 on next loop (ugly fix)
<td valign="top" align="left">
<div style="width:100%;">
<div style="height:11px; width:11px; background-color: <?php echo $hotspot_colors[$answerId]; ?>; float:left; margin:3px;"></div>
<div> <?php echo $answer ?></div>
<td valign="top" align="left"> <?php echo $answerId; ?></td>
<td valign="top" align="left">
<?php $studentChoice = ($studentChoice)? get_lang('Correct'): get_lang('Fault'); echo $studentChoice; ?>
==============================================================================
==============================================================================
<table width="100%" border="0" cellspacing=0 cellpadding=0>
$sql_test_name= 'SELECT title, description FROM '. $TBL_EXERCICES. ' as exercises, '. $TBL_TRACK_EXERCICES. ' as track_exercises WHERE exercises.id=track_exercises.exe_exo_id AND track_exercises.exe_id="'. $id. '"';
$user_restriction = $is_allowedToEdit ? '' : "AND user_id=". intval($_user['user_id']). " ";
$query = "select * 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
INNER JOIN ". $TBL_QUESTIONS. " as questions ON questions.id=quizz_rel_questions.question_id
WHERE attempts.exe_id='$id' $user_restriction
GROUP BY questions.position, attempts.question_id";
<td style="font-weight:bold"> <?php echo get_lang('CourseTitle')?> : </td>
<td> <?php echo $_course['name'] ?></td>
<td style="font-weight:bold"> <?php echo get_lang('User')?> : </td>
<td> <?php echo $user_name ?></td>
<td style="font-weight:bold">
<?php echo $exerciseDexcription; ?>
$i= $totalScore= $totalWeighting= 0;
if($debug> 0){echo "ExerciseResult: "; var_dump($exerciseResult); echo "QuestionList: ";var_dump($questionList);}
$exerciseResult = array();
$questionList[] = $row['question_id'];
$exerciseResult[] = $row['answer'];
foreach($questionList as $questionId)
$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
<td colspan="2" > <?php echo get_lang("Question"). ' '. ($counter). ' : '. $questionName; ?> </td>
<td colspan="2"> <?php echo $questionDescription; ?> </td>
<td width="200" height="90" valign="top">
<table width="355" border="0" cellspacing="3" cellpadding="3">
<td><i> <?php echo get_lang("Choice"); ?></i> </td>
<td><i> <?php echo get_lang("ExpectedChoice"); ?></i></td>
<td><i> <?php echo get_lang("Answer"); ?></i></td>
// 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);
$queryans = "select * from ". $TBL_TRACK_ATTEMPT. " where exe_id = $id and question_id= $questionId";
$studentChoice= $choice[$answerId];
$questionScore+= $answerWeighting;
$totalScore+= $answerWeighting;
<table width="355" border="0">
<td><i> <?php echo get_lang("Choice"); ?></i> </td>
<td><i> <?php echo get_lang("ExpectedChoice"); ?></i></td>
<td><i> <?php echo get_lang("Answer"); ?></i></td>
$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);
$queryans = "select answer from ". $TBL_TRACK_ATTEMPT. " where exe_id = $id and question_id= $questionId";
$studentChoice= ($choice == $answerId)? 1: 0;
$questionScore+= $answerWeighting;
$totalScore+= $answerWeighting;
<td> <?php if($answerId== 1)
<table width="355" border="0">
<td><i> <?php echo get_lang("Answer"); ?></i> </td>
$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);
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
// quits the loop if there are no more blanks
if(($pos = strpos($temp,']')) === false)
$queryfill = "select answer from ". $TBL_TRACK_ATTEMPT. " where exe_id = $id and question_id= $questionId";
$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];
// else if the word entered by the student IS NOT the same as the one defined by the professor
<table width="355" border="0" cellspacing="0" cellpadding="0">
<td><i> <?php echo get_lang("Answer"); ?></i> </td>
$objAnswerTmp= new Answer($questionId);
$nbrAnswers= $objAnswerTmp->selectNbrAnswers();
$query = "select answer, marks from ". $TBL_TRACK_ATTEMPT. " where exe_id = $id and question_id= $questionId";
$totalScore+= $questionScore;
$objAnswerTmp= new Answer($questionId);
$sql_select_answer = 'SELECT id, answer, correct, position FROM '. $table_ans. ' WHERE question_id="'. $questionId. '" AND correct<>0';
$res_answers = api_sql_query($sql_select_answer, __FILE__ , __LINE__ );
echo '<table width="355" height="71" border="0">';
echo '<tr><td colspan="2"> </td></tr>';
<td><span style="font-style: italic;">'. get_lang("ElementList"). '</span> </td>
<td><span style="font-style: italic;">'. get_lang("CorrespondsTo"). '</span></td>
echo '<tr><td colspan="2"> </td></tr>';
$i_answer_id = $a_answers['id'];
$s_answer_label = $a_answers['answer'];
$i_answer_correct_answer = $a_answers['correct'];
$i_answer_position = $a_answers['position'];
FROM '. $TBL_TRACK_ATTEMPT. ' as track_e_attempt
INNER JOIN '. $table_ans. ' as answers
ON answers.position = track_e_attempt.answer
AND track_e_attempt.question_id=answers.question_id
WHERE answers.correct = 0
AND track_e_attempt.exe_id = "'. $id. '"
AND track_e_attempt.question_id = "'. $questionId. '"
AND track_e_attempt.position="'. $i_answer_position. '"';
$res_user_answer = api_sql_query($sql_user_answer, __FILE__ , __LINE__ );
$s_correct_answer = $s_answer_label;
$i_answerWeighting= $objAnswerTmp->selectWeighting($i_answer_id);
if($s_user_answer == $s_correct_answer){
$questionScore+= $i_answerWeighting;
$totalScore+= $i_answerWeighting;
$s_user_answer = '<span style="color: #FF0000; text-decoration: line-through;">'. $s_user_answer. '</span>';
echo '<td>'. $s_answer_label. '</td><td>'. $s_user_answer. ' / <span style="color: #008000;">'. $s_correct_answer. '</span></td>';
<table width="355" border="0" cellspacing="0" cellpadding="0">
$objAnswerTmp= new Answer($questionId);
$nbrAnswers= $objAnswerTmp->selectNbrAnswers();
<td valign="top" align="left">
<table style="border: 1px solid #4271b5;border-bottom:none" width="556">
for($answerId= 1;$answerId <= $nbrAnswers;$answerId++ )
$answer= $objAnswerTmp->selectAnswer($answerId);
$answerComment= $objAnswerTmp->selectComment($answerId);
$answerCorrect= $objAnswerTmp->isCorrect($answerId);
$answerWeighting= $objAnswerTmp->selectWeighting($answerId);
$query = "select hotspot_correct from ". $TBL_TRACK_HOTSPOT. " where hotspot_exe_id = $id and hotspot_question_id= $questionId AND hotspot_answer_id=$answerId";
$queryfree = "select marks from ". $TBL_TRACK_ATTEMPT. " where exe_id = $id and question_id= $questionId";
$totalScore+= $questionScore;
<object type="application/x-shockwave-flash" data="../plugin/hotspot/hotspot_solution.swf?modifyAnswers='. $questionId. '&exe_id='. $id. '&from_db=1" width="556" height="421">
<param name="movie" value="../plugin/hotspot/hotspot_solution.swf?modifyAnswers='. $questionId. '&exe_id='. $id. '&from_db=1" />
<td width="346" valign = "top"><i>
<?php if($is_allowedToEdit)
//if (isset($_REQUEST['showdiv']) && $questionId==$_REQUEST['ques_id'])
$name = "fckdiv". $questionId;
$marksname = "marksName". $questionId;
<a href="javascript://" onclick="showfck(' <?php echo $name; ?>',' <?php echo $marksname; ?>');"> <?php if ($answerType == FREE_ANSWER) echo " ". get_lang('EditCommentsAndMarks'); else echo " ". get_lang('AddComments');?></a>
<div id=" <?php echo $name; ?>" style="visibility:hidden">
$fck_attribute['Width'] = '400';
$fck_attribute['Height'] = '150';
$fck_attribute['ToolbarSet'] = 'Comment';
$fck_attribute['Config']['IMUploadPath'] = 'upload/test/';
$ $questionId = new FormValidator('frmcomments'. $questionId,'post','');
$renderer = & $ $questionId->defaultRenderer();
$renderer->setFormTemplate(
'<form{attributes}><div align="left">{content}</div></form>');
$renderer->setElementTemplate(
'<div align="left">{element}</div>'
$ {user. $questionId}['comments_'. $questionId] = $comnt;
$ $questionId->addElement('html_editor','comments_'. $questionId,false);
//$$questionId->addElement('submit','submitQuestion',get_lang('Ok'));
$ $questionId->setDefaults($ {user. $questionId});
$marksname = "marksName". $questionId;
<div id=" <?php echo $marksname; ?>" style="visibility:hidden">
<form name="marksform_ <?php echo $questionId; ?>" method="post" action="">
$arrmarks[] = $questionId;
echo "<select name='marks' id='marks'>";
for($i= 0;$i<= $questionWeighting;$i++ )
<option <?php if ($i== $questionScore) echo "selected='selected'";?>>
echo '<br>'. get_lang('notCorrectedYet');
$arrmarks[] = $questionId;
echo '<div id="'. $marksname. '" style="visibility:hidden"><form name="marksform_'. $questionId. '" method="post" action=""><select name="marks" id="marks" style="display:none;"><option>'. $questionScore. '</option></select></form></div>';
</td><tr><td align="left"><b> <?php echo get_lang('Score'). " : $questionScore/$questionWeighting"; ?></b><br /><br /></td>
<?php unset ($objAnswerTmp);
$totalWeighting+= $questionWeighting;
<tr><td align="left"><b> <?php
//$query = "update ".$TBL_TRACK_EXERCICES." set exe_result = $totalScore where exe_id = '$id'";
//api_sql_query($query,__FILE__,__LINE__);
echo '<br/>'. get_lang('YourTotalScore'). " ";
echo number_format(($totalScore/ $totalWeighting)* 100,1,'.',''). "%";
echo $totalScore. "/". $totalWeighting;
<?php $strids = implode(",",$arrid);
if(in_array($origin, array('tracking_course','user_course'))){
echo ' <form name="myform" id="myform" action="exercice.php?show=result&comments=update&exeid='. $id. '&test='. $test. '&emailid='. $emailId. '&origin='. $origin. '&student='. $_GET['student']. '&details=true&course='. $_GET['cidReq']. '" method="post">';
echo ' <form name="myform" id="myform" action="exercice.php?show=result&comments=update&exeid='. $id. '&test='. $test. '&emailid='. $emailId. '" method="post">';
<input type="submit" value=" <?php echo get_lang('Ok'); ?>" onclick="getFCK(' <?php echo $strids; ?>',' <?php echo $marksid; ?>');"/>
|