|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 // This file is part of Moodle - http://moodle.org/ 00003 // 00004 // Moodle is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // Moodle is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00016 00028 require('../../../config.php'); 00029 require_once($CFG->libdir.'/adminlib.php'); 00030 require_once($CFG->libdir.'/ddllib.php'); 00031 // Add required XMLDB action classes 00032 require_once('actions/XMLDBAction.class.php'); 00033 require_once('actions/XMLDBCheckAction.class.php'); 00034 00035 00036 admin_externalpage_setup('toolxmld'); 00037 00038 // Add other used libraries 00039 require_once($CFG->libdir . '/xmlize.php'); 00040 00041 // Handle session data 00042 global $XMLDB; 00043 00044 // State is stored in session - we have to serialise it because the classes are not loaded when creating session 00045 if (!isset($SESSION->xmldb)) { 00046 $XMLDB = new stdClass; 00047 } else { 00048 $XMLDB = unserialize($SESSION->xmldb); 00049 } 00050 00051 // Some previous checks 00052 $site = get_site(); 00053 00054 require_login(); 00055 require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)); 00056 00057 // Body of the script, based on action, we delegate the work 00058 $action = optional_param ('action', 'main_view', PARAM_ALPHAEXT); 00059 00060 // Get the action path and invoke it 00061 $actionsroot = "$CFG->dirroot/$CFG->admin/tool/xmldb/actions"; 00062 $actionclass = $action . '.class.php'; 00063 $actionpath = "$actionsroot/$action/$actionclass"; 00064 00065 // Load and invoke the proper action 00066 if (file_exists($actionpath) && is_readable($actionpath)) { 00067 require_once($actionpath); 00068 if ($xmldb_action = new $action) { 00069 // Invoke it 00070 $result = $xmldb_action->invoke(); 00071 // store the result in session 00072 $SESSION->xmldb = serialize($XMLDB); 00073 00074 if ($result) { 00075 // Based on getDoesGenerate() 00076 switch ($xmldb_action->getDoesGenerate()) { 00077 case ACTION_GENERATE_HTML: 00078 00079 $action = optional_param('action', '', PARAM_ALPHAEXT); 00080 $postaction = optional_param('postaction', '', PARAM_ALPHAEXT); 00081 // If the js exists, load it 00082 if ($action) { 00083 $script = $CFG->admin . '/tool/xmldb/actions/' . $action . '/' . $action . '.js'; 00084 $file = $CFG->dirroot . '/' . $script; 00085 if (file_exists($file) && is_readable($file)) { 00086 $PAGE->requires->js('/'.$script); 00087 } else if ($postaction) { 00088 // Try to load the postaction javascript if exists 00089 $script = $CFG->admin . '/tool/xmldb/actions/' . $postaction . '/' . $postaction . '.js'; 00090 $file = $CFG->dirroot . '/' . $script; 00091 if (file_exists($file) && is_readable($file)) { 00092 $PAGE->requires->js('/'.$script); 00093 } 00094 } 00095 } 00096 00097 // Go with standard admin header 00098 echo $OUTPUT->header(); 00099 echo $OUTPUT->heading($xmldb_action->getTitle()); 00100 echo $xmldb_action->getOutput(); 00101 echo $OUTPUT->footer(); 00102 break; 00103 case ACTION_GENERATE_XML: 00104 header('Content-type: application/xhtml+xml; charset=utf-8'); 00105 echo $xmldb_action->getOutput(); 00106 break; 00107 } 00108 } else { 00109 // TODO: need more detailed error info 00110 print_error('xmldberror'); 00111 } 00112 } else { 00113 $a = new stdClass(); 00114 $a->action = $action; 00115 $a->actionclass = $actionclass; 00116 print_error('cannotinstantiateclass', 'tool_xmldb', '', $a); 00117 } 00118 } else { 00119 print_error('invalidaction'); 00120 } 00121 00122 if ($xmldb_action->getDoesGenerate() != ACTION_GENERATE_XML) { 00123 if (debugging()) { 00124 // print_object($XMLDB); 00125 } 00126 }