MDL-14279: use get_file_url instead of checking $CFG->slashargument manually (merge...
[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();
18 foreach ($fileformatnames as $id => $fileformatname) {
79e3dd8e 19 $radioelement = &MoodleQuickForm::createElement('radio','format','',$fileformatname,$id );
20 $radioelement->setHelpButton(array("format{$id}",$fileformatname,'quiz'));
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
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//--------------------------------------------------------------------------------
8b66a42a 58 $mform->addElement('submit', 'submitbutton', get_string('uploadthisfile'));
515ed4c3 59
60//--------------------------------------------------------------------------------
15b83581 61 if (has_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $COURSE->id))){
62 $mform->addElement('header', 'importfilearea', get_string('importfilearea','quiz'));
515ed4c3 63
15b83581 64 $mform->addElement('choosecoursefile', 'choosefile', get_string('choosefile','quiz'));
515ed4c3 65//--------------------------------------------------------------------------------
8b66a42a 66 $mform->addElement('submit', 'submitbutton', get_string('importfromthisfile','quiz'));
15b83581 67 }
515ed4c3 68//--------------------------------------------------------------------------------
8b66a42a 69 $mform->addElement('static', 'dummy', '');
70 $mform->closeHeaderBefore('dummy');
79e3dd8e 71
72 // set a template for the format select elements
73 $renderer =& $mform->defaultRenderer();
74 $template = "{help} {element}\n";
75 $renderer->setGroupElementTemplate($template, 'format');
515ed4c3 76 }
77 function get_importfile_name(){
78 if ($this->is_submitted() and $this->is_validated()) {
79 // return the temporary filename to process
80 return $this->_upload_manager->files['newfile']['tmp_name'];
81 }else{
82 return NULL;
83 }
84 }
85}
86?>