3 // vim: expandtab sw=4 ts=4 sts=4:
6 * Gets some core libraries
8 require('./libraries/grab_globals.lib.php3');
9 require('./libraries/common.lib.php3');
12 * Defines the url to return to in case of error in a sql statement
16 $is_gotofile = ereg_replace('^([^?]+).*$', '\\1', $goto);
17 if (!@file_exists
('./' . $is_gotofile)) {
20 $is_gotofile = ($is_gotofile == $goto);
22 } // end if (security checkings)
25 $goto = (empty($table)) ?
$cfg['DefaultTabDatabase'] : $cfg['DefaultTabTable'];
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)) ?
'&table=' . urlencode($table) : '');
34 // Coming from a bookmark dialog
35 if (isset($fields['query'])) {
36 $sql_query = $fields['query'];
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);
63 if (isset($store_bkm)) {
64 include('./libraries/bookmark.lib.php3');
65 PMA_addBookmarks($fields, $cfg['Bookmark']);
66 header('Location: ' . $cfg['PmaAbsoluteUri'] . $goto);
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);
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
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)
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'];
117 $reload = ($db == $prev_db) ?
0 : 1;
121 * Sets or modifies the $goto variable if required
123 if ($goto == 'sql.php3') {
125 . PMA_generate_common_url($db, $table)
127 . '&sql_query=' . urlencode($sql_query);
132 * Go back to further page if table should not be dropped
134 if (isset($btnDrop) && $btnDrop == $strNo) {
139 if (strpos(' ' . $goto, 'db_details') == 1 && !empty($table)) {
142 include('./' . ereg_replace('\.\.*', '.', $goto));
144 header('Location: ' . $cfg['PmaAbsoluteUri'] . str_replace('&', '&', $goto));
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
160 ||
(isset($is_js_confirmed) && $is_js_confirmed)
162 ||
!empty($GLOBALS['show_as_php'])
163 ||
!empty($GLOBALS['validatequery'])) {
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']);
172 $stripped_sql_query = $sql_query;
173 include('./header.inc.php3');
174 echo $strDoYouReally . ' :<br />' . "\n";
175 echo '<tt>' . htmlspecialchars($stripped_sql_query) . '</tt> ?<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; ?>" />
197 * Executes the query and displays results
200 if (!isset($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)) {
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
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)) {
238 } else if (eregi('^DELETE[[:space:]]+', $sql_query)) {
241 } else if (eregi('^(INSERT|LOAD[[:space:]]+DATA|REPLACE)[[:space:]]+', $sql_query)) {
244 } else if (eregi('^UPDATE[[:space:]]+', $sql_query)) {
246 } else if (eregi('^SHOW[[:space:]]+', $sql_query)) {
248 } else if (eregi('^(CHECK|ANALYZE|REPAIR|OPTIMIZE)[[:space:]]+TABLE[[:space:]]+', $sql_query)) {
252 // Do append a "LIMIT" clause?
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];
262 $full_sql_query = $sql_query . $sql_limit_to_append;
265 $full_sql_query = $sql_query;
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
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);
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'])) {
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 . '&show_query=1&sql_query=' . urlencode($sql_query)
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)
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']) {
332 @mysql_free_result
($res);
336 // tmpfile remove after convert encoding appended by Y.Kawada
337 if (function_exists('PMA_kanji_file_conv')
338 && (isset($textfile) && file_exists($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'];
359 $count_query = 'SELECT COUNT(' . $count_what . ') AS count';
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
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 // if using SQL_CALC_FOUND_ROWS, add a LIMIT to avoid
396 // long delays. Returned count will be complete anyway.
398 if (PMA_MYSQL_INT_VERSION
>= 40000) {
399 $count_query .= ' LIMIT 1';
402 // do not put the order_by_clause, it interferes
403 // run the count query
404 if (PMA_MYSQL_INT_VERSION
< 40000) {
405 if ($cnt_all_result = mysql_query($count_query)) {
407 $unlim_num_rows = @mysql_num_rows
($cnt_all_result);
409 $unlim_num_rows = mysql_result($cnt_all_result, 0, 'count');
411 mysql_free_result($cnt_all_result);
414 // there are some cases where the generated
415 // count_query (for MySQL 3) is wrong,
417 //TODO: use a big unlimited query to get
418 // the correct number of rows (depending
419 // on a config variable?)
424 mysql_query($count_query);
426 // void. I tried the case
427 // (SELECT `User`, `Host`, `Db`, `Select_priv` FROM `db`)
428 // UNION (SELECT `User`, `Host`, "%" AS "Db",
430 // FROM `user`) ORDER BY `User`, `Host`, `Db`;
431 // and although the generated count_query is wrong
432 // the SELECT FOUND_ROWS() work!
434 $cnt_all_result = mysql_query('SELECT FOUND_ROWS() as count');
435 $unlim_num_rows = mysql_result($cnt_all_result,0,'count');
438 } else { // not $is_select
440 } // end rows total count
442 // garvin: if a table or database gets dropped, check column comments.
443 if (isset($purge) && $purge == '1') {
444 include('./libraries/relation.lib.php3');
445 $cfgRelation = PMA_getRelationsParam();
447 if (isset($table) && isset($db) && !empty($table) && !empty($db)) {
448 // garvin: Only a table is deleted. Remove all references in PMA_*
449 if ($cfgRelation['commwork']) {
450 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['column_info'])
451 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
452 . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'';
453 $rmv_rs = PMA_query_as_cu($remove_query);
457 if ($cfgRelation['displaywork']) {
458 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['table_info'])
459 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
460 . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'';
461 $rmv_rs = PMA_query_as_cu($remove_query);
465 if ($cfgRelation['pdfwork']) {
466 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['table_coords'])
467 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
468 . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'';
469 $rmv_rs = PMA_query_as_cu($remove_query);
473 if ($cfgRelation['relwork']) {
474 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['relation'])
475 . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\''
476 . ' AND master_table = \'' . PMA_sqlAddslashes($table) . '\'';
477 $rmv_rs = PMA_query_as_cu($remove_query);
480 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['relation'])
481 . ' WHERE foreign_db = \'' . PMA_sqlAddslashes($db) . '\''
482 . ' AND foreign_table = \'' . PMA_sqlAddslashes($table) . '\'';
483 $rmv_rs = PMA_query_as_cu($remove_query);
486 } elseif (isset($db) && !empty($db)) {
487 // garvin: A whole DB gets deleted. Remove all references in PMA_*
488 if ($cfgRelation['commwork']) {
489 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['column_info'])
490 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
491 $rmv_rs = PMA_query_as_cu($remove_query);
495 if ($cfgRelation['bookmarkwork']) {
496 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['bookmark'])
497 . ' WHERE dbase = \'' . PMA_sqlAddslashes($db) . '\'';
498 $rmv_rs = PMA_query_as_cu($remove_query);
502 if ($cfgRelation['displaywork']) {
503 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['table_info'])
504 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
505 $rmv_rs = PMA_query_as_cu($remove_query);
509 if ($cfgRelation['pdfwork']) {
510 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['pdf_pages'])
511 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
512 $rmv_rs = PMA_query_as_cu($remove_query);
515 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['table_coords'])
516 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
517 $rmv_rs = PMA_query_as_cu($remove_query);
521 if ($cfgRelation['relwork']) {
522 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['relation'])
523 . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\'';
524 $rmv_rs = PMA_query_as_cu($remove_query);
527 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['relation'])
528 . ' WHERE foreign_db = \'' . PMA_sqlAddslashes($db) . '\'';
529 $rmv_rs = PMA_query_as_cu($remove_query);
534 // garvin: VOID. No DB/Table gets deleted.
535 } // end if relation-stuff
538 // garvin: If a column gets dropped, do relation magic.
539 if (isset($cpurge) && $cpurge == '1' && isset($purgekey)
540 && isset($db) && isset($table)
541 && !empty($db) && !empty($table) && !empty($purgekey)) {
542 include('./libraries/relation.lib.php3');
543 $cfgRelation = PMA_getRelationsParam();
545 if ($cfgRelation['commwork']) {
546 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['column_info'])
547 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
548 . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''
549 . ' AND column_name = \'' . PMA_sqlAddslashes(urldecode($purgekey)) . '\'';
550 $rmv_rs = PMA_query_as_cu($remove_query);
554 if ($cfgRelation['displaywork']) {
555 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['table_info'])
556 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
557 . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''
558 . ' AND display_field = \'' . PMA_sqlAddslashes(urldecode($purgekey)) . '\'';
559 $rmv_rs = PMA_query_as_cu($remove_query);
563 if ($cfgRelation['relwork']) {
564 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['relation'])
565 . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\''
566 . ' AND master_table = \'' . PMA_sqlAddslashes($table) . '\''
567 . ' AND master_field = \'' . PMA_sqlAddslashes(urldecode($purgekey)) . '\'';
568 $rmv_rs = PMA_query_as_cu($remove_query);
571 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['relation'])
572 . ' WHERE foreign_db = \'' . PMA_sqlAddslashes($db) . '\''
573 . ' AND foreign_table = \'' . PMA_sqlAddslashes($table) . '\''
574 . ' AND foreign_field = \'' . PMA_sqlAddslashes(urldecode($purgekey)) . '\'';
575 $rmv_rs = PMA_query_as_cu($remove_query);
578 } // end if column PMA_* purge
579 } // end else "didn't ask to see php code"
582 // No rows returned -> move back to the calling page
583 if ($num_rows < 1 ||
$is_affected) {
585 $message = $strDeletedRows . ' ' . $num_rows;
586 } else if ($is_insert) {
587 $message = $strInsertedRows . ' ' . $num_rows;
588 } else if ($is_affected) {
589 $message = $strAffectedRows . ' ' . $num_rows;
590 } else if (!empty($zero_rows)) {
591 $message = $zero_rows;
592 } else if (!empty($GLOBALS['show_as_php'])) {
594 } else if (!empty($GLOBALS['validatequery'])) {
595 $message = $strValidateSQL;
597 $message = $strEmptyResultSet;
600 $message .= ' ' . (isset($GLOBALS['querytime']) ?
'(' . sprintf($strQueryTime, $GLOBALS['querytime']) . ')' : '');
603 $goto = ereg_replace('\.\.*', '.', $goto);
604 // Checks for a valid target script
605 if (isset($table) && $table == '') {
608 if (isset($db) && $db == '') {
611 $is_db = $is_table = FALSE;
612 if (strpos(' ' . $goto, 'tbl_properties') == 1) {
613 if (!isset($table)) {
614 $goto = 'db_details.php3';
616 $is_table = @PMA_mysql_query
('SHOW TABLES LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\'');
617 if (!($is_table && @mysql_numrows
($is_table))) {
618 $goto = 'db_details.php3';
621 } // end if... else...
623 if (strpos(' ' . $goto, 'db_details') == 1) {
630 $is_db = @PMA_mysql_select_db
($db);
635 } // end if... else...
637 // Loads to target script
638 if (strpos(' ' . $goto, 'db_details') == 1
639 ||
strpos(' ' . $goto, 'tbl_properties') == 1) {
640 $js_to_run = 'functions.js';
642 if ($goto != 'main.php3') {
643 include('./header.inc.php3');
645 include('./' . $goto);
646 } // end if file_exist
648 header('Location: ' . $cfg['PmaAbsoluteUri'] . str_replace('&', '&', $goto) . '&message=' . urlencode($message));
651 } // end no rows returned
653 // At least one row is returned -> displays a table with results
655 // Displays the headers
656 if (isset($show_query)) {
659 if (isset($printview) && $printview == '1') {
660 include('./header_printview.inc.php3');
662 $js_to_run = 'functions.js';
664 if (!empty($table)) {
665 include('./tbl_properties_common.php3');
666 $url_query .= '&goto=tbl_properties.php3&back=tbl_properties.php3';
667 include('./tbl_properties_table_info.php3');
670 include('./db_details_common.php3');
671 include('./db_details_db_info.php3');
673 include('./libraries/relation.lib.php3');
674 $cfgRelation = PMA_getRelationsParam();
677 // Gets the list of fields properties
678 if (isset($result) && $result) {
679 while ($field = PMA_mysql_fetch_field($result)) {
680 $fields_meta[] = $field;
682 $fields_cnt = count($fields_meta);
685 // Display previous update query (from tbl_replace)
686 if (isset($disp_query) && $cfg['ShowSQL'] == TRUE) {
687 $tmp_sql_query = $GLOBALS['sql_query'];
688 $tmp_sql_limit_to_append = (isset($GLOBALS['sql_limit_to_append'])?
$GLOBALS['sql_limit_to_append']:'');
689 $GLOBALS['sql_query'] = $disp_query;
690 $GLOBALS['sql_limit_to_append'] = '';
691 PMA_showMessage($disp_message);
692 $GLOBALS['sql_query'] = $tmp_sql_query;
693 $GLOBALS['sql_limit_to_append'] = $tmp_sql_limit_to_append;
696 // Displays the results in a table
697 include('./libraries/display_tbl.lib.php3');
698 if (empty($disp_mode)) {
699 // see the "PMA_setDisplayMode()" function in
700 // libraries/display_tbl.lib.php3
701 $disp_mode = 'urdr111101';
703 if (!isset($dontlimitchars)) {
707 PMA_displayTable($result, $disp_mode, $analyzed_sql);
708 mysql_free_result($result);
710 if ($disp_mode[6] == '1' ||
$disp_mode[9] == '1') {
714 // Displays "Insert a new row" link if required
715 if ($disp_mode[6] == '1') {
716 $lnk_goto = 'sql.php3?'
717 . PMA_generate_common_url($db, $table)
719 . '&session_max_rows=' . $session_max_rows
720 . '&disp_direction=' . $disp_direction
721 . '&repeat_cells=' . $repeat_cells
722 . '&dontlimitchars=' . $dontlimitchars
723 . '&sql_query=' . urlencode($sql_query);
725 . PMA_generate_common_url($db, $table)
727 . '&session_max_rows=' . $session_max_rows
728 . '&disp_direction=' . $disp_direction
729 . '&repeat_cells=' . $repeat_cells
730 . '&dontlimitchars=' . $dontlimitchars
731 . '&sql_query=' . urlencode($sql_query)
732 . '&goto=' . urlencode($lnk_goto);
734 echo ' <!-- Insert a new row -->' . "\n"
735 . ' <a href="tbl_change.php3' . $url_query . '">' . $strInsertNewRow . '</a>';
736 if ($disp_mode[9] == '1') {
740 } // end insert new row
742 // Displays "printable view" link if required
743 if ($disp_mode[9] == '1') {
745 . PMA_generate_common_url($db, $table)
747 . '&session_max_rows=' . $session_max_rows
748 . '&disp_direction=' . $disp_direction
749 . '&repeat_cells=' . $repeat_cells
751 . ((isset($dontlimitchars) && $dontlimitchars == '1') ?
'&dontlimitchars=1' : '')
752 . '&sql_query=' . urlencode($sql_query);
753 echo ' <!-- Print view -->' . "\n"
754 . ' <a href="sql.php3' . $url_query . '" target="print_view">' . $strPrintView . '</a>' . "\n";
755 } // end displays "printable view"
760 // Export link, if only one table
761 // (the url_query has extra parameters that won't be used to export)
762 if (!isset($printview)
763 && isset($analyzed_sql[0]['table_ref'][0]['table_true_name'])
764 && !isset($analyzed_sql[0]['table_ref'][1]['table_true_name'])) {
765 echo ' <!-- Export -->' . "\n"
766 . ' <a href="tbl_properties_export.php3' . $url_query . '&unlim_num_rows=' . $unlim_num_rows . '">' . $strExport . '</a>' . "\n";
769 // Bookmark Support if required
770 if ($disp_mode[7] == '1'
771 && ($cfg['Bookmark']['db'] && $cfg['Bookmark']['table'] && empty($id_bookmark))
772 && !empty($sql_query)) {
776 . PMA_generate_common_url($db, $table)
778 . '&session_max_rows=' . $session_max_rows
779 . '&disp_direction=' . $disp_direction
780 . '&repeat_cells=' . $repeat_cells
781 . '&dontlimitchars=' . $dontlimitchars
782 . '&sql_query=' . urlencode($sql_query)
783 . '&id_bookmark=1';
785 <!-- Bookmark the query
-->
786 <form action
="sql.php3" method
="post" onsubmit
="return emptyFormElements(this, 'fields[label]');">
789 if ($disp_mode[3] == '1') {
790 echo ' <i>' . $strOr . '</i>' . "\n";
794 <?php
echo $strBookmarkLabel; ?
> 
;:
795 <?php
echo PMA_generate_common_hidden_inputs(); ?
>
796 <input type
="hidden" name
="goto" value
="<?php echo $goto; ?>" />
797 <input type
="hidden" name
="fields[dbase]" value
="<?php echo htmlspecialchars($db); ?>" />
798 <input type
="hidden" name
="fields[user]" value
="<?php echo $cfg['Bookmark']['user']; ?>" />
799 <input type
="hidden" name
="fields[query]" value
="<?php echo urlencode($sql_query); ?>" />
800 <input type
="text" name
="fields[label]" value
="" />
801 <input type
="submit" name
="store_bkm" value
="<?php echo $strBookmarkThis; ?>" />
804 } // end bookmark support
806 // Do print the page if required
807 if (isset($printview) && $printview == '1') {
810 <script type
="text/javascript" language
="javascript1.2">
813 if (typeof(window
.print) != 'undefined') {
820 } // end rows returned
822 } // end executes the query
827 * Displays the footer
829 require('./footer.inc.php3');