Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
/**
18
 * Configurable Reports
19
 * A Moodle block for creating Configurable Reports
20
 * @package blocks
21
 * @author: Juan leyva <http://www.twitter.com/jleyvadelgado>
22
 * @date: 2009
23
 */
24
 
25
require_once("../../config.php");
26
 
27
require_once($CFG->dirroot."/blocks/configurable_reports/locallib.php");
28
 
29
$id = required_param('id', PARAM_INT);
30
 
31
if (!$report = $DB->get_record('block_configurable_reports', array('id' => $id))) {
32
    print_error('reportdoesnotexists', 'block_configurable_reports');
33
}
34
 
35
 
36
if (!$course = $DB->get_record('course', array('id' => $report->courseid))) {
37
    print_error('nosuchcourseid', 'block_configurable_reports');
38
}
39
 
40
 
41
// Force user login in course (SITE or Course).
42
if ($course->id == SITEID) {
43
    require_login();
44
    $context = context_system::instance();
45
} else {
46
    require_login($course->id);
47
    $context = context_course::instance($course->id);
48
}
49
 
50
$PAGE->set_context($context);
51
 
52
if (!has_capability('block/configurable_reports:managereports', $context) && !(has_capability('block/configurable_reports:manageownreports', $context) && $report->ownerid == $USER->id)) {
53
    print_error('badpermissions', 'block_configurable_reports');
54
}
55
 
56
if (!confirm_sesskey()) {
57
    print_error('badpermissions', 'block_configurable_reports');
58
}
59
 
60
$downloadfilename = clean_filename(format_string($report->name)).'.xml';
61
 
62
$version = $DB->get_field('config_plugins', 'value', array('plugin' => 'block_configurable_reports', 'name' => 'version'));
63
if (!$version) {
64
    if (!$version = $DB->get_field('block', 'version', array('name' => 'configurable_reports'))) {
65
        print_error('Plugin not found');
66
    }
67
}
68
 
69
$data = '<?xml version="1.0" encoding="UTF-8" ?>'."\n";
70
$data .= "<report version=\"$version\">";
71
 
72
$reportdata = (array) $report;
73
unset($reportdata['id']);
74
unset($reportdata['courseid']);
75
unset($reportdata['ownerid']);
76
$reportdata['components'] = base64_encode($reportdata['components']);
77
 
78
foreach ($reportdata as $key => $value) {
79
    $data .= "<$key><![CDATA[$value]]></$key>\n";
80
}
81
 
82
$data .= "</report>";
83
 
84
if (strpos($CFG->wwwroot, 'https://') === 0) {
85
    // Https sites - watch out for IE! KB812935 and KB316431.
86
    @header('Cache-Control: max-age=10');
87
    @header('Expires: '. gmdate('D, d M Y H:i:s', 0) .' GMT');
88
    @header('Pragma: ');
89
} else {
90
    // Normal http - prevent caching at all cost.
91
    @header('Cache-Control: private, must-revalidate, pre-check=0, post-check=0, max-age=0');
92
    @header('Expires: '. gmdate('D, d M Y H:i:s', 0) .' GMT');
93
    @header('Pragma: no-cache');
94
}
95
header("Content-type: text/xml; charset=UTF-8");
96
header("Content-Disposition: attachment; filename=\"$downloadfilename\"");
97
 
98
print($data);