MDL-9629 Changed grade_item.gradetype default to 1, added GRADE_TYPE_NONE constant...
[moodle.git] / grade / import / grade_import_form.php
CommitLineData
7f999ccb 1<?php // $Id$
2require_once $CFG->libdir.'/formslib.php';
3
4class grade_import_form extends moodleform {
5 function definition (){
6 $mform =& $this->_form;
7
8 // course id needs to be passed for auth purposes
9 $mform->addElement('hidden', 'id', optional_param('id'));
10
11 // file upload
12 $mform->addElement('file', 'userfile', get_string('file'));
13 $mform->addRule('userfile', null, 'required');
14
15 $this->add_action_buttons(false, get_string('uploadgrades'));
16 }
17
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'];
22 }else{
23 return NULL;
24 }
25 }
26}
85e287de 27
85e287de 28class grade_import_mapping_form extends moodleform {
3f8bcf7c 29
85e287de 30 function definition () {
3f8bcf7c 31 global $CFG;
32
85e287de 33 $mform =& $this->_form;
34
3f8bcf7c 35 // this is an array of headers
36 $header = $this->_customdata['header'];
37 // temporary filename
38 $filename = $this->_customdata['filename'];
39 // course id
40 $id = $this->_customdata['id'];
85e287de 41
3f8bcf7c 42 $mform->addElement('header', 'general', get_string('identifier'));
43 $mapfromoptions = array();
44
45 if ($header) {
46 foreach ($header as $h) {
47 $mapfromoptions[$h] = $h;
48 }
49 }
50 $mform->addElement('select', 'mapfrom', get_string('mapfrom'), $mapfromoptions);
51 //choose_from_menu($mapfromoptions, 'mapfrom');
52
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);
56
57 $mform->addElement('header', 'general', get_string('mappings'));
58
59 $gradeitems = array();
85e287de 60
3f8bcf7c 61 include_once($CFG->libdir.'/gradelib.php');
62
63 if ($id) {
64 if ($grade_items = grade_get_items($id)) {
65 foreach ($grade_items as $grade_item) {
66 $gradeitems[$grade_item->idnumber] = $grade_item->itemname;
67 }
85e287de 68 }
69 }
3f8bcf7c 70
71 if ($header) {
72 foreach ($header as $h) {
73
74 $h = trim($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
79
80 $mapfromoptions = array_merge(array('0'=>'ignore'), $gradeitems);
81 $mform->addElement('select', 'mapping[]', $h, $mapfromoptions);
82 //choose_from_menu($mapfromoptions, 'mapping[]', $h);
83
84 }
85e287de 85 }
3f8bcf7c 86 $newfilename = 'cvstemp_'.time();
87 move_uploaded_file($filename, $CFG->dataroot.'/temp/'.$newfilename);
88
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);
94
95 $this->add_action_buttons(false, get_string('uploadgrades'));
85e287de 96
85e287de 97 }
98}
7f999ccb 99?>