3 // vim: expandtab sw=4 ts=4 sts=4:
7 * Gets some core libraries
9 require('./libraries/grab_globals.lib.php3');
10 if (!isset($submit_mult)) {
11 $js_to_run = 'functions.js';
12 include('./header.inc.php3');
17 * Defines the url to return to in case of error in a sql statement
19 $err_url = 'tbl_properties_structure.php3?' . PMA_generate_common_url($db, $table);
23 * Modifications have been submitted -> updates the table
27 $field_cnt = count($field_orig);
28 for ($i = 0; $i < $field_cnt; $i++
) {
29 if (PMA_MYSQL_INT_VERSION
< 32306) {
30 PMA_checkReservedWords($field_name[$i], $err_url);
33 // Some fields have been urlencoded or double quotes have been translated
34 // to """ in tbl_properties.php3
35 $field_orig[$i] = urldecode($field_orig[$i]);
36 if (strcmp(str_replace('"', '"', $field_orig[$i]), $field_name[$i]) == 0) {
37 $field_name[$i] = $field_orig[$i];
39 $field_default_orig[$i] = urldecode($field_default_orig[$i]);
40 if (strcmp(str_replace('"', '"', $field_default_orig[$i]), $field_default[$i]) == 0) {
41 $field_default[$i] = $field_default_orig[$i];
43 $field_length_orig[$i] = urldecode($field_length_orig[$i]);
44 if (strcmp(str_replace('"', '"', $field_length_orig[$i]), $field_length[$i]) == 0) {
45 $field_length[$i] = $field_length_orig[$i];
50 $query .= ', CHANGE ';
52 $query .= PMA_backquote($field_orig[$i]) . ' ' . PMA_backquote($field_name[$i]) . ' ' . $field_type[$i];
53 // Some field types shouldn't have lengths
54 if ($field_length[$i] != ''
55 && !eregi('^(DATE|DATETIME|TIME|TINYBLOB|TINYTEXT|BLOB|TEXT|MEDIUMBLOB|MEDIUMTEXT|LONGBLOB|LONGTEXT)$', $field_type[$i])) {
56 $query .= '(' . $field_length[$i] . ')';
58 if ($field_attribute[$i] != '') {
59 $query .= ' ' . $field_attribute[$i];
61 if ($field_default[$i] != '') {
62 if (strtoupper($field_default[$i]) == 'NULL') {
63 $query .= ' DEFAULT NULL';
65 $query .= ' DEFAULT \'' . PMA_sqlAddslashes($field_default[$i]) . '\'';
68 if ($field_null[$i] != '') {
69 $query .= ' ' . $field_null[$i];
71 if ($field_extra[$i] != '') {
72 $query .= ' ' . $field_extra[$i];
76 // To allow replication, we first select the db to use and then run queries
78 $sql_query = 'USE ' . PMA_backquote($db);
79 $result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', '', '', $err_url);
80 // Optimization fix - 2 May 2001 - Robbat2
81 $sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' CHANGE ' . $query;
82 $error_create = false;
83 $result = PMA_mysql_query($sql_query) or $error_create = true;
85 if ($error_create == false) {
86 $message = $strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenAltered;
89 // garvin: If comments were sent, enable relation stuff
90 require('./libraries/relation.lib.php3');
91 require('./libraries/transformations.lib.php3');
93 $cfgRelation = PMA_getRelationsParam();
95 // garvin: Update comment table, if a comment was set.
96 if (isset($field_comments) && is_array($field_comments) && $cfgRelation['commwork']) {
97 @reset
($field_comments);
98 while(list($fieldindex, $fieldcomment) = each($field_comments)) {
99 PMA_setComment($db, $table, $field_name[$fieldindex], $fieldcomment, $field_orig[$fieldindex]);
103 // garvin: Rename relations&display fields, if altered.
104 if (($cfgRelation['displaywork'] ||
$cfgRelation['relwork']) && isset($field_orig) && is_array($field_orig)) {
106 while(list($fieldindex, $fieldcontent) = each($field_orig)) {
107 if ($field_name[$fieldindex] != $fieldcontent) {
108 if ($cfgRelation['displaywork']) {
109 $table_query = 'UPDATE ' . PMA_backquote($cfgRelation['table_info'])
110 . ' SET display_field = \'' . PMA_sqlAddslashes($field_name[$fieldindex]) . '\''
111 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
112 . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''
113 . ' AND display_field = \'' . PMA_sqlAddslashes($fieldcontent) . '\'';
114 $tb_rs = PMA_query_as_cu($table_query);
119 if ($cfgRelation['relwork']) {
120 $table_query = 'UPDATE ' . PMA_backquote($cfgRelation['relation'])
121 . ' SET master_field = \'' . PMA_sqlAddslashes($field_name[$fieldindex]) . '\''
122 . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\''
123 . ' AND master_table = \'' . PMA_sqlAddslashes($table) . '\''
124 . ' AND master_field = \'' . PMA_sqlAddslashes($fieldcontent) . '\'';
125 $tb_rs = PMA_query_as_cu($table_query);
129 $table_query = 'UPDATE ' . PMA_backquote($cfgRelation['relation'])
130 . ' SET foreign_field = \'' . PMA_sqlAddslashes($field_name[$fieldindex]) . '\''
131 . ' WHERE foreign_db = \'' . PMA_sqlAddslashes($db) . '\''
132 . ' AND foreign_table = \'' . PMA_sqlAddslashes($table) . '\''
133 . ' AND foreign_field = \'' . PMA_sqlAddslashes($fieldcontent) . '\'';
134 $tb_rs = PMA_query_as_cu($table_query);
138 } // end if fieldname has changed
139 } // end while check fieldnames
140 } // end if relations/display has to be changed
142 // garvin: Update comment table for mime types [MIME]
143 if (isset($field_mimetype) && is_array($field_mimetype) && $cfgRelation['commwork'] && $cfgRelation['mimework'] && $cfg['BrowseMIME']) {
144 @reset
($field_mimetype);
145 while(list($fieldindex, $mimetype) = each($field_mimetype)) {
146 PMA_setMIME($db, $table, $field_name[$fieldindex], $mimetype, $field_transformation[$fieldindex], $field_transformation_options[$fieldindex]);
150 include('./tbl_properties_structure.php3');
153 PMA_mysqlDie('', '', '', $err_url, FALSE);
154 // garvin: An error happened while inserting/updating a table definition.
155 // to prevent total loss of that data, we embed the form once again.
156 // The variable $regenerate will be used to restore data in tbl_properties.inc.php3
157 if (isset($orig_field)) {
158 $field = $orig_field;
166 * No modifications yet required -> displays the table fields
168 if ($abort == FALSE) {
169 if (!isset($selected)) {
170 $selected[] = $field;
172 } else { // from a multiple submit
173 $selected_cnt = count($selected);
176 // TODO: optimize in case of multiple fields to modify
177 for ($i = 0; $i < $selected_cnt; $i++
) {
178 if (!empty($submit_mult)) {
179 $field = PMA_sqlAddslashes(urldecode($selected[$i]), TRUE);
181 $field = PMA_sqlAddslashes($selected[$i], TRUE);
183 $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db) . " LIKE '$field'";
184 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
185 $fields_meta[] = PMA_mysql_fetch_array($result);
186 mysql_free_result($result);
189 $num_fields = count($fields_meta);
190 $action = 'tbl_alter.php3';
191 include('./tbl_properties.inc.php3');
196 * Displays the footer
198 require('./footer.inc.php3');