Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/admin/tool/xmldb/actions/view_table_sql/view_table_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_table_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         // Get parameters
00085         $tableparam = required_param('table', PARAM_PATH);
00086         if (!$table = $structure->getTable($tableparam)) {
00087             $this->errormsg = 'Wrong table specified: ' . $tableparam;
00088             return false;
00089         }
00090 
00091         // The back to edit table button
00092         $b = ' <p class="centerpara buttons">';
00093         $b .= '<a href="index.php?action=edit_table&amp;table=' . $tableparam . '&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['back'] . ']</a>';
00094         $b .= '</p>';
00095         $o = $b;
00096 
00097         $o.= '    <table id="formelements" class="boxaligncenter" cellpadding="5">';
00098         $o.= '      <tr><td><textarea cols="80" rows="32">';
00099 
00100         // Get an array of statements
00101         if ($starr = $DB->get_manager()->generator->getCreateTableSQL($table)) {
00102             $starr = $dbman->generator->getEndedStatements($starr);
00103             $sqltext = '';
00104             foreach ($starr as $st) {
00105                 $sqltext .= s($st) . "\n\n";
00106             }
00107             $sqltext = trim($sqltext);
00108             $o.= $sqltext;
00109         }
00110         $o.= '</textarea></td></tr>';
00111         $o.= '    </table>';
00112 
00113         $this->output = $o;
00114 
00115         // Launch postaction if exists (leave this here!)
00116         if ($this->getPostAction() && $result) {
00117             return $this->launch($this->getPostAction());
00118         }
00119 
00120         // Return ok if arrived here
00121         return $result;
00122     }
00123 }
00124 
 All Data Structures Namespaces Files Functions Variables Enumerations