bug #1715709 export in SQL format always includes procedures and functions
[phpmyadmin/crack.git] / sql.php
blob4e2c00e1e1f4fd6d4f6192c55c8b78aa71c38cdd
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * @todo we must handle the case if sql.php is called directly with a query
5 * what returns 0 rows - to prevent cyclic redirects or includes
6 * @version $Id$
7 */
9 /**
10 * Gets some core libraries
12 require_once './libraries/common.inc.php';
13 require_once './libraries/Table.class.php';
14 require_once './libraries/tbl_indexes.lib.php';
15 require_once './libraries/check_user_privileges.lib.php';
16 require_once './libraries/bookmark.lib.php';
18 /**
19 * Defines the url to return to in case of error in a sql statement
21 // Security checkings
22 if (!empty($goto)) {
23 $is_gotofile = preg_replace('@^([^?]+).*$@s', '\\1', $goto);
24 if (!@file_exists('./' . $is_gotofile)) {
25 unset($goto);
26 } else {
27 $is_gotofile = ($is_gotofile == $goto);
29 } // end if (security checkings)
31 if (empty($goto)) {
32 $goto = (! strlen($table)) ? $cfg['DefaultTabDatabase'] : $cfg['DefaultTabTable'];
33 $is_gotofile = true;
34 } // end if
35 if (!isset($err_url)) {
36 $err_url = (!empty($back) ? $back : $goto)
37 . '?' . PMA_generate_common_url($db)
38 . ((strpos(' ' . $goto, 'db_') != 1 && strlen($table)) ? '&amp;table=' . urlencode($table) : '');
39 } // end if
41 // Coming from a bookmark dialog
42 if (isset($fields['query'])) {
43 $sql_query = $fields['query'];
46 // This one is just to fill $db
47 if (isset($fields['dbase'])) {
48 $db = $fields['dbase'];
51 // Default to browse if no query set an we have table
52 // (needed for browsing from DefaultTabTable)
53 if (empty($sql_query) && strlen($table) && strlen($db)) {
54 require_once './libraries/bookmark.lib.php';
55 $book_sql_query = PMA_queryBookmarks($db,
56 $GLOBALS['cfg']['Bookmark'], '\'' . PMA_sqlAddslashes($table) . '\'',
57 'label');
59 if (! empty($book_sql_query)) {
60 $sql_query = $book_sql_query;
61 } else {
62 $sql_query = 'SELECT * FROM ' . PMA_backquote($table);
64 unset($book_sql_query);
66 // set $goto to what will be displayed if query returns 0 rows
67 $goto = 'tbl_structure.php';
68 } else {
69 // Now we can check the parameters
70 PMA_checkParameters(array('sql_query'));
73 // instead of doing the test twice
74 $is_drop_database = preg_match('/DROP[[:space:]]+(DATABASE|SCHEMA)[[:space:]]+/i',
75 $sql_query);
77 /**
78 * Check rights in case of DROP DATABASE
80 * This test may be bypassed if $is_js_confirmed = 1 (already checked with js)
81 * but since a malicious user may pass this variable by url/form, we don't take
82 * into account this case.
84 if (!defined('PMA_CHK_DROP')
85 && !$cfg['AllowUserDropDatabase']
86 && $is_drop_database
87 && !$is_superuser) {
88 require_once './libraries/header.inc.php';
89 PMA_mysqlDie($strNoDropDatabases, '', '', $err_url);
90 } // end if
92 require_once './libraries/display_tbl.lib.php';
93 PMA_displayTable_checkConfigParams();
95 /**
96 * Need to find the real end of rows?
98 if (isset($find_real_end) && $find_real_end) {
99 $unlim_num_rows = PMA_Table::countRecords($db, $table, true, true);
100 $_SESSION['userconf']['pos'] = @((ceil($unlim_num_rows / $_SESSION['userconf']['max_rows']) - 1) * $_SESSION['userconf']['max_rows']);
105 * Bookmark add
107 if (isset($store_bkm)) {
108 PMA_addBookmarks($fields, $cfg['Bookmark'], (isset($bkm_all_users) && $bkm_all_users == 'true' ? true : false));
109 PMA_sendHeaderLocation($cfg['PmaAbsoluteUri'] . $goto);
110 } // end if
114 * Gets the true sql query
116 // $sql_query has been urlencoded in the confirmation form for drop/delete
117 // queries or in the navigation bar for browsing among records
118 if (isset($btnDrop) || isset($navig)) {
119 $sql_query = urldecode($sql_query);
123 * Parse and analyze the query
125 require_once './libraries/parse_analyze.lib.php';
128 * Sets or modifies the $goto variable if required
130 if ($goto == 'sql.php') {
131 $is_gotofile = false;
132 $goto = 'sql.php?'
133 . PMA_generate_common_url($db, $table)
134 . '&amp;sql_query=' . urlencode($sql_query);
135 } // end if
139 * Go back to further page if table should not be dropped
141 if (isset($btnDrop) && $btnDrop == $strNo) {
142 if (!empty($back)) {
143 $goto = $back;
145 if ($is_gotofile) {
146 if (strpos(' ' . $goto, 'db_') == 1 && strlen($table)) {
147 $table = '';
149 $active_page = $goto;
150 require './' . PMA_securePath($goto);
151 } else {
152 PMA_sendHeaderLocation($cfg['PmaAbsoluteUri'] . str_replace('&amp;', '&', $goto));
154 exit();
155 } // end if
159 * Displays the confirm page if required
161 * This part of the script is bypassed if $is_js_confirmed = 1 (already checked
162 * with js) because possible security issue is not so important here: at most,
163 * the confirm message isn't displayed.
165 * Also bypassed if only showing php code.or validating a SQL query
167 if (! $cfg['Confirm'] || isset($_REQUEST['is_js_confirmed']) || isset($btnDrop)
168 // if we are coming from a "Create PHP code" or a "Without PHP Code"
169 // dialog, we won't execute the query anyway, so don't confirm
170 //|| !empty($GLOBALS['show_as_php'])
171 || isset($GLOBALS['show_as_php'])
172 || !empty($GLOBALS['validatequery'])) {
173 $do_confirm = false;
174 } else {
175 $do_confirm = isset($analyzed_sql[0]['queryflags']['need_confirm']);
178 if ($do_confirm) {
179 $stripped_sql_query = $sql_query;
180 require_once './libraries/header.inc.php';
181 if ($is_drop_database) {
182 echo '<h1 class="warning">' . $strDropDatabaseStrongWarning . '</h1>';
184 echo '<form action="sql.php" method="post">' . "\n"
185 .PMA_generate_common_hidden_inputs($db, $table);
187 <input type="hidden" name="sql_query" value="<?php echo urlencode($sql_query); ?>" />
188 <input type="hidden" name="zero_rows" value="<?php echo isset($zero_rows) ? PMA_sanitize($zero_rows) : ''; ?>" />
189 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
190 <input type="hidden" name="back" value="<?php echo isset($back) ? PMA_sanitize($back) : ''; ?>" />
191 <input type="hidden" name="reload" value="<?php echo isset($reload) ? PMA_sanitize($reload) : 0; ?>" />
192 <input type="hidden" name="purge" value="<?php echo isset($purge) ? PMA_sanitize($purge) : ''; ?>" />
193 <input type="hidden" name="cpurge" value="<?php echo isset($cpurge) ? PMA_sanitize($cpurge) : ''; ?>" />
194 <input type="hidden" name="purgekey" value="<?php echo isset($purgekey) ? PMA_sanitize($purgekey) : ''; ?>" />
195 <input type="hidden" name="show_query" value="<?php echo isset($show_query) ? PMA_sanitize($show_query) : ''; ?>" />
196 <?php
197 echo '<fieldset class="confirmation">' . "\n"
198 .' <legend>' . $strDoYouReally . '</legend>'
199 .' <tt>' . htmlspecialchars($stripped_sql_query) . '</tt>' . "\n"
200 .'</fieldset>' . "\n"
201 .'<fieldset class="tblFooters">' . "\n";
203 <input type="submit" name="btnDrop" value="<?php echo $strYes; ?>" id="buttonYes" />
204 <input type="submit" name="btnDrop" value="<?php echo $strNo; ?>" id="buttonNo" />
205 <?php
206 echo '</fieldset>' . "\n"
207 . '</form>' . "\n";
210 * Displays the footer and exit
212 require_once './libraries/footer.inc.php';
213 } // end if $do_confirm
216 // Defines some variables
217 // A table has to be created or renamed -> left frame should be reloaded
219 * @todo use the parser/analyzer
222 if (empty($reload)
223 && preg_match('/^(CREATE|ALTER|DROP)\s+(VIEW|TABLE|DATABASE|SCHEMA)\s+/i', $sql_query)) {
224 $reload = 1;
227 // SK -- Patch: $is_group added for use in calculation of total number of
228 // rows.
229 // $is_count is changed for more correct "LIMIT" clause
230 // appending in queries like
231 // "SELECT COUNT(...) FROM ... GROUP BY ..."
234 * @todo detect all this with the parser, to avoid problems finding
235 * those strings in comments or backquoted identifiers
238 $is_explain = $is_count = $is_export = $is_delete = $is_insert = $is_affected = $is_show = $is_maint = $is_analyse = $is_group = $is_func = $is_replace = false;
239 if ($is_select) { // see line 141
240 $is_group = preg_match('@(GROUP[[:space:]]+BY|HAVING|SELECT[[:space:]]+DISTINCT)[[:space:]]+@i', $sql_query);
241 $is_func = !$is_group && (preg_match('@[[:space:]]+(SUM|AVG|STD|STDDEV|MIN|MAX|BIT_OR|BIT_AND)\s*\(@i', $sql_query));
242 $is_count = !$is_group && (preg_match('@^SELECT[[:space:]]+COUNT\((.*\.+)?.*\)@i', $sql_query));
243 $is_export = (preg_match('@[[:space:]]+INTO[[:space:]]+OUTFILE[[:space:]]+@i', $sql_query));
244 $is_analyse = (preg_match('@[[:space:]]+PROCEDURE[[:space:]]+ANALYSE@i', $sql_query));
245 } elseif (preg_match('@^EXPLAIN[[:space:]]+@i', $sql_query)) {
246 $is_explain = true;
247 } elseif (preg_match('@^DELETE[[:space:]]+@i', $sql_query)) {
248 $is_delete = true;
249 $is_affected = true;
250 } elseif (preg_match('@^(INSERT|LOAD[[:space:]]+DATA|REPLACE)[[:space:]]+@i', $sql_query)) {
251 $is_insert = true;
252 $is_affected = true;
253 if (preg_match('@^(REPLACE)[[:space:]]+@i', $sql_query)) {
254 $is_replace = true;
256 } elseif (preg_match('@^UPDATE[[:space:]]+@i', $sql_query)) {
257 $is_affected = true;
258 } elseif (preg_match('@^SHOW[[:space:]]+@i', $sql_query)) {
259 $is_show = true;
260 } elseif (preg_match('@^(CHECK|ANALYZE|REPAIR|OPTIMIZE)[[:space:]]+TABLE[[:space:]]+@i', $sql_query)) {
261 $is_maint = true;
264 // Do append a "LIMIT" clause?
265 if ((!$cfg['ShowAll'] || $_SESSION['userconf']['max_rows'] != 'all')
266 && !($is_count || $is_export || $is_func || $is_analyse)
267 && isset($analyzed_sql[0]['queryflags']['select_from'])
268 && !isset($analyzed_sql[0]['queryflags']['offset'])
269 && !preg_match('@[[:space:]]LIMIT[[:space:]0-9,-]+(;)?$@i', $sql_query)
271 $sql_limit_to_append = ' LIMIT ' . $_SESSION['userconf']['pos'] . ', ' . $_SESSION['userconf']['max_rows'] . " ";
273 $full_sql_query = $analyzed_sql[0]['section_before_limit'] . "\n" . $sql_limit_to_append . $analyzed_sql[0]['section_after_limit'];
275 * @todo pretty printing of this modified query
277 if (isset($display_query)) {
278 // if the analysis of the original query revealed that we found
279 // a section_after_limit, we now have to analyze $display_query
280 // to display it correctly
282 if (!empty($analyzed_sql[0]['section_after_limit']) && trim($analyzed_sql[0]['section_after_limit']) != ';') {
283 $analyzed_display_query = PMA_SQP_analyze(PMA_SQP_parse($display_query));
284 $display_query = $analyzed_display_query[0]['section_before_limit'] . "\n" . $sql_limit_to_append . $analyzed_display_query[0]['section_after_limit'];
288 } else {
289 $full_sql_query = $sql_query;
290 } // end if...else
292 if (strlen($db)) {
293 PMA_DBI_select_db($db);
296 // If the query is a DELETE query with no WHERE clause, get the number of
297 // rows that will be deleted (mysql_affected_rows will always return 0 in
298 // this case)
299 // Note: testing shows that this no longer applies since MySQL 4.0.x
301 if (PMA_MYSQL_INT_VERSION < 40000) {
302 if ($is_delete
303 && preg_match('@^DELETE([[:space:]].+)?(FROM[[:space:]](.+))$@i', $sql_query, $parts)
304 && !preg_match('@[[:space:]]WHERE[[:space:]]@i', $parts[3])) {
305 $cnt_all_result = @PMA_DBI_try_query('SELECT COUNT(*) as count ' . $parts[2]);
306 if ($cnt_all_result) {
307 list($num_rows) = PMA_DBI_fetch_row($cnt_all_result);
308 PMA_DBI_free_result($cnt_all_result);
309 } else {
310 $num_rows = 0;
315 // E x e c u t e t h e q u e r y
317 // Only if we didn't ask to see the php code (mikebeck)
318 if (isset($GLOBALS['show_as_php']) || !empty($GLOBALS['validatequery'])) {
319 unset($result);
320 $num_rows = 0;
321 } else {
322 // garvin: Measure query time.
323 // TODO-Item http://sourceforge.net/tracker/index.php?func=detail&aid=571934&group_id=23067&atid=377411
324 $querytime_before = array_sum(explode(' ', microtime()));
326 $result = @PMA_DBI_try_query($full_sql_query, null, PMA_DBI_QUERY_STORE);
328 $querytime_after = array_sum(explode(' ', microtime()));
330 $GLOBALS['querytime'] = $querytime_after - $querytime_before;
332 // Displays an error message if required and stop parsing the script
333 if ($error = PMA_DBI_getError()) {
334 require_once './libraries/header.inc.php';
335 $full_err_url = (preg_match('@^(db|tbl)_@', $err_url))
336 ? $err_url . '&amp;show_query=1&amp;sql_query=' . urlencode($sql_query)
337 : $err_url;
338 PMA_mysqlDie($error, $full_sql_query, '', $full_err_url);
340 unset($error);
342 // Gets the number of rows affected/returned
343 // (This must be done immediately after the query because
344 // mysql_affected_rows() reports about the last query done)
346 if (!$is_affected) {
347 $num_rows = ($result) ? @PMA_DBI_num_rows($result) : 0;
348 } elseif (!isset($num_rows)) {
349 $num_rows = @PMA_DBI_affected_rows();
352 // Checks if the current database has changed
353 // This could happen if the user sends a query like "USE `database`;"
354 $res = PMA_DBI_query('SELECT DATABASE() AS \'db\';');
355 $row = PMA_DBI_fetch_row($res);
356 if (strlen($db) && is_array($row) && isset($row[0]) && (strcasecmp($db, $row[0]) != 0)) {
357 $db = $row[0];
358 $reload = 1;
360 @PMA_DBI_free_result($res);
361 unset($res, $row);
363 // tmpfile remove after convert encoding appended by Y.Kawada
364 if (function_exists('PMA_kanji_file_conv')
365 && (isset($textfile) && file_exists($textfile))) {
366 unlink($textfile);
369 // Counts the total number of rows for the same 'SELECT' query without the
370 // 'LIMIT' clause that may have been programatically added
372 if (empty($sql_limit_to_append)) {
373 $unlim_num_rows = $num_rows;
374 // if we did not append a limit, set this to get a correct
375 // "Showing rows..." message
376 //$_SESSION['userconf']['max_rows'] = 'all';
377 } elseif ($is_select) {
379 // c o u n t q u e r y
381 // If we are "just browsing", there is only one table,
382 // and no where clause (or just 'WHERE 1 '),
383 // so we do a quick count (which uses MaxExactCount)
384 // because SQL_CALC_FOUND_ROWS
385 // is not quick on large InnoDB tables
387 // but do not count again if we did it previously
388 // due to $find_real_end == true
390 if (!$is_group
391 && !isset($analyzed_sql[0]['queryflags']['union'])
392 && !isset($analyzed_sql[0]['table_ref'][1]['table_name'])
393 && (empty($analyzed_sql[0]['where_clause'])
394 || $analyzed_sql[0]['where_clause'] == '1 ')
395 && !isset($find_real_end)
398 // "j u s t b r o w s i n g"
399 $unlim_num_rows = PMA_Table::countRecords($db, $table, true);
401 } else { // n o t " j u s t b r o w s i n g "
403 if (PMA_MYSQL_INT_VERSION < 40000) {
405 // detect this case:
406 // SELECT DISTINCT x AS foo, y AS bar FROM sometable
408 if (isset($analyzed_sql[0]['queryflags']['distinct'])) {
409 $count_what = 'DISTINCT ';
410 $first_expr = true;
411 foreach ($analyzed_sql[0]['select_expr'] as $part) {
412 $count_what .= (!$first_expr ? ', ' : '') . $part['expr'];
413 $first_expr = false;
415 } else {
416 $count_what = '*';
418 // this one does not apply to VIEWs
419 $count_query = 'SELECT COUNT(' . $count_what . ') AS count';
422 // add the remaining of select expression if there is
423 // a GROUP BY or HAVING clause
424 if (PMA_MYSQL_INT_VERSION < 40000
425 && $count_what =='*'
426 && (!empty($analyzed_sql[0]['group_by_clause'])
427 || !empty($analyzed_sql[0]['having_clause']))) {
428 $count_query .= ' ,' . $analyzed_sql[0]['select_expr_clause'];
431 if (PMA_MYSQL_INT_VERSION >= 40000) {
432 // add select expression after the SQL_CALC_FOUND_ROWS
434 // for UNION, just adding SQL_CALC_FOUND_ROWS
435 // after the first SELECT works.
437 // take the left part, could be:
438 // SELECT
439 // (SELECT
440 $count_query = PMA_SQP_formatHtml($parsed_sql, 'query_only', 0, $analyzed_sql[0]['position_of_first_select'] + 1);
441 $count_query .= ' SQL_CALC_FOUND_ROWS ';
442 // add everything that was after the first SELECT
443 $count_query .= PMA_SQP_formatHtml($parsed_sql, 'query_only', $analyzed_sql[0]['position_of_first_select']+1);
444 // ensure there is no semicolon at the end of the
445 // count query because we'll probably add
446 // a LIMIT 1 clause after it
447 $count_query = rtrim($count_query);
448 $count_query = rtrim($count_query, ';');
449 } else { // PMA_MYSQL_INT_VERSION < 40000
451 if (!empty($analyzed_sql[0]['from_clause'])) {
452 $count_query .= ' FROM ' . $analyzed_sql[0]['from_clause'];
454 if (!empty($analyzed_sql[0]['where_clause'])) {
455 $count_query .= ' WHERE ' . $analyzed_sql[0]['where_clause'];
457 if (!empty($analyzed_sql[0]['group_by_clause'])) {
458 $count_query .= ' GROUP BY ' . $analyzed_sql[0]['group_by_clause'];
460 if (!empty($analyzed_sql[0]['having_clause'])) {
461 $count_query .= ' HAVING ' . $analyzed_sql[0]['having_clause'];
463 } // end if
465 // if using SQL_CALC_FOUND_ROWS, add a LIMIT to avoid
466 // long delays. Returned count will be complete anyway.
467 // (but a LIMIT would disrupt results in an UNION)
469 if (PMA_MYSQL_INT_VERSION >= 40000
470 && !isset($analyzed_sql[0]['queryflags']['union'])) {
471 $count_query .= ' LIMIT 1';
474 // run the count query
476 if (PMA_MYSQL_INT_VERSION < 40000) {
477 if ($cnt_all_result = PMA_DBI_try_query($count_query)) {
478 if ($is_group && $count_what == '*') {
479 $unlim_num_rows = @PMA_DBI_num_rows($cnt_all_result);
480 } else {
481 $unlim_num_rows = PMA_DBI_fetch_assoc($cnt_all_result);
482 $unlim_num_rows = $unlim_num_rows['count'];
484 PMA_DBI_free_result($cnt_all_result);
485 } else {
486 if (PMA_DBI_getError()) {
488 // there are some cases where the generated
489 // count_query (for MySQL 3) is wrong,
490 // so we get here.
492 * @todo use a big unlimited query to get the correct
493 * number of rows (depending on a config variable?)
495 $unlim_num_rows = 0;
498 } else {
499 PMA_DBI_try_query($count_query);
500 // if (mysql_error()) {
501 // void.
502 // I tried the case
503 // (SELECT `User`, `Host`, `Db`, `Select_priv` FROM `db`)
504 // UNION (SELECT `User`, `Host`, "%" AS "Db",
505 // `Select_priv`
506 // FROM `user`) ORDER BY `User`, `Host`, `Db`;
507 // and although the generated count_query is wrong
508 // the SELECT FOUND_ROWS() work! (maybe it gets the
509 // count from the latest query that worked)
511 // another case where the count_query is wrong:
512 // SELECT COUNT(*), f1 from t1 group by f1
513 // and you click to sort on count(*)
514 // }
515 $cnt_all_result = PMA_DBI_query('SELECT FOUND_ROWS() as count;');
516 list($unlim_num_rows) = PMA_DBI_fetch_row($cnt_all_result);
517 @PMA_DBI_free_result($cnt_all_result);
519 } // end else "just browsing"
521 } else { // not $is_select
522 $unlim_num_rows = 0;
523 } // end rows total count
525 // garvin: if a table or database gets dropped, check column comments.
526 if (isset($purge) && $purge == '1') {
527 require_once './libraries/relation_cleanup.lib.php';
529 if (strlen($table) && strlen($db)) {
530 PMA_relationsCleanupTable($db, $table);
531 } elseif (strlen($db)) {
532 PMA_relationsCleanupDatabase($db);
533 } else {
534 // garvin: VOID. No DB/Table gets deleted.
535 } // end if relation-stuff
536 } // end if ($purge)
538 // garvin: If a column gets dropped, do relation magic.
539 if (isset($cpurge) && $cpurge == '1' && isset($purgekey)
540 && strlen($db) && strlen($table) && !empty($purgekey)) {
541 require_once './libraries/relation_cleanup.lib.php';
542 PMA_relationsCleanupColumn($db, $table, $purgekey);
544 } // end if column PMA_* purge
545 } // end else "didn't ask to see php code"
547 // No rows returned -> move back to the calling page
548 if ($num_rows < 1 || $is_affected) {
549 if ($is_delete) {
550 $message = $strDeletedRows . '&nbsp;' . $num_rows;
551 } elseif ($is_insert) {
552 if ($is_replace) {
553 /* For replace we get DELETED + INSERTED row count, so we have to call it affected */
554 $message = $strAffectedRows . '&nbsp;' . $num_rows;
555 } else {
556 $message = $strInsertedRows . '&nbsp;' . $num_rows;
558 $insert_id = PMA_DBI_insert_id();
559 if ($insert_id != 0) {
560 // insert_id is id of FIRST record inserted in one insert, so if we inserted multiple rows, we had to increment this
561 $message .= '[br]'.$strInsertedRowId . '&nbsp;' . ($insert_id + $num_rows - 1);
563 } elseif ($is_affected) {
564 $message = $strAffectedRows . '&nbsp;' . $num_rows;
566 // Ok, here is an explanation for the !$is_select.
567 // The form generated by sql_query_form.lib.php
568 // and db_sql.php has many submit buttons
569 // on the same form, and some confusion arises from the
570 // fact that $zero_rows is sent for every case.
571 // The $zero_rows containing $strSuccess and sent with
572 // the form should not have priority over
573 // errors like $strEmptyResultSet
574 } elseif (!empty($zero_rows) && !$is_select) {
575 $message = $zero_rows;
576 } elseif (!empty($GLOBALS['show_as_php'])) {
577 $message = $strShowingPhp;
578 } elseif (isset($GLOBALS['show_as_php'])) {
579 /* User disable showing as PHP, query is only displayed */
580 $message = $strShowingSQL;
581 } elseif (!empty($GLOBALS['validatequery'])) {
582 $message = $strValidateSQL;
583 } else {
584 $message = $strEmptyResultSet;
587 $message .= ' ' . (isset($GLOBALS['querytime']) ? '(' . sprintf($strQueryTime, $GLOBALS['querytime']) . ')' : '');
589 if ($is_gotofile) {
590 $goto = PMA_securePath($goto);
591 // Checks for a valid target script
592 $is_db = $is_table = false;
593 include 'libraries/db_table_exists.lib.php';
594 if (strpos($goto, 'tbl_') === 0 && ! $is_table) {
595 if (strlen($table)) {
596 $table = '';
598 $goto = 'db_sql.php';
600 if (strpos($goto, 'db_') === 0 && ! $is_db) {
601 if (strlen($db)) {
602 $db = '';
604 $goto = 'main.php';
606 // Loads to target script
607 if (strpos($goto, 'db_') === 0
608 || strpos($goto, 'tbl_') === 0) {
609 $js_to_run = 'functions.js';
611 if ($goto != 'main.php') {
612 require_once './libraries/header.inc.php';
614 $active_page = $goto;
615 require './' . $goto;
616 } else {
617 // avoid a redirect loop when last record was deleted
618 if ('sql.php' == $cfg['DefaultTabTable']) {
619 $goto = str_replace('sql.php','tbl_structure.php',$goto);
621 PMA_sendHeaderLocation($cfg['PmaAbsoluteUri'] . str_replace('&amp;', '&', $goto) . '&message=' . urlencode($message));
622 } // end else
623 exit();
624 } // end no rows returned
626 // At least one row is returned -> displays a table with results
627 else {
628 // Displays the headers
629 if (isset($show_query)) {
630 unset($show_query);
632 if (isset($printview) && $printview == '1') {
633 require_once './libraries/header_printview.inc.php';
634 } else {
635 $js_to_run = 'functions.js';
636 unset($message);
637 if (strlen($table)) {
638 require './libraries/tbl_common.php';
639 $url_query .= '&amp;goto=tbl_sql.php&amp;back=tbl_sql.php';
640 require './libraries/tbl_info.inc.php';
641 require './libraries/tbl_links.inc.php';
642 } elseif (strlen($db)) {
643 require './libraries/db_common.inc.php';
644 require './libraries/db_info.inc.php';
645 } else {
646 require './libraries/server_common.inc.php';
647 require './libraries/server_links.inc.php';
651 if (strlen($db)) {
652 require_once './libraries/relation.lib.php';
653 $cfgRelation = PMA_getRelationsParam();
656 // Gets the list of fields properties
657 if (isset($result) && $result) {
658 $fields_meta = PMA_DBI_get_fields_meta($result);
659 $fields_cnt = count($fields_meta);
662 // Display previous update query (from tbl_replace)
663 if (isset($disp_query) && $cfg['ShowSQL'] == true) {
664 $tmp_sql_query = $GLOBALS['sql_query'];
665 $GLOBALS['sql_query'] = $disp_query;
666 PMA_showMessage($disp_message);
667 $GLOBALS['sql_query'] = $tmp_sql_query;
670 // Displays the results in a table
671 if (empty($disp_mode)) {
672 // see the "PMA_setDisplayMode()" function in
673 // libraries/display_tbl.lib.php
674 $disp_mode = 'urdr111101';
677 // hide edit and delete links for information_schema
678 if (PMA_MYSQL_INT_VERSION >= 50002 && $db == 'information_schema') {
679 $disp_mode = 'nnnn110111';
682 PMA_displayTable($result, $disp_mode, $analyzed_sql);
683 PMA_DBI_free_result($result);
685 // BEGIN INDEX CHECK See if indexes should be checked.
686 if (isset($query_type) && $query_type == 'check_tbl' && isset($selected) && is_array($selected)) {
687 foreach ($selected as $idx => $tbl_name) {
688 $check = PMA_check_indexes($tbl_name);
689 if (! empty($check)) {
691 <table border="0" cellpadding="2" cellspacing="0">
692 <tr>
693 <td class="tblHeaders" colspan="7"><?php printf($strIndexWarningTable, urldecode($tbl_name)); ?></td>
694 </tr>
695 <?php echo $check; ?>
696 </table>
697 <?php
700 } // End INDEX CHECK
702 // Bookmark support if required
703 if ($disp_mode[7] == '1'
704 && (isset($cfg['Bookmark']) && ! empty($cfg['Bookmark']['db']) && ! empty($cfg['Bookmark']['table']) && empty($id_bookmark))
705 && !empty($sql_query)) {
706 echo "\n";
708 $goto = 'sql.php?'
709 . PMA_generate_common_url($db, $table)
710 . '&amp;sql_query=' . urlencode($sql_query)
711 . '&amp;id_bookmark=1';
714 <form action="sql.php" method="post" onsubmit="return emptyFormElements(this, 'fields[label]');">
715 <?php echo PMA_generate_common_hidden_inputs(); ?>
716 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
717 <input type="hidden" name="fields[dbase]" value="<?php echo htmlspecialchars($db); ?>" />
718 <input type="hidden" name="fields[user]" value="<?php echo $cfg['Bookmark']['user']; ?>" />
719 <input type="hidden" name="fields[query]" value="<?php echo urlencode(isset($complete_query) ? $complete_query : $sql_query); ?>" />
720 <fieldset>
721 <legend><?php
722 echo ($cfg['PropertiesIconic'] ? '<img class="icon" src="' . $pmaThemeImage . 'b_bookmark.png" width="16" height="16" alt="' . $strBookmarkThis . '" />' : '')
723 . $strBookmarkThis;
725 </legend>
727 <div class="formelement">
728 <label for="fields_label_"><?php echo $strBookmarkLabel; ?>:</label>
729 <input type="text" id="fields_label_" name="fields[label]" value="" />
730 </div>
732 <div class="formelement">
733 <input type="checkbox" name="bkm_all_users" id="bkm_all_users" value="true" />
734 <label for="bkm_all_users"><?php echo $strBookmarkAllUsers; ?></label>
735 </div>
737 <div class="clearfloat"></div>
738 </fieldset>
739 <fieldset class="tblFooters">
740 <input type="submit" name="store_bkm" value="<?php echo $strBookmarkThis; ?>" />
741 </fieldset>
742 </form>
743 <?php
744 } // end bookmark support
746 // Do print the page if required
747 if (isset($printview) && $printview == '1') {
749 <script type="text/javascript">
750 //<![CDATA[
751 // Do print the page
752 window.onload = function()
754 if (typeof(window.print) != 'undefined') {
755 window.print();
758 //]]>
759 </script>
760 <?php
761 } // end print case
762 } // end rows returned
765 * Displays the footer
767 require_once './libraries/footer.inc.php';