3 ///////////////////////////////////////////////////////////////////////////
5 // NOTICE OF COPYRIGHT //
7 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
8 // http://moodle.com //
10 // Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
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. //
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: //
22 // http://www.gnu.org/copyleft/gpl.html //
24 ///////////////////////////////////////////////////////////////////////////
26 require_once '../../../config.php';
27 require_once 'lib.php';
28 require_once 'grade_import_form.php';
30 $id = required_param('id', PARAM_INT
); // course id
32 if (!$course = get_record('course', 'id', $id)) {
33 print_error('nocourseid');
36 require_login($course);
37 $context = get_context_instance(CONTEXT_COURSE
, $id);
38 require_capability('moodle/grade:import', $context);
39 require_capability('gradeimport/xml:view', $context);
42 $strgrades = get_string('grades', 'grades');
43 $actionstr = get_string('modulename', 'gradeimport_xml');
44 $navigation = grade_build_nav(__FILE__
, $actionstr, array('courseid' => $course->id
));
46 $mform = new grade_import_form();
48 if ($data = $mform->get_data()) {
49 // Large files are likely to take their time and memory. Let PHP know
50 // that we'll take longer, and that the process should be recycled soon
53 @raise_memory_limit
("256M");
54 if (function_exists('apache_child_terminate')) {
55 @apache_child_terminate
();
58 if ($text = $mform->get_file_content('userfile')) {
59 print_header($course->shortname
.': '.get_string('grades'), $course->fullname
, $navigation);
60 print_grade_plugin_selector($id, 'import', 'xml');
63 $importcode = import_xml_grades($text, $course, $error);
65 grade_import_commit($id, $importcode);
70 print_continue($CFG->wwwroot
.'/grade/index.php?id='.$course->id
);
75 } else if (empty($data->key
)) {
76 redirect('import.php?id='.$id.'&url='.urlencode($data->url
));
79 if ($data->key
== 1) {
80 $data->key
= create_user_key('grade/import', $USER->id
, $course->id
, $data->iprestriction
, $data->validuntil
);
83 print_header($course->shortname
.': '.get_string('grades'), $course->fullname
, $navigation);
84 print_grade_plugin_selector($id, 'import', 'xml');
86 echo '<div class="gradeexportlink">';
87 $link = $CFG->wwwroot
.'/grade/import/xml/fetch.php?id='.$id.'&url='.urlencode($data->url
).'&key='.$data->key
;
88 echo get_string('import', 'grades').': <a href="'.$link.'">'.$link.'</a>';
95 print_header($course->shortname
.': '.get_string('grades'), $course->fullname
, $navigation);
96 print_grade_plugin_selector($id, 'import', 'xml');