* @version $Id: exercise.lib.php 13301 2007-09-27 03:47:39Z yannoo $ */ require("../inc/lib/fckeditor/fckeditor.php") ; function showQuestion($questionId, $onlyAnswers=false, $origin=false) { // 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(); $s="  "; $questionName=api_parse_tex($questionName); $s.=$questionName; $s.=" "; $questionDescription=api_parse_tex($questionDescription); $s.=$questionDescription; $s.=" "; if(!empty($pictureName)) { $s.=" "; } } // end if(!$onlyAnswers) // 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); // $upload_path = api_get_path(REL_COURSE_PATH).$_SESSION['_course']['path'].'/document/'; $oFCKeditor = new FCKeditor("choice[".$questionId."]") ; $oFCKeditor->BasePath = api_get_path(WEB_PATH) . 'main/inc/lib/fckeditor/' ; $oFCKeditor->Config['CustomConfigurationsPath'] = api_get_path(REL_PATH)."main/inc/lib/fckeditor/myconfig.js"; $oFCKeditor->Config['IMUploadPath'] = 'upload/test/'; $oFCKeditor->ToolbarSet = "Test"; $oFCKeditor->Width = '80%'; $oFCKeditor->Height = '300'; $oFCKeditor->Value = '' ; $TBL_LANGUAGES = Database::get_main_table(TABLE_MAIN_LANGUAGE); $sql="SELECT isocode FROM ".$TBL_LANGUAGES." WHERE english_name='".$_SESSION["_course"]["language"]."'"; $result_sql=api_sql_query($sql); $isocode_language=mysql_result($result_sql,0,0); $oFCKeditor->Config['DefaultLanguage'] = $isocode_language; $s .= "".$oFCKeditor->CreateHtml().""; //$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=strpos($answer,'[tex]'); $endlocations=strpos($answer,'[/tex]'); if($startlocations !== false && $endlocations !== false) { $texstring=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 $answer=ereg_replace('\[[^]]+\]','',nl2br($answer)); // 4. 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.=" "; $answer=api_parse_tex($answer); $s.=$answer; $s.=""; } // multiple answers elseif($answerType == MULTIPLE_ANSWER) { $s.=" "; $answer = api_parse_tex($answer); $s.=$answer; $s.=""; } // fill in blanks elseif($answerType == FILL_IN_BLANKS) { $s.="$answer"; } // 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.=" "; $answer=api_parse_tex($answer); $s.="
".$cpt2.". ".$answer."      "; if(isset($Select[$cpt2])) $s.=''.$Select[$cpt2]['Lettre'].'. '.$Select[$cpt2]['Reponse']; else $s.=' '; $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.="
  "; $s.=''.$Select[$cpt2]['Lettre'].'. '.$Select[$cpt2]['Reponse']; $s.="
"; $cpt2++; } // end while() } // end if() } } } // end for() // 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 .= '
  1. '.$objAnswerTmp->selectAnswer($answerId).'
  2. '; } $answer_list .= '
'; if(!$onlyAnswers) { $s="  "; $questionName=api_parse_tex($questionName); $s.=$questionName; $s.=" "; $questionDescription=api_parse_tex($questionDescription); $s.=$questionDescription; $s.=" "; } $canClick = isset($_GET['editQuestion']) ? '0' : (isset($_GET['modifyAnswers']) ? '0' : '1'); //$tes = isset($_GET['modifyAnswers']) ? '0' : '1'; //echo $tes; $s .= " "; $s .= '
'." $answer_list
"; echo $s; } echo " "; return $nbrAnswers; } ?>