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($CFG->libdir . '/gradelib.php');
20
require_once($CFG->dirroot . '/grade/lib.php');
21
require_once($CFG->dirroot . '/grade/import/xml/lib.php');
22
require_once($CFG->dirroot . '/grade/import/xml/grade_import_form.php');
23
 
24
$id = required_param('id', PARAM_INT); // course id
25
 
26
$PAGE->set_url(new moodle_url('/grade/import/xml/index.php', array('id'=>$id)));
27
$PAGE->set_pagelayout('admin');
28
 
29
if (!$course = $DB->get_record('course', array('id'=>$id))) {
30
    throw new \moodle_exception('invalidcourseid');
31
}
32
 
33
require_login($course);
34
$context = context_course::instance($id);
35
require_capability('moodle/grade:import', $context);
36
require_capability('gradeimport/xml:view', $context);
37
 
38
// print header
39
$strgrades = get_string('grades', 'grades');
40
$actionstr = get_string('pluginname', 'gradeimport_xml');
41
 
42
if (!empty($CFG->gradepublishing)) {
43
    $CFG->gradepublishing = has_capability('gradeimport/xml:publish', $context);
44
}
45
 
46
$mform = new grade_import_form(null, array('acceptedtypes' => array('.xml')));
47
 
48
if ($data = $mform->get_data()) {
49
    // Large files are likely to take their time and memory. Let PHP know
50
    // that we'll take longer, and that the process should be recycled soon
51
    // to free up memory.
52
    core_php_time_limit::raise();
53
    raise_memory_limit(MEMORY_EXTRA);
54
 
55
    if ($text = $mform->get_file_content('userfile')) {
56
        print_grade_page_head($COURSE->id, 'import', 'xml',
57
                              get_string('importxml', 'grades'), false, false, true, 'importxml', 'gradeimport_xml');
58
 
59
        $error = '';
60
        $importcode = import_xml_grades($text, $course, $error);
61
        if ($importcode) {
62
            grade_import_commit($id, $importcode, $data->feedback, true);
63
            echo $OUTPUT->footer();
64
            die;
65
        } else {
66
            echo $OUTPUT->notification($error);
67
            echo $OUTPUT->continue_button($CFG->wwwroot.'/grade/index.php?id='.$course->id);
68
            echo $OUTPUT->footer();
69
            die;
70
        }
71
 
72
    } else if (empty($data->key)) {
73
        redirect('import.php?id='.$id.'&amp;feedback='.(int)($data->feedback).'&url='.urlencode($data->url));
74
 
75
    } else {
76
        if ($data->key == 1) {
77
            $data->key = create_user_key('grade/import', $USER->id, $course->id, $data->iprestriction, $data->validuntil);
78
        }
79
 
80
        print_grade_page_head($COURSE->id, 'import', 'xml',
81
                              get_string('importxml', 'grades'), false, false, true, 'importxml', 'gradeimport_xml');
82
 
83
        echo '<div class="gradeexportlink">';
84
        $link = $CFG->wwwroot.'/grade/import/xml/fetch.php?id='.$id.'&amp;feedback='.(int)($data->feedback).'&amp;url='.urlencode($data->url).'&amp;key='.$data->key;
85
        echo get_string('import', 'grades').': <a href="'.$link.'">'.$link.'</a>';
86
        echo '</div>';
87
        echo $OUTPUT->footer();
88
        die;
89
    }
90
}
91
 
92
$actionbar = new \core_grades\output\import_action_bar($context, null, 'xml');
93
print_grade_page_head($COURSE->id, 'import', 'xml', get_string('importxml', 'grades'),
94
    false, false, true, 'importxml', 'gradeimport_xml', null, $actionbar);
95
 
96
$mform->display();
97
 
98
echo $OUTPUT->footer();