cvsimport fixups
[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
32 // course id needs to be passed for auth purposes
33 $mform->addElement('hidden', 'id', optional_param('id'));
eff9c473 34 $mform->setType('id', PARAM_INT);
f115f8c8 35 $mform->addElement('header', 'general', get_string('importfile', 'grades'));
7f999ccb 36 // file upload
37 $mform->addElement('file', 'userfile', get_string('file'));
eff9c473 38 $mform->setType('userfile', PARAM_FILE);
7f999ccb 39 $mform->addRule('userfile', null, 'required');
8e1ec6be 40 $textlib = textlib_get_instance();
4d40aa14 41 $encodings = $textlib->get_encodings();
f115f8c8 42 $mform->addElement('select', 'encoding', get_string('encoding', 'grades'), $encodings);
7f999ccb 43
ba74762b 44 $options = array('10'=>10, '20'=>20, '100'=>100, '1000'=>1000, '100000'=>100000);
8108909a 45 $mform->addElement('select', 'previewrows', get_string('rowpreviewnum', 'grades'), $options); // TODO: localize
eff9c473 46 $mform->setType('previewrows', PARAM_INT);
f115f8c8 47 $this->add_action_buttons(false, get_string('uploadgrades', 'grades'));
7f999ccb 48 }
7f999ccb 49}
85e287de 50
85e287de 51class grade_import_mapping_form extends moodleform {
ba74762b 52
85e287de 53 function definition () {
3f8bcf7c 54 global $CFG;
85e287de 55 $mform =& $this->_form;
56
3f8bcf7c 57 // this is an array of headers
58 $header = $this->_customdata['header'];
3f8bcf7c 59 // course id
85e287de 60
f115f8c8 61 $mform->addElement('header', 'general', get_string('identifier', 'grades'));
3f8bcf7c 62 $mapfromoptions = array();
ffe8ee55 63
3f8bcf7c 64 if ($header) {
b4355273 65 foreach ($header as $i=>$h) {
5c2aa198 66 $mapfromoptions[$i] = s($h);
3f8bcf7c 67 }
68 }
f115f8c8 69 $mform->addElement('select', 'mapfrom', get_string('mapfrom', 'grades'), $mapfromoptions);
ba74762b 70 //choose_from_menu($mapfromoptions, 'mapfrom');
71
3f8bcf7c 72 $maptooptions = array('userid'=>'userid', 'username'=>'username', 'useridnumber'=>'useridnumber', 'useremail'=>'useremail', '0'=>'ignore');
73 //choose_from_menu($maptooptions, 'mapto');
f115f8c8 74 $mform->addElement('select', 'mapto', get_string('mapto', 'grades'), $maptooptions);
ba74762b 75
f115f8c8 76 $mform->addElement('header', 'general', get_string('mappings', 'grades'));
ba74762b 77
ffe8ee55 78 // add a comment option
79
80 if ($gradeitems = $this->_customdata['gradeitems']) {
ba74762b 81 $comments = array();
ffe8ee55 82 foreach ($gradeitems as $itemid => $itemname) {
ba74762b 83 $comments['feedback_'.$itemid] = 'comments for '.$itemname;
84 }
ffe8ee55 85 }
b4355273 86
ba74762b 87 if ($header) {
b4355273 88 $i = 0; // index
3f8bcf7c 89 foreach ($header as $h) {
3f8bcf7c 90
ffe8ee55 91 $h = trim($h);
ba74762b 92 // this is what each header maps to
93 $mform->addElement('selectgroups',
94 'mapping_'.$i, s($h),
95 array('others'=>array('0'=>'ignore', 'new'=>'new gradeitem'),
96 'gradeitems'=>$gradeitems,
ffe8ee55 97 'comments'=>$comments));
b4355273 98 $i++;
3f8bcf7c 99 }
85e287de 100 }
ffe8ee55 101
3f8bcf7c 102 // course id needs to be passed for auth purposes
103 $mform->addElement('hidden', 'map', 1);
eff9c473 104 $mform->setType('map', PARAM_INT);
8108909a 105 $mform->addElement('hidden', 'id');
eff9c473 106 $mform->setType('id', PARAM_INT);
8108909a 107 $mform->addElement('hidden', 'importcode');
108 $mform->setType('importcode', PARAM_FILE);
ba74762b 109 $this->add_action_buttons(false, get_string('uploadgrades', 'grades'));
ffe8ee55 110
85e287de 111 }
112}
7f999ccb 113?>