Merge pull request #573 from ayushchd/codestyle_fixes
[phpmyadmin.git] / tbl_structure.php
blob1f18dedaa0253604eeaf4a34374c969fb38a1ae1
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Displays table structure infos like columns, indexes, size, rows
5 * and allows manipulation of indexes and columns
7 * @package PhpMyAdmin
8 */
10 /**
13 require_once 'libraries/common.inc.php';
14 require_once 'libraries/mysql_charsets.inc.php';
16 /**
17 * Function implementations for this script
19 require_once 'libraries/structure.lib.php';
20 require_once 'libraries/index.lib.php';
21 require_once 'libraries/sql.lib.php';
22 require_once 'libraries/bookmark.lib.php';
24 $response = PMA_Response::getInstance();
25 $header = $response->getHeader();
26 $scripts = $header->getScripts();
27 $scripts->addFile('tbl_structure.js');
28 $scripts->addFile('indexes.js');
30 /**
31 * Handle column moving
33 if (isset($_REQUEST['move_columns'])
34 && is_array($_REQUEST['move_columns'])
35 && $response->isAjax()
36 ) {
37 PMA_moveColumns($db, $table);
38 exit;
41 /**
42 * A click on Change has been made for one column
44 if (isset($_REQUEST['change_column'])) {
45 PMA_displayHtmlForColumnChange($db, $table, null, 'tbl_structure.php');
46 exit;
48 /**
49 * Modifications have been submitted -> updates the table
51 if (isset($_REQUEST['do_save_data'])) {
52 $regenerate = PMA_updateColumns($db, $table);
53 if ($regenerate) {
54 // This happens when updating failed
55 // @todo: do something appropriate
56 } else {
57 // continue to show the table's structure
58 unset($_REQUEST['selected']);
62 /**
63 * handle multiple field commands if required
65 * submit_mult_*_x comes from IE if <input type="img" ...> is used
67 if (isset($_REQUEST['submit_mult_change_x'])) {
68 $submit_mult = 'change';
69 } elseif (isset($_REQUEST['submit_mult_drop_x'])) {
70 $submit_mult = 'drop';
71 } elseif (isset($_REQUEST['submit_mult_primary_x'])) {
72 $submit_mult = 'primary';
73 } elseif (isset($_REQUEST['submit_mult_index_x'])) {
74 $submit_mult = 'index';
75 } elseif (isset($_REQUEST['submit_mult_unique_x'])) {
76 $submit_mult = 'unique';
77 } elseif (isset($_REQUEST['submit_mult_spatial_x'])) {
78 $submit_mult = 'spatial';
79 } elseif (isset($_REQUEST['submit_mult_fulltext_x'])) {
80 $submit_mult = 'ftext';
81 } elseif (isset($_REQUEST['submit_mult_browse_x'])) {
82 $submit_mult = 'browse';
83 } elseif (isset($_REQUEST['submit_mult'])) {
84 $submit_mult = $_REQUEST['submit_mult'];
85 } elseif (isset($_REQUEST['mult_btn']) && $_REQUEST['mult_btn'] == __('Yes')) {
86 $submit_mult = 'row_delete';
87 if (isset($_REQUEST['selected'])) {
88 $_REQUEST['selected_fld'] = $_REQUEST['selected'];
91 if (! empty($submit_mult)) {
92 if (isset($_REQUEST['selected_fld'])) {
93 $err_url = 'tbl_structure.php?' . PMA_URL_getCommon($db, $table);
94 if ($submit_mult == 'browse') {
95 // browsing the table displaying only selected columns
96 $GLOBALS['active_page'] = 'sql.php';
97 $sql_query = '';
98 foreach ($_REQUEST['selected_fld'] as $idx => $sval) {
99 if ($sql_query == '') {
100 $sql_query .= 'SELECT ' . PMA_Util::backquote($sval);
101 } else {
102 $sql_query .= ', ' . PMA_Util::backquote($sval);
105 $sql_query .= ' FROM ' . PMA_Util::backquote($db)
106 . '.' . PMA_Util::backquote($table);
108 // Parse and analyze the query
109 include_once 'libraries/parse_analyze.inc.php';
111 PMA_executeQueryAndSendQueryResponse(
112 $analyzed_sql_results, false, $db, $table, null, null, null, false,
113 null, null, null, null, $goto, $pmaThemeImage, null, null,
114 null, $sql_query, null, null
116 } else {
117 // handle multiple field commands
118 // handle confirmation of deleting multiple columns
119 $action = 'tbl_structure.php';
120 include 'libraries/mult_submits.inc.php';
122 * if $submit_mult == 'change', execution will have stopped
123 * at this point
126 if (empty($message)) {
127 $message = PMA_Message::success();
130 } else {
131 $response = PMA_Response::getInstance();
132 $response->isSuccess(false);
133 $response->addJSON('message', __('No column selected.'));
138 * Gets the relation settings
140 $cfgRelation = PMA_getRelationsParam();
143 * Runs common work
145 require_once 'libraries/tbl_common.inc.php';
146 $url_query .= '&amp;goto=tbl_structure.php&amp;back=tbl_structure.php';
147 $url_params['goto'] = 'tbl_structure.php';
148 $url_params['back'] = 'tbl_structure.php';
150 // Check column names for MySQL reserved words
151 $reserved_word_column_messages = PMA_getReservedWordColumnNameMessages($db, $table);
152 $response->addHTML($reserved_word_column_messages);
155 * Prepares the table structure display
160 * Gets tables informations
162 require_once 'libraries/tbl_info.inc.php';
164 require_once 'libraries/Index.class.php';
166 // 2. Gets table keys and retains them
167 // @todo should be: $server->db($db)->table($table)->primary()
168 $primary = PMA_Index::getPrimary($table, $db);
170 $columns_with_unique_index = PMA_getColumnsWithUniqueIndex($db, $table);
172 // 3. Get fields
173 $fields = (array) $GLOBALS['dbi']->getColumns($db, $table, null, true);
175 // Get more complete field information
176 // For now, this is done just for MySQL 4.1.2+ new TIMESTAMP options
177 // but later, if the analyser returns more information, it
178 // could be executed for any MySQL version and replace
179 // the info given by SHOW FULL COLUMNS FROM.
181 // We also need this to correctly learn if a TIMESTAMP is NOT NULL, since
182 // SHOW FULL COLUMNS or INFORMATION_SCHEMA incorrectly says NULL
183 // and SHOW CREATE TABLE says NOT NULL (tested
184 // in MySQL 4.0.25 and 5.0.21, http://bugs.mysql.com/20910).
186 $show_create_table = $GLOBALS['dbi']->fetchValue(
187 'SHOW CREATE TABLE ' . PMA_Util::backquote($db) . '.'
188 . PMA_Util::backquote($table),
189 0, 1
191 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
194 * prepare table infos
196 // action titles (image or string)
197 $titles = PMA_getActionTitlesArray();
199 // hidden action titles (image and string)
200 $hidden_titles = PMA_getHiddenTitlesArray();
202 //display table structure
203 require_once 'libraries/display_structure.lib.php';