status is not a reserved word
[phpmyadmin/crack.git] / tbl_alter.php3
blob8c816f702193ba37deda28361a774707ce9380e2
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
6 /**
7 * Gets some core libraries
8 */
9 require('./libraries/grab_globals.lib.php3');
10 $js_to_run = 'functions.js';
11 include('./header.inc.php3');
14 /**
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);
20 /**
21 * Modifications have been submitted -> updates the table
23 $abort = false;
24 if (isset($submit)) {
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 "&quot;" in tbl_properties.php3
33 $field_orig[$i] = urldecode($field_orig[$i]);
34 if (strcmp(str_replace('"', '&quot;', $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('"', '&quot;', $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('"', '&quot;', $field_length_orig[$i]), $field_length[$i]) == 0) {
43 $field_length[$i] = $field_length_orig[$i];
45 if (!isset($query)) {
46 $query = '';
47 } else {
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';
62 } else {
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];
72 } // end for
74 // To allow replication, we first select the db to use and then run queries
75 // on this db.
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;
85 $btnDrop = 'Fake';
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)) {
103 @reset($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);
113 unset($table_query);
114 unset($tb_rs);
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);
124 unset($table_query);
125 unset($tb_rs);
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);
133 unset($table_query);
134 unset($tb_rs);
135 } // end if relwork
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 include('./tbl_properties_structure.php3');
149 exit();
150 } else {
151 PMA_mysqlDie('', '', '', $err_url, FALSE);
152 // garvin: An error happened while inserting/updating a table definition.
153 // to prevent total loss of that data, we embed the form once again.
154 // The variable $regenerate will be used to restore data in tbl_properties.inc.php3
155 if (isset($orig_field)) {
156 $field = $orig_field;
159 $regenerate = true;
164 * No modifications yet required -> displays the table fields
166 if ($abort == FALSE) {
167 if (!isset($selected)) {
168 $selected[] = $field;
169 $selected_cnt = 1;
170 } else { // from a multiple submit
171 $selected_cnt = count($selected);
174 // TODO: optimize in case of multiple fields to modify
175 for ($i = 0; $i < $selected_cnt; $i++) {
176 if (!empty($submit_mult)) {
177 $field = PMA_sqlAddslashes(urldecode($selected[$i]), TRUE);
178 } else {
179 $field = PMA_sqlAddslashes($selected[$i], TRUE);
181 $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db) . " LIKE '$field'";
182 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
183 $fields_meta[] = PMA_mysql_fetch_array($result);
184 mysql_free_result($result);
187 $num_fields = count($fields_meta);
188 $action = 'tbl_alter.php3';
189 include('./tbl_properties.inc.php3');
194 * Displays the footer
196 require('./footer.inc.php3');