MDL-22388 Added some checks to kill these scripts dead with an unequivocal notice...
[moodle.git] / grade / import / grade_import_form.php
blob3d74664b2f3ffa39483b5d3656bc4cc0f1205154
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'));
39 $mform->setType('id', PARAM_INT);
40 $mform->addElement('header', 'general', get_string('importfile', 'grades'));
41 // file upload
42 $mform->addElement('file', 'userfile', get_string('file'));
43 $mform->setType('userfile', PARAM_FILE);
44 $mform->addRule('userfile', null, 'required');
45 $textlib = textlib_get_instance();
46 $encodings = $textlib->get_encodings();
47 $mform->addElement('select', 'encoding', get_string('encoding', 'grades'), $encodings);
49 if (!empty($features['includeseparator'])) {
50 $radio = array();
51 $radio[] = &MoodleQuickForm::createElement('radio', 'separator', null, get_string('septab', 'grades'), 'tab');
52 $radio[] = &MoodleQuickForm::createElement('radio', 'separator', null, get_string('sepcomma', 'grades'), 'comma');
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);
90 //choose_from_menu($mapfromoptions, 'mapfrom');
92 $maptooptions = array('userid'=>'userid', 'username'=>'username', 'useridnumber'=>'useridnumber', 'useremail'=>'useremail', '0'=>'ignore');
93 //choose_from_menu($maptooptions, 'mapto');
94 $mform->addElement('select', 'mapto', get_string('mapto', 'grades'), $maptooptions);
96 $mform->addElement('header', 'general', get_string('mappings', 'grades'));
98 // add a comment option
100 if ($gradeitems = $this->_customdata['gradeitems']) {
101 $comments = array();
102 foreach ($gradeitems as $itemid => $itemname) {
103 $comments['feedback_'.$itemid] = 'comments for '.$itemname;
107 if ($header) {
108 $i = 0; // index
109 foreach ($header as $h) {
111 $h = trim($h);
112 // this is what each header maps to
113 $mform->addElement('selectgroups',
114 'mapping_'.$i, s($h),
115 array('others'=>array('0'=>'ignore', 'new'=>'new gradeitem'),
116 'gradeitems'=>$gradeitems,
117 'comments'=>$comments));
118 $i++;
122 // course id needs to be passed for auth purposes
123 $mform->addElement('hidden', 'map', 1);
124 $mform->setType('map', PARAM_INT);
125 $mform->addElement('hidden', 'id');
126 $mform->setType('id', PARAM_INT);
127 $mform->addElement('hidden', 'importcode');
128 $mform->setType('importcode', PARAM_FILE);
129 $mform->addElement('hidden', 'verbosescales', 1);
130 $mform->setType('separator', PARAM_ALPHA);
131 $mform->addElement('hidden', 'separator', 'comma');
132 $mform->setType('verbosescales', PARAM_INT);
133 $mform->addElement('hidden', 'groupid', groups_get_course_group($COURSE));
134 $mform->setType('groupid', PARAM_INT);
135 $this->add_action_buttons(false, get_string('uploadgrades', 'grades'));