Source for file exercise.lib.php
Documentation is available at exercise.lib.php
DOKEOS - elearning and course management software
For a full list of contributors, see documentation/credits.html
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
See "documentation/licence.html" more details.
Rue des Palais 44 Paleizenstraat
B-1030 Brussels - Belgium
* shows a question and its answers
* @package dokeos.exercise
* @author Olivier Brouckaert <oli.brouckaert@skynet.be>
* @version $Id: exercise.lib.php 15412 2008-05-26 13:56:24Z elixir_inter $
require ("../inc/lib/fckeditor/fckeditor.php") ;
function showQuestion($questionId, $onlyAnswers= false, $origin= false)
// reads question informations
$answerType= $objQuestionTmp->selectType();
$pictureName= $objQuestionTmp->selectPicture();
if ($answerType != HOT_SPOT) // Question is not of type hotspot
$questionName= $objQuestionTmp->selectTitle();
$questionDescription= $objQuestionTmp->selectDescription();
<td valign='top' colspan='2'>
$s.= $questionDescription;
<td align='center' colspan='2'><img src='../document/download.php?doc_url=%2Fimages%2F'". $pictureName. "' border='0'></td>
} // end if(!$onlyAnswers)
// construction of the Answer object
$objAnswerTmp= new Answer($questionId);
$nbrAnswers= $objAnswerTmp->selectNbrAnswers();
// only used for the answer type "Matching"
#$comment = $objAnswerTmp->selectComment(1);
$oFCKeditor = new FCKeditor("choice[". $questionId. "]") ;
$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 = '' ;
$sql= "SELECT isocode FROM ". $TBL_LANGUAGES. " WHERE english_name='". $_SESSION["_course"]["language"]. "'";
$oFCKeditor->Config['DefaultLanguage'] = $isocode_language;
$s .= "<tr><td colspan='2'>". $oFCKeditor->CreateHtml(). "</td></tr>";
//$s.="<tr><td colspan='2'><textarea cols='80' rows='10' name='choice[".$questionId."]'>$answer</textarea></td></tr>";
for($answerId= 1;$answerId <= $nbrAnswers;$answerId++ )
$answer= $objAnswerTmp->selectAnswer($answerId);
$answerCorrect= $objAnswerTmp->isCorrect($answerId);
// 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}
// 3. do the normal matching parsing
// replaces [blank] by an input field
$answer= ereg_replace('\[[^]]+\]','<input type="text" name="choice['. $questionId. '][]" size="10">',nl2br($answer));
// 4. replace the {texcode by the api_pare_tex parsed code}
<input class='checkbox' type='radio' name='choice[". $questionId. "]' value='". $answerId. "'>
<input class='checkbox' type='checkbox' name='choice[". $questionId. "][". $answerId. "]' value='1'>
$s.= "<tr><td colspan='2'>$answer</td></tr>";
// 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
$Select[$answerId]['Reponse']= $answer;
<table border='0' cellpadding='0' cellspacing='0' width='100%'>
$s.= "<td width='40%' valign='top'><b>". $cpt2. "</b>. ". $answer. "</td>
<td width='20%' align='center'> <select name='choice[". $questionId. "][". $answerId. "]'>
<option value='0'>--</option>";
foreach($Select as $key=> $val)
$s.= "<option value='". $key. "'>". $val['Lettre']. "</option>";
$s.= "</select> </td>
<td width='40%' valign='top'>";
if(isset ($Select[$cpt2])) $s.= '<b>'. $Select[$cpt2]['Lettre']. '.</b> '. $Select[$cpt2]['Reponse'];
// 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]))
<table border='0' cellpadding='0' cellspacing='0' width='100%'>
<td width='60%' colspan='2'> </td>
<td width='40%' valign='top'>";
$s.= '<b>'. $Select[$cpt2]['Lettre']. '.</b> '. $Select[$cpt2]['Reponse'];
// destruction of the Answer object
// destruction of the Question object
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 = '<div style="padding: 10px; margin-left: 0px; border: 1px solid #4271b5; height: 481px; width: 200px;"><b>'. get_lang('HotspotZones'). '</b><ol>';
for($answerId= 1;$answerId <= $nbrAnswers;$answerId++ )
$answer_list .= '<li>'. $objAnswerTmp->selectAnswer($answerId). '</li>';
$answer_list .= '</ol></div>';
<td valign='top' colspan='2'>
$s.= $questionDescription;
$canClick = isset ($_GET['editQuestion']) ? '0' : (isset ($_GET['modifyAnswers']) ? '0' : '1');
//$tes = isset($_GET['modifyAnswers']) ? '0' : '1';
$s .= "<script type=\"text/javascript\" src=\"../plugin/hotspot/JavaScriptFlashGateway.js\"></script>
<script src=\"../plugin/hotspot/hotspot.js\" type=\"text/javascript\"></script>
<script language=\"JavaScript\" type=\"text/javascript\">
// -----------------------------------------------------------------------------
// Major version of Flash required
var requiredMajorVersion = 7;
// Minor version of Flash required
var requiredMinorVersion = 0;
// Minor version of Flash required
var requiredRevision = 0;
// the version of javascript supported
// -----------------------------------------------------------------------------
<script language=\"VBScript\" type=\"text/vbscript\">
<!-- // Visual basic helper required to detect Flash Player ActiveX control version information
set swControl = CreateObject(\"ShockwaveFlash.ShockwaveFlash.\" + CStr(i))
if (IsObject(swControl)) then
swVersion = swControl.GetVariable(\"\$version\")
<script language=\"JavaScript1.1\" type=\"text/javascript\">
<!-- // Detect Client Browser type
var isIE = (navigator.appVersion.indexOf(\"MSIE\") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf(\"win\") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf(\"Opera\") != -1) ? true : false;
// JavaScript helper required to detect Flash Player PlugIn version information
// NS/Opera version >= 3 check for Flash plugin in plugin array
if (navigator.plugins != null && navigator.plugins.length > 0) {
if (navigator.plugins[\"Shockwave Flash 2.0\"] || navigator.plugins[\"Shockwave Flash\"]) {
var swVer2 = navigator.plugins[\"Shockwave Flash 2.0\"] ? \" 2.0\" : \"\";
var flashDescription = navigator.plugins[\"Shockwave Flash\" + swVer2].description;
descArray = flashDescription.split(\" \");
tempArrayMajor = descArray[2].split(\".\");
versionMajor = tempArrayMajor[0];
versionMinor = tempArrayMajor[1];
if ( descArray[3] != \"\" ) {
tempArrayMinor = descArray[3].split(\"r\");
tempArrayMinor = descArray[4].split(\"r\");
versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
flashVer = versionMajor + \".\" + versionMinor + \".\" + versionRevision;
// MSN/WebTV 2.6 supports Flash 4
else if (navigator.userAgent.toLowerCase().indexOf(\"webtv/2.6\") != -1) flashVer = 4;
// WebTV 2.5 supports Flash 3
else if (navigator.userAgent.toLowerCase().indexOf(\"webtv/2.5\") != -1) flashVer = 3;
// older WebTV supports Flash 2
else if (navigator.userAgent.toLowerCase().indexOf(\"webtv\") != -1) flashVer = 2;
// Can't detect in all other cases
// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
reqVer = parseFloat(reqMajorVer + \".\" + reqRevision);
// loop backwards through the versions until we find the newest version
if (isIE && isWin && !isOpera) {
versionStr = VBGetSwfVer(i);
versionStr = JSGetSwfVer(i);
} else if (versionStr != 0) {
if(isIE && isWin && !isOpera) {
tempArray = versionStr.split(\" \");
tempString = tempArray[1];
versionArray = tempString .split(\",\");
versionArray = versionStr.split(\".\");
versionMajor = versionArray[0];
versionMinor = versionArray[1];
versionRevision = versionArray[2];
versionString = versionMajor + \".\" + versionRevision; // 7.0r24 == 7.24
versionNum = parseFloat(versionString);
// is the major.revision >= requested major.revision AND the minor version >= requested minor
if ( (versionMajor > reqMajorVer) && (versionNum >= reqVer) ) {
return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false );
$s .= '<tr><td valign="top" colspan="2" width="100%"><table><tr><td width="570">'. "
<script language=\"JavaScript\" type=\"text/javascript\">
// Version check based upon the values entered above in \"Globals\"
var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
// Check to see if the version meets the requirements for playback
if (hasReqestedVersion) { // if we've detected an acceptable version
var oeTags = '<object type=\"application/x-shockwave-flash\" data=\"../plugin/hotspot/hotspot_user.swf?modifyAnswers=". $questionId. "&canClick:". $canClick. "\" width=\"556\" height=\"501\">'
+ '<param name=\"movie\" value=\"../plugin/hotspot/hotspot_user.swf?modifyAnswers=". $questionId. "&canClick:". $canClick. "\" \/>'
document.write(oeTags); // embed the Flash Content SWF when all tests are passed
} else { // flash is too old or we can't detect the plugin
var alternateContent = 'Error<br \/>'
+ 'Hotspots requires Macromedia Flash 7.<br \/>'
+ '<a href=http://www.macromedia.com/go/getflash/>Get Flash<\/a>';
document.write(alternateContent); // insert non-flash content
<td valign='top' align='left'>$answer_list</td></tr></table>
echo "<tr><td colspan='2'> </td></tr>";
|