2 require_once $CFG->libdir
.'/formslib.php';
4 class grade_import_form
extends moodleform
{
5 function definition (){
6 $mform =& $this->_form
;
8 // course id needs to be passed for auth purposes
9 $mform->addElement('hidden', 'id', optional_param('id'));
12 $mform->addElement('file', 'userfile', get_string('file'));
13 $mform->addRule('userfile', null, 'required');
15 $this->add_action_buttons(false, get_string('uploadgrades'));
18 function get_userfile_name(){
19 if ($this->is_submitted() and $this->is_validated()) {
20 // return the temporary filename to process
21 return $this->_upload_manager
->files
['userfile']['tmp_name'];
28 class grade_import_mapping_form
extends moodleform
{
30 function definition () {
33 $mform =& $this->_form
;
35 // this is an array of headers
36 $header = $this->_customdata
['header'];
38 $filename = $this->_customdata
['filename'];
40 $id = $this->_customdata
['id'];
42 $mform->addElement('header', 'general', get_string('identifier'));
43 $mapfromoptions = array();
46 foreach ($header as $h) {
47 $mapfromoptions[$h] = $h;
50 $mform->addElement('select', 'mapfrom', get_string('mapfrom'), $mapfromoptions);
51 //choose_from_menu($mapfromoptions, 'mapfrom');
53 $maptooptions = array('userid'=>'userid', 'username'=>'username', 'useridnumber'=>'useridnumber', 'useremail'=>'useremail', '0'=>'ignore');
54 //choose_from_menu($maptooptions, 'mapto');
55 $mform->addElement('select', 'mapto', get_string('mapto'), $maptooptions);
57 $mform->addElement('header', 'general', get_string('mappings'));
59 $gradeitems = array();
61 include_once($CFG->libdir
.'/gradelib.php');
64 if ($grade_items = grade_get_items($id)) {
65 foreach ($grade_items as $grade_item) {
66 $gradeitems[$grade_item->idnumber
] = $grade_item->itemname
;
72 foreach ($header as $h) {
75 // this is the order of the headers
76 $mform->addElement('hidden', 'maps[]', $h);
77 //echo '<input type="hidden" name="maps[]" value="'.$h.'"/>';
78 // this is what they map to
80 $mapfromoptions = array_merge(array('0'=>'ignore'), $gradeitems);
81 $mform->addElement('select', 'mapping[]', $h, $mapfromoptions);
82 //choose_from_menu($mapfromoptions, 'mapping[]', $h);
86 $newfilename = 'cvstemp_'.time();
87 move_uploaded_file($filename, $CFG->dataroot
.'/temp/'.$newfilename);
89 // course id needs to be passed for auth purposes
90 $mform->addElement('hidden', 'map', 1);
91 $mform->addElement('hidden', 'id', optional_param('id'));
92 //echo '<input name="filename" value='.$newfilename.' type="hidden" />';
93 $mform->addElement('hidden', 'filename', $newfilename);
95 $this->add_action_buttons(false, get_string('uploadgrades'));