Translated using Weblate (Dutch)
[phpmyadmin.git] / tbl_structure.php
blobb812bb60b2e394fbe72f1b3d1d15ea7282070371
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_names = array();
49 foreach ($columns_names as $column) {
50 if (PMA_SQP_isKeyWord(trim($column))) {
51 $reserved_keywords_names[] = trim($column);
54 if (PMA_SQP_isKeyWord(trim($table))) {
55 $reserved_keywords_names[] = trim($table);
57 if (count($reserved_keywords_names) == 0) {
58 $response->isSuccess(false);
60 $response->addJSON(
61 'message', sprintf(
62 _ngettext(
63 'The name \'%s\' is a MySQL reserved keyword.',
64 'The names \'%s\' are MySQL reserved keywords.',
65 count($reserved_keywords_names)
67 implode(',', $reserved_keywords_names)
70 } else {
71 $response->isSuccess(false);
73 exit;
75 /**
76 * A click on Change has been made for one column
78 if (isset($_REQUEST['change_column'])) {
79 PMA_displayHtmlForColumnChange($db, $table, null, 'tbl_structure.php');
80 exit;
83 /**
84 * handle multiple field commands if required
86 * submit_mult_*_x comes from IE if <input type="img" ...> is used
88 $submit_mult = PMA_getMultipleFieldCommandType();
90 if (! empty($submit_mult)) {
91 if (isset($_REQUEST['selected_fld'])) {
92 if ($submit_mult == 'browse') {
93 // browsing the table displaying only selected columns
94 PMA_displayTableBrowseForSelectedColumns(
95 $db, $table, $goto, $pmaThemeImage
97 } else {
98 // handle multiple field commands
99 // handle confirmation of deleting multiple columns
100 $action = 'tbl_structure.php';
101 include 'libraries/mult_submits.inc.php';
103 * if $submit_mult == 'change', execution will have stopped
104 * at this point
107 if (empty($message)) {
108 $message = PMA_Message::success();
111 } else {
112 $response = PMA_Response::getInstance();
113 $response->isSuccess(false);
114 $response->addJSON('message', __('No column selected.'));
118 // display secondary level tabs if necessary
119 $engine = PMA_Table::sGetStatusInfo($db, $table, 'ENGINE');
120 $response->addHTML(PMA_getStructureSecondaryTabs($engine));
121 $response->addHTML('<div id="structure_content">');
124 * Modifications have been submitted -> updates the table
126 if (isset($_REQUEST['do_save_data'])) {
127 $regenerate = PMA_updateColumns($db, $table);
128 if ($regenerate) {
129 // This happens when updating failed
130 // @todo: do something appropriate
131 } else {
132 // continue to show the table's structure
133 unset($_REQUEST['selected']);
138 * Adding indexes
140 if (isset($_REQUEST['add_key'])) {
141 include 'sql.php';
142 $GLOBALS['reload'] = true;
146 * Gets the relation settings
148 $cfgRelation = PMA_getRelationsParam();
151 * Runs common work
153 require_once 'libraries/tbl_common.inc.php';
154 $url_query .= '&amp;goto=tbl_structure.php&amp;back=tbl_structure.php';
155 $url_params['goto'] = 'tbl_structure.php';
156 $url_params['back'] = 'tbl_structure.php';
159 * Prepares the table structure display
164 * Gets tables informations
166 require_once 'libraries/tbl_info.inc.php';
168 require_once 'libraries/Index.class.php';
170 // 2. Gets table keys and retains them
171 // @todo should be: $server->db($db)->table($table)->primary()
172 $primary = PMA_Index::getPrimary($table, $db);
174 $columns_with_unique_index = PMA_getColumnsWithUniqueIndex($db, $table);
176 // 3. Get fields
177 $fields = (array) $GLOBALS['dbi']->getColumns($db, $table, null, true);
179 // Get more complete field information
180 // For now, this is done just for MySQL 4.1.2+ new TIMESTAMP options
181 // but later, if the analyser returns more information, it
182 // could be executed for any MySQL version and replace
183 // the info given by SHOW FULL COLUMNS FROM.
185 // We also need this to correctly learn if a TIMESTAMP is NOT NULL, since
186 // SHOW FULL COLUMNS or INFORMATION_SCHEMA incorrectly says NULL
187 // and SHOW CREATE TABLE says NOT NULL (tested
188 // in MySQL 4.0.25 and 5.0.21, http://bugs.mysql.com/20910).
190 $show_create_table = $GLOBALS['dbi']->fetchValue(
191 'SHOW CREATE TABLE ' . PMA_Util::backquote($db) . '.'
192 . PMA_Util::backquote($table),
193 0, 1
195 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
198 * prepare table infos
200 // action titles (image or string)
201 $titles = PMA_getActionTitlesArray();
203 // hidden action titles (image and string)
204 $hidden_titles = PMA_getHiddenTitlesArray();
206 //display table structure
207 require_once 'libraries/display_structure.inc.php';
209 $response->addHTML('</div>');