$settings->add(new admin_setting_configtext('qtype_stack/maximalibraries', get_string('settingmaximalibraries', 'qtype_stack'), get_string('settingmaximalibraries_desc', 'qtype_stack'), 'stats, distrib, descriptive'));
$settings->add(new admin_setting_configcheckbox('qtype_stack/casdebugging', get_string('settingcasdebugging', 'qtype_stack'), get_string('settingcasdebugging_desc', 'qtype_stack'), 0));
// Options for maths display.
$settings->add(new admin_setting_heading('mathsdisplayheading', get_string('settingsmathsdisplayheading', 'qtype_stack'), ''));
$settings->add(new admin_setting_configcheckbox('qtype_stack/ajaxvalidation', get_string('settingajaxvalidation', 'qtype_stack'), get_string('settingajaxvalidation_desc', 'qtype_stack'), 1));
$settings->add(new qtype_stack_admin_setting_maths_display_method('qtype_stack/mathsdisplay', get_string('settingmathsdisplay', 'qtype_stack'), get_string('settingmathsdisplay_desc', 'qtype_stack'), 'mathjax', null));
$settings->add(new admin_setting_configcheckbox('qtype_stack/replacedollars', get_string('settingreplacedollars', 'qtype_stack'), get_string('settingreplacedollars_desc', 'qtype_stack'), false));
// Options for new inputs.
$settings->add(new admin_setting_heading('inputoptionsheading', get_string('settingdefaultinputoptions', 'qtype_stack'), get_string('settingdefaultinputoptions_desc', 'qtype_stack')));
$settings->add(new qtype_stack_admin_setting_input_types('qtype_stack/inputtype', get_string('inputtype', 'qtype_stack'), get_string('inputtype_help', 'qtype_stack'), 'algebraic', null));
$settings->add(new admin_setting_configtext('qtype_stack/inputboxsize', get_string('boxsize', 'qtype_stack'), get_string('boxsize_help', 'qtype_stack'), '15', PARAM_INT));
$settings->add(new admin_setting_configselect('qtype_stack/inputstrictsyntax', get_string('strictsyntax', 'qtype_stack'), get_string('strictsyntax_help', 'qtype_stack'), '1', stack_options::get_yes_no_options()));
$settings->add(new admin_setting_configselect('qtype_stack/inputinsertstars', get_string('insertstars', 'qtype_stack'), get_string('insertstars_help', 'qtype_stack'), '0', stack_options::get_insert_star_options()));
$settings->add(new admin_setting_configtext('qtype_stack/inputforbidwords', get_string('forbidwords', 'qtype_stack'), get_string('forbidwords_help', 'qtype_stack'), '', PARAM_RAW));
$settings->add(new admin_setting_configselect('qtype_stack/inputforbidfloat', get_string('forbidfloat', 'qtype_stack'), get_string('forbidfloat_help', 'qtype_stack'), '1', stack_options::get_yes_no_options()));
$settings->add(new admin_setting_configselect('qtype_stack/inputrequirelowestterms', get_string('requirelowestterms', 'qtype_stack'), get_string('requirelowestterms_help', 'qtype_stack'), '0', stack_options::get_yes_no_options()));
$settings->add(new admin_setting_configselect('qtype_stack/inputcheckanswertype', get_string('checkanswertype', 'qtype_stack'), get_string('checkanswertype_help', 'qtype_stack'), '0', stack_options::get_yes_no_options()));
$settings->add(new admin_setting_configselect('qtype_stack/inputmustverify', get_string('mustverify', 'qtype_stack'), get_string('mustverify_help', 'qtype_stack'), '1', stack_options::get_yes_no_options()));
$settings->add(new admin_setting_configselect('qtype_stack/inputshowvalidation', get_string('showvalidation', 'qtype_stack'), get_string('showvalidation_help', 'qtype_stack'), '1', stack_options::get_showvalidation_options()));
// Options for new questions.
$settings->add(new admin_setting_heading('questionoptionsheading', get_string('settingdefaultquestionoptions', 'qtype_stack'), get_string('settingdefaultquestionoptions_desc', 'qtype_stack')));
$settings->add(new admin_setting_configselect('qtype_stack/questionsimplify', get_string('questionsimplify', 'qtype_stack'), get_string('autosimplify_help', 'qtype_stack'), '1', stack_options::get_yes_no_options()));
$settings->add(new admin_setting_configselect('qtype_stack/assumepositive', get_string('assumepositive', 'qtype_stack'), get_string('assumepositive_help', 'qtype_stack'), '0', stack_options::get_yes_no_options()));
$settings->add(new admin_setting_configtextarea('qtype_stack/prtcorrect', get_string('prtcorrectfeedback', 'qtype_stack'), '', get_string('defaultprtcorrectfeedback', 'qtype_stack'), PARAM_RAW, 60, 3));
$settings->add(new admin_setting_configtextarea('qtype_stack/prtpartiallycorrect', get_string('prtpartiallycorrectfeedback', 'qtype_stack'), '', get_string('defaultprtpartiallycorrectfeedback', 'qtype_stack'), PARAM_RAW, 60, 3));
$settings->add(new admin_setting_configtextarea('qtype_stack/prtincorrect', get_string('prtincorrectfeedback', 'qtype_stack'), '', get_string('defaultprtincorrectfeedback', 'qtype_stack'), PARAM_RAW, 60, 3));
$settings->add(new admin_setting_configselect('qtype_stack/multiplicationsign', get_string('multiplicationsign', 'qtype_stack'), get_string('multiplicationsign_help', 'qtype_stack'), 'dot', stack_options::get_multiplication_sign_options()));
$settings->add(new admin_setting_configselect('qtype_stack/sqrtsign', get_string('sqrtsign', 'qtype_stack'), get_string('sqrtsign_help', 'qtype_stack'), '1', stack_options::get_yes_no_options()));
$settings->add(new admin_setting_configselect('qtype_stack/complexno', get_string('complexno', 'qtype_stack'), get_string('complexno_help', 'qtype_stack'), 'i', stack_options::get_complex_no_options()));
$settings->add(new admin_setting_configselect('qtype_stack/inversetrig', get_string('inversetrig', 'qtype_stack'), get_string('inversetrig_help', 'qtype_stack'), 'cos-1', stack_options::get_inverse_trig_options()));
$settings->add(new admin_setting_configselect('qtype_stack/matrixparens', get_string('matrixparens', 'qtype_stack'), get_string('matrixparens_help', 'qtype_stack'), '[', stack_options::get_matrix_parens_options()));
 protected function definition_inner($mform)
 {
     // Load the configuration.
     $this->stackconfig = stack_utils::get_config();
     // Prepare input types.
     $this->typechoices = stack_input_factory::get_available_type_choices();
     // Prepare answer test types.
     $answertests = stack_ans_test_controller::get_available_ans_tests();
     // Algebraic Equivalence should be the default test, and first on the list.
     // This does not come first in the alphabet of all languages.
     $default = 'AlgEquiv';
     $defaultstr = stack_string($answertests[$default]);
     unset($answertests[$default]);
     $this->answertestchoices = array();
     foreach ($answertests as $test => $string) {
         $this->answertestchoices[$test] = stack_string($string);
     }
     stack_utils::sort_array($this->answertestchoices);
     $this->answertestchoices = array_merge(array($default => $defaultstr), $this->answertestchoices);
     // Prepare score mode choices.
     $this->scoremodechoices = array('=' => '=', '+' => '+', '-' => '-');
     $inputnames = $this->get_input_names_from_question_text();
     $prtnames = $this->get_prt_names_from_question();
     // Note that for the editor elements, we are using
     // $mform->getElement('prtincorrect')->setValue(...);
     // instead of setDefault, because setDefault does not work for editors.
     $mform->addHelpButton('questiontext', 'questiontext', 'qtype_stack');
     $mform->addRule('questiontext', stack_string('questiontextnonempty'), 'required', '', 'client');
     $qvars = $mform->createElement('textarea', 'questionvariables', stack_string('questionvariables'), array('rows' => 5, 'cols' => 80));
     $mform->insertElementBefore($qvars, 'questiontext');
     $mform->addHelpButton('questionvariables', 'questionvariables', 'qtype_stack');
     $seed = $mform->createElement('text', 'variantsselectionseed', stack_string('variantsselectionseed'), array('size' => 50));
     $mform->insertElementBefore($seed, 'questiontext');
     $mform->setType('variantsselectionseed', PARAM_RAW);
     $mform->addHelpButton('variantsselectionseed', 'variantsselectionseed', 'qtype_stack');
     $sf = $mform->createElement('editor', 'specificfeedback', get_string('specificfeedback', 'question'), array('rows' => 10), $this->editoroptions);
     $mform->insertElementBefore($sf, 'generalfeedback');
     $mform->getElement('specificfeedback')->setValue(array('text' => self::DEFAULT_SPECIFIC_FEEDBACK));
     $mform->addHelpButton('specificfeedback', 'specificfeedback', 'qtype_stack');
     $mform->addHelpButton('generalfeedback', 'generalfeedback', 'qtype_stack');
     $mform->addElement('textarea', 'questionnote', stack_string('questionnote'), array('rows' => 2, 'cols' => 80));
     $mform->addHelpButton('questionnote', 'questionnote', 'qtype_stack');
     $mform->addElement('submit', 'verify', stack_string('verifyquestionandupdate'));
     $mform->registerNoSubmitButton('verify');
     // Inputs.
     foreach ($inputnames as $inputname => $counts) {
         $this->definition_input($inputname, $mform, $counts);
     }
     // PRTs.
     foreach ($prtnames as $prtname => $count) {
         $this->definition_prt($prtname, $mform, $count);
     }
     // Options.
     $mform->addElement('header', 'optionsheader', stack_string('options'));
     $mform->addElement('selectyesno', 'questionsimplify', stack_string('questionsimplify'));
     $mform->setDefault('questionsimplify', $this->stackconfig->questionsimplify);
     $mform->addHelpButton('questionsimplify', 'autosimplify', 'qtype_stack');
     $mform->addElement('selectyesno', 'assumepositive', stack_string('assumepositive'));
     $mform->setDefault('assumepositive', $this->stackconfig->assumepositive);
     $mform->addHelpButton('assumepositive', 'assumepositive', 'qtype_stack');
     $mform->addElement('editor', 'prtcorrect', stack_string('prtcorrectfeedback'), array('rows' => 1), $this->editoroptions);
     $mform->getElement('prtcorrect')->setValue(array('text' => $this->stackconfig->prtcorrect));
     $mform->addElement('editor', 'prtpartiallycorrect', stack_string('prtpartiallycorrectfeedback'), array('rows' => 1), $this->editoroptions);
     $mform->getElement('prtpartiallycorrect')->setValue(array('text' => $this->stackconfig->prtpartiallycorrect));
     $mform->addElement('editor', 'prtincorrect', stack_string('prtincorrectfeedback'), array('rows' => 1), $this->editoroptions);
     $mform->getElement('prtincorrect')->setValue(array('text' => $this->stackconfig->prtincorrect));
     $mform->addElement('select', 'multiplicationsign', stack_string('multiplicationsign'), stack_options::get_multiplication_sign_options());
     $mform->setDefault('multiplicationsign', $this->stackconfig->multiplicationsign);
     $mform->addHelpButton('multiplicationsign', 'multiplicationsign', 'qtype_stack');
     $mform->addElement('selectyesno', 'sqrtsign', stack_string('sqrtsign'));
     $mform->setDefault('sqrtsign', $this->stackconfig->sqrtsign);
     $mform->addHelpButton('sqrtsign', 'sqrtsign', 'qtype_stack');
     $mform->addElement('select', 'complexno', stack_string('complexno'), stack_options::get_complex_no_options());
     $mform->setDefault('complexno', $this->stackconfig->complexno);
     $mform->addHelpButton('complexno', 'complexno', 'qtype_stack');
     $mform->addElement('select', 'inversetrig', stack_string('inversetrig'), stack_options::get_inverse_trig_options());
     $mform->setDefault('inversetrig', $this->stackconfig->inversetrig);
     $mform->addHelpButton('inversetrig', 'inversetrig', 'qtype_stack');
     $mform->addElement('select', 'matrixparens', stack_string('matrixparens'), stack_options::get_matrix_parens_options());
     $mform->setDefault('matrixparens', $this->stackconfig->matrixparens);
     $mform->addHelpButton('matrixparens', 'matrixparens', 'qtype_stack');
     // Hints.
     $this->add_interactive_settings();
     // Replace standard penalty input at the bottom with the one we want.
     $mform->removeElement('multitriesheader');
     $mform->removeElement('penalty');
     $pen = $mform->createElement('text', 'penalty', stack_string('penalty'), array('size' => 5));
     $mform->insertElementBefore($pen, 'generalfeedback');
     $mform->setType('penalty', PARAM_FLOAT);
     $mform->addHelpButton('penalty', 'penalty', 'qtype_stack');
     $mform->setDefault('penalty', 0.1);
     $mform->addRule('penalty', null, 'required', null, 'client');
 }