MDL-10876:
[moodle.git] / question / import_form.php
1 <?php  //$Id$
3 require_once($CFG->libdir.'/formslib.php');
4 require_once($CFG->libdir.'/form/selectgroups.php');
6 class question_import_form extends moodleform {
8     function definition() {
9         global $COURSE;
10         $mform    =& $this->_form;
12         $defaultcategory   = $this->_customdata['defaultcategory'];
13         $contexts   = $this->_customdata['contexts'];
15 //--------------------------------------------------------------------------------
16         $mform->addElement('header','fileformat', get_string('fileformat','quiz'));
17         $fileformatnames = get_import_export_formats('import');
18         $radioarray = array();
19         foreach ($fileformatnames as $id => $fileformatname) {
20             $radioarray[] = &MoodleQuickForm::createElement('radio','format','',$fileformatname,$id );
21         }
22         $mform->addGroup($radioarray,'format', '', array('<br />'), false);
23         $mform->addRule('format', null, 'required', null, 'client' );
24         $mform->setHelpButton('format', array('import', get_string('importquestions', 'quiz'), 'quiz'));
26 //--------------------------------------------------------------------------------
27         $mform->addElement('header','general', get_string('general', 'form'));
29         $mform->addElement('questioncategory', 'category', get_string('category','quiz'), compact('contexts'));
30         $mform->setDefault('category', $defaultcategory);
31         $mform->setHelpButton('category', array('importcategory', get_string('importcategory','quiz'), 'quiz'));
33         $categorygroup = array();
34         $categorygroup[] =& $mform->createElement('checkbox', 'catfromfile', '', get_string('getcategoryfromfile', 'question'));
35         $categorygroup[] =& $mform->createElement('checkbox', 'contextfromfile', '', get_string('getcontextfromfile', 'question'));
36         $mform->addGroup($categorygroup, 'categorygroup', '', '', false);
37         $mform->disabledIf('categorygroup', 'catfromfile', 'notchecked');
38         $mform->setDefault('catfromfile', 1);
39         $mform->setDefault('contextfromfile', 1);
42         $matchgrades = array();
43         $matchgrades['error'] = get_string('matchgradeserror','quiz');
44         $matchgrades['nearest'] = get_string('matchgradesnearest','quiz');
45         $mform->addElement('select', 'matchgrades', get_string('matchgrades','quiz'), $matchgrades);
46         $mform->setHelpButton('matchgrades', array('matchgrades', get_string('matchgrades','quiz'), 'quiz'));
47         $mform->setDefault('matchgrades', 'error');
49         $mform->addElement('selectyesno', 'stoponerror', get_string('stoponerror', 'quiz'));
50         $mform->setDefault('stoponerror', 1);
51         $mform->setHelpButton('stoponerror', array('stoponerror', get_string('stoponerror', 'quiz'), 'quiz'));
52         
53 //--------------------------------------------------------------------------------
54         $mform->addElement('header', 'importfileupload', get_string('importfileupload','quiz'));
56         $this->set_upload_manager(new upload_manager('newfile', true, false, $COURSE, false, 0, false, true, false));
57         $mform->addElement('file', 'newfile', get_string('upload'));
58 //--------------------------------------------------------------------------------
59         $this->add_action_buttons(true, get_string('uploadthisfile'));
61 //--------------------------------------------------------------------------------
62         $mform->addElement('header', 'importfilearea', get_string('importfilearea','quiz'));
64         $mform->addElement('choosecoursefile', 'choosefile', get_string('choosefile','quiz'));
65 //--------------------------------------------------------------------------------
66         $this->add_action_buttons(true, get_string('importfromthisfile','quiz'));
67 //--------------------------------------------------------------------------------
68     }
69     function get_importfile_name(){
70         if ($this->is_submitted() and $this->is_validated()) {
71             // return the temporary filename to process
72             return $this->_upload_manager->files['newfile']['tmp_name'];
73         }else{
74             return  NULL;
75         }
76     }
77 }
78 ?>