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];
58 } else if (PMA_MYSQL_INT_VERSION
>= 40100 && $field_charset[$i] != '') {
59 $query .= ' CHARACTER SET ' . $field_charset[$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 $active_page = 'tbl_properties_structure.php3';
151 include('./tbl_properties_structure.php3');
154 PMA_mysqlDie('', '', '', $err_url, FALSE);
155 // garvin: An error happened while inserting/updating a table definition.
156 // to prevent total loss of that data, we embed the form once again.
157 // The variable $regenerate will be used to restore data in tbl_properties.inc.php3
158 if (isset($orig_field)) {
159 $field = $orig_field;
167 * No modifications yet required -> displays the table fields
169 if ($abort == FALSE) {
170 if (!isset($selected)) {
171 $selected[] = $field;
173 } else { // from a multiple submit
174 $selected_cnt = count($selected);
177 // TODO: optimize in case of multiple fields to modify
178 for ($i = 0; $i < $selected_cnt; $i++
) {
179 if (!empty($submit_mult)) {
180 $field = PMA_sqlAddslashes(urldecode($selected[$i]), TRUE);
182 $field = PMA_sqlAddslashes($selected[$i], TRUE);
184 $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db) . " LIKE '$field'";
185 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
186 $fields_meta[] = PMA_mysql_fetch_array($result);
187 mysql_free_result($result);
190 $num_fields = count($fields_meta);
191 $action = 'tbl_alter.php3';
192 include('./tbl_properties.inc.php3');
197 * Displays the footer
199 require('./footer.inc.php3');