-
Notifications
You must be signed in to change notification settings - Fork 0
/
xmlview.php
105 lines (95 loc) · 3.44 KB
/
xmlview.php
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
<?php
/**
*
* A document generator, using XML -> XSLT transform to HTML
*
*
* @package mod-project
* @category mod
* @author Yann Ducruy (yann[dot]ducruy[at]gmail[dot]com). Contact me if needed
* @date 12/06/2015
* @version 3.2
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*
*/
/**
* Requires and includes
*/
require_once('../../config.php');
require_once($CFG->dirroot.'/mod/project/lib.php');
require_once($CFG->dirroot.'/mod/project/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
$timenow = time();
// get some useful stuff...
if (! $cm = $DB->get_record('course_modules', array("id" => $id))) {
error('Course Module ID was incorrect');
}
if (! $course = $DB->get_record('course', array('id' => $cm->course))) {
error('Course is misconfigured');
}
if (! $project = $DB->get_record('project', array('id' => $cm->instance))) {
error('Course module is incorrect');
}
require_login($course->id, false, $cm);
$context = context_module::instance($cm->id);
/// check current group and change, for anyone who could
if (!$groupmode = groupmode($course, $cm)){ // 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 = project_get_full_xml($project, $currentGroupId);
/// invoke XSLT transformation for making the output document
if (phpversion() >= 5.0){
$xsl = new XSLTProcessor();
$doc = new DOMDocument();
$xsl_sheet = $project->xslfilter;
$doc->load($xsl_sheet);
$xsl->importStyleSheet($doc);
$doc = DOMDocument::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/>";
}
} else {
/*
$arguments = array(
'/_xml' => $xml,
);
$procesor = xslt_create();
if ($html = xslt_process($processor, "arg:/_xml", $project->xslfilter, null, $arguments)){
}
else{
$html = xslt_error($processor);
}
*/
echo $OUTPUT->notification("Php 4 implementation of XSL processing code has not been experimented.");
}
/// deliver the document
header("Content-Type:text/html\n\n");
echo $html;
?>