3 ///////////////////////////////////////////////////////////////////////////
5 // NOTICE OF COPYRIGHT //
7 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
8 // http://moodle.com //
10 // Copyright (C) 2001-3001 Martin Dougiamas http://dougiamas.com //
11 // (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com //
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. //
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: //
23 // http://www.gnu.org/copyleft/gpl.html //
25 ///////////////////////////////////////////////////////////////////////////
27 /// This is the main script for the complete XMLDB interface. From here
28 /// all the actions supported will be launched.
30 /// Add required XMLDB constants
31 require_once('../../lib/xmldb/classes/XMLDBConstants.php');
33 /// Add required XMLDB action classes
34 require_once('actions/XMLDBAction.class.php');
36 /// Add main XMLDB Generator
37 require_once('../../lib/xmldb/classes/generators/XMLDBGenerator.class.php');
39 /// Add required XMLDB DB classes
40 require_once('../../lib/xmldb/classes/XMLDBObject.class.php');
41 require_once('../../lib/xmldb/classes/XMLDBFile.class.php');
42 require_once('../../lib/xmldb/classes/XMLDBStructure.class.php');
43 require_once('../../lib/xmldb/classes/XMLDBTable.class.php');
44 require_once('../../lib/xmldb/classes/XMLDBField.class.php');
45 require_once('../../lib/xmldb/classes/XMLDBKey.class.php');
46 require_once('../../lib/xmldb/classes/XMLDBIndex.class.php');
47 require_once('../../lib/xmldb/classes/XMLDBStatement.class.php');
49 /// Add Moodle config script (this is loaded AFTER all the rest
50 /// of classes because it starts the SESSION and classes to be
51 /// stored there MUST be declared before in order to avoid
52 /// getting "incomplete" objects
53 require_once('../../config.php');
54 require_once($CFG->libdir
.'/adminlib.php');
55 require_once($CFG->libdir
.'/ddllib.php'); // Install/upgrade related db functions
57 admin_externalpage_setup('xmldbeditor');
59 /// Add other used libraries
60 require_once($CFG->libdir
. '/xmlize.php');
62 /// Add all the available SQL generators
63 $generators = get_list_of_plugins('lib/xmldb/classes/generators');
64 foreach($generators as $generator) {
65 require_once ('../../lib/xmldb/classes/generators/' . $generator . '/' . $generator . '.class.php');
68 /// Handle session data
70 /// The global SESSION object where everything will happen
71 if (!isset($SESSION->xmldb
)) {
72 $SESSION->xmldb
= new stdClass
;
74 $XMLDB =& $SESSION->xmldb
;
76 /// Some previous checks
77 if (! $site = get_site()) {
78 redirect("$CFG->wwwroot/$CFG->admin/index.php");
82 require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM
, SITEID
));
84 /// Body of the script, based on action, we delegate the work
85 $action = optional_param ('action', 'main_view', PARAM_ALPHAEXT
);
87 /// Get the action path and invoke it
88 $actionsroot = "$CFG->dirroot/$CFG->admin/xmldb/actions";
89 $actionclass = $action . '.class.php';
90 $actionpath = "$actionsroot/$action/$actionclass";
92 /// Load and invoke the proper action
93 if (file_exists($actionpath) && is_readable($actionpath)) {
94 require_once($actionpath);
95 if ($xmldb_action = new $action) {
97 $result = $xmldb_action->invoke();
99 /// Based on getDoesGenerate()
100 switch ($xmldb_action->getDoesGenerate()) {
101 case ACTION_GENERATE_HTML
:
102 /// Define $CFG->javascript to use our custom javascripts.
103 /// Save the original one to add it from ours. Global too! :-(
104 global $standard_javascript;
105 $standard_javascript = $CFG->javascript
; // Save original javascript file
106 $CFG->javascript
= $CFG->dirroot
.'/'.$CFG->admin
.'/xmldb/javascript.php'; //Use our custom javascript code
107 /// Go with standard admin header
108 admin_externalpage_print_header();
109 print_heading($xmldb_action->getTitle());
110 echo $xmldb_action->getOutput();
111 admin_externalpage_print_footer();
113 case ACTION_GENERATE_XML
:
114 header('Content-type: application/xhtml+xml');
115 echo $xmldb_action->getOutput();
119 error($xmldb_action->getError());
122 error ("Error: cannot instantiate class (actions/$action/$actionclass)");
125 error ("Error: wrong action specified ($action)");
128 if ($xmldb_action->getDoesGenerate() != ACTION_GENERATE_XML
) {
130 ///print_object($XMLDB);