Fixing exercise_show and exercise_results requires testing

skala
Julio Montoya 14 years ago
parent f49c0e94e6
commit 5e4fee84ac
  1. 7
      main/exercice/exercice_submit.php
  2. 411
      main/exercice/exercise.class.php
  3. 4
      main/exercice/exercise_result.php
  4. 239
      main/exercice/exercise_show.php
  5. 17
      main/inc/lib/events.lib.inc.php
  6. 155
      main/inc/lib/exercise_show_functions.lib.php

@ -25,6 +25,8 @@ require_once 'question.class.php';
require_once 'answer.class.php'; require_once 'answer.class.php';
require_once 'exercise.lib.php'; require_once 'exercise.lib.php';
// debug var. Set to 0 to hide all debug display. Set to 1 to display debug messages. // debug var. Set to 0 to hide all debug display. Set to 1 to display debug messages.
$debug = 1; $debug = 1;
@ -32,6 +34,7 @@ $debug = 1;
$language_file = 'exercice'; $language_file = 'exercice';
require_once '../inc/global.inc.php'; require_once '../inc/global.inc.php';
$this_section = SECTION_COURSES; $this_section = SECTION_COURSES;
// Notice for unauthorized people. // 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 the user has submitted the form
if ($formSent) { if ($formSent && isset($_POST)) {
if ($debug > 0) { error_log('$formSent was set'); } if ($debug > 0) { error_log('$formSent was set'); }
// Initializing // Initializing
@ -371,7 +374,7 @@ if ($formSent) {
$choice = $exerciseResult[$questionId]; $choice = $exerciseResult[$questionId];
if (isset($exe_id)) { if (isset($exe_id)) {
//Manage the question and answer attempts //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 //END of saving and qualifying
} }

@ -16,6 +16,8 @@ define('EXERCISE_FEEDBACK_TYPE_END',0);
define('EXERCISE_FEEDBACK_TYPE_DIRECT',1); define('EXERCISE_FEEDBACK_TYPE_DIRECT',1);
define('EXERCISE_FEEDBACK_TYPE_EXAM',2); define('EXERCISE_FEEDBACK_TYPE_EXAM',2);
require_once '../inc/lib/exercise_show_functions.lib.php';
if(!class_exists('Exercise')): if(!class_exists('Exercise')):
class Exercise { class Exercise {
@ -1638,9 +1640,13 @@ class Exercise {
* @param int the choice the user selected * @param int the choice the user selected
* @param string function is called from 'exercise_show' or 'exercise_result' * @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; 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 // Creates a temporary Question object
$objQuestionTmp = Question :: read($questionId); $objQuestionTmp = Question :: read($questionId);
@ -1649,7 +1655,8 @@ class Exercise {
$questionDescription = $objQuestionTmp->selectDescription(); $questionDescription = $objQuestionTmp->selectDescription();
$questionWeighting = $objQuestionTmp->selectWeighting(); $questionWeighting = $objQuestionTmp->selectWeighting();
$answerType = $objQuestionTmp->selectType(); $answerType = $objQuestionTmp->selectType();
$quesId = $objQuestionTmp->selectId(); //added by priya saini $quesId = $objQuestionTmp->selectId();
$totalWeighting = 0; $totalWeighting = 0;
$totalScore = 0; $totalScore = 0;
@ -1668,7 +1675,7 @@ class Exercise {
$nbrAnswers = 1; $nbrAnswers = 1;
} }
$user_answer = ''; $user_answer = '';
$table_ans = Database::get_course_table(TABLE_QUIZ_ANSWER);
// Get answer list for matching // Get answer list for matching
$sql_answer = 'SELECT id, answer FROM '.$table_ans.' WHERE question_id="'.Database::escape_string($questionId).'" '; $sql_answer = 'SELECT id, answer FROM '.$table_ans.' WHERE question_id="'.Database::escape_string($questionId).'" ';
@ -1679,30 +1686,89 @@ class Exercise {
} }
$real_answers = array(); $real_answers = array();
for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) { for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) {
$answer = $objAnswerTmp->selectAnswer($answerId); $answer = $objAnswerTmp->selectAnswer($answerId);
$answerComment = $objAnswerTmp->selectComment($answerId); $answerComment = $objAnswerTmp->selectComment($answerId);
$answerCorrect = $objAnswerTmp->isCorrect($answerId); $answerCorrect = $objAnswerTmp->isCorrect($answerId);
$answerWeighting = $objAnswerTmp->selectWeighting($answerId); $answerWeighting = $objAnswerTmp->selectWeighting($answerId);
$numAnswer=$objAnswerTmp->selectAutoId($answerId); $numAnswer = $objAnswerTmp->selectAutoId($answerId);
switch ($answerType) { switch ($answerType) {
// for unique answer // for unique answer
case UNIQUE_ANSWER : case UNIQUE_ANSWER :
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; $studentChoice=($choice == $numAnswer)?1:0;
if ($studentChoice) { if ($studentChoice) {
$questionScore+=$answerWeighting; $questionScore+=$answerWeighting;
$totalScore+=$answerWeighting; $totalScore+=$answerWeighting;
} }
}
break; break;
// for multiple answers // for multiple answers
case MULTIPLE_ANSWER : 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) {
$questionScore+=$answerWeighting;
$totalScore+=$answerWeighting;
}
} else {
$studentChoice=$choice[$numAnswer]; $studentChoice=$choice[$numAnswer];
if ($studentChoice) { if ($studentChoice) {
$questionScore+=$answerWeighting; $questionScore+=$answerWeighting;
$totalScore+=$answerWeighting; $totalScore+=$answerWeighting;
} }
}
break; break;
case MULTIPLE_ANSWER_COMBINATION: 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 {
if ($studentChoice) {
$real_answers[$answerId] = false;
} else {
$real_answers[$answerId] = true;
}
}
} else {
$studentChoice=$choice[$numAnswer]; $studentChoice=$choice[$numAnswer];
if ($answerCorrect == 1) { if ($answerCorrect == 1) {
if ($studentChoice) { if ($studentChoice) {
@ -1723,6 +1789,7 @@ class Exercise {
$final_answer = false; $final_answer = false;
} }
} }
}
break; break;
// for fill in the blanks // for fill in the blanks
case FILL_IN_BLANKS : case FILL_IN_BLANKS :
@ -1731,24 +1798,19 @@ class Exercise {
// number 1 before the "@" means that is a switchable fill in blank question // 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 // [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 // means that is a normal fill blank question
// first we explode the "::" // first we explode the "::"
$pre_array = explode('::', $answer); $pre_array = explode('::', $answer);
// is switchable fill blank or not // is switchable fill blank or not
$last = count($pre_array) - 1; $last = count($pre_array) - 1;
$is_set_switchable = explode('@', $pre_array[$last]); $is_set_switchable = explode('@', $pre_array[$last]);
$switchable_answer_set = false; $switchable_answer_set = false;
if (isset ($is_set_switchable[1]) && $is_set_switchable[1] == 1) { if (isset ($is_set_switchable[1]) && $is_set_switchable[1] == 1) {
$switchable_answer_set = true; $switchable_answer_set = true;
} }
$answer = ''; $answer = '';
for ($k = 0; $k < $last; $k++) { for ($k = 0; $k < $last; $k++) {
$answer .= $pre_array[$k]; $answer .= $pre_array[$k];
} }
// splits weightings that are joined with a comma // splits weightings that are joined with a comma
$answerWeighting = explode(',', $is_set_switchable[0]); $answerWeighting = explode(',', $is_set_switchable[0]);
@ -1770,7 +1832,6 @@ class Exercise {
*/ */
$answer = ''; $answer = '';
$j = 0; $j = 0;
//initialise answer tags //initialise answer tags
$user_tags = array (); $user_tags = array ();
$correct_tags = array (); $correct_tags = array ();
@ -1801,7 +1862,25 @@ class Exercise {
$answer .= $temp; $answer .= $temp;
break; break;
} }
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]); $choice[$j] = trim($choice[$j]);
}
$user_tags[] = api_strtolower($choice[$j]); $user_tags[] = api_strtolower($choice[$j]);
//put the contents of the [] answer tag into correct_tags[] //put the contents of the [] answer tag into correct_tags[]
$correct_tags[] = api_strtolower(api_substr($temp, 0, $pos)); $correct_tags[] = api_strtolower(api_substr($temp, 0, $pos));
@ -1809,7 +1888,6 @@ class Exercise {
$temp = api_substr($temp, $pos +1); $temp = api_substr($temp, $pos +1);
//$answer .= ']'; //$answer .= ']';
} }
$answer = ''; $answer = '';
$real_correct_tags = $correct_tags; $real_correct_tags = $correct_tags;
$chosen_list = array (); $chosen_list = array ();
@ -1818,7 +1896,6 @@ class Exercise {
if ($i == 0) { if ($i == 0) {
$answer .= $real_text[0]; $answer .= $real_text[0];
} }
if (!$switchable_answer_set) { if (!$switchable_answer_set) {
//needed to parse ' and " characters //needed to parse ' and " characters
$user_tags[$i] = stripslashes($user_tags[$i]); $user_tags[$i] = stripslashes($user_tags[$i]);
@ -1866,19 +1943,94 @@ class Exercise {
$answer .= $real_text[$i +1]; $answer .= $real_text[$i +1];
} }
} }
break; break;
// for free answer // for free answer
case FREE_ANSWER : case FREE_ANSWER :
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 {
$totalScore+=$questionScore;
}
$arrques[] = $questionName;
$arrans[] = $choice;
} else {
$studentChoice = $choice; $studentChoice = $choice;
if ($studentChoice) { if ($studentChoice) {
//Score is at -1 because the question has'nt been corected //@todo verify this--> set to -1 because the question has'nt been corrected
$questionScore = -1; $questionScore = -1;
$totalScore += 0; $totalScore += 0;
} }
}
break; break;
// for matching // for matching
case 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 '<table width="100%" height="71" border="0" cellspacing="3" cellpadding="3" >';
echo '<tr><td colspan="2">&nbsp;</td></tr>';
echo '<tr>
<td><span style="font-style: italic;">'.get_lang('ElementList').'</span> </td>
<td><span style="font-style: italic;">'.get_lang('CorrespondsTo').'</span></td>
</tr>';
echo '<tr><td colspan="2">&nbsp;</td></tr>';
}
$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 = '<span>'.$real_list[$i_answer_correct_answer].'</span>';
} else {
$user_answer = '<span style="color: #FF0000; text-decoration: line-through;">'.$real_list[$s_user_answer].'</span>';
}
}
if ($show_result) {
echo '<tr>';
echo '<td>'.$s_answer_label.'</td><td>'.$user_answer.' / <b><span style="color: #008000;">'.$real_list[$i_answer_correct_answer].'</span></b></td>';
echo '</tr>';
}
}
break(2); //break the switch and the for condition
} else {
$numAnswer=$objAnswerTmp->selectAutoId($answerId); $numAnswer=$objAnswerTmp->selectAutoId($answerId);
if ($answerCorrect) { if ($answerCorrect) {
if ($answerCorrect == $choice[$numAnswer]) { if ($answerCorrect == $choice[$numAnswer]) {
@ -1891,18 +2043,29 @@ class Exercise {
$matching[$numAnswer] = $choice[$numAnswer]; $matching[$numAnswer] = $choice[$numAnswer];
} }
break; break;
}
// for hotspot with no order // for hotspot with no order
case HOT_SPOT : case HOT_SPOT :
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]; $studentChoice = $choice[$answerId];
if ($studentChoice) { if ($studentChoice) {
$questionScore += $answerWeighting; $questionScore += $answerWeighting;
$totalScore += $answerWeighting; $totalScore += $answerWeighting;
} }
}
break; break;
// for hotspot with fixed order // @todo never added to chamilo
//for hotspot with fixed order
case HOT_SPOT_ORDER : case HOT_SPOT_ORDER :
$studentChoice = $choice['order'][$answerId]; $studentChoice = $choice['order'][$answerId];
if ($studentChoice == $answerId) { if ($studentChoice == $answerId) {
$questionScore += $answerWeighting; $questionScore += $answerWeighting;
$totalScore += $answerWeighting; $totalScore += $answerWeighting;
@ -1913,8 +2076,10 @@ class Exercise {
break; 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) //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 ($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER || $answerType == MULTIPLE_ANSWER_COMBINATION) {
@ -1933,6 +2098,7 @@ class Exercise {
ExerciseShowFunctions::display_free_answer($choice,0,0); ExerciseShowFunctions::display_free_answer($choice,0,0);
} }
} elseif($answerType == HOT_SPOT) { } elseif($answerType == HOT_SPOT) {
exit;
if ($origin != 'learnpath') { if ($origin != 'learnpath') {
ExerciseShowFunctions::display_hotspot_answer($answerId, $answer, $studentChoice, $answerComment); ExerciseShowFunctions::display_hotspot_answer($answerId, $answer, $studentChoice, $answerComment);
} }
@ -1946,11 +2112,91 @@ class Exercise {
} }
} }
} }
} 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 '<tr><td>';
ExerciseShowFunctions::display_fill_in_blanks_answer($answer,$exeId,$questionId);
echo '</td></tr>';
break;
case FREE_ANSWER:
echo '<tr>
<td valign="top">'.ExerciseShowFunctions::display_free_answer($choice, $exeId, $questionId).'</td>
</tr>
</table>';
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 '<tr>';
echo '<td>'.text_filter($answer_matching[$answerId]).'</td><td>'.text_filter($user_answer).' / <b><span style="color: #008000;">'.text_filter($answer_matching[$answerCorrect]).'</span></b></td>';
echo '</tr>';
}
break;
}
}
//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) {
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 '<tr>';
echo '<td>'.text_filter($answer_matching[$answerId]).'</td><td>'.text_filter($user_answer).' / <b><span style="color: #008000;">'.text_filter($answer_matching[$answerCorrect]).'</span></b></td>';
echo '</tr>';
}
}
}*/
} }
} // end for that loops over all answers of the current question } // end for that loops over all answers of the current question
// destruction of Answer // 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 //we add the total score after dealing with the answers
if ($answerType == MULTIPLE_ANSWER_COMBINATION) { if ($answerType == MULTIPLE_ANSWER_COMBINATION) {
if ($final_answer) { if ($final_answer) {
@ -1961,7 +2207,6 @@ class Exercise {
} }
} }
if ($from == 'exercise_result') { if ($from == 'exercise_result') {
global $colspan; global $colspan;
// if answer is hotspot. To the difference of exercise_show.php, we use the results from the session (from_db=0) // if answer is hotspot. To the difference of exercise_show.php, we use the results from the session (from_db=0)
@ -1980,17 +2225,18 @@ class Exercise {
</tr>'; </tr>';
} }
} }
?> if($origin != 'learnpath') { ?>
<?php if($origin != 'learnpath') { ?>
<tr> <tr>
<td colspan="<?php echo $colspan; ?>" align="left"> <td colspan="<?php echo $colspan; ?>" align="left">
<b> <b>
<?php <?php
if ($this->type == ALL_ON_ONE_PAGE) {
if($questionScore==-1){ if($questionScore==-1){
echo get_lang('Score').": 0 /".float_format($questionWeighting); echo get_lang('Score').": 0 /".float_format($questionWeighting);
} else { } else {
echo get_lang('Score').": ".float_format($questionScore,1)."/".float_format($questionWeighting,1); echo get_lang('Score').": ".float_format($questionScore,1)."/".float_format($questionWeighting,1);
} }
}
?></b><br /><br /> ?></b><br /><br />
</td> </td>
</tr> </tr>
@ -2003,11 +2249,11 @@ class Exercise {
$i++; $i++;
$totalWeighting += $questionWeighting; $totalWeighting += $questionWeighting;
//added by priya saini
// Store results directly in the database // Store results directly in the database
// For all in one page exercises, the results will be // For all in one page exercises, the results will be
// stored by exercise_results.php (using the session) // stored by exercise_results.php (using the session)
if ($_configuration['tracking_enabled']) {
if ($saved_results) {
if (empty ($choice)) { if (empty ($choice)) {
$choice = 0; $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); $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; $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); Database::query($sql_update);
} }
return array('score'=>$questionScore, 'weight'=>$questionWeighting); return array('score'=>$questionScore, 'weight'=>$questionWeighting);
} //End function } //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 = '<html><head>
<link rel="stylesheet" href="'.api_get_path(WEB_CODE_PATH).'css/'.api_get_setting('stylesheets').'/default.css" type="text/css">
<meta content="text/html; charset='.$mycharset.'" http-equiv="content-type"></head>';
if(count($arrques)>0) {
$msg .= '<body>
<p>'.get_lang('OpenQuestionsAttempted').' :
</p>
<p>'.get_lang('AttemptDetails').' : <br />
</p>
<table width="730" height="136" border="0" cellpadding="3" cellspacing="3">
<tr>
<td width="229" valign="top"><h2>&nbsp;&nbsp;'.get_lang('CourseName').'</h2></td>
<td width="469" valign="top"><h2>#course#</h2></td>
</tr>
<tr>
<td width="229" valign="top" class="outerframe">&nbsp;&nbsp;'.get_lang('TestAttempted').'</span></td>
<td width="469" valign="top" class="outerframe">#exercise#</td>
</tr>
<tr>
<td valign="top">&nbsp;&nbsp;<span class="style10">'.get_lang('StudentName').'</span></td>
<td valign="top" >#firstName# #lastName#</td>
</tr>
<tr>
<td valign="top" >&nbsp;&nbsp;'.get_lang('StudentEmail').' </td>
<td valign="top"> #mail#</td>
</tr></table>
<p><br />'.get_lang('OpenQuestionsAttemptedAre').' :</p>
<table width="730" height="136" border="0" cellpadding="3" cellspacing="3">';
for($i=0;$i<sizeof($arrques);$i++) {
$msg.='
<tr>
<td width="220" valign="top" bgcolor="#E5EDF8">&nbsp;&nbsp;<span class="style10">'.get_lang('Question').'</span></td>
<td width="473" valign="top" bgcolor="#F3F3F3"><span class="style16"> #questionName#</span></td>
</tr>
<tr>
<td width="220" valign="top" bgcolor="#E5EDF8">&nbsp;&nbsp;<span class="style10">'.get_lang('Answer').' </span></td>
<td valign="top" bgcolor="#F3F3F3"><span class="style16"> #answer#</span></td>
</tr>';
$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.='</table><br>
<span class="style16">'.get_lang('ClickToCommentAndGiveFeedback').',<br />
<a href="#url#">#url#</a></span></body></html>';
$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 .= '<body>
<p>'.get_lang('ExerciseAttempted').' <br />
</p>
<table width="730" height="136" border="0" cellpadding="3" cellspacing="3">
<tr>
<td width="229" valign="top"><h2>&nbsp;&nbsp;'.get_lang('CourseName').'</h2></td>
<td width="469" valign="top"><h2>#course#</h2></td>
</tr>
<tr>
<td width="229" valign="top" class="outerframe">&nbsp;&nbsp;'.get_lang('TestAttempted').'</span></td>
<td width="469" valign="top" class="outerframe">#exercise#</td>
</tr>
<tr>
<td valign="top">&nbsp;&nbsp;<span class="style10">'.get_lang('StudentName').'</span></td>
'.(api_is_western_name_order() ? '<td valign="top" >#firstName# #lastName#</td>' : '<td valign="top" >#lastName# #firstName#</td>').'
</tr>
<tr>
<td valign="top" >&nbsp;&nbsp;'.get_lang('StudentEmail').' </td>
<td valign="top"> #mail#</td>
</tr></table>';
$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.='<br />
<span class="style16">'.get_lang('ClickToCommentAndGiveFeedback').',<br />
<a href="#url#">#url#</a></span></body></html>';
$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; endif;
?> ?>

@ -182,6 +182,7 @@ foreach ($questionList as $questionId) {
$counter++; $counter++;
// gets the student choice for this question // gets the student choice for this question
$choice = $exerciseResult[$questionId]; $choice = $exerciseResult[$questionId];
// creates a temporary Question object // creates a temporary Question object
$objQuestionTmp = Question :: read($questionId); $objQuestionTmp = Question :: read($questionId);
// initialize question information // initialize question information
@ -242,8 +243,7 @@ foreach ($questionList as $questionId) {
<?php } ?> <?php } ?>
</tr> </tr>
<?php <?php
} elseif ($answerType == FILL_IN_BLANKS) { } elseif ($answerType == FILL_IN_BLANKS) { ?>
?>
<tr> <tr>
<td> <td>
<i><?php echo get_lang("Answer"); ?></i> <i><?php echo get_lang("Answer"); ?></i>

@ -12,19 +12,20 @@
* */ * */
// name of the language file that needs to be included // name of the language file that needs to be included
$language_file=array('exercice','tracking'); $language_file=array('exercice');
// including the global dokeos file
require_once '../inc/global.inc.php';
require_once '../inc/lib/course.lib.php';
// including additional libraries // including additional libraries
require_once 'exercise.class.php'; require_once 'exercise.class.php';
require_once 'exercise.lib.php'; require_once 'exercise.lib.php';
require_once 'question.class.php'; //also defines answer type constants require_once 'question.class.php'; //also defines answer type constants
require_once 'answer.class.php'; require_once 'answer.class.php';
require_once '../inc/global.inc.php';
require_once api_get_path(LIBRARY_PATH).'course.lib.php';
require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php'; require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php'; require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php';
require_once api_get_path(LIBRARY_PATH).'exercise_show_functions.lib.php';
if ( empty ( $origin ) ) { if ( empty ( $origin ) ) {
$origin = $_REQUEST['origin']; $origin = $_REQUEST['origin'];
@ -89,14 +90,9 @@ $lp_item_view_id = $track_exercise_info['orig_lp_item_view_id'];
$course_code = api_get_course_id(); $course_code = api_get_course_id();
$current_user_id = api_get_user_id(); $current_user_id = api_get_user_id();
//Check if user can see the results if (empty($objExercise)) {
if (!$is_allowedToEdit) { $objExercise = new Exercise();
if ($track_exercise_info['results_disabled']) { $objExercise->read($exercise_id);
api_not_allowed();
}
if ($student_id != $current_user_id) {
api_not_allowed();
}
} }
if (!exercise_time_control_is_valid($exercise_id)) { if (!exercise_time_control_is_valid($exercise_id)) {
@ -104,6 +100,13 @@ if (!exercise_time_control_is_valid($exercise_id)) {
Database::query($sql_fraud); Database::query($sql_fraud);
} }
//Only users can see their own results
if (!$is_allowedToEdit) {
if ($student_id != $current_user_id) {
api_not_allowed();
}
}
//Unset session for clock time //Unset session for clock time
exercise_time_control_delete($exercise_id); exercise_time_control_delete($exercise_id);
@ -339,7 +342,8 @@ if ($show_results) {
// for each question // for each question
$counter=0; $counter=0;
foreach($questionList as $questionId) { //var_dump($exerciseResult);
foreach ($questionList as $questionId) {
$counter++; $counter++;
$choice=$exerciseResult[$questionId]; $choice=$exerciseResult[$questionId];
// creates a temporary Question object // creates a temporary Question object
@ -361,17 +365,15 @@ if ($show_results) {
} else { } else {
$colspan=2; $colspan=2;
} }
?>
<div id="question_title" class="sectiontitle">
<?php echo get_lang("Question").' '.($counter).' : '.$questionName; ?>
</div>
<div id="question_description">
<?php echo $questionDescription; ?>
</div>
<?php echo '<div id="question_title" class="sectiontitle">';
echo get_lang("Question").' '.($counter).' : '.$questionName;
echo '</div>';
echo '<div id="question_description">';
echo $questionDescription;
echo '</div>';
if ($answerType == MULTIPLE_ANSWER) { if ($answerType == MULTIPLE_ANSWER) {
$choice=array();
?> ?>
<table width="100%" border="0" cellspacing="3" cellpadding="3"> <table width="100%" border="0" cellspacing="3" cellpadding="3">
<tr> <tr>
@ -392,6 +394,9 @@ if ($show_results) {
</tr> </tr>
<?php <?php
// construction of the Answer object // construction of the Answer object
/* $choice=array();
$objAnswerTmp=new Answer($questionId); $objAnswerTmp=new Answer($questionId);
$nbrAnswers=$objAnswerTmp->selectNbrAnswers(); $nbrAnswers=$objAnswerTmp->selectNbrAnswers();
$questionScore=0; $questionScore=0;
@ -400,6 +405,7 @@ if ($show_results) {
$answerComment=$objAnswerTmp->selectComment($answerId); $answerComment=$objAnswerTmp->selectComment($answerId);
$answerCorrect=$objAnswerTmp->isCorrect($answerId); $answerCorrect=$objAnswerTmp->isCorrect($answerId);
$answerWeighting=$objAnswerTmp->selectWeighting($answerId); $answerWeighting=$objAnswerTmp->selectWeighting($answerId);
$queryans = "select * from ".$TBL_TRACK_ATTEMPT." where exe_id = '".Database::escape_string($id)."' and question_id= '".Database::escape_string($questionId)."'"; $queryans = "select * from ".$TBL_TRACK_ATTEMPT." where exe_id = '".Database::escape_string($id)."' and question_id= '".Database::escape_string($questionId)."'";
$resultans = Database::query($queryans); $resultans = Database::query($queryans);
while ($row = Database::fetch_array($resultans)) { while ($row = Database::fetch_array($resultans)) {
@ -414,13 +420,17 @@ if ($show_results) {
} }
echo '<tr><td>'; echo '<tr><td>';
if ($answerId==1) { if ($answerId==1) {
ExerciseShowFunctions::display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,$answerId); //ExerciseShowFunctions::display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,$answerId);
} else { } else {
ExerciseShowFunctions::display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,""); //ExerciseShowFunctions::display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,"");
} }
echo '</td></tr>'; echo '</td></tr>';
$i++; $i++;
} }*/
$question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', false, true);
//var_dump($question_result);
$questionScore = $question_result['score'];
$totalScore += $question_result['score'];
echo '</table>'; echo '</table>';
} elseif ($answerType == MULTIPLE_ANSWER_COMBINATION) { } elseif ($answerType == MULTIPLE_ANSWER_COMBINATION) {
$choice=array(); $choice=array();
@ -440,7 +450,7 @@ if ($show_results) {
</tr> </tr>
<?php <?php
// construction of the Answer object // construction of the Answer object
$objAnswerTmp=new Answer($questionId); /*$objAnswerTmp=new Answer($questionId);
$nbrAnswers=$objAnswerTmp->selectNbrAnswers(); $nbrAnswers=$objAnswerTmp->selectNbrAnswers();
$questionScore=0; $questionScore=0;
@ -495,7 +505,12 @@ if ($show_results) {
$answerWeighting=$objAnswerTmp->selectWeighting(1); $answerWeighting=$objAnswerTmp->selectWeighting(1);
$questionScore+=$answerWeighting; $questionScore+=$answerWeighting;
$totalScore+=$answerWeighting; $totalScore+=$answerWeighting;
} }*/
$question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', false, true);
$questionScore = $question_result['score'];
$totalScore += $question_result['score'];
echo '</table>'; echo '</table>';
} elseif ($answerType == UNIQUE_ANSWER) { } elseif ($answerType == UNIQUE_ANSWER) {
@ -518,7 +533,7 @@ if ($show_results) {
<td>&nbsp;</td> <td>&nbsp;</td>
</tr> </tr>
<?php <?php
$objAnswerTmp=new Answer($questionId); /*$objAnswerTmp=new Answer($questionId);
$nbrAnswers=$objAnswerTmp->selectNbrAnswers(); $nbrAnswers=$objAnswerTmp->selectNbrAnswers();
$questionScore=0; $questionScore=0;
for ($answerId=1;$answerId <= $nbrAnswers;$answerId++) { for ($answerId=1;$answerId <= $nbrAnswers;$answerId++) {
@ -545,11 +560,14 @@ if ($show_results) {
} }
echo '</td></tr>'; echo '</td></tr>';
$i++; $i++;
} }*/
$question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', false, true);
$questionScore = $question_result['score'];
$totalScore += $question_result['score'];
echo '</table>'; echo '</table>';
} elseif ($answerType == FILL_IN_BLANKS) { } elseif ($answerType == FILL_IN_BLANKS) {
?> ?>
<table width="100%" border="0" cellspacing="3" cellpadding="3"> <table width="100%" border="0" cellspacing="3" cellpadding="3">
<tr> <tr>
@ -562,6 +580,7 @@ if ($show_results) {
<td>&nbsp;</td> <td>&nbsp;</td>
</tr> </tr>
<?php <?php
/*
$objAnswerTmp=new Answer($questionId); $objAnswerTmp=new Answer($questionId);
$nbrAnswers=$objAnswerTmp->selectNbrAnswers(); $nbrAnswers=$objAnswerTmp->selectNbrAnswers();
$questionScore=0; $questionScore=0;
@ -599,17 +618,7 @@ if ($show_results) {
//$temp=$answer; //$temp=$answer;
$temp = text_filter($answer); $temp = text_filter($answer);
/* // Deprecated code
// TeX parsing
// 1. find everything between the [tex] and [/tex] tags
$startlocations=api_strpos($temp,'[tex]');
$endlocations=api_strpos($temp,'[/tex]');
if ($startlocations !== false && $endlocations !== false) {
$texstring=api_substr($temp,$startlocations,$endlocations-$startlocations+6);
// 2. replace this by {texcode}
$temp=str_replace($texstring,'{texcode}',$temp);
}
*/
$j=0; $j=0;
// the loop will stop at the end of the text // the loop will stop at the end of the text
@ -622,10 +631,7 @@ if ($show_results) {
if (($pos = api_strpos($temp,'[')) === false) { if (($pos = api_strpos($temp,'[')) === false) {
// adds the end of the text // adds the end of the text
$answer.=$temp; $answer.=$temp;
/* // Deprecated code
// TeX parsing
$texstring = api_parse_tex($texstring);
*/
break; break;
} }
$temp=api_substr($temp,$pos+1); $temp=api_substr($temp,$pos+1);
@ -673,11 +679,7 @@ if ($show_results) {
if (($pos = api_strpos($temp,'[')) === false) { if (($pos = api_strpos($temp,'[')) === false) {
// adds the end of the text // adds the end of the text
$answer.=$temp; $answer.=$temp;
/* // Deprecated code
// TeX parsing
$texstring = api_parse_tex($texstring);
//$answer=str_replace("{texcode}",$texstring,$answer);
*/
break; break;
} }
// adds the piece of text that is before the blank and ended by [ // adds the piece of text that is before the blank and ended by [
@ -723,9 +725,15 @@ if ($show_results) {
ExerciseShowFunctions::display_fill_in_blanks_answer($answer,$id,$questionId); ExerciseShowFunctions::display_fill_in_blanks_answer($answer,$id,$questionId);
echo '</td></tr>'; echo '</td></tr>';
$i++; $i++;
} }*/
$question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', false, true);
$questionScore = $question_result['score'];
$totalScore += $question_result['score'];
echo '</table>'; echo '</table>';
} elseif ($answerType == FREE_ANSWER) {$answer = $str; } elseif ($answerType == FREE_ANSWER) {
$answer = $str;
?> ?>
<table width="100%" border="0" cellspacing="3" cellpadding="3"> <table width="100%" border="0" cellspacing="3" cellpadding="3">
<tr> <tr>
@ -739,7 +747,8 @@ if ($show_results) {
</tr> </tr>
<?php <?php
$objAnswerTmp = new Answer($questionId);
/* $objAnswerTmp = new Answer($questionId);
$nbrAnswers = $objAnswerTmp->selectNbrAnswers(); $nbrAnswers = $objAnswerTmp->selectNbrAnswers();
$questionScore = 0; $questionScore = 0;
$query = "SELECT answer, marks FROM ".$TBL_TRACK_ATTEMPT." WHERE exe_id = '".Database::escape_string($id)."' AND question_id= '".Database::escape_string($questionId)."'"; $query = "SELECT answer, marks FROM ".$TBL_TRACK_ATTEMPT." WHERE exe_id = '".Database::escape_string($id)."' AND question_id= '".Database::escape_string($questionId)."'";
@ -756,112 +765,34 @@ if ($show_results) {
} }
$arrques[] = $questionName; $arrques[] = $questionName;
$arrans[] = $choice; $arrans[] = $choice;*/
$question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', false, true);
$questionScore = $question_result['score'];
$totalScore += $question_result['score'];
echo '<tr> /*echo '<tr>
<td valign="top">'.ExerciseShowFunctions::display_free_answer($choice, $id, $questionId).'</td> <td valign="top">'.ExerciseShowFunctions::display_free_answer($choice, $id, $questionId).'</td>
</tr> </tr>
</table>'; </table>';*/
} elseif ($answerType == MATCHING) { } elseif ($answerType == MATCHING) {
$question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', false, true);
$objAnswerTmp=new Answer($questionId); $questionScore = $question_result['score'];
$table_ans = Database :: get_course_table(TABLE_QUIZ_ANSWER); $totalScore += $question_result['score'];
$TBL_TRACK_ATTEMPT= Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
$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);
echo '<table width="100%" height="71" border="0" cellspacing="3" cellpadding="3" >';
echo '<tr><td colspan="2">&nbsp;</td></tr>';
echo '<tr>
<td><span style="font-style: italic;">'.get_lang('ElementList').'</span> </td>
<td><span style="font-style: italic;">'.get_lang('CorrespondsTo').'</span></td>
</tr>';
echo '<tr><td colspan="2">&nbsp;</td></tr>';
$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 = '$id' 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 = '<span>'.$real_list[$i_answer_correct_answer].'</span>';
} else {
$user_answer = '<span style="color: #FF0000; text-decoration: line-through;">'.$real_list[$s_user_answer].'</span>';
}
}
echo '<tr>';
echo '<td>'.$s_answer_label.'</td><td>'.$user_answer.' / <b><span style="color: #008000;">'.$real_list[$i_answer_correct_answer].'</span></b></td>';
echo '</tr>';
}
echo '</table>'; echo '</table>';
} elseif ($answerType == HOT_SPOT) { } elseif ($answerType == HOT_SPOT) {
?>
<table width="500" border="0">
<?php echo '<table width="500" border="0">
$objAnswerTmp=new Answer($questionId);
$nbrAnswers=$objAnswerTmp->selectNbrAnswers();
$questionScore=0;
?>
<tr> <tr>
<td valign="top" align="center" style="padding-left:0px;" > <td valign="top" align="center" style="padding-left:0px;" >
<table border="1" bordercolor="#A4A4A4" style="border-collapse: collapse;" width="552"> <table border="1" bordercolor="#A4A4A4" style="border-collapse: collapse;" width="552">';
<?php $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', false, true);
for ($answerId=1;$answerId <= $nbrAnswers;$answerId++) { $questionScore = $question_result['score'];
$answer=$objAnswerTmp->selectAnswer($answerId); $totalScore += $question_result['score'];
$answerComment=$objAnswerTmp->selectComment($answerId);
$answerCorrect=$objAnswerTmp->isCorrect($answerId);
$answerWeighting=$objAnswerTmp->selectWeighting($answerId);
$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($id)."' and hotspot_question_id= '".Database::escape_string($questionId)."' AND hotspot_answer_id='".Database::escape_string($answerId)."'";
$resq=Database::query($query);
$choice = Database::result($resq,0,"hotspot_correct");
ExerciseShowFunctions::display_hotspot_answer($answerId,$answer,$choice,$answerComment);
$i++;
}
$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 '</table></td></tr>'; echo '</table></td></tr>';
echo '<tr> echo '<tr>
<td colspan="2">'. <td colspan="2">'.
//<object type="application/x-shockwave-flash" data="../plugin/hotspot/hotspot_solution.swf?modifyAnswers='.$questionId.'&exe_id='.$id.'&from_db=1" width="556" height="421"> '<object type="application/x-shockwave-flash" data="'.api_get_path(WEB_CODE_PATH).'plugin/hotspot/hotspot_solution.swf?modifyAnswers='.Security::remove_XSS($questionId).'&exe_id='.$id.'&from_db=1" width="552" height="352">
'<object type="application/x-shockwave-flash" data="../plugin/hotspot/hotspot_solution.swf?modifyAnswers='.Security::remove_XSS($questionId).'&exe_id='.$id.'&from_db=1" width="552" height="352">
<param name="movie" value="../plugin/hotspot/hotspot_solution.swf?modifyAnswers='.Security::remove_XSS($questionId).'&exe_id='.$id.'&from_db=1" /> <param name="movie" value="../plugin/hotspot/hotspot_solution.swf?modifyAnswers='.Security::remove_XSS($questionId).'&exe_id='.$id.'&from_db=1" />
</object> </object>
@ -889,7 +820,7 @@ if ($show_results) {
} }
} }
echo '</a><br /><div id="feedback_'.$name.'" style="width:100%">'; echo '</a><br /><div id="feedback_'.$name.'" style="width:100%">';
$comnt = trim(ExerciseShowFunctions::get_comments($id,$questionId)); $comnt = trim(get_comments($id,$questionId));
if (empty($comnt)) { if (empty($comnt)) {
echo '<br />'; echo '<br />';
} else { } else {
@ -903,7 +834,7 @@ if ($show_results) {
$renderer =& $feedback_form->defaultRenderer(); $renderer =& $feedback_form->defaultRenderer();
$renderer->setFormTemplate('<form{attributes}><div align="left">{content}</div></form>'); $renderer->setFormTemplate('<form{attributes}><div align="left">{content}</div></form>');
$renderer->setElementTemplate('<div align="left">{element}</div>'); $renderer->setElementTemplate('<div align="left">{element}</div>');
$comnt = ExerciseShowFunctions::get_comments($id,$questionId); $comnt = get_comments($id,$questionId);
${user.$questionId}['comments_'.$questionId] = $comnt; ${user.$questionId}['comments_'.$questionId] = $comnt;
$feedback_form->addElement('html_editor', 'comments_'.$questionId, null, null, array('ToolbarSet' => 'TestAnswerFeedback', 'Width' => '100%', 'Height' => '120')); $feedback_form->addElement('html_editor', 'comments_'.$questionId, null, null, array('ToolbarSet' => 'TestAnswerFeedback', 'Width' => '100%', 'Height' => '120'));
$feedback_form->addElement('html','<br>'); $feedback_form->addElement('html','<br>');
@ -912,7 +843,7 @@ if ($show_results) {
$feedback_form->display(); $feedback_form->display();
echo '</div>'; echo '</div>';
} else { } else {
$comnt = ExerciseShowFunctions::get_comments($id,$questionId); $comnt = get_comments($id,$questionId);
echo '<tr><td><br />'; echo '<tr><td><br />';
if (!empty($comnt)) { if (!empty($comnt)) {
echo '<b>'.get_lang('Feedback').'</b>'; echo '<b>'.get_lang('Feedback').'</b>';
@ -958,7 +889,7 @@ if ($show_results) {
$my_total_weight = float_format($questionWeighting,1); $my_total_weight = float_format($questionWeighting,1);
echo '<div id="question_score">'; echo '<div id="question_score">';
echo get_lang('YourTotalScore')." : $my_total_score/$my_total_weight"; echo get_lang('Score')." : $my_total_score/$my_total_weight";
echo '</div>'; echo '</div>';
unset($objAnswerTmp); unset($objAnswerTmp);
@ -971,12 +902,14 @@ if ($origin!='learnpath' || ($origin == 'learnpath' && isset($_GET['fb_type'])))
//$query = "update ".$TBL_TRACK_EXERCICES." set exe_result = $totalScore where exe_id = '$id'"; //$query = "update ".$TBL_TRACK_EXERCICES." set exe_result = $totalScore where exe_id = '$id'";
//Database::query($query); //Database::query($query);
if ($show_results) { if ($show_results) {
echo '<div id="question_score">'.get_lang('YourTotalScore')." "; echo '<div id="question_score">'.get_lang('YourTotalScore')." ";
if ($dsp_percent) { if ($dsp_percent) {
$my_result = number_format(($totalScore/$totalWeighting)*100,1,'.',''); $my_result = number_format(($totalScore/$totalWeighting)*100,1,'.','');
$my_result = float_format($my_result,1); $my_result = float_format($my_result,1);
echo $my_result."%"; echo $my_result."%";
} else { } else {
$my_total_score = float_format($totalScore,1); $my_total_score = float_format($totalScore,1);
$my_total_weight = float_format($totalWeighting,1); $my_total_weight = float_format($totalWeighting,1);
echo $my_total_score."/".$my_total_weight; echo $my_total_score."/".$my_total_weight;
@ -1038,7 +971,7 @@ if ($origin != 'learnpath') {
echo '</body></html>'; echo '</body></html>';
} else { } else {
if (!$is_allowedToEdit) { if (!$is_allowedToEdit) {
ExerciseShowFunctions::send_notification($arrques, $arrans, $to); $objExercise->send_notification($arrques, $arrans, $to);
} }
Display::display_normal_message(get_lang('ExerciseFinished').' '.get_lang('ToContinueUseMenu')); Display::display_normal_message(get_lang('ExerciseFinished').' '.get_lang('ToContinueUseMenu'));
echo '<br />'; echo '<br />';
@ -1047,7 +980,7 @@ if ($origin != 'learnpath') {
if (!$is_allowedToEdit) { if (!$is_allowedToEdit) {
if ($origin != 'learnpath') { if ($origin != 'learnpath') {
ExerciseShowFunctions::send_notification($arrques, $arrans, $to); $objExercise->send_notification($arrques, $arrans, $to);
} }
} }

@ -772,3 +772,20 @@ function get_all_exercises_from_lp($lp_id, $course_db) {
return $my_exercise_list; return $my_exercise_list;
} }
/**
* This function gets the comments of an exercise
*
* @param int $id
* @param int $question_id
* @return str the comment
*/
function get_comments($id,$question_id)
{
$TBL_TRACK_ATTEMPT = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
$sql = "SELECT teacher_comment FROM ".$TBL_TRACK_ATTEMPT." where exe_id='".Database::escape_string($id)."' and question_id = '".Database::escape_string($question_id)."' ORDER by question_id";
$sqlres = Database::query($sql);
$comm = Database::result($sqlres,0,"teacher_comment");
return $comm;
}

@ -12,15 +12,6 @@
* @todo convert queries to use Database API * @todo convert queries to use Database API
*/ */
$TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
$TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
$TBL_REPONSES = Database::get_course_table(TABLE_QUIZ_ANSWER);
$main_user_table = Database :: get_main_table(TABLE_MAIN_USER);
$main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
$TBL_TRACK_EXERCICES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
$TBL_TRACK_ATTEMPT = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
class ExerciseShowFunctions { class ExerciseShowFunctions {
/** /**
@ -46,7 +37,7 @@ class ExerciseShowFunctions {
if(!api_is_allowed_to_edit(null,true) && $feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) {?> if(!api_is_allowed_to_edit(null,true) && $feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) {?>
<td> <td>
<?php <?php
$comm = ExerciseShowFunctions::get_comments($id,$questionId); $comm = get_comments($id,$questionId);
?> ?>
</td> </td>
<?php } ?> <?php } ?>
@ -91,7 +82,7 @@ class ExerciseShowFunctions {
<?php if(!api_is_allowed_to_edit(null,true) && $feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) {?> <?php if(!api_is_allowed_to_edit(null,true) && $feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) {?>
<td> <td>
<?php <?php
$comm = ExerciseShowFunctions::get_comments($id,$questionId); $comm = get_comments($id,$questionId);
?> ?>
</td> </td>
<?php }?> <?php }?>
@ -174,8 +165,7 @@ class ExerciseShowFunctions {
* @param boolean Whether to show the answer comment or not * @param boolean Whether to show the answer comment or not
* @return void * @return void
*/ */
function display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect, $id, $questionId, $ans) function display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect, $id, $questionId, $ans) {
{
global $feedback_type; global $feedback_type;
?> ?>
<tr> <tr>
@ -216,7 +206,7 @@ class ExerciseShowFunctions {
</td> </td>
<?php <?php
if ($ans==1) { if ($ans==1) {
$comm = ExerciseShowFunctions::get_comments($id,$questionId); $comm = get_comments($id,$questionId);
} }
?> ?>
<?php } else { ?> <?php } else { ?>
@ -225,141 +215,4 @@ class ExerciseShowFunctions {
</tr> </tr>
<?php <?php
} }
/**
* This function gets the comments of an exercise
*
* @param int $id
* @param int $question_id
* @return str the comment
*/
function get_comments($id,$question_id)
{
global $TBL_TRACK_ATTEMPT;
$sql = "SELECT teacher_comment FROM ".$TBL_TRACK_ATTEMPT." where exe_id='".Database::escape_string($id)."' and question_id = '".Database::escape_string($question_id)."' ORDER by question_id";
$sqlres = Database::query($sql);
$comm = Database::result($sqlres,0,"teacher_comment");
return $comm;
}
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 = '<html><head>
<link rel="stylesheet" href="'.api_get_path(WEB_CODE_PATH).'css/'.api_get_setting('stylesheets').'/default.css" type="text/css">
<meta content="text/html; charset='.$mycharset.'" http-equiv="content-type"></head>';
if(count($arrques)>0) {
$msg .= '<body>
<p>'.get_lang('OpenQuestionsAttempted').' :
</p>
<p>'.get_lang('AttemptDetails').' : <br />
</p>
<table width="730" height="136" border="0" cellpadding="3" cellspacing="3">
<tr>
<td width="229" valign="top"><h2>&nbsp;&nbsp;'.get_lang('CourseName').'</h2></td>
<td width="469" valign="top"><h2>#course#</h2></td>
</tr>
<tr>
<td width="229" valign="top" class="outerframe">&nbsp;&nbsp;'.get_lang('TestAttempted').'</span></td>
<td width="469" valign="top" class="outerframe">#exercise#</td>
</tr>
<tr>
<td valign="top">&nbsp;&nbsp;<span class="style10">'.get_lang('StudentName').'</span></td>
<td valign="top" >#firstName# #lastName#</td>
</tr>
<tr>
<td valign="top" >&nbsp;&nbsp;'.get_lang('StudentEmail').' </td>
<td valign="top"> #mail#</td>
</tr></table>
<p><br />'.get_lang('OpenQuestionsAttemptedAre').' :</p>
<table width="730" height="136" border="0" cellpadding="3" cellspacing="3">';
for($i=0;$i<sizeof($arrques);$i++) {
$msg.='
<tr>
<td width="220" valign="top" bgcolor="#E5EDF8">&nbsp;&nbsp;<span class="style10">'.get_lang('Question').'</span></td>
<td width="473" valign="top" bgcolor="#F3F3F3"><span class="style16"> #questionName#</span></td>
</tr>
<tr>
<td width="220" valign="top" bgcolor="#E5EDF8">&nbsp;&nbsp;<span class="style10">'.get_lang('Answer').' </span></td>
<td valign="top" bgcolor="#F3F3F3"><span class="style16"> #answer#</span></td>
</tr>';
$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.='</table><br>
<span class="style16">'.get_lang('ClickToCommentAndGiveFeedback').',<br />
<a href="#url#">#url#</a></span></body></html>';
$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 .= '<body>
<p>'.get_lang('ExerciseAttempted').' <br />
</p>
<table width="730" height="136" border="0" cellpadding="3" cellspacing="3">
<tr>
<td width="229" valign="top"><h2>&nbsp;&nbsp;'.get_lang('CourseName').'</h2></td>
<td width="469" valign="top"><h2>#course#</h2></td>
</tr>
<tr>
<td width="229" valign="top" class="outerframe">&nbsp;&nbsp;'.get_lang('TestAttempted').'</span></td>
<td width="469" valign="top" class="outerframe">#exercise#</td>
</tr>
<tr>
<td valign="top">&nbsp;&nbsp;<span class="style10">'.get_lang('StudentName').'</span></td>
'.(api_is_western_name_order() ? '<td valign="top" >#firstName# #lastName#</td>' : '<td valign="top" >#lastName# #firstName#</td>').'
</tr>
<tr>
<td valign="top" >&nbsp;&nbsp;'.get_lang('StudentEmail').' </td>
<td valign="top"> #mail#</td>
</tr></table>';
$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.='<br />
<span class="style16">'.get_lang('ClickToCommentAndGiveFeedback').',<br />
<a href="#url#">#url#</a></span></body></html>';
$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));
}
}
} }
Loading…
Cancel
Save