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
72 * Prepares the update of a row
74 if (isset($primary_key) && ($submit_type != $strInsertAsNewRow)) {
75 // Restore the "primary key" to a convenient format
76 $primary_key = urldecode($primary_key);
78 // Defines the SET part of the sql query
81 while (list($key, $val) = each($fields)) {
83 $key = urldecode($key);
85 include('./tbl_replace_fields.php3');
87 // No change for this column and no MySQL function is used -> next column
88 if (empty($funcs[$encoded_key])
89 && isset($fields_prev) && isset($fields_prev[$encoded_key])
90 && ("'" . PMA_sqlAddslashes(urldecode($fields_prev[$encoded_key])) . "'" == $val)) {
93 else if (!empty($val)) {
94 if (empty($funcs[$encoded_key])) {
95 $valuelist .= PMA_backquote($key) . ' = ' . $val . ', ';
96 } else if ($val == '\'\''
97 && (ereg('^(NOW|CURDATE|CURTIME|UNIX_TIMESTAMP|RAND|USER|LAST_INSERT_ID)$', $funcs[$encoded_key]))) {
98 $valuelist .= PMA_backquote($key) . ' = ' . $funcs[$encoded_key] . '(), ';
100 $valuelist .= PMA_backquote($key) . ' = ' . $funcs[$encoded_key] . "($val), ";
105 // Builds the sql update query
106 $valuelist = ereg_replace(', $', '', $valuelist);
107 if (!empty($valuelist)) {
108 $query = 'UPDATE ' . PMA_backquote($table) . ' SET ' . $valuelist . ' WHERE' . $primary_key
109 . ((PMA_MYSQL_INT_VERSION
>= 32300) ?
' LIMIT 1' : '');
110 $message = $strAffectedRows . ' ';
112 // No change -> move back to the calling script
114 $message = $strNoModification;
116 $js_to_run = 'functions.js';
117 include('./header.inc.php3');
118 include('./' . ereg_replace('\.\.*', '.', $goto));
120 header('Location: ' . $cfg['PmaAbsoluteUri'] . $goto . '&message=' . urlencode($message));
128 * Prepares the insert of a row
133 while (list($key, $val) = each($fields)) {
135 $key = urldecode($key);
136 $fieldlist .= PMA_backquote($key) . ', ';
138 include('./tbl_replace_fields.php3');
140 if (empty($funcs[$encoded_key])) {
141 $valuelist .= $val . ', ';
142 } else if (($val == '\'\''
143 && ereg('^(UNIX_TIMESTAMP|RAND|LAST_INSERT_ID)$', $funcs[$encoded_key]))
144 ||
ereg('^(NOW|CURDATE|CURTIME|USER)$', $funcs[$encoded_key])) {
145 $valuelist .= $funcs[$encoded_key] . '(), ';
147 $valuelist .= $funcs[$encoded_key] . '(' . $val . '), ';
151 // Builds the sql insert query
152 $fieldlist = ereg_replace(', $', '', $fieldlist);
153 $valuelist = ereg_replace(', $', '', $valuelist);
154 $query = 'INSERT INTO ' . PMA_backquote($table) . ' (' . $fieldlist . ') VALUES (' . $valuelist . ')';
155 $message = $strInsertedRows . ' ';
156 } // end row insertion
160 * Executes the sql query and get the result, then move back to the calling
163 PMA_mysql_select_db($db);
164 $sql_query = $query . ';';
165 $result = PMA_mysql_query($query);
167 $error = PMA_mysql_error();
168 include('./header.inc.php3');
169 PMA_mysqlDie($error, '', '', $err_url);
171 if (@mysql_affected_rows
()) {
172 $message .= @mysql_affected_rows
();
174 $message = $strModifications;
177 if ($goto == 'db_details.php3' && !empty($table)) {
180 $js_to_run = 'functions.js';
181 include('./header.inc.php3');
182 include('./' . ereg_replace('\.\.*', '.', $goto));
184 // I don't understand this one:
185 //$add_query = (strpos(' ' . $goto, 'tbl_change') ? '&disp_query=' . urlencode($sql_query) : '');
187 // if we have seen binary,
188 // we do not append the query to the Location so it won't be displayed
189 // on the resulting page
190 $add_query = (!$seen_binary ?
'&disp_query=' . urlencode($sql_query) : '');
191 header('Location: ' . $cfg['PmaAbsoluteUri'] . $goto . '&disp_message=' . urlencode($message) . $add_query);