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 if (!empty($CFG->gradepublishing
)) {
47 $CFG->gradepublishing
= has_capability('gradeimport/xml:publish', $context);
50 $mform = new grade_import_form();
52 if ($data = $mform->get_data()) {
53 // Large files are likely to take their time and memory. Let PHP know
54 // that we'll take longer, and that the process should be recycled soon
57 @raise_memory_limit
("256M");
58 if (function_exists('apache_child_terminate')) {
59 @apache_child_terminate
();
62 if ($text = $mform->get_file_content('userfile')) {
63 print_header($course->shortname
.': '.get_string('grades'), $course->fullname
, $navigation);
64 print_grade_plugin_selector($id, 'import', 'xml');
67 $importcode = import_xml_grades($text, $course, $error);
69 grade_import_commit($id, $importcode, $data->feedback
, true);
74 print_continue($CFG->wwwroot
.'/grade/index.php?id='.$course->id
);
79 } else if (empty($data->key
)) {
80 redirect('import.php?id='.$id.'&feedback='.(int)($data->feedback
).'&url='.urlencode($data->url
));
83 if ($data->key
== 1) {
84 $data->key
= create_user_key('grade/import', $USER->id
, $course->id
, $data->iprestriction
, $data->validuntil
);
87 print_header($course->shortname
.': '.get_string('grades'), $course->fullname
, $navigation);
88 print_grade_plugin_selector($id, 'import', 'xml');
90 echo '<div class="gradeexportlink">';
91 $link = $CFG->wwwroot
.'/grade/import/xml/fetch.php?id='.$id.'&feedback='.(int)($data->feedback
).'&url='.urlencode($data->url
).'&key='.$data->key
;
92 echo get_string('import', 'grades').': <a href="'.$link.'">'.$link.'</a>';
99 print_header($course->shortname
.': '.get_string('grades'), $course->fullname
, $navigation);
100 print_grade_plugin_selector($id, 'import', 'xml');