Updated the HEAD build version to 20100513
[moodle.git] / question / import_form.php
CommitLineData
aeb15530 1<?php
515ed4c3 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');
a387e8ac 17 $i = 0 ;
f94902db 18 foreach ($fileformatnames as $shortname => $fileformatname) {
a387e8ac
PP
19 $currentgrp1 = array();
20 $currentgrp1[] = &$mform->createElement('radio','format','',$fileformatname,$shortname);
21 $mform->addGroup($currentgrp1,"formathelp[$i]",'',array('<br />'),false);
22 $mform->setHelpButton("formathelp[$i]", array("$shortname",$fileformatname,"qformat_$shortname"));
23 $i++ ;
45b68eef 24 }
a387e8ac 25 $mform->addRule("formathelp[0]", null, 'required', null, 'client' );
515ed4c3 26//--------------------------------------------------------------------------------
27 $mform->addElement('header','general', get_string('general', 'form'));
28
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'));
32
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);
40
515ed4c3 41
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');
48
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'));
15b83581 52
515ed4c3 53//--------------------------------------------------------------------------------
54 $mform->addElement('header', 'importfileupload', get_string('importfileupload','quiz'));
55
515ed4c3 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');
aeb15530
PS
71
72 // set a template for the format select elements
79e3dd8e 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
8239d2c6 80 // TODO change this to use the files API properly.
81 return $_FILES['newfile']['tmp_name'];
82// return $this->_upload_manager->files['newfile']['tmp_name'];
515ed4c3 83 }else{
84 return NULL;
85 }
86 }
aeb15530 87
bced3022 88 function get_importfile_realname(){
73b7b195 89 if ($this->is_submitted() and $this->is_validated()) {
90 // return the temporary filename to process
91 // TODO change this to use the files API properly.
92 return $_FILES['newfile']['name'];
93 }else{
94 return NULL;
95 }
96 }
515ed4c3 97}
aeb15530 98