6 * Gets some core libraries
8 require('./libraries/grab_globals.lib.php3');
9 require('./libraries/common.lib.php3');
13 * Initializes some variables
15 // Defines the url to return in case of success of the query
16 if (isset($sql_query)) {
17 $sql_query = urldecode($sql_query);
20 if (isset($after_insert) && $after_insert == 'new_insert') {
21 $goto = 'tbl_change.php3'
23 . '&convcharset=' . $convcharset
24 . '&server=' . $server
25 . '&db=' . urlencode($db)
26 . '&table=' . urlencode($table)
27 . '&goto=' . urlencode($goto)
29 . '&session_max_rows=' . $session_max_rows
30 . '&disp_direction=' . $disp_direction
31 . '&repeat_cells=' . $repeat_cells
32 . (empty($sql_query) ?
'' : '&sql_query=' . urlencode($sql_query));
33 } else if ($goto == 'sql.php3') {
36 . '&convcharset=' . $convcharset
37 . '&server=' . $server
38 . '&db=' . urlencode($db)
39 . '&table=' . urlencode($table)
41 . '&session_max_rows=' . $session_max_rows
42 . '&disp_direction=' . $disp_direction
43 . '&repeat_cells=' . $repeat_cells
44 . '&sql_query=' . urlencode($sql_query);
45 } else if (!empty($goto)) {
47 $is_gotofile = ereg_replace('^([^?]+).*$', '\\1', $goto);
48 if (!@file_exists
('./' . $is_gotofile)) {
49 $goto = (empty($table)) ?
'db_details.php3' : 'tbl_properties.php3';
52 $is_gotofile = ($is_gotofile == $goto);
56 // Defines the url to return in case of failure of the query
57 if (isset($err_url)) {
58 $err_url = urldecode($err_url);
60 $err_url = str_replace('&', '&', $goto)
61 . (empty($primary_key) ?
'' : '&primary_key=' . $primary_key);
64 // Resets tables defined in the configuration file
71 if (get_magic_quotes_gpc()) {
72 $submit_type = stripslashes($submit_type);
77 * Prepares the update of a row
79 if (isset($primary_key) && ($submit_type != $strInsertAsNewRow)) {
80 // Restore the "primary key" to a convenient format
81 $primary_key = urldecode($primary_key);
83 // Defines the SET part of the sql query
85 while (list($key, $val) = each($fields)) {
87 $key = urldecode($key);
89 switch (strtolower($val)) {
93 // if we have an enum, then construct the value
94 $f = 'field_' . md5($key);
96 $val = implode(',', $
$f);
100 $val = "'" . PMA_sqlAddslashes(urldecode($val)) . "'";
107 // if we have a set, then construct the value
108 $f = 'field_' . md5($key);
110 $val = implode(',', $
$f);
111 $val = "'" . PMA_sqlAddslashes(urldecode($val)) . "'";
117 if (get_magic_quotes_gpc()) {
118 $val = "'" . str_replace('\\"', '"', $val) . "'";
120 $val = "'" . PMA_sqlAddslashes($val) . "'";
125 // Was the Null checkbox checked for this field?
126 if (isset($fields_null) && isset($fields_null[$encoded_key])) {
130 // No change for this column and no MySQL function is used -> next column
131 if (empty($funcs[$encoded_key])
132 && isset($fields_prev) && isset($fields_prev[$encoded_key])
133 && ("'" . PMA_sqlAddslashes(urldecode($fields_prev[$encoded_key])) . "'" == $val)) {
136 else if (!empty($val)) {
137 if (empty($funcs[$encoded_key])) {
138 $valuelist .= PMA_backquote($key) . ' = ' . $val . ', ';
139 } else if ($val == '\'\''
140 && (ereg('^(NOW|CURDATE|CURTIME|UNIX_TIMESTAMP|RAND|USER|LAST_INSERT_ID)$', $funcs[$encoded_key]))) {
141 $valuelist .= PMA_backquote($key) . ' = ' . $funcs[$encoded_key] . '(), ';
143 $valuelist .= PMA_backquote($key) . ' = ' . $funcs[$encoded_key] . "($val), ";
148 // Builds the sql upate query
149 $valuelist = ereg_replace(', $', '', $valuelist);
150 if (!empty($valuelist)) {
151 $query = 'UPDATE ' . PMA_backquote($table) . ' SET ' . $valuelist . ' WHERE' . $primary_key
152 . ((PMA_MYSQL_INT_VERSION
>= 32300) ?
' LIMIT 1' : '');
153 $message = $strAffectedRows . ' ';
155 // No change -> move back to the calling script
157 $message = $strNoModification;
159 $js_to_run = 'functions.js';
160 include('./header.inc.php3');
161 include('./' . ereg_replace('\.\.*', '.', $goto));
163 header('Location: ' . $cfg['PmaAbsoluteUri'] . $goto . '&message=' . urlencode($message));
171 * Prepares the insert of a row
176 while (list($key, $val) = each($fields)) {
178 $key = urldecode($key);
179 $fieldlist .= PMA_backquote($key) . ', ';
181 switch (strtolower($val)) {
185 // if we have a set, then construct the value
186 $f = 'field_' . md5($key);
188 $val = implode(',', $
$f);
189 if ($val == 'null') {
192 $val = "'" . PMA_sqlAddslashes(urldecode($val)) . "'";
199 // if we have a set, then construct the value
200 $f = 'field_' . md5($key);
202 $val = implode(',', $
$f);
203 $val = "'" . PMA_sqlAddslashes(urldecode($val)) . "'";
209 if (get_magic_quotes_gpc()) {
210 $val = "'" . str_replace('\\"', '"', $val) . "'";
212 $val = "'" . PMA_sqlAddslashes($val) . "'";
217 // Was the Null checkbox checked for this field?
218 if (isset($fields_null) && isset($fields_null[$encoded_key])) {
222 if (empty($funcs[$encoded_key])) {
223 $valuelist .= $val . ', ';
224 } else if (($val == '\'\''
225 && ereg('^(UNIX_TIMESTAMP|RAND|LAST_INSERT_ID)$', $funcs[$encoded_key]))
226 ||
ereg('^(NOW|CURDATE|CURTIME|USER)$', $funcs[$encoded_key])) {
227 $valuelist .= $funcs[$encoded_key] . '(), ';
229 $valuelist .= $funcs[$encoded_key] . '(' . $val . '), ';
233 // Builds the sql insert query
234 $fieldlist = ereg_replace(', $', '', $fieldlist);
235 $valuelist = ereg_replace(', $', '', $valuelist);
236 $query = 'INSERT INTO ' . PMA_backquote($table) . ' (' . $fieldlist . ') VALUES (' . $valuelist . ')';
237 $message = $strInsertedRows . ' ';
238 } // end row insertion
242 * Executes the sql query and get the result, then move back to the calling
245 PMA_mysql_select_db($db);
246 $sql_query = $query . ';';
247 $result = PMA_mysql_query($query);
250 $error = PMA_mysql_error();
251 include('./header.inc.php3');
252 PMA_mysqlDie($error, '', '', $err_url);
254 if (@mysql_affected_rows
()) {
255 $message .= @mysql_affected_rows
();
257 $message = $strModifications;
260 if ($goto == 'db_details.php3' && !empty($table)) {
263 $js_to_run = 'functions.js';
264 include('./header.inc.php3');
265 include('./' . ereg_replace('\.\.*', '.', $goto));
267 $add_query = (strpos(' ' . $goto, 'tbl_change') ?
'&disp_query=' . urlencode($sql_query) : '');
268 header('Location: ' . $cfg['PmaAbsoluteUri'] . $goto . '&message=' . urlencode($message) . $add_query);