Automatically generated installer lang files
[moodle.git] / grade / import / grade_import_form.php
CommitLineData
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
18if (!defined('MOODLE_INTERNAL')) {
19 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
20}
21
7f999ccb 22require_once $CFG->libdir.'/formslib.php';
8108909a 23require_once($CFG->libdir.'/gradelib.php');
7f999ccb 24
25class 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');
4d933beb
JN
51 $mform->addGroup($radio, 'separator', get_string('separator', 'grades'), ' ', false);
52 $mform->setDefault('separator', 'comma');
53 }
54
55 if (!empty($features['verbosescales'])) {
56 $options = array(1=>get_string('yes'), 0=>get_string('no'));
6c3ef410 57 $mform->addElement('select', 'verbosescales', get_string('verbosescales', 'grades'), $options);
4d933beb
JN
58 }
59
ba74762b 60 $options = array('10'=>10, '20'=>20, '100'=>100, '1000'=>1000, '100000'=>100000);
8108909a 61 $mform->addElement('select', 'previewrows', get_string('rowpreviewnum', 'grades'), $options); // TODO: localize
eff9c473 62 $mform->setType('previewrows', PARAM_INT);
1dc9f2e2 63 $mform->addElement('hidden', 'groupid', groups_get_course_group($COURSE));
64 $mform->setType('groupid', PARAM_INT);
f115f8c8 65 $this->add_action_buttons(false, get_string('uploadgrades', 'grades'));
7f999ccb 66 }
7f999ccb 67}
85e287de 68
85e287de 69class grade_import_mapping_form extends moodleform {
ba74762b 70
85e287de 71 function definition () {
1dc9f2e2 72 global $CFG, $COURSE;
85e287de 73 $mform =& $this->_form;
74
3f8bcf7c 75 // this is an array of headers
76 $header = $this->_customdata['header'];
3f8bcf7c 77 // course id
85e287de 78
f115f8c8 79 $mform->addElement('header', 'general', get_string('identifier', 'grades'));
3f8bcf7c 80 $mapfromoptions = array();
ffe8ee55 81
3f8bcf7c 82 if ($header) {
b4355273 83 foreach ($header as $i=>$h) {
5c2aa198 84 $mapfromoptions[$i] = s($h);
3f8bcf7c 85 }
86 }
f115f8c8 87 $mform->addElement('select', 'mapfrom', get_string('mapfrom', 'grades'), $mapfromoptions);
ba74762b 88
3f8bcf7c 89 $maptooptions = array('userid'=>'userid', 'username'=>'username', 'useridnumber'=>'useridnumber', 'useremail'=>'useremail', '0'=>'ignore');
f115f8c8 90 $mform->addElement('select', 'mapto', get_string('mapto', 'grades'), $maptooptions);
ba74762b 91
f115f8c8 92 $mform->addElement('header', 'general', get_string('mappings', 'grades'));
ba74762b 93
ffe8ee55 94 // add a comment option
95
a12f8571 96 $comments = array();
ffe8ee55 97 if ($gradeitems = $this->_customdata['gradeitems']) {
ffe8ee55 98 foreach ($gradeitems as $itemid => $itemname) {
ba74762b 99 $comments['feedback_'.$itemid] = 'comments for '.$itemname;
100 }
ffe8ee55 101 }
b4355273 102
ba74762b 103 if ($header) {
b4355273 104 $i = 0; // index
3f8bcf7c 105 foreach ($header as $h) {
ffe8ee55 106 $h = trim($h);
ba74762b 107 // this is what each header maps to
a12f8571
DC
108 $mform->addElement('selectgroups', 'mapping_'.$i, s($h),
109 array('others'=>array('0'=>'ignore', 'new'=>'new gradeitem'),
110 'gradeitems'=>$gradeitems,
111 'comments'=>$comments));
b4355273 112 $i++;
3f8bcf7c 113 }
85e287de 114 }
ffe8ee55 115
3f8bcf7c 116 // course id needs to be passed for auth purposes
117 $mform->addElement('hidden', 'map', 1);
eff9c473 118 $mform->setType('map', PARAM_INT);
8108909a 119 $mform->addElement('hidden', 'id');
eff9c473 120 $mform->setType('id', PARAM_INT);
8108909a 121 $mform->addElement('hidden', 'importcode');
122 $mform->setType('importcode', PARAM_FILE);
4d933beb
JN
123 $mform->addElement('hidden', 'verbosescales', 1);
124 $mform->setType('separator', PARAM_ALPHA);
125 $mform->addElement('hidden', 'separator', 'comma');
126 $mform->setType('verbosescales', PARAM_INT);
1dc9f2e2 127 $mform->addElement('hidden', 'groupid', groups_get_course_group($COURSE));
128 $mform->setType('groupid', PARAM_INT);
ba74762b 129 $this->add_action_buttons(false, get_string('uploadgrades', 'grades'));
ffe8ee55 130
85e287de 131 }
132}