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 $CFG->libdir
.'/filelib.php';
30 $url = required_param('url', PARAM_URL
); // only real urls here
31 $id = required_param('id', PARAM_INT
); // course id
32 $feedback = optional_param('feedback', 0, PARAM_BOOL
);
34 if (!$course = get_record('course', 'id', $id)) {
35 print_error('nocourseid');
38 require_login($course);
39 $context = get_context_instance(CONTEXT_COURSE
, $id);
41 require_capability('moodle/grade:import', $context);
42 require_capability('gradeimport/xml:view', $context);
45 // Large files are likely to take their time and memory. Let PHP know
46 // that we'll take longer, and that the process should be recycled soon
49 @raise_memory_limit
("256M");
50 if (function_exists('apache_child_terminate')) {
51 @apache_child_terminate
();
54 $text = download_file_content($url);
55 if ($text === false) {
56 error('Can not read file');
60 $importcode = import_xml_grades($text, $course, $error);
62 if ($importcode !== false) {
63 /// comit the code if we are up this far
65 if (defined('USER_KEY_LOGIN')) {
66 if (grade_import_commit($id, $importcode, $feedback, false)) {
70 error('Grade import error'); //TODO: localize
74 $strgrades = get_string('grades', 'grades');
75 $actionstr = get_string('xml', 'grades');
76 $navigation = grade_build_nav(__FILE__
, $actionstr, array('courseid' => $course->id
));
78 print_header($course->shortname
.': '.get_string('grades'), $course->fullname
, $navigation);
79 print_grade_plugin_selector($id, 'import', 'xml');
81 grade_import_commit($id, $importcode, $feedback, true);