Commit | Line | Data |
---|---|---|
e060e33d | 1 | <?php |
2 | ||
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. | |
14 | // | |
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/>. | |
8ad36f4c | 17 | |
bfebaf64 MD |
18 | if (!defined('MOODLE_INTERNAL')) { |
19 | die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page | |
20 | } | |
21 | ||
7f999ccb | 22 | require_once $CFG->libdir.'/formslib.php'; |
8108909a | 23 | require_once($CFG->libdir.'/gradelib.php'); |
7f999ccb | 24 | |
25 | class grade_import_form extends moodleform { | |
26 | function definition (){ | |
1dc9f2e2 | 27 | global $COURSE; |
28 | ||
7f999ccb | 29 | $mform =& $this->_form; |
30 | ||
4d933beb JN |
31 | if (isset($this->_customdata)) { // hardcoding plugin names here is hacky |
32 | $features = $this->_customdata; | |
33 | } else { | |
34 | $features = array(); | |
35 | } | |
36 | ||
7f999ccb | 37 | // course id needs to be passed for auth purposes |
622365d2 | 38 | $mform->addElement('hidden', 'id', optional_param('id', 0, PARAM_INT)); |
eff9c473 | 39 | $mform->setType('id', PARAM_INT); |
f115f8c8 | 40 | $mform->addElement('header', 'general', get_string('importfile', 'grades')); |
7f999ccb | 41 | // file upload |
a12f8571 | 42 | $mform->addElement('filepicker', 'userfile', get_string('file')); |
7f999ccb | 43 | $mform->addRule('userfile', null, 'required'); |
f8311def | 44 | $encodings = textlib::get_encodings(); |
f115f8c8 | 45 | $mform->addElement('select', 'encoding', get_string('encoding', 'grades'), $encodings); |
7f999ccb | 46 | |
4d933beb JN |
47 | if (!empty($features['includeseparator'])) { |
48 | $radio = array(); | |
f20edd52 PS |
49 | $radio[] = $mform->createElement('radio', 'separator', null, get_string('septab', 'grades'), 'tab'); |
50 | $radio[] = $mform->createElement('radio', 'separator', null, get_string('sepcomma', 'grades'), 'comma'); | |
bb2306eb AG |
51 | $radio[] = $mform->createElement('radio', 'separator', null, get_string('sepcolon', 'grades'), 'colon'); |
52 | $radio[] = $mform->createElement('radio', 'separator', null, get_string('sepsemicolon', 'grades'), 'semicolon'); | |
4d933beb JN |
53 | $mform->addGroup($radio, 'separator', get_string('separator', 'grades'), ' ', false); |
54 | $mform->setDefault('separator', 'comma'); | |
55 | } | |
56 | ||
57 | if (!empty($features['verbosescales'])) { | |
58 | $options = array(1=>get_string('yes'), 0=>get_string('no')); | |
6c3ef410 | 59 | $mform->addElement('select', 'verbosescales', get_string('verbosescales', 'grades'), $options); |
4d933beb JN |
60 | } |
61 | ||
ba74762b | 62 | $options = array('10'=>10, '20'=>20, '100'=>100, '1000'=>1000, '100000'=>100000); |
8108909a | 63 | $mform->addElement('select', 'previewrows', get_string('rowpreviewnum', 'grades'), $options); // TODO: localize |
eff9c473 | 64 | $mform->setType('previewrows', PARAM_INT); |
1dc9f2e2 | 65 | $mform->addElement('hidden', 'groupid', groups_get_course_group($COURSE)); |
66 | $mform->setType('groupid', PARAM_INT); | |
f115f8c8 | 67 | $this->add_action_buttons(false, get_string('uploadgrades', 'grades')); |
7f999ccb | 68 | } |
7f999ccb | 69 | } |
85e287de | 70 | |
85e287de | 71 | class grade_import_mapping_form extends moodleform { |
ba74762b | 72 | |
85e287de | 73 | function definition () { |
1dc9f2e2 | 74 | global $CFG, $COURSE; |
85e287de | 75 | $mform =& $this->_form; |
76 | ||
3f8bcf7c | 77 | // this is an array of headers |
78 | $header = $this->_customdata['header']; | |
3f8bcf7c | 79 | // course id |
85e287de | 80 | |
f115f8c8 | 81 | $mform->addElement('header', 'general', get_string('identifier', 'grades')); |
3f8bcf7c | 82 | $mapfromoptions = array(); |
ffe8ee55 | 83 | |
3f8bcf7c | 84 | if ($header) { |
b4355273 | 85 | foreach ($header as $i=>$h) { |
5c2aa198 | 86 | $mapfromoptions[$i] = s($h); |
3f8bcf7c | 87 | } |
88 | } | |
f115f8c8 | 89 | $mform->addElement('select', 'mapfrom', get_string('mapfrom', 'grades'), $mapfromoptions); |
ba74762b | 90 | |
3f8bcf7c | 91 | $maptooptions = array('userid'=>'userid', 'username'=>'username', 'useridnumber'=>'useridnumber', 'useremail'=>'useremail', '0'=>'ignore'); |
f115f8c8 | 92 | $mform->addElement('select', 'mapto', get_string('mapto', 'grades'), $maptooptions); |
ba74762b | 93 | |
f115f8c8 | 94 | $mform->addElement('header', 'general', get_string('mappings', 'grades')); |
ba74762b | 95 | |
ffe8ee55 | 96 | // add a comment option |
97 | ||
a12f8571 | 98 | $comments = array(); |
ffe8ee55 | 99 | if ($gradeitems = $this->_customdata['gradeitems']) { |
ffe8ee55 | 100 | foreach ($gradeitems as $itemid => $itemname) { |
ba74762b | 101 | $comments['feedback_'.$itemid] = 'comments for '.$itemname; |
102 | } | |
ffe8ee55 | 103 | } |
b4355273 | 104 | |
ba74762b | 105 | if ($header) { |
b4355273 | 106 | $i = 0; // index |
3f8bcf7c | 107 | foreach ($header as $h) { |
ffe8ee55 | 108 | $h = trim($h); |
ba74762b | 109 | // this is what each header maps to |
a12f8571 DC |
110 | $mform->addElement('selectgroups', 'mapping_'.$i, s($h), |
111 | array('others'=>array('0'=>'ignore', 'new'=>'new gradeitem'), | |
112 | 'gradeitems'=>$gradeitems, | |
113 | 'comments'=>$comments)); | |
b4355273 | 114 | $i++; |
3f8bcf7c | 115 | } |
85e287de | 116 | } |
ffe8ee55 | 117 | |
3f8bcf7c | 118 | // course id needs to be passed for auth purposes |
119 | $mform->addElement('hidden', 'map', 1); | |
eff9c473 | 120 | $mform->setType('map', PARAM_INT); |
8108909a | 121 | $mform->addElement('hidden', 'id'); |
eff9c473 | 122 | $mform->setType('id', PARAM_INT); |
9ea9d1d7 AG |
123 | $mform->addElement('hidden', 'iid'); |
124 | $mform->setType('iid', PARAM_INT); | |
8108909a | 125 | $mform->addElement('hidden', 'importcode'); |
126 | $mform->setType('importcode', PARAM_FILE); | |
4d933beb | 127 | $mform->addElement('hidden', 'verbosescales', 1); |
4d933beb | 128 | $mform->setType('verbosescales', PARAM_INT); |
1dc9f2e2 | 129 | $mform->addElement('hidden', 'groupid', groups_get_course_group($COURSE)); |
130 | $mform->setType('groupid', PARAM_INT); | |
ba74762b | 131 | $this->add_action_buttons(false, get_string('uploadgrades', 'grades')); |
ffe8ee55 | 132 | |
85e287de | 133 | } |
134 | } |