merging MOODLE_19_QUESTIONS with HEAD
[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'];
14 //--------------------------------------------------------------------------------
15         $mform->addElement('header','general', get_string('general', 'form'));
17         $mform->addElement('questioncategory', 'category', get_string('category','quiz'), compact('contexts'));
18         $mform->setDefault('category', $defaultcategory);
19         $mform->setHelpButton('category', array('importcategory', get_string('importcategory','quiz'), 'quiz'));
21         $categorygroup = array();
22         $categorygroup[] =& $mform->createElement('checkbox', 'catfromfile', '', get_string('getcategoryfromfile', 'question'));
23         $categorygroup[] =& $mform->createElement('checkbox', 'contextfromfile', '', get_string('getcontextfromfile', 'question'));
24         $mform->addGroup($categorygroup, 'categorygroup', '', '', false);
25         $mform->disabledIf('categorygroup', 'catfromfile', 'notchecked');
26         $mform->setDefault('catfromfile', 1);
27         $mform->setDefault('contextfromfile', 1);
29         $fileformatnames = get_import_export_formats('import');
30         $mform->addElement('select', 'format', get_string('fileformat','quiz'), $fileformatnames);
31         $mform->setDefault('format', 'gift');
33         $matchgrades = array();
34         $matchgrades['error'] = get_string('matchgradeserror','quiz');
35         $matchgrades['nearest'] = get_string('matchgradesnearest','quiz');
36         $mform->addElement('select', 'matchgrades', get_string('matchgrades','quiz'), $matchgrades);
37         $mform->setHelpButton('matchgrades', array('matchgrades', get_string('matchgrades','quiz'), 'quiz'));
38         $mform->setDefault('matchgrades', 'error');
40         $mform->addElement('selectyesno', 'stoponerror', get_string('stoponerror', 'quiz'));
41         $mform->setDefault('stoponerror', 1);
42         $mform->setHelpButton('stoponerror', array('stoponerror', get_string('stoponerror', 'quiz'), 'quiz'));
43         
44 //--------------------------------------------------------------------------------
45         $mform->addElement('header', 'importfileupload', get_string('importfileupload','quiz'));
47         $this->set_upload_manager(new upload_manager('newfile', true, false, $COURSE, false, 0, false, true, false));
48         $mform->addElement('file', 'newfile', get_string('upload'));
49 //--------------------------------------------------------------------------------
50         $this->add_action_buttons(true, get_string('uploadthisfile'));
52 //--------------------------------------------------------------------------------
53         $mform->addElement('header', 'importfilearea', get_string('importfilearea','quiz'));
55         $mform->addElement('choosecoursefile', 'choosefile', get_string('choosefile','quiz'));
56 //--------------------------------------------------------------------------------
57         $this->add_action_buttons(true, get_string('importfromthisfile','quiz'));
58 //--------------------------------------------------------------------------------
59     }
60     function get_importfile_name(){
61         if ($this->is_submitted() and $this->is_validated()) {
62             // return the temporary filename to process
63             return $this->_upload_manager->files['newfile']['tmp_name'];
64         }else{
65             return  NULL;
66         }
67     }
68 }
69 ?>