MDL-25407 ignore errors in CLI mysql engine conversion script
[moodle.git] / grade / import / xml / index.php
blob5ce766b43319202dba703294e09d04d43367ff56
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 require_once('../../../config.php');
19 require_once('lib.php');
20 require_once('grade_import_form.php');
22 $id = required_param('id', PARAM_INT); // course id
24 $PAGE->set_url(new moodle_url('/grade/import/xml/index.php', array('id'=>$id)));
25 $PAGE->set_pagelayout('admin');
27 if (!$course = $DB->get_record('course', array('id'=>$id))) {
28 print_error('nocourseid');
31 require_login($course);
32 $context = get_context_instance(CONTEXT_COURSE, $id);
33 require_capability('moodle/grade:import', $context);
34 require_capability('gradeimport/xml:view', $context);
36 // print header
37 $strgrades = get_string('grades', 'grades');
38 $actionstr = get_string('pluginname', 'gradeimport_xml');
40 if (!empty($CFG->gradepublishing)) {
41 $CFG->gradepublishing = has_capability('gradeimport/xml:publish', $context);
44 $mform = new grade_import_form();
46 if ($data = $mform->get_data()) {
47 // Large files are likely to take their time and memory. Let PHP know
48 // that we'll take longer, and that the process should be recycled soon
49 // to free up memory.
50 @set_time_limit(0);
51 raise_memory_limit(MEMORY_EXTRA);
53 if ($text = $mform->get_file_content('userfile')) {
54 print_grade_page_head($COURSE->id, 'import', 'xml', get_string('importxml', 'grades'));
56 $error = '';
57 $importcode = import_xml_grades($text, $course, $error);
58 if ($importcode) {
59 grade_import_commit($id, $importcode, $data->feedback, true);
60 echo $OUTPUT->footer();
61 die;
62 } else {
63 echo $OUTPUT->notification($error);
64 echo $OUTPUT->continue_button($CFG->wwwroot.'/grade/index.php?id='.$course->id);
65 echo $OUTPUT->footer();
66 die;
69 } else if (empty($data->key)) {
70 redirect('import.php?id='.$id.'&amp;feedback='.(int)($data->feedback).'&url='.urlencode($data->url));
72 } else {
73 if ($data->key == 1) {
74 $data->key = create_user_key('grade/import', $USER->id, $course->id, $data->iprestriction, $data->validuntil);
77 print_grade_page_head($COURSE->id, 'import', 'xml', get_string('importxml', 'grades'));
79 echo '<div class="gradeexportlink">';
80 $link = $CFG->wwwroot.'/grade/import/xml/fetch.php?id='.$id.'&amp;feedback='.(int)($data->feedback).'&amp;url='.urlencode($data->url).'&amp;key='.$data->key;
81 echo get_string('import', 'grades').': <a href="'.$link.'">'.$link.'</a>';
82 echo '</div>';
83 echo $OUTPUT->footer();
84 die;
88 print_grade_page_head($COURSE->id, 'import', 'xml', get_string('importxml', 'grades'));
90 $mform->display();
92 echo $OUTPUT->footer();