Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/admin/tool/xmldb/actions/view_structure_sql/view_structure_sql.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 
00033 class view_structure_sql extends XMLDBAction {
00034 
00038     function init() {
00039         parent::init();
00040 
00041         // Set own custom attributes
00042         $this->sesskey_protected = false; // This action doesn't need sesskey protection
00043 
00044         // Get needed strings
00045         $this->loadStrings(array(
00046             'selectdb' => 'tool_xmldb',
00047             'back' => 'tool_xmldb'
00048         ));
00049     }
00050 
00056     function invoke() {
00057         parent::invoke();
00058 
00059         $result = true;
00060 
00061         // Set own core attributes
00062         $this->does_generate = ACTION_GENERATE_HTML;
00063 
00064         // These are always here
00065         global $CFG, $XMLDB, $DB;
00066         $dbman = $DB->get_manager();
00067 
00068         // Do the job, setting result as needed
00069         // Get the dir containing the file
00070         $dirpath = required_param('dir', PARAM_PATH);
00071         $dirpath = $CFG->dirroot . $dirpath;
00072 
00073         // Get the correct dirs
00074         if (!empty($XMLDB->dbdirs)) {
00075             $dbdir =& $XMLDB->dbdirs[$dirpath];
00076         } else {
00077             return false;
00078         }
00079         if (!empty($XMLDB->editeddirs)) {
00080             $editeddir =& $XMLDB->editeddirs[$dirpath];
00081             $structure =& $editeddir->xml_file->getStructure();
00082         }
00083 
00084         // The back to edit table button
00085         $b = ' <p class="centerpara buttons">';
00086         $b .= '<a href="index.php?action=edit_xml_file&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['back'] . ']</a>';
00087         $b .= '</p>';
00088         $o = $b;
00089 
00090         $o.= '    <table id="formelements" class="boxaligncenter" cellpadding="5">';
00091         $o.= '      <tr><td><textarea cols="80" rows="32">';
00092         // Get an array of statements
00093         if ($starr = $DB->get_manager()->generator->getCreateStructureSQL($structure)) {
00094             $starr = $dbman->generator->getEndedStatements($starr);
00095             $sqltext = '';
00096             foreach ($starr as $st) {
00097                 $sqltext .= s($st) . "\n\n";
00098             }
00099             $sqltext = trim($sqltext);
00100             $o.= $sqltext;
00101         }
00102         $o.= '</textarea></td></tr>';
00103         $o.= '    </table>';
00104 
00105         $this->output = $o;
00106 
00107         // Launch postaction if exists (leave this here!)
00108         if ($this->getPostAction() && $result) {
00109             return $this->launch($this->getPostAction());
00110         }
00111 
00112         // Return ok if arrived here
00113         return $result;
00114     }
00115 }
00116 
 All Data Structures Namespaces Files Functions Variables Enumerations