3 require_once($CFG->libdir
.'/formslib.php');
5 class question_import_form
extends moodleform
{
7 function definition() {
9 $mform =& $this->_form
;
11 $defaultcategory = $this->_customdata
['defaultcategory'];
12 $contexts = $this->_customdata
['contexts'];
14 //--------------------------------------------------------------------------------
15 $mform->addElement('header','fileformat', get_string('fileformat','quiz'));
16 $fileformatnames = get_import_export_formats('import');
17 $radioarray = array();
18 foreach ($fileformatnames as $id => $fileformatname) {
19 $radioarray[] = &MoodleQuickForm
::createElement('radio','format','',$fileformatname,$id );
21 $mform->addGroup($radioarray,'format', '', array('<br />'), false);
22 $mform->addRule('format', null, 'required', null, 'client' );
23 $mform->setHelpButton('format', array('import', get_string('importquestions', 'quiz'), 'quiz'));
25 //--------------------------------------------------------------------------------
26 $mform->addElement('header','general', get_string('general', 'form'));
28 $mform->addElement('questioncategory', 'category', get_string('category','quiz'), compact('contexts'));
29 $mform->setDefault('category', $defaultcategory);
30 $mform->setHelpButton('category', array('importcategory', get_string('importcategory','quiz'), 'quiz'));
32 $categorygroup = array();
33 $categorygroup[] =& $mform->createElement('checkbox', 'catfromfile', '', get_string('getcategoryfromfile', 'question'));
34 $categorygroup[] =& $mform->createElement('checkbox', 'contextfromfile', '', get_string('getcontextfromfile', 'question'));
35 $mform->addGroup($categorygroup, 'categorygroup', '', '', false);
36 $mform->disabledIf('categorygroup', 'catfromfile', 'notchecked');
37 $mform->setDefault('catfromfile', 1);
38 $mform->setDefault('contextfromfile', 1);
41 $matchgrades = array();
42 $matchgrades['error'] = get_string('matchgradeserror','quiz');
43 $matchgrades['nearest'] = get_string('matchgradesnearest','quiz');
44 $mform->addElement('select', 'matchgrades', get_string('matchgrades','quiz'), $matchgrades);
45 $mform->setHelpButton('matchgrades', array('matchgrades', get_string('matchgrades','quiz'), 'quiz'));
46 $mform->setDefault('matchgrades', 'error');
48 $mform->addElement('selectyesno', 'stoponerror', get_string('stoponerror', 'quiz'));
49 $mform->setDefault('stoponerror', 1);
50 $mform->setHelpButton('stoponerror', array('stoponerror', get_string('stoponerror', 'quiz'), 'quiz'));
52 //--------------------------------------------------------------------------------
53 $mform->addElement('header', 'importfileupload', get_string('importfileupload','quiz'));
55 $this->set_upload_manager(new upload_manager('newfile', true, false, $COURSE, false, 0, false, true, false));
56 $mform->addElement('file', 'newfile', get_string('upload'));
57 //--------------------------------------------------------------------------------
58 $mform->addElement('submit', 'submitbutton', get_string('uploadthisfile'));
60 //--------------------------------------------------------------------------------
61 if (has_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE
, $COURSE->id
))){
62 $mform->addElement('header', 'importfilearea', get_string('importfilearea','quiz'));
64 $mform->addElement('choosecoursefile', 'choosefile', get_string('choosefile','quiz'));
65 //--------------------------------------------------------------------------------
66 $mform->addElement('submit', 'submitbutton', get_string('importfromthisfile','quiz'));
68 //--------------------------------------------------------------------------------
69 $mform->addElement('static', 'dummy', '');
70 $mform->closeHeaderBefore('dummy');
72 function get_importfile_name(){
73 if ($this->is_submitted() and $this->is_validated()) {
74 // return the temporary filename to process
75 return $this->_upload_manager
->files
['newfile']['tmp_name'];