@ -29,7 +29,7 @@
* @author Olivier Brouckaert, main author
* @author Olivier Brouckaert, main author
* @author Roan Embrechts, some refactoring
* @author Roan Embrechts, some refactoring
* @author Julio Montoya Armas switchable fill in blank option added
* @author Julio Montoya Armas switchable fill in blank option added
* @version $Id: exercise_result.php 15957 2008-08-08 08:23:59Z elixir_inter $
* @version $Id: exercise_result.php 15967 2008-08-10 06:40:40Z yannoo $
*
*
* @todo split more code up in functions, move functions to library?
* @todo split more code up in functions, move functions to library?
*/
*/
@ -649,51 +649,53 @@ $exerciseTitle=api_parse_tex($exerciseTitle);
$answer='';
$answer='';
$j=0;
$j=0;
$user_tags[]=array();
//initialise answer tags
$correct_tags[]=array();
$user_tags=array();
$correct_tags=array();
$real_text=array();
$real_text=array();
// the loop will stop at the end of the text
// the loop will stop at the end of the text
while(1)
while(1)
{
{
// quits the loop if there are no more blanks
// quits the loop if there are no more blanks (detect '[')
if(($pos = strpos($temp,'[')) === false)
if(($pos = strpos($temp,'[')) === false)
{
{
// adds the end of the text
// adds the end of the text
$answer. =$temp;
$answer=$temp;
// TeX parsing
// TeX parsing - replacement of texcode tags
$texstring = api_parse_tex($texstring);
$texstring = api_parse_tex($texstring);
$answer=str_replace("{texcode}",$texstring,$answer);
$answer=str_replace("{texcode}",$texstring,$answer);
break;
$real_text[] = $answer;
break; //no more "blanks", quit the loop
}
}
// adds the piece of text that is before the blank and ended by [
// adds the piece of text that is before the blank
$real_text[]=substr($temp,0,$pos+1);
//and ends with '[' into a general storage array
$real_text[]=substr($temp,0,$pos+1);
$answer.=substr($temp,0,$pos+1);
$answer.=substr($temp,0,$pos+1);
//take the string remaining (after the last "[" we found)
$temp=substr($temp,$pos+1);
$temp=substr($temp,$pos+1);
// quit the loop if there are no more blanks, and update $pos to the position of next ']'
// quits the loop if there are no more blanks
if(($pos = strpos($temp,']')) === false)
if(($pos = strpos($temp,']')) === false)
{
{
// adds the end of the text
// adds the end of the text
$answer.=$temp;
$answer.=$temp;
break;
break;
}
}
$choice[$j]=trim($choice[$j]);
$choice[$j]=trim($choice[$j]);
$user_tags[]=stripslashes(strtolower($choice[$j]));
$user_tags[]=stripslashes(strtolower($choice[$j]));
$correct_tags[]=strtolower(substr($temp,0,$pos));
//put the contents of the [] answer tag into correct_tags[]
$correct_tags[]=strtolower(substr($temp,0,$pos));
$j++;
$j++;
$temp=substr($temp,$pos+1);
$temp=substr($temp,$pos+1);
//$answer .= ']';
}
}
$answer='';
$answer='';
$real_correct_tags = $correct_tags;
$real_correct_tags = $correct_tags;
$chosen_list=array();
$chosen_list=array();
for($i=1 ;$i< count ( $ real_correct_tags ) ; $ i + + )
for($i=0 ;$i< count ( $ real_correct_tags ) ; $ i + + )
{
{
if ($i==1 )
if ($i==0 )
{
{
$answer.=$real_text[0];
$answer.=$real_text[0];
}
}
@ -703,9 +705,9 @@ $exerciseTitle=api_parse_tex($exerciseTitle);
if ($correct_tags[$i]==$user_tags[$i])
if ($correct_tags[$i]==$user_tags[$i])
{
{
// gives the related weighting to the student
// gives the related weighting to the student
$questionScore+=$answerWeighting[$i-1 ];
$questionScore+=$answerWeighting[$i];
// increments total score
// increments total score
$totalScore+=$answerWeighting[$i-1 ];
$totalScore+=$answerWeighting[$i];
// adds the word in green at the end of the string
// adds the word in green at the end of the string
$answer.=stripslashes($correct_tags[$i]);
$answer.=stripslashes($correct_tags[$i]);
}
}
@ -729,9 +731,9 @@ $exerciseTitle=api_parse_tex($exerciseTitle);
$correct_tags=array_diff($correct_tags,$chosen_list);
$correct_tags=array_diff($correct_tags,$chosen_list);
// gives the related weighting to the student
// gives the related weighting to the student
$questionScore+=$answerWeighting[$i-1 ];
$questionScore+=$answerWeighting[$i];
// increments total score
// increments total score
$totalScore+=$answerWeighting[$i-1 ];
$totalScore+=$answerWeighting[$i];
// adds the word in green at the end of the string
// adds the word in green at the end of the string
$answer.=stripslashes($user_tags[$i]);
$answer.=stripslashes($user_tags[$i]);
} // else if the word entered by the student IS NOT the same as the one defined by the professor
} // else if the word entered by the student IS NOT the same as the one defined by the professor
@ -748,7 +750,9 @@ $exerciseTitle=api_parse_tex($exerciseTitle);
}
}
// adds the correct word, followed by ] to close the blank
// adds the correct word, followed by ] to close the blank
$answer.=' / < font color = "green" > < b > '.$real_correct_tags[$i].'< / b > < / font > ]';
$answer.=' / < font color = "green" > < b > '.$real_correct_tags[$i].'< / b > < / font > ]';
$answer.=$real_text[$i];
if ( isset( $real_text[$i+1] ) ) {
$answer.=$real_text[$i+1];
}
}
}
break;
break;