Merge pull request #11432 from devenbansod/fix_11431
[phpmyadmin.git] / db_datadict.php
blob555063e7d38fa3c7cd199b5366b5c03fbc3db98d
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Renders data dictionary
6 * @package PhpMyAdmin
7 */
9 /**
10 * Gets the variables sent or posted to this script, then displays headers
12 require_once 'libraries/common.inc.php';
14 if (! isset($selected_tbl)) {
15 include 'libraries/db_common.inc.php';
16 include 'libraries/db_info.inc.php';
19 $response = PMA_Response::getInstance();
20 $header = $response->getHeader();
21 $header->enablePrintView();
23 /**
24 * Gets the relations settings
26 $cfgRelation = PMA_getRelationsParam();
28 require_once 'libraries/transformations.lib.php';
29 require_once 'libraries/Index.class.php';
31 /**
32 * Check parameters
34 PMA_Util::checkParameters(array('db'));
36 /**
37 * Defines the url to return to in case of error in a sql statement
39 $err_url = 'db_sql.php' . PMA_URL_getCommon(array('db' => $db));
41 if ($cfgRelation['commwork']) {
42 $comment = PMA_getDbComment($db);
44 /**
45 * Displays DB comment
47 if ($comment) {
48 echo '<p>' . __('Database comment:')
49 . ' <i>' . htmlspecialchars($comment) . '</i></p>';
50 } // end if
53 /**
54 * Selects the database and gets tables names
56 $GLOBALS['dbi']->selectDb($db);
57 $tables = $GLOBALS['dbi']->getTables($db);
59 $count = 0;
60 foreach ($tables as $table) {
61 $comments = PMA_getComments($db, $table);
63 echo '<div>' . "\n";
65 echo '<h2>' . htmlspecialchars($table) . '</h2>' . "\n";
67 /**
68 * Gets table informations
70 $show_comment = PMA_Table::sGetStatusInfo($db, $table, 'TABLE_COMMENT');
72 /**
73 * Gets table keys and retains them
75 $GLOBALS['dbi']->selectDb($db);
76 $indexes = $GLOBALS['dbi']->getTableIndexes($db, $table);
77 list($primary, $pk_array, $indexes_info, $indexes_data)
78 = PMA_Util::processIndexData($indexes);
80 /**
81 * Gets columns properties
83 $columns = $GLOBALS['dbi']->getColumns($db, $table);
85 // Check if we can use Relations
86 list($res_rel, $have_rel) = PMA_getRelationsAndStatus(
87 ! empty($cfgRelation['relation']), $db, $table
90 /**
91 * Displays the comments of the table if MySQL >= 3.23
93 if (!empty($show_comment)) {
94 echo __('Table comments:') . ' ';
95 echo htmlspecialchars($show_comment) . '<br /><br />';
98 /**
99 * Displays the table structure
102 echo '<table width="100%" class="print">';
103 echo '<tr><th width="50">' . __('Column') . '</th>';
104 echo '<th width="80">' . __('Type') . '</th>';
105 echo '<th width="40">' . __('Null') . '</th>';
106 echo '<th width="70">' . __('Default') . '</th>';
107 if ($have_rel) {
108 echo ' <th>' . __('Links to') . '</th>' . "\n";
110 echo ' <th>' . __('Comments') . '</th>' . "\n";
111 if ($cfgRelation['mimework']) {
112 echo ' <th>MIME</th>' . "\n";
114 echo '</tr>';
115 $odd_row = true;
116 foreach ($columns as $row) {
118 if ($row['Null'] == '') {
119 $row['Null'] = 'NO';
121 $extracted_columnspec
122 = PMA_Util::extractColumnSpec($row['Type']);
124 // reformat mysql query output
125 // set or enum types: slashes single quotes inside options
126 if ('set' == $extracted_columnspec['type']
127 || 'enum' == $extracted_columnspec['type']
129 $type_nowrap = '';
131 } else {
132 $type_nowrap = ' class="nowrap"';
134 $type = htmlspecialchars($extracted_columnspec['print_type']);
135 $attribute = $extracted_columnspec['attribute'];
136 if (! isset($row['Default'])) {
137 if ($row['Null'] != 'NO') {
138 $row['Default'] = '<i>NULL</i>';
140 } else {
141 $row['Default'] = htmlspecialchars($row['Default']);
143 $column_name = $row['Field'];
145 echo '<tr class="';
146 echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row;
147 echo '">';
148 echo '<td class="nowrap">';
149 echo htmlspecialchars($column_name);
151 if (isset($pk_array[$row['Field']])) {
152 echo ' <em>(' . __('Primary') . ')</em>';
154 echo '</td>';
155 echo '<td' . $type_nowrap . ' lang="en" dir="ltr">' . $type . '</td>';
156 echo '<td>';
157 echo (($row['Null'] == 'NO') ? __('No') : __('Yes'));
158 echo '</td>';
159 echo '<td class="nowrap">';
160 if (isset($row['Default'])) {
161 echo $row['Default'];
163 echo '</td>';
165 if ($have_rel) {
166 echo ' <td>';
167 if ($foreigner = PMA_searchColumnInForeigners($res_rel, $column_name)) {
168 echo htmlspecialchars(
169 $foreigner['foreign_table']
170 . ' -> '
171 . $foreigner['foreign_field']
174 echo '</td>' . "\n";
176 echo ' <td>';
177 if (isset($comments[$column_name])) {
178 echo htmlspecialchars($comments[$column_name]);
180 echo '</td>' . "\n";
181 if ($cfgRelation['mimework']) {
182 $mime_map = PMA_getMIME($db, $table, true);
184 echo ' <td>';
185 if (isset($mime_map[$column_name])) {
186 echo htmlspecialchars(
187 str_replace('_', '/', $mime_map[$column_name]['mimetype'])
190 echo '</td>' . "\n";
192 echo '</tr>';
193 } // end foreach
194 $count++;
195 echo '</table>';
196 // display indexes information
197 if (count(PMA_Index::getFromTable($table, $db)) > 0) {
198 echo PMA_Index::getView($table, $db, true);
200 echo '</div>';
201 } //ends main while
204 * Displays the footer
206 echo PMA_Util::getButton();