Continue refactoring db tracking
[phpmyadmin.git] / db_datadict.php
blob8602d95f4a7faf1aa1c02de0e1d85995fe233e03
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 . '<br /><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 information
70 $show_comment = $GLOBALS['dbi']->getTable($db, $table)
71 ->sGetStatusInfo('TABLE_COMMENT');
73 /**
74 * Gets table keys and retains them
76 $GLOBALS['dbi']->selectDb($db);
77 $indexes = $GLOBALS['dbi']->getTableIndexes($db, $table);
78 list($primary, $pk_array, $indexes_info, $indexes_data)
79 = PMA_Util::processIndexData($indexes);
81 /**
82 * Gets columns properties
84 $columns = $GLOBALS['dbi']->getColumns($db, $table);
86 // Check if we can use Relations
87 list($res_rel, $have_rel) = PMA_getRelationsAndStatus(
88 ! empty($cfgRelation['relation']), $db, $table
91 /**
92 * Displays the comments of the table if MySQL >= 3.23
94 if (!empty($show_comment)) {
95 echo __('Table comments:') . ' ';
96 echo htmlspecialchars($show_comment) . '<br /><br />';
99 /**
100 * Displays the table structure
103 echo '<table width="100%" class="print">';
104 echo '<tr><th width="50">' . __('Column') . '</th>';
105 echo '<th width="80">' . __('Type') . '</th>';
106 echo '<th width="40">' . __('Null') . '</th>';
107 echo '<th width="70">' . __('Default') . '</th>';
108 if ($have_rel) {
109 echo ' <th>' . __('Links to') . '</th>' . "\n";
111 echo ' <th>' . __('Comments') . '</th>' . "\n";
112 if ($cfgRelation['mimework']) {
113 echo ' <th>MIME</th>' . "\n";
115 echo '</tr>';
116 $odd_row = true;
117 foreach ($columns as $row) {
119 if ($row['Null'] == '') {
120 $row['Null'] = 'NO';
122 $extracted_columnspec
123 = PMA_Util::extractColumnSpec($row['Type']);
125 // reformat mysql query output
126 // set or enum types: slashes single quotes inside options
128 $type = htmlspecialchars($extracted_columnspec['print_type']);
129 $attribute = $extracted_columnspec['attribute'];
130 if (! isset($row['Default'])) {
131 if ($row['Null'] != 'NO') {
132 $row['Default'] = '<i>NULL</i>';
134 } else {
135 $row['Default'] = htmlspecialchars($row['Default']);
137 $column_name = $row['Field'];
139 echo '<tr class="';
140 echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row;
141 echo '">';
142 echo '<td class="nowrap">';
143 echo htmlspecialchars($column_name);
145 if (isset($pk_array[$row['Field']])) {
146 echo ' <em>(' . __('Primary') . ')</em>';
148 echo '</td>';
149 echo '<td'
150 . PMA_Util::getClassForType(
151 $extracted_columnspec['type']
153 . ' lang="en" dir="ltr">' . $type . '</td>';
155 echo '<td>';
156 echo (($row['Null'] == 'NO') ? __('No') : __('Yes'));
157 echo '</td>';
158 echo '<td class="nowrap">';
159 if (isset($row['Default'])) {
160 echo $row['Default'];
162 echo '</td>';
164 if ($have_rel) {
165 echo ' <td>';
166 if ($foreigner = PMA_searchColumnInForeigners($res_rel, $column_name)) {
167 echo htmlspecialchars(
168 $foreigner['foreign_table']
169 . ' -> '
170 . $foreigner['foreign_field']
173 echo '</td>' . "\n";
175 echo ' <td>';
176 if (isset($comments[$column_name])) {
177 echo htmlspecialchars($comments[$column_name]);
179 echo '</td>' . "\n";
180 if ($cfgRelation['mimework']) {
181 $mime_map = PMA_getMIME($db, $table, true);
183 echo ' <td>';
184 if (isset($mime_map[$column_name])) {
185 echo htmlspecialchars(
186 str_replace('_', '/', $mime_map[$column_name]['mimetype'])
189 echo '</td>' . "\n";
191 echo '</tr>';
192 } // end foreach
193 $count++;
194 echo '</table>';
195 // display indexes information
196 if (count(PMA_Index::getFromTable($table, $db)) > 0) {
197 echo PMA_Index::getHtmlForIndexes($table, $db, true);
199 echo '</div>';
200 } //ends main while
203 * Displays the footer
205 echo PMA_Util::getButton();