js checks for user_password
[phpmyadmin/crack.git] / sql.php3
blobf32cf169324ba67e311b6cd68388d63b0f0df08b
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
5 /**
6 * Gets some core libraries
7 */
8 require('./libraries/grab_globals.lib.php3');
9 require('./libraries/common.lib.php3');
11 /**
12 * Defines the url to return to in case of error in a sql statement
14 // Security checkings
15 if (!empty($goto)) {
16 $is_gotofile = ereg_replace('^([^?]+).*$', '\\1', $goto);
17 if (!@file_exists('./' . $is_gotofile)) {
18 unset($goto);
19 } else {
20 $is_gotofile = ($is_gotofile == $goto);
22 } // end if (security checkings)
24 if (empty($goto)) {
25 $goto = (empty($table)) ? $cfg['DefaultTabDatabase'] : $cfg['DefaultTabTable'];
26 $is_gotofile = TRUE;
27 } // end if
28 if (!isset($err_url)) {
29 $err_url = (!empty($back) ? $back : $goto)
30 . '?' . PMA_generate_common_url(isset($db) ? $db : '')
31 . ((strpos(' ' . $goto, 'db_details') != 1 && isset($table)) ? '&amp;table=' . urlencode($table) : '');
32 } // end if
34 // Coming from a bookmark dialog
35 if (isset($fields['query'])) {
36 $sql_query = $fields['query'];
39 /**
40 * Check rights in case of DROP DATABASE
42 * This test may be bypassed if $is_js_confirmed = 1 (already checked with js)
43 * but since a malicious user may pass this variable by url/form, we don't take
44 * into account this case.
46 if (!defined('PMA_CHK_DROP')
47 && !$cfg['AllowUserDropDatabase']
48 && eregi('DROP[[:space:]]+(IF EXISTS[[:space:]]+)?DATABASE[[:space:]]', $sql_query)) {
49 // Checks if the user is a Superuser
50 // TODO: set a global variable with this information
51 // loic1: optimized query
52 $result = @PMA_mysql_query('USE mysql');
53 if (PMA_mysql_error()) {
54 include('./header.inc.php3');
55 PMA_mysqlDie($strNoDropDatabases, '', '', $err_url);
56 } // end if
57 } // end if
60 /**
61 * Bookmark add
63 if (isset($store_bkm)) {
64 include('./libraries/bookmark.lib.php3');
65 PMA_addBookmarks($fields, $cfg['Bookmark']);
66 header('Location: ' . $cfg['PmaAbsoluteUri'] . $goto);
67 } // end if
70 /**
71 * Gets the true sql query
73 // $sql_query has been urlencoded in the confirmation form for drop/delete
74 // queries or in the navigation bar for browsing among records
75 if (isset($btnDrop) || isset($navig)) {
76 $sql_query = urldecode($sql_query);
79 /**
80 * Reformat the query
83 $parsed_sql = PMA_SQP_parse($sql_query);
84 $analyzed_sql = PMA_SQP_analyze($parsed_sql);
85 // Bug #641765 - Robbat2 - 12 January 2003, 10:49PM
86 // Reverted - Robbat2 - 13 January 2003, 2:40PM
87 $sql_query = PMA_SQP_formatHtml($parsed_sql, 'query_only');
89 // old code did not work, for example, when there is a bracket
90 // before the SELECT
91 // so I guess it's ok to check for a real SELECT ... FROM
92 //$is_select = eregi('^SELECT[[:space:]]+', $sql_query);
93 $is_select = isset($analyzed_sql[0]['queryflags']['select_from']);
95 // If the query is a Select, extract the db and table names and modify
96 // $db and $table, to have correct page headers, links and left frame.
97 // db and table name may be enclosed with backquotes, db is optionnal,
98 // query may contain aliases.
100 // (TODO: if there are more than one table name in the Select:
101 // - do not extract the first table name
102 // - do not show a table name in the page header
103 // - do not display the sub-pages links)
105 if ($is_select) {
106 $prev_db = $db;
107 if (isset($analyzed_sql[0]['table_ref'][0]['table_true_name'])) {
108 $table = $analyzed_sql[0]['table_ref'][0]['table_true_name'];
110 if (isset($analyzed_sql[0]['table_ref'][0]['db'])
111 && !empty($analyzed_sql[0]['table_ref'][0]['db'])) {
112 $db = $analyzed_sql[0]['table_ref'][0]['db'];
114 else {
115 $db = $prev_db;
117 $reload = ($db == $prev_db) ? 0 : 1;
121 * Sets or modifies the $goto variable if required
123 if ($goto == 'sql.php3') {
124 $goto = 'sql.php3?'
125 . PMA_generate_common_url($db, $table)
126 . '&amp;pos=' . $pos
127 . '&amp;sql_query=' . urlencode($sql_query);
128 } // end if
132 * Go back to further page if table should not be dropped
134 if (isset($btnDrop) && $btnDrop == $strNo) {
135 if (!empty($back)) {
136 $goto = $back;
138 if ($is_gotofile) {
139 if (strpos(' ' . $goto, 'db_details') == 1 && !empty($table)) {
140 unset($table);
142 include('./' . ereg_replace('\.\.*', '.', $goto));
143 } else {
144 header('Location: ' . $cfg['PmaAbsoluteUri'] . str_replace('&amp;', '&', $goto));
146 exit();
147 } // end if
151 * Displays the confirm page if required
153 * This part of the script is bypassed if $is_js_confirmed = 1 (already checked
154 * with js) because possible security issue is not so important here: at most,
155 * the confirm message isn't displayed.
157 * Also bypassed if only showing php code.or validating a SQL query
159 if (!$cfg['Confirm']
160 || (isset($is_js_confirmed) && $is_js_confirmed)
161 || isset($btnDrop)
162 || !empty($GLOBALS['show_as_php'])
163 || !empty($GLOBALS['validatequery'])) {
164 $do_confirm = FALSE;
165 } else {
166 //$do_confirm = (eregi('DROP[[:space:]]+(IF[[:space:]]+EXISTS[[:space:]]+)?(TABLE|DATABASE[[:space:]])|ALTER[[:space:]]+TABLE[[:space:]]+((`[^`]+`)|([A-Za-z0-9_$]+))[[:space:]]+DROP[[:space:]]|DELETE[[:space:]]+FROM[[:space:]]', $sql_query));
168 $do_confirm = isset($analyzed_sql[0]['queryflags']['need_confirm']);
171 if ($do_confirm) {
172 $stripped_sql_query = $sql_query;
173 include('./header.inc.php3');
174 echo $strDoYouReally . '&nbsp;:<br />' . "\n";
175 echo '<tt>' . htmlspecialchars($stripped_sql_query) . '</tt>&nbsp;?<br/>' . "\n";
177 <form action="sql.php3" method="post">
178 <?php echo PMA_generate_common_hidden_inputs($db, (isset($table)?$table:'')); ?>
179 <input type="hidden" name="sql_query" value="<?php echo urlencode($sql_query); ?>" />
180 <input type="hidden" name="zero_rows" value="<?php echo isset($zero_rows) ? $zero_rows : ''; ?>" />
181 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
182 <input type="hidden" name="back" value="<?php echo isset($back) ? $back : ''; ?>" />
183 <input type="hidden" name="reload" value="<?php echo isset($reload) ? $reload : 0; ?>" />
184 <input type="hidden" name="purge" value="<?php echo isset($purge) ? $purge : ''; ?>" />
185 <input type="hidden" name="cpurge" value="<?php echo isset($cpurge) ? $cpurge : ''; ?>" />
186 <input type="hidden" name="purgekey" value="<?php echo isset($purgekey) ? $purgekey : ''; ?>" />
187 <input type="hidden" name="show_query" value="<?php echo isset($show_query) ? $show_query : ''; ?>" />
188 <input type="submit" name="btnDrop" value="<?php echo $strYes; ?>" />
189 <input type="submit" name="btnDrop" value="<?php echo $strNo; ?>" />
190 </form>
191 <?php
192 echo "\n";
193 } // end if
197 * Executes the query and displays results
199 else {
200 if (!isset($sql_query)) {
201 $sql_query = '';
203 // Defines some variables
204 // loic1: A table has to be created -> left frame should be reloaded
205 if ((!isset($reload) || $reload == 0)
206 && eregi('^CREATE TABLE[[:space:]]+(.*)', $sql_query)) {
207 $reload = 1;
209 // Gets the number of rows per page
210 if (!isset($session_max_rows)) {
211 $session_max_rows = $cfg['MaxRows'];
212 } else if ($session_max_rows != 'all') {
213 $cfg['MaxRows'] = $session_max_rows;
215 // Defines the display mode (horizontal/vertical) and header "frequency"
216 if (empty($disp_direction)) {
217 $disp_direction = $cfg['DefaultDisplay'];
219 if (empty($repeat_cells)) {
220 $repeat_cells = $cfg['RepeatCells'];
223 // SK -- Patch: $is_group added for use in calculation of total number of
224 // rows.
225 // $is_count is changed for more correct "LIMIT" clause
226 // appending in queries like
227 // "SELECT COUNT(...) FROM ... GROUP BY ..."
228 $is_explain = $is_count = $is_export = $is_delete = $is_insert = $is_affected = $is_show = $is_maint = $is_analyse = $is_group = $is_func = FALSE;
229 if ($is_select) { // see line 141
230 $is_group = eregi('[[:space:]]+(GROUP[[:space:]]+BY|HAVING|SELECT[[:space:]]+DISTINCT)[[:space:]]+', $sql_query);
232 $is_func = !$is_group && (eregi('[[:space:]]+(SUM|AVG|STD|STDDEV|MIN|MAX|BIT_OR|BIT_AND)\s*\(', $sql_query));
233 $is_count = !$is_group && (eregi('^SELECT[[:space:]]+COUNT\((.*\.+)?.*\)', $sql_query));
234 $is_export = (eregi('[[:space:]]+INTO[[:space:]]+OUTFILE[[:space:]]+', $sql_query));
235 $is_analyse = (eregi('[[:space:]]+PROCEDURE[[:space:]]+ANALYSE\(', $sql_query));
236 } else if (eregi('^EXPLAIN[[:space:]]+', $sql_query)) {
237 $is_explain = TRUE;
238 } else if (eregi('^DELETE[[:space:]]+', $sql_query)) {
239 $is_delete = TRUE;
240 $is_affected = TRUE;
241 } else if (eregi('^(INSERT|LOAD[[:space:]]+DATA|REPLACE)[[:space:]]+', $sql_query)) {
242 $is_insert = TRUE;
243 $is_affected = TRUE;
244 } else if (eregi('^UPDATE[[:space:]]+', $sql_query)) {
245 $is_affected = TRUE;
246 } else if (eregi('^SHOW[[:space:]]+', $sql_query)) {
247 $is_show = TRUE;
248 } else if (eregi('^(CHECK|ANALYZE|REPAIR|OPTIMIZE)[[:space:]]+TABLE[[:space:]]+', $sql_query)) {
249 $is_maint = TRUE;
252 // Do append a "LIMIT" clause?
253 if (isset($pos)
254 && (!$cfg['ShowAll'] || $session_max_rows != 'all')
255 && !($is_count || $is_export || $is_func || $is_analyse)
256 && isset($analyzed_sql[0]['queryflags']['select_from'])
257 && !eregi('[[:space:]]LIMIT[[:space:]0-9,-]+$', $sql_query)) {
258 $sql_limit_to_append = " LIMIT $pos, ".$cfg['MaxRows'];
259 if (eregi('(.*)([[:space:]](PROCEDURE[[:space:]](.*)|FOR[[:space:]]+UPDATE|LOCK[[:space:]]+IN[[:space:]]+SHARE[[:space:]]+MODE))$', $sql_query, $regs)) {
260 $full_sql_query = $regs[1] . $sql_limit_to_append . $regs[2];
261 } else {
262 $full_sql_query = $sql_query . $sql_limit_to_append;
264 } else {
265 $full_sql_query = $sql_query;
266 } // end if...else
268 PMA_mysql_select_db($db);
270 // If the query is a DELETE query with no WHERE clause, get the number of
271 // rows that will be deleted (mysql_affected_rows will always return 0 in
272 // this case)
273 if ($is_delete
274 && eregi('^DELETE([[:space:]].+)?([[:space:]]FROM[[:space:]](.+))$', $sql_query, $parts)
275 && !eregi('[[:space:]]WHERE[[:space:]]', $parts[3])) {
276 $cnt_all_result = @PMA_mysql_query('SELECT COUNT(*) as count' . $parts[2]);
277 if ($cnt_all_result) {
278 $num_rows = PMA_mysql_result($cnt_all_result, 0, 'count');
279 mysql_free_result($cnt_all_result);
280 } else {
281 $num_rows = 0;
285 // E x e c u t e t h e q u e r y
287 // Only if we didn't ask to see the php code (mikebeck)
288 if (!empty($GLOBALS['show_as_php']) || !empty($GLOBALS['validatequery'])) {
289 unset($result);
290 $num_rows = 0;
292 else {
293 // garvin: Measure query time. TODO-Item http://sourceforge.net/tracker/index.php?func=detail&aid=571934&group_id=23067&atid=377411
294 list($usec, $sec) = explode(' ',microtime());
295 $querytime_before = ((float)$usec + (float)$sec);
297 $result = @PMA_mysql_query($full_sql_query);
299 list($usec, $sec) = explode(' ',microtime());
300 $querytime_after = ((float)$usec + (float)$sec);
302 $GLOBALS['querytime'] = $querytime_after - $querytime_before;
304 // Displays an error message if required and stop parsing the script
305 if (PMA_mysql_error()) {
306 $error = PMA_mysql_error();
307 include('./header.inc.php3');
308 $full_err_url = (ereg('^(db_details|tbl_properties)', $err_url))
309 ? $err_url . '&amp;show_query=1&amp;sql_query=' . urlencode($sql_query)
310 : $err_url;
311 PMA_mysqlDie($error, $full_sql_query, '', $full_err_url);
314 // Gets the number of rows affected/returned
315 // (This must be done immediately after the query because
316 // mysql_affected_rows() reports about the last query done)
318 if (!$is_affected) {
319 $num_rows = ($result) ? @mysql_num_rows($result) : 0;
320 } else if (!isset($num_rows)) {
321 $num_rows = @mysql_affected_rows();
324 // Checks if the current database has changed
325 // This could happen if the user sends a query like "USE `database`;"
326 $res = PMA_mysql_query('SELECT DATABASE() AS "db";');
327 $row = PMA_mysql_fetch_array($res);
328 if ($db != $row['db']) {
329 $db = $row['db'];
330 $reload = 1;
332 @mysql_free_result($res);
333 unset($res);
334 unset($row);
336 // tmpfile remove after convert encoding appended by Y.Kawada
337 if (function_exists('PMA_kanji_file_conv')
338 && (isset($textfile) && file_exists($textfile))) {
339 unlink($textfile);
342 // Counts the total number of rows for the same 'SELECT' query without the
343 // 'LIMIT' clause that may have been programatically added
345 if (empty($sql_limit_to_append)) {
346 $unlim_num_rows = $num_rows;
348 else if ($is_select) {
350 // c o u n t q u e r y
352 if (PMA_MYSQL_INT_VERSION < 40000) {
353 if (eregi('DISTINCT(.*)', $sql_query)) {
354 $count_what = 'DISTINCT ' . $analyzed_sql[0]['select_expr_clause'];
355 } else {
356 $count_what = '*';
359 $count_query = 'SELECT COUNT(' . $count_what . ') AS count';
361 else {
362 $count_query = 'SELECT SQL_CALC_FOUND_ROWS ';
365 // add the remaining of select expression if there is
366 // a GROUP BY or HAVING clause
367 if (PMA_MYSQL_INT_VERSION < 40000
368 && $count_what =='*'
369 && (!empty($analyzed_sql[0]['group_by_clause'])
370 || !empty($analyzed_sql[0]['having_clause']))) {
371 $count_query .= ' ,' . $analyzed_sql[0]['select_expr_clause'];
374 // add select expression after the SQL_CALC_FOUND_ROWS
375 if (PMA_MYSQL_INT_VERSION >= 40000) {
376 $count_query .= $analyzed_sql[0]['select_expr_clause'];
380 if (!empty($analyzed_sql[0]['from_clause'])) {
381 $count_query .= ' FROM ' . $analyzed_sql[0]['from_clause'];
384 if (!empty($analyzed_sql[0]['where_clause'])) {
385 $count_query .= ' WHERE ' . $analyzed_sql[0]['where_clause'];
387 if (!empty($analyzed_sql[0]['group_by_clause'])) {
388 $count_query .= ' GROUP BY ' . $analyzed_sql[0]['group_by_clause'];
391 if (!empty($analyzed_sql[0]['having_clause'])) {
392 $count_query .= ' HAVING ' . $analyzed_sql[0]['having_clause'];
395 // do not put the order_by_clause, it interferes
396 // run the count query
397 if (PMA_MYSQL_INT_VERSION < 40000) {
398 if ($cnt_all_result = mysql_query($count_query)) {
399 if ($is_group) {
400 $unlim_num_rows = @mysql_num_rows($cnt_all_result);
401 } else {
402 $unlim_num_rows = mysql_result($cnt_all_result, 0, 'count');
404 mysql_free_result($cnt_all_result);
405 } else {
406 if (mysql_error()) {
407 // there are some cases where the generated
408 // count_query (for MySQL 3) is wrong,
409 // so we get here.
410 //TODO: use a big unlimited query to get
411 // the correct number of rows (depending
412 // on a config variable?)
413 $unlim_num_rows = 0;
416 } else {
417 mysql_query($count_query);
418 if (mysql_error()) {
419 // void. I tried the case
420 // (SELECT `User`, `Host`, `Db`, `Select_priv` FROM `db`)
421 // UNION (SELECT `User`, `Host`, "%" AS "Db",
422 // `Select_priv`
423 // FROM `user`) ORDER BY `User`, `Host`, `Db`;
424 // and although the generated count_query is wrong
425 // the SELECT FOUND_ROWS() work!
427 $cnt_all_result = mysql_query('SELECT FOUND_ROWS() as count');
428 $unlim_num_rows = mysql_result($cnt_all_result,0,'count');
431 } else { // not $is_select
432 $unlim_num_rows = 0;
433 } // end rows total count
435 // garvin: if a table or database gets dropped, check column comments.
436 if (isset($purge) && $purge == '1') {
437 include('./libraries/relation.lib.php3');
438 $cfgRelation = PMA_getRelationsParam();
440 if (isset($table) && isset($db) && !empty($table) && !empty($db)) {
441 // garvin: Only a table is deleted. Remove all references in PMA_*
442 if ($cfgRelation['commwork']) {
443 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['column_info'])
444 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
445 . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'';
446 $rmv_rs = PMA_query_as_cu($remove_query);
447 unset($rmv_query);
450 if ($cfgRelation['displaywork']) {
451 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['table_info'])
452 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
453 . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'';
454 $rmv_rs = PMA_query_as_cu($remove_query);
455 unset($rmv_query);
458 if ($cfgRelation['pdfwork']) {
459 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['table_coords'])
460 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
461 . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'';
462 $rmv_rs = PMA_query_as_cu($remove_query);
463 unset($rmv_query);
466 if ($cfgRelation['relwork']) {
467 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['relation'])
468 . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\''
469 . ' AND master_table = \'' . PMA_sqlAddslashes($table) . '\'';
470 $rmv_rs = PMA_query_as_cu($remove_query);
471 unset($rmv_query);
473 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['relation'])
474 . ' WHERE foreign_db = \'' . PMA_sqlAddslashes($db) . '\''
475 . ' AND foreign_table = \'' . PMA_sqlAddslashes($table) . '\'';
476 $rmv_rs = PMA_query_as_cu($remove_query);
477 unset($rmv_query);
479 } elseif (isset($db) && !empty($db)) {
480 // garvin: A whole DB gets deleted. Remove all references in PMA_*
481 if ($cfgRelation['commwork']) {
482 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['column_info'])
483 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
484 $rmv_rs = PMA_query_as_cu($remove_query);
485 unset($rmv_query);
488 if ($cfgRelation['bookmarkwork']) {
489 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['bookmark'])
490 . ' WHERE dbase = \'' . PMA_sqlAddslashes($db) . '\'';
491 $rmv_rs = PMA_query_as_cu($remove_query);
492 unset($rmv_query);
495 if ($cfgRelation['displaywork']) {
496 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['table_info'])
497 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
498 $rmv_rs = PMA_query_as_cu($remove_query);
499 unset($rmv_query);
502 if ($cfgRelation['pdfwork']) {
503 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['pdf_pages'])
504 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
505 $rmv_rs = PMA_query_as_cu($remove_query);
506 unset($rmv_query);
508 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['table_coords'])
509 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
510 $rmv_rs = PMA_query_as_cu($remove_query);
511 unset($rmv_query);
514 if ($cfgRelation['relwork']) {
515 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['relation'])
516 . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\'';
517 $rmv_rs = PMA_query_as_cu($remove_query);
518 unset($rmv_query);
520 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['relation'])
521 . ' WHERE foreign_db = \'' . PMA_sqlAddslashes($db) . '\'';
522 $rmv_rs = PMA_query_as_cu($remove_query);
523 unset($rmv_query);
526 } else {
527 // garvin: VOID. No DB/Table gets deleted.
528 } // end if relation-stuff
529 } // end if ($purge)
531 // garvin: If a column gets dropped, do relation magic.
532 if (isset($cpurge) && $cpurge == '1' && isset($purgekey)
533 && isset($db) && isset($table)
534 && !empty($db) && !empty($table) && !empty($purgekey)) {
535 include('./libraries/relation.lib.php3');
536 $cfgRelation = PMA_getRelationsParam();
538 if ($cfgRelation['commwork']) {
539 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['column_info'])
540 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
541 . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''
542 . ' AND column_name = \'' . PMA_sqlAddslashes(urldecode($purgekey)) . '\'';
543 $rmv_rs = PMA_query_as_cu($remove_query);
544 unset($rmv_query);
547 if ($cfgRelation['displaywork']) {
548 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['table_info'])
549 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
550 . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''
551 . ' AND display_field = \'' . PMA_sqlAddslashes(urldecode($purgekey)) . '\'';
552 $rmv_rs = PMA_query_as_cu($remove_query);
553 unset($rmv_query);
556 if ($cfgRelation['relwork']) {
557 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['relation'])
558 . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\''
559 . ' AND master_table = \'' . PMA_sqlAddslashes($table) . '\''
560 . ' AND master_field = \'' . PMA_sqlAddslashes(urldecode($purgekey)) . '\'';
561 $rmv_rs = PMA_query_as_cu($remove_query);
562 unset($rmv_query);
564 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['relation'])
565 . ' WHERE foreign_db = \'' . PMA_sqlAddslashes($db) . '\''
566 . ' AND foreign_table = \'' . PMA_sqlAddslashes($table) . '\''
567 . ' AND foreign_field = \'' . PMA_sqlAddslashes(urldecode($purgekey)) . '\'';
568 $rmv_rs = PMA_query_as_cu($remove_query);
569 unset($rmv_query);
571 } // end if column PMA_* purge
572 } // end else "didn't ask to see php code"
575 // No rows returned -> move back to the calling page
576 if ($num_rows < 1 || $is_affected) {
577 if ($is_delete) {
578 $message = $strDeletedRows . '&nbsp;' . $num_rows;
579 } else if ($is_insert) {
580 $message = $strInsertedRows . '&nbsp;' . $num_rows;
581 } else if ($is_affected) {
582 $message = $strAffectedRows . '&nbsp;' . $num_rows;
583 } else if (!empty($zero_rows)) {
584 $message = $zero_rows;
585 } else if (!empty($GLOBALS['show_as_php'])) {
586 $message = $strPhp;
587 } else if (!empty($GLOBALS['validatequery'])) {
588 $message = $strValidateSQL;
589 } else {
590 $message = $strEmptyResultSet;
593 $message .= ' ' . (isset($GLOBALS['querytime']) ? '(' . sprintf($strQueryTime, $GLOBALS['querytime']) . ')' : '');
595 if ($is_gotofile) {
596 $goto = ereg_replace('\.\.*', '.', $goto);
597 // Checks for a valid target script
598 if (isset($table) && $table == '') {
599 unset($table);
601 if (isset($db) && $db == '') {
602 unset($db);
604 $is_db = $is_table = FALSE;
605 if (strpos(' ' . $goto, 'tbl_properties') == 1) {
606 if (!isset($table)) {
607 $goto = 'db_details.php3';
608 } else {
609 $is_table = @PMA_mysql_query('SHOW TABLES LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\'');
610 if (!($is_table && @mysql_numrows($is_table))) {
611 $goto = 'db_details.php3';
612 unset($table);
614 } // end if... else...
616 if (strpos(' ' . $goto, 'db_details') == 1) {
617 if (isset($table)) {
618 unset($table);
620 if (!isset($db)) {
621 $goto = 'main.php3';
622 } else {
623 $is_db = @PMA_mysql_select_db($db);
624 if (!$is_db) {
625 $goto = 'main.php3';
626 unset($db);
628 } // end if... else...
630 // Loads to target script
631 if (strpos(' ' . $goto, 'db_details') == 1
632 || strpos(' ' . $goto, 'tbl_properties') == 1) {
633 $js_to_run = 'functions.js';
635 if ($goto != 'main.php3') {
636 include('./header.inc.php3');
638 include('./' . $goto);
639 } // end if file_exist
640 else {
641 header('Location: ' . $cfg['PmaAbsoluteUri'] . str_replace('&amp;', '&', $goto) . '&message=' . urlencode($message));
642 } // end else
643 exit();
644 } // end no rows returned
646 // At least one row is returned -> displays a table with results
647 else {
648 // Displays the headers
649 if (isset($show_query)) {
650 unset($show_query);
652 if (isset($printview) && $printview == '1') {
653 include('./header_printview.inc.php3');
654 } else {
655 $js_to_run = 'functions.js';
656 unset($message);
657 if (!empty($table)) {
658 include('./tbl_properties_common.php3');
659 $url_query .= '&amp;goto=tbl_properties.php3&amp;back=tbl_properties.php3';
660 include('./tbl_properties_table_info.php3');
662 else {
663 include('./db_details_common.php3');
664 include('./db_details_db_info.php3');
666 include('./libraries/relation.lib.php3');
667 $cfgRelation = PMA_getRelationsParam();
670 // Gets the list of fields properties
671 if (isset($result) && $result) {
672 while ($field = PMA_mysql_fetch_field($result)) {
673 $fields_meta[] = $field;
675 $fields_cnt = count($fields_meta);
678 // Display previous update query (from tbl_replace)
679 if (isset($disp_query) && $cfg['ShowSQL'] == TRUE) {
680 $tmp_sql_query = $GLOBALS['sql_query'];
681 $tmp_sql_limit_to_append = (isset($GLOBALS['sql_limit_to_append'])?$GLOBALS['sql_limit_to_append']:'');
682 $GLOBALS['sql_query'] = $disp_query;
683 $GLOBALS['sql_limit_to_append'] = '';
684 PMA_showMessage($disp_message);
685 $GLOBALS['sql_query'] = $tmp_sql_query;
686 $GLOBALS['sql_limit_to_append'] = $tmp_sql_limit_to_append;
689 // Displays the results in a table
690 include('./libraries/display_tbl.lib.php3');
691 if (empty($disp_mode)) {
692 // see the "PMA_setDisplayMode()" function in
693 // libraries/display_tbl.lib.php3
694 $disp_mode = 'urdr111101';
696 if (!isset($dontlimitchars)) {
697 $dontlimitchars = 0;
700 PMA_displayTable($result, $disp_mode, $analyzed_sql);
701 mysql_free_result($result);
703 if ($disp_mode[6] == '1' || $disp_mode[9] == '1') {
704 echo "\n";
705 echo '<p>' . "\n";
707 // Displays "Insert a new row" link if required
708 if ($disp_mode[6] == '1') {
709 $lnk_goto = 'sql.php3?'
710 . PMA_generate_common_url($db, $table)
711 . '&amp;pos=' . $pos
712 . '&amp;session_max_rows=' . $session_max_rows
713 . '&amp;disp_direction=' . $disp_direction
714 . '&amp;repeat_cells=' . $repeat_cells
715 . '&amp;dontlimitchars=' . $dontlimitchars
716 . '&amp;sql_query=' . urlencode($sql_query);
717 $url_query = '?'
718 . PMA_generate_common_url($db, $table)
719 . '&amp;pos=' . $pos
720 . '&amp;session_max_rows=' . $session_max_rows
721 . '&amp;disp_direction=' . $disp_direction
722 . '&amp;repeat_cells=' . $repeat_cells
723 . '&amp;dontlimitchars=' . $dontlimitchars
724 . '&amp;sql_query=' . urlencode($sql_query)
725 . '&amp;goto=' . urlencode($lnk_goto);
727 echo ' <!-- Insert a new row -->' . "\n"
728 . ' <a href="tbl_change.php3' . $url_query . '">' . $strInsertNewRow . '</a>';
729 if ($disp_mode[9] == '1') {
730 echo '<br />';
732 echo "\n";
733 } // end insert new row
735 // Displays "printable view" link if required
736 if ($disp_mode[9] == '1') {
737 $url_query = '?'
738 . PMA_generate_common_url($db, $table)
739 . '&amp;pos=' . $pos
740 . '&amp;session_max_rows=' . $session_max_rows
741 . '&amp;disp_direction=' . $disp_direction
742 . '&amp;repeat_cells=' . $repeat_cells
743 . '&amp;printview=1'
744 . ((isset($dontlimitchars) && $dontlimitchars == '1') ? '&amp;dontlimitchars=1' : '')
745 . '&amp;sql_query=' . urlencode($sql_query);
746 echo ' <!-- Print view -->' . "\n"
747 . ' <a href="sql.php3' . $url_query . '" target="print_view">' . $strPrintView . '</a>' . "\n";
748 } // end displays "printable view"
750 echo '</p>' . "\n";
753 // Export link, if only one table
754 // (the url_query has extra parameters that won't be used to export)
755 if (!isset($printview)
756 && isset($analyzed_sql[0]['table_ref'][0]['table_true_name'])
757 && !isset($analyzed_sql[0]['table_ref'][1]['table_true_name'])) {
758 echo ' <!-- Export -->' . "\n"
759 . ' <a href="tbl_properties_export.php3' . $url_query . '&amp;unlim_num_rows=' . $unlim_num_rows . '">' . $strExport . '</a>' . "\n";
762 // Bookmark Support if required
763 if ($disp_mode[7] == '1'
764 && ($cfg['Bookmark']['db'] && $cfg['Bookmark']['table'] && empty($id_bookmark))
765 && !empty($sql_query)) {
766 echo "\n";
768 $goto = 'sql.php3?'
769 . PMA_generate_common_url($db, $table)
770 . '&amp;pos=' . $pos
771 . '&amp;session_max_rows=' . $session_max_rows
772 . '&amp;disp_direction=' . $disp_direction
773 . '&amp;repeat_cells=' . $repeat_cells
774 . '&amp;dontlimitchars=' . $dontlimitchars
775 . '&amp;sql_query=' . urlencode($sql_query)
776 . '&amp;id_bookmark=1';
778 <!-- Bookmark the query -->
779 <form action="sql.php3" method="post" onsubmit="return emptyFormElements(this, 'fields[label]');">
780 <?php
781 echo "\n";
782 if ($disp_mode[3] == '1') {
783 echo ' <i>' . $strOr . '</i>' . "\n";
786 <br /><br />
787 <?php echo $strBookmarkLabel; ?>&nbsp;:
788 <?php echo PMA_generate_common_hidden_inputs(); ?>
789 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
790 <input type="hidden" name="fields[dbase]" value="<?php echo htmlspecialchars($db); ?>" />
791 <input type="hidden" name="fields[user]" value="<?php echo $cfg['Bookmark']['user']; ?>" />
792 <input type="hidden" name="fields[query]" value="<?php echo urlencode($sql_query); ?>" />
793 <input type="text" name="fields[label]" value="" />
794 <input type="submit" name="store_bkm" value="<?php echo $strBookmarkThis; ?>" />
795 </form>
796 <?php
797 } // end bookmark support
799 // Do print the page if required
800 if (isset($printview) && $printview == '1') {
801 echo "\n";
803 <script type="text/javascript" language="javascript1.2">
804 <!--
805 // Do print the page
806 if (typeof(window.print) != 'undefined') {
807 window.print();
809 //-->
810 </script>
811 <?php
812 } // end print case
813 } // end rows returned
815 } // end executes the query
816 echo "\n\n";
820 * Displays the footer
822 require('./footer.inc.php3');