type = FILL_IN_BLANKS;
}
/**
* function which redifines Question::createAnswersForm
* @param the formvalidator instance
*/
function createAnswersForm ($form) {
$defaults = array();
if(!empty($this->id))
{
$objAnswer = new answer($this->id);
$a_answer = explode('::', $objAnswer->selectAnswer(1));
$defaults['answer'] = $a_answer[0];
$a_weightings = explode(',',$a_answer[1]);
}
else
{
$defaults['answer'] = get_lang('DefaultTextInBlanks');
}
// javascript
echo '
';
// answer
$form -> addElement ('html', '
'.get_lang('TypeTextBelow').', '.get_lang('And').' '.get_lang('UseTagForBlank').'
');
$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','/\[.*\]/');
$form -> addElement('html','');
$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();
}
}
endif;
?>