[svn r10594] major commit :

- 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
Eric Marguin 18 years ago
parent b2ae4ce07e
commit 63f47b7b9b
  1. 61
      main/exercice/admin.php
  2. 6
      main/exercice/answer.class.php
  3. 13
      main/exercice/answer_admin.inc.php
  4. 10
      main/exercice/exercice_submit.php
  5. 7
      main/exercice/exercise.lib.php
  6. 5
      main/exercice/exercise_result.php
  7. 3
      main/exercice/exercise_show.php
  8. 3
      main/exercice/feedback.php
  9. 148
      main/exercice/fill_blanks.class.php
  10. 90
      main/exercice/freeanswer.class.php
  11. 92
      main/exercice/hotspot.class.php
  12. 3
      main/exercice/hotspot_actionscript.as.php
  13. 3
      main/exercice/hotspot_actionscript_admin.as.php
  14. 393
      main/exercice/hotspot_admin.inc.php
  15. 3
      main/exercice/hotspot_answers.as.php
  16. 3
      main/exercice/mark_free_answer.php
  17. 272
      main/exercice/matching.class.php
  18. 192
      main/exercice/multiple_answer.class.php
  19. 146
      main/exercice/question.class.php
  20. 327
      main/exercice/question_admin.inc.php
  21. 9
      main/exercice/question_list_admin.inc.php
  22. 11
      main/exercice/question_pool.php
  23. 328
      main/exercice/statement_admin.inc.php
  24. 198
      main/exercice/unique_answer.class.php

@ -1,4 +1,4 @@
<?php // $Id: admin.php 10204 2006-11-26 20:46:53Z pcool $
<?php // $Id: admin.php 10594 2007-01-05 13:54:24Z elixir_inter $
/*
==============================================================================
Dokeos - elearning and course management software
@ -75,7 +75,6 @@ include('question.class.php');
include('answer.class.php');
// name of the language file that needs to be included
$language_file='exercice';
@ -141,14 +140,7 @@ $objExercise = $_SESSION['objExercise'];
$objQuestion = $_SESSION['objQuestion'];
$objAnswer = $_SESSION['objAnswer'];
// answer types
define(UNIQUE_ANSWER, 1);
define(MULTIPLE_ANSWER, 2);
define(FILL_IN_BLANKS, 3);
define(MATCHING, 4);
define(FREE_ANSWER, 5);
define(HOT_SPOT, 6);
define(HOT_SPOT_ORDER, 7);
// allows script inclusions
define(ALLOWED_TO_INCLUDE,1);
@ -214,20 +206,17 @@ if($editQuestion || $newQuestion || $modifyQuestion || $modifyAnswers)
{
if($editQuestion || $newQuestion)
{
// construction of the Question object
$objQuestion=new Question();
// saves the object into the session
api_session_register('objQuestion');
// reads question data
if($editQuestion)
{
// question not found
if(!$objQuestion->read($editQuestion))
if(!$objQuestion = Question::read($editQuestion))
{
die(get_lang('QuestionNotFound'));
}
// saves the object into the session
api_session_register('objQuestion');
}
}
@ -237,11 +226,6 @@ if($editQuestion || $newQuestion || $modifyQuestion || $modifyAnswers)
// gets the question ID
$questionId=$objQuestion->selectId();
}
// question not found
else
{
die(get_lang('QuestionNotFound'));
}
}
// if cancelling an exercise
@ -432,7 +416,7 @@ function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
}
// -->
</script>";
$interbreadcrumb[] = array ("url"=>"exercice.php", "name"=> get_lang('Exercices'));
Display::display_header($nameTools,"Exercise");
?>
@ -441,39 +425,20 @@ Display::display_header($nameTools,"Exercise");
</h4>
<?php
if($newQuestion || $modifyQuestion)
if($newQuestion || $editQuestion)
{
// statement management
$type = $_REQUEST['answerType'];
?><input type="hidden" name="Type" value=" <?php echo $type; ?>" />
?><input type="hidden" name="Type" value="<?php echo $type; ?>" />
<?php
include("statement_admin.inc.php");
}
/*if($modifyAnswers && !$_REQUEST['setWeighting'])
{ // this might be loaded after statement_admin (second step of answers writing)
// and $modifyAnswers is then set within statement_admin.inc.php
// answer management
include('answer_admin.inc.php');
}
*/
if($modifyAnswers)
{ // this might be loaded after statement_admin (second step of answers writing)
// and $modifyAnswers is then set within statement_admin.inc.php
// answer management
include('answer_admin.inc.php');
include('question_admin.inc.php');
}
if($editQuestion || $usedInSeveralExercises)
if(isset($_GET['hotspotadmin']))
{
// question management
include('question_admin.inc.php');
include('hotspot_admin.inc.php');
}
if(!$newQuestion && !$modifyQuestion && !$editQuestion && !$modifyAnswers)
if(!$newQuestion && !$modifyQuestion && !$editQuestion && !isset($_GET['hotspotadmin']))
{
// exercise management
include('exercise_admin.inc.php');

@ -1,4 +1,4 @@
<?php // $Id: answer.class.php 10237 2006-11-28 14:54:07Z develop-it $
<?php // $Id: answer.class.php 10594 2007-01-05 13:54:24Z elixir_inter $
/*
==============================================================================
Dokeos - elearning and course management software
@ -396,6 +396,7 @@ $this->hotspot_coordinates[$i]=$object->hotspot_coordinates;
"`position` = '$position' " .
"WHERE `id` =$position " .
"AND `question_id` =$questionId";
api_sql_query($sql,__FILE__,__LINE__);
}
@ -418,7 +419,7 @@ $this->hotspot_coordinates[$i]=$object->hotspot_coordinates;
$sql="INSERT INTO `$TBL_REPONSES`" .
"(id,question_id,answer,correct,comment," .
"ponderation,position,hotspot_coordinates,hotspot_type) VALUES";
for($i=1;$i <= $this->new_nbrAnswers;$i++)
{
$answer=addslashes($this->new_answer[$i]);
@ -434,6 +435,7 @@ $this->hotspot_coordinates[$i]=$object->hotspot_coordinates;
}
$sql = substr($sql,0,-1);
api_sql_query($sql,__FILE__,__LINE__);
// moves $new_* arrays

@ -1,4 +1,4 @@
<?php // $Id: answer_admin.inc.php 10285 2006-12-04 09:52:39Z develop-it $
<?php // $Id: answer_admin.inc.php 10594 2007-01-05 13:54:24Z elixir_inter $
/*
==============================================================================
Dokeos - elearning and course management software
@ -37,10 +37,15 @@ if(!defined('ALLOWED_TO_INCLUDE'))
{
exit();
}
if(!is_object($objQuestion))
{
$objQuestion = Question :: read($_GET['modifyAnswers']);
}
$questionName=$objQuestion->selectTitle();
$answerType=$objQuestion->selectType();
$pictureName=$objQuestion->selectPicture();
$debug = 0; // debug variable to get where we are
$okPicture=empty($pictureName)?false:true;
@ -65,9 +70,7 @@ if($modifyIn)
$objExercise->addToList($questionId);
// construction of the duplicated Question
$objQuestion=new Question();
$objQuestion->read($questionId);
$objQuestion = Question::read($questionId);
// adds the exercise ID into the exercise list of the Question object
$objQuestion->addToList($exerciseId);
@ -609,6 +612,7 @@ if($modifyAnswers)
// construction of the Answer object
$objAnswer=new Answer($questionId);
api_session_register('objAnswer');
if($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER)
@ -811,6 +815,7 @@ if($modifyAnswers)
if(!$nbrAnswers)
{
$nbrAnswers=$objAnswer->selectNbrAnswers();
$reponse=Array();

@ -1,4 +1,4 @@
<?php // $Id: exercice_submit.php 10547 2006-12-22 15:03:14Z elixir_inter $
<?php // $Id: exercice_submit.php 10594 2007-01-05 13:54:24Z elixir_inter $
/*
==============================================================================
Dokeos - elearning and course management software
@ -442,8 +442,7 @@ $i=0;
foreach($questionList as $questionId)
{
$i++;
$objQuestionTmp=new Question();
$objQuestionTmp->read($questionId);
$objQuestionTmp = Question :: read($questionId);
// for sequential exercises
if($exerciseType == 2)
@ -519,10 +518,7 @@ foreach($questionList as $questionId)
if(isset($exerciseResult[$questionId]))
{
// construction of the Question object
$objQuestionTmp=new Question();
// reads question informations
$objQuestionTmp->read($questionId);
$objQuestionTmp = Question::read($questionId);
$questionName=$objQuestionTmp->selectTitle();

@ -1,4 +1,4 @@
<?php // $Id: exercise.lib.php 10556 2006-12-26 15:35:00Z elixir_inter $
<?php // $Id: exercise.lib.php 10594 2007-01-05 13:54:24Z elixir_inter $
/*
==============================================================================
Dokeos - elearning and course management software
@ -39,11 +39,8 @@
require("../inc/lib/fckeditor/fckeditor.php") ;
function showQuestion($questionId, $onlyAnswers=false, $origin=false)
{
// construction of the Question object
$objQuestionTmp=new Question();
// reads question informations
if(!$objQuestionTmp->read($questionId))
if(!$objQuestionTmp = Question::read($questionId))
{
// question not found
return false;

@ -1,4 +1,4 @@
<?php // $Id: exercise_result.php 10547 2006-12-22 15:03:14Z elixir_inter $
<?php // $Id: exercise_result.php 10594 2007-01-05 13:54:24Z elixir_inter $
/*
==============================================================================
Dokeos - elearning and course management software
@ -280,9 +280,8 @@ $exerciseTitle=api_parse_tex($exerciseTitle);
// gets the student choice for this question
$choice=$exerciseResult[$questionId];
// creates a temporary Question object
$objQuestionTmp=new Question();
$objQuestionTmp->read($questionId);
$objQuestionTmp = Question :: read($questionId);
$questionName=$objQuestionTmp->selectTitle();
$questionWeighting=$objQuestionTmp->selectWeighting();

@ -285,8 +285,7 @@ $result =api_sql_query($query, __FILE__, __LINE__);
$k++;
$choice=$exerciseResult[$questionId];
// creates a temporary Question object
$objQuestionTmp=new Question();
$objQuestionTmp->read($questionId);
$objQuestionTmp = Question::read($questionId);
$questionName=$objQuestionTmp->selectTitle();
$questionWeighting=$objQuestionTmp->selectWeighting();
$answerType=$objQuestionTmp->selectType();

@ -24,8 +24,7 @@ Display::display_header($nameTools,"Exercise");
</h4>
<?php
$id = $_REQUEST['question'];
$objQuestionTmp=new Question();
$objQuestionTmp->read($id);
$objQuestionTmp = Question::read($id);
echo "<tr><td><b>".get_lang('Question')." : </b>";
echo $objQuestionTmp->selectTitle();
echo "</td></tr>";

@ -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;
?>

@ -38,8 +38,7 @@
// set vars
$questionId = $_GET['modifyAnswers'];
$objQuestion = new Question();
$objQuestion->read($questionId);
$objQuestion = Question::read($questionId);
$TBL_ANSWERS = $_course['dbNameGlu'].'quiz_answer';

@ -38,8 +38,7 @@
// set vars
$questionId = $_GET['modifyAnswers'];
$objQuestion = new Question();
$objQuestion->read($questionId);
$objQuestion = Question::read($questionId);
$TBL_ANSWERS = $_course['dbNameGlu'].'quiz_answer';

@ -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('&nbsp;',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('&nbsp;',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('&nbsp;',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('&nbsp;',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('&nbsp;',2).'$usedInSeveralExercises is untrue'."<br />\n";}
if($debug>0){echo str_repeat('&nbsp;',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">&nbsp;<?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('&nbsp;',0).'$modifyAnswers was set - end'."<br />\n";}
}
?>

@ -42,8 +42,7 @@
$userId = $_user['user_id'];
$questionId = $_GET['modifyAnswers'];
$objQuestion = new Question();
$objQuestion->read($questionId);
$objQuestion = Question :: read($questionId);
$TBL_ANSWERS = $_course['dbNameGlu'].'quiz_answer';

@ -100,8 +100,7 @@ if(!$is_courseTutor)
api_not_allowed();
}
$obj_question=new Question();
$obj_question->read($my_qst);
$obj_question = Question :: read($my_qst);
$nameTools=get_lang('Exercice');

@ -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>
</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>
</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>
</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,4 +1,4 @@
<?php // $Id: question.class.php 10234 2006-11-28 13:43:34Z develop-it $
<?php // $Id: question.class.php 10594 2007-01-05 13:54:24Z elixir_inter $
/*
==============================================================================
Dokeos - elearning and course management software
@ -32,6 +32,17 @@
if(!class_exists('Question')):
// answer types
define(UNIQUE_ANSWER, 1);
define(MULTIPLE_ANSWER, 2);
define(FILL_IN_BLANKS, 3);
define(MATCHING, 4);
define(FREE_ANSWER, 5);
define(HOT_SPOT, 6);
define(HOT_SPOT_ORDER, 7);
/**
CLASS QUESTION
*
@ -41,7 +52,7 @@ if(!class_exists('Question')):
* @author Patrick Cool, LaTeX support
* @package dokeos.exercise
*/
class Question
abstract class Question
{
var $id;
var $question;
@ -52,6 +63,16 @@ class Question
var $picture;
var $exerciseList; // array with the list of exercises which this question is in
// list
static $questionTypes = array(
UNIQUE_ANSWER => array('unique_answer.class.php' , 'UniqueAnswer'),
MULTIPLE_ANSWER => array('multiple_answer.class.php' , 'MultipleAnswer'),
FILL_IN_BLANKS => array('fill_blanks.class.php' , 'FillBlanks'),
MATCHING => array('matching.class.php' , 'Matching'),
FREE_ANSWER => array('freeanswer.class.php' , 'FreeAnswer'),
HOT_SPOT => array('hotspot.class.php' , 'HotSpot')
);
/**
* constructor of the class
@ -78,7 +99,7 @@ class Question
* @param - integer $id - question ID
* @return - boolean - true if question exists, otherwise false
*/
function read($id)
static function read($id)
{
global $_course;
@ -92,24 +113,25 @@ class Question
// if the question has been found
if($object=mysql_fetch_object($result))
{
$this->id=$id;
$this->question=$object->question;
$this->description=$object->description;
$this->weighting=$object->ponderation;
$this->position=$object->position;
$this->type=$object->type;
$this->picture=$object->picture;
$sql="SELECT exercice_id FROM `$TBL_EXERCICE_QUESTION` WHERE question_id='$id'";
$objQuestion = Question::getInstance($object->type);
$objQuestion->id=$id;
$objQuestion->question=$object->question;
$objQuestion->description=$object->description;
$objQuestion->weighting=$object->ponderation;
$objQuestion->position=$object->position;
$objQuestion->type=$object->type;
$objQuestion->picture=$object->picture;
$sql="SELECT exercice_id FROM `$TBL_EXERCICE_QUESTION` WHERE question_id='".intval($id)."'";
$result=api_sql_query($sql,__FILE__,__LINE__);
// fills the array with the exercises which this question is in
while($object=mysql_fetch_object($result))
{
$this->exerciseList[]=$object->exercice_id;
$objQuestion->exerciseList[]=$object->exercice_id;
}
return true;
return $objQuestion;
}
// question not found
@ -306,7 +328,6 @@ class Question
$Extension=$PictureName[sizeof($PictureName)-1];
$this->picture='quiz-'.$this->id.'.'.$Extension;
return move_uploaded_file($Picture,$picturePath.'/'.$this->picture)?true:false;
}
@ -574,6 +595,7 @@ class Question
$this->exerciseList[]=$exerciseId;
$sql="INSERT INTO `$TBL_EXERCICE_QUESTION`(question_id,exercice_id) VALUES('$id','$exerciseId')";
api_sql_query($sql,__FILE__,__LINE__);
}
}
@ -675,7 +697,101 @@ class Question
return $id;
}
/**
* Returns an instance of the class corresponding to the type
* @param integer $type the type of the question
* @return an instance of a Question subclass (or of Questionc class by default)
*/
static function getInstance ($type) {
list($file_name,$class_name) = self::$questionTypes[$type];
include_once ($file_name);
if(class_exists($class_name))
{
return new $class_name();
}
else
{
echo 'Can\'t instanciate class '.$class_name.' of type '.$type;
return null;
}
}
/**
* Creates the form to create / edit a question
* A subclass can redifine this function to add fields...
* @param FormValidator $form the formvalidator instance (by reference)
*/
function createForm (&$form) {
// question name
$form->addElement('text','questionName',get_lang('Question'),'size="60"');
$form->addRule('questionName', get_lang('GiveQuestion'), 'required');
// question type
$answerType= intval($_REQUEST['answerType']);
$form->addElement('hidden','answerType',$_REQUEST['answerType']);
// html editor
global $fck_attribute;
$fck_attribute = array();
$fck_attribute['Width'] = '100%';
$fck_attribute['Height'] = '150';
$fck_attribute['ToolbarSet'] = 'Small';
$fck_attribute['Config']['IMUploadPath'] = 'upload/test/';
$fck_attribute['Config']['FlashUploadPath'] = 'upload/test/';
if(!api_is_allowed_to_edit()) $fck_attribute['Config']['UserStatus'] = 'student';
$form->add_html_editor('questionDescription', get_lang('QuestionDescription'), false);
// hidden values
$form->addElement('hidden','myid',$_REQUEST['myid']);
// default values
$defaults = array();
$defaults['questionName'] = $this -> question;
$defaults['questionDescription'] = $this -> description;
$form -> setDefaults($defaults);
}
/**
* function which process the creation of answers
* @param FormValidator $form the formvalidator instance
* @param Exercise $objExercise the objExercise number to display
*/
function processCreation ($form, $objExercise) {
$this -> updateTitle($form->getSubmitValue('questionName'));
$this -> updateDescription($form->getSubmitValue('questionDescription'));
$this -> save($objExercise -> id);
// modify the exercise
$objExercise->addToList($this -> id);
$objExercise->save();
}
/**
* abstract function which creates the form to create / edit the answers of the question
* @param the formvalidator instance
*/
abstract function createAnswersForm ($form);
/**
* abstract function which process the creation of answers
* @param the formvalidator instance
*/
abstract function processAnswersCreation ($form);
}
endif;
?>

@ -1,4 +1,4 @@
<?php
<? // $Id: question_admin.inc.php 10594 2007-01-05 13:54:24Z elixir_inter $
/*
==============================================================================
Dokeos - elearning and course management software
@ -6,7 +6,6 @@
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".
@ -18,14 +17,14 @@
See the GNU General Public License for more details.
Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
Mail: info@dokeos.com
==============================================================================
*/
/**
==============================================================================
* QUESTION ADMINISTRATION
*
* This script allows to manage a question and its answers
* STATEMENT ADMINISTRATION
* This script allows to manage the statements of questions.
* It is included from the script admin.php
*
* @author Olivier Brouckaert
@ -33,253 +32,111 @@
==============================================================================
*/
/*
==============================================================================
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();
}
$pictureName=$objQuestion->selectPicture();
if ( empty ($answerType) ) {
$answerType = $objQuestion->selectType();
}
//added
if($_REQUEST['exerciseId'])
$myid=1;
else
$myid=0;
// if the question we are modifying is used in several exercises
if($usedInSeveralExercises)
/*********************
* INIT QUESTION
*********************/
if(isset($_GET['editQuestion']))
{
?>
<h3>
<?php echo $questionName; ?>
</h3>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>?modifyQuestion=<?php echo $modifyQuestion; ?>&modifyAnswers=<?php echo $modifycAnswers; ?>">
<?php
// submit question
if($submitQuestion)
{
?>
<input type="hidden" name="questionName" value="<?php echo htmlentities($questionName); ?>">
<input type="hidden" name="questionDescription" value="<?php echo htmlentities($questionDescription); ?>">
<input type="hidden" name="imageUpload_size" value="<?php echo $imageUpload_size; ?>">
<input type="hidden" name="deletePicture" value="<?php echo $deletePicture; ?>">
<input type="hidden" name="pictureName" value="<?php echo htmlentities($pictureName); ?>">
<?php
}
// submit answers
else
{
if($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER)
{
?>
<input type="hidden" name="correct" value="<?php echo htmlentities(serialize($correct)); ?>">
<input type="hidden" name="reponse" value="<?php echo htmlentities(serialize($reponse)); ?>">
<input type="hidden" name="comment" value="<?php echo htmlentities(serialize($comment)); ?>">
<input type="hidden" name="weighting" value="<?php echo htmlentities(serialize($weighting)); ?>">
<input type="hidden" name="nbrAnswers" value="<?php echo $nbrAnswers; ?>">
<?php
}
elseif($answerType == MATCHING)
{
?>
<input type="hidden" name="option" value="<?php echo htmlentities(serialize($option)); ?>">
<input type="hidden" name="match" value="<?php echo htmlentities(serialize($match)); ?>">
<input type="hidden" name="sel" value="<?php echo htmlentities(serialize($sel)); ?>">
<input type="hidden" name="weighting" value="<?php echo htmlentities(serialize($weighting)); ?>">
<input type="hidden" name="nbrOptions" value="<?php echo $nbrOptions; ?>">
<input type="hidden" name="nbrMatches" value="<?php echo $nbrMatches; ?>">
<?php
}
elseif ( $answerType == HOT_SPOT)
{
?>
<input type="hidden" name="nbrAnswers" value="<?php echo $nbrAnswers; ?>">
<input type="hidden" name="reponse" value="<?php echo htmlentities(serialize($reponse)); ?>">
<input type="hidden" name="comment" value="<?php echo htmlentities(serialize($comment)); ?>">
<input type="hidden" name="weighting" value="<?php echo htmlentities(serialize($weighting)); ?>">
<input type="hidden" name="hotspot_coordinates" value="<?php echo htmlentities(serialize($hotspot_coordinates)); ?>">
<input type="hidden" name="hotspot_type" value="<?php echo htmlentities(serialize($hotspot_type)); ?>">
<?php
}
elseif ( $answerType == FREE_ANSWER)
{
?>
<input type="hidden" name="reponse" value="<?php echo htmlentities(serialize($reponse)); ?>">
<input type="hidden" name="comment" value="<?php echo htmlentities(serialize($comment)); ?>">
<input type="hidden" name="weighting" value="<?php echo htmlentities(serialize($weighting)); ?>">
<input type="hidden" name="setWeighting" value="1">
<?php
}
else
{
?>
<input type="hidden" name="reponse" value="<?php echo htmlentities(serialize($reponse)); ?>">
<input type="hidden" name="comment" value="<?php echo htmlentities(serialize($comment)); ?>">
<input type="hidden" name="blanks" value="<?php echo htmlentities(serialize($blanks)); ?>">
<input type="hidden" name="weighting" value="<?php echo htmlentities(serialize($weighting)); ?>">
<input type="hidden" name="setWeighting" value="1">
<?php
}
} // end submit answers
?>
<input type="hidden" name="answerType" value="<?php echo $answerType; ?>">
<?php
$msgBox= " ".get_lang('UsedInSeveralExercises')." :<br />
<input class=\"checkbox\" type=\"radio\" name=\"modifyIn\" value=\"allExercises\" checked=\"checked\"> ".get_lang('ModifyInAllExercises')."<br />
<input class=\"checkbox\" type=\"radio\" name=\"modifyIn\" value=\"thisExercise\"> ".get_lang('ModifyInThisExercise')."<br />
<input type=\"submit\" name=\"".($submitQuestion?'submitQuestion':'submitAnswers')."\" value=\"".get_lang('Ok')."\">
";
Display::display_normal_message($msgBox); //main API
?>
</form>
<?php
$objQuestion = Question::read ($_GET['editQuestion']);
$action = $_SERVER['PHP_SELF']."?modifyQuestion=".$modifyQuestion."&editQuestion=".$objQuestion->id;
}
else
{
// selects question informations
$questionName=$objQuestion->selectTitle();
$questionDescription=$objQuestion->selectDescription();
// is picture set ?
$okPicture=empty($pictureName)?false:true;
?>
<h3>
<?php echo $questionName; ?>
<?php
// doesn't show the edit link if we come from the question pool to pick a question for an exercise
if(!$fromExercise)
{
//edited
?>
<a href="<?php echo $_SERVER['PHP_SELF']; ?>?myid=<?php echo $myid; ?>&modifyQuestion=<?php echo $questionId; ?>"><img src="../img/edit.gif" border="0" align="absmiddle" alt="<?php echo get_lang('Modify'); ?>"></a>
<?php
}
?></h3>
<?php
// show the picture of the question
if($okPicture && $questionType != HOT_SPOT)
{
?>
<center><img src="../document/download.php?doc_url=%2Fimages%2F<?php echo $pictureName; ?>" border="0"></center>
<?php
}
?>
<blockquote>
<?php echo $questionDescription; ?>
</blockquote>
<?php
// doesn't show the edit link if we come from the question pool to pick a question for an exercise
/*if(!$fromExercise)
{
?>
<a href="<?php echo $_SERVER['PHP_SELF']; ?>?modifyQuestion=<?php echo $questionId; ?>"><img src="../img/edit.gif" border="0" align="absmiddle" alt="<?php echo get_lang('Modify'); ?>"></a>
<?php
}*/
?>
<hr size="1" noshade="noshade">
<?php
// we are in an exercise
if($exerciseId)
{
?>
<!--<a href="<?php echo $_SERVER['PHP_SELF']; ?>">&lt;&lt; <?php echo get_lang('GoBackToQuestionList'); ?></a>-->
<?php
}
// we are not in an exercise, so we come from the question pool
else
{
?>
<a href="question_pool.php?fromExercise=<?php echo $fromExercise; ?>">&lt;&lt; <?php echo get_lang('GoBackToQuestionPool'); ?></a>
<?php
}
if($answerType != FREE_ANSWER){
?>
<b><?php echo get_lang('QuestionAnswers'); ?></b>
<a href="<?php echo $_SERVER['PHP_SELF']; ?>?myid=<?php echo $myid; ?>&modifyAnswers=<?php echo $questionId; ?>"><img src="../img/edit.gif" border="0" align="absmiddle" alt="<?php echo get_lang('Modify'); ?>"></a>
<table border="0" align="center" cellpadding="2" cellspacing="2" width="100%">
<form>
<?php
// shows answers of the question. 'true' means that we don't show the question, only answers
$hide_question = true;
#if ( $answerType == FREE_ANSWER) { $hide_question = false; echo "voila"; } //show the question if free answer, because there is no set answer
if(!showQuestion($questionId,$hide_question))
{
?>
$objQuestion = Question :: getInstance($_REQUEST['answerType']);
$action = $_SERVER['PHP_SELF']."?modifyQuestion=".$modifyQuestion."&newQuestion=".$newQuestion;
}
<tr>
<td><?php echo get_lang('NoAnswer'); ?></td>
</tr>
if(is_object($objQuestion))
{
<?php
/*********************
* FORM STYLES
*********************/
// if you have a better way to improve the display, please inform me e.marguin@elixir-interactive.com
$styles = '
<style>
div.row div.label{
width: 10%;
}
?>
</form>
</table>
<br>
<?php
div.row div.formw{
width: 85%;
}
// doesn't show the edit link if we come from the question pool to pick a question for an exercise
if(!$fromExercise)
{
?>
<!--<a href="<?php //echo $_SERVER['PHP_SELF']; ?>?modifyAnswers=<?php //echo $questionId; ?>"><img src="../img/edit.gif" border="0" align="absmiddle" alt="<?php //echo get_lang('Modify'); ?>"></a>-->
<?php
[dir=ltr] div.row div.label,
[dir=rtl] div.row div.formw {
float: left;
text-align: left;
}
if ($exerciseId)
{
?><a href="<?php echo $_SERVER['PHP_SELF']; ?>">&lt;&lt; <?php echo get_lang('GoBackToQuestionList'); ?></a>
</style>
';
echo $styles;
/*********************
* INIT FORM
*********************/
$form = new FormValidator('question_admin_form','post',$action);
<?php
/*********************
* FORM CREATION
*********************/
$objQuestion -> createForm ($form);
$objQuestion -> createAnswersForm ($form);
$form->addElement('submit','submitQuestion',get_lang('Ok'));
/**********************
* FORM VALIDATION
**********************/
if(isset($_POST['submitQuestion']) && $form->validate())
{
// question
$objQuestion -> processCreation($form,$objExercise);
// answers
$objQuestion -> processAnswersCreation($form,$nb_answers);
}
else
{
/******************
* FORM DISPLAY
******************/
echo '<h3>'.$questionName.'</h3>';
if(!empty($pictureName)){
echo '<img src="../document/download.php?doc_url=%2Fimages%2F'.$pictureName.'" border="0">';
}
if(!empty($msgErr))
{
Display::display_normal_message($msgErr); //main API
}
// display the form
$form->display();
}
}
?>

@ -1,4 +1,4 @@
<?php // $Id: question_list_admin.inc.php 10109 2006-11-22 15:20:01Z gmludo $
<?php // $Id: question_list_admin.inc.php 10594 2007-01-05 13:54:24Z elixir_inter $
/*
==============================================================================
Dokeos - elearning and course management software
@ -56,11 +56,9 @@ if($moveDown)
// deletes a question from the exercise (not from the data base)
if($deleteQuestion)
{
// construction of the Question object
$objQuestionTmp=new Question();
// if the question exists
if($objQuestionTmp->read($deleteQuestion))
if($objQuestionTmp = Question::read($deleteQuestion))
{
$objQuestionTmp->delete($exerciseId);
@ -104,9 +102,8 @@ if($nbrQuestions)
$i=1;
foreach($questionList as $id)
{
$objQuestionTmp=new Question();
$objQuestionTmp->read($id);
$objQuestionTmp = Question :: read($id);
//showQuestion($id);
?>

@ -1,4 +1,4 @@
<?php // $Id: question_pool.php 10204 2006-11-26 20:46:53Z pcool $
<?php // $Id: question_pool.php 10594 2007-01-05 13:54:24Z elixir_inter $
/*
==============================================================================
Dokeos - elearning and course management software
@ -77,10 +77,8 @@ if($is_allowedToEdit)
if($delete)
{
// construction of the Question object
$objQuestionTmp=new Question();
// if the question exists
if($objQuestionTmp->read($delete))
if($objQuestionTmp = Question::read($delete))
{
// deletes the question from all exercises
$objQuestionTmp->delete();
@ -92,11 +90,8 @@ if($is_allowedToEdit)
// gets an existing question and copies it into a new exercise
elseif($recup && $fromExercise)
{
// construction of the Question object
$objQuestionTmp=new Question();
// if the question exists
if($objQuestionTmp->read($recup))
if($objQuestionTmp = Question :: read($recup))
{
// adds the exercise ID represented by $fromExercise into the list of exercises for the current question
$objQuestionTmp->addToList($fromExercise);

@ -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('&nbsp;',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('&nbsp;',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('&nbsp;',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('&nbsp;',2).'$submitQuestion is true - end'."<br />\n";}
}
else
{
if($debug>0){echo str_repeat('&nbsp;',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('&nbsp;',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('&nbsp;',2).'$submitQuestion was unset - end'."<br />\n";}
}
if(($newQuestion || $modifyQuestion) && !$usedInSeveralExercises)
{
if($debug>0){echo str_repeat('&nbsp;',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, '&nbsp;');
//$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>&nbsp;</td>
<td>
<input type="hidden" name="myid" value="<?php echo $_REQUEST['myid'];?>">
<input type="submit" name="submitQuestion" value="<?php echo get_lang('Ok'); ?>">
<!-- &nbsp;&nbsp;<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>
</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…
Cancel
Save