3 ///////////////////////////////////////////////////////////////////////////
5 // NOTICE OF COPYRIGHT //
7 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
8 // http://moodle.com //
10 // Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
11 // (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com //
13 // This program is free software; you can redistribute it and/or modify //
14 // it under the terms of the GNU General Public License as published by //
15 // the Free Software Foundation; either version 2 of the License, or //
16 // (at your option) any later version. //
18 // This program is distributed in the hope that it will be useful, //
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
21 // GNU General Public License for more details: //
23 // http://www.gnu.org/copyleft/gpl.html //
25 ///////////////////////////////////////////////////////////////////////////
27 /// This class will show all the reserved words in a format suitable to
28 /// be pasted to: http://docs.moodle.org/en/XMLDB_reserved_words and
29 /// http://docs.moodle.org/en/Database_reserved_words
30 /// Also, it introspects te DB looking for such words and informing about
32 class view_reserved_words
extends XMLDBAction
{
35 * Init method, every subclass will have its own
40 /// Set own custom attributes
42 /// Get needed strings
43 $this->loadStrings(array(
44 'listreservedwords' => 'xmldb',
45 'wrongreservedwords' => 'xmldb',
53 * Invoke method, every class will have its own
54 * returns true/false on completion, setting both
55 * errormsg and output as necessary
62 /// Set own core attributes
63 $this->does_generate
= ACTION_GENERATE_HTML
;
65 /// These are always here
66 global $CFG, $XMLDB, $db;
68 /// Calculate list of available SQL generators
69 $plugins = get_list_of_plugins('lib/xmldb/classes/generators');
70 $reserved_words = array();
71 $reserved_words_bydb = array();
72 foreach($plugins as $plugin) {
73 $classname = 'XMLDB' . $plugin;
74 $generator = new $classname();
75 $reserved_words = array_merge($reserved_words, $generator->getReservedWords());
76 $reserved_words_bydb[$plugin] = $generator->getReservedWords();
78 sort($reserved_words);
79 $reserved_words = array_unique($reserved_words);
81 /// Now, calculate, looking into current DB (with AdoDB Metadata), which fields are
82 /// in the list of reserved words
84 $dbtables = $db->MetaTables('TABLES');
86 foreach ($dbtables as $dbtable) {
87 $table = str_replace($CFG->prefix
, '', $dbtable);
88 if (in_array($table, $reserved_words)) {
89 $list_of_db = array();
90 foreach ($reserved_words_bydb as $key=>$words) {
91 if (in_array($table, $words)) {
95 $wronguses[] = $this->str
['table'] . ' - ' . $table . ' (' . implode(', ',$list_of_db) . ')';
98 $dbfields = $db->MetaColumns($dbtable);
100 foreach ($dbfields as $dbfield) {
101 if (in_array($dbfield->name
, $reserved_words)) {
102 $list_of_db = array();
103 foreach ($reserved_words_bydb as $key=>$words) {
104 if (in_array($dbfield->name
, $words)) {
105 $list_of_db[] = $key;
108 $wronguses[] = $this->str
['field'] . ' - ' . $table . '->' . $dbfield->name
. ' (' . implode(', ',$list_of_db) . ')';
115 /// Sort the wrong uses
118 /// The back to edit table button
119 $b = ' <p class="centerpara buttons">';
120 $b .= '<a href="index.php">[' . $this->str
['back'] . ']</a>';
124 /// The list of currently wrong field names
126 $o.= ' <table id="formelements" class="boxaligncenter" cellpadding="5">';
127 $o.= ' <tr><td align="center"><font color="red">' . $this->str
['wrongreservedwords'] . '</font></td></tr>';
129 $o.= ' <ul><li>' . implode('</li><li>', $wronguses) . '</li></ul>';
134 /// The textarea showing all the reserved words
135 $o.= ' <table id="formelements" class="boxaligncenter" cellpadding="5">';
136 $o.= ' <tr><td align="center">' . $this->str
['listreservedwords'].'</td></tr>';
137 $o.= ' <tr><td><textarea cols="80" rows="32">';
138 $o.= s(implode(', ', $reserved_words));
139 $o.= '</textarea></td></tr>';
144 /// Launch postaction if exists (leave this here!)
145 if ($this->getPostAction() && $result) {
146 return $this->launch($this->getPostAction());
149 /// Return ok if arrived here