Translated using Weblate (Danish)
[phpmyadmin.git] / libraries / display_structure.inc.php
blob60eeba3c006f3c705cb21988c6cab26c128e3ef2
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Displays the table structure ('show table' works correct since 3.23.03)
6 * @package PhpMyAdmin
7 */
9 require_once 'libraries/common.inc.php';
10 require_once 'libraries/mysql_charsets.inc.php';
11 require_once 'libraries/structure.lib.php';
12 require_once 'libraries/index.lib.php';
13 require_once 'libraries/tbl_info.inc.php';
15 if (! defined('PHPMYADMIN')) {
16 exit;
19 /* TABLE INFORMATION */
20 // table header
23 $HideStructureActions = '';
24 if (PMA_Util::showText('ActionLinksMode')
25 && $GLOBALS['cfg']['HideStructureActions'] === true
26 ) {
27 $HideStructureActions .= ' HideStructureActions';
30 $html_form = '<form method="post" action="tbl_structure.php" name="fieldsForm" '
31 . 'id="fieldsForm" class="ajax' . $HideStructureActions . '">';
33 $response->addHTML($html_form);
34 $response->addHTML(PMA_URL_getHiddenInputs($db, $table));
36 $tabletype = '<input type="hidden" name="table_type" value=';
37 if ($db_is_information_schema) {
38 $tabletype .= '"information_schema" />';
39 } else if ($tbl_is_view) {
40 $tabletype .= '"view" />';
41 } else {
42 $tabletype .= '"table" />';
44 $response->addHTML($tabletype);
46 $tablestructure = '<table id="tablestructure" class="data">';
47 $response->addHTML($tablestructure);
50 $response->addHTML(
51 PMA_getHtmlForTableStructureHeader(
52 $db_is_information_schema,
53 $tbl_is_view
57 $response->addHTML('<tbody>');
59 // table body
61 // prepare comments
62 $comments_map = array();
63 $mime_map = array();
65 if ($GLOBALS['cfg']['ShowPropertyComments']) {
66 include_once 'libraries/transformations.lib.php';
67 $comments_map = PMA_getComments($db, $table);
68 if ($cfgRelation['mimework'] && $cfg['BrowseMIME']) {
69 $mime_map = PMA_getMIME($db, $table, true);
73 $rownum = 0;
74 $columns_list = array();
75 $save_row = array();
76 $odd_row = true;
77 foreach ($fields as $row) {
78 $save_row[] = $row;
79 $rownum++;
80 $columns_list[] = $row['Field'];
82 $type = $row['Type'];
83 $extracted_columnspec = PMA_Util::extractColumnSpec($row['Type']);
85 if ('set' == $extracted_columnspec['type']
86 || 'enum' == $extracted_columnspec['type']
87 ) {
88 $type_nowrap = '';
89 } else {
90 $type_nowrap = ' class="nowrap"';
92 $type = $extracted_columnspec['print_type'];
93 if (empty($type)) {
94 $type = ' ';
97 $field_charset = '';
98 if ($extracted_columnspec['can_contain_collation']
99 && ! empty($row['Collation'])
101 $field_charset = $row['Collation'];
104 // Display basic mimetype [MIME]
105 if ($cfgRelation['commwork']
106 && $cfgRelation['mimework']
107 && $cfg['BrowseMIME']
108 && isset($mime_map[$row['Field']]['mimetype'])
110 $type_mime = '<br />MIME: '
111 . str_replace('_', '/', $mime_map[$row['Field']]['mimetype']);
112 } else {
113 $type_mime = '';
116 $attribute = $extracted_columnspec['attribute'];
118 // prepare a common variable to reuse below; however,
119 // in case of a VIEW, $analyzed_sql[0]['create_table_fields'] is empty
120 if (isset($analyzed_sql[0]['create_table_fields'][$row['Field']])) {
121 $tempField = $analyzed_sql[0]['create_table_fields'][$row['Field']];
122 } else {
123 $tempField = array();
126 // MySQL 4.1.2+ TIMESTAMP options
127 // (if on_update_current_timestamp is set, then it's TRUE)
128 if (isset($tempField['on_update_current_timestamp'])) {
129 $attribute = 'on update CURRENT_TIMESTAMP';
132 // here, we have a TIMESTAMP that SHOW FULL COLUMNS reports as having the
133 // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
134 // the latter.
135 if (! empty($tempField['type'])
136 && $tempField['type'] == 'TIMESTAMP'
137 && $tempField['timestamp_not_null']
139 $row['Null'] = '';
143 if (! isset($row['Default'])) {
144 if ($row['Null'] == 'YES') {
145 $row['Default'] = '<i>NULL</i>';
147 } else {
148 $row['Default'] = htmlspecialchars($row['Default']);
151 $field_encoded = urlencode($row['Field']);
152 $field_name = htmlspecialchars($row['Field']);
153 $displayed_field_name = $field_name;
155 // underline commented fields and display a hover-title (CSS only)
157 if (isset($comments_map[$row['Field']])) {
158 $displayed_field_name = '<span class="commented_column" title="'
159 . htmlspecialchars($comments_map[$row['Field']]) . '">'
160 . $field_name . '</span>';
163 if ($primary && $primary->hasColumn($field_name)) {
164 $displayed_field_name = '<u>' . $field_name . '</u>';
166 $response->addHTML(
167 '<tr class="' . ($odd_row ? 'odd': 'even') . '">'
169 $odd_row = !$odd_row;
171 $response->addHTML(
172 PMA_getHtmlTableStructureRow(
173 $row, $rownum, $displayed_field_name,
174 $type_nowrap, $extracted_columnspec, $type_mime,
175 $field_charset, $attribute, $tbl_is_view,
176 $db_is_information_schema, $url_query, $field_encoded, $titles, $table
180 if (! $tbl_is_view && ! $db_is_information_schema) {
181 $response->addHTML(
182 PMA_getHtmlForActionsInTableStructure(
183 $type, $tbl_storage_engine, $primary,
184 $field_name, $url_query, $titles, $row, $rownum,
185 $hidden_titles, $columns_with_unique_index
188 } // end if (! $tbl_is_view && ! $db_is_information_schema)
190 $response->addHTML('</tr>');
192 unset($field_charset);
193 } // end foreach
195 $response->addHTML('</tbody></table>');
197 $response->addHTML(
198 PMA_getHtmlForCheckAllTableColumn(
199 $pmaThemeImage, $text_dir, $tbl_is_view,
200 $db_is_information_schema, $tbl_storage_engine
204 $response->addHTML(
205 '</form><hr />'
207 $response->addHTML(
208 PMA_getHtmlDivForMoveColumnsDialog()
212 * Work on the table
215 if ($tbl_is_view) {
216 $response->addHTML(PMA_getHtmlForEditView($url_params));
218 $response->addHTML(
219 PMA_getHtmlForOptionalActionLinks(
220 $url_query, $tbl_is_view, $db_is_information_schema,
221 $tbl_storage_engine, $cfgRelation
225 if (! $tbl_is_view && ! $db_is_information_schema) {
226 $response->addHTML('<br />');
227 $response->addHTML(PMA_getHtmlForAddColumn($columns_list));
228 $response->addHTML(
229 '<div id="index_div" class="ajax" >'
234 * Displays indexes
237 if (! $tbl_is_view
238 && ! $db_is_information_schema
239 && 'ARCHIVE' != $tbl_storage_engine
241 //return the list of index
242 $response->addJSON(
243 'indexes_list',
244 PMA_Index::getView($GLOBALS['table'], $GLOBALS['db'])
246 $response->addHTML(PMA_getHtmlForDisplayIndexes());
250 * Displays Space usage and row statistics
252 // BEGIN - Calc Table Space
253 // Get valid statistics whatever is the table type
254 if ($cfg['ShowStats']) {
255 //get table stats in HTML format
256 $tablestats = PMA_getHtmlForDisplayTableStats(
257 $showtable, $table_info_num_rows, $tbl_is_view,
258 $db_is_information_schema, $tbl_storage_engine,
259 $url_query, $tbl_collation
261 //returning the response in JSON format to be used by Ajax
262 $response->addJSON('tableStat', $tablestats);
263 $response->addHTML($tablestats);
265 // END - Calc Table Space
267 $response->addHTML(
268 '<div class="clearfloat"></div>'