@ -1,30 +1,30 @@
<?php // $Id: exercise.lib.php 9665 2006-10-24 10:43:48Z elixir_inter $
<?php // $Id: exercise.lib.php 9866 2006-11-06 09:43:17Z bmol $
/*
/*
==============================================================================
==============================================================================
Dokeos - elearning and course management software
Dokeos - elearning and course management software
Copyright (c) 2004 Dokeos S.A.
Copyright (c) 2004 Dokeos S.A.
Copyright (c) 2003 Ghent University (UGent)
Copyright (c) 2003 Ghent University (UGent)
Copyright (c) 2001 Universite catholique de Louvain (UCL)
Copyright (c) 2001 Universite catholique de Louvain (UCL)
Copyright (c) Olivier Brouckaert
Copyright (c) Olivier Brouckaert
For a full list of contributors, see "credits.txt".
For a full list of contributors, see "credits.txt".
The full license can be read in "license.txt".
The full license can be read in "license.txt".
This program is free software; you can redistribute it and/or
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
of the License, or (at your option) any later version.
See the GNU General Public License for more details.
See the GNU General Public License for more details.
Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
==============================================================================
==============================================================================
*/
*/
/**
/**
==============================================================================
==============================================================================
EXERCISE TOOL LIBRARY
EXERCISE TOOL LIBRARY
*
*
* shows a question and its answers
* shows a question and its answers
*
*
* @returns 'number of answers' if question exists, otherwise false
* @returns 'number of answers' if question exists, otherwise false
@ -34,7 +34,7 @@
* @param integer $questionId ID of the question to show
* @param integer $questionId ID of the question to show
* @param boolean $onlyAnswers set to true to show only answers
* @param boolean $onlyAnswers set to true to show only answers
* @package dokeos.exercise
* @package dokeos.exercise
==============================================================================
==============================================================================
*/
*/
require("../inc/lib/fckeditor/fckeditor.php") ;
require("../inc/lib/fckeditor/fckeditor.php") ;
function showQuestion($questionId, $onlyAnswers=false, $origin=false)
function showQuestion($questionId, $onlyAnswers=false, $origin=false)
@ -51,15 +51,15 @@ function showQuestion($questionId, $onlyAnswers=false, $origin=false)
$answerType=$objQuestionTmp->selectType();
$answerType=$objQuestionTmp->selectType();
$pictureName=$objQuestionTmp->selectPicture();
$pictureName=$objQuestionTmp->selectPicture();
if ($answerType != HOT_SPOT) // Question is not of type hotspot
if ($answerType != HOT_SPOT) // Question is not of type hotspot
{
{
if(!$onlyAnswers)
if(!$onlyAnswers)
{
{
$questionName=$objQuestionTmp->selectTitle();
$questionName=$objQuestionTmp->selectTitle();
$questionDescription=$objQuestionTmp->selectDescription();
$questionDescription=$objQuestionTmp->selectDescription();
$s="< tr >
$s="< tr >
< td valign = 'top' colspan = '2' > ";
< td valign = 'top' colspan = '2' > ";
$questionName=api_parse_tex($questionName);
$questionName=api_parse_tex($questionName);
@ -74,7 +74,7 @@ function showQuestion($questionId, $onlyAnswers=false, $origin=false)
$s.="< / i >
$s.="< / i >
< / td >
< / td >
< / tr > ";
< / tr > ";
if(!empty($pictureName))
if(!empty($pictureName))
{
{
$s.="
$s.="
@ -82,14 +82,14 @@ function showQuestion($questionId, $onlyAnswers=false, $origin=false)
< td align = 'center' colspan = '2' > < img src = '../document/download.php?doc_url=%2Fimages%2F' " . $ pictureName . " ' border = '0' > < / td >
< td align = 'center' colspan = '2' > < img src = '../document/download.php?doc_url=%2Fimages%2F' " . $ pictureName . " ' border = '0' > < / td >
< / tr > ";
< / tr > ";
}
}
} // end if(!$onlyAnswers)
} // end if(!$onlyAnswers)
// construction of the Answer object
// construction of the Answer object
$objAnswerTmp=new Answer($questionId);
$objAnswerTmp=new Answer($questionId);
$nbrAnswers=$objAnswerTmp->selectNbrAnswers();
$nbrAnswers=$objAnswerTmp->selectNbrAnswers();
// only used for the answer type "Matching"
// only used for the answer type "Matching"
if($answerType == MATCHING)
if($answerType == MATCHING)
{
{
@ -106,75 +106,75 @@ function showQuestion($questionId, $onlyAnswers=false, $origin=false)
$oFCKeditor->BasePath = api_get_path(WEB_LIBRARY_PATH)."fckeditor/";
$oFCKeditor->BasePath = api_get_path(WEB_LIBRARY_PATH)."fckeditor/";
//$oFCKeditor->Config['CustomConfigurationsPath'] = api_get_path(WEB_PATH)."claroline/inc/lib/fckeditor_new/myconfig.js?".time(); //to clear cache we use time() but always clear history manually
//$oFCKeditor->Config['CustomConfigurationsPath'] = api_get_path(WEB_PATH)."claroline/inc/lib/fckeditor_new/myconfig.js?".time(); //to clear cache we use time() but always clear history manually
/*
/*
$oFCKeditor->Config['ImageBrowserURL'] = $oFCKeditor->BasePath . "editor/filemanager/browser/default/browser.html?Type=Image&Connector=connectors/php/connector.php&ServerPath=/$upload_path/";
$oFCKeditor->Config['ImageBrowserURL'] = $oFCKeditor->BasePath . "editor/filemanager/browser/default/browser.html?Type=Image&Connector=connectors/php/connector.php&ServerPath=/$upload_path/";
$oFCKeditor->Config['ImageUploadURL'] = $oFCKeditor->BasePath . "editor/filemanager/upload/php/upload.php?Type=Image& ServerPath=/$upload_path/" ;
$oFCKeditor->Config['ImageUploadURL'] = $oFCKeditor->BasePath . "editor/filemanager/upload/php/upload.php?Type=Image& ServerPath=/$upload_path/" ;
//for Link/File
//for Link/File
$oFCKeditor->Config['LinkBrowserURL'] = $oFCKeditor->BasePath . "editor/filemanager/browser/default/browser.html?Connector=connectors/php/connector.php&ServerPath=$upload_path";
$oFCKeditor->Config['LinkBrowserURL'] = $oFCKeditor->BasePath . "editor/filemanager/browser/default/browser.html?Connector=connectors/php/connector.php&ServerPath=$upload_path";
$oFCKeditor->Config['LinkUploadURL'] = $oFCKeditor->BasePath . "editor/filemanager/upload/php/upload.php?ServerPath=$upload_path" ;
$oFCKeditor->Config['LinkUploadURL'] = $oFCKeditor->BasePath . "editor/filemanager/upload/php/upload.php?ServerPath=$upload_path" ;
//for image
//for image
$oFCKeditor->Config['ImageBrowserURL'] = $oFCKeditor->BasePath . "editor/filemanager/browser/default/browser.html?Type=Image&Connector=connectors/php/connector.php&ServerPath=$upload_path";
$oFCKeditor->Config['ImageBrowserURL'] = $oFCKeditor->BasePath . "editor/filemanager/browser/default/browser.html?Type=Image&Connector=connectors/php/connector.php&ServerPath=$upload_path";
$oFCKeditor->Config['ImageUploadURL'] = $oFCKeditor->BasePath . "editor/filemanager/upload/php/upload.php?Type=Image& ServerPath=$upload_path" ;
$oFCKeditor->Config['ImageUploadURL'] = $oFCKeditor->BasePath . "editor/filemanager/upload/php/upload.php?Type=Image& ServerPath=$upload_path" ;
//for flash
//for flash
$oFCKeditor->Config['FlashBrowserURL'] = $oFCKeditor->BasePath . "editor/filemanager/browser/default/browser.html?Type=Flash&Connector=connectors/php/connector.php&ServerPath=$upload_path";
$oFCKeditor->Config['FlashBrowserURL'] = $oFCKeditor->BasePath . "editor/filemanager/browser/default/browser.html?Type=Flash&Connector=connectors/php/connector.php&ServerPath=$upload_path";
$oFCKeditor->Config['FlashUploadURL'] = $oFCKeditor->BasePath . "editor/filemanager/upload/php/upload.php?Type=Flash& ServerPath=$upload_path" ;
$oFCKeditor->Config['FlashUploadURL'] = $oFCKeditor->BasePath . "editor/filemanager/upload/php/upload.php?Type=Flash& ServerPath=$upload_path" ;
//for MP3
//for MP3
$oFCKeditor->Config['MP3BrowserURL'] = $oFCKeditor->BasePath . "editor/filemanager/browser/default/browser.html?Type=MP3&Connector=connectors/php/connector.php&ServerPath=$upload_path";
$oFCKeditor->Config['MP3BrowserURL'] = $oFCKeditor->BasePath . "editor/filemanager/browser/default/browser.html?Type=MP3&Connector=connectors/php/connector.php&ServerPath=$upload_path";
$oFCKeditor->Config['MP3UploadURL'] = $oFCKeditor->BasePath . "editor/filemanager/upload/php/upload.php?Type=MP3& ServerPath=$upload_path" ;
$oFCKeditor->Config['MP3UploadURL'] = $oFCKeditor->BasePath . "editor/filemanager/upload/php/upload.php?Type=MP3& ServerPath=$upload_path" ;
//for other media
//for other media
$oFCKeditor->Config['VideoBrowserURL'] = $oFCKeditor->BasePath . "editor/filemanager/browser/default/browser.html?Type=Video&Connector=connectors/php/connector.php&ServerPath=$upload_path";
$oFCKeditor->Config['VideoBrowserURL'] = $oFCKeditor->BasePath . "editor/filemanager/browser/default/browser.html?Type=Video&Connector=connectors/php/connector.php&ServerPath=$upload_path";
$oFCKeditor->Config['VideoUploadURL'] = $oFCKeditor->BasePath . "editor/filemanager/upload/php/upload.php?Type=Video& ServerPath=$upload_path" ;
$oFCKeditor->Config['VideoUploadURL'] = $oFCKeditor->BasePath . "editor/filemanager/upload/php/upload.php?Type=Video& ServerPath=$upload_path" ;
$oFCKeditor->ToolbarSet = 'Comment' ;*/
$oFCKeditor->ToolbarSet = 'Comment' ;*/
$oFCKeditor->Width = '70%';
$oFCKeditor->Width = '70%';
$oFCKeditor->Height = '150';
$oFCKeditor->Height = '150';
$oFCKeditor->Value = '' ;
$oFCKeditor->Value = '' ;
$s .= "< tr > < td colspan = '2' > ".$oFCKeditor->CreateHtml()."< / td > < / tr > ";
$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 > ";
//$s.="< tr > < td colspan = '2' > < textarea cols = '80' rows = '10' name = 'choice[".$questionId."]' > $answer< / textarea > < / td > < / tr > ";
}
}
for($answerId=1;$answerId < = $nbrAnswers;$answerId++)
for($answerId=1;$answerId < = $nbrAnswers;$answerId++)
{
{
$answer=$objAnswerTmp->selectAnswer($answerId);
$answer=$objAnswerTmp->selectAnswer($answerId);
$answerCorrect=$objAnswerTmp->isCorrect($answerId);
$answerCorrect=$objAnswerTmp->isCorrect($answerId);
if($answerType == FILL_IN_BLANKS)
if($answerType == FILL_IN_BLANKS)
{
{
// splits text and weightings that are joined with the character '::'
// splits text and weightings that are joined with the character '::'
list($answer)=explode('::',$answer);
list($answer)=explode('::',$answer);
// because [] is parsed here we follow this procedure:
// because [] is parsed here we follow this procedure:
// 1. find everything between the [tex] and [/tex] tags
// 1. find everything between the [tex] and [/tex] tags
$startlocations=strpos($answer,'[tex]');
$startlocations=strpos($answer,'[tex]');
$endlocations=strpos($answer,'[/tex]');
$endlocations=strpos($answer,'[/tex]');
if($startlocations !== false & & $endlocations !== false)
if($startlocations !== false & & $endlocations !== false)
{
{
$texstring=substr($answer,$startlocations,$endlocations-$startlocations+6);
$texstring=substr($answer,$startlocations,$endlocations-$startlocations+6);
// 2. replace this by {texcode}
// 2. replace this by {texcode}
$answer=str_replace($texstring,'{texcode}',$answer);
$answer=str_replace($texstring,'{texcode}',$answer);
}
}
// 3. do the normal matching parsing
// 3. do the normal matching parsing
// replaces [blank] by an input field
// replaces [blank] by an input field
$answer=ereg_replace('\[[^]]+\]','< input type = "text" name = "choice['.$questionId.'][]" size = "10" > ',nl2br($answer));
$answer=ereg_replace('\[[^]]+\]','< input type = "text" name = "choice['.$questionId.'][]" size = "10" > ',nl2br($answer));
// 4. replace the {texcode by the api_pare_tex parsed code}
// 4. replace the {texcode by the api_pare_tex parsed code}
$texstring = api_parse_tex($texstring);
$texstring = api_parse_tex($texstring);
$answer=str_replace("{texcode}",$texstring,$answer);
$answer=str_replace("{texcode}",$texstring,$answer);
}
}
// unique answer
// unique answer
if($answerType == UNIQUE_ANSWER)
if($answerType == UNIQUE_ANSWER)
{
{
@ -187,7 +187,7 @@ function showQuestion($questionId, $onlyAnswers=false, $origin=false)
$answer=api_parse_tex($answer);
$answer=api_parse_tex($answer);
$s.=$answer;
$s.=$answer;
$s.="< / td > < / tr > ";
$s.="< / td > < / tr > ";
}
}
// multiple answers
// multiple answers
elseif($answerType == MULTIPLE_ANSWER)
elseif($answerType == MULTIPLE_ANSWER)
@ -200,16 +200,16 @@ function showQuestion($questionId, $onlyAnswers=false, $origin=false)
$answer = api_parse_tex($answer);
$answer = api_parse_tex($answer);
$s.=$answer;
$s.=$answer;
$s.="< / td > < / tr > ";
$s.="< / td > < / tr > ";
}
}
// fill in blanks
// fill in blanks
elseif($answerType == FILL_IN_BLANKS)
elseif($answerType == FILL_IN_BLANKS)
{
{
$s.="< tr > < td colspan = '2' > $answer< / td > < / tr > ";
$s.="< tr > < td colspan = '2' > $answer< / td > < / tr > ";
}
}
// free answer
// free answer
// matching
// matching
else
else
{
{
@ -229,18 +229,18 @@ function showQuestion($questionId, $onlyAnswers=false, $origin=false)
< table border = '0' cellpadding = '0' cellspacing = '0' width = '100%' >
< table border = '0' cellpadding = '0' cellspacing = '0' width = '100%' >
< tr > ";
< tr > ";
$answer=api_parse_tex($answer);
$answer=api_parse_tex($answer);
$s.="< td width = '40%' valign = 'top' > < b > ".$cpt2."< / b > .& nbsp ".$answer."< / td >
$s.="< td width = '40%' valign = 'top' > < b > ".$cpt2."< / b > . ".$answer."< / td >
< td width = '20%' align = 'center' > < select name = 'choice[".$questionId."][".$answerId."]' >
< td width = '20%' align = 'center' > < select name = 'choice[".$questionId."][".$answerId."]' >
< option value = '0' > --< / option > ";
< option value = '0' > --< / option > ";
// fills the list-box
// fills the list-box
foreach($Select as $key=>$val)
foreach($Select as $key=>$val)
{
{
$s.="< option value = '".$key."' > ".$val['Lettre']."< / option > ";
$s.="< option value = '".$key."' > ".$val['Lettre']."< / option > ";
} // end foreach()
} // end foreach()
$s.="< / select > < / td >
$s.="< / select > < / td >
< td width = '40%' valign = 'top' > ";
< td width = '40%' valign = 'top' > ";
if(isset($Select[$cpt2])) $s.='< b > '.$Select[$cpt2]['Lettre'].'.< / b > '.$Select[$cpt2]['Reponse'];
if(isset($Select[$cpt2])) $s.='< b > '.$Select[$cpt2]['Lettre'].'.< / b > '.$Select[$cpt2]['Reponse'];
@ -251,17 +251,17 @@ function showQuestion($questionId, $onlyAnswers=false, $origin=false)
< / table >
< / table >
< / td >
< / td >
< / tr > ";
< / tr > ";
$cpt2++;
$cpt2++;
// if the left side of the "matching" has been completely shown
// if the left side of the "matching" has been completely shown
if($answerId == $nbrAnswers)
if($answerId == $nbrAnswers)
{
{
// if it remains answers to shown at the right side
// if it remains answers to shown at the right side
while(isset($Select[$cpt2]))
while(isset($Select[$cpt2]))
{
{
$s.="< tr >
$s.="< tr >
< td colspan = '2' >
< td colspan = '2' >
< table border = '0' cellpadding = '0' cellspacing = '0' width = '100%' >
< table border = '0' cellpadding = '0' cellspacing = '0' width = '100%' >
@ -274,21 +274,21 @@ function showQuestion($questionId, $onlyAnswers=false, $origin=false)
< / table >
< / table >
< / td >
< / td >
< / tr > ";
< / tr > ";
$cpt2++;
$cpt2++;
} // end while()
} // end while()
} // end if()
} // end if()
}
}
}
}
} // end for()
} // end for()
// destruction of the Answer object
// destruction of the Answer object
unset($objAnswerTmp);
unset($objAnswerTmp);
// destruction of the Question object
// destruction of the Question object
unset($objQuestionTmp);
unset($objQuestionTmp);
if ($origin != 'export')
if ($origin != 'export')
{
{
echo $s;
echo $s;
@ -302,11 +302,11 @@ function showQuestion($questionId, $onlyAnswers=false, $origin=false)
{
{
$questionName=$objQuestionTmp->selectTitle();
$questionName=$objQuestionTmp->selectTitle();
$questionDescription=$objQuestionTmp->selectDescription();
$questionDescription=$objQuestionTmp->selectDescription();
// Get the answers, make a list
// Get the answers, make a list
$objAnswerTmp=new Answer($questionId);
$objAnswerTmp=new Answer($questionId);
$nbrAnswers=$objAnswerTmp->selectNbrAnswers();
$nbrAnswers=$objAnswerTmp->selectNbrAnswers();
$answer_list = '< div style = "padding: 10px; margin-left: -8px; border: 1px solid #4271b5; height: 448px; width: 200px;" > < b > '.get_lang('langHotspotZones').'< / b > < ol > ';
$answer_list = '< div style = "padding: 10px; margin-left: -8px; border: 1px solid #4271b5; height: 448px; width: 200px;" > < b > '.get_lang('langHotspotZones').'< / b > < ol > ';
for($answerId=1;$answerId < = $nbrAnswers;$answerId++)
for($answerId=1;$answerId < = $nbrAnswers;$answerId++)
{
{
@ -331,17 +331,17 @@ function showQuestion($questionId, $onlyAnswers=false, $origin=false)
< / td >
< / td >
< / tr > ";
< / tr > ";
}
}
$canClick = isset($_GET['editQuestion']) ? '0' : (isset($_GET['modifyAnswers']) ? '0' : '1');
$canClick = isset($_GET['editQuestion']) ? '0' : (isset($_GET['modifyAnswers']) ? '0' : '1');
//$tes = isset($_GET['modifyAnswers']) ? '0' : '1';
//$tes = isset($_GET['modifyAnswers']) ? '0' : '1';
//echo $tes;
//echo $tes;
$s .= '< tr > < td valign = "top" colspan = "2" > < table > < tr > < td > '."
$s .= '< tr > < td valign = "top" colspan = "2" > < table > < tr > < td > '."
< script language = \"JavaScript\" type = \"text/javascript\" >
< script language = \"JavaScript\" type = \"text/javascript\" >
<!--
<!--
// Version check based upon the values entered above in \"Globals\"
// Version check based upon the values entered above in \"Globals\"
var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
// Check to see if the version meets the requirements for playback
// Check to see if the version meets the requirements for playback
if (hasReqestedVersion) { // if we've detected an acceptable version
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 = \"380\" height = \"470\" > '
var oeTags = '< object type = \"application/x-shockwave-flash\" data = \"../plugin/hotspot/hotspot_user.swf?modifyAnswers=".$questionId."&canClick:".$canClick."\" width = \"380\" height = \"470\" > '
@ -359,7 +359,7 @@ function showQuestion($questionId, $onlyAnswers=false, $origin=false)
< td valign = 'top' > $answer_list< / td > < / tr > < / table >
< td valign = 'top' > $answer_list< / td > < / tr > < / table >
< / td > < / tr > ";
< / td > < / tr > ";
echo $s;
echo $s;
}
}
return $nbrAnswers;
return $nbrAnswers;