2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Displays the table structure ('show table' works correct since 3.23.03)
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')) {
19 /* TABLE INFORMATION */
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" />';
40 $tabletype .= '"table" />';
42 $response->addHTML($tabletype);
44 $tablestructure = '<table id="tablestructure" class="data">';
45 $response->addHTML($tablestructure);
49 PMA_getHtmlForTableStructureHeader(
55 $response->addHTML('<tbody>');
60 $comments_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);
73 $columns_list = array();
76 foreach ($fields as $row) {
79 $columns_list[] = $row['Field'];
82 $extracted_columnspec = PMA_Util
::extractColumnSpec($row['Type']);
84 if ('set' == $extracted_columnspec['type']
85 ||
'enum' == $extracted_columnspec['type']
89 $type_nowrap = ' class="nowrap"';
91 $type = $extracted_columnspec['print_type'];
97 if ($extracted_columnspec['can_contain_collation']
98 && ! empty($row['Collation'])
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']);
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']];
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
134 if (! empty($tempField['type'])
135 && $tempField['type'] == 'TIMESTAMP'
136 && $tempField['timestamp_not_null']
142 if (! isset($row['Default'])) {
143 if ($row['Null'] == 'YES') {
144 $row['Default'] = '<i>NULL</i>';
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')
168 '<tr class="' . ($odd_row ?
'odd': 'even') . '">'
170 $odd_row = !$odd_row;
171 $isInCentralColumns = in_array($row['Field'], $central_list)?
true:false;
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) {
183 PMA_getHtmlForActionsInTableStructure(
184 $type, $tbl_storage_engine, $primary,
185 $field_name, $url_query, $titles, $row, $rownum,
186 $hidden_titles, $columns_with_unique_index,
190 } // end if (! $tbl_is_view && ! $db_is_system_schema)
192 $response->addHTML('</tr>');
194 unset($field_charset);
197 $response->addHTML('</tbody></table>');
200 PMA_getHtmlForCheckAllTableColumn(
201 $pmaThemeImage, $text_dir, $tbl_is_view,
202 $db_is_system_schema, $tbl_storage_engine
210 PMA_getHtmlDivForMoveColumnsDialog()
217 $response->addHTML('<div id="structure-action-links">');
220 $response->addHTML(PMA_getHtmlForEditView($url_params));
223 PMA_getHtmlForOptionalActionLinks(
224 $url_query, $tbl_is_view, $db_is_system_schema,
225 $tbl_storage_engine, $cfgRelation
229 $response->addHTML('</div>');
231 if (! $tbl_is_view && ! $db_is_system_schema) {
232 $response->addHTML('<br />');
233 $response->addHTML(PMA_getHtmlForAddColumn($columns_list));
241 && ! $db_is_system_schema
242 && 'ARCHIVE' != $tbl_storage_engine
244 //return the list of index
247 PMA_Index
::getView($GLOBALS['table'], $GLOBALS['db'])
249 $response->addHTML(PMA_getHtmlForDisplayIndexes());
253 * Displays Space usage and row statistics
255 // BEGIN - Calc Table Space
256 // Get valid statistics whatever is the table type
257 if ($cfg['ShowStats']) {
258 //get table stats in HTML format
259 $tablestats = PMA_getHtmlForDisplayTableStats(
260 $showtable, $table_info_num_rows, $tbl_is_view,
261 $db_is_system_schema, $tbl_storage_engine,
262 $url_query, $tbl_collation
264 //returning the response in JSON format to be used by Ajax
265 $response->addJSON('tableStat', $tablestats);
266 $response->addHTML($tablestats);
268 // END - Calc Table Space
271 '<div class="clearfloat"></div>'