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