* @version $Id: exercise.lib.php 20860 2009-05-20 00:09:00Z cvargas1 $ */ /** * @param int question id * @param boolean only answers * @param boolean origin i.e = learnpath * @param int current item from the list of questions * @param int number of total questions * */ require("../inc/lib/fckeditor/fckeditor.php") ; function showQuestion($questionId, $onlyAnswers=false, $origin=false,$current_item, $total_item) { if (!ereg("MSIE", $_SERVER["HTTP_USER_AGENT"])) { echo ''; echo ''; } // reads question informations if(!$objQuestionTmp = Question::read($questionId)) { // question not found return false; } $answerType=$objQuestionTmp->selectType(); $pictureName=$objQuestionTmp->selectPicture(); if ($answerType != HOT_SPOT) // Question is not of type hotspot { if(!$onlyAnswers) { $questionName=$objQuestionTmp->selectTitle(); $questionDescription=$objQuestionTmp->selectDescription(); $questionName=api_parse_tex($questionName); $s="
".get_lang('Question').' '; $s.=$current_item; //@todo I need the get the feedback type //if($answerType != 1) //$s.=' / '.$total_item; echo $s; echo ' : '; echo $questionName.'
'; $s=''; $s.="
"; $questionDescription=api_parse_tex($questionDescription); $s.=$questionDescription; $s.="
"; if(!empty($pictureName)) { $s.=" "; } } $s.= ''; if (!ereg("MSIE",$_SERVER["HTTP_USER_AGENT"])) { $s.=""; $s.="
"; } else { $option_ie="margin-left:10px"; } $s.=""; // construction of the Answer object $objAnswerTmp=new Answer($questionId); $nbrAnswers=$objAnswerTmp->selectNbrAnswers(); // only used for the answer type "Matching" if($answerType == MATCHING) { $cpt1='A'; $cpt2=1; $Select=array(); } elseif($answerType == FREE_ANSWER) { #$comment = $objAnswerTmp->selectComment(1); // $oFCKeditor = new FCKeditor("choice[".$questionId."]") ; $oFCKeditor->ToolbarSet = "FreeAnswer"; $oFCKeditor->Width = '100%'; $oFCKeditor->Height = '200'; $oFCKeditor->Value = '' ; $s .= ""; //$s.=""; } for($answerId=1;$answerId <= $nbrAnswers;$answerId++) { $answer=$objAnswerTmp->selectAnswer($answerId); $answerCorrect=$objAnswerTmp->isCorrect($answerId); if($answerType == FILL_IN_BLANKS) { // splits text and weightings that are joined with the character '::' list($answer)=explode('::',$answer); // because [] is parsed here we follow this procedure: // 1. find everything between the [tex] and [/tex] tags $startlocations=api_strpos($answer,'[tex]'); $endlocations=api_strpos($answer,'[/tex]'); if($startlocations !== false && $endlocations !== false) { $texstring=api_substr($answer,$startlocations,$endlocations-$startlocations+6); // 2. replace this by {texcode} $answer=str_replace($texstring,'{texcode}',$answer); } // 3. do the normal matching parsing // replaces [blank] by an input field //getting the matches $answer=api_ereg_replace('\[[^]]+\]','',($answer)); // Change input size /* preg_match_all('/\[[^]]+]/',$answer,$matches); $answer=ereg_replace('\[[^]]+\]','',($answer)); // 4. resize the input foreach($matches[0] as $match) { $answer_len = strlen($match)-2; //we will only replace 1 item // echo implode("replace term", explode("search term", "input", $limit)); if ($answer_len <= 5) { $answer = (implode("5", explode("@@", $answer, 2))); } elseif($answer_len <= 10) { $answer = (implode("10", explode("@@", $answer, 2))); } elseif($answer_len <= 20) { $answer = (implode("20", explode("@@", $answer, 2))); } elseif($answer_len <= 30) { $answer = (implode("30", explode("@@", $answer, 2))); } elseif($answer_len <= 40) { $answer = (implode("40", explode("@@", $answer, 2))); } elseif($answer_len > 40) { $answer = (implode("55", explode("@@", $answer, 2))); } } */ // 5. replace the {texcode by the api_pare_tex parsed code} $texstring = api_parse_tex($texstring); $answer=str_replace("{texcode}",$texstring,$answer); } // unique answer if($answerType == UNIQUE_ANSWER) { $s.=""; } elseif($answerType == MULTIPLE_ANSWER) { // multiple answers $s.=""; } // fill in blanks elseif($answerType == FILL_IN_BLANKS) { $s.=""; } // free answer // matching else { if(!$answerCorrect) { // options (A, B, C, ...) that will be put into the list-box $Select[$answerId]['Lettre']=$cpt1++; // answers that will be shown at the right side $answer = api_parse_tex($answer); $Select[$answerId]['Reponse']=$answer; } else { $s.=" "; $cpt2++; // if the left side of the "matching" has been completely shown if($answerId == $nbrAnswers) { // if it remains answers to shown at the right side while(isset($Select[$cpt2])) { $s.=""; $cpt2++; } // end while() } // end if() } } } // end for() if (!ereg("MSIE", $_SERVER["HTTP_USER_AGENT"])) { $s .= '
".$oFCKeditor->CreateHtml()."
"; $answer=api_parse_tex($answer); $s.=$answer; $s.="
"; $answer = api_parse_tex($answer); $s.=$answer; $s.="
$answer
"; $answer=api_parse_tex($answer); $s.="
".$cpt2.". ".$answer."      "; if(isset($Select[$cpt2])) $s.=''.$Select[$cpt2]['Lettre'].'. '.$Select[$cpt2]['Reponse']; else $s.=' '; $s.="
  "; $s.=''.$Select[$cpt2]['Lettre'].'. '.$Select[$cpt2]['Reponse']; $s.="
'; } $s .= '
'; // destruction of the Answer object unset($objAnswerTmp); // destruction of the Question object unset($objQuestionTmp); if ($origin != 'export') { echo $s; } else { return($s); } } elseif ($answerType == HOT_SPOT) // Question is of type HOT_SPOT { $questionName=$objQuestionTmp->selectTitle(); $questionDescription=$objQuestionTmp->selectDescription(); // Get the answers, make a list $objAnswerTmp=new Answer($questionId); $nbrAnswers=$objAnswerTmp->selectNbrAnswers(); $answer_list = '
'.get_lang('HotspotZones').'
'; for($answerId=1;$answerId <= $nbrAnswers;$answerId++) { $answer_list .= '
'.$answerId.'.- '.$objAnswerTmp->selectAnswer($answerId).'

'; } $answer_list .= '
'; if(!$onlyAnswers) { $s="
".get_lang('Question').' '; $s.=$current_item; //@todo I need to the get the feedback type //if($answerType == 2) // $s.=' / '.$total_item; echo $s; echo ': '; $s =$questionName.'
'; $s.=""; } $canClick = isset($_GET['editQuestion']) ? '0' : (isset($_GET['modifyAnswers']) ? '0' : '1'); //$tes = isset($_GET['modifyAnswers']) ? '0' : '1'; //echo $tes; $s .= ""; $s .= '"; echo $s; } echo "
"; $questionDescription=api_parse_tex($questionDescription); $s.=$questionDescription; $s.="
'." $answer_list
"; return $nbrAnswers; } ?>