MDL-20601 fixed fatal SQL upgrade error, missing {} around table names
[moodle.git] / question / import_form.php
CommitLineData
515ed4c3 1<?php //$Id$
2
3require_once($CFG->libdir.'/formslib.php');
515ed4c3 4
5class question_import_form extends moodleform {
6
7 function definition() {
8 global $COURSE;
9 $mform =& $this->_form;
10
11 $defaultcategory = $this->_customdata['defaultcategory'];
12 $contexts = $this->_customdata['contexts'];
45b68eef 13
14//--------------------------------------------------------------------------------
15 $mform->addElement('header','fileformat', get_string('fileformat','quiz'));
16 $fileformatnames = get_import_export_formats('import');
17 $radioarray = array();
f94902db 18 foreach ($fileformatnames as $shortname => $fileformatname) {
19 $radioelement = &MoodleQuickForm::createElement('radio','format','',$fileformatname,$shortname );
20 $radioelement->setHelpButton(array("$shortname",$fileformatname,"qformat_$shortname"));
79e3dd8e 21 $radioarray[] = $radioelement;
45b68eef 22 }
79e3dd8e 23 $mform->addGroup($radioarray,'format', '', array('<br />'), false);
45b68eef 24 $mform->addRule('format', null, 'required', null, 'client' );
515ed4c3 25//--------------------------------------------------------------------------------
26 $mform->addElement('header','general', get_string('general', 'form'));
27
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'));
31
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);
39
515ed4c3 40
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');
47
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'));
15b83581 51
515ed4c3 52//--------------------------------------------------------------------------------
53 $mform->addElement('header', 'importfileupload', get_string('importfileupload','quiz'));
54
515ed4c3 55 $mform->addElement('file', 'newfile', get_string('upload'));
56//--------------------------------------------------------------------------------
8b66a42a 57 $mform->addElement('submit', 'submitbutton', get_string('uploadthisfile'));
515ed4c3 58
59//--------------------------------------------------------------------------------
15b83581 60 if (has_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $COURSE->id))){
61 $mform->addElement('header', 'importfilearea', get_string('importfilearea','quiz'));
515ed4c3 62
15b83581 63 $mform->addElement('choosecoursefile', 'choosefile', get_string('choosefile','quiz'));
515ed4c3 64//--------------------------------------------------------------------------------
8b66a42a 65 $mform->addElement('submit', 'submitbutton', get_string('importfromthisfile','quiz'));
15b83581 66 }
515ed4c3 67//--------------------------------------------------------------------------------
8b66a42a 68 $mform->addElement('static', 'dummy', '');
69 $mform->closeHeaderBefore('dummy');
79e3dd8e 70
71 // set a template for the format select elements
72 $renderer =& $mform->defaultRenderer();
73 $template = "{help} {element}\n";
74 $renderer->setGroupElementTemplate($template, 'format');
515ed4c3 75 }
76 function get_importfile_name(){
77 if ($this->is_submitted() and $this->is_validated()) {
78 // return the temporary filename to process
8239d2c6 79 // TODO change this to use the files API properly.
80 return $_FILES['newfile']['tmp_name'];
81// return $this->_upload_manager->files['newfile']['tmp_name'];
515ed4c3 82 }else{
83 return NULL;
84 }
85 }
73b7b195 86
bced3022 87 function get_importfile_realname(){
73b7b195 88 if ($this->is_submitted() and $this->is_validated()) {
89 // return the temporary filename to process
90 // TODO change this to use the files API properly.
91 return $_FILES['newfile']['name'];
92 }else{
93 return NULL;
94 }
95 }
515ed4c3 96}
97?>