- question.class.php is now an abstract class. hotspot.class.php, uniquer_answer.class.php are extending Question. - when we create / edit a question, the question form and the answers form are now on the same page (except for hotspot) I'm writing a wiki page on the new structure... See http://www.dokeos.com/wiki/index.php/Test_tool_redesign in a few moment.skala
parent
b2ae4ce07e
commit
63f47b7b9b
@ -0,0 +1,148 @@ |
||||
<?php // $Id: uniquer_answer.class.php 10234 2006-12-26
|
||||
/* |
||||
============================================================================== |
||||
Dokeos - elearning and course management software |
||||
|
||||
Copyright (c) 2004 Dokeos S.A. |
||||
Copyright (c) 2003 Ghent University (UGent) |
||||
Copyright (c) 2001 Universite catholique de Louvain (UCL) |
||||
Copyright (c) Olivier Brouckaert |
||||
|
||||
For a full list of contributors, see "credits.txt". |
||||
The full license can be read in "license.txt". |
||||
|
||||
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 the GNU General Public License for more details. |
||||
|
||||
Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com |
||||
============================================================================== |
||||
*/ |
||||
/** |
||||
============================================================================== |
||||
* File containing the FillBlanks class. |
||||
* |
||||
* @author Eric Marguin |
||||
* @package dokeos.exercise |
||||
============================================================================== |
||||
*/ |
||||
|
||||
if(!class_exists('FillBlanks')): |
||||
|
||||
/** |
||||
CLASS FillBlanks |
||||
* |
||||
* This class allows to instantiate an object of type MULTIPLE_ANSWER (MULTIPLE CHOICE, MULTIPLE ANSWER), |
||||
* extending the class question |
||||
* |
||||
* @author Eric Marguin |
||||
* @package dokeos.exercise |
||||
**/ |
||||
|
||||
class FillBlanks extends Question { |
||||
|
||||
/** |
||||
* Constructor |
||||
*/ |
||||
function FillBlanks(){ |
||||
parent::question(); |
||||
$this -> type = FILL_IN_BLANKS; |
||||
} |
||||
|
||||
/** |
||||
* function which redifines Question::createAnswersForm |
||||
* @param the formvalidator instance |
||||
*/ |
||||
function createAnswersForm ($form) { |
||||
|
||||
// javascript |
||||
echo ' |
||||
<script type="text/javascript"> |
||||
function updateBlanks() { |
||||
field = document.getElementById("answer"); |
||||
var answer = field.value; |
||||
var blanks = answer.match(/\[[^\]]*\]/g); |
||||
|
||||
var fields = "<div class=\"row\"><div class=\"label\">'.get_lang('Weighting').'</div><div class=\"formw\"><table>"; |
||||
for(i=0 ; i<blanks.length ; i++){ |
||||
if(document.getElementById("weighting["+i+"]")) |
||||
value = document.getElementById("weighting["+i+"]").value; |
||||
else |
||||
value = "1"; |
||||
fields += "<tr><td>"+blanks[i]+"</td><td><input size=\"5\" value=\""+value+"\" type=\"text\" id=\"weighting["+i+"]\" name=\"weighting["+i+"]\" /></td></tr>"; |
||||
|
||||
} |
||||
document.getElementById("blanks_weighting").innerHTML = fields + "</table></div></div>"; |
||||
|
||||
} |
||||
window.onload = updateBlanks; |
||||
</script> |
||||
'; |
||||
|
||||
|
||||
// answer |
||||
$form -> addElement ('html', '<br /><br /><div class="row"><div class="label"></div><div class="formw">'.get_lang('TypeTextBelow').', '.get_lang('And').' '.get_lang('UseTagForBlank').'</div></div>'); |
||||
$form -> addElement ('textarea', 'answer',get_lang('Answer'),'id="answer" cols="65" rows="6" onkeyup="updateBlanks(this)"'); |
||||
$form -> addRule ('answer',get_lang('GiveText'),'required'); |
||||
$form -> addRule ('answer',get_lang('DefineBlanks'),'regex','/\[.*\]/'); |
||||
|
||||
$defaults = array(); |
||||
|
||||
if(!empty($this->id)) |
||||
{ |
||||
$objAnswer = new answer($this->id); |
||||
$defaults['answer'] = $objAnswer->selectAnswer(1); |
||||
} |
||||
else |
||||
{ |
||||
$defaults['answer'] = get_lang('DefaultTextInBlanks'); |
||||
} |
||||
|
||||
$form -> addElement('html','<div id="blanks_weighting"></div>'); |
||||
|
||||
$form -> setDefaults($defaults); |
||||
|
||||
} |
||||
|
||||
|
||||
/** |
||||
* abstract function which creates the form to create / edit the answers of the question |
||||
* @param the formvalidator instance |
||||
*/ |
||||
function processAnswersCreation($form) { |
||||
|
||||
$answer = $form -> getSubmitValue('answer'); |
||||
|
||||
//remove the :: eventually written by the user |
||||
$answer = str_replace('::','',$answer); |
||||
|
||||
// get the blanks weightings |
||||
$nb = preg_match_all('/\[[^\]]*\]/', $answer, $blanks); |
||||
if($nb>0) |
||||
{ |
||||
$answer .= '::'; |
||||
for($i=0 ; $i<$nb ; ++$i) |
||||
{ |
||||
$answer .= $form -> getSubmitValue('weighting['.$i.']').','; |
||||
$this -> weighting += $form -> getSubmitValue('weighting['.$i.']'); |
||||
} |
||||
$answer = substr($answer,0,-1); |
||||
} |
||||
|
||||
$this -> save(); |
||||
|
||||
$objAnswer = new answer($this->id); |
||||
$objAnswer->createAnswer($answer,0,'',0,''); |
||||
$objAnswer->save(); |
||||
|
||||
echo '<script type="text/javascript">window.location.href="admin.php"</script>'; |
||||
|
||||
} |
||||
|
||||
} |
||||
|
||||
endif; |
||||
?> |
@ -0,0 +1,90 @@ |
||||
<?php // $Id: uniquer_answer.class.php 10234 2006-12-26
|
||||
/* |
||||
============================================================================== |
||||
Dokeos - elearning and course management software |
||||
|
||||
Copyright (c) 2004 Dokeos S.A. |
||||
Copyright (c) 2003 Ghent University (UGent) |
||||
Copyright (c) 2001 Universite catholique de Louvain (UCL) |
||||
Copyright (c) Olivier Brouckaert |
||||
|
||||
For a full list of contributors, see "credits.txt". |
||||
The full license can be read in "license.txt". |
||||
|
||||
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 the GNU General Public License for more details. |
||||
|
||||
Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com |
||||
============================================================================== |
||||
*/ |
||||
/** |
||||
============================================================================== |
||||
* File containing the FreeAnswer class. |
||||
* |
||||
* @author Eric Marguin |
||||
* @package dokeos.exercise |
||||
============================================================================== |
||||
*/ |
||||
|
||||
if(!class_exists('FreeAnswer')): |
||||
|
||||
/** |
||||
CLASS FreeAnswer |
||||
* |
||||
* This class allows to instantiate an object of type FREE_ANSWER, |
||||
* extending the class question |
||||
* |
||||
* @author Eric Marguin |
||||
* @package dokeos.exercise |
||||
**/ |
||||
|
||||
class FreeAnswer extends Question { |
||||
|
||||
/** |
||||
* Constructor |
||||
*/ |
||||
function FreeAnswer(){ |
||||
parent::question(); |
||||
$this -> type = FREE_ANSWER; |
||||
} |
||||
|
||||
/** |
||||
* function which redifines Question::createAnswersForm |
||||
* @param the formvalidator instance |
||||
*/ |
||||
function createAnswersForm ($form) { |
||||
|
||||
$form -> addElement('text','weighting',get_lang('Weighting'),'size="5"'); |
||||
if(!empty($this->id)) |
||||
{ |
||||
$form -> setDefaults(array('weighting' => $this->weighting)); |
||||
} |
||||
else { |
||||
$form -> setDefaults(array('weighting' => '1')); |
||||
} |
||||
|
||||
} |
||||
|
||||
|
||||
/** |
||||
* abstract function which creates the form to create / edit the answers of the question |
||||
* @param the formvalidator instance |
||||
*/ |
||||
function processAnswersCreation($form) { |
||||
|
||||
$this -> weighting = $form -> getSubmitValue('weighting'); |
||||
|
||||
$this->save(); |
||||
|
||||
echo '<script type="text/javascript">window.location.href="admin.php"</script>'; |
||||
|
||||
} |
||||
|
||||
} |
||||
|
||||
endif; |
||||
?> |
@ -0,0 +1,92 @@ |
||||
<?php // $Id: hotspot.class.php 10234 2006-12-26
|
||||
/* |
||||
============================================================================== |
||||
Dokeos - elearning and course management software |
||||
|
||||
Copyright (c) 2004 Dokeos S.A. |
||||
Copyright (c) 2003 Ghent University (UGent) |
||||
Copyright (c) 2001 Universite catholique de Louvain (UCL) |
||||
Copyright (c) Olivier Brouckaert |
||||
|
||||
For a full list of contributors, see "credits.txt". |
||||
The full license can be read in "license.txt". |
||||
|
||||
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 the GNU General Public License for more details. |
||||
|
||||
Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com |
||||
============================================================================== |
||||
*/ |
||||
/** |
||||
============================================================================== |
||||
* File containing the HotSpot class. |
||||
* |
||||
* @author Eric Marguin |
||||
* @package dokeos.exercise |
||||
============================================================================== |
||||
*/ |
||||
|
||||
if(!class_exists('HotSpot')): |
||||
|
||||
/** |
||||
CLASS HotSpot |
||||
* |
||||
* This class allows to instantiate an object of type HotSpot (MULTIPLE CHOICE, UNIQUE ANSWER), |
||||
* extending the class question |
||||
* |
||||
* @author Eric Marguin |
||||
* @package dokeos.exercise |
||||
**/ |
||||
|
||||
class HotSpot extends Question { |
||||
|
||||
function HotSpot(){ |
||||
parent::question(); |
||||
$this -> type = HOT_SPOT; |
||||
} |
||||
|
||||
function display(){ |
||||
|
||||
} |
||||
|
||||
function createForm ($form) { |
||||
parent::createForm ($form); |
||||
if(!isset($_GET['editQuestion'])) |
||||
{ |
||||
$form->addElement('file','imageUpload'); |
||||
$form->addRule('imageUpload', get_lang('OnlyJPG'), 'mimetype','image/jpeg'); |
||||
$form->addRule('imageUpload', get_lang('NoImage'), 'uploadedfile'); |
||||
} |
||||
} |
||||
|
||||
function processCreation ($form, $objExercise) { |
||||
$file_info = $form -> getSubmitValue('imageUpload'); |
||||
parent::processCreation ($form, $objExercise); |
||||
if(!empty($file_info['tmp_name'])) |
||||
{ |
||||
$this->uploadPicture($file_info['tmp_name'], $file_info['name']); |
||||
$this->save(); |
||||
} |
||||
echo '<script type="text/javascript">window.location.href="admin.php?hotspotadmin='.$this->id.'"</script>'; |
||||
} |
||||
|
||||
function createAnswersForm ($form) { |
||||
|
||||
// nothing |
||||
|
||||
} |
||||
|
||||
function processAnswersCreation ($form) { |
||||
|
||||
// nothing |
||||
|
||||
} |
||||
|
||||
} |
||||
|
||||
endif; |
||||
?> |
@ -0,0 +1,393 @@ |
||||
<?php // $Id: answer_admin.inc.php 10285 2006-12-04 10:52:39 +0100 (lun., 04 déc. 2006) develop-it $
|
||||
/* |
||||
============================================================================== |
||||
Dokeos - elearning and course management software |
||||
|
||||
Copyright (c) 2004 Dokeos S.A. |
||||
Copyright (c) 2003 Ghent University (UGent) |
||||
Copyright (c) 2001 Universite catholique de Louvain (UCL) |
||||
Copyright (c) Olivier Brouckaert |
||||
|
||||
For a full list of contributors, see "credits.txt". |
||||
The full license can be read in "license.txt". |
||||
|
||||
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 the GNU General Public License for more details. |
||||
|
||||
Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com |
||||
============================================================================== |
||||
*/ |
||||
/*>>>>>>>>>>>>>>>>>>>> ANSWER ADMINISTRATION <<<<<<<<<<<<<<<<<<<<*/ |
||||
/** |
||||
============================================================================== |
||||
* This script allows to manage answers |
||||
* |
||||
* It is included from the script admin.php |
||||
* @author Olivier Brouckaert |
||||
* @package dokeos.exercise |
||||
============================================================================== |
||||
*/ |
||||
|
||||
// ALLOWED_TO_INCLUDE is defined in admin.php |
||||
if(!defined('ALLOWED_TO_INCLUDE')) |
||||
{ |
||||
exit(); |
||||
} |
||||
|
||||
$modifyAnswers = $_GET['hotspotadmin']; |
||||
|
||||
if(!is_object($objQuestion)) |
||||
{ |
||||
$objQuestion = Question :: read($modifyAnswers); |
||||
} |
||||
|
||||
$questionName=$objQuestion->selectTitle(); |
||||
$answerType=$objQuestion->selectType(); |
||||
$pictureName=$objQuestion->selectPicture(); |
||||
|
||||
|
||||
$debug = 0; // debug variable to get where we are |
||||
|
||||
$okPicture=empty($pictureName)?false:true; |
||||
|
||||
// if we come from the warning box "this question is used in serveral exercises" |
||||
if($modifyIn) |
||||
{ |
||||
if($debug>0){echo '$modifyIn was set'."<br />\n";} |
||||
// if the user has chosed to modify the question only in the current exercise |
||||
if($modifyIn == 'thisExercise') |
||||
{ |
||||
// duplicates the question |
||||
$questionId=$objQuestion->duplicate(); |
||||
|
||||
// deletes the old question |
||||
$objQuestion->delete($exerciseId); |
||||
|
||||
// removes the old question ID from the question list of the Exercise object |
||||
$objExercise->removeFromList($modifyAnswers); |
||||
|
||||
// adds the new question ID into the question list of the Exercise object |
||||
$objExercise->addToList($questionId); |
||||
|
||||
// construction of the duplicated Question |
||||
$objQuestion = Question :: read($questionId); |
||||
|
||||
// adds the exercise ID into the exercise list of the Question object |
||||
$objQuestion->addToList($exerciseId); |
||||
|
||||
// copies answers from $modifyAnswers to $questionId |
||||
$objAnswer->duplicate($questionId); |
||||
|
||||
// construction of the duplicated Answers |
||||
|
||||
$objAnswer=new Answer($questionId); |
||||
} |
||||
|
||||
|
||||
$color=unserialize($color); |
||||
$reponse=unserialize($reponse); |
||||
$comment=unserialize($comment); |
||||
$weighting=unserialize($weighting); |
||||
$hotspot_coordinates=unserialize($hotspot_coordinates); |
||||
$hotspot_type=unserialize($hotspot_type); |
||||
|
||||
|
||||
unset($buttonBack); |
||||
} |
||||
|
||||
// the answer form has been submitted |
||||
if($submitAnswers || $buttonBack) |
||||
{ |
||||
if($debug>0){echo '$submitAnswers or $buttonBack was set'."<br />\n";} |
||||
|
||||
$questionWeighting=$nbrGoodAnswers=0; |
||||
|
||||
for($i=1;$i <= $nbrAnswers;$i++) |
||||
{ |
||||
if($debug>0){echo str_repeat(' ',4).'$answerType is HOT_SPOT'."<br />\n";} |
||||
|
||||
$reponse[$i]=trim($reponse[$i]); |
||||
$comment[$i]=trim($comment[$i]); |
||||
$weighting[$i]=intval($weighting[$i]); |
||||
|
||||
// checks if field is empty |
||||
if(empty($reponse[$i]) && $reponse[$i] != '0') |
||||
{ |
||||
$msgErr=get_lang('HotspotGiveAnswers'); |
||||
|
||||
// clears answers already recorded into the Answer object |
||||
$objAnswer->cancel(); |
||||
|
||||
break; |
||||
} |
||||
|
||||
if($weighting[$i] <= 0) |
||||
{ |
||||
$msgErr=get_lang('HotspotWeightingError'); |
||||
|
||||
// clears answers already recorded into the Answer object |
||||
$objAnswer->cancel(); |
||||
|
||||
break; |
||||
} |
||||
if($hotspot_coordinates[$i] == '0;0|0|0' || empty($hotspot_coordinates[$i])) |
||||
{ |
||||
$msgErr=get_lang('HotspotNotDrawn'); |
||||
|
||||
// clears answers already recorded into the Answer object |
||||
$objAnswer->cancel(); |
||||
|
||||
break; |
||||
} |
||||
|
||||
} // end for() |
||||
|
||||
|
||||
if(empty($msgErr)) |
||||
{ |
||||
|
||||
for($i=1;$i <= $nbrAnswers;$i++) |
||||
{ |
||||
if($debug>0){echo str_repeat(' ',4).'$answerType is HOT_SPOT'."<br />\n";} |
||||
|
||||
$reponse[$i]=trim($reponse[$i]); |
||||
$comment[$i]=addslashes(trim($comment[$i])); |
||||
$weighting[$i]=intval($weighting[$i]); |
||||
if($weighting[$i]) |
||||
{ |
||||
$questionWeighting+=$weighting[$i]; |
||||
} |
||||
|
||||
// creates answer |
||||
$objAnswer->createAnswer($reponse[$i], '',$comment[$i],$weighting[$i],$i,$hotspot_coordinates[$i],$hotspot_type[$i]); |
||||
} // end for() |
||||
// saves the answers into the data base |
||||
$objAnswer->save(); |
||||
|
||||
// sets the total weighting of the question |
||||
$objQuestion->updateWeighting($questionWeighting); |
||||
$objQuestion->save($exerciseId); |
||||
|
||||
$editQuestion=$questionId; |
||||
|
||||
unset($modifyAnswers); |
||||
|
||||
echo '<script type="text/javascript">window.location.href="admin.php"</script>'; |
||||
|
||||
} |
||||
if($debug>0){echo '$modifyIn was set - end'."<br />\n";} |
||||
|
||||
} |
||||
|
||||
if($modifyAnswers) |
||||
{ |
||||
|
||||
|
||||
if($debug>0){echo str_repeat(' ',0).'$modifyAnswers is set'."<br />\n";} |
||||
|
||||
// construction of the Answer object |
||||
$objAnswer=new Answer($objQuestion -> id); |
||||
|
||||
api_session_register('objAnswer'); |
||||
|
||||
if($debug>0){echo str_repeat(' ',2).'$answerType is HOT_SPOT'."<br />\n";} |
||||
|
||||
$TBL_ANSWERS = $_course['dbNameGlu'].'quiz_answer'; |
||||
|
||||
if(!$nbrAnswers) |
||||
{ |
||||
|
||||
$nbrAnswers=$objAnswer->selectNbrAnswers(); |
||||
|
||||
$reponse=Array(); |
||||
$comment=Array(); |
||||
$weighting=Array(); |
||||
$hotspot_coordinates=Array(); |
||||
$hotspot_type=array(); |
||||
|
||||
|
||||
for($i=1;$i <= $nbrAnswers;$i++) |
||||
{ |
||||
$reponse[$i]=$objAnswer->selectAnswer($i); |
||||
$comment[$i]=$objAnswer->selectComment($i); |
||||
$weighting[$i]=$objAnswer->selectWeighting($i); |
||||
$hotspot_coordinates[$i]=$objAnswer->selectHotspotCoordinates($i); |
||||
$hotspot_type[$i]=$objAnswer->selectHotspotType($i); |
||||
} |
||||
|
||||
|
||||
} |
||||
|
||||
$_SESSION['tmp_answers'] = array(); |
||||
$_SESSION['tmp_answers']['answer'] = $reponse; |
||||
$_SESSION['tmp_answers']['comment'] = $comment; |
||||
$_SESSION['tmp_answers']['weighting'] = $weighting; |
||||
$_SESSION['tmp_answers']['hotspot_coordinates'] = $hotspot_coordinates; |
||||
$_SESSION['tmp_answers']['hotspot_type'] = $hotspot_type; |
||||
|
||||
if($lessAnswers) |
||||
{ |
||||
// At least 1 answer |
||||
if ($nbrAnswers > 1) { |
||||
|
||||
$nbrAnswers--; |
||||
|
||||
// Remove the last answer |
||||
$tmp = array_pop($_SESSION['tmp_answers']['answer']); |
||||
$tmp = array_pop($_SESSION['tmp_answers']['comment']); |
||||
$tmp = array_pop($_SESSION['tmp_answers']['weighting']); |
||||
$tmp = array_pop($_SESSION['tmp_answers']['hotspot_coordinates']); |
||||
$tmp = array_pop($_SESSION['tmp_answers']['hotspot_type']); |
||||
} |
||||
else |
||||
{ |
||||
$msgErr=get_lang('MinHotspot'); |
||||
} |
||||
} |
||||
|
||||
if($moreAnswers) |
||||
{ |
||||
if ($nbrAnswers < 12) |
||||
{ |
||||
$nbrAnswers++; |
||||
|
||||
// Add a new answer |
||||
$_SESSION['tmp_answers']['answer'][]=''; |
||||
$_SESSION['tmp_answers']['comment'][]=''; |
||||
$_SESSION['tmp_answers']['weighting'][]='1'; |
||||
$_SESSION['tmp_answers']['hotspot_coordinates'][]='0;0|0|0'; |
||||
$_SESSION['tmp_answers']['hotspot_type'][]='square'; |
||||
} |
||||
else |
||||
{ |
||||
$msgErr=get_lang('MaxHotspot'); |
||||
} |
||||
|
||||
|
||||
} |
||||
|
||||
if($debug>0){echo str_repeat(' ',2).'$usedInSeveralExercises is untrue'."<br />\n";} |
||||
|
||||
|
||||
if($debug>0){echo str_repeat(' ',4).'$answerType is HOT_SPOT'."<br />\n";} |
||||
$hotspot_colors = array("", // $i starts from 1 on next loop (ugly fix) |
||||
"#4271B5", |
||||
"#FE8E16", |
||||
"#3B3B3B", |
||||
"#BCD631", |
||||
"#D63173", |
||||
"#D7D7D7", |
||||
"#90AFDD", |
||||
"#AF8640", |
||||
"#4F9242", |
||||
"#F4EB24", |
||||
"#ED2024", |
||||
"#45C7F0", |
||||
"#F7BDE2"); |
||||
?> |
||||
|
||||
<h3> |
||||
<?php echo $langQuestion.": ".$questionName; ?> |
||||
</h3> |
||||
<?php |
||||
if(!empty($msgErr)) |
||||
{ |
||||
Display::display_normal_message($msgErr); //main API |
||||
} |
||||
?> |
||||
<table border="0" cellpadding="0" cellspacing="0" width="100%"> |
||||
<tr> |
||||
<td colspan="2" style="border:1px solid #4271b5; border-bottom:none;"><?php echo stripslashes(get_lang('HotspotChoose')); ?></td>
|
||||
</tr> |
||||
<tr> |
||||
<td width="550" valign="top"> |
||||
<script 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_admin.swf?modifyAnswers=<?php echo $modifyAnswers ?>" width="550" height="377">'
|
||||
+ '<param name="movie" value="../plugin/hotspot/hotspot_admin.swf?modifyAnswers=<?php echo $modifyAnswers ?>" />'
|
||||
+ '<param name="test" value="OOoowww fo shooww" />' |
||||
+ '</object>'; |
||||
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 \/>' |
||||
+ 'This content requires the Macromedia Flash Player.<br \/>' |
||||
+ '<a href=http://www.macromedia.com/go/getflash/>Get Flash<\/a>'; |
||||
document.write(alternateContent); // insert non-flash content |
||||
} |
||||
// --> |
||||
</script> |
||||
</td> |
||||
<td valign="top"> |
||||
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>?hotspotadmin=<?php echo $modifyAnswers; ?>" name="frm_exercise">
|
||||
<input type="hidden" name="formSent" value="1" /> |
||||
<input type="hidden" name="nbrAnswers" value="<?php echo $nbrAnswers; ?>" />
|
||||
<table border="0" cellpadding="3" cellspacing="0" style="border: 1px solid #4271b5; border-left:none; width: 100%; "> |
||||
<!-- |
||||
<tr> |
||||
<td colspan="5"><?php echo get_lang('AnswerHotspot'); ?> :</td>
|
||||
</tr> |
||||
--> |
||||
<tr style="background-color: #E6E6E6; height: 37px"> |
||||
<td style="width: 20px; border-bottom: 1px solid #4271b5"> <?php /* echo get_lang('Hotspot'); */ ?></td>
|
||||
<td style="width: 100px; border-bottom: 1px solid #4271b5"><?php echo get_lang('Description'); ?>*</td>
|
||||
<td style="border-bottom: 1px solid #4271b5"><?php echo get_lang('Comment'); ?></td>
|
||||
<td style="width: 60px; border-bottom: 1px solid #4271b5"><?php echo get_lang('QuestionWeighting'); ?>*</td>
|
||||
</tr> |
||||
|
||||
<?php |
||||
for($i=1;$i <= $nbrAnswers;$i++) |
||||
{ |
||||
?> |
||||
|
||||
<tr> |
||||
<td valign="top"><div style="height: 15px; width: 15px; background-color: <?php echo $hotspot_colors[$i]; ?>"> </div></td>
|
||||
<td valign="top" align="left"><input type="text" name="reponse[<?php echo $i; ?>]" value="<?php echo htmlentities($reponse[$i]); ?>" size="12" /></td>
|
||||
<td align="left"><textarea wrap="virtual" rows="3" cols="10" name="comment[<?php echo $i; ?>]" style="width: 100%"><?php echo htmlentities($comment[$i]); ?></textarea></td>
|
||||
<td valign="top"><input type="text" name="weighting[<?php echo $i; ?>]" size="1" value="<?php echo (isset($weighting[$i]) ? $weighting[$i] : 1); ?>" />
|
||||
<input type="hidden" name="hotspot_coordinates[<?php echo $i; ?>]" value="<?php echo (empty($hotspot_coordinates[$i]) ? '0;0|0|0' : $hotspot_coordinates[$i]); ?>" />
|
||||
<input type="hidden" name="hotspot_type[<?php echo $i; ?>]" value="<?php echo (empty($hotspot_type[$i]) ? 'square' : $hotspot_type[$i]); ?>" /></td>
|
||||
</tr> |
||||
|
||||
<?php |
||||
} |
||||
?> |
||||
|
||||
<tr> |
||||
<td colspan="5"> |
||||
<input type="submit" name="lessAnswers" value="<?php echo get_lang('LessHotspots'); ?>" />
|
||||
<input type="submit" name="moreAnswers" value="<?php echo get_lang('MoreHotspots'); ?>" />
|
||||
<hr noshade="noshade" size="1" style="color: #4271b5" /> |
||||
<input type="submit" name="submitAnswers" value="<?php echo get_lang('Ok'); ?>" />
|
||||
<input type="submit" name="cancelAnswers" value="<?php echo get_lang('Cancel'); ?>" onclick="javascript:if(!confirm('<?php echo addslashes(htmlentities(get_lang('ConfirmYourChoice'))); ?>')) return false;" />
|
||||
</td> |
||||
</tr> |
||||
</table> |
||||
</form> |
||||
<table cellpadding="0" cellspacing="0"> |
||||
<tr> |
||||
<td style="text-align:center; vertical-align:top; width:20px;">*</td> |
||||
<td style="width:auto;"><?php echo get_lang('HotspotRequired'); ?></td>
|
||||
</tr> |
||||
</table> |
||||
</td> |
||||
</tr> |
||||
</table> |
||||
|
||||
|
||||
|
||||
|
||||
<?php |
||||
|
||||
if($debug>0){echo str_repeat(' ',0).'$modifyAnswers was set - end'."<br />\n";} |
||||
} |
||||
?> |
@ -0,0 +1,272 @@ |
||||
<?php // $Id: uniquer_answer.class.php 10234 2006-12-26
|
||||
/* |
||||
============================================================================== |
||||
Dokeos - elearning and course management software |
||||
|
||||
Copyright (c) 2004 Dokeos S.A. |
||||
Copyright (c) 2003 Ghent University (UGent) |
||||
Copyright (c) 2001 Universite catholique de Louvain (UCL) |
||||
Copyright (c) Olivier Brouckaert |
||||
|
||||
For a full list of contributors, see "credits.txt". |
||||
The full license can be read in "license.txt". |
||||
|
||||
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 the GNU General Public License for more details. |
||||
|
||||
Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com |
||||
============================================================================== |
||||
*/ |
||||
/** |
||||
============================================================================== |
||||
* File containing the Matching class. |
||||
* |
||||
* @author Eric Marguin |
||||
* @package dokeos.exercise |
||||
============================================================================== |
||||
*/ |
||||
|
||||
if(!class_exists('Matching')): |
||||
|
||||
/** |
||||
CLASS Matching |
||||
* |
||||
* This class allows to instantiate an object of type MULTIPLE_ANSWER (MULTIPLE CHOICE, MULTIPLE ANSWER), |
||||
* extending the class question |
||||
* |
||||
* @author Eric Marguin |
||||
* @package dokeos.exercise |
||||
**/ |
||||
|
||||
class Matching extends Question { |
||||
|
||||
/** |
||||
* Constructor |
||||
*/ |
||||
function Matching(){ |
||||
parent::question(); |
||||
$this -> type = MATCHING; |
||||
} |
||||
|
||||
/** |
||||
* function which redifines Question::createAnswersForm |
||||
* @param the formvalidator instance |
||||
*/ |
||||
function createAnswersForm ($form) { |
||||
|
||||
$defaults = array(); |
||||
|
||||
$nb_matches = $nb_options = 2; |
||||
if($form -> isSubmitted()) |
||||
{ |
||||
$nb_matches = $form -> getSubmitValue('nb_matches'); |
||||
$nb_options = $form -> getSubmitValue('nb_options'); |
||||
if(isset($_POST['lessMatches'])) |
||||
$nb_matches--; |
||||
if(isset($_POST['moreMatches'])) |
||||
$nb_matches++; |
||||
if(isset($_POST['lessOptions'])) |
||||
$nb_options--; |
||||
if(isset($_POST['moreOptions'])) |
||||
$nb_options++; |
||||
|
||||
} |
||||
else if(!empty($this -> id)) |
||||
{ |
||||
$answer = new Answer($this -> id); |
||||
$answer -> read(); |
||||
if(count($answer->nbrAnswers)>0) |
||||
{ |
||||
$a_matches = $a_options = array(); |
||||
$nb_matches = $nb_options = 0; |
||||
for($i=1 ; $i<=$answer->nbrAnswers ; $i++){ |
||||
if($answer -> isCorrect($i)) |
||||
{ |
||||
$nb_matches++; |
||||
$defaults['answer['.$nb_matches.']'] = $answer -> selectAnswer($i); |
||||
$defaults['weighting['.$nb_matches.']'] = $answer -> selectWeighting($i); |
||||
$defaults['matches['.$nb_matches.']'] = $answer -> correct[$i]; |
||||
} |
||||
else |
||||
{ |
||||
$nb_options++; |
||||
$defaults['option['.$nb_options.']'] = $answer -> selectAnswer($i); |
||||
} |
||||
} |
||||
|
||||
} |
||||
} |
||||
else { |
||||
$defaults['answer[1]'] = get_lang('DefaultMakeCorrespond1'); |
||||
$defaults['answer[2]'] = get_lang('DefaultMakeCorrespond2'); |
||||
$defaults['matches[2]'] = '2'; |
||||
$defaults['option[1]'] = get_lang('DefaultMatchingOptA'); |
||||
$defaults['option[2]'] = get_lang('DefaultMatchingOptB'); |
||||
} |
||||
$a_matches = array(); |
||||
for($i=1 ; $i<=$nb_options ; ++$i) |
||||
{ |
||||
$a_matches[$i] = chr(64+$i); // fill the array with A, B, C..... |
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$form -> addElement('hidden', 'nb_matches', $nb_matches); |
||||
$form -> addElement('hidden', 'nb_options', $nb_options); |
||||
|
||||
|
||||
//////////////////////// |
||||
// DISPLAY MATCHES //// |
||||
////////////////////// |
||||
|
||||
$html=' |
||||
<div class="row"> |
||||
<div class="label"> |
||||
'.get_lang('Answers').' |
||||
</div> |
||||
<div class="formw"> |
||||
'.get_lang('MakeCorrespond').' |
||||
<table cellpadding="0" cellspacing="5"> |
||||
<tr bgcolor="#e6e6e6"> |
||||
<td> |
||||
N° |
||||
</td> |
||||
<td> |
||||
'.get_lang('Answer').' |
||||
</td> |
||||
<td> |
||||
'.get_lang('MatchesTo').' |
||||
</td> |
||||
<td> |
||||
Weighting |
||||
</td> |
||||
<td width="0"></td> |
||||
</tr>'; |
||||
$form -> addElement ('html', $html); |
||||
|
||||
|
||||
for($i = 1 ; $i <= $nb_matches ; ++$i) |
||||
{ |
||||
|
||||
$form -> addElement ('html', '<tr><td>'); |
||||
|
||||
$group = array(); |
||||
$puce = FormValidator :: createElement ('text', null,null,'value="'.$i.'"'); |
||||
$puce->freeze(); |
||||
$group[] = $puce; |
||||
$group[] = FormValidator :: createElement ('text', 'answer['.$i.']',null, 'size="30"'); |
||||
$group[] = FormValidator :: createElement ('select', 'matches['.$i.']',null,$a_matches); |
||||
$group[] = FormValidator :: createElement ('text', 'weighting['.$i.']',null, 'style="vertical-align:middle" size="2" value="1"'); |
||||
$form -> addGroup($group, null, null, '</td><td width="0">'); |
||||
|
||||
$form -> addElement ('html', '</td></tr>'); |
||||
|
||||
} |
||||
|
||||
$form -> addElement ('html', '</table></div></div>'); |
||||
$group = array(); |
||||
$group[] = FormValidator :: createElement ('submit', 'lessMatches', '-elem'); |
||||
$group[] = FormValidator :: createElement ('submit', 'moreMatches', '+elem'); |
||||
$form -> addGroup($group); |
||||
|
||||
|
||||
|
||||
//////////////////////// |
||||
// DISPLAY OPTIONS //// |
||||
////////////////////// |
||||
$html=' |
||||
<div class="row"> |
||||
<div class="label"> |
||||
</div> |
||||
<div class="formw"><br /><br /> |
||||
<table cellpadding="0" cellspacing="5"> |
||||
<tr bgcolor="#e6e6e6"> |
||||
<td> |
||||
N° |
||||
</td> |
||||
<td> |
||||
'.get_lang('Answer').' |
||||
</td> |
||||
<td width="0"></td> |
||||
</tr>'; |
||||
$form -> addElement ('html', $html); |
||||
|
||||
|
||||
|
||||
for($i = 1 ; $i <= $nb_options ; ++$i) |
||||
{ |
||||
$form -> addElement ('html', '<tr><td>'); |
||||
|
||||
$group = array(); |
||||
$puce = FormValidator :: createElement ('text', null,null,'value="'.chr(64+$i).'"'); |
||||
$puce->freeze(); |
||||
$group[] = $puce; |
||||
$group[] = FormValidator :: createElement ('text', 'option['.$i.']',null, 'size="30"'); |
||||
$form -> addGroup($group, null, null, '</td><td width="0">'); |
||||
|
||||
$form -> addElement ('html', '</td></tr>'); |
||||
|
||||
} |
||||
|
||||
$form -> addElement ('html', '</table></div></div>'); |
||||
$group = array(); |
||||
$group[] = FormValidator :: createElement ('submit', 'lessOptions', '-elem'); |
||||
$group[] = FormValidator :: createElement ('submit', 'moreOptions', '+elem'); |
||||
$form -> addGroup($group); |
||||
|
||||
$form -> setDefaults($defaults); |
||||
|
||||
$form->setConstants(array('nb_matches' => $nb_matches,'nb_options' => $nb_options)); |
||||
|
||||
} |
||||
|
||||
|
||||
/** |
||||
* abstract function which creates the form to create / edit the answers of the question |
||||
* @param the formvalidator instance |
||||
*/ |
||||
function processAnswersCreation($form) { |
||||
|
||||
$nb_matches = $form -> getSubmitValue('nb_matches'); |
||||
$nb_options = $form -> getSubmitValue('nb_options'); |
||||
$this -> weighting = 0; |
||||
$objAnswer = new Answer($this->id); |
||||
|
||||
$position = 0; |
||||
|
||||
// insert the options |
||||
for($i=1 ; $i<=$nb_options ; ++$i) |
||||
{ |
||||
$position++; |
||||
$option = $form -> getSubmitValue('option['.$i.']'); |
||||
$objAnswer->createAnswer($option, 0, '', 0, $position); |
||||
} |
||||
|
||||
// insert the answers |
||||
for($i=1 ; $i<=$nb_matches ; ++$i) |
||||
{ |
||||
$position++; |
||||
$answer = $form -> getSubmitValue('answer['.$i.']'); |
||||
$matches = $form -> getSubmitValue('matches['.$i.']'); |
||||
$weighting = $form -> getSubmitValue('weighting['.$i.']'); |
||||
$this -> weighting += $weighting; |
||||
$objAnswer->createAnswer($answer,$matches,'',$weighting,$position); |
||||
} |
||||
|
||||
$objAnswer->save(); |
||||
$this->save(); |
||||
|
||||
echo '<script type="text/javascript">window.location.href="admin.php"</script>'; |
||||
|
||||
} |
||||
|
||||
} |
||||
|
||||
endif; |
||||
?> |
@ -0,0 +1,192 @@ |
||||
<?php // $Id: uniquer_answer.class.php 10234 2006-12-26
|
||||
/* |
||||
============================================================================== |
||||
Dokeos - elearning and course management software |
||||
|
||||
Copyright (c) 2004 Dokeos S.A. |
||||
Copyright (c) 2003 Ghent University (UGent) |
||||
Copyright (c) 2001 Universite catholique de Louvain (UCL) |
||||
Copyright (c) Olivier Brouckaert |
||||
|
||||
For a full list of contributors, see "credits.txt". |
||||
The full license can be read in "license.txt". |
||||
|
||||
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 the GNU General Public License for more details. |
||||
|
||||
Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com |
||||
============================================================================== |
||||
*/ |
||||
/** |
||||
============================================================================== |
||||
* File containing the MultipleAnswer class. |
||||
* |
||||
* @author Eric Marguin |
||||
* @package dokeos.exercise |
||||
============================================================================== |
||||
*/ |
||||
|
||||
if(!class_exists('MultipleAnswer')): |
||||
|
||||
/** |
||||
CLASS MultipleAnswer |
||||
* |
||||
* This class allows to instantiate an object of type MULTIPLE_ANSWER (MULTIPLE CHOICE, MULTIPLE ANSWER), |
||||
* extending the class question |
||||
* |
||||
* @author Eric Marguin |
||||
* @package dokeos.exercise |
||||
**/ |
||||
|
||||
class MultipleAnswer extends Question { |
||||
|
||||
/** |
||||
* Constructor |
||||
*/ |
||||
function MultipleAnswer(){ |
||||
parent::question(); |
||||
$this -> type = MULTIPLE_ANSWER; |
||||
} |
||||
|
||||
/** |
||||
* function which redifines Question::createAnswersForm |
||||
* @param the formvalidator instance |
||||
* @param the answers number to display |
||||
*/ |
||||
function createAnswersForm ($form) { |
||||
|
||||
$nb_answers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 2; |
||||
$nb_answers += (isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0)); |
||||
|
||||
$html=' |
||||
<div class="row"> |
||||
<div class="label"> |
||||
'.get_lang('Answers').' |
||||
</div> |
||||
<div class="formw"> |
||||
<table cellpadding="0" cellspacing="5"> |
||||
<tr bgcolor="#e6e6e6"> |
||||
<td> |
||||
N° |
||||
</td> |
||||
<td> |
||||
True |
||||
</td> |
||||
<td> |
||||
Answer |
||||
</td> |
||||
<td> |
||||
Comment |
||||
</td> |
||||
<td> |
||||
Weighting |
||||
</td> |
||||
<td width="0"></td> |
||||
</tr>'; |
||||
$form -> addElement ('html', $html); |
||||
|
||||
$defaults = array(); |
||||
if(!empty($this -> id)) |
||||
{ |
||||
$answer = new Answer($this -> id); |
||||
$answer -> read(); |
||||
if(count($answer->nbrAnswers)>0 && !$form->isSubmitted()) |
||||
{ |
||||
$nb_answers = $answer->nbrAnswers; |
||||
} |
||||
} |
||||
|
||||
$form -> addElement('hidden', 'nb_answers'); |
||||
|
||||
for($i = 1 ; $i <= $nb_answers ; ++$i) |
||||
{ |
||||
|
||||
if(is_object($answer)) |
||||
{ |
||||
$defaults['answer['.$i.']'] = $answer -> answer[$i]; |
||||
$defaults['comment['.$i.']'] = $answer -> comment[$i]; |
||||
$defaults['weighting['.$i.']'] = $answer -> weighting[$i]; |
||||
$defaults['correct['.$i.']'] = $answer -> correct[$i]; |
||||
} |
||||
|
||||
$form -> addElement ('html', '<tr><td>'); |
||||
|
||||
$group = array(); |
||||
$puce = FormValidator :: createElement ('text', null,null,'value="1"'); |
||||
$puce->freeze(); |
||||
$group[] = $puce; |
||||
$group[] = FormValidator :: createElement ('checkbox', 'correct['.$i.']', null, null, $i); |
||||
$group[] = FormValidator :: createElement ('textarea', 'answer['.$i.']',null, 'style="vertical-align:middle" cols="30"'); |
||||
$group[] = FormValidator :: createElement ('textarea', 'comment['.$i.']',null, 'style="vertical-align:middle" cols="30"'); |
||||
$group[] = FormValidator :: createElement ('text', 'weighting['.$i.']',null, 'style="vertical-align:middle" size="5" value="0"'); |
||||
$form -> addGroup($group, null, null, '</td><td width="0">'); |
||||
|
||||
$form -> addElement ('html', '</td></tr>'); |
||||
|
||||
} |
||||
|
||||
$form -> addElement ('html', '</table></div></div>'); |
||||
$group = array(); |
||||
$group[] = FormValidator :: createElement ('submit', 'lessAnswers', '-answ'); |
||||
$group[] = FormValidator :: createElement ('submit', 'moreAnswers', '+answ'); |
||||
$form -> addGroup($group); |
||||
|
||||
$form -> setDefaults($defaults); |
||||
$form->setConstants(array('nb_answers' => $nb_answers)); |
||||
|
||||
|
||||
} |
||||
|
||||
|
||||
/** |
||||
* abstract function which creates the form to create / edit the answers of the question |
||||
* @param the formvalidator instance |
||||
* @param the answers number to display |
||||
*/ |
||||
function processAnswersCreation($form) { |
||||
|
||||
$questionWeighting = $nbrGoodAnswers = 0; |
||||
|
||||
$objAnswer = new Answer($this->id); |
||||
|
||||
$nb_answers = $form -> getSubmitValue('nb_answers'); |
||||
|
||||
for($i=1 ; $i <= $nb_answers ; $i++) |
||||
{ |
||||
$answer = trim($form -> getSubmitValue('answer['.$i.']')); |
||||
$comment = trim($form -> getSubmitValue('comment['.$i.']')); |
||||
$weighting = trim($form -> getSubmitValue('weighting['.$i.']')); |
||||
$goodAnswer = trim($form -> getSubmitValue('correct['.$i.']')); |
||||
|
||||
if($goodAnswer) |
||||
{ |
||||
$nbrGoodAnswers++; |
||||
$weighting = abs($weighting); |
||||
if($weighting > 0) |
||||
{ |
||||
$questionWeighting += $weighting; |
||||
} |
||||
} |
||||
|
||||
$objAnswer -> createAnswer($answer,$goodAnswer,$comment,$weighting,$i); |
||||
|
||||
} |
||||
|
||||
// saves the answers into the data base |
||||
$objAnswer -> save(); |
||||
|
||||
// sets the total weighting of the question |
||||
$this -> updateWeighting($questionWeighting); |
||||
$this -> save(); |
||||
|
||||
echo '<script type="text/javascript">window.location.href="admin.php"</script>'; |
||||
} |
||||
|
||||
} |
||||
|
||||
endif; |
||||
?> |
@ -1,328 +0,0 @@ |
||||
<?php // $Id: statement_admin.inc.php 10545 2006-12-21 15:09:31Z elixir_inter $
|
||||
/* |
||||
============================================================================== |
||||
Dokeos - elearning and course management software |
||||
|
||||
Copyright (c) 2004 Dokeos S.A. |
||||
Copyright (c) 2003 Ghent University (UGent) |
||||
Copyright (c) 2001 Universite catholique de Louvain (UCL) |
||||
|
||||
For a full list of contributors, see "credits.txt". |
||||
The full license can be read in "license.txt". |
||||
|
||||
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 the GNU General Public License for more details. |
||||
|
||||
Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium |
||||
Mail: info@dokeos.com |
||||
============================================================================== |
||||
*/ |
||||
/** |
||||
============================================================================== |
||||
* STATEMENT ADMINISTRATION |
||||
* This script allows to manage the statements of questions. |
||||
* It is included from the script admin.php |
||||
* |
||||
* @author Olivier Brouckaert |
||||
* @package dokeos.exercise |
||||
============================================================================== |
||||
*/ |
||||
|
||||
/* |
||||
============================================================================== |
||||
INIT SECTION |
||||
============================================================================== |
||||
*/ |
||||
|
||||
include_once(api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php'); |
||||
|
||||
// ALLOWED_TO_INCLUDE is defined in admin.php |
||||
if(!defined('ALLOWED_TO_INCLUDE')) |
||||
{ |
||||
exit(); |
||||
} |
||||
|
||||
//debug var. Set to 0 if you don't want any debug display |
||||
$debug = 0; |
||||
|
||||
$fck_attribute['Width'] = '80%'; |
||||
$fck_attribute['Height'] = '300'; |
||||
$fck_attribute['ToolbarSet'] = 'Small'; |
||||
|
||||
// the question form has been submitted |
||||
// this question form is the one below. |
||||
// In case the form has been submitted, at the end of the process part of this script, we "skip" the form |
||||
// display and pass to answer_admin.inc.php which displays a form for the answer itself |
||||
if($submitQuestion) |
||||
{ |
||||
if($debug>0){echo str_repeat(' ',2).'$submitQuestion is true'."<br />\n";} |
||||
|
||||
$questionName=trim(stripslashes($_POST['questionName'])); |
||||
$questionDescription=trim(stripslashes($_POST['questionDescription'])); |
||||
$_FILES['imageUpload']['name']=strtolower($_FILES['imageUpload']['name']); |
||||
|
||||
$hotspotErr = false; |
||||
|
||||
// no name given |
||||
if(!$modifyQuestion && (empty($questionName) || ($answerType == HOT_SPOT && ($_FILES['imageUpload']['type'] != 'image/jpeg' && $_FILES['imageUpload']['type'] != 'image/pjpeg' && $_FILES['imageUpload']['type'] != 'image/jpg')) || ($answerType == HOT_SPOT && empty($_FILES['imageUpload']['name'])))) |
||||
{ |
||||
if(($_FILES['imageUpload']['type'] != 'image/jpeg' && $_FILES['imageUpload']['type'] != 'image/pjpeg' && $_FILES['imageUpload']['type'] != 'image/jpg') && !$modifyQuestion) |
||||
{ |
||||
$msgErr = get_lang('langOnlyJPG'); |
||||
$hotspotErr = true; |
||||
} |
||||
if(empty($_FILES['imageUpload']['name']) && !$modifyQuestion) |
||||
{ |
||||
$msgErr=get_lang('NoImage'); |
||||
$hotspotErr = true; |
||||
} |
||||
if(empty($questionName)) |
||||
{ |
||||
$msgErr=get_lang('GiveQuestion'); |
||||
} |
||||
} |
||||
// checks if the question is used in several exercises |
||||
elseif($exerciseId && !$modifyIn && $objQuestion->selectNbrExercises() > 1) |
||||
{ |
||||
if($debug>0){echo str_repeat(' ',4).'$exerciseId is set and $modifyIn is unset and this question is in more than one exercise'."<br />\n";} |
||||
$usedInSeveralExercises=1; |
||||
|
||||
// if a picture has been set |
||||
if($_FILES['imageUpload']['size']) |
||||
{ |
||||
// saves the picture into a temporary file |
||||
$objQuestion->setTmpPicture($_FILES['imageUpload']['tmp_name'],$_FILES['imageUpload']['name']); |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
if($debug>0){echo str_repeat(' ',4).'You have chosen to modify/add a question locally'."<br />\n";} |
||||
// if the user has chosed to modify the question only in the current exercise |
||||
if($modifyIn == 'thisExercise') |
||||
{ |
||||
// duplicates the question |
||||
$questionId=$objQuestion->duplicate(); |
||||
|
||||
// deletes the old question |
||||
$objQuestion->delete($exerciseId); |
||||
|
||||
// removes the old question ID from the question list of the Exercise object |
||||
$objExercise->removeFromList($modifyQuestion); |
||||
|
||||
$nbrQuestions--; |
||||
|
||||
// construction of the duplicated Question |
||||
$objQuestion=new Question(); |
||||
|
||||
$objQuestion->read($questionId); |
||||
|
||||
// adds the exercise ID into the exercise list of the Question object |
||||
$objQuestion->addToList($exerciseId); |
||||
|
||||
// construction of the Answer object |
||||
$objAnswerTmp=new Answer($modifyQuestion); |
||||
|
||||
// copies answers from $modifyQuestion to $questionId |
||||
$objAnswerTmp->duplicate($questionId); |
||||
|
||||
// destruction of the Answer object |
||||
unset($objAnswerTmp); |
||||
} |
||||
|
||||
$objQuestion->updateTitle($questionName); |
||||
$objQuestion->updateDescription($questionDescription); |
||||
|
||||
$objQuestion->updateType($_REQUEST['answerType']); |
||||
$objQuestion->save($exerciseId); |
||||
|
||||
// if a picture has been set or checkbox "delete" has been checked |
||||
if($_FILES['imageUpload']['size'] || $deletePicture) |
||||
{ |
||||
// we remove the picture |
||||
$objQuestion->removePicture(); |
||||
|
||||
// if we add a new picture |
||||
if($_FILES['imageUpload']['size']) |
||||
{ |
||||
// image is already saved in a temporary file |
||||
if($modifyIn) |
||||
{ |
||||
$objQuestion->getTmpPicture(); |
||||
} |
||||
// saves the picture coming from POST FILE |
||||
else |
||||
{ |
||||
$objQuestion->uploadPicture($_FILES['imageUpload']['tmp_name'],$_FILES['imageUpload']['name']); |
||||
|
||||
if(!$objQuestion->resizePicture("any", 350)) |
||||
{ |
||||
$msgErr = get_lang('langHotspotBadMetadata'); |
||||
$hotspotErr = true; |
||||
|
||||
$objQuestion->removePicture(); |
||||
} |
||||
} |
||||
} |
||||
|
||||
if($hotspotErr === false) |
||||
{ |
||||
$objQuestion->save($exerciseId); |
||||
} |
||||
else |
||||
{ |
||||
if($newQuestion) |
||||
$objQuestion->removeFromList($exerciseId); |
||||
} |
||||
} |
||||
|
||||
if($hotspotErr === false) |
||||
{ |
||||
$questionId=$objQuestion->selectId(); |
||||
|
||||
if($exerciseId) |
||||
{ |
||||
// adds the question ID into the question list of the Exercise object |
||||
if($objExercise->addToList($questionId)) |
||||
{ |
||||
$objExercise->save(); |
||||
|
||||
$nbrQuestions++; |
||||
} |
||||
} |
||||
|
||||
if($newQuestion) |
||||
{ |
||||
// goes to answer administration |
||||
// -> answer_admin.inc.php |
||||
$modifyAnswers=$questionId; |
||||
} |
||||
else |
||||
{ |
||||
// goes to exercise viewing |
||||
$editQuestion=$questionId; |
||||
} |
||||
|
||||
// avoids displaying the following form in case we're editing the answer |
||||
unset($newQuestion,$modifyQuestion); |
||||
} |
||||
} |
||||
if($debug>0){echo str_repeat(' ',2).'$submitQuestion is true - end'."<br />\n";} |
||||
|
||||
} |
||||
else |
||||
{ |
||||
if($debug>0){echo str_repeat(' ',2).'$submitQuestion was unset'."<br />\n";} |
||||
|
||||
// if we don't come here after having cancelled the warning message "used in serveral exercises" |
||||
if(!$buttonBack) |
||||
{ |
||||
if($debug>0){echo str_repeat(' ',4).'$buttonBack was unset'."<br />\n";} |
||||
$questionName=$objQuestion->selectTitle(); |
||||
$questionDescription=$objQuestion->selectDescription(); |
||||
$answerType= isset($_REQUEST['answerType']) ? $_REQUEST['answerType'] : $objQuestion->selectType(); |
||||
$pictureName=$objQuestion->selectPicture(); |
||||
} |
||||
|
||||
$okPicture=empty($pictureName)?false:true; |
||||
if($debug>0){echo str_repeat(' ',2).'$submitQuestion was unset - end'."<br />\n";} |
||||
} |
||||
if(($newQuestion || $modifyQuestion) && !$usedInSeveralExercises) |
||||
{ |
||||
if($debug>0){echo str_repeat(' ',2).'$newQuestion or modifyQuestion was set but the question only exists in this exercise'."<br />\n";} |
||||
|
||||
?> |
||||
|
||||
<h3> |
||||
<?php echo $questionName; ?> |
||||
</h3> |
||||
|
||||
<?php |
||||
if($okPicture) |
||||
{ |
||||
?> |
||||
|
||||
<img src="../document/download.php?doc_url=%2Fimages%2F<?php echo $pictureName; ?>" border="0">
|
||||
<?php |
||||
} |
||||
|
||||
if(!empty($msgErr)) |
||||
{ |
||||
Display::display_normal_message($msgErr); //main API |
||||
} |
||||
//api_disp_html_area('questionDescription',$questionDescription,'250px'); |
||||
$defaultType = isset($_REQUEST['answerType']) ? $_REQUEST['answerType'] : $answerType; |
||||
$user = array("questionDescription"=>$questionDescription, |
||||
"questionName"=>$questionName, |
||||
"answerType"=>$defaultType); |
||||
|
||||
|
||||
$form = new FormValidator('introduction_text','post',$_SERVER['PHP_SELF']."?modifyQuestion=".$modifyQuestion."&newQuestion=".$newQuestion); |
||||
//$renderer =&$form->defaultRenderer(); |
||||
//$renderer->setElementTemplate('<div align ="left">{element}</div>'); |
||||
//$attrs = array("align"=>"right"); |
||||
|
||||
//$buttons[] = &$form->createElement('static','label1',get_lang('Question')); |
||||
//$buttons[] = &$form->createElement('text','questionName'); |
||||
//$form->addGroup($buttons, null, null, ' '); |
||||
|
||||
//$form->addelement('static','label1',get_lang('Question')); |
||||
$form->addelement('text','questionName',get_lang('Question')); |
||||
$form->addelement('hidden','myid',$_REQUEST['myid']); |
||||
$form->add_html_editor('questionDescription', get_lang('questionDescription')); |
||||
//$form->addElement('html_editor','questionDescription',get_lang('QuestionDescription'),false); |
||||
if($okPicture) |
||||
{ |
||||
$form->addelement('checkbox','deletePicture',get_lang('DeletePicture')); |
||||
} |
||||
|
||||
if($modifyQuestion) { |
||||
$obj_group_type[] = &HTML_QuickForm::createElement('radio', NULL, NULL, get_lang('UniqueSelect'),1); |
||||
$obj_group_type[] = &HTML_QuickForm::createElement('radio', NULL, NULL, get_lang('MultipleSelect'),2); |
||||
$obj_group_type[] = &HTML_QuickForm::createElement('radio', NULL, NULL, get_lang('Matching'),4); |
||||
$obj_group_type[] = &HTML_QuickForm::createElement('radio', NULL, NULL, get_lang('FillBlanks'),3); |
||||
$obj_group_type[] = &HTML_QuickForm::createElement('radio', NULL, NULL, get_lang('freeAnswer'),5); |
||||
$obj_group_type[] = &HTML_QuickForm::createElement('radio', NULL, NULL, get_lang('Hotspot'),6); |
||||
$form->addGroup($obj_group_type, 'answerType', get_lang('AnswerType').':','<br />'); |
||||
} |
||||
else { |
||||
$form->addElement('hidden','answerType',$_REQUEST['answerType']); |
||||
} |
||||
|
||||
if($answerType == HOT_SPOT) |
||||
$form->addElement('file','imageUpload'); |
||||
$form->addElement('submit','submitQuestion',get_lang('Ok')); |
||||
|
||||
$form->setDefaults($user); |
||||
|
||||
$form->display(); |
||||
|
||||
?> |
||||
|
||||
<!-- |
||||
<td valign="top"><?php echo get_lang('AnswerType'); ?> :</td>
|
||||
<td><input class="checkbox" type="radio" name="answerType" value="1" <?php if($answerType <= 1) echo 'checked="checked"'; ?>> <?php echo get_lang('UniqueSelect'); ?><br />
|
||||
<input class="checkbox" type="radio" name="answerType" value="2" <?php if($answerType == 2) echo 'checked="checked"'; ?>> <?php echo get_lang('MultipleSelect'); ?><br />
|
||||
<input class="checkbox" type="radio" name="answerType" value="4" <?php if($answerType == 4) echo 'checked="checked"'; ?>> <?php echo get_lang('Matching'); ?><br />
|
||||
<input class="checkbox" type="radio" name="answerType" value="3" <?php if($answerType == 3) echo 'checked="checked"'; ?>> <?php echo get_lang('FillBlanks'); ?><br />
|
||||
<input class="checkbox" type="radio" name="answerType" value="5" <?php if($answerType == 5) echo 'checked="checked"'; ?>> <?php echo get_lang('freeAnswer'); ?> |
||||
<input class="checkbox" type="radio" name="answerType" value="6" <?php if($answerType == 6) echo 'checked="checked"'; ?>> <?php echo get_lang('Hotspot'); ?> |
||||
</td> |
||||
</tr> |
||||
<tr> |
||||
<td> </td> |
||||
<td> |
||||
<input type="hidden" name="myid" value="<?php echo $_REQUEST['myid'];?>">
|
||||
<input type="submit" name="submitQuestion" value="<?php echo get_lang('Ok'); ?>">
|
||||
<!-- <input type="submit" name="cancelQuestion" value="<?php echo get_lang('Cancel'); ?>" onclick="javascript:if(!confirm('<?php echo addslashes(htmlentities(get_lang('ConfirmYourChoice'))); ?>')) return false;">
|
||||
<!-- </td> |
||||
</tr> |
||||
</table> |
||||
</form>--> |
||||
|
||||
<?php |
||||
} |
||||
?> |
@ -0,0 +1,198 @@ |
||||
<?php // $Id: uniquer_answer.class.php 10234 2006-12-26
|
||||
/* |
||||
============================================================================== |
||||
Dokeos - elearning and course management software |
||||
|
||||
Copyright (c) 2004 Dokeos S.A. |
||||
Copyright (c) 2003 Ghent University (UGent) |
||||
Copyright (c) 2001 Universite catholique de Louvain (UCL) |
||||
Copyright (c) Olivier Brouckaert |
||||
|
||||
For a full list of contributors, see "credits.txt". |
||||
The full license can be read in "license.txt". |
||||
|
||||
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 the GNU General Public License for more details. |
||||
|
||||
Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com |
||||
============================================================================== |
||||
*/ |
||||
/** |
||||
============================================================================== |
||||
* File containing the UNIQUE_ANSWER class. |
||||
* |
||||
* @author Eric Marguin |
||||
* @package dokeos.exercise |
||||
============================================================================== |
||||
*/ |
||||
|
||||
if(!class_exists('UniqueAnswer')): |
||||
|
||||
/** |
||||
CLASS UNIQUE_ANSWER |
||||
* |
||||
* This class allows to instantiate an object of type UNIQUE_ANSWER (MULTIPLE CHOICE, UNIQUE ANSWER), |
||||
* extending the class question |
||||
* |
||||
* @author Eric Marguin |
||||
* @package dokeos.exercise |
||||
**/ |
||||
|
||||
class UniqueAnswer extends Question { |
||||
|
||||
/** |
||||
* Constructor |
||||
*/ |
||||
function UniqueAnswer(){ |
||||
parent::question(); |
||||
$this -> type = UNIQUE_ANSWER; |
||||
} |
||||
|
||||
/** |
||||
* function which redifines Question::createAnswersForm |
||||
* @param the formvalidator instance |
||||
* @param the answers number to display |
||||
*/ |
||||
function createAnswersForm ($form) { |
||||
|
||||
|
||||
$nb_answers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 2; |
||||
$nb_answers += (isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0)); |
||||
|
||||
$html=' |
||||
<div class="row"> |
||||
<div class="label"> |
||||
'.get_lang('Answers').' |
||||
</div> |
||||
<div class="formw"> |
||||
<table cellpadding="0" cellspacing="5"> |
||||
<tr bgcolor="#e6e6e6"> |
||||
<td> |
||||
N° |
||||
</td> |
||||
<td> |
||||
True |
||||
</td> |
||||
<td> |
||||
Answer |
||||
</td> |
||||
<td> |
||||
Comment |
||||
</td> |
||||
<td> |
||||
Weighting |
||||
</td> |
||||
<td width="0"></td> |
||||
</tr>'; |
||||
$form -> addElement ('html', $html); |
||||
|
||||
$defaults = array(); |
||||
$correct = 0; |
||||
if(!empty($this -> id)) |
||||
{ |
||||
$answer = new Answer($this -> id); |
||||
$answer -> read(); |
||||
if(count($answer->nbrAnswers)>0 && !$form->isSubmitted()) |
||||
{ |
||||
$nb_answers = $answer->nbrAnswers; |
||||
} |
||||
} |
||||
|
||||
$form -> addElement('hidden', 'nb_answers'); |
||||
|
||||
for($i = 1 ; $i <= $nb_answers ; ++$i) |
||||
{ |
||||
|
||||
if(is_object($answer)) |
||||
{ |
||||
if($answer -> correct[$i]) |
||||
{ |
||||
$correct = $i; |
||||
} |
||||
$defaults['answer['.$i.']'] = $answer -> answer[$i]; |
||||
$defaults['comment['.$i.']'] = $answer -> comment[$i]; |
||||
$defaults['weighting['.$i.']'] = $answer -> weighting[$i]; |
||||
} |
||||
|
||||
$form -> addElement ('html', '<tr><td>'); |
||||
|
||||
$group = array(); |
||||
$puce = FormValidator :: createElement ('text', null,null,'value="'.$i.'"'); |
||||
$puce->freeze(); |
||||
$group[] = $puce; |
||||
$group[] = FormValidator :: createElement ('radio', 'correct', null, null, $i); |
||||
$group[] = FormValidator :: createElement ('textarea', 'answer['.$i.']',null, 'style="vertical-align:middle" cols="30"'); |
||||
$group[] = FormValidator :: createElement ('textarea', 'comment['.$i.']',null, 'style="vertical-align:middle" cols="30"'); |
||||
$group[] = FormValidator :: createElement ('text', 'weighting['.$i.']',null, 'style="vertical-align:middle" size="5" value="0"'); |
||||
$form -> addGroup($group, null, null, '</td><td width="0">'); |
||||
|
||||
$form -> addElement ('html', '</td></tr>'); |
||||
|
||||
} |
||||
|
||||
$form -> addElement ('html', '</table></div></div>'); |
||||
$group = array(); |
||||
$group[] = FormValidator :: createElement ('submit', 'lessAnswers', '-answ'); |
||||
$group[] = FormValidator :: createElement ('submit', 'moreAnswers', '+answ'); |
||||
$form -> addGroup($group); |
||||
|
||||
$defaults['correct'] = $correct; |
||||
$form -> setDefaults($defaults); |
||||
|
||||
$form->setConstants(array('nb_answers' => $nb_answers)); |
||||
|
||||
} |
||||
|
||||
|
||||
/** |
||||
* abstract function which creates the form to create / edit the answers of the question |
||||
* @param the formvalidator instance |
||||
* @param the answers number to display |
||||
*/ |
||||
function processAnswersCreation($form) { |
||||
|
||||
$questionWeighting = $nbrGoodAnswers = 0; |
||||
|
||||
$correct = $form -> getSubmitValue('correct'); |
||||
$objAnswer = new Answer($this->id); |
||||
$nb_answers = $form -> getSubmitValue('nb_answers'); |
||||
|
||||
for($i=1 ; $i <= $nb_answers ; $i++) |
||||
{ |
||||
$answer = trim($form -> getSubmitValue('answer['.$i.']')); |
||||
$comment = trim($form -> getSubmitValue('comment['.$i.']')); |
||||
$weighting = trim($form -> getSubmitValue('weighting['.$i.']')); |
||||
|
||||
$goodAnswer= ($correct == $i) ? true : false; |
||||
|
||||
if($goodAnswer) |
||||
{ |
||||
$nbrGoodAnswers++; |
||||
$weighting = abs($weighting); |
||||
if($weighting > 0) |
||||
{ |
||||
$questionWeighting += $weighting; |
||||
} |
||||
} |
||||
|
||||
$objAnswer -> createAnswer($answer,$goodAnswer,$comment,$weighting,$i); |
||||
|
||||
} |
||||
|
||||
// saves the answers into the data base |
||||
$objAnswer -> save(); |
||||
|
||||
// sets the total weighting of the question |
||||
$this -> updateWeighting($questionWeighting); |
||||
$this -> save(); |
||||
echo '<script type="text/javascript">window.location.href="admin.php"</script>'; |
||||
} |
||||
|
||||
} |
||||
|
||||
endif; |
||||
?> |
Loading…
Reference in new issue