MDL-39298 - gradebook: Added more delimiters for uploading and downloading the gradeb...
[moodle.git] / grade / import / grade_import_form.php
blob9f86e483e3b3fd5d1ee18eeab59cb9792dc418ad
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 if (!defined('MOODLE_INTERNAL')) {
19 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
22 require_once $CFG->libdir.'/formslib.php';
23 require_once($CFG->libdir.'/gradelib.php');
25 class grade_import_form extends moodleform {
26 function definition (){
27 global $COURSE;
29 $mform =& $this->_form;
31 if (isset($this->_customdata)) { // hardcoding plugin names here is hacky
32 $features = $this->_customdata;
33 } else {
34 $features = array();
37 // course id needs to be passed for auth purposes
38 $mform->addElement('hidden', 'id', optional_param('id', 0, PARAM_INT));
39 $mform->setType('id', PARAM_INT);
40 $mform->addElement('header', 'general', get_string('importfile', 'grades'));
41 // file upload
42 $mform->addElement('filepicker', 'userfile', get_string('file'));
43 $mform->addRule('userfile', null, 'required');
44 $encodings = textlib::get_encodings();
45 $mform->addElement('select', 'encoding', get_string('encoding', 'grades'), $encodings);
47 if (!empty($features['includeseparator'])) {
48 $radio = array();
49 $radio[] = $mform->createElement('radio', 'separator', null, get_string('septab', 'grades'), 'tab');
50 $radio[] = $mform->createElement('radio', 'separator', null, get_string('sepcomma', 'grades'), 'comma');
51 $radio[] = $mform->createElement('radio', 'separator', null, get_string('sepcolon', 'grades'), 'colon');
52 $radio[] = $mform->createElement('radio', 'separator', null, get_string('sepsemicolon', 'grades'), 'semicolon');
53 $mform->addGroup($radio, 'separator', get_string('separator', 'grades'), ' ', false);
54 $mform->setDefault('separator', 'comma');
57 if (!empty($features['verbosescales'])) {
58 $options = array(1=>get_string('yes'), 0=>get_string('no'));
59 $mform->addElement('select', 'verbosescales', get_string('verbosescales', 'grades'), $options);
62 $options = array('10'=>10, '20'=>20, '100'=>100, '1000'=>1000, '100000'=>100000);
63 $mform->addElement('select', 'previewrows', get_string('rowpreviewnum', 'grades'), $options); // TODO: localize
64 $mform->setType('previewrows', PARAM_INT);
65 $mform->addElement('hidden', 'groupid', groups_get_course_group($COURSE));
66 $mform->setType('groupid', PARAM_INT);
67 $this->add_action_buttons(false, get_string('uploadgrades', 'grades'));
71 class grade_import_mapping_form extends moodleform {
73 function definition () {
74 global $CFG, $COURSE;
75 $mform =& $this->_form;
77 // this is an array of headers
78 $header = $this->_customdata['header'];
79 // course id
81 $mform->addElement('header', 'general', get_string('identifier', 'grades'));
82 $mapfromoptions = array();
84 if ($header) {
85 foreach ($header as $i=>$h) {
86 $mapfromoptions[$i] = s($h);
89 $mform->addElement('select', 'mapfrom', get_string('mapfrom', 'grades'), $mapfromoptions);
91 $maptooptions = array('userid'=>'userid', 'username'=>'username', 'useridnumber'=>'useridnumber', 'useremail'=>'useremail', '0'=>'ignore');
92 $mform->addElement('select', 'mapto', get_string('mapto', 'grades'), $maptooptions);
94 $mform->addElement('header', 'general', get_string('mappings', 'grades'));
96 // add a comment option
98 $comments = array();
99 if ($gradeitems = $this->_customdata['gradeitems']) {
100 foreach ($gradeitems as $itemid => $itemname) {
101 $comments['feedback_'.$itemid] = 'comments for '.$itemname;
105 if ($header) {
106 $i = 0; // index
107 foreach ($header as $h) {
108 $h = trim($h);
109 // this is what each header maps to
110 $mform->addElement('selectgroups', 'mapping_'.$i, s($h),
111 array('others'=>array('0'=>'ignore', 'new'=>'new gradeitem'),
112 'gradeitems'=>$gradeitems,
113 'comments'=>$comments));
114 $i++;
118 // course id needs to be passed for auth purposes
119 $mform->addElement('hidden', 'map', 1);
120 $mform->setType('map', PARAM_INT);
121 $mform->addElement('hidden', 'id');
122 $mform->setType('id', PARAM_INT);
123 $mform->addElement('hidden', 'iid');
124 $mform->setType('iid', PARAM_INT);
125 $mform->addElement('hidden', 'importcode');
126 $mform->setType('importcode', PARAM_FILE);
127 $mform->addElement('hidden', 'verbosescales', 1);
128 $mform->setType('verbosescales', PARAM_INT);
129 $mform->addElement('hidden', 'groupid', groups_get_course_group($COURSE));
130 $mform->setType('groupid', PARAM_INT);
131 $this->add_action_buttons(false, get_string('uploadgrades', 'grades'));