MDL-24751 fixed default memory limit when deciding to use apache_child_terminate...
[moodle.git] / grade / import / xml / index.php
CommitLineData
e060e33d 1<?php
ce34ed3a 2
e060e33d 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.
14//
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/>.
e77bcaa3 17
a12f8571
DC
18require_once('../../../config.php');
19require_once('lib.php');
20require_once('grade_import_form.php');
ce34ed3a 21
ce34ed3a 22$id = required_param('id', PARAM_INT); // course id
ce34ed3a 23
4d5059d4
SH
24$PAGE->set_url(new moodle_url('/grade/import/xml/index.php', array('id'=>$id)));
25$PAGE->set_pagelayout('admin');
beebcf26 26
f400841b 27if (!$course = $DB->get_record('course', array('id'=>$id))) {
e77bcaa3 28 print_error('nocourseid');
29}
30
31require_login($course);
32$context = get_context_instance(CONTEXT_COURSE, $id);
33require_capability('moodle/grade:import', $context);
34require_capability('gradeimport/xml:view', $context);
ce34ed3a 35
ffe8ee55 36// print header
b263e539 37$strgrades = get_string('grades', 'grades');
b5e7b2bf 38$actionstr = get_string('pluginname', 'gradeimport_xml');
826c5f86 39
0a3bdfaf 40if (!empty($CFG->gradepublishing)) {
41 $CFG->gradepublishing = has_capability('gradeimport/xml:publish', $context);
42}
43
ce34ed3a 44$mform = new grade_import_form();
45
294ce987 46if ($data = $mform->get_data()) {
ce34ed3a 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);
1843999a 51 @raise_memory_limit("256M");
ce34ed3a 52
1843999a 53 if ($text = $mform->get_file_content('userfile')) {
dc482cfa 54 print_grade_page_head($COURSE->id, 'import', 'xml', get_string('importxml', 'grades'));
741bde47 55
1843999a 56 $error = '';
57 $importcode = import_xml_grades($text, $course, $error);
58 if ($importcode) {
34058207 59 grade_import_commit($id, $importcode, $data->feedback, true);
5a931394 60 echo $OUTPUT->footer();
1843999a 61 die;
62 } else {
c3b834b4 63 echo $OUTPUT->notification($error);
64 echo $OUTPUT->continue_button($CFG->wwwroot.'/grade/index.php?id='.$course->id);
5a931394 65 echo $OUTPUT->footer();
1843999a 66 die;
ba74762b 67 }
1843999a 68
69 } else if (empty($data->key)) {
34058207 70 redirect('import.php?id='.$id.'&amp;feedback='.(int)($data->feedback).'&url='.urlencode($data->url));
1843999a 71
741bde47 72 } else {
1843999a 73 if ($data->key == 1) {
74 $data->key = create_user_key('grade/import', $USER->id, $course->id, $data->iprestriction, $data->validuntil);
75 }
76
dc482cfa 77 print_grade_page_head($COURSE->id, 'import', 'xml', get_string('importxml', 'grades'));
1843999a 78
79 echo '<div class="gradeexportlink">';
34058207 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;
1843999a 81 echo get_string('import', 'grades').': <a href="'.$link.'">'.$link.'</a>';
82 echo '</div>';
5a931394 83 echo $OUTPUT->footer();
1843999a 84 die;
ce34ed3a 85 }
ce34ed3a 86}
741bde47 87
dc482cfa 88print_grade_page_head($COURSE->id, 'import', 'xml', get_string('importxml', 'grades'));
1843999a 89
90$mform->display();
91
5a931394 92echo $OUTPUT->footer();
1843999a 93
6c3ef410 94