Removing old documentation
[openemr.git] / phpmyadmin / db_datadict.php
blob63670871522d851d63ae3b7e301138d40fb0a0ea
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 list(
17 $tables,
18 $num_tables,
19 $total_num_tables,
20 $sub_part,
21 $is_show_stats,
22 $db_is_system_schema,
23 $tooltip_truename,
24 $tooltip_aliasname,
25 $pos
26 ) = PMA_Util::getDbInfo($db, isset($sub_part) ? $sub_part : '');
29 $response = PMA_Response::getInstance();
30 $header = $response->getHeader();
31 $header->enablePrintView();
33 /**
34 * Gets the relations settings
36 $cfgRelation = PMA_getRelationsParam();
38 require_once 'libraries/transformations.lib.php';
39 require_once 'libraries/Index.class.php';
41 /**
42 * Check parameters
44 PMA_Util::checkParameters(array('db'));
46 /**
47 * Defines the url to return to in case of error in a sql statement
49 $err_url = 'db_sql.php' . PMA_URL_getCommon(array('db' => $db));
51 if ($cfgRelation['commwork']) {
52 $comment = PMA_getDbComment($db);
54 /**
55 * Displays DB comment
57 if ($comment) {
58 echo '<p>' . __('Database comment')
59 . '<br /><i>' . htmlspecialchars($comment) . '</i></p>';
60 } // end if
63 /**
64 * Selects the database and gets tables names
66 $GLOBALS['dbi']->selectDb($db);
67 $tables = $GLOBALS['dbi']->getTables($db);
69 $count = 0;
70 foreach ($tables as $table) {
71 $comments = PMA_getComments($db, $table);
73 echo '<div>' . "\n";
75 echo '<h2>' . htmlspecialchars($table) . '</h2>' . "\n";
77 /**
78 * Gets table information
80 $show_comment = $GLOBALS['dbi']->getTable($db, $table)
81 ->getStatusInfo('TABLE_COMMENT');
83 /**
84 * Gets table keys and retains them
86 $GLOBALS['dbi']->selectDb($db);
87 $indexes = $GLOBALS['dbi']->getTableIndexes($db, $table);
88 list($primary, $pk_array, $indexes_info, $indexes_data)
89 = PMA_Util::processIndexData($indexes);
91 /**
92 * Gets columns properties
94 $columns = $GLOBALS['dbi']->getColumns($db, $table);
96 // Check if we can use Relations
97 list($res_rel, $have_rel) = PMA_getRelationsAndStatus(
98 ! empty($cfgRelation['relation']), $db, $table
102 * Displays the comments of the table if MySQL >= 3.23
104 if (!empty($show_comment)) {
105 echo __('Table comments:') . ' ';
106 echo htmlspecialchars($show_comment) . '<br /><br />';
110 * Displays the table structure
113 echo '<table width="100%" class="print">';
114 echo '<tr><th width="50">' . __('Column') . '</th>';
115 echo '<th width="80">' . __('Type') . '</th>';
116 echo '<th width="40">' . __('Null') . '</th>';
117 echo '<th width="70">' . __('Default') . '</th>';
118 if ($have_rel) {
119 echo ' <th>' . __('Links to') . '</th>' . "\n";
121 echo ' <th>' . __('Comments') . '</th>' . "\n";
122 if ($cfgRelation['mimework']) {
123 echo ' <th>MIME</th>' . "\n";
125 echo '</tr>';
126 $odd_row = true;
127 foreach ($columns as $row) {
129 if ($row['Null'] == '') {
130 $row['Null'] = 'NO';
132 $extracted_columnspec
133 = PMA_Util::extractColumnSpec($row['Type']);
135 // reformat mysql query output
136 // set or enum types: slashes single quotes inside options
138 $type = htmlspecialchars($extracted_columnspec['print_type']);
139 $attribute = $extracted_columnspec['attribute'];
140 if (! isset($row['Default'])) {
141 if ($row['Null'] != 'NO') {
142 $row['Default'] = '<i>NULL</i>';
144 } else {
145 $row['Default'] = htmlspecialchars($row['Default']);
147 $column_name = $row['Field'];
149 echo '<tr class="';
150 echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row;
151 echo '">';
152 echo '<td class="nowrap">';
153 echo htmlspecialchars($column_name);
155 if (isset($pk_array[$row['Field']])) {
156 echo ' <em>(' . __('Primary') . ')</em>';
158 echo '</td>';
159 echo '<td'
160 . PMA_Util::getClassForType(
161 $extracted_columnspec['type']
163 . ' lang="en" dir="ltr">' . $type . '</td>';
165 echo '<td>';
166 echo (($row['Null'] == 'NO') ? __('No') : __('Yes'));
167 echo '</td>';
168 echo '<td class="nowrap">';
169 if (isset($row['Default'])) {
170 echo $row['Default'];
172 echo '</td>';
174 if ($have_rel) {
175 echo ' <td>';
176 if ($foreigner = PMA_searchColumnInForeigners($res_rel, $column_name)) {
177 echo htmlspecialchars(
178 $foreigner['foreign_table']
179 . ' -> '
180 . $foreigner['foreign_field']
183 echo '</td>' . "\n";
185 echo ' <td>';
186 if (isset($comments[$column_name])) {
187 echo htmlspecialchars($comments[$column_name]);
189 echo '</td>' . "\n";
190 if ($cfgRelation['mimework']) {
191 $mime_map = PMA_getMIME($db, $table, true);
193 echo ' <td>';
194 if (isset($mime_map[$column_name])) {
195 echo htmlspecialchars(
196 str_replace('_', '/', $mime_map[$column_name]['mimetype'])
199 echo '</td>' . "\n";
201 echo '</tr>';
202 } // end foreach
203 $count++;
204 echo '</table>';
205 // display indexes information
206 if (count(PMA_Index::getFromTable($table, $db)) > 0) {
207 echo PMA_Index::getHtmlForIndexes($table, $db, true);
209 echo '</div>';
210 } //ends main while
213 * Displays the footer
215 echo PMA_Util::getButton();