diff --git a/libraries/Response.class.php b/libraries/Response.class.php index 1bc183293c..dbea700dfa 100644 --- a/libraries/Response.class.php +++ b/libraries/Response.class.php @@ -213,7 +213,11 @@ class PMA_Response */ public function addHTML($content) { - if ($content instanceof PMA_Message) { + if (is_array($content)) { + foreach ($content as $msg) { + $this->addHTML($msg); + } + } elseif ($content instanceof PMA_Message) { $this->_HTML .= $content->getDisplay(); } else { $this->_HTML .= $content; diff --git a/libraries/display_structure.lib.php b/libraries/display_structure.lib.php new file mode 100644 index 0000000000..dd92ceaec7 --- /dev/null +++ b/libraries/display_structure.lib.php @@ -0,0 +1,263 @@ +'; + +$response->addHTML($html_form); +$response->addHTML(PMA_generate_common_hidden_inputs($db, $table)); + +$tabletype = ''; +} else if ($tbl_is_view) { + $tabletype .= '"view" />'; +} else { + $tabletype .= '"table" />'; +} +$response->addHTML($tabletype); + +$tablestructure = ''; +$response->addHTML($tablestructure); + + +$response->addHTML( + PMA_getHtmlForTableStructureHeader( + $db_is_information_schema, + $tbl_is_view + ) +); + +$response->addHTML(''); + +// table body + +// prepare comments +$comments_map = array(); +$mime_map = array(); + +if ($GLOBALS['cfg']['ShowPropertyComments']) { + include_once 'libraries/transformations.lib.php'; + $comments_map = PMA_getComments($db, $table); + if ($cfgRelation['mimework'] && $cfg['BrowseMIME']) { + $mime_map = PMA_getMIME($db, $table, true); + } +} + +$rownum = 0; +$columns_list = array(); +$save_row = array(); +$odd_row = true; +foreach ($fields as $row) { + $save_row[] = $row; + $rownum++; + $columns_list[] = $row['Field']; + + $type = $row['Type']; + $extracted_columnspec = PMA_Util::extractColumnSpec($row['Type']); + + if ('set' == $extracted_columnspec['type'] + || 'enum' == $extracted_columnspec['type'] + ) { + $type_nowrap = ''; + } else { + $type_nowrap = ' class="nowrap"'; + } + $type = $extracted_columnspec['print_type']; + if (empty($type)) { + $type = ' '; + } + + $field_charset = ''; + if ($extracted_columnspec['can_contain_collation'] + && ! empty($row['Collation']) + ) { + $field_charset = $row['Collation']; + } + + // Display basic mimetype [MIME] + if ($cfgRelation['commwork'] + && $cfgRelation['mimework'] + && $cfg['BrowseMIME'] + && isset($mime_map[$row['Field']]['mimetype']) + ) { + $type_mime = '
MIME: ' + . str_replace('_', '/', $mime_map[$row['Field']]['mimetype']); + } else { + $type_mime = ''; + } + + $attribute = $extracted_columnspec['attribute']; + + // prepare a common variable to reuse below; however, + // in case of a VIEW, $analyzed_sql[0]['create_table_fields'] is empty + if (isset($analyzed_sql[0]['create_table_fields'][$row['Field']])) { + $tempField = $analyzed_sql[0]['create_table_fields'][$row['Field']]; + } else { + $tempField = array(); + } + + // MySQL 4.1.2+ TIMESTAMP options + // (if on_update_current_timestamp is set, then it's TRUE) + if (isset($tempField['on_update_current_timestamp'])) { + $attribute = 'on update CURRENT_TIMESTAMP'; + } + + // here, we have a TIMESTAMP that SHOW FULL COLUMNS reports as having the + // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe + // the latter. + if (! empty($tempField['type']) + && $tempField['type'] == 'TIMESTAMP' + && $tempField['timestamp_not_null'] + ) { + $row['Null'] = ''; + } + + + if (! isset($row['Default'])) { + if ($row['Null'] == 'YES') { + $row['Default'] = 'NULL'; + } + } else { + $row['Default'] = htmlspecialchars($row['Default']); + } + + $field_encoded = urlencode($row['Field']); + $field_name = htmlspecialchars($row['Field']); + $displayed_field_name = $field_name; + + // underline commented fields and display a hover-title (CSS only) + + if (isset($comments_map[$row['Field']])) { + $displayed_field_name = '' + . $field_name . ''; + } + + if ($primary && $primary->hasColumn($field_name)) { + $displayed_field_name = '' . $field_name . ''; + } + $response->addHTML( + '' + ); + $odd_row = !$odd_row; + + $response->addHTML( + PMA_getHtmlTableStructureRow( + $row, $rownum, $displayed_field_name, + $type_nowrap, $extracted_columnspec, $type_mime, + $field_charset, $attribute, $tbl_is_view, + $db_is_information_schema, $url_query, $field_encoded, $titles, $table + ) + ); + + if (! $tbl_is_view && ! $db_is_information_schema) { + $response->addHTML( + PMA_getHtmlForActionsInTableStructure( + $type, $tbl_storage_engine, $primary, + $field_name, $url_query, $titles, $row, $rownum, + $hidden_titles, $columns_with_unique_index + ) + ); + } // end if (! $tbl_is_view && ! $db_is_information_schema) + + $response->addHTML(''); + + unset($field_charset); +} // end foreach + +$response->addHTML('
'); + +$response->addHTML( + PMA_getHtmlForCheckAllTableColumn( + $pmaThemeImage, $text_dir, $tbl_is_view, + $db_is_information_schema, $tbl_storage_engine + ) +); + +$response->addHTML( + '
' +); +$response->addHTML( + PMA_getHtmlDivForMoveColumnsDialog() +); + +/** + * Work on the table + */ + +if ($tbl_is_view) { + $response->addHTML(PMA_getHtmlForEditView($url_params)); +} +$response->addHTML( + PMA_getHtmlForOptionalActionLinks( + $url_query, $tbl_is_view, $db_is_information_schema, + $tbl_storage_engine, $cfgRelation + ) +); + +if (! $tbl_is_view && ! $db_is_information_schema) { + $response->addHTML('
'); + $response->addHTML(PMA_getHtmlForAddColumn($columns_list)); + $response->addHTML( + '
' + ); +} + +/** + * Displays indexes + */ + +if (! $tbl_is_view + && ! $db_is_information_schema + && 'ARCHIVE' != $tbl_storage_engine +) { + $response->addHTML(PMA_getHtmlForDisplayIndexes()); +} + +/** + * Displays Space usage and row statistics + */ +// BEGIN - Calc Table Space +// Get valid statistics whatever is the table type +if ($cfg['ShowStats']) { + $response->addHTML( + PMA_getHtmlForDisplayTableStats( + $showtable, $table_info_num_rows, $tbl_is_view, + $db_is_information_schema, $tbl_storage_engine, + $url_query, $tbl_collation + ) + ); +} +// END - Calc Table Space + +$response->addHTML( + '
' +); +?> diff --git a/libraries/structure.lib.php b/libraries/structure.lib.php index 0574471a21..9121a59207 100644 --- a/libraries/structure.lib.php +++ b/libraries/structure.lib.php @@ -2505,4 +2505,54 @@ function PMA_moveColumns($db, $table) } exit; } + +/** + * Get columns with unique index + * + * @param string $db database name + * @param string $table tablename + * + * @return array $columns_with_unique_index An array of columns with unique index, + * with $column name as the array key + */ +function PMA_getColumnsWithUniqueIndex($db ,$table) +{ + $columns_with_unique_index = array(); + foreach (PMA_Index::getFromTable($table, $db) as $index) { + if ($index->isUnique() && $index->getChoice() == 'UNIQUE') { + $columns = $index->getColumns(); + foreach ($columns as $column_name => $dummy) { + $columns_with_unique_index[$column_name] = 1; + } + } + } + return $columns_with_unique_index; +} + +/** + * Check column names for MySQL reserved words + * + * @param string $db database name + * @param string $table tablename + * + * @return array $messages array of PMA_Messages + */ +function PMA_getReservedWordColumnNameMessages($db ,$table) +{ + $messages = array(); + if ($GLOBALS['cfg']['ReservedWordDisableWarning'] === false) { + $pma_table = new PMA_Table($table, $db); + $columns = $pma_table->getReservedColumnNames(); + if (!empty($columns)) { + foreach ($columns as $column) { + $msg = PMA_message::notice( + __('The column name \'%s\' is a MySQL reserved keyword.') + ); + $msg->addParam($column); + $messages[] = $msg; + } + } + } + return $messages; +} ?> diff --git a/tbl_structure.php b/tbl_structure.php index 0f10ea2ffd..6862097e64 100644 --- a/tbl_structure.php +++ b/tbl_structure.php @@ -140,19 +140,8 @@ $url_params['goto'] = 'tbl_structure.php'; $url_params['back'] = 'tbl_structure.php'; // Check column names for MySQL reserved words -if ($cfg['ReservedWordDisableWarning'] === false) { - $pma_table = new PMA_Table($table, $db); - $columns = $pma_table->getReservedColumnNames(); - if (! empty($columns)) { - foreach ($columns as $column) { - $msg = PMA_message::notice( - __('The column name \'%s\' is a MySQL reserved keyword.') - ); - $msg->addParam($column); - $response->addHTML($msg); - } - } -} +$reserved_word_column_messages = PMA_getReservedWordColumnNameMessages($db ,$table); +$response->addHTML($reserved_word_column_messages); /** * Prepares the table structure display @@ -170,16 +159,7 @@ require_once 'libraries/Index.class.php'; // @todo should be: $server->db($db)->table($table)->primary() $primary = PMA_Index::getPrimary($table, $db); -$columns_with_unique_index = array(); -foreach (PMA_Index::getFromTable($table, $db) as $index) { - if ($index->isUnique() && $index->getChoice() == 'UNIQUE') { - $columns = $index->getColumns(); - foreach ($columns as $column_name => $dummy) { - $columns_with_unique_index[$column_name] = 1; - } - } -} -unset($index, $columns, $column_name, $dummy); +$columns_with_unique_index = PMA_getColumnsWithUniqueIndex($db ,$table); // 3. Get fields $fields = (array) PMA_DBI_getColumns($db, $table, null, true); @@ -211,252 +191,7 @@ $titles = PMA_getActionTitlesArray(); // hidden action titles (image and string) $hidden_titles = PMA_getHiddenTitlesArray(); -/** - * Displays the table structure ('show table' works correct since 3.23.03) - */ -/* TABLE INFORMATION */ -// table header - - -$HideStructureActions = ''; -if ($GLOBALS['cfg']['PropertiesIconic'] !== true - && $GLOBALS['cfg']['HideStructureActions'] === true -) { - $HideStructureActions .= ' HideStructureActions'; -} - -$html_form = '
'; - -$response->addHTML($html_form); -$response->addHTML(PMA_generate_common_hidden_inputs($db, $table)); - -$tabletype = ''; -} else if ($tbl_is_view) { - $tabletype .= '"view" />'; -} else { - $tabletype .= '"table" />'; -} -$response->addHTML($tabletype); - -$tablestructure = ''; -$response->addHTML($tablestructure); - - -$response->addHTML( - PMA_getHtmlForTableStructureHeader( - $db_is_information_schema, - $tbl_is_view - ) -); - -$response->addHTML(''); - -// table body - -// prepare comments -$comments_map = array(); -$mime_map = array(); - -if ($GLOBALS['cfg']['ShowPropertyComments']) { - include_once 'libraries/transformations.lib.php'; - $comments_map = PMA_getComments($db, $table); - if ($cfgRelation['mimework'] && $cfg['BrowseMIME']) { - $mime_map = PMA_getMIME($db, $table, true); - } -} - -$rownum = 0; -$columns_list = array(); -$save_row = array(); -$odd_row = true; -foreach ($fields as $row) { - $save_row[] = $row; - $rownum++; - $columns_list[] = $row['Field']; - - $type = $row['Type']; - $extracted_columnspec = PMA_Util::extractColumnSpec($row['Type']); - - if ('set' == $extracted_columnspec['type'] - || 'enum' == $extracted_columnspec['type'] - ) { - $type_nowrap = ''; - } else { - $type_nowrap = ' class="nowrap"'; - } - $type = $extracted_columnspec['print_type']; - if (empty($type)) { - $type = ' '; - } - - $field_charset = ''; - if ($extracted_columnspec['can_contain_collation'] - && ! empty($row['Collation']) - ) { - $field_charset = $row['Collation']; - } - - // Display basic mimetype [MIME] - if ($cfgRelation['commwork'] - && $cfgRelation['mimework'] - && $cfg['BrowseMIME'] - && isset($mime_map[$row['Field']]['mimetype']) - ) { - $type_mime = '
MIME: ' - . str_replace('_', '/', $mime_map[$row['Field']]['mimetype']); - } else { - $type_mime = ''; - } - - $attribute = $extracted_columnspec['attribute']; - - // prepare a common variable to reuse below; however, - // in case of a VIEW, $analyzed_sql[0]['create_table_fields'] is empty - if (isset($analyzed_sql[0]['create_table_fields'][$row['Field']])) { - $tempField = $analyzed_sql[0]['create_table_fields'][$row['Field']]; - } else { - $tempField = array(); - } - - // MySQL 4.1.2+ TIMESTAMP options - // (if on_update_current_timestamp is set, then it's TRUE) - if (isset($tempField['on_update_current_timestamp'])) { - $attribute = 'on update CURRENT_TIMESTAMP'; - } - - // here, we have a TIMESTAMP that SHOW FULL COLUMNS reports as having the - // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe - // the latter. - if (! empty($tempField['type']) - && $tempField['type'] == 'TIMESTAMP' - && $tempField['timestamp_not_null'] - ) { - $row['Null'] = ''; - } - - - if (! isset($row['Default'])) { - if ($row['Null'] == 'YES') { - $row['Default'] = 'NULL'; - } - } else { - $row['Default'] = htmlspecialchars($row['Default']); - } - - $field_encoded = urlencode($row['Field']); - $field_name = htmlspecialchars($row['Field']); - $displayed_field_name = $field_name; - - // underline commented fields and display a hover-title (CSS only) - - if (isset($comments_map[$row['Field']])) { - $displayed_field_name = '' - . $field_name . ''; - } - - if ($primary && $primary->hasColumn($field_name)) { - $displayed_field_name = '' . $field_name . ''; - } - $response->addHTML( - '' - ); - $odd_row = !$odd_row; - - $response->addHTML( - PMA_getHtmlTableStructureRow( - $row, $rownum, $displayed_field_name, - $type_nowrap, $extracted_columnspec, $type_mime, - $field_charset, $attribute, $tbl_is_view, - $db_is_information_schema, $url_query, $field_encoded, $titles, $table - ) - ); - - if (! $tbl_is_view && ! $db_is_information_schema) { - $response->addHTML( - PMA_getHtmlForActionsInTableStructure( - $type, $tbl_storage_engine, $primary, - $field_name, $url_query, $titles, $row, $rownum, - $hidden_titles, $columns_with_unique_index - ) - ); - } // end if (! $tbl_is_view && ! $db_is_information_schema) - - $response->addHTML(''); - - unset($field_charset); -} // end foreach - -$response->addHTML('
'); - -$response->addHTML( - PMA_getHtmlForCheckAllTableColumn( - $pmaThemeImage, $text_dir, $tbl_is_view, - $db_is_information_schema, $tbl_storage_engine - ) -); - -$response->addHTML( - '

' -); -$response->addHTML( - PMA_getHtmlDivForMoveColumnsDialog() -); - -/** - * Work on the table - */ - -if ($tbl_is_view) { - $response->addHTML(PMA_getHtmlForEditView($url_params)); -} -$response->addHTML( - PMA_getHtmlForOptionalActionLinks( - $url_query, $tbl_is_view, $db_is_information_schema, - $tbl_storage_engine, $cfgRelation - ) -); - -if (! $tbl_is_view && ! $db_is_information_schema) { - $response->addHTML('
'); - $response->addHTML(PMA_getHtmlForAddColumn($columns_list)); - $response->addHTML( - '
' - ); -} - -/** - * Displays indexes - */ - -if (! $tbl_is_view - && ! $db_is_information_schema - && 'ARCHIVE' != $tbl_storage_engine -) { - $response->addHTML(PMA_getHtmlForDisplayIndexes()); -} - -/** - * Displays Space usage and row statistics - */ -// BEGIN - Calc Table Space -// Get valid statistics whatever is the table type -if ($cfg['ShowStats']) { - $response->addHTML( - PMA_getHtmlForDisplayTableStats( - $showtable, $table_info_num_rows, $tbl_is_view, - $db_is_information_schema, $tbl_storage_engine, - $url_query, $tbl_collation - ) - ); -} -// END - Calc Table Space - -$response->addHTML( - '
' -); +//display table structure +require_once 'libraries/display_structure.lib.php'; ?>