|
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 00032 class view_structure_xml extends XMLDBAction { 00033 00037 function init() { 00038 parent::init(); 00039 00040 // Set own custom attributes 00041 $this->sesskey_protected = false; // This action doesn't need sesskey protection 00042 00043 // Get needed strings 00044 $this->loadStrings(array( 00045 // 'key' => 'module', 00046 )); 00047 } 00048 00054 function invoke() { 00055 parent::invoke(); 00056 00057 $result = true; 00058 00059 // Set own core attributes 00060 $this->does_generate = ACTION_GENERATE_XML; 00061 00062 // These are always here 00063 global $CFG, $XMLDB; 00064 00065 // Do the job, setting result as needed 00066 00067 // Get the file parameter 00068 $select = required_param('select', PARAM_ALPHA); //original/edited 00069 // Get the dir containing the file 00070 $dirpath = required_param('dir', PARAM_PATH); 00071 $dirpath = $CFG->dirroot . $dirpath; 00072 00073 // Get the correct dir 00074 if ($select == 'original') { 00075 if (!empty($XMLDB->dbdirs)) { 00076 $base =& $XMLDB->dbdirs[$dirpath]; 00077 } 00078 } else if ($select == 'edited') { 00079 if (!empty($XMLDB->editeddirs)) { 00080 $base =& $XMLDB->editeddirs[$dirpath]; 00081 } 00082 } else { 00083 $this->errormsg = 'Cannot access to ' . $select . ' info'; 00084 $result = false; 00085 } 00086 if ($base) { 00087 // Only if the directory exists and it has been loaded 00088 if (!$base->path_exists || !$base->xml_loaded) { 00089 $this->errormsg = 'Directory ' . $dirpath . ' not loaded'; 00090 return false; 00091 } 00092 } else { 00093 $this->errormsg = 'Problem handling ' . $select . ' files'; 00094 return false; 00095 } 00096 00097 // Get the structure 00098 if ($result) { 00099 if (!$structure =& $base->xml_file->getStructure()) { 00100 $this->errormsg = 'Error retrieving ' . $select . ' structure'; 00101 $result = false; 00102 } 00103 } 00104 00105 if ($result) { 00106 // Everything is ok. Generate the XML output 00107 $this->output = $structure->xmlOutput(); 00108 } else { 00109 // Switch to HTML and error 00110 $this->does_generate = ACTION_GENERATE_HTML; 00111 } 00112 00113 // Return ok if arrived here 00114 return $result; 00115 } 00116 } 00117