'.stripslashes($user_tags[$i]).'';
+ }
+ else
+ {
+ // adds a tabulation if no word has been typed by the student
+ $answer.=' ';
+ }
+ }
+ else
+ { // multiple fill in blank magic
+ if (in_array($user_tags[$i],$correct_tags))
+ {
+ $chosen_list[]=$user_tags[$i];
+ $correct_tags=array_diff($correct_tags,$chosen_list);
+
+ // gives the related weighting to the student
+ $questionScore+=$answerWeighting[$i-1];
+ // increments total score
+ $totalScore+=$answerWeighting[$i-1];
+ // adds the word in green at the end of the string
+ $answer.=stripslashes($user_tags[$i]);
+ } // else if the word entered by the student IS NOT the same as the one defined by the professor
+ elseif(!empty($user_tags[$i]))
+ {
+ // adds the word in red at the end of the string, and strikes it
+ $answer.=''.stripslashes($user_tags[$i]).'';
+ }
+ else
+ {
+ // adds a tabulation if no word has been typed by the student
+ $answer.=' ';
+ }
+ }
+ // adds the correct word, followed by ] to close the blank
+ $answer.=' / '.$real_correct_tags[$i].']';
+ $answer.=$real_text[$i];
+ }
+
+ /*
+ $answer='';
+ // the loop will stop at the end of the text
+ while(1)
+ {
+ // quits the loop if there are no more blanks
+ if(($pos = strpos($temp,'[')) === false)
{
- // gives the related weighting to the student
- $questionScore+=$answerWeighting[$j];
+ // adds the end of the text
+ $answer.=$temp;
+ // TeX parsing
+ $texstring = api_parse_tex($texstring);
+ $answer=str_replace("{texcode}",$texstring,$answer);
+ break;
+ }
- // increments total score
- $totalScore+=$answerWeighting[$j];
+ // adds the piece of text that is before the blank and ended by [
+ $answer.=substr($temp,0,$pos+1);
+ $temp=substr($temp,$pos+1);
- // adds the word in green at the end of the string
- $answer.=stripslashes($choice[$j]);
+ // quits the loop if there are no more blanks
+ if(($pos = strpos($temp,']')) === false)
+ {
+ // adds the end of the text
+ $answer.=$temp;
+ break;
}
- // else if the word entered by the student IS NOT the same as the one defined by the professor
- elseif(!empty($choice[$j]))
+
+ $choice[$j]=trim($choice[$j]);
+
+ if (!$multiple_answer_set)
+ {
+ // if the word entered by the student IS the same as the one defined by the professor
+ if(strtolower(substr($temp,0,$pos)) == stripslashes(strtolower($choice[$j])))
+ {
+ // 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
+ $answer.=stripslashes($choice[$j]);
+ }
+ }
+ else
+ {
+
+ }
+
+ // else if the word entered by the student IS NOT the same as the one defined by the professor
+ if(!empty($choice[$j]))
{
// adds the word in red at the end of the string, and strikes it
$answer.=''.stripslashes($choice[$j]).'';
@@ -576,6 +712,7 @@ $exerciseTitle=api_parse_tex($exerciseTitle);
$temp=substr($temp,$pos+1);
}
+ */
break;
// for free answer
diff --git a/main/exercice/exercise_show.php b/main/exercice/exercise_show.php
index f71c3f4ae3..4526a5a07a 100644
--- a/main/exercice/exercise_show.php
+++ b/main/exercice/exercise_show.php
@@ -1,27 +1,30 @@
selectId(); //added by priya saini
// destruction of the Question object
- unset($objQuestionTmp);
+ unset($objQuestionTmp);
@@ -551,74 +555,162 @@ $result =api_sql_query($query, __FILE__, __LINE__);
$objAnswerTmp=new Answer($questionId);
$nbrAnswers=$objAnswerTmp->selectNbrAnswers();
$questionScore=0;
+
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);
+
+ // the question is encoded like this
+ // [A] B [C] D [E] F::10,10,10@1
+ // number 1 before the "@" means that is a multiple fill in blank question
+ // [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
+ $multiple=explode('@',$answer);
+
+ // is multiple fill blank or not
+ $multiple_answer_set=false;
+ if ($multiple[1]==1)
+ {
+ $multiple_answer_set=true;
+ }
+
+ list($answer,$answerWeighting)=explode('::',$multiple[0]);
+
// splits weightings that are joined with a comma
$answerWeighting=explode(',',$answerWeighting);
// we save the answer because it will be modified
$temp=$answer;
+
// TeX parsing
// 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}
$temp=str_replace($texstring,'{texcode}',$temp);
- }
+ }
$j=0;
// the loop will stop at the end of the text
$i=0;
- while(1)
+ //normal fill in blank
+ if (!$multiple_answer_set)
+ {
+ while(1)
{
- // quits the loop if there are no more blanks
- if(($pos = strpos($temp,'[')) === false)
+ // quits the loop if there are no more blanks
+ if(($pos = strpos($temp,'[')) === false)
{
- // adds the end of the text
- $answer.=$temp;
- // TeX parsing
- $texstring = api_parse_tex($texstring);
- break;
+ // adds the end of the text
+ $answer.=$temp;
+ // TeX parsing
+ $texstring = api_parse_tex($texstring);
+ break;
}
- $temp=substr($temp,$pos+1);
- // quits the loop if there are no more blanks
- if(($pos = strpos($temp,']')) === false)
+ $temp=substr($temp,$pos+1);
+ // quits the loop if there are no more blanks
+ if(($pos = strpos($temp,']')) === false)
{
break;
}
- $queryfill = "select answer from ".$TBL_TRACK_ATTEMPT." where exe_id = '".Database::escape_string($id)."' and question_id= '".Database::escape_string($questionId)."'";
- $resfill = api_sql_query($queryfill, __FILE__, __LINE__);
- $str=mysql_result($resfill,0,"answer");
- preg_match_all ('#\[([^[/]*)/#', $str, $arr);
- $choice = $arr[1];
- $choice[$j]=trim($choice[$j]);
- // if the word entered by the student IS the same as the one defined by the professor
- if(strtolower(substr($temp,0,$pos)) == stripslashes(strtolower($choice[$j])))
+
+ $queryfill = "select answer from ".$TBL_TRACK_ATTEMPT." where exe_id = '".Database::escape_string($id)."' and question_id= '".Database::escape_string($questionId)."'";
+ $resfill = api_sql_query($queryfill, __FILE__, __LINE__);
+ $str=mysql_result($resfill,0,"answer");
+ preg_match_all ('#\[([^[/]*)/#', $str, $arr);
+
+ $choice = $arr[1];
+ $choice[$j]=trim($choice[$j]);
+ // if the word entered by the student IS the same as the one defined by the professor
+ if(strtolower(substr($temp,0,$pos)) == stripslashes(strtolower($choice[$j])))
{
- // gives the related weighting to the student
- $questionScore+=$answerWeighting[$j];
- // increments total score
- $totalScore+=$answerWeighting[$j];
+ // 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
- $j++;
- $temp=substr($temp,$pos+1);
- $i=$i+1;
- } $answer = $str;
+ // else if the word entered by the student IS NOT the same as the one defined by the professor
+ $j++;
+ $temp=substr($temp,$pos+1);
+ $i=$i+1;
+ }
+ $answer = $str;
+ }
+ else
+ { //multiple fill in blank
+ while(1)
+ {
+ // quits the loop if there are no more blanks
+ if(($pos = strpos($temp,'[')) === false)
+ {
+ // adds the end of the text
+ $answer.=$temp;
+ // TeX parsing
+ $texstring = api_parse_tex($texstring);
+ //$answer=str_replace("{texcode}",$texstring,$answer);
+ break;
+ }
+ // adds the piece of text that is before the blank and ended by [
+ $real_text[]=substr($temp,0,$pos+1);
+ $answer.=substr($temp,0,$pos+1);
+ $temp=substr($temp,$pos+1);
+
+ // quits the loop if there are no more blanks
+ if(($pos = strpos($temp,']')) === false)
+ {
+ // adds the end of the text
+ //$answer.=$temp;
+ break;
+ }
+
+ $queryfill = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT." WHERE exe_id = '".Database::escape_string($id)."' and question_id= '".Database::escape_string($questionId)."'";
+ $resfill = api_sql_query($queryfill, __FILE__, __LINE__);
+ $str=mysql_result($resfill,0,"answer");
+ preg_match_all ('#\[([^[/]*)/#', $str, $arr);
+ $choice = $arr[1];
+
+ $choice[$j]=trim($choice[$j]);
+ $user_tags[]=stripslashes(strtolower($choice[$j]));
+ $correct_tags[]=strtolower(substr($temp,0,$pos));
+
+ $j++;
+ $temp=substr($temp,$pos+1);
+ $i=$i+1;
+ }
+ /*
+ echo "";
+ print_r($user_tags);
+ echo "
";
+ print_r($correct_tags);
+ print_r($answerWeighting);
+ echo "
";
+ */
+ $answer='';
+ for($i=0;$i
- | |
+ |
+ }
+ ?>
type = FILL_IN_BLANKS;
}
@@ -55,21 +60,35 @@ class FillBlanks extends Question {
* function which redifines Question::createAnswersForm
* @param the formvalidator instance
*/
- function createAnswersForm ($form) {
-
-
-
+ function createAnswersForm ($form)
+ {
$defaults = array();
if(!empty($this->id))
{
$objAnswer = new answer($this->id);
- $a_answer = explode('::', $objAnswer->selectAnswer(1));
+
+ // the question is encoded like this
+ // [A] B [C] D [E] F::10,10,10@1
+ // number 1 before the "@" means that is a multiple fill in blank question
+ // [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
+
+ $is_set_multiple = explode('@', $objAnswer->selectAnswer(1));
+ if ($is_set_multiple[1])
+ {
+ $defaults['multiple_answer']=1;
+ }
+ else
+ {
+ $defaults['multiple_answer']=0;
+ }
+ $a_answer = explode('::', $is_set_multiple[0]);
$defaults['answer'] = $a_answer[0];
$a_weightings = explode(',',$a_answer[1]);
}
else
- {
+ {
$defaults['answer'] = get_lang('DefaultTextInBlanks');
}
@@ -103,7 +122,6 @@ class FillBlanks extends Question {
foreach($a_weightings as $i=>$weighting)
{
echo 'document.getElementById("weighting['.$i.']").value = "'.$weighting.'";';
-
}
}
echo '}
@@ -118,10 +136,13 @@ class FillBlanks extends Question {
$form -> addElement ('textarea', 'answer',get_lang('Answer'),'id="answer" cols="65" rows="6" onkeyup="updateBlanks(this)"');
$form -> addRule ('answer',get_lang('GiveText'),'required');
$form -> addRule ('answer',get_lang('DefineBlanks'),'regex','/\[.*\]/');
-
-
+
+ //added multiple answers
+ $form -> addElement ('checkbox','multiple_answer','', get_lang('FillInBlankMultiple'));
+
$form -> addElement('html','');
+
$form -> setDefaults($defaults);
}
@@ -140,9 +161,11 @@ class FillBlanks extends Question {
// get the blanks weightings
$nb = preg_match_all('/\[[^\]]*\]/', $answer, $blanks);
- if(isset($_GET['editQuestion'])){
+ if(isset($_GET['editQuestion']))
+ {
$this -> weighting = 0;
}
+
if($nb>0)
{
$answer .= '::';
@@ -153,6 +176,9 @@ class FillBlanks extends Question {
}
$answer = substr($answer,0,-1);
}
+ $is_multiple = $form -> getSubmitValue('multiple_answer');
+ $answer.='@'.$is_multiple;
+
$this -> save();
$objAnswer = new answer($this->id);
$objAnswer->createAnswer($answer,0,'',0,'');