MDL-11543 Printing nice list of categories for parent category drop-down
[moodle.git] / grade / import / grade_import_form.php
CommitLineData
7f999ccb 1<?php // $Id$
2require_once $CFG->libdir.'/formslib.php';
8108909a 3require_once($CFG->libdir.'/gradelib.php');
7f999ccb 4
5class grade_import_form extends moodleform {
6 function definition (){
7 $mform =& $this->_form;
8
9 // course id needs to be passed for auth purposes
10 $mform->addElement('hidden', 'id', optional_param('id'));
eff9c473 11 $mform->setType('id', PARAM_INT);
f115f8c8 12 $mform->addElement('header', 'general', get_string('importfile', 'grades'));
7f999ccb 13 // file upload
14 $mform->addElement('file', 'userfile', get_string('file'));
eff9c473 15 $mform->setType('userfile', PARAM_FILE);
7f999ccb 16 $mform->addRule('userfile', null, 'required');
8e1ec6be 17 $textlib = textlib_get_instance();
4d40aa14 18 $encodings = $textlib->get_encodings();
f115f8c8 19 $mform->addElement('select', 'encoding', get_string('encoding', 'grades'), $encodings);
7f999ccb 20
ba74762b 21 $options = array('10'=>10, '20'=>20, '100'=>100, '1000'=>1000, '100000'=>100000);
8108909a 22 $mform->addElement('select', 'previewrows', get_string('rowpreviewnum', 'grades'), $options); // TODO: localize
eff9c473 23 $mform->setType('previewrows', PARAM_INT);
f115f8c8 24 $this->add_action_buttons(false, get_string('uploadgrades', 'grades'));
7f999ccb 25 }
7f999ccb 26}
85e287de 27
85e287de 28class grade_import_mapping_form extends moodleform {
ba74762b 29
85e287de 30 function definition () {
3f8bcf7c 31 global $CFG;
85e287de 32 $mform =& $this->_form;
33
3f8bcf7c 34 // this is an array of headers
35 $header = $this->_customdata['header'];
3f8bcf7c 36 // course id
85e287de 37
f115f8c8 38 $mform->addElement('header', 'general', get_string('identifier', 'grades'));
3f8bcf7c 39 $mapfromoptions = array();
ffe8ee55 40
3f8bcf7c 41 if ($header) {
b4355273 42 foreach ($header as $i=>$h) {
5c2aa198 43 $mapfromoptions[$i] = s($h);
3f8bcf7c 44 }
45 }
f115f8c8 46 $mform->addElement('select', 'mapfrom', get_string('mapfrom', 'grades'), $mapfromoptions);
ba74762b 47 //choose_from_menu($mapfromoptions, 'mapfrom');
48
3f8bcf7c 49 $maptooptions = array('userid'=>'userid', 'username'=>'username', 'useridnumber'=>'useridnumber', 'useremail'=>'useremail', '0'=>'ignore');
50 //choose_from_menu($maptooptions, 'mapto');
f115f8c8 51 $mform->addElement('select', 'mapto', get_string('mapto', 'grades'), $maptooptions);
ba74762b 52
f115f8c8 53 $mform->addElement('header', 'general', get_string('mappings', 'grades'));
ba74762b 54
ffe8ee55 55 // add a comment option
56
57 if ($gradeitems = $this->_customdata['gradeitems']) {
ba74762b 58 $comments = array();
ffe8ee55 59 foreach ($gradeitems as $itemid => $itemname) {
ba74762b 60 $comments['feedback_'.$itemid] = 'comments for '.$itemname;
61 }
ffe8ee55 62 }
b4355273 63
ba74762b 64 if ($header) {
b4355273 65 $i = 0; // index
3f8bcf7c 66 foreach ($header as $h) {
3f8bcf7c 67
ffe8ee55 68 $h = trim($h);
ba74762b 69 // this is what each header maps to
70 $mform->addElement('selectgroups',
71 'mapping_'.$i, s($h),
72 array('others'=>array('0'=>'ignore', 'new'=>'new gradeitem'),
73 'gradeitems'=>$gradeitems,
ffe8ee55 74 'comments'=>$comments));
b4355273 75 $i++;
3f8bcf7c 76 }
85e287de 77 }
ffe8ee55 78
3f8bcf7c 79 // course id needs to be passed for auth purposes
80 $mform->addElement('hidden', 'map', 1);
eff9c473 81 $mform->setType('map', PARAM_INT);
8108909a 82 $mform->addElement('hidden', 'id');
eff9c473 83 $mform->setType('id', PARAM_INT);
8108909a 84 $mform->addElement('hidden', 'importcode');
85 $mform->setType('importcode', PARAM_FILE);
ba74762b 86 $this->add_action_buttons(false, get_string('uploadgrades', 'grades'));
ffe8ee55 87
85e287de 88 }
89}
7f999ccb 90?>