Translated using Weblate (Italian)
[phpmyadmin.git] / tbl_structure.php
blobde949459fbb3de754b60470bc537b3d2af1d32cd
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';
15 require_once 'libraries/config/page_settings.class.php';
17 PMA_PageSettings::showGroup('TableStructure');
19 /**
20 * Function implementations for this script
22 require_once 'libraries/check_user_privileges.lib.php';
23 require_once 'libraries/structure.lib.php';
24 require_once 'libraries/index.lib.php';
25 require_once 'libraries/sql.lib.php';
26 require_once 'libraries/bookmark.lib.php';
28 $response = PMA_Response::getInstance();
29 $header = $response->getHeader();
30 $scripts = $header->getScripts();
31 $scripts->addFile('tbl_structure.js');
32 $scripts->addFile('indexes.js');
34 /**
35 * Handle column moving
37 if (isset($_REQUEST['move_columns'])
38 && is_array($_REQUEST['move_columns'])
39 && $response->isAjax()
40 ) {
41 PMA_moveColumns($db, $table);
42 exit;
45 /**
46 * handle MySQL reserved words columns check
48 if (isset($_REQUEST['reserved_word_check'])) {
49 $response = PMA_Response::getInstance();
50 if ($GLOBALS['cfg']['ReservedWordDisableWarning'] === false) {
51 $columns_names = $_REQUEST['field_name'];
52 $reserved_keywords_names = array();
53 foreach ($columns_names as $column) {
54 if (SqlParser\Context::isKeyword(trim($column), true)) {
55 $reserved_keywords_names[] = trim($column);
58 if (SqlParser\Context::isKeyword(trim($table), true)) {
59 $reserved_keywords_names[] = trim($table);
61 if (count($reserved_keywords_names) == 0) {
62 $response->isSuccess(false);
64 $response->addJSON(
65 'message', sprintf(
66 _ngettext(
67 'The name \'%s\' is a MySQL reserved keyword.',
68 'The names \'%s\' are MySQL reserved keywords.',
69 count($reserved_keywords_names)
71 implode(',', $reserved_keywords_names)
74 } else {
75 $response->isSuccess(false);
77 exit;
79 /**
80 * A click on Change has been made for one column
82 if (isset($_REQUEST['change_column'])) {
83 PMA_displayHtmlForColumnChange($db, $table, null, 'tbl_structure.php');
84 exit;
87 /**
88 * handle multiple field commands if required
90 * submit_mult_*_x comes from IE if <input type="img" ...> is used
92 $submit_mult = PMA_getMultipleFieldCommandType();
94 if (! empty($submit_mult)) {
95 if (isset($_REQUEST['selected_fld'])) {
96 if ($submit_mult == 'browse') {
97 // browsing the table displaying only selected columns
98 PMA_displayTableBrowseForSelectedColumns(
99 $db, $table, $goto, $pmaThemeImage
101 } else {
102 // handle multiple field commands
103 // handle confirmation of deleting multiple columns
104 $action = 'tbl_structure.php';
105 include 'libraries/mult_submits.inc.php';
107 * if $submit_mult == 'change', execution will have stopped
108 * at this point
111 if (empty($message)) {
112 $message = PMA_Message::success();
115 } else {
116 $response = PMA_Response::getInstance();
117 $response->isSuccess(false);
118 $response->addJSON('message', __('No column selected.'));
122 // display secondary level tabs if necessary
123 $engine = $GLOBALS['dbi']->getTable($db, $table)->sGetStatusInfo('ENGINE');
124 $response->addHTML(PMA_getStructureSecondaryTabs($engine));
125 $response->addHTML('<div id="structure_content">');
128 * Modifications have been submitted -> updates the table
130 if (isset($_REQUEST['do_save_data'])) {
131 $regenerate = PMA_updateColumns($db, $table);
132 if ($regenerate) {
133 // This happens when updating failed
134 // @todo: do something appropriate
135 } else {
136 // continue to show the table's structure
137 unset($_REQUEST['selected']);
142 * Adding indexes
144 if (isset($_REQUEST['add_key'])) {
145 include 'sql.php';
146 $GLOBALS['reload'] = true;
150 * Gets the relation settings
152 $cfgRelation = PMA_getRelationsParam();
155 * Runs common work
157 require_once 'libraries/tbl_common.inc.php';
158 $url_query .= '&amp;goto=tbl_structure.php&amp;back=tbl_structure.php';
159 $url_params['goto'] = 'tbl_structure.php';
160 $url_params['back'] = 'tbl_structure.php';
163 * Prepares the table structure display
168 * Gets tables information
170 require_once 'libraries/tbl_info.inc.php';
172 require_once 'libraries/Index.class.php';
174 // 2. Gets table keys and retains them
175 // @todo should be: $server->db($db)->table($table)->primary()
176 $primary = PMA_Index::getPrimary($table, $db);
177 $columns_with_index = PMA_getColumnsWithIndex(
178 $db, $table,
179 PMA_Index::UNIQUE | PMA_Index::INDEX | PMA_Index::SPATIAL | PMA_Index::FULLTEXT
181 $columns_with_unique_index = PMA_getColumnsWithIndex($db, $table, PMA_Index::UNIQUE);
183 // 3. Get fields
184 $fields = (array) $GLOBALS['dbi']->getColumns($db, $table, null, true);
186 // Get more complete field information
187 // For now, this is done just for MySQL 4.1.2+ new TIMESTAMP options
188 // but later, if the analyser returns more information, it
189 // could be executed for any MySQL version and replace
190 // the info given by SHOW FULL COLUMNS FROM.
192 // We also need this to correctly learn if a TIMESTAMP is NOT NULL, since
193 // SHOW FULL COLUMNS or INFORMATION_SCHEMA incorrectly says NULL
194 // and SHOW CREATE TABLE says NOT NULL (tested
195 // in MySQL 4.0.25 and 5.0.21, http://bugs.mysql.com/20910).
197 $tableObj = new PMA_Table($table, $db);
198 $show_create_table = $tableObj->showCreate();
199 $parser = new SqlParser\Parser($show_create_table);
202 * @var CreateStatement $stmt
204 $stmt = $parser->statements[0];
206 $create_table_fields = SqlParser\Utils\Table::getFields($stmt);
209 * prepare table infos
211 // action titles (image or string)
212 $titles = PMA_getActionTitlesArray();
214 //display table structure
215 require_once 'libraries/display_structure.inc.php';
217 $response->addHTML('</div>');