forked from vfremaux/moodle-mod_customlabel
/
view.php
64 lines (55 loc) · 2.21 KB
/
view.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
<?php // $Id: view.php,v 1.3 2011-07-07 14:01:23 vf Exp $
/**
* main view of a customlabel is always in its course container, unless
* we display its XML exportation.
*
* @package mod-customlabel
* @category mod
* @author Valery Fremaux <valery.fremaux@club-internet.fr>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com
*/
/**
* Includes and requires
*/
require_once("../../config.php");
require_once("{$CFG->dirroot}/mod/customlabel/lib.php");
$id = optional_param('id',0,PARAM_INT); // Course Module ID, or
$l = optional_param('l',0,PARAM_INT); // Label ID
$what = optional_param('what', '', PARAM_ALPHA); // What to be seen
if ($id) {
if (! $cm = get_coursemodule_from_id('customlabel', $id)) {
error("Course Module ID was incorrect");
}
if (! $course = $DB->get_record('course', array('id' => $cm->course))) {
error("Course is misconfigured");
}
if (! $customlabel = $DB->get_record('customlabel', array('id' => $cm->instance))) {
error("Course module is incorrect");
}
} else {
if (! $customlabel = $DB->get_record('customlabel', array('id' => $l))) {
error("Course module is incorrect");
}
if (! $course = $DB->get_record('course', array('id' => $customlabel->course))) {
error("Course is misconfigured");
}
if (! $cm = get_coursemodule_from_instance("customlabel", $customlabel->id, $course->id)) {
error("Course Module ID was incorrect");
}
}
require_login($course->id);
/// if we are exporting to XML
if ($what == 'xml'){
echo $OUTPUT->header();
$customlabel = $DB->get_record('customlabel', array('id' => $l));
$instance = customlabel_load_class($customlabel);
$xml = $instance->get_xml();
$xml = str_replace('<', '<', $xml);
$xml = str_replace('>', '>', $xml);
echo "<pre>".$xml."</pre>";
die;
}
/// normal view "in-situ"
redirect($CFG->wwwroot."/course/view.php?id={$course->id}");
?>