Translated using Weblate (Indonesian)
[phpmyadmin.git] / tbl_structure.php
blobf5e937bd74f69c068ec384d659abedd0efe7923e
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 * handle MySQL reserved words columns check
44 if (isset($_REQUEST['reserved_word_check'])) {
45 $response = PMA_Response::getInstance();
46 if ($GLOBALS['cfg']['ReservedWordDisableWarning'] === false) {
47 $columns_names = $_REQUEST['field_name'];
48 $reserved_keywords_columns = array();
49 foreach ($columns_names as $column) {
50 if (PMA_SQP_isKeyWord($column)) {
51 $reserved_keywords_columns[] = $column;
54 if (count($reserved_keywords_columns) == 0) {
55 $response->isSuccess(false);
57 $response->addJSON(
58 'message', sprintf(
59 _ngettext(
60 'The column name \'%s\' is a MySQL reserved keyword.',
61 'The column names \'%s\' are MySQL reserved keywords.',
62 count($reserved_keywords_columns)
64 implode(',', $reserved_keywords_columns)
67 } else {
68 $response->isSuccess(false);
70 exit;
72 /**
73 * A click on Change has been made for one column
75 if (isset($_REQUEST['change_column'])) {
76 PMA_displayHtmlForColumnChange($db, $table, null, 'tbl_structure.php');
77 exit;
79 /**
80 * Modifications have been submitted -> updates the table
82 if (isset($_REQUEST['do_save_data'])) {
83 $regenerate = PMA_updateColumns($db, $table);
84 if ($regenerate) {
85 // This happens when updating failed
86 // @todo: do something appropriate
87 } else {
88 // continue to show the table's structure
89 unset($_REQUEST['selected']);
93 /**
94 * handle multiple field commands if required
96 * submit_mult_*_x comes from IE if <input type="img" ...> is used
98 $submit_mult = PMA_getMultipleFieldCommandType();
100 if (! empty($submit_mult)) {
101 if (isset($_REQUEST['selected_fld'])) {
102 if ($submit_mult == 'browse') {
103 // browsing the table displaying only selected columns
104 PMA_displayTableBrowseForSelectedColumns(
105 $db, $table, $goto, $pmaThemeImage
107 } else {
108 // handle multiple field commands
109 // handle confirmation of deleting multiple columns
110 $action = 'tbl_structure.php';
111 include 'libraries/mult_submits.inc.php';
113 * if $submit_mult == 'change', execution will have stopped
114 * at this point
117 if (empty($message)) {
118 $message = PMA_Message::success();
121 } else {
122 $response = PMA_Response::getInstance();
123 $response->isSuccess(false);
124 $response->addJSON('message', __('No column selected.'));
129 * Gets the relation settings
131 $cfgRelation = PMA_getRelationsParam();
134 * Runs common work
136 require_once 'libraries/tbl_common.inc.php';
137 $url_query .= '&amp;goto=tbl_structure.php&amp;back=tbl_structure.php';
138 $url_params['goto'] = 'tbl_structure.php';
139 $url_params['back'] = 'tbl_structure.php';
142 * Prepares the table structure display
147 * Gets tables informations
149 require_once 'libraries/tbl_info.inc.php';
151 require_once 'libraries/Index.class.php';
153 // 2. Gets table keys and retains them
154 // @todo should be: $server->db($db)->table($table)->primary()
155 $primary = PMA_Index::getPrimary($table, $db);
157 $columns_with_unique_index = PMA_getColumnsWithUniqueIndex($db, $table);
159 // 3. Get fields
160 $fields = (array) $GLOBALS['dbi']->getColumns($db, $table, null, true);
162 // Get more complete field information
163 // For now, this is done just for MySQL 4.1.2+ new TIMESTAMP options
164 // but later, if the analyser returns more information, it
165 // could be executed for any MySQL version and replace
166 // the info given by SHOW FULL COLUMNS FROM.
168 // We also need this to correctly learn if a TIMESTAMP is NOT NULL, since
169 // SHOW FULL COLUMNS or INFORMATION_SCHEMA incorrectly says NULL
170 // and SHOW CREATE TABLE says NOT NULL (tested
171 // in MySQL 4.0.25 and 5.0.21, http://bugs.mysql.com/20910).
173 $show_create_table = $GLOBALS['dbi']->fetchValue(
174 'SHOW CREATE TABLE ' . PMA_Util::backquote($db) . '.'
175 . PMA_Util::backquote($table),
176 0, 1
178 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
181 * prepare table infos
183 // action titles (image or string)
184 $titles = PMA_getActionTitlesArray();
186 // hidden action titles (image and string)
187 $hidden_titles = PMA_getHiddenTitlesArray();
189 //display table structure
190 require_once 'libraries/display_structure.inc.php';