diff --git a/main/exercice/exercise.lib.php b/main/exercice/exercise.lib.php
index 9d9aba32c9..13928775d0 100644
--- a/main/exercice/exercise.lib.php
+++ b/main/exercice/exercise.lib.php
@@ -27,35 +27,35 @@ require_once dirname(__FILE__).'/../inc/lib/fckeditor/fckeditor.php';
* */
function showQuestion($questionId, $only_questions = false, $origin = false, $current_item = '', $show_title = true, $freeze = false, $user_choice = array(), $show_comment = false, $exercise_feedback = null, $show_answers = false) {
- // Text direction for the current language
- $is_ltr_text_direction = api_get_text_direction() != 'rtl';
+ // Text direction for the current language
+ $is_ltr_text_direction = api_get_text_direction() != 'rtl';
- // Change false to true in the following line to enable answer hinting
- $debug_mark_answer = $show_answers; //api_is_allowed_to_edit() && false;
+ // Change false to true in the following line to enable answer hinting
+ $debug_mark_answer = $show_answers; //api_is_allowed_to_edit() && false;
- // Reads question information
- if (!$objQuestionTmp = Question::read($questionId)) {
- // Question not found
- return false;
- }
+ // Reads question information
+ if (!$objQuestionTmp = Question::read($questionId)) {
+ // Question not found
+ return false;
+ }
if ($exercise_feedback != EXERCISE_FEEDBACK_TYPE_END) {
$show_comment = false;
}
- $answerType = $objQuestionTmp->selectType();
- $pictureName = $objQuestionTmp->selectPicture();
+ $answerType = $objQuestionTmp->selectType();
+ $pictureName = $objQuestionTmp->selectPicture();
- if ($answerType != HOT_SPOT && $answerType != HOT_SPOT_DELINEATION) {
- // Question is not a hotspot
+ if ($answerType != HOT_SPOT && $answerType != HOT_SPOT_DELINEATION) {
+ // Question is not a hotspot
- if (!$only_questions) {
- $questionDescription = $objQuestionTmp->selectDescription();
- if ($show_title) {
- Testcategory::displayCategoryAndTitle($objQuestionTmp->id); //
- echo Display::div($current_item.'. '.$objQuestionTmp->selectTitle(), array('class'=>'question_title'));
- }
- if (!empty($questionDescription)) {
+ if (!$only_questions) {
+ $questionDescription = $objQuestionTmp->selectDescription();
+ if ($show_title) {
+ Testcategory::displayCategoryAndTitle($objQuestionTmp->id); //
+ echo Display::div($current_item.'. '.$objQuestionTmp->selectTitle(), array('class'=>'question_title'));
+ }
+ if (!empty($questionDescription)) {
echo Display::div($questionDescription, array('class'=>'question_description'));
}
}
@@ -67,104 +67,104 @@ function showQuestion($questionId, $only_questions = false, $origin = false, $cu
echo '
';
- $s = '';
+ $s = '';
- // construction of the Answer object (also gets all answers details)
- $objAnswerTmp = new Answer($questionId);
+ // construction of the Answer object (also gets all answers details)
+ $objAnswerTmp = new Answer($questionId);
- $nbrAnswers = $objAnswerTmp->selectNbrAnswers();
+ $nbrAnswers = $objAnswerTmp->selectNbrAnswers();
$course_id = api_get_course_int_id();
$quiz_question_options = Question::readQuestionOption($questionId, $course_id);
- // For "matching" type here, we need something a little bit special
- // because the match between the suggestions and the answers cannot be
- // done easily (suggestions and answers are in the same table), so we
- // have to go through answers first (elems with "correct" value to 0).
- $select_items = array();
- //This will contain the number of answers on the left side. We call them
- // suggestions here, for the sake of comprehensions, while the ones
- // on the right side are called answers
- $num_suggestions = 0;
-
- if ($answerType == MATCHING) {
+ // For "matching" type here, we need something a little bit special
+ // because the match between the suggestions and the answers cannot be
+ // done easily (suggestions and answers are in the same table), so we
+ // have to go through answers first (elems with "correct" value to 0).
+ $select_items = array();
+ //This will contain the number of answers on the left side. We call them
+ // suggestions here, for the sake of comprehensions, while the ones
+ // on the right side are called answers
+ $num_suggestions = 0;
+
+ if ($answerType == MATCHING) {
$s .= '
';
- $x = 1; //iterate through answers
- $letter = 'A'; //mark letters for each answer
- $answer_matching = $cpt1 = array();
-
- for ($answerId=1; $answerId <= $nbrAnswers; $answerId++) {
- $answerCorrect = $objAnswerTmp->isCorrect($answerId);
- $numAnswer = $objAnswerTmp->selectAutoId($answerId);
- $answer=$objAnswerTmp->selectAnswer($answerId);
- if ($answerCorrect==0) {
- // options (A, B, C, ...) that will be put into the list-box
- // have the "correct" field set to 0 because they are answer
- $cpt1[$x] = $letter;
- $answer_matching[$x]=$objAnswerTmp->selectAnswerByAutoId($numAnswer);
- $x++; $letter++;
- }
- }
- $i = 1;
-
- $select_items[0]['id'] = 0;
- $select_items[0]['letter'] = '--';
- $select_items[0]['answer'] = '';
-
- foreach ($answer_matching as $id => $value) {
- $select_items[$i]['id'] = $value['id'];
- $select_items[$i]['letter'] = $cpt1[$id];
- $select_items[$i]['answer'] = $value['answer'];
- $i ++;
- }
- $num_suggestions = ($nbrAnswers - $x) + 1;
-
- } elseif ($answerType == FREE_ANSWER) {
- $fck_content = isset($user_choice[0]) && !empty($user_choice[0]['answer']) ? $user_choice[0]['answer']:null;
-
- $oFCKeditor = new FCKeditor("choice[".$questionId."]") ;
-
- $oFCKeditor->ToolbarSet = 'TestFreeAnswer';
- $oFCKeditor->Width = '100%';
- $oFCKeditor->Height = '200';
- $oFCKeditor->Value = $fck_content;
+ $x = 1; //iterate through answers
+ $letter = 'A'; //mark letters for each answer
+ $answer_matching = $cpt1 = array();
+
+ for ($answerId=1; $answerId <= $nbrAnswers; $answerId++) {
+ $answerCorrect = $objAnswerTmp->isCorrect($answerId);
+ $numAnswer = $objAnswerTmp->selectAutoId($answerId);
+ $answer=$objAnswerTmp->selectAnswer($answerId);
+ if ($answerCorrect==0) {
+ // options (A, B, C, ...) that will be put into the list-box
+ // have the "correct" field set to 0 because they are answer
+ $cpt1[$x] = $letter;
+ $answer_matching[$x]=$objAnswerTmp->selectAnswerByAutoId($numAnswer);
+ $x++; $letter++;
+ }
+ }
+ $i = 1;
+
+ $select_items[0]['id'] = 0;
+ $select_items[0]['letter'] = '--';
+ $select_items[0]['answer'] = '';
+
+ foreach ($answer_matching as $id => $value) {
+ $select_items[$i]['id'] = $value['id'];
+ $select_items[$i]['letter'] = $cpt1[$id];
+ $select_items[$i]['answer'] = $value['answer'];
+ $i ++;
+ }
+ $num_suggestions = ($nbrAnswers - $x) + 1;
+
+ } elseif ($answerType == FREE_ANSWER) {
+ $fck_content = isset($user_choice[0]) && !empty($user_choice[0]['answer']) ? $user_choice[0]['answer']:null;
+
+ $oFCKeditor = new FCKeditor("choice[".$questionId."]") ;
+
+ $oFCKeditor->ToolbarSet = 'TestFreeAnswer';
+ $oFCKeditor->Width = '100%';
+ $oFCKeditor->Height = '200';
+ $oFCKeditor->Value = $fck_content;
$s .= $oFCKeditor->CreateHtml();
- } elseif ($answerType == ORAL_EXPRESSION) {
- //Add nanog
- if (api_get_setting('enable_nanogong') == 'true') {
- require_once api_get_path(LIBRARY_PATH).'nanogong.lib.php';
- //@todo pass this as a parameter
- global $exercise_stat_info, $exerciseId, $exe_id;
-
- if (!empty($exercise_stat_info)) {
- $params = array(
- 'exercise_id' => $exercise_stat_info['exe_exo_id'],
- 'exe_id' => $exercise_stat_info['exe_id'],
- 'question_id' => $questionId
- );
- } else {
- $params = array(
- 'exercise_id' => $exerciseId,
- 'exe_id' => 'temp_exe',
- 'question_id' => $questionId
- );
- }
- $nano = new Nanogong($params);
- echo $nano->show_button();
- }
-
- $oFCKeditor = new FCKeditor("choice[".$questionId."]") ;
- $oFCKeditor->ToolbarSet = 'TestFreeAnswer';
- $oFCKeditor->Width = '100%';
- $oFCKeditor->Height = '150';
- $oFCKeditor->ToolbarStartExpanded = false;
- $oFCKeditor->Value = '' ;
- $s .= $oFCKeditor->CreateHtml();
- }
-
- // Now navigate through the possible answers, using the max number of
- // answers for the question as a limiter
- $lines_count = 1; // a counter for matching-type answers
+ } elseif ($answerType == ORAL_EXPRESSION) {
+ //Add nanog
+ if (api_get_setting('enable_nanogong') == 'true') {
+ require_once api_get_path(LIBRARY_PATH).'nanogong.lib.php';
+ //@todo pass this as a parameter
+ global $exercise_stat_info, $exerciseId, $exe_id;
+
+ if (!empty($exercise_stat_info)) {
+ $params = array(
+ 'exercise_id' => $exercise_stat_info['exe_exo_id'],
+ 'exe_id' => $exercise_stat_info['exe_id'],
+ 'question_id' => $questionId
+ );
+ } else {
+ $params = array(
+ 'exercise_id' => $exerciseId,
+ 'exe_id' => 'temp_exe',
+ 'question_id' => $questionId
+ );
+ }
+ $nano = new Nanogong($params);
+ echo $nano->show_button();
+ }
+
+ $oFCKeditor = new FCKeditor("choice[".$questionId."]") ;
+ $oFCKeditor->ToolbarSet = 'TestFreeAnswer';
+ $oFCKeditor->Width = '100%';
+ $oFCKeditor->Height = '150';
+ $oFCKeditor->ToolbarStartExpanded = false;
+ $oFCKeditor->Value = '' ;
+ $s .= $oFCKeditor->CreateHtml();
+ }
+
+ // Now navigate through the possible answers, using the max number of
+ // answers for the question as a limiter
+ $lines_count = 1; // a counter for matching-type answers
if ($answerType == MULTIPLE_ANSWER_TRUE_FALSE || $answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE) {
$header = Display::tag('th', get_lang('Options'));
@@ -197,38 +197,38 @@ function showQuestion($questionId, $only_questions = false, $origin = false, $cu
}
}
- for ($answerId=1; $answerId <= $nbrAnswers; $answerId++) {
- $answer = $objAnswerTmp->selectAnswer($answerId);
- $answerCorrect = $objAnswerTmp->isCorrect($answerId);
- $numAnswer = $objAnswerTmp->selectAutoId($answerId);
+ for ($answerId=1; $answerId <= $nbrAnswers; $answerId++) {
+ $answer = $objAnswerTmp->selectAnswer($answerId);
+ $answerCorrect = $objAnswerTmp->isCorrect($answerId);
+ $numAnswer = $objAnswerTmp->selectAutoId($answerId);
$comment = $objAnswerTmp->selectComment($answerId);
$attributes = array();
- // Unique answer
- if ($answerType == UNIQUE_ANSWER || $answerType == UNIQUE_ANSWER_NO_OPTION) {
- $input_id = 'choice-'.$questionId.'-'.$answerId;
- if (isset($user_choice[0]['answer']) && $user_choice[0]['answer'] == $numAnswer ) {
- $attributes = array('id' =>$input_id, 'checked'=>1, 'selected'=>1);
- } else {
- $attributes = array('id' =>$input_id);
- }
+ // Unique answer
+ if ($answerType == UNIQUE_ANSWER || $answerType == UNIQUE_ANSWER_NO_OPTION) {
+ $input_id = 'choice-'.$questionId.'-'.$answerId;
+ if (isset($user_choice[0]['answer']) && $user_choice[0]['answer'] == $numAnswer ) {
+ $attributes = array('id' =>$input_id, 'checked'=>1, 'selected'=>1);
+ } else {
+ $attributes = array('id' =>$input_id);
+ }
if ($debug_mark_answer) {
- if ($answerCorrect) {
- $attributes['checked'] = 1;
+ if ($answerCorrect) {
+ $attributes['checked'] = 1;
$attributes['selected'] = 1;
- }
- }
+ }
+ }
- $answer = Security::remove_XSS($answer, STUDENT);
+ $answer = Security::remove_XSS($answer, STUDENT);
- $s .= Display::input('hidden','choice2['.$questionId.']','0');
+ $s .= Display::input('hidden','choice2['.$questionId.']','0');
- $answer_input = '';
+ $answer_input = '';
if ($show_comment) {
$s .= '