protected function definition_inner($mform)
 {
     $this->add_per_answer_fields($mform, get_string('answerno', 'qtype_numerical', '{no}'), question_bank::fraction_options());
     $this->add_unit_options($mform);
     $this->add_unit_fields($mform);
     $this->add_interactive_settings();
 }
 protected function definition_inner($mform)
 {
     global $PAGE, $CFG;
     $PAGE->requires->css('/question/type/easyoselectjs/easyoselectjs_styles.css');
     $marvinjsconfig = get_config('qtype_easyoselectjs_options');
     $marvinjspath = $marvinjsconfig->path;
     $protocol = (empty($_SERVER['HTTPS']) or $_SERVER['HTTPS'] == 'off') ? 'http://' : 'https://';
     $PAGE->requires->js(new moodle_url($protocol . $_SERVER['HTTP_HOST'] . $marvinjspath . '/js/promise-0.1.1.min.js'));
     $PAGE->requires->js(new moodle_url($protocol . $_SERVER['HTTP_HOST'] . $marvinjspath . '/js/marvinjslauncher.js'));
     $mform->addElement('static', 'answersinstruct', get_string('correctanswers', 'qtype_easyoselectjs'), get_string('filloutoneanswer', 'qtype_easyoselectjs'));
     $mform->closeHeaderBefore('answersinstruct');
     $mform->setType('structure', PARAM_RAW);
     $mform->addElement('hidden', 'structure', "", array('id' => 'id_structure'));
     $mform->addElement('html', html_writer::start_tag('div', array('id' => 'appletdiv', 'class' => 'easyomechjs resizable')));
     $mform->addElement('html', html_writer::start_tag('div', array('style' => 'float: left;font-style: italic ;')));
     $mform->addElement('html', html_writer::start_tag('small'));
     $easyoselectjshomeurl = 'http://www.chemaxon.com';
     $mform->addElement('html', html_writer::link($easyoselectjshomeurl, get_string('easyoselectjseditor', 'qtype_easyoselectjs')));
     $mform->addElement('html', html_writer::empty_tag('br'));
     $mform->addElement('html', html_writer::tag('span', get_string('author', 'qtype_easyoselectjs'), array('class' => 'easyoselectjsauthor')));
     $mform->addElement('html', html_writer::end_tag('small'));
     $mform->addElement('html', html_writer::end_tag('div'));
     $mform->addElement('html', html_writer::end_tag('div'));
     $marvinconfig = get_config('qtype_easyoselectjs_options');
     $marvinpath = $marvinconfig->path;
     $PAGE->requires->js_init_call('M.qtype_easyoselectjs.insert_applet', array($CFG->wwwroot, $marvinpath));
     $this->add_per_answer_fields($mform, get_string('answerno', 'qtype_easyoselectjs', '{no}'), question_bank::fraction_options());
     $this->add_interactive_settings();
     $PAGE->requires->js_init_call('M.qtype_easyoselectjs.init_getanswerstring', array($CFG->version));
     $PAGE->requires->js_init_call('M.qtype_easyoselectjs.init_viewanswerstring', array($CFG->version));
 }
 protected function definition_inner($mform)
 {
     global $PAGE, $CFG;
     $PAGE->requires->js('/question/type/jme/jme_script.js');
     $PAGE->requires->css('/question/type/jme/styles.css');
     $mform->addElement('hidden', 'usecase', 1);
     $mform->setType('usecase', PARAM_INT);
     $optionscript = 'onClick = "setJSMEoptions()"';
     $label = get_string('jmeoptions', 'qtype_jme');
     $editoroptions[] = $mform->createElement('text', 'jmeoptions', '', array('size' => 50));
     $editoroptions[] = $mform->createElement('button', 'setoptions', get_string('setoptions', 'qtype_jme'), $optionscript);
     $mform->addElement('group', 'editoroptions', $label, $editoroptions, null, false);
     $mform->setDefault('jmeoptions', $CFG->qtype_jme_options);
     $mform->setType('jmeoptions', PARAM_RAW);
     $mform->addHelpButton('editoroptions', 'jmeoptions', 'qtype_jme');
     $mform->addElement('text', 'width', get_string('width', 'qtype_jme'), array('size' => 6));
     $mform->setDefault('width', QTYPE_JME_APPLET_WIDTH);
     $mform->setType('width', PARAM_INT);
     $mform->addElement('text', 'height', get_string('height', 'qtype_jme'), array('size' => 6));
     $mform->setDefault('height', QTYPE_JME_APPLET_HEIGHT);
     $mform->setType('height', PARAM_INT);
     $mform->addElement('static', 'answersinstruct', get_string('correctanswers', 'qtype_jme'), get_string('filloutoneanswer', 'qtype_jme'));
     $mform->addElement('html', html_writer::tag('div', get_string('enablejavascript', 'qtype_jme'), array('class' => 'jme_applet', 'code' => 'JME.class', 'id' => 'jme1', 'name' => 'JME1', 'archive' => 'JME.jar', 'width' => '360', 'height' => '315', 'style' => 'margin: 1.5em auto')));
     $mform->closeHeaderBefore('answersinstruct');
     $this->add_per_answer_fields($mform, get_string('answerno', 'qtype_jme', '{no}'), question_bank::fraction_options());
     $this->add_interactive_settings();
     // Include JSME loader script as an html tag.
     $jsmescript = $CFG->wwwroot . '/question/type/jme/jsme/jsme.nocache.js';
     $mform->addElement('html', html_writer::tag('script', '', array('src' => $jsmescript)));
 }
 protected function definition_inner($mform)
 {
     $menu = array(get_string('caseno', 'qtype_shortanswer'), get_string('caseyes', 'qtype_shortanswer'));
     $mform->addElement('select', 'usecase', get_string('casesensitive', 'qtype_shortanswer'), $menu);
     $mform->addElement('static', 'answersinstruct', get_string('correctanswers', 'qtype_shortanswer'), get_string('filloutoneanswer', 'qtype_shortanswer'));
     $mform->closeHeaderBefore('answersinstruct');
     $this->add_per_answer_fields($mform, get_string('answerno', 'qtype_shortanswer', '{no}'), question_bank::fraction_options());
     $this->add_interactive_settings();
 }
 public function test_fraction_options()
 {
     $fractions = question_bank::fraction_options();
     $this->assertSame(get_string('none'), reset($fractions));
     $this->assertSame('0.0', key($fractions));
     $this->assertSame('5%', end($fractions));
     $this->assertSame('0.05', key($fractions));
     array_shift($fractions);
     array_pop($fractions);
     array_pop($fractions);
     $this->assertSame('100%', reset($fractions));
     $this->assertSame('1.0', key($fractions));
     $this->assertSame('11.11111%', end($fractions));
     $this->assertSame('0.1111111', key($fractions));
 }
 /**
  * Add question-type specific form fields.
  *
  * @param MoodleQuickForm $mform the form being built.
  */
 protected function definition_inner($mform)
 {
     $strquestionlabel = $this->qtypeobj->comment_header($this->nonemptyanswer);
     $label = get_string("sharedwildcards", "qtype_calculated");
     $mform->addElement('hidden', 'synchronize', 0);
     $mform->addElement('hidden', 'initialcategory', 1);
     $mform->setType('synchronize', PARAM_BOOL);
     $mform->setType('initialcategory', PARAM_INT);
     $mform->addElement('hidden', 'reload', 1);
     $mform->setType('reload', PARAM_INT);
     $addfieldsname = 'updatequestion value';
     $addstring = get_string("updatecategory", "qtype_calculated");
     $mform->registerNoSubmitButton($addfieldsname);
     $this->add_per_answer_fields($mform, get_string('answerhdr', 'qtype_calculated', '{no}'), question_bank::fraction_options(), 1, 1);
     $this->add_unit_options($mform, $this);
     $this->add_unit_fields($mform, $this);
     $this->add_interactive_settings();
     $label = "<div class='mdl-align'></div><div class='mdl-align'>" . get_string('wildcardrole', 'qtype_calculatedsimple') . "</div>";
     $mform->addElement('html', "<div class='mdl-align'>&nbsp;</div>");
     // Explaining the role of datasets so other strings can be shortened.
     $mform->addElement('html', $label);
     $mform->addElement('submit', 'analyzequestion', get_string('findwildcards', 'qtype_calculatedsimple'));
     $mform->registerNoSubmitButton('analyzequestion');
     $mform->closeHeaderBefore('analyzequestion');
     $this->wizarddisplay = optional_param('analyzequestion', false, PARAM_BOOL);
     if ($this->maxnumber != -1) {
         $this->noofitems = $this->maxnumber;
     } else {
         $this->noofitems = 0;
     }
     if (!empty($this->datasetdefs)) {
         // So there are some datadefs.
         // We put them on the page.
         $key = 0;
         $mform->addElement('header', 'additemhdr', get_string('wildcardparam', 'qtype_calculatedsimple'));
         $idx = 1;
         if (!empty($this->datasetdefs)) {
             // Unnecessary test.
             $j = $this->noofitems * count($this->datasetdefs) + 1;
             //
             foreach ($this->datasetdefs as $defkey => $datasetdef) {
                 $mform->addElement('static', "na[{$j}]", get_string('param', 'qtype_calculated', $datasetdef->name));
                 $this->qtypeobj->custom_generator_tools_part($mform, $idx, $j);
                 $mform->addElement('hidden', "datasetdef[{$idx}]");
                 $mform->setType("datasetdef[{$idx}]", PARAM_RAW);
                 $mform->addElement('hidden', "defoptions[{$idx}]");
                 $mform->setType("defoptions[{$idx}]", PARAM_RAW);
                 $idx++;
                 $mform->addElement('static', "divider[{$j}]", '', '<hr />');
                 $j++;
             }
         }
         // This should be done before the elements are created and stored as $this->formdata.
         // Fill out all data sets and also the fields for the next item to add.
         /*Here we do already the values error analysis so that
          * we could force all wild cards values display if there is an error in values.
          * as using a , in a number */
         $this->numbererrors = array();
         if (!empty($this->datasetdefs)) {
             $j = $this->noofitems * count($this->datasetdefs);
             for ($itemnumber = $this->noofitems; $itemnumber >= 1; $itemnumber--) {
                 $data = array();
                 $numbererrors = array();
                 $comment = new stdClass();
                 $comment->stranswers = array();
                 $comment->outsidelimit = false;
                 $comment->answers = array();
                 foreach ($this->datasetdefs as $defid => $datasetdef) {
                     if (isset($datasetdef->items[$itemnumber])) {
                         $this->formdata["definition[{$j}]"] = $defid;
                         $this->formdata["itemid[{$j}]"] = $datasetdef->items[$itemnumber]->id;
                         $data[$datasetdef->name] = $datasetdef->items[$itemnumber]->value;
                         $this->formdata["number[{$j}]"] = $number = $datasetdef->items[$itemnumber]->value;
                         if (!is_numeric($number)) {
                             $a = new stdClass();
                             $a->name = '{' . $datasetdef->name . '}';
                             $a->value = $datasetdef->items[$itemnumber]->value;
                             if (stristr($number, ',')) {
                                 $this->numbererrors["number[{$j}]"] = get_string('nocommaallowed', 'qtype_calculated');
                                 $numbererrors .= $this->numbererrors['number[' . $j . ']'] . "<br />";
                             } else {
                                 $this->numbererrors["number[{$j}]"] = get_string('notvalidnumber', 'qtype_calculated', $a);
                                 $numbererrors .= $this->numbererrors['number[' . $j . ']'] . "<br />";
                             }
                         } else {
                             if (stristr($number, 'x')) {
                                 // Hexa will pass the test.
                                 $a = new stdClass();
                                 $a->name = '{' . $datasetdef->name . '}';
                                 $a->value = $datasetdef->items[$itemnumber]->value;
                                 $this->numbererrors['number[' . $j . ']'] = get_string('hexanotallowed', 'qtype_calculated', $a);
                                 $numbererrors .= $this->numbererrors['number[' . $j . ']'] . "<br />";
                             } else {
                                 if (is_nan($number)) {
                                     $a = new stdClass();
                                     $a->name = '{' . $datasetdef->name . '}';
                                     $a->value = $datasetdef->items[$itemnumber]->value;
                                     $this->numbererrors["number[{$j}]"] = get_string('notvalidnumber', 'qtype_calculated', $a);
                                     $numbererrors .= $this->numbererrors['number[' . $j . ']'] . "<br />";
                                 }
                             }
                         }
                     }
                     $j--;
                 }
                 if ($this->noofitems != 0) {
                     if (empty($numbererrors)) {
                         if (!isset($this->question->id)) {
                             $this->question->id = 0;
                         }
                         $this->question->questiontext = !empty($this->question->questiontext) ? $this->question->questiontext : '';
                         $comment = $this->qtypeobj->comment_on_datasetitems($this->qtypeobj, $this->question->id, $this->question->questiontext, $this->nonemptyanswer, $data, $itemnumber);
                         if ($comment->outsidelimit) {
                             $this->outsidelimit = $comment->outsidelimit;
                         }
                         $totalcomment = '';
                         foreach ($this->nonemptyanswer as $key => $answer) {
                             $totalcomment .= $comment->stranswers[$key] . '<br/>';
                         }
                         $this->formdata['answercomment[' . $itemnumber . ']'] = $totalcomment;
                     }
                 }
             }
             $this->formdata['selectdelete'] = '1';
             $this->formdata['selectadd'] = '1';
             $j = $this->noofitems * count($this->datasetdefs) + 1;
             $data = array();
             // Data for comment_on_datasetitems later.
             $idx = 1;
             foreach ($this->datasetdefs as $defid => $datasetdef) {
                 $this->formdata["datasetdef[{$idx}]"] = $defid;
                 $idx++;
             }
             $this->formdata = $this->qtypeobj->custom_generator_set_data($this->datasetdefs, $this->formdata);
         }
         $addoptions = array();
         $addoptions['1'] = '1';
         for ($i = 10; $i <= 100; $i += 10) {
             $addoptions["{$i}"] = "{$i}";
         }
         $showoptions = array();
         $showoptions['1'] = '1';
         $showoptions['2'] = '2';
         $showoptions['5'] = '5';
         for ($i = 10; $i <= 100; $i += 10) {
             $showoptions["{$i}"] = "{$i}";
         }
         $mform->closeHeaderBefore('additemhdr');
         $addgrp = array();
         $addgrp[] = $mform->createElement('submit', 'addbutton', get_string('generatenewitemsset', 'qtype_calculatedsimple'));
         $addgrp[] = $mform->createElement('select', "selectadd", '', $addoptions);
         $addgrp[] = $mform->createElement('static', "stat", '', get_string('newsetwildcardvalues', 'qtype_calculatedsimple'));
         $mform->addGroup($addgrp, 'addgrp', '', '   ', false);
         $mform->registerNoSubmitButton('addbutton');
         $mform->closeHeaderBefore('addgrp');
         $addgrp1 = array();
         $addgrp1[] = $mform->createElement('submit', 'showbutton', get_string('showitems', 'qtype_calculatedsimple'));
         $addgrp1[] = $mform->createElement('select', "selectshow", '', $showoptions);
         $addgrp1[] = $mform->createElement('static', "stat", '', get_string('setwildcardvalues', 'qtype_calculatedsimple'));
         $mform->addGroup($addgrp1, 'addgrp1', '', '   ', false);
         $mform->registerNoSubmitButton('showbutton');
         $mform->closeHeaderBefore('addgrp1');
         $mform->addElement('static', "divideradd", '', '');
         if ($this->noofitems == 0) {
             $mform->addElement('static', 'warningnoitems', '', '<span class="error">' . get_string('youmustaddatleastonevalue', 'qtype_calculatedsimple') . '</span>');
             $mform->closeHeaderBefore('warningnoitems');
         } else {
             $mform->addElement('header', 'additemhdr1', get_string('wildcardvalues', 'qtype_calculatedsimple'));
             $mform->closeHeaderBefore('additemhdr1');
             if (!empty($this->numbererrors) || $this->outsidelimit) {
                 $mform->addElement('static', "alert", '', '<span class="error">' . get_string('useadvance', 'qtype_calculatedsimple') . '</span>');
             }
             $mform->addElement('submit', 'updatedatasets', get_string('updatewildcardvalues', 'qtype_calculatedsimple'));
             $mform->registerNoSubmitButton('updatedatasets');
             $mform->setAdvanced("updatedatasets", true);
             // ...--------------------------------------------------------------.
             $j = $this->noofitems * count($this->datasetdefs);
             $k = optional_param('selectshow', 1, PARAM_INT);
             for ($i = $this->noofitems; $i >= 1; $i--) {
                 foreach ($this->datasetdefs as $defkey => $datasetdef) {
                     if ($k > 0 || $this->outsidelimit || !empty($this->numbererrors)) {
                         $mform->addElement('text', "number[{$j}]", get_string('wildcard', 'qtype_calculatedsimple', $datasetdef->name));
                         $mform->setAdvanced("number[{$j}]", true);
                         if (!empty($this->numbererrors['number[' . $j . ']'])) {
                             $mform->addElement('static', "numbercomment[{$j}]", '', '<span class="error">' . $this->numbererrors['number[' . $j . ']'] . '</span>');
                             $mform->setAdvanced("numbercomment[{$j}]", true);
                         }
                     } else {
                         $mform->addElement('hidden', "number[{$j}]", get_string('wildcard', 'qtype_calculatedsimple', $datasetdef->name));
                     }
                     $mform->setType("number[{$j}]", PARAM_RAW);
                     // This parameter will be validated in validation().
                     $mform->addElement('hidden', "itemid[{$j}]");
                     $mform->setType("itemid[{$j}]", PARAM_INT);
                     $mform->addElement('hidden', "definition[{$j}]");
                     $mform->setType("definition[{$j}]", PARAM_NOTAGS);
                     $j--;
                 }
                 if (!empty($strquestionlabel) && ($k > 0 || $this->outsidelimit || !empty($this->numbererrors))) {
                     $mform->addElement('static', "answercomment[{$i}]", "<b>" . get_string('setno', 'qtype_calculatedsimple', $i) . "</b>&nbsp;&nbsp;" . $strquestionlabel);
                 }
                 if ($k > 0 || $this->outsidelimit || !empty($this->numbererrors)) {
                     $mform->addElement('static', "divider1[{$j}]", '', '<hr />');
                 }
                 $k--;
             }
         }
     } else {
         $mform->addElement('static', 'warningnowildcards', '', '<span class="error">' . get_string('atleastonewildcard', 'qtype_calculatedsimple') . '</span>');
         $mform->closeHeaderBefore('warningnowildcards');
     }
     // ...----------------------------------------------------------------------.
     // Non standard name for button element needed so not using add_action_buttons.
     // Hidden elements.
     $mform->addElement('hidden', 'id');
     $mform->setType('id', PARAM_INT);
     $mform->addElement('hidden', 'courseid');
     $mform->setType('courseid', PARAM_INT);
     $mform->setDefault('courseid', 0);
     $mform->addElement('hidden', 'cmid');
     $mform->setType('cmid', PARAM_INT);
     $mform->setDefault('cmid', 0);
     if (!empty($this->question->id)) {
         if ($this->question->formoptions->cansaveasnew) {
             $mform->addElement('header', 'additemhdr', get_string('converttocalculated', 'qtype_calculatedsimple'));
             $mform->closeHeaderBefore('additemhdr');
             $mform->addElement('checkbox', 'convert', '', get_string('willconverttocalculated', 'qtype_calculatedsimple'));
             $mform->setDefault('convert', 0);
         }
     }
 }
    /**
     * Add question-type specific form fields.
     *
     * @param MoodleQuickForm $mform the form being built.
     */
    protected function definition_inner($mform) {
        $this->qtypeobj = question_bank::get_qtype($this->qtype());
        $label = get_string('sharedwildcards', 'qtype_calculated');
        $mform->addElement('hidden', 'initialcategory', 1);
        $mform->addElement('hidden', 'reload', 1);
        $mform->setType('initialcategory', PARAM_INT);
        $html2 = $this->qtypeobj->print_dataset_definitions_category($this->question);
        $mform->insertElementBefore(
                $mform->createElement('static', 'listcategory', $label, $html2), 'name');
        if (isset($this->question->id)) {
            $mform->insertElementBefore($mform->createElement('static', 'initialname',
                    get_string('questionstoredname', 'qtype_calculated'),
                    $this->initialname), 'name');
        };
        $addfieldsname = 'updatecategory';
        $addstring = get_string('updatecategory', 'qtype_calculated');
        $mform->registerNoSubmitButton($addfieldsname);

        $mform->insertElementBefore(
                $mform->createElement('submit', $addfieldsname, $addstring), 'listcategory');
        $mform->registerNoSubmitButton('createoptionbutton');

        //editing as regular
        $mform->setType('single', PARAM_INT);

        $mform->addElement('hidden', 'shuffleanswers', '1');
        $mform->setType('shuffleanswers', PARAM_INT);
        $mform->addElement('hidden', 'answernumbering', 'abc');
        $mform->setType('answernumbering', PARAM_SAFEDIR);

        $this->add_per_answer_fields($mform, get_string('answerhdr', 'qtype_calculated', '{no}'),
                question_bank::fraction_options(), 1, 1);

        $repeated = array();

        $this->add_unit_options($mform, $this);
        $this->add_unit_fields($mform, $this);
        $this->add_interactive_settings();

        // Hidden elements
        $mform->addElement('hidden', 'synchronize', '');
        $mform->setType('synchronize', PARAM_INT);
        $mform->addElement('hidden', 'wizard', 'datasetdefinitions');
        $mform->setType('wizard', PARAM_ALPHA);
    }
/**
 * Returns list of 'allowed' grades for grade selection
 * formatted suitably for dropdown box function
 *
 * @deprecated since 2.1. Use {@link question_bank::fraction_options()} or
 * {@link question_bank::fraction_options_full()} instead.
 *
 * @return object ->gradeoptionsfull full array ->gradeoptions +ve only
 */
function get_grade_options()
{
    $grades = new stdClass();
    $grades->gradeoptions = question_bank::fraction_options();
    $grades->gradeoptionsfull = question_bank::fraction_options_full();
    return $grades;
}
 /**
  * Adds the combobox to select penalty for each incorrectly selected area.
  * By default 12.5% (1/8) is selected 
  * 
  * @param MoodleQuickForm $mform
  */
 protected function add_penalty_fields($mform)
 {
     $fldname = 'vd_penalty';
     $mform->addElement('select', $fldname, get_string('penalty_per_wrong_area', 'qtype_vdmarker'), question_bank::fraction_options());
     $mform->setDefault($fldname, 1.0);
 }
 /**
  * Create the form element used to define the weight of the cell
  * 
  * @param MoodleQuickForm   $form
  * @param int               $row
  * @param int               $col
  * 
  * @return object
  */
 public function create_cell_element($form, $row, $col, $multiple)
 {
     $options = question_bank::fraction_options();
     $cell_name = $this->cell_name($row, $col, $multiple);
     return $form->createElement('select', $cell_name, 'label', $options);
 }
 /**
  * Add question-type specific form fields.
  *
  * @param MoodleQuickForm $mform the form being built.
  */
 protected function definition_inner($mform)
 {
     global $CFG, $OUTPUT, $SESSION;
     require_once $CFG->dirroot . '/question/type/regexp/locallib.php';
     $this->showalternate = false;
     if ("" != optional_param('showalternate', '', PARAM_RAW)) {
         $this->showalternate = true;
         $this->questionid = optional_param('id', '', PARAM_NOTAGS);
         $this->usecase = optional_param('usecase', '', PARAM_NOTAGS);
         $this->studentshowalternate = optional_param('studentshowalternate', '', PARAM_NOTAGS);
         $this->fraction = optional_param_array('fraction', '', PARAM_RAW);
         $this->currentanswers = optional_param_array('answer', '', PARAM_NOTAGS);
         //$this->feedback = optional_param('feedback', '', PARAM_NOTAGS);
         // no longer works in moodle 2.2 and later see http://moodle.org/mod/forum/discuss.php?d=197118
         // so use data_submitted() instead
         $feedback = data_submitted()->feedback;
         // we only need to get the feedback text, for validation purposes when showalternate is requested
         foreach ($feedback as $key => $fb) {
             $this->feedback[$key]['text'] = clean_param($fb['text'], PARAM_NOTAGS);
         }
     }
     // JR added advanced settings to hide mostly unwanted hints and tags settings
     if ("" != optional_param('addhint', '', PARAM_RAW)) {
         $this->hints = optional_param('hint', '', PARAM_NOTAGS);
     } elseif (isset($this->question->hints)) {
         $this->hints = $this->question->hints;
     }
     $counthints = 0;
     if (isset($this->hints)) {
         $counthints = count($this->hints);
     }
     $mform->setAdvanced('tags');
     for ($i = 0; $i < $counthints; $i++) {
         $mform->setAdvanced("hint[{$i}]");
     }
     // hint mode :: None / Letter / Word
     $menu = array(get_string('none'), get_string('letter', 'qtype_regexp'), get_string('word', 'qtype_regexp'));
     $mform->addElement('select', 'usehint', get_string('usehint', 'qtype_regexp'), $menu);
     $mform->addHelpButton('usehint', 'usehint', 'qtype_regexp');
     // use case :: yes / no
     $menu = array(get_string('caseno', 'qtype_regexp'), get_string('caseyes', 'qtype_regexp'));
     $mform->addElement('select', 'usecase', get_string('casesensitive', 'qtype_regexp'), $menu);
     // display all correct alternate answers to student on review page :: yes / no
     $menu = array(get_string('no'), get_string('yes'));
     $mform->addElement('select', 'studentshowalternate', get_string('studentshowalternate', 'qtype_regexp'), $menu);
     $mform->addHelpButton('studentshowalternate', 'studentshowalternate', 'qtype_regexp');
     //$mform->closeHeaderBefore('answersinstruct');
     $mform->addElement('static', 'answersinstruct', 'Note.-', get_string('filloutoneanswer', 'qtype_regexp'));
     $this->add_per_answer_fields($mform, get_string('answerno', 'qtype_shortanswer', '{no}'), question_bank::fraction_options(), $minoptions = 3, $addoptions = 1);
     $mform->addElement('header', 'showhidealternate', get_string('showhidealternate', 'qtype_regexp'));
     $mform->addHelpButton('showhidealternate', 'showhidealternate', 'qtype_regexp');
     $buttonarray = array();
     $buttonarray[] = $mform->createElement('submit', 'showalternate', get_string('showalternate', 'qtype_regexp'));
     $mform->registerNoSubmitButton('showalternate');
     if ($this->showalternate) {
         $qu = new stdClass();
         $qu->id = $this->questionid;
         $qu->answers = array();
         $i = 0;
         $this->fraction[0] = 1;
         $data = array();
         foreach ($this->currentanswers as $key => $answer) {
             $qu->answers[$i] = new stdClass();
             $qu->answers[$i]->answer = $answer;
             $qu->answers[$i]->fraction = $this->fraction[$i];
             // for sending $data to validation
             $data['answer'][$i] = $answer;
             $data['fraction'][$i] = $this->fraction[$i];
             $data['feedback'][$i] = $this->feedback[$i];
             $i++;
         }
         $moodle_val = $this->validation($data, '');
         if (is_array($moodle_val) && count($moodle_val) !== 0) {
             // non-empty array means errors
             foreach ($moodle_val as $element => $msg) {
                 $mform->setElementError($element, $msg);
             }
             // set to false in order to set hidealternate button to disabled
             $this->showalternate = false;
         } else {
             // we need to unset SESSION in case Answers have been edited since last call to get_alternateanswers()
             if (isset($SESSION->qtype_regexp_question->alternateanswers[$this->questionid])) {
                 unset($SESSION->qtype_regexp_question->alternateanswers[$this->questionid]);
             }
             $alternateanswers = get_alternateanswers($qu);
             $mform->addElement('html', '<div class="alternateanswers">');
             $alternatelist = '';
             foreach ($alternateanswers as $key => $alternateanswer) {
                 $mform->addElement('static', 'alternateanswer', get_string('answer') . ' ' . $key . ' (' . $alternateanswer['fraction'] . ')', '<span class="regexp">' . $alternateanswer['regexp'] . '</span>');
                 $list = '';
                 foreach ($alternateanswer['answers'] as $alternate) {
                     $list .= '<li>' . $alternate . '</li>';
                 }
                 $mform->addElement('static', 'alternateanswer', '', '<ul class="square">' . $list . '</ul>');
             }
             $mform->addElement('html', '</div>');
         }
     }
     $disabled = '';
     if ($this->showalternate) {
         $disabled = '';
     } else {
         $disabled = 'disabled';
     }
     $buttonarray[] = $mform->createElement('submit', 'hidealternate', get_string('hidealternate', 'qtype_regexp'), $disabled);
     $mform->registerNoSubmitButton('hidealternate');
     $mform->addGroup($buttonarray, '', '', array(' '), false);
     $mform->addElement('header', 'multitriesheader', get_string('settingsformultipletries', 'qtype_regexp'));
     $withclearwrong = false;
     $withshownumpartscorrect = false;
     $penalties = array(1.0, 0.5, 0.33, 0.25, 0.2, 0.1, 0.05, 0.0);
     if (!empty($this->question->penalty) && !in_array($this->question->penalty, $penalties)) {
         $penalties[] = $this->question->penalty;
         sort($penalties);
     }
     $penaltyoptions = array();
     foreach ($penalties as $penalty) {
         $penaltyoptions["{$penalty}"] = 100 * $penalty . '%';
     }
     $mform->addElement('select', 'penalty', get_string('penaltyforeachincorrecttry', 'qtype_regexp'), $penaltyoptions);
     $mform->addRule('penalty', null, 'required', null, 'client');
     $mform->addHelpButton('penalty', 'penaltyforeachincorrecttry', 'qtype_regexp');
     $mform->setDefault('penalty', 0.1);
     if ($this->question->formoptions->repeatelements) {
         //$repeatsatstart = max(self::DEFAULT_NUM_HINTS, $counthints);
         // JR we suppose hints are not really needed in REGEXP question type, so set start nb at zero
         $repeatsatstart = max(0, $counthints);
     } else {
         $repeatsatstart = $counthints;
     }
     if ($counthints != 0) {
         $addhint = get_string('addanotherhint', 'question');
     } else {
         $addhint = get_string('addahint', 'qtype_regexp');
     }
     list($repeated, $repeatedoptions) = $this->get_hint_fields($withclearwrong, $withshownumpartscorrect);
     $this->repeat_elements($repeated, $repeatsatstart, $repeatedoptions, 'numhints', 'addhint', 1, $addhint);
 }