XMLDB: MDL-18980 add missing error message lang strings
[moodle.git] / grade / import / grade_import_form.php
CommitLineData
7f999ccb 1<?php // $Id$
8ad36f4c 2
3///////////////////////////////////////////////////////////////////////////
4// //
5// NOTICE OF COPYRIGHT //
6// //
7// Moodle - Modular Object-Oriented Dynamic Learning Environment //
8// http://moodle.com //
9// //
10// Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
11// //
12// This program is free software; you can redistribute it and/or modify //
13// it under the terms of the GNU General Public License as published by //
14// the Free Software Foundation; either version 2 of the License, or //
15// (at your option) any later version. //
16// //
17// This program is distributed in the hope that it will be useful, //
18// but WITHOUT ANY WARRANTY; without even the implied warranty of //
19// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
20// GNU General Public License for more details: //
21// //
22// http://www.gnu.org/copyleft/gpl.html //
23// //
24///////////////////////////////////////////////////////////////////////////
7f999ccb 25require_once $CFG->libdir.'/formslib.php';
8108909a 26require_once($CFG->libdir.'/gradelib.php');
7f999ccb 27
28class grade_import_form extends moodleform {
29 function definition (){
30 $mform =& $this->_form;
31
4d933beb
JN
32 if (isset($this->_customdata)) { // hardcoding plugin names here is hacky
33 $features = $this->_customdata;
34 } else {
35 $features = array();
36 }
37
7f999ccb 38 // course id needs to be passed for auth purposes
39 $mform->addElement('hidden', 'id', optional_param('id'));
eff9c473 40 $mform->setType('id', PARAM_INT);
f115f8c8 41 $mform->addElement('header', 'general', get_string('importfile', 'grades'));
7f999ccb 42 // file upload
43 $mform->addElement('file', 'userfile', get_string('file'));
eff9c473 44 $mform->setType('userfile', PARAM_FILE);
7f999ccb 45 $mform->addRule('userfile', null, 'required');
8e1ec6be 46 $textlib = textlib_get_instance();
4d40aa14 47 $encodings = $textlib->get_encodings();
f115f8c8 48 $mform->addElement('select', 'encoding', get_string('encoding', 'grades'), $encodings);
7f999ccb 49
4d933beb
JN
50 if (!empty($features['includeseparator'])) {
51 $radio = array();
52 $radio[] = &MoodleQuickForm::createElement('radio', 'separator', null, get_string('septab', 'grades'), 'tab');
53 $radio[] = &MoodleQuickForm::createElement('radio', 'separator', null, get_string('sepcomma', 'grades'), 'comma');
54 $mform->addGroup($radio, 'separator', get_string('separator', 'grades'), ' ', false);
55 $mform->setDefault('separator', 'comma');
56 }
57
58 if (!empty($features['verbosescales'])) {
59 $options = array(1=>get_string('yes'), 0=>get_string('no'));
60 $mform->addElement('select', 'verbosescales', get_string('verbosescales', 'grades'), $options);
61 }
62
ba74762b 63 $options = array('10'=>10, '20'=>20, '100'=>100, '1000'=>1000, '100000'=>100000);
8108909a 64 $mform->addElement('select', 'previewrows', get_string('rowpreviewnum', 'grades'), $options); // TODO: localize
eff9c473 65 $mform->setType('previewrows', PARAM_INT);
f115f8c8 66 $this->add_action_buttons(false, get_string('uploadgrades', 'grades'));
7f999ccb 67 }
7f999ccb 68}
85e287de 69
85e287de 70class grade_import_mapping_form extends moodleform {
ba74762b 71
85e287de 72 function definition () {
3f8bcf7c 73 global $CFG;
85e287de 74 $mform =& $this->_form;
75
3f8bcf7c 76 // this is an array of headers
77 $header = $this->_customdata['header'];
3f8bcf7c 78 // course id
85e287de 79
f115f8c8 80 $mform->addElement('header', 'general', get_string('identifier', 'grades'));
3f8bcf7c 81 $mapfromoptions = array();
ffe8ee55 82
3f8bcf7c 83 if ($header) {
b4355273 84 foreach ($header as $i=>$h) {
5c2aa198 85 $mapfromoptions[$i] = s($h);
3f8bcf7c 86 }
87 }
f115f8c8 88 $mform->addElement('select', 'mapfrom', get_string('mapfrom', 'grades'), $mapfromoptions);
ba74762b 89 //choose_from_menu($mapfromoptions, 'mapfrom');
90
3f8bcf7c 91 $maptooptions = array('userid'=>'userid', 'username'=>'username', 'useridnumber'=>'useridnumber', 'useremail'=>'useremail', '0'=>'ignore');
92 //choose_from_menu($maptooptions, 'mapto');
f115f8c8 93 $mform->addElement('select', 'mapto', get_string('mapto', 'grades'), $maptooptions);
ba74762b 94
f115f8c8 95 $mform->addElement('header', 'general', get_string('mappings', 'grades'));
ba74762b 96
ffe8ee55 97 // add a comment option
98
99 if ($gradeitems = $this->_customdata['gradeitems']) {
ba74762b 100 $comments = array();
ffe8ee55 101 foreach ($gradeitems as $itemid => $itemname) {
ba74762b 102 $comments['feedback_'.$itemid] = 'comments for '.$itemname;
103 }
ffe8ee55 104 }
b4355273 105
ba74762b 106 if ($header) {
b4355273 107 $i = 0; // index
3f8bcf7c 108 foreach ($header as $h) {
3f8bcf7c 109
ffe8ee55 110 $h = trim($h);
ba74762b 111 // this is what each header maps to
112 $mform->addElement('selectgroups',
113 'mapping_'.$i, s($h),
114 array('others'=>array('0'=>'ignore', 'new'=>'new gradeitem'),
115 'gradeitems'=>$gradeitems,
ffe8ee55 116 'comments'=>$comments));
b4355273 117 $i++;
3f8bcf7c 118 }
85e287de 119 }
ffe8ee55 120
3f8bcf7c 121 // course id needs to be passed for auth purposes
122 $mform->addElement('hidden', 'map', 1);
eff9c473 123 $mform->setType('map', PARAM_INT);
8108909a 124 $mform->addElement('hidden', 'id');
eff9c473 125 $mform->setType('id', PARAM_INT);
8108909a 126 $mform->addElement('hidden', 'importcode');
127 $mform->setType('importcode', PARAM_FILE);
4d933beb
JN
128 $mform->addElement('hidden', 'verbosescales', 1);
129 $mform->setType('separator', PARAM_ALPHA);
130 $mform->addElement('hidden', 'separator', 'comma');
131 $mform->setType('verbosescales', PARAM_INT);
ba74762b 132 $this->add_action_buttons(false, get_string('uploadgrades', 'grades'));
ffe8ee55 133
85e287de 134 }
135}
7f999ccb 136?>