MDL-19404 Getting default values for grade_item object when creating a new grade_cate...
[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 (){
1dc9f2e2 30 global $COURSE;
31
7f999ccb 32 $mform =& $this->_form;
33
4d933beb
JN
34 if (isset($this->_customdata)) { // hardcoding plugin names here is hacky
35 $features = $this->_customdata;
36 } else {
37 $features = array();
38 }
39
7f999ccb 40 // course id needs to be passed for auth purposes
41 $mform->addElement('hidden', 'id', optional_param('id'));
eff9c473 42 $mform->setType('id', PARAM_INT);
f115f8c8 43 $mform->addElement('header', 'general', get_string('importfile', 'grades'));
7f999ccb 44 // file upload
45 $mform->addElement('file', 'userfile', get_string('file'));
eff9c473 46 $mform->setType('userfile', PARAM_FILE);
7f999ccb 47 $mform->addRule('userfile', null, 'required');
8e1ec6be 48 $textlib = textlib_get_instance();
4d40aa14 49 $encodings = $textlib->get_encodings();
f115f8c8 50 $mform->addElement('select', 'encoding', get_string('encoding', 'grades'), $encodings);
7f999ccb 51
4d933beb
JN
52 if (!empty($features['includeseparator'])) {
53 $radio = array();
54 $radio[] = &MoodleQuickForm::createElement('radio', 'separator', null, get_string('septab', 'grades'), 'tab');
55 $radio[] = &MoodleQuickForm::createElement('radio', 'separator', null, get_string('sepcomma', 'grades'), 'comma');
56 $mform->addGroup($radio, 'separator', get_string('separator', 'grades'), ' ', false);
57 $mform->setDefault('separator', 'comma');
58 }
59
60 if (!empty($features['verbosescales'])) {
61 $options = array(1=>get_string('yes'), 0=>get_string('no'));
62 $mform->addElement('select', 'verbosescales', get_string('verbosescales', 'grades'), $options);
63 }
64
ba74762b 65 $options = array('10'=>10, '20'=>20, '100'=>100, '1000'=>1000, '100000'=>100000);
8108909a 66 $mform->addElement('select', 'previewrows', get_string('rowpreviewnum', 'grades'), $options); // TODO: localize
eff9c473 67 $mform->setType('previewrows', PARAM_INT);
1dc9f2e2 68 $mform->addElement('hidden', 'groupid', groups_get_course_group($COURSE));
69 $mform->setType('groupid', PARAM_INT);
f115f8c8 70 $this->add_action_buttons(false, get_string('uploadgrades', 'grades'));
7f999ccb 71 }
7f999ccb 72}
85e287de 73
85e287de 74class grade_import_mapping_form extends moodleform {
ba74762b 75
85e287de 76 function definition () {
1dc9f2e2 77 global $CFG, $COURSE;
85e287de 78 $mform =& $this->_form;
79
3f8bcf7c 80 // this is an array of headers
81 $header = $this->_customdata['header'];
3f8bcf7c 82 // course id
85e287de 83
f115f8c8 84 $mform->addElement('header', 'general', get_string('identifier', 'grades'));
3f8bcf7c 85 $mapfromoptions = array();
ffe8ee55 86
3f8bcf7c 87 if ($header) {
b4355273 88 foreach ($header as $i=>$h) {
5c2aa198 89 $mapfromoptions[$i] = s($h);
3f8bcf7c 90 }
91 }
f115f8c8 92 $mform->addElement('select', 'mapfrom', get_string('mapfrom', 'grades'), $mapfromoptions);
ba74762b 93 //choose_from_menu($mapfromoptions, 'mapfrom');
94
3f8bcf7c 95 $maptooptions = array('userid'=>'userid', 'username'=>'username', 'useridnumber'=>'useridnumber', 'useremail'=>'useremail', '0'=>'ignore');
96 //choose_from_menu($maptooptions, 'mapto');
f115f8c8 97 $mform->addElement('select', 'mapto', get_string('mapto', 'grades'), $maptooptions);
ba74762b 98
f115f8c8 99 $mform->addElement('header', 'general', get_string('mappings', 'grades'));
ba74762b 100
ffe8ee55 101 // add a comment option
102
103 if ($gradeitems = $this->_customdata['gradeitems']) {
ba74762b 104 $comments = array();
ffe8ee55 105 foreach ($gradeitems as $itemid => $itemname) {
ba74762b 106 $comments['feedback_'.$itemid] = 'comments for '.$itemname;
107 }
ffe8ee55 108 }
b4355273 109
ba74762b 110 if ($header) {
b4355273 111 $i = 0; // index
3f8bcf7c 112 foreach ($header as $h) {
3f8bcf7c 113
ffe8ee55 114 $h = trim($h);
ba74762b 115 // this is what each header maps to
116 $mform->addElement('selectgroups',
117 'mapping_'.$i, s($h),
118 array('others'=>array('0'=>'ignore', 'new'=>'new gradeitem'),
119 'gradeitems'=>$gradeitems,
ffe8ee55 120 'comments'=>$comments));
b4355273 121 $i++;
3f8bcf7c 122 }
85e287de 123 }
ffe8ee55 124
3f8bcf7c 125 // course id needs to be passed for auth purposes
126 $mform->addElement('hidden', 'map', 1);
eff9c473 127 $mform->setType('map', PARAM_INT);
8108909a 128 $mform->addElement('hidden', 'id');
eff9c473 129 $mform->setType('id', PARAM_INT);
8108909a 130 $mform->addElement('hidden', 'importcode');
131 $mform->setType('importcode', PARAM_FILE);
4d933beb
JN
132 $mform->addElement('hidden', 'verbosescales', 1);
133 $mform->setType('separator', PARAM_ALPHA);
134 $mform->addElement('hidden', 'separator', 'comma');
135 $mform->setType('verbosescales', PARAM_INT);
1dc9f2e2 136 $mform->addElement('hidden', 'groupid', groups_get_course_group($COURSE));
137 $mform->setType('groupid', PARAM_INT);
ba74762b 138 $this->add_action_buttons(false, get_string('uploadgrades', 'grades'));
ffe8ee55 139
85e287de 140 }
141}
7f999ccb 142?>