MDL-25973 add missing charset
[moodle.git] / admin / xmldb / index.php
CommitLineData
0df0df23 1<?php
8c15ae99 2
3///////////////////////////////////////////////////////////////////////////
4// //
5// NOTICE OF COPYRIGHT //
6// //
7// Moodle - Modular Object-Oriented Dynamic Learning Environment //
8// http://moodle.com //
9// //
46293bd7 10// Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
8c15ae99 11// (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com //
12// //
13// This program is free software; you can redistribute it and/or modify //
14// it under the terms of the GNU General Public License as published by //
15// the Free Software Foundation; either version 2 of the License, or //
16// (at your option) any later version. //
17// //
18// This program is distributed in the hope that it will be useful, //
19// but WITHOUT ANY WARRANTY; without even the implied warranty of //
20// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
21// GNU General Public License for more details: //
22// //
23// http://www.gnu.org/copyleft/gpl.html //
24// //
25///////////////////////////////////////////////////////////////////////////
26
27/// This is the main script for the complete XMLDB interface. From here
28/// all the actions supported will be launched.
29
c05ede98 30 require_once('../../config.php');
31 require_once($CFG->libdir.'/adminlib.php');
32 require_once($CFG->libdir.'/ddllib.php');
8c15ae99 33/// Add required XMLDB action classes
34 require_once('actions/XMLDBAction.class.php');
9f5e5dee 35 require_once('actions/XMLDBCheckAction.class.php');
8c15ae99 36
1ae083e4 37
38 admin_externalpage_setup('xmldbeditor');
8c15ae99 39
40/// Add other used libraries
41 require_once($CFG->libdir . '/xmlize.php');
42
8c15ae99 43/// Handle session data
44 global $XMLDB;
c05ede98 45
46/// State is stored in session - we have to serialise it because the classes are not loaded when creating session
8c15ae99 47 if (!isset($SESSION->xmldb)) {
c05ede98 48 $XMLDB = new stdClass;
49 } else {
50 $XMLDB = unserialize($SESSION->xmldb);
8c15ae99 51 }
8c15ae99 52
53/// Some previous checks
2a250a0b 54 $site = get_site();
8c15ae99 55
56 require_login();
957f6fc9 57 require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
8c15ae99 58
8c15ae99 59/// Body of the script, based on action, we delegate the work
eef868d1 60 $action = optional_param ('action', 'main_view', PARAM_ALPHAEXT);
8c15ae99 61
62/// Get the action path and invoke it
63 $actionsroot = "$CFG->dirroot/$CFG->admin/xmldb/actions";
64 $actionclass = $action . '.class.php';
65 $actionpath = "$actionsroot/$action/$actionclass";
66
67/// Load and invoke the proper action
68 if (file_exists($actionpath) && is_readable($actionpath)) {
69 require_once($actionpath);
70 if ($xmldb_action = new $action) {
71 //Invoke it
72 $result = $xmldb_action->invoke();
c05ede98 73 // store the result in session
74 $SESSION->xmldb = serialize($XMLDB);
75
8c15ae99 76 if ($result) {
77 /// Based on getDoesGenerate()
78 switch ($xmldb_action->getDoesGenerate()) {
79 case ACTION_GENERATE_HTML:
e11a8328 80
81 $action = optional_param('action', '', PARAM_ALPHAEXT);
82 $postaction = optional_param('postaction', '', PARAM_ALPHAEXT);
83 /// If the js exists, load it
84 if ($action) {
85 $script = $CFG->admin . '/xmldb/actions/' . $action . '/' . $action . '.js';
86 $file = $CFG->dirroot . '/' . $script;
87 if (file_exists($file) && is_readable($file)) {
9dec75db 88 $PAGE->requires->js('/'.$script);
e11a8328 89 } else if ($postaction) {
90 /// Try to load the postaction javascript if exists
91 $script = $CFG->admin . '/xmldb/actions/' . $postaction . '/' . $postaction . '.js';
92 $file = $CFG->dirroot . '/' . $script;
93 if (file_exists($file) && is_readable($file)) {
9dec75db 94 $PAGE->requires->js('/'.$script);
e11a8328 95 }
96 }
97 }
98
fa323030 99 /// Go with standard admin header
61ef8f9f 100 echo $OUTPUT->header();
2fff8846 101 echo $OUTPUT->heading($xmldb_action->getTitle());
8c15ae99 102 echo $xmldb_action->getOutput();
73d6f52f 103 echo $OUTPUT->footer();
8c15ae99 104 break;
105 case ACTION_GENERATE_XML:
8a7703ce 106 header('Content-type: application/xhtml+xml; charset=utf-8');
8c15ae99 107 echo $xmldb_action->getOutput();
108 break;
109 }
110 } else {
bcc45748 111 //TODO: need more detailed error info
112 print_error('xmldberror');
8c15ae99 113 }
114 } else {
6bdfef5d 115 $a = new stdClass();
771dc7b2 116 $a->action = $action;
117 $a->actionclass = $actionclass;
118 print_error('cannotinstantiateclass', 'xmldb', '', $a);
8c15ae99 119 }
120 } else {
771dc7b2 121 print_error('invalidaction');
8c15ae99 122 }
123
eef868d1 124 if ($xmldb_action->getDoesGenerate() != ACTION_GENERATE_XML) {
a229726a 125 if (debugging()) {
8c15ae99 126 ///print_object($XMLDB);
127 }
128 }