2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Renders data dictionary
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();
24 * Gets the relations settings
26 $cfgRelation = PMA_getRelationsParam();
28 require_once 'libraries/transformations.lib.php';
29 require_once 'libraries/Index.class.php';
34 PMA_Util
::checkParameters(array('db'));
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);
48 echo '<p>' . __('Database comment')
49 . '<br /><i>' . htmlspecialchars($comment) . '</i></p>';
54 * Selects the database and gets tables names
56 $GLOBALS['dbi']->selectDb($db);
57 $tables = $GLOBALS['dbi']->getTables($db);
60 foreach ($tables as $table) {
61 $comments = PMA_getComments($db, $table);
65 echo '<h2>' . htmlspecialchars($table) . '</h2>' . "\n";
68 * Gets table information
70 $show_comment = $GLOBALS['dbi']->getTable($db, $table)
71 ->sGetStatusInfo('TABLE_COMMENT');
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);
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
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 />';
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>';
109 echo ' <th>' . __('Links to') . '</th>' . "\n";
111 echo ' <th>' . __('Comments') . '</th>' . "\n";
112 if ($cfgRelation['mimework']) {
113 echo ' <th>MIME</th>' . "\n";
117 foreach ($columns as $row) {
119 if ($row['Null'] == '') {
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>';
135 $row['Default'] = htmlspecialchars($row['Default']);
137 $column_name = $row['Field'];
140 echo $odd_row ?
'odd' : 'even'; $odd_row = ! $odd_row;
142 echo '<td class="nowrap">';
143 echo htmlspecialchars($column_name);
145 if (isset($pk_array[$row['Field']])) {
146 echo ' <em>(' . __('Primary') . ')</em>';
150 . PMA_Util
::getClassForType(
151 $extracted_columnspec['type']
153 . ' lang="en" dir="ltr">' . $type . '</td>';
156 echo (($row['Null'] == 'NO') ?
__('No') : __('Yes'));
158 echo '<td class="nowrap">';
159 if (isset($row['Default'])) {
160 echo $row['Default'];
166 if ($foreigner = PMA_searchColumnInForeigners($res_rel, $column_name)) {
167 echo htmlspecialchars(
168 $foreigner['foreign_table']
170 . $foreigner['foreign_field']
176 if (isset($comments[$column_name])) {
177 echo htmlspecialchars($comments[$column_name]);
180 if ($cfgRelation['mimework']) {
181 $mime_map = PMA_getMIME($db, $table, true);
184 if (isset($mime_map[$column_name])) {
185 echo htmlspecialchars(
186 str_replace('_', '/', $mime_map[$column_name]['mimetype'])
195 // display indexes information
196 if (count(PMA_Index
::getFromTable($table, $db)) > 0) {
197 echo PMA_Index
::getHtmlForIndexes($table, $db, true);
203 * Displays the footer
205 echo PMA_Util
::getButton();