3 // This file is part of Moodle - http://moodle.org/
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.
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 (){
29 $mform =& $this->_form
;
31 if (isset($this->_customdata
)) { // hardcoding plugin names here is hacky
32 $features = $this->_customdata
;
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'));
42 // Restrict the possible upload file types.
43 if (!empty($features['acceptedtypes'])) {
44 $acceptedtypes = $features['acceptedtypes'];
50 $mform->addElement('filepicker', 'userfile', get_string('file'), null, array('accepted_types' => $acceptedtypes));
51 $mform->addRule('userfile', null, 'required');
52 $encodings = core_text
::get_encodings();
53 $mform->addElement('select', 'encoding', get_string('encoding', 'grades'), $encodings);
55 if (!empty($features['includeseparator'])) {
57 $radio[] = $mform->createElement('radio', 'separator', null, get_string('septab', 'grades'), 'tab');
58 $radio[] = $mform->createElement('radio', 'separator', null, get_string('sepcomma', 'grades'), 'comma');
59 $radio[] = $mform->createElement('radio', 'separator', null, get_string('sepcolon', 'grades'), 'colon');
60 $radio[] = $mform->createElement('radio', 'separator', null, get_string('sepsemicolon', 'grades'), 'semicolon');
61 $mform->addGroup($radio, 'separator', get_string('separator', 'grades'), ' ', false);
62 $mform->setDefault('separator', 'comma');
65 if (!empty($features['verbosescales'])) {
66 $options = array(1=>get_string('yes'), 0=>get_string('no'));
67 $mform->addElement('select', 'verbosescales', get_string('verbosescales', 'grades'), $options);
70 $options = array('10'=>10, '20'=>20, '100'=>100, '1000'=>1000, '100000'=>100000);
71 $mform->addElement('select', 'previewrows', get_string('rowpreviewnum', 'grades'), $options); // TODO: localize
72 $mform->setType('previewrows', PARAM_INT
);
73 $mform->addElement('hidden', 'groupid', groups_get_course_group($COURSE));
74 $mform->setType('groupid', PARAM_INT
);
75 $this->add_action_buttons(false, get_string('uploadgrades', 'grades'));
79 class grade_import_mapping_form
extends moodleform
{
81 function definition () {
83 $mform =& $this->_form
;
85 // this is an array of headers
86 $header = $this->_customdata
['header'];
89 $mform->addElement('header', 'general', get_string('identifier', 'grades'));
90 $mapfromoptions = array();
93 foreach ($header as $i=>$h) {
94 $mapfromoptions[$i] = s($h);
97 $mform->addElement('select', 'mapfrom', get_string('mapfrom', 'grades'), $mapfromoptions);
99 $maptooptions = array(
100 'userid' => get_string('userid', 'grades'),
101 'username' => get_string('username'),
102 'useridnumber' => get_string('idnumber'),
103 'useremail' => get_string('email'),
104 '0' => get_string('ignore', 'grades')
106 $mform->addElement('select', 'mapto', get_string('mapto', 'grades'), $maptooptions);
108 $mform->addElement('header', 'general', get_string('mappings', 'grades'));
110 // Add a feedback option.
111 $feedbacks = array();
112 if ($gradeitems = $this->_customdata
['gradeitems']) {
113 foreach ($gradeitems as $itemid => $itemname) {
114 $feedbacks['feedback_'.$itemid] = get_string('feedbackforgradeitems', 'grades', $itemname);
120 foreach ($header as $h) {
122 // This is what each header maps to.
123 $headermapsto = array(
124 get_string('others', 'grades') => array(
125 '0' => get_string('ignore', 'grades'),
126 'new' => get_string('newitem', 'grades')
128 get_string('gradeitems', 'grades') => $gradeitems,
129 get_string('feedbacks', 'grades') => $feedbacks
131 $mform->addElement('selectgroups', 'mapping_'.$i, s($h), $headermapsto);
136 // course id needs to be passed for auth purposes
137 $mform->addElement('hidden', 'map', 1);
138 $mform->setType('map', PARAM_INT
);
139 $mform->addElement('hidden', 'id');
140 $mform->setType('id', PARAM_INT
);
141 $mform->addElement('hidden', 'iid');
142 $mform->setType('iid', PARAM_INT
);
143 $mform->addElement('hidden', 'importcode');
144 $mform->setType('importcode', PARAM_FILE
);
145 $mform->addElement('hidden', 'verbosescales', 1);
146 $mform->setType('verbosescales', PARAM_INT
);
147 $mform->addElement('hidden', 'groupid', groups_get_course_group($COURSE));
148 $mform->setType('groupid', PARAM_INT
);
149 $this->add_action_buttons(false, get_string('uploadgrades', 'grades'));