Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/admin/tool/xmldb/actions/view_table_xml/view_table_xml.class.php
Go to the documentation of this file.
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_table_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         $table =  required_param('table', PARAM_CLEAN);
00069         $select = required_param('select', PARAM_ALPHA); //original/edited
00070         // Get the dir containing the file
00071         $dirpath = required_param('dir', PARAM_PATH);
00072         $dirpath = $CFG->dirroot . $dirpath;
00073 
00074         // Get the correct dir
00075         if ($select == 'original') {
00076             if (!empty($XMLDB->dbdirs)) {
00077                 $base =& $XMLDB->dbdirs[$dirpath];
00078             }
00079         } else if ($select == 'edited') {
00080             if (!empty($XMLDB->editeddirs)) {
00081                 $base =& $XMLDB->editeddirs[$dirpath];
00082             }
00083         } else {
00084             $this->errormsg = 'Cannot access to ' . $select . ' info';
00085             $result = false;
00086         }
00087         if ($base) {
00088             // Only if the directory exists and it has been loaded
00089             if (!$base->path_exists || !$base->xml_loaded) {
00090                 $this->errormsg = 'Directory ' . $dirpath . ' not loaded';
00091                 return false;
00092             }
00093         } else {
00094             $this->errormsg = 'Problem handling ' . $select . ' files';
00095             return false;
00096         }
00097 
00098         // Get the structure
00099         if ($result) {
00100             if (!$structure =& $base->xml_file->getStructure()) {
00101                 $this->errormsg = 'Error retrieving ' . $select . ' structure';
00102                 $result = false;
00103             }
00104         }
00105         // Get the tables
00106         if ($result) {
00107             if (!$tables =& $structure->getTables()) {
00108                 $this->errormsg = 'Error retrieving ' . $select . ' tables';
00109                 $result = false;
00110             }
00111         }
00112         // Get the table
00113         if ($result && !$t =& $structure->getTable($table)) {
00114             $this->errormsg = 'Error retrieving ' . $table . ' table';
00115             $result = false;
00116         }
00117 
00118         if ($result) {
00119             // Everything is ok. Generate the XML output
00120             $this->output = $t->xmlOutput();
00121         } else {
00122             // Switch to HTML and error
00123             $this->does_generate = ACTION_GENERATE_HTML;
00124         }
00125 
00126         // Return ok if arrived here
00127         return $result;
00128     }
00129 }
00130 
 All Data Structures Namespaces Files Functions Variables Enumerations