MDL-29029 move dbtransfer to admin tools
[moodle.git] / admin / xmldb / actions / view_xml / view_xml.class.php
CommitLineData
0df0df23 1<?php
8c15ae99 2
f25d53a9
EL
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/>.
8c15ae99 17
f25d53a9
EL
18/**
19 * @package xmldb-editor
20 * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22 */
8c15ae99 23
f25d53a9
EL
24/**
25 * This class will display one XML file
26 *
27 * @package xmldb-editor
28 * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
29 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30 */
8c15ae99 31class view_xml extends XMLDBAction {
32
eef868d1 33 /**
8c15ae99 34 * Init method, every subclass will have its own
35 */
36 function init() {
37 parent::init();
38 /// Set own core attributes
39 $this->can_subaction = ACTION_NONE;
40 //$this->can_subaction = ACTION_HAVE_SUBACTIONS;
41
42 /// Set own custom attributes
f25d53a9 43 $this->sesskey_protected = false; // This action doesn't need sesskey protection
8c15ae99 44
45 /// Get needed strings
46 $this->loadStrings(array(
47 /// 'key' => 'module',
48 ));
49 }
50
51 /**
52 * Invoke method, every class will have its own
53 * returns true/false on completion, setting both
54 * errormsg and output as necessary
55 */
56 function invoke() {
57 parent::invoke();
58
59 $result = true;
60
61 /// Set own core attributes
62 $this->does_generate = ACTION_GENERATE_XML;
63
64 /// These are always here
65 global $CFG, $XMLDB;
66
67 /// Do the job, setting result as needed
68
69 /// Get the file parameter
115a7365 70 $file = required_param('file', PARAM_PATH);
294ce987 71 $file = $CFG->dirroot . $file;
eef868d1 72 /// File must be under $CFG->wwwroot and
8c15ae99 73 /// under one db directory (simple protection)
74 if (substr($file, 0, strlen($CFG->dirroot)) == $CFG->dirroot &&
75 substr(dirname($file), -2, 2) == 'db') {
76 /// Everything is ok. Load the file to memory
77 $this->output = file_get_contents($file);
78 } else {
79 /// Switch to HTML and error
80 $this->does_generate = ACTION_GENERATE_HTML;
81 $this->errormsg = 'File not viewable (' . $file .')';
82 $result = false;
83 }
84
85 /// Return ok if arrived here
86 return $result;
87 }
88}
0df0df23 89