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);
19 if (!isset($dontlimitchars)) {
23 if (isset($after_insert) && $after_insert == 'new_insert') {
24 $goto = 'tbl_change.php3'
26 . '&convcharset=' . $convcharset
27 . '&server=' . $server
28 . '&db=' . urlencode($db)
29 . '&table=' . urlencode($table)
30 . '&goto=' . urlencode($goto)
32 . '&session_max_rows=' . $session_max_rows
33 . '&disp_direction=' . $disp_direction
34 . '&repeat_cells=' . $repeat_cells
35 . '&dontlimitchars=' . $dontlimitchars
36 . (empty($sql_query) ?
'' : '&sql_query=' . urlencode($sql_query));
37 } else if ($goto == 'sql.php3') {
40 . '&convcharset=' . $convcharset
41 . '&server=' . $server
42 . '&db=' . urlencode($db)
43 . '&table=' . urlencode($table)
45 . '&session_max_rows=' . $session_max_rows
46 . '&disp_direction=' . $disp_direction
47 . '&repeat_cells=' . $repeat_cells
48 . '&dontlimitchars=' . $dontlimitchars
49 . '&sql_query=' . urlencode($sql_query);
50 } else if (!empty($goto)) {
52 $is_gotofile = ereg_replace('^([^?]+).*$', '\\1', $goto);
53 if (!@file_exists
('./' . $is_gotofile)) {
54 $goto = (empty($table)) ?
'db_details.php3' : 'tbl_properties.php3';
57 $is_gotofile = ($is_gotofile == $goto);
61 // Defines the url to return in case of failure of the query
62 if (isset($err_url)) {
63 $err_url = urldecode($err_url);
65 $err_url = str_replace('&', '&', $goto)
66 . (empty($primary_key) ?
'' : '&primary_key=' . $primary_key);
69 // Resets tables defined in the configuration file
76 if (get_magic_quotes_gpc()) {
77 $submit_type = stripslashes($submit_type);
82 * Prepares the update of a row
84 if (isset($primary_key) && ($submit_type != $strInsertAsNewRow)) {
85 // Restore the "primary key" to a convenient format
86 $primary_key = urldecode($primary_key);
88 // Defines the SET part of the sql query
90 while (list($key, $val) = each($fields)) {
92 $key = urldecode($key);
94 switch (strtolower($val)) {
98 // if we have an enum, then construct the value
99 $f = 'field_' . md5($key);
101 $val = implode(',', $
$f);
102 if ($val == 'null') {
105 $val = "'" . PMA_sqlAddslashes(urldecode($val)) . "'";
112 // if we have a set, then construct the value
113 $f = 'field_' . md5($key);
115 $val = implode(',', $
$f);
116 $val = "'" . PMA_sqlAddslashes(urldecode($val)) . "'";
122 // if we have a foreign key, then construct the value
123 $f = 'field_' . md5($key);
125 $val = implode(',', $
$f);
126 if ($val == 'null') {
129 $val = "'" . PMA_sqlAddslashes(urldecode($val)) . "'";
136 if (get_magic_quotes_gpc()) {
137 $val = "'" . str_replace('\\"', '"', $val) . "'";
139 $val = "'" . PMA_sqlAddslashes($val) . "'";
144 // Was the Null checkbox checked for this field?
145 if (isset($fields_null) && isset($fields_null[$encoded_key])) {
149 // No change for this column and no MySQL function is used -> next column
150 if (empty($funcs[$encoded_key])
151 && isset($fields_prev) && isset($fields_prev[$encoded_key])
152 && ("'" . PMA_sqlAddslashes(urldecode($fields_prev[$encoded_key])) . "'" == $val)) {
155 else if (!empty($val)) {
156 if (empty($funcs[$encoded_key])) {
157 $valuelist .= PMA_backquote($key) . ' = ' . $val . ', ';
158 } else if ($val == '\'\''
159 && (ereg('^(NOW|CURDATE|CURTIME|UNIX_TIMESTAMP|RAND|USER|LAST_INSERT_ID)$', $funcs[$encoded_key]))) {
160 $valuelist .= PMA_backquote($key) . ' = ' . $funcs[$encoded_key] . '(), ';
162 $valuelist .= PMA_backquote($key) . ' = ' . $funcs[$encoded_key] . "($val), ";
167 // Builds the sql upate query
168 $valuelist = ereg_replace(', $', '', $valuelist);
169 if (!empty($valuelist)) {
170 $query = 'UPDATE ' . PMA_backquote($table) . ' SET ' . $valuelist . ' WHERE' . $primary_key
171 . ((PMA_MYSQL_INT_VERSION
>= 32300) ?
' LIMIT 1' : '');
172 $message = $strAffectedRows . ' ';
174 // No change -> move back to the calling script
176 $message = $strNoModification;
178 $js_to_run = 'functions.js';
179 include('./header.inc.php3');
180 include('./' . ereg_replace('\.\.*', '.', $goto));
182 header('Location: ' . $cfg['PmaAbsoluteUri'] . $goto . '&message=' . urlencode($message));
190 * Prepares the insert of a row
195 while (list($key, $val) = each($fields)) {
197 $key = urldecode($key);
198 $fieldlist .= PMA_backquote($key) . ', ';
200 switch (strtolower($val)) {
204 // if we have a set, then construct the value
205 $f = 'field_' . md5($key);
207 $val = implode(',', $
$f);
208 if ($val == 'null') {
211 $val = "'" . PMA_sqlAddslashes(urldecode($val)) . "'";
218 // if we have a set, then construct the value
219 $f = 'field_' . md5($key);
221 $val = implode(',', $
$f);
222 $val = "'" . PMA_sqlAddslashes(urldecode($val)) . "'";
228 // if we have a foreign key, then construct the value
229 $f = 'field_' . md5($key);
231 $val = implode(',', $
$f);
232 if ($val == 'null') {
235 $val = "'" . PMA_sqlAddslashes(urldecode($val)) . "'";
242 if (get_magic_quotes_gpc()) {
243 $val = "'" . str_replace('\\"', '"', $val) . "'";
245 $val = "'" . PMA_sqlAddslashes($val) . "'";
250 // Was the Null checkbox checked for this field?
251 if (isset($fields_null) && isset($fields_null[$encoded_key])) {
255 if (empty($funcs[$encoded_key])) {
256 $valuelist .= $val . ', ';
257 } else if (($val == '\'\''
258 && ereg('^(UNIX_TIMESTAMP|RAND|LAST_INSERT_ID)$', $funcs[$encoded_key]))
259 ||
ereg('^(NOW|CURDATE|CURTIME|USER)$', $funcs[$encoded_key])) {
260 $valuelist .= $funcs[$encoded_key] . '(), ';
262 $valuelist .= $funcs[$encoded_key] . '(' . $val . '), ';
266 // Builds the sql insert query
267 $fieldlist = ereg_replace(', $', '', $fieldlist);
268 $valuelist = ereg_replace(', $', '', $valuelist);
269 $query = 'INSERT INTO ' . PMA_backquote($table) . ' (' . $fieldlist . ') VALUES (' . $valuelist . ')';
270 $message = $strInsertedRows . ' ';
271 } // end row insertion
275 * Executes the sql query and get the result, then move back to the calling
278 PMA_mysql_select_db($db);
279 $sql_query = $query . ';';
280 $result = PMA_mysql_query($query);
283 $error = PMA_mysql_error();
284 include('./header.inc.php3');
285 PMA_mysqlDie($error, '', '', $err_url);
287 if (@mysql_affected_rows
()) {
288 $message .= @mysql_affected_rows
();
290 $message = $strModifications;
293 if ($goto == 'db_details.php3' && !empty($table)) {
296 $js_to_run = 'functions.js';
297 include('./header.inc.php3');
298 include('./' . ereg_replace('\.\.*', '.', $goto));
300 $add_query = (strpos(' ' . $goto, 'tbl_change') ?
'&disp_query=' . urlencode($sql_query) : '');
301 header('Location: ' . $cfg['PmaAbsoluteUri'] . $goto . '&message=' . urlencode($message) . $add_query);