source: moodle/trunk/fuentes/grade/import/xml/index.php @ 1331

Last change on this file since 1331 was 1331, checked in by jrpelegrina, 3 years ago

Updated to moodle 3.0.3

File size: 3.5 KB
Line 
1<?php
2
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/>.
17
18require_once('../../../config.php');
19require_once('lib.php');
20require_once('grade_import_form.php');
21
22$id = required_param('id', PARAM_INT); // course id
23
24$PAGE->set_url(new moodle_url('/grade/import/xml/index.php', array('id'=>$id)));
25$PAGE->set_pagelayout('admin');
26
27if (!$course = $DB->get_record('course', array('id'=>$id))) {
28    print_error('nocourseid');
29}
30
31require_login($course);
32$context = context_course::instance($id);
33require_capability('moodle/grade:import', $context);
34require_capability('gradeimport/xml:view', $context);
35
36// print header
37$strgrades = get_string('grades', 'grades');
38$actionstr = get_string('pluginname', 'gradeimport_xml');
39
40if (!empty($CFG->gradepublishing)) {
41    $CFG->gradepublishing = has_capability('gradeimport/xml:publish', $context);
42}
43
44$mform = new grade_import_form(null, array('acceptedtypes' => array('.xml')));
45
46if ($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    core_php_time_limit::raise();
51    raise_memory_limit(MEMORY_EXTRA);
52
53    if ($text = $mform->get_file_content('userfile')) {
54        print_grade_page_head($COURSE->id, 'import', 'xml',
55                              get_string('importxml', 'grades'), false, false, true, 'importxml', 'gradeimport_xml');
56
57        $error = '';
58        $importcode = import_xml_grades($text, $course, $error);
59        if ($importcode) {
60            grade_import_commit($id, $importcode, $data->feedback, true);
61            echo $OUTPUT->footer();
62            die;
63        } else {
64            echo $OUTPUT->notification($error);
65            echo $OUTPUT->continue_button($CFG->wwwroot.'/grade/index.php?id='.$course->id);
66            echo $OUTPUT->footer();
67            die;
68        }
69
70    } else if (empty($data->key)) {
71        redirect('import.php?id='.$id.'&amp;feedback='.(int)($data->feedback).'&url='.urlencode($data->url));
72
73    } else {
74        if ($data->key == 1) {
75            $data->key = create_user_key('grade/import', $USER->id, $course->id, $data->iprestriction, $data->validuntil);
76        }
77
78        print_grade_page_head($COURSE->id, 'import', 'xml',
79                              get_string('importxml', 'grades'), false, false, true, 'importxml', 'gradeimport_xml');
80
81        echo '<div class="gradeexportlink">';
82        $link = $CFG->wwwroot.'/grade/import/xml/fetch.php?id='.$id.'&amp;feedback='.(int)($data->feedback).'&amp;url='.urlencode($data->url).'&amp;key='.$data->key;
83        echo get_string('import', 'grades').': <a href="'.$link.'">'.$link.'</a>';
84        echo '</div>';
85        echo $OUTPUT->footer();
86        die;
87    }
88}
89
90print_grade_page_head($COURSE->id, 'import', 'xml',
91                      get_string('importxml', 'grades'), false, false, true, 'importxml', 'gradeimport_xml');
92
93$mform->display();
94
95echo $OUTPUT->footer();
Note: See TracBrowser for help on using the repository browser.