3 // vim: expandtab sw=4 ts=4 sts=4:
5 require_once './libraries/Table.class.php';
8 * Gets some core libraries
10 require_once('./libraries/common.lib.php');
12 $js_to_run = 'functions.js';
13 require_once('./libraries/header.inc.php');
16 PMA_checkParameters(array('db', 'table'));
19 * Gets tables informations
21 require_once('./libraries/tbl_properties_common.php');
22 require_once('./libraries/tbl_properties_table_info.inc.php');
24 * Displays top menu links
26 $active_page = 'tbl_properties_structure.php';
27 // I don't see the need to display the links here, they will be displayed later
28 //require('./libraries/tbl_properties_links.inc.php');
32 * Defines the url to return to in case of error in a sql statement
34 $err_url = 'tbl_properties_structure.php?' . PMA_generate_common_url($db, $table);
38 * Modifications have been submitted -> updates the table
41 if (isset($do_save_data)) {
42 $field_cnt = count($field_orig);
43 for ($i = 0; $i < $field_cnt; $i++
) {
44 // to """ in tbl_properties.php
45 $field_orig[$i] = urldecode($field_orig[$i]);
46 if (strcmp(str_replace('"', '"', $field_orig[$i]), $field_name[$i]) == 0) {
47 $field_name[$i] = $field_orig[$i];
49 $field_default_orig[$i] = urldecode($field_default_orig[$i]);
50 if (strcmp(str_replace('"', '"', $field_default_orig[$i]), $field_default[$i]) == 0) {
51 $field_default[$i] = $field_default_orig[$i];
53 $field_length_orig[$i] = urldecode($field_length_orig[$i]);
54 if (strcmp(str_replace('"', '"', $field_length_orig[$i]), $field_length[$i]) == 0) {
55 $field_length[$i] = $field_length_orig[$i];
60 $query .= ', CHANGE ';
63 $query .= PMA_Table
::generateAlter($field_orig[$i], $field_name[$i], $field_type[$i], $field_length[$i], $field_attribute[$i], isset($field_collation[$i]) ?
$field_collation[$i] : '', $field_null[$i], $field_default[$i], isset($field_default_current_timestamp[$i]), $field_extra[$i], (isset($field_comments[$i]) ?
$field_comments[$i] : ''), $field_default_orig[$i]);
66 // To allow replication, we first select the db to use and then run queries
68 PMA_DBI_select_db($db) or PMA_mysqlDie(PMA_DBI_getError(), 'USE ' . PMA_backquote($db) . ';', '', $err_url);
69 // Optimization fix - 2 May 2001 - Robbat2
70 $sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' CHANGE ' . $query;
71 $error_create = FALSE;
72 $result = PMA_DBI_try_query($sql_query) or $error_create = TRUE;
74 if ($error_create == FALSE) {
75 $message = $strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenAltered;
78 // garvin: If comments were sent, enable relation stuff
79 require_once('./libraries/relation.lib.php');
80 require_once('./libraries/transformations.lib.php');
82 $cfgRelation = PMA_getRelationsParam();
84 // take care of pmadb internal comments here
85 // garvin: Update comment table, if a comment was set.
86 if (PMA_MYSQL_INT_VERSION
< 40100 && isset($field_comments) && is_array($field_comments) && $cfgRelation['commwork']) {
87 foreach ($field_comments AS $fieldindex => $fieldcomment) {
88 if (isset($field_name[$fieldindex]) && strlen($field_name[$fieldindex])) {
89 PMA_setComment($db, $table, $field_name[$fieldindex], $fieldcomment, $field_orig[$fieldindex], 'pmadb');
94 // garvin: Rename relations&display fields, if altered.
95 if (($cfgRelation['displaywork'] ||
$cfgRelation['relwork']) && isset($field_orig) && is_array($field_orig)) {
96 foreach ($field_orig AS $fieldindex => $fieldcontent) {
97 if ($field_name[$fieldindex] != $fieldcontent) {
98 if ($cfgRelation['displaywork']) {
99 $table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_info'])
100 . ' SET display_field = \'' . PMA_sqlAddslashes($field_name[$fieldindex]) . '\''
101 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
102 . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''
103 . ' AND display_field = \'' . PMA_sqlAddslashes($fieldcontent) . '\'';
104 $tb_rs = PMA_query_as_cu($table_query);
109 if ($cfgRelation['relwork']) {
110 $table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation'])
111 . ' SET master_field = \'' . PMA_sqlAddslashes($field_name[$fieldindex]) . '\''
112 . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\''
113 . ' AND master_table = \'' . PMA_sqlAddslashes($table) . '\''
114 . ' AND master_field = \'' . PMA_sqlAddslashes($fieldcontent) . '\'';
115 $tb_rs = PMA_query_as_cu($table_query);
119 $table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation'])
120 . ' SET foreign_field = \'' . PMA_sqlAddslashes($field_name[$fieldindex]) . '\''
121 . ' WHERE foreign_db = \'' . PMA_sqlAddslashes($db) . '\''
122 . ' AND foreign_table = \'' . PMA_sqlAddslashes($table) . '\''
123 . ' AND foreign_field = \'' . PMA_sqlAddslashes($fieldcontent) . '\'';
124 $tb_rs = PMA_query_as_cu($table_query);
128 } // end if fieldname has changed
129 } // end while check fieldnames
130 } // end if relations/display has to be changed
132 // garvin: Update comment table for mime types [MIME]
133 if (isset($field_mimetype) && is_array($field_mimetype) && $cfgRelation['commwork'] && $cfgRelation['mimework'] && $cfg['BrowseMIME']) {
134 foreach ($field_mimetype AS $fieldindex => $mimetype) {
135 if (isset($field_name[$fieldindex]) && strlen($field_name[$fieldindex])) {
136 PMA_setMIME($db, $table, $field_name[$fieldindex], $mimetype, $field_transformation[$fieldindex], $field_transformation_options[$fieldindex]);
141 $active_page = 'tbl_properties_structure.php';
142 require('./tbl_properties_structure.php');
144 PMA_mysqlDie('', '', '', $err_url, FALSE);
145 // garvin: An error happened while inserting/updating a table definition.
146 // to prevent total loss of that data, we embed the form once again.
147 // The variable $regenerate will be used to restore data in libraries/tbl_properties.inc.php
148 if (isset($orig_field)) {
149 $field = $orig_field;
157 * No modifications yet required -> displays the table fields
159 if ($abort == FALSE) {
160 if (!isset($selected)) {
161 PMA_checkParameters(array('field'));
162 $selected[] = $field;
164 } else { // from a multiple submit
165 $selected_cnt = count($selected);
168 // TODO: optimize in case of multiple fields to modify
169 for ($i = 0; $i < $selected_cnt; $i++
) {
170 if (!empty($submit_mult)) {
171 $field = PMA_sqlAddslashes(urldecode($selected[$i]), TRUE);
173 $field = PMA_sqlAddslashes($selected[$i], TRUE);
175 $result = PMA_DBI_query('SHOW FULL FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db) . ' LIKE \'' . $field . '\';');
176 $fields_meta[] = PMA_DBI_fetch_assoc($result);
177 PMA_DBI_free_result($result);
179 $num_fields = count($fields_meta);
180 $action = 'tbl_alter.php';
182 // Get more complete field information
183 // For now, this is done just for MySQL 4.1.2+ new TIMESTAMP options
184 // but later, if the analyser returns more information, it
185 // could be executed for any MySQL version and replace
186 // the info given by SHOW FULL FIELDS FROM.
187 // TODO: put this code into a require()
188 // or maybe make it part of PMA_DBI_get_fields();
190 // We also need this to correctly learn if a TIMESTAMP is NOT NULL, since
191 // SHOW FULL FIELDS says NULL and SHOW CREATE TABLE says NOT NULL (tested
194 $show_create_table = PMA_DBI_fetch_value(
195 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
197 $analyzed_sql = PMA_SQP_analyze( PMA_SQP_parse( $show_create_table ) );
199 require('./libraries/tbl_properties.inc.php');
204 * Displays the footer
206 require_once('./libraries/footer.inc.php');