Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
 
18
require_once '../../../config.php';
19
require_once 'lib.php';
20
require_once $CFG->libdir.'/filelib.php';
21
 
22
$gradesurl = required_param('url', PARAM_URL); // only real urls here
23
$id        = required_param('id', PARAM_INT); // course id
24
$feedback  = optional_param('feedback', 0, PARAM_BOOL);
25
 
26
$url = new moodle_url('/grade/import/xml/import.php', array('id' => $id,'url' => $gradesurl));
27
if ($feedback !== 0) {
28
    $url->param('feedback', $feedback);
29
}
30
$PAGE->set_url($url);
31
 
32
if (!$course = $DB->get_record('course', array('id'=>$id))) {
33
    throw new \moodle_exception('invalidcourseid');
34
}
35
 
36
require_login($course);
37
$context = context_course::instance($id);
38
 
39
require_capability('moodle/grade:import', $context);
40
require_capability('gradeimport/xml:view', $context);
41
 
42
 
43
// Large files are likely to take their time and memory. Let PHP know
44
// that we'll take longer, and that the process should be recycled soon
45
// to free up memory.
46
core_php_time_limit::raise();
47
raise_memory_limit(MEMORY_EXTRA);
48
 
49
$text = download_file_content($gradesurl);
50
if ($text === false) {
51
    throw new \moodle_exception('cannotreadfile', 'error',
52
            $CFG->wwwroot . '/grade/import/xml/index.php?id=' . $id, $gradesurl);
53
}
54
 
55
$error = '';
56
$importcode = import_xml_grades($text, $course, $error);
57
 
58
if ($importcode !== false) {
59
    /// commit the code if we are up this far
60
 
61
    if (defined('USER_KEY_LOGIN')) {
62
        if (grade_import_commit($id, $importcode, $feedback, false)) {
63
            echo 'ok';
64
            die;
65
        } else {
66
            throw new \moodle_exception('cannotimportgrade'); // TODO: localize.
67
        }
68
 
69
    } else {
70
        print_grade_page_head($course->id, 'import', 'xml', get_string('importxml', 'grades'));
71
 
72
        grade_import_commit($id, $importcode, $feedback, true);
73
 
74
        echo $OUTPUT->footer();
75
        die;
76
    }
77
 
78
} else {
79
    throw new \moodle_exception('errorduringimport', 'gradeimport_xml',
80
            $CFG->wwwroot . '/grade/import/xml/index.php?id=' . $id, $error);
81
}