Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / grade / import / xml / index.php
blob2124bf97ca125f0b9e25cffc3aa258004d7ce869
1 <?php //$Id$
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 ///////////////////////////////////////////////////////////////////////////
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);
41 // print header
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
55 // to free up memory.
56 @set_time_limit(0);
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');
66 $error = '';
67 $importcode = import_xml_grades($text, $course, $error);
68 if ($importcode) {
69 grade_import_commit($id, $importcode, $data->feedback, true);
70 print_footer();
71 die;
72 } else {
73 notify($error);
74 print_continue($CFG->wwwroot.'/grade/index.php?id='.$course->id);
75 print_footer();
76 die;
79 } else if (empty($data->key)) {
80 redirect('import.php?id='.$id.'&amp;feedback='.(int)($data->feedback).'&url='.urlencode($data->url));
82 } else {
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.'&amp;feedback='.(int)($data->feedback).'&amp;url='.urlencode($data->url).'&amp;key='.$data->key;
92 echo get_string('import', 'grades').': <a href="'.$link.'">'.$link.'</a>';
93 echo '</div>';
94 print_footer();
95 die;
99 print_header($course->shortname.': '.get_string('grades'), $course->fullname, $navigation);
100 print_grade_plugin_selector($id, 'import', 'xml');
102 $mform->display();
104 print_footer();