Repository navigation
Expand file tree
/
Copy pathxmlview.php
More file actions
118 lines (101 loc) · 3.72 KB
/
Copy pathxmlview.php
File metadata and controls
118 lines (101 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* A document generator, using XML -> XSLT transform to HTML
*
* @package mod-techproject
* @category mod
* @author Valery Fremaux (France) (admin@www.ethnoinformatique.fr)
* @date 2008/03/03
* @version phase1
* @contributors LUU Tao Meng, So Gerard (parts of treelib.php), Guillaume Magnien, Olivier Petit
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*/
require('../../config.php');
require_once($CFG->dirroot.'/mod/techproject/lib.php');
require_once($CFG->dirroot.'/mod/techproject/locallib.php');
// Fixes locale for all date printing.
setlocale(LC_TIME, substr(current_language(), 0, 2));
// Get context information.
$id = required_param('id', PARAM_INT); // Module id.
$view = optional_param('view', '', PARAM_CLEAN); // Viewed page id.
$accesskey = optional_param('accesskey', '', PARAM_TEXT);
$timenow = time();
// Get some useful stuff.
if (! $cm = $DB->get_record('course_modules', array('id' => $id))) {
print_error('invalidcoursemodule');
}
if (! $course = $DB->get_record('course', array('id' => $cm->course))) {
print_error('coursemisconf');
}
if (! $project = $DB->get_record('techproject', array('id' => $cm->instance))) {
print_error('invalidtechprojectid', 'techproject');
}
// Security.
// Allow anonymized access (document reading) with access key.
if (empty($project->accesskey) || $accesskey != $project->accesskey) {
require_login($course->id, false, $cm);
} else {
$COURSE = $course;
}
$context = context_module::instance($cm->id);
// Check current group and change, for anyone who could.
if (!$groupmode = groups_get_activity_groupmode($cm)) {
// Are groups are being used ?
$currentgroupid = 0;
} else {
$changegroup = isset($_GET['group']) ? $_GET['group'] : -1;
// Group change requested ?
if (isguestuser()) {
// For guests, use session.
if ($changegroup >= 0) {
$_SESSION['guestgroup'] = $changegroup;
}
$currentgroupid = 0 + @$_SESSION['guestgroup'];
} else {
// For normal users, change current group.
$currentgroupid = 0 + groups_get_course_group($course, true);
if (!groups_is_member($currentgroupid , $USER->id) && !is_siteadmin()) {
$USER->editmode = "off";
}
}
}
// Get all information about the current project.
$xml = techproject_get_full_xml($project, $currentgroupid);
// Invoke XSLT transformation for making the output document.
$xsl = new XSLTProcessor();
$doc = new DOMDocument();
$xslsheet = techproject_get_internal_file($project, 'xsl');
$doc->load($xslsheet);
$xsl->importStyleSheet($doc);
$doc->loadXML($xml);
if (is_object($doc)) {
$html = $xsl->transformToXML($doc);
} else {
$formattedxml = htmlentities($xml, ENT_QUOTES, 'UTF-8');
$formattedxmllines = explode("\n", $formattedxml);
$html = 'XML Generation Error';
$html .= '<hr/><pre>';
$i = 1;
foreach ($formattedxmllines as $line) {
$html .= $i . " " . $line."\n";
$i++;
}
$html .= "</pre><hr/>";
}
// Deliver the document.
header("Content-Type:text/html\n\n");
echo $html;