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