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?'
26 . PMA_generate_common_url($db, $table, '&')
27 . '&goto=' . urlencode($goto)
29 . '&session_max_rows=' . $session_max_rows
30 . '&disp_direction=' . $disp_direction
31 . '&repeat_cells=' . $repeat_cells
32 . '&dontlimitchars=' . $dontlimitchars
33 . (empty($sql_query) ?
'' : '&sql_query=' . urlencode($sql_query));
34 } else if ($goto == 'sql.php3') {
36 . PMA_generate_common_url($db, $table, '&')
38 . '&session_max_rows=' . $session_max_rows
39 . '&disp_direction=' . $disp_direction
40 . '&repeat_cells=' . $repeat_cells
41 . '&dontlimitchars=' . $dontlimitchars
42 . '&sql_query=' . urlencode($sql_query);
43 } else if (!empty($goto)) {
45 $is_gotofile = ereg_replace('^([^?]+).*$', '\\1', $goto);
46 if (!@file_exists
('./' . $is_gotofile)) {
47 $goto = (empty($table)) ?
'db_details.php3' : 'tbl_properties.php3';
50 $is_gotofile = ($is_gotofile == $goto);
54 // Defines the url to return in case of failure of the query
55 if (isset($err_url)) {
56 $err_url = urldecode($err_url);
58 $err_url = str_replace('&', '&', $goto)
59 . (empty($primary_key) ?
'' : '&primary_key=' . $primary_key);
62 // Resets tables defined in the configuration file
69 if (get_magic_quotes_gpc()) {
70 $submit_type = stripslashes($submit_type);
75 * Prepares the update of a row
77 if (isset($primary_key) && ($submit_type != $strInsertAsNewRow)) {
78 // Restore the "primary key" to a convenient format
79 $primary_key = urldecode($primary_key);
81 // Defines the SET part of the sql query
83 while (list($key, $val) = each($fields)) {
85 $key = urldecode($key);
87 switch (strtolower($val)) {
91 // if we have an enum, then construct the value
92 $f = 'field_' . md5($key);
94 $val = implode(',', $
$f);
98 $val = "'" . PMA_sqlAddslashes(urldecode($val)) . "'";
105 // if we have a set, then construct the value
106 $f = 'field_' . md5($key);
108 $val = implode(',', $
$f);
109 $val = "'" . PMA_sqlAddslashes(urldecode($val)) . "'";
115 // if we have a foreign key, then construct the value
116 $f = 'field_' . md5($key);
118 $val = implode(',', $
$f);
119 if ($val == 'null') {
122 $val = "'" . PMA_sqlAddslashes(urldecode($val)) . "'";
129 if (get_magic_quotes_gpc()) {
130 $val = "'" . str_replace('\\"', '"', $val) . "'";
132 $val = "'" . PMA_sqlAddslashes($val) . "'";
137 // Was the Null checkbox checked for this field?
138 // (if there is a value, we ignore the Null checkbox: this could
139 // be possible if Javascript is disabled in the browser)
140 if (isset($fields_null) && isset($fields_null[$encoded_key])
145 // No change for this column and no MySQL function is used -> next column
146 if (empty($funcs[$encoded_key])
147 && isset($fields_prev) && isset($fields_prev[$encoded_key])
148 && ("'" . PMA_sqlAddslashes(urldecode($fields_prev[$encoded_key])) . "'" == $val)) {
151 else if (!empty($val)) {
152 if (empty($funcs[$encoded_key])) {
153 $valuelist .= PMA_backquote($key) . ' = ' . $val . ', ';
154 } else if ($val == '\'\''
155 && (ereg('^(NOW|CURDATE|CURTIME|UNIX_TIMESTAMP|RAND|USER|LAST_INSERT_ID)$', $funcs[$encoded_key]))) {
156 $valuelist .= PMA_backquote($key) . ' = ' . $funcs[$encoded_key] . '(), ';
158 $valuelist .= PMA_backquote($key) . ' = ' . $funcs[$encoded_key] . "($val), ";
163 // Builds the sql update query
164 $valuelist = ereg_replace(', $', '', $valuelist);
165 if (!empty($valuelist)) {
166 $query = 'UPDATE ' . PMA_backquote($table) . ' SET ' . $valuelist . ' WHERE' . $primary_key
167 . ((PMA_MYSQL_INT_VERSION
>= 32300) ?
' LIMIT 1' : '');
168 $message = $strAffectedRows . ' ';
170 // No change -> move back to the calling script
172 $message = $strNoModification;
174 $js_to_run = 'functions.js';
175 include('./header.inc.php3');
176 include('./' . ereg_replace('\.\.*', '.', $goto));
178 header('Location: ' . $cfg['PmaAbsoluteUri'] . $goto . '&message=' . urlencode($message));
186 * Prepares the insert of a row
191 while (list($key, $val) = each($fields)) {
193 $key = urldecode($key);
194 $fieldlist .= PMA_backquote($key) . ', ';
196 switch (strtolower($val)) {
200 // if we have a set, then construct the value
201 $f = 'field_' . md5($key);
203 $val = implode(',', $
$f);
204 if ($val == 'null') {
207 $val = "'" . PMA_sqlAddslashes(urldecode($val)) . "'";
214 // if we have a set, then construct the value
215 $f = 'field_' . md5($key);
217 $val = implode(',', $
$f);
218 $val = "'" . PMA_sqlAddslashes(urldecode($val)) . "'";
224 // if we have a foreign key, then construct the value
225 $f = 'field_' . md5($key);
227 $val = implode(',', $
$f);
228 if ($val == 'null') {
231 $val = "'" . PMA_sqlAddslashes(urldecode($val)) . "'";
238 if (get_magic_quotes_gpc()) {
239 $val = "'" . str_replace('\\"', '"', $val) . "'";
241 $val = "'" . PMA_sqlAddslashes($val) . "'";
246 // Was the Null checkbox checked for this field?
247 // (if there is a value, we ignore the Null checkbox: this could
248 // be possible if Javascript is disabled in the browser)
249 if (isset($fields_null) && isset($fields_null[$encoded_key])
254 if (empty($funcs[$encoded_key])) {
255 $valuelist .= $val . ', ';
256 } else if (($val == '\'\''
257 && ereg('^(UNIX_TIMESTAMP|RAND|LAST_INSERT_ID)$', $funcs[$encoded_key]))
258 ||
ereg('^(NOW|CURDATE|CURTIME|USER)$', $funcs[$encoded_key])) {
259 $valuelist .= $funcs[$encoded_key] . '(), ';
261 $valuelist .= $funcs[$encoded_key] . '(' . $val . '), ';
265 // Builds the sql insert query
266 $fieldlist = ereg_replace(', $', '', $fieldlist);
267 $valuelist = ereg_replace(', $', '', $valuelist);
268 $query = 'INSERT INTO ' . PMA_backquote($table) . ' (' . $fieldlist . ') VALUES (' . $valuelist . ')';
269 $message = $strInsertedRows . ' ';
270 } // end row insertion
274 * Executes the sql query and get the result, then move back to the calling
277 PMA_mysql_select_db($db);
278 $sql_query = $query . ';';
279 $result = PMA_mysql_query($query);
282 $error = PMA_mysql_error();
283 include('./header.inc.php3');
284 PMA_mysqlDie($error, '', '', $err_url);
286 if (@mysql_affected_rows
()) {
287 $message .= @mysql_affected_rows
();
289 $message = $strModifications;
292 if ($goto == 'db_details.php3' && !empty($table)) {
295 $js_to_run = 'functions.js';
296 include('./header.inc.php3');
297 include('./' . ereg_replace('\.\.*', '.', $goto));
299 $add_query = (strpos(' ' . $goto, 'tbl_change') ?
'&disp_query=' . urlencode($sql_query) : '');
300 header('Location: ' . $cfg['PmaAbsoluteUri'] . $goto . '&message=' . urlencode($message) . $add_query);