3 // vim: expandtab sw=4 ts=4 sts=4:
7 * Gets some core libraries
9 require('./libraries/grab_globals.lib.php3');
10 require('./libraries/common.lib.php3');
14 * Initializes some variables
16 // Defines the url to return in case of success of the query
17 if (isset($sql_query)) {
18 $sql_query = urldecode($sql_query);
20 if (!isset($dontlimitchars)) {
24 if (isset($after_insert) && $after_insert == 'new_insert') {
25 $goto = 'tbl_change.php3'
27 . '&convcharset=' . $convcharset
28 . '&server=' . $server
29 . '&db=' . urlencode($db)
30 . '&table=' . urlencode($table)
31 . '&goto=' . urlencode($goto)
33 . '&session_max_rows=' . $session_max_rows
34 . '&disp_direction=' . $disp_direction
35 . '&repeat_cells=' . $repeat_cells
36 . '&dontlimitchars=' . $dontlimitchars
37 . (empty($sql_query) ?
'' : '&sql_query=' . urlencode($sql_query));
38 } else if ($goto == 'sql.php3') {
41 . '&convcharset=' . $convcharset
42 . '&server=' . $server
43 . '&db=' . urlencode($db)
44 . '&table=' . urlencode($table)
46 . '&session_max_rows=' . $session_max_rows
47 . '&disp_direction=' . $disp_direction
48 . '&repeat_cells=' . $repeat_cells
49 . '&dontlimitchars=' . $dontlimitchars
50 . '&sql_query=' . urlencode($sql_query);
51 } else if (!empty($goto)) {
53 $is_gotofile = ereg_replace('^([^?]+).*$', '\\1', $goto);
54 if (!@file_exists
('./' . $is_gotofile)) {
55 $goto = (empty($table)) ?
'db_details.php3' : 'tbl_properties.php3';
58 $is_gotofile = ($is_gotofile == $goto);
62 // Defines the url to return in case of failure of the query
63 if (isset($err_url)) {
64 $err_url = urldecode($err_url);
66 $err_url = str_replace('&', '&', $goto)
67 . (empty($primary_key) ?
'' : '&primary_key=' . $primary_key);
70 // Resets tables defined in the configuration file
77 if (get_magic_quotes_gpc()) {
78 $submit_type = stripslashes($submit_type);
83 * Prepares the update of a row
85 if (isset($primary_key) && ($submit_type != $strInsertAsNewRow)) {
86 // Restore the "primary key" to a convenient format
87 $primary_key = urldecode($primary_key);
89 // Defines the SET part of the sql query
91 while (list($key, $val) = each($fields)) {
93 $key = urldecode($key);
95 switch (strtolower($val)) {
99 // if we have an enum, then construct the value
100 $f = 'field_' . md5($key);
102 $val = implode(',', $
$f);
103 if ($val == 'null') {
106 $val = "'" . PMA_sqlAddslashes(urldecode($val)) . "'";
113 // if we have a set, then construct the value
114 $f = 'field_' . md5($key);
116 $val = implode(',', $
$f);
117 $val = "'" . PMA_sqlAddslashes(urldecode($val)) . "'";
123 // if we have a foreign key, then construct the value
124 $f = 'field_' . md5($key);
126 $val = implode(',', $
$f);
127 if ($val == 'null') {
130 $val = "'" . PMA_sqlAddslashes(urldecode($val)) . "'";
137 if (get_magic_quotes_gpc()) {
138 $val = "'" . str_replace('\\"', '"', $val) . "'";
140 $val = "'" . PMA_sqlAddslashes($val) . "'";
145 // Was the Null checkbox checked for this field?
146 // (if there is a value, we ignore the Null checkbox: this could
147 // be possible if Javascript is disabled in the browser)
148 if (isset($fields_null) && isset($fields_null[$encoded_key])
153 // No change for this column and no MySQL function is used -> next column
154 if (empty($funcs[$encoded_key])
155 && isset($fields_prev) && isset($fields_prev[$encoded_key])
156 && ("'" . PMA_sqlAddslashes(urldecode($fields_prev[$encoded_key])) . "'" == $val)) {
159 else if (!empty($val)) {
160 if (empty($funcs[$encoded_key])) {
161 $valuelist .= PMA_backquote($key) . ' = ' . $val . ', ';
162 } else if ($val == '\'\''
163 && (ereg('^(NOW|CURDATE|CURTIME|UNIX_TIMESTAMP|RAND|USER|LAST_INSERT_ID)$', $funcs[$encoded_key]))) {
164 $valuelist .= PMA_backquote($key) . ' = ' . $funcs[$encoded_key] . '(), ';
166 $valuelist .= PMA_backquote($key) . ' = ' . $funcs[$encoded_key] . "($val), ";
171 // Builds the sql update query
172 $valuelist = ereg_replace(', $', '', $valuelist);
173 if (!empty($valuelist)) {
174 $query = 'UPDATE ' . PMA_backquote($table) . ' SET ' . $valuelist . ' WHERE' . $primary_key
175 . ((PMA_MYSQL_INT_VERSION
>= 32300) ?
' LIMIT 1' : '');
176 $message = $strAffectedRows . ' ';
178 // No change -> move back to the calling script
180 $message = $strNoModification;
182 $js_to_run = 'functions.js';
183 include('./header.inc.php3');
184 include('./' . ereg_replace('\.\.*', '.', $goto));
186 header('Location: ' . $cfg['PmaAbsoluteUri'] . $goto . '&message=' . urlencode($message));
194 * Prepares the insert of a row
199 while (list($key, $val) = each($fields)) {
201 $key = urldecode($key);
202 $fieldlist .= PMA_backquote($key) . ', ';
204 switch (strtolower($val)) {
208 // if we have a set, then construct the value
209 $f = 'field_' . md5($key);
211 $val = implode(',', $
$f);
212 if ($val == 'null') {
215 $val = "'" . PMA_sqlAddslashes(urldecode($val)) . "'";
222 // if we have a set, then construct the value
223 $f = 'field_' . md5($key);
225 $val = implode(',', $
$f);
226 $val = "'" . PMA_sqlAddslashes(urldecode($val)) . "'";
232 // if we have a foreign key, then construct the value
233 $f = 'field_' . md5($key);
235 $val = implode(',', $
$f);
236 if ($val == 'null') {
239 $val = "'" . PMA_sqlAddslashes(urldecode($val)) . "'";
246 if (get_magic_quotes_gpc()) {
247 $val = "'" . str_replace('\\"', '"', $val) . "'";
249 $val = "'" . PMA_sqlAddslashes($val) . "'";
254 // Was the Null checkbox checked for this field?
255 // (if there is a value, we ignore the Null checkbox: this could
256 // be possible if Javascript is disabled in the browser)
257 if (isset($fields_null) && isset($fields_null[$encoded_key])
262 if (empty($funcs[$encoded_key])) {
263 $valuelist .= $val . ', ';
264 } else if (($val == '\'\''
265 && ereg('^(UNIX_TIMESTAMP|RAND|LAST_INSERT_ID)$', $funcs[$encoded_key]))
266 ||
ereg('^(NOW|CURDATE|CURTIME|USER)$', $funcs[$encoded_key])) {
267 $valuelist .= $funcs[$encoded_key] . '(), ';
269 $valuelist .= $funcs[$encoded_key] . '(' . $val . '), ';
273 // Builds the sql insert query
274 $fieldlist = ereg_replace(', $', '', $fieldlist);
275 $valuelist = ereg_replace(', $', '', $valuelist);
276 $query = 'INSERT INTO ' . PMA_backquote($table) . ' (' . $fieldlist . ') VALUES (' . $valuelist . ')';
277 $message = $strInsertedRows . ' ';
278 } // end row insertion
282 * Executes the sql query and get the result, then move back to the calling
285 PMA_mysql_select_db($db);
286 $sql_query = $query . ';';
287 $result = PMA_mysql_query($query);
290 $error = PMA_mysql_error();
291 include('./header.inc.php3');
292 PMA_mysqlDie($error, '', '', $err_url);
294 if (@mysql_affected_rows
()) {
295 $message .= @mysql_affected_rows
();
297 $message = $strModifications;
300 if ($goto == 'db_details.php3' && !empty($table)) {
303 $js_to_run = 'functions.js';
304 include('./header.inc.php3');
305 include('./' . ereg_replace('\.\.*', '.', $goto));
307 $add_query = (strpos(' ' . $goto, 'tbl_change') ?
'&disp_query=' . urlencode($sql_query) : '');
308 header('Location: ' . $cfg['PmaAbsoluteUri'] . $goto . '&message=' . urlencode($message) . $add_query);