UPDATE 4.4.0.0
[phpmyadmin.git] / libraries / display_structure.inc.php
blob503724d6888c2db7c011e6764fd2a3c5b96b9675
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 ($GLOBALS['cfg']['HideStructureActions'] === true) {
25 $HideStructureActions .= ' HideStructureActions';
28 $html_form = '<form method="post" action="tbl_structure.php" name="fieldsForm" '
29 . 'id="fieldsForm" class="ajax' . $HideStructureActions . '">';
31 $response->addHTML($html_form);
32 $response->addHTML(PMA_URL_getHiddenInputs($db, $table));
34 $tabletype = '<input type="hidden" name="table_type" value=';
35 if ($db_is_system_schema) {
36 $tabletype .= '"information_schema" />';
37 } else if ($tbl_is_view) {
38 $tabletype .= '"view" />';
39 } else {
40 $tabletype .= '"table" />';
42 $response->addHTML($tabletype);
44 $tablestructure = '<table id="tablestructure" class="data topmargin">';
45 $response->addHTML($tablestructure);
48 $response->addHTML(
49 PMA_getHtmlForTableStructureHeader(
50 $db_is_system_schema,
51 $tbl_is_view
55 $response->addHTML('<tbody>');
57 // table body
59 // prepare comments
60 $comments_map = array();
61 $mime_map = array();
63 if ($GLOBALS['cfg']['ShowPropertyComments']) {
64 include_once 'libraries/transformations.lib.php';
65 $comments_map = PMA_getComments($db, $table);
66 if ($cfgRelation['mimework'] && $cfg['BrowseMIME']) {
67 $mime_map = PMA_getMIME($db, $table, true);
70 require_once 'libraries/central_columns.lib.php';
71 $central_list = PMA_getCentralColumnsFromTable($db, $table);
72 $rownum = 0;
73 $columns_list = array();
74 $save_row = array();
75 $odd_row = true;
76 foreach ($fields as $row) {
77 $save_row[] = $row;
78 $rownum++;
79 $columns_list[] = $row['Field'];
81 $type = $row['Type'];
82 $extracted_columnspec = PMA_Util::extractColumnSpec($row['Type']);
84 if ('set' == $extracted_columnspec['type']
85 || 'enum' == $extracted_columnspec['type']
86 ) {
87 $type_nowrap = '';
88 } else {
89 $type_nowrap = ' class="nowrap"';
91 $type = $extracted_columnspec['print_type'];
92 if (empty($type)) {
93 $type = ' ';
96 $field_charset = '';
97 if ($extracted_columnspec['can_contain_collation']
98 && ! empty($row['Collation'])
99 ) {
100 $field_charset = $row['Collation'];
103 // Display basic mimetype [MIME]
104 if ($cfgRelation['commwork']
105 && $cfgRelation['mimework']
106 && $cfg['BrowseMIME']
107 && isset($mime_map[$row['Field']]['mimetype'])
109 $type_mime = '<br />MIME: '
110 . str_replace('_', '/', $mime_map[$row['Field']]['mimetype']);
111 } else {
112 $type_mime = '';
115 $attribute = $extracted_columnspec['attribute'];
117 // prepare a common variable to reuse below; however,
118 // in case of a VIEW, $analyzed_sql[0]['create_table_fields'] is empty
119 if (isset($analyzed_sql[0]['create_table_fields'][$row['Field']])) {
120 $tempField = $analyzed_sql[0]['create_table_fields'][$row['Field']];
121 } else {
122 $tempField = array();
125 // MySQL 4.1.2+ TIMESTAMP options
126 // (if on_update_current_timestamp is set, then it's TRUE)
127 if (isset($tempField['on_update_current_timestamp'])) {
128 $attribute = 'on update CURRENT_TIMESTAMP';
131 // here, we have a TIMESTAMP that SHOW FULL COLUMNS reports as having the
132 // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
133 // the latter.
134 if (! empty($tempField['type'])
135 && $tempField['type'] == 'TIMESTAMP'
136 && $tempField['timestamp_not_null']
138 $row['Null'] = '';
142 if (! isset($row['Default'])) {
143 if ($row['Null'] == 'YES') {
144 $row['Default'] = '<i>NULL</i>';
146 } else {
147 $row['Default'] = htmlspecialchars($row['Default']);
150 $field_encoded = urlencode($row['Field']);
151 $field_name = htmlspecialchars($row['Field']);
152 $displayed_field_name = $field_name;
154 // underline commented fields and display a hover-title (CSS only)
156 if (isset($comments_map[$row['Field']])) {
157 $displayed_field_name = '<span class="commented_column" title="'
158 . htmlspecialchars($comments_map[$row['Field']]) . '">'
159 . $field_name . '</span>';
162 if ($primary && $primary->hasColumn($field_name)) {
163 $displayed_field_name .= PMA_Util::getImage(
164 'b_primary.png', __('Primary')
167 $response->addHTML(
168 '<tr class="' . ($odd_row ? 'odd': 'even') . '">'
170 $odd_row = !$odd_row;
171 $isInCentralColumns = in_array($row['Field'], $central_list)?true:false;
172 $response->addHTML(
173 PMA_getHtmlTableStructureRow(
174 $row, $rownum, $displayed_field_name,
175 $type_nowrap, $extracted_columnspec, $type_mime,
176 $field_charset, $attribute, $tbl_is_view,
177 $db_is_system_schema, $url_query, $field_encoded, $titles, $table
181 if (! $tbl_is_view && ! $db_is_system_schema) {
182 $response->addHTML(
183 PMA_getHtmlForActionsInTableStructure(
184 $type, $tbl_storage_engine, $primary,
185 $field_name, $url_query, $titles, $row, $rownum,
186 $columns_with_unique_index,
187 $isInCentralColumns
190 } // end if (! $tbl_is_view && ! $db_is_system_schema)
192 $response->addHTML('</tr>');
194 unset($field_charset);
195 } // end foreach
197 $response->addHTML('</tbody></table>');
199 $response->addHTML(
200 PMA_getHtmlForCheckAllTableColumn(
201 $pmaThemeImage, $text_dir, $tbl_is_view,
202 $db_is_system_schema, $tbl_storage_engine
206 $response->addHTML(
207 '</form><hr />'
209 $response->addHTML(
210 PMA_getHtmlDivForMoveColumnsDialog()
214 * Work on the table
217 $response->addHTML('<div id="structure-action-links">');
219 if ($tbl_is_view) {
220 $response->addHTML(PMA_getHtmlForEditView($url_params));
222 $response->addHTML(
223 PMA_getHtmlForOptionalActionLinks(
224 $url_query, $tbl_is_view, $db_is_system_schema
228 $response->addHTML('</div>');
230 if (! $tbl_is_view && ! $db_is_system_schema) {
231 $response->addHTML('<br />');
232 $response->addHTML(PMA_getHtmlForAddColumn($columns_list));
236 * Displays indexes
239 if (! $tbl_is_view
240 && ! $db_is_system_schema
241 && 'ARCHIVE' != $tbl_storage_engine
243 //return the list of index
244 $response->addJSON(
245 'indexes_list',
246 PMA_Index::getView($GLOBALS['table'], $GLOBALS['db'])
248 $response->addHTML(PMA_getHtmlForDisplayIndexes());
252 * Displays Space usage and row statistics
254 // BEGIN - Calc Table Space
255 // Get valid statistics whatever is the table type
256 if ($cfg['ShowStats']) {
257 //get table stats in HTML format
258 $tablestats = PMA_getHtmlForDisplayTableStats(
259 $showtable, $table_info_num_rows, $tbl_is_view,
260 $db_is_system_schema, $tbl_storage_engine,
261 $url_query, $tbl_collation
263 //returning the response in JSON format to be used by Ajax
264 $response->addJSON('tableStat', $tablestats);
265 $response->addHTML($tablestats);
267 // END - Calc Table Space
269 $response->addHTML(
270 '<div class="clearfloat"></div>'