Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/admin/tool/xmldb/actions/view_reserved_words/view_reserved_words.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 
00035 class view_reserved_words extends XMLDBAction {
00036 
00040     function init() {
00041         parent::init();
00042 
00043         // Set own custom attributes
00044     $this->sesskey_protected = false; // This action doesn't need sesskey protection
00045 
00046         // Get needed strings
00047         $this->loadStrings(array(
00048             'listreservedwords' => 'tool_xmldb',
00049             'wrongreservedwords' => 'tool_xmldb',
00050             'table' => 'tool_xmldb',
00051             'field' => 'tool_xmldb',
00052             'back' => 'tool_xmldb'
00053         ));
00054     }
00055 
00061     function invoke() {
00062         parent::invoke();
00063 
00064         $result = true;
00065 
00066         // Set own core attributes
00067         $this->does_generate = ACTION_GENERATE_HTML;
00068 
00069         // These are always here
00070         global $CFG, $XMLDB, $DB;
00071 
00072         // Calculate list of available SQL generators
00073         require_once("$CFG->libdir/ddl/sql_generator.php");
00074         $reserved_words = sql_generator::getAllReservedWords();
00075 
00076         // Now, calculate, looking into current DB (with AdoDB Metadata), which fields are
00077         // in the list of reserved words
00078         $wronguses = array();
00079         $dbtables = $DB->get_tables();
00080         if ($dbtables) {
00081             foreach ($dbtables as $table) {
00082                 if (array_key_exists($table, $reserved_words)) {
00083                     $wronguses[] = $this->str['table'] . ' - ' . $table . ' (' . implode(', ',$reserved_words[$table]) . ')';
00084 
00085                 }
00086                 $dbfields = $DB->get_columns($table);
00087                 if ($dbfields) {
00088                     foreach ($dbfields as $dbfield) {
00089                         if (array_key_exists($dbfield->name, $reserved_words)) {
00090                             $wronguses[] = $this->str['field'] . ' - ' . $table . '->' . $dbfield->name . ' (' . implode(', ',$reserved_words[$dbfield->name]) . ')';
00091                         }
00092                     }
00093                 }
00094             }
00095         }
00096 
00097         // Sort the wrong uses
00098         sort($wronguses);
00099 
00100         // The back to edit table button
00101         $b = ' <p class="centerpara buttons">';
00102         $b .= '<a href="index.php">[' . $this->str['back'] . ']</a>';
00103         $b .= '</p>';
00104         $o = $b;
00105 
00106         // The list of currently wrong field names
00107         if ($wronguses) {
00108             $o.= '    <table id="formelements" class="boxaligncenter" cellpadding="5">';
00109             $o.= '      <tr><td align="center"><font color="red">' . $this->str['wrongreservedwords'] . '</font></td></tr>';
00110             $o.= '      <tr><td>';
00111             $o.= '        <ul><li>' . implode('</li><li>', $wronguses) . '</li></ul>';
00112             $o.= '      </td></tr>';
00113             $o.= '    </table>';
00114         }
00115 
00116         // The textarea showing all the reserved words
00117         $o.= '    <table id="formelements" class="boxaligncenter" cellpadding="5">';
00118         $o.= '      <tr><td align="center">' . $this->str['listreservedwords'].'</td></tr>';
00119         $o.= '      <tr><td><textarea cols="80" rows="32">';
00120         $o.= s(implode(', ', array_keys($reserved_words)));
00121         $o.= '</textarea></td></tr>';
00122         $o.= '    </table>';
00123 
00124         $this->output = $o;
00125 
00126         // Launch postaction if exists (leave this here!)
00127         if ($this->getPostAction() && $result) {
00128             return $this->launch($this->getPostAction());
00129         }
00130 
00131         // Return ok if arrived here
00132         return $result;
00133     }
00134 }
00135 
 All Data Structures Namespaces Files Functions Variables Enumerations