lang
[phpmyadmin/crack.git] / sql.php3
blobd5dd3dffd7d8be8f62c1bbf37f10ea398108054a
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 $active_page = $goto;
143 include('./' . ereg_replace('\.\.*', '.', $goto));
144 } else {
145 header('Location: ' . $cfg['PmaAbsoluteUri'] . str_replace('&amp;', '&', $goto));
147 exit();
148 } // end if
152 * Displays the confirm page if required
154 * This part of the script is bypassed if $is_js_confirmed = 1 (already checked
155 * with js) because possible security issue is not so important here: at most,
156 * the confirm message isn't displayed.
158 * Also bypassed if only showing php code.or validating a SQL query
160 if (!$cfg['Confirm']
161 || (isset($is_js_confirmed) && $is_js_confirmed)
162 || isset($btnDrop)
163 || !empty($GLOBALS['show_as_php'])
164 || !empty($GLOBALS['validatequery'])) {
165 $do_confirm = FALSE;
166 } else {
167 //$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));
169 $do_confirm = isset($analyzed_sql[0]['queryflags']['need_confirm']);
172 if ($do_confirm) {
173 $stripped_sql_query = $sql_query;
174 include('./header.inc.php3');
175 echo $strDoYouReally . '&nbsp;:<br />' . "\n";
176 echo '<tt>' . htmlspecialchars($stripped_sql_query) . '</tt>&nbsp;?<br/>' . "\n";
178 <form action="sql.php3" method="post">
179 <?php echo PMA_generate_common_hidden_inputs($db, (isset($table)?$table:'')); ?>
180 <input type="hidden" name="sql_query" value="<?php echo urlencode($sql_query); ?>" />
181 <input type="hidden" name="zero_rows" value="<?php echo isset($zero_rows) ? $zero_rows : ''; ?>" />
182 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
183 <input type="hidden" name="back" value="<?php echo isset($back) ? $back : ''; ?>" />
184 <input type="hidden" name="reload" value="<?php echo isset($reload) ? $reload : 0; ?>" />
185 <input type="hidden" name="purge" value="<?php echo isset($purge) ? $purge : ''; ?>" />
186 <input type="hidden" name="cpurge" value="<?php echo isset($cpurge) ? $cpurge : ''; ?>" />
187 <input type="hidden" name="purgekey" value="<?php echo isset($purgekey) ? $purgekey : ''; ?>" />
188 <input type="hidden" name="show_query" value="<?php echo isset($show_query) ? $show_query : ''; ?>" />
189 <input type="submit" name="btnDrop" value="<?php echo $strYes; ?>" />
190 <input type="submit" name="btnDrop" value="<?php echo $strNo; ?>" />
191 </form>
192 <?php
193 echo "\n";
194 } // end if
198 * Executes the query and displays results
200 else {
201 if (!isset($sql_query)) {
202 $sql_query = '';
204 // Defines some variables
205 // loic1: A table has to be created -> left frame should be reloaded
206 if ((!isset($reload) || $reload == 0)
207 && eregi('^CREATE TABLE[[:space:]]+(.*)', $sql_query)) {
208 $reload = 1;
210 // Gets the number of rows per page
211 if (!isset($session_max_rows)) {
212 $session_max_rows = $cfg['MaxRows'];
213 } else if ($session_max_rows != 'all') {
214 $cfg['MaxRows'] = $session_max_rows;
216 // Defines the display mode (horizontal/vertical) and header "frequency"
217 if (empty($disp_direction)) {
218 $disp_direction = $cfg['DefaultDisplay'];
220 if (empty($repeat_cells)) {
221 $repeat_cells = $cfg['RepeatCells'];
224 // SK -- Patch: $is_group added for use in calculation of total number of
225 // rows.
226 // $is_count is changed for more correct "LIMIT" clause
227 // appending in queries like
228 // "SELECT COUNT(...) FROM ... GROUP BY ..."
229 $is_explain = $is_count = $is_export = $is_delete = $is_insert = $is_affected = $is_show = $is_maint = $is_analyse = $is_group = $is_func = FALSE;
230 if ($is_select) { // see line 141
231 $is_group = eregi('(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 (isset($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 we are "just browsing", there is only one table,
353 // and no where clause (or just 'WHERE 1 '),
354 // so we do a quick count (which uses MaxExactCount)
355 // because SQL_CALC_FOUND_ROWS
356 // is not quick on large InnoDB tables
358 if (!$is_group
359 && !isset($analyzed_sql[0]['queryflags']['union'])
360 && !isset($analyzed_sql[0]['table_ref'][1]['table_name'])
361 && (empty($analyzed_sql[0]['where_clause'])
362 || $analyzed_sql[0]['where_clause'] == '1 ')) {
364 // "j u s t b r o w s i n g"
365 $unlim_num_rows = PMA_countRecords($db, $table, TRUE);
367 } else { // n o t " j u s t b r o w s i n g "
369 if (PMA_MYSQL_INT_VERSION < 40000) {
370 if (eregi('DISTINCT(.*)', $sql_query)) {
371 $count_what = 'DISTINCT ' . $analyzed_sql[0]['select_expr_clause'];
372 } else {
373 $count_what = '*';
376 $count_query = 'SELECT COUNT(' . $count_what . ') AS count';
379 // add the remaining of select expression if there is
380 // a GROUP BY or HAVING clause
381 if (PMA_MYSQL_INT_VERSION < 40000
382 && $count_what =='*'
383 && (!empty($analyzed_sql[0]['group_by_clause'])
384 || !empty($analyzed_sql[0]['having_clause']))) {
385 $count_query .= ' ,' . $analyzed_sql[0]['select_expr_clause'];
388 if (PMA_MYSQL_INT_VERSION >= 40000) {
389 // add select expression after the SQL_CALC_FOUND_ROWS
390 // if (eregi('DISTINCT(.*)', $sql_query)) {
391 // $count_query .= 'DISTINCT ' . $analyzed_sql[0]['select_expr_clause'];
392 // } else {
393 //$count_query .= $analyzed_sql[0]['select_expr_clause'];
395 // for UNION, just adding SQL_CALC_FOUND_ROWS
396 // after the first SELECT works.
398 // take the left part, could be:
399 // SELECT
400 // (SELECT
401 $count_query = PMA_SQP_formatHtml($parsed_sql, 'query_only', 0, $analyzed_sql[0]['position_of_first_select'] + 1);
402 $count_query .= ' SQL_CALC_FOUND_ROWS ';
404 // add everything that was after the first SELECT
405 $count_query .= PMA_SQP_formatHtml($parsed_sql, 'query_only', $analyzed_sql[0]['position_of_first_select']+1);
406 // }
407 } else { // PMA_MYSQL_INT_VERSION < 40000
409 if (!empty($analyzed_sql[0]['from_clause'])) {
410 $count_query .= ' FROM ' . $analyzed_sql[0]['from_clause'];
412 if (!empty($analyzed_sql[0]['where_clause'])) {
413 $count_query .= ' WHERE ' . $analyzed_sql[0]['where_clause'];
415 if (!empty($analyzed_sql[0]['group_by_clause'])) {
416 $count_query .= ' GROUP BY ' . $analyzed_sql[0]['group_by_clause'];
418 if (!empty($analyzed_sql[0]['having_clause'])) {
419 $count_query .= ' HAVING ' . $analyzed_sql[0]['having_clause'];
421 } // end if
423 // if using SQL_CALC_FOUND_ROWS, add a LIMIT to avoid
424 // long delays. Returned count will be complete anyway.
425 // (but a LIMIT would disrupt results in an UNION)
427 if (PMA_MYSQL_INT_VERSION >= 40000
428 && !isset($analyzed_sql[0]['queryflags']['union'])) {
429 $count_query .= ' LIMIT 1';
432 // run the count query
433 //DEBUG echo "trace cq=" . $count_query . "<br/>";
435 if (PMA_MYSQL_INT_VERSION < 40000) {
436 if ($cnt_all_result = PMA_mysql_query($count_query)) {
437 if ($is_group) {
438 // if ($count_what == '*') {
439 $unlim_num_rows = @mysql_num_rows($cnt_all_result);
440 } else {
441 $unlim_num_rows = PMA_mysql_result($cnt_all_result, 0, 'count');
443 mysql_free_result($cnt_all_result);
444 } else {
445 if (mysql_error()) {
447 // there are some cases where the generated
448 // count_query (for MySQL 3) is wrong,
449 // so we get here.
450 //TODO: use a big unlimited query to get
451 // the correct number of rows (depending
452 // on a config variable?)
453 $unlim_num_rows = 0;
456 } else {
457 PMA_mysql_query($count_query);
458 if (mysql_error()) {
459 // void. I tried the case
460 // (SELECT `User`, `Host`, `Db`, `Select_priv` FROM `db`)
461 // UNION (SELECT `User`, `Host`, "%" AS "Db",
462 // `Select_priv`
463 // FROM `user`) ORDER BY `User`, `Host`, `Db`;
464 // and although the generated count_query is wrong
465 // the SELECT FOUND_ROWS() work!
467 $cnt_all_result = PMA_mysql_query('SELECT FOUND_ROWS() as count');
468 $unlim_num_rows = PMA_mysql_result($cnt_all_result,0,'count');
470 } // end else "just browsing"
472 } else { // not $is_select
473 $unlim_num_rows = 0;
474 } // end rows total count
476 // garvin: if a table or database gets dropped, check column comments.
477 if (isset($purge) && $purge == '1') {
478 include('./libraries/relation_cleanup.lib.php3');
480 if (isset($table) && isset($db) && !empty($table) && !empty($db)) {
481 PMA_relationsCleanupTable($db, $table);
482 } elseif (isset($db) && !empty($db)) {
483 PMA_relationsCleanupDatabase($db);
484 } else {
485 // garvin: VOID. No DB/Table gets deleted.
486 } // end if relation-stuff
487 } // end if ($purge)
489 // garvin: If a column gets dropped, do relation magic.
490 if (isset($cpurge) && $cpurge == '1' && isset($purgekey)
491 && isset($db) && isset($table)
492 && !empty($db) && !empty($table) && !empty($purgekey)) {
493 include('./libraries/relation_cleanup.lib.php3');
494 PMA_relationsCleanupColumn($db, $table, $purgekey);
496 } // end if column PMA_* purge
497 } // end else "didn't ask to see php code"
500 // No rows returned -> move back to the calling page
501 if ($num_rows < 1 || $is_affected) {
502 if ($is_delete) {
503 $message = $strDeletedRows . '&nbsp;' . $num_rows;
504 } else if ($is_insert) {
505 $message = $strInsertedRows . '&nbsp;' . $num_rows;
506 $insert_id = mysql_insert_id();
507 if ($insert_id != 0) {
508 $message .= '<br />'.$strInsertedRowId . '&nbsp;' . $insert_id;
510 } else if ($is_affected) {
511 $message = $strAffectedRows . '&nbsp;' . $num_rows;
512 } else if (!empty($zero_rows)) {
513 $message = $zero_rows;
514 } else if (!empty($GLOBALS['show_as_php'])) {
515 $message = $strPhp;
516 } else if (!empty($GLOBALS['validatequery'])) {
517 $message = $strValidateSQL;
518 } else {
519 $message = $strEmptyResultSet;
522 $message .= ' ' . (isset($GLOBALS['querytime']) ? '(' . sprintf($strQueryTime, $GLOBALS['querytime']) . ')' : '');
524 if ($is_gotofile) {
525 $goto = ereg_replace('\.\.*', '.', $goto);
526 // Checks for a valid target script
527 if (isset($table) && $table == '') {
528 unset($table);
530 if (isset($db) && $db == '') {
531 unset($db);
533 $is_db = $is_table = FALSE;
534 if (strpos(' ' . $goto, 'tbl_properties') == 1) {
535 if (!isset($table)) {
536 $goto = 'db_details.php3';
537 } else {
538 $is_table = @PMA_mysql_query('SHOW TABLES LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\'');
539 if (!($is_table && @mysql_numrows($is_table))) {
540 $goto = 'db_details.php3';
541 unset($table);
543 } // end if... else...
545 if (strpos(' ' . $goto, 'db_details') == 1) {
546 if (isset($table)) {
547 unset($table);
549 if (!isset($db)) {
550 $goto = 'main.php3';
551 } else {
552 $is_db = @PMA_mysql_select_db($db);
553 if (!$is_db) {
554 $goto = 'main.php3';
555 unset($db);
557 } // end if... else...
559 // Loads to target script
560 if (strpos(' ' . $goto, 'db_details') == 1
561 || strpos(' ' . $goto, 'tbl_properties') == 1) {
562 $js_to_run = 'functions.js';
564 if ($goto != 'main.php3') {
565 include('./header.inc.php3');
567 $active_page = $goto;
568 include('./' . $goto);
569 } // end if file_exist
570 else {
571 header('Location: ' . $cfg['PmaAbsoluteUri'] . str_replace('&amp;', '&', $goto) . '&message=' . urlencode($message));
572 } // end else
573 exit();
574 } // end no rows returned
576 // At least one row is returned -> displays a table with results
577 else {
578 // Displays the headers
579 if (isset($show_query)) {
580 unset($show_query);
582 if (isset($printview) && $printview == '1') {
583 include('./header_printview.inc.php3');
584 } else {
585 $js_to_run = 'functions.js';
586 unset($message);
587 if (!empty($table)) {
588 include('./tbl_properties_common.php3');
589 $url_query .= '&amp;goto=tbl_properties.php3&amp;back=tbl_properties.php3';
590 include('./tbl_properties_table_info.php3');
592 else {
593 include('./db_details_common.php3');
594 include('./db_details_db_info.php3');
596 include('./libraries/relation.lib.php3');
597 $cfgRelation = PMA_getRelationsParam();
600 // Gets the list of fields properties
601 if (isset($result) && $result) {
602 while ($field = PMA_mysql_fetch_field($result)) {
603 $fields_meta[] = $field;
605 $fields_cnt = count($fields_meta);
608 // Display previous update query (from tbl_replace)
609 if (isset($disp_query) && $cfg['ShowSQL'] == TRUE) {
610 $tmp_sql_query = $GLOBALS['sql_query'];
611 $tmp_sql_limit_to_append = (isset($GLOBALS['sql_limit_to_append'])?$GLOBALS['sql_limit_to_append']:'');
612 $GLOBALS['sql_query'] = $disp_query;
613 $GLOBALS['sql_limit_to_append'] = '';
614 PMA_showMessage($disp_message);
615 $GLOBALS['sql_query'] = $tmp_sql_query;
616 $GLOBALS['sql_limit_to_append'] = $tmp_sql_limit_to_append;
619 // Displays the results in a table
620 include('./libraries/display_tbl.lib.php3');
621 if (empty($disp_mode)) {
622 // see the "PMA_setDisplayMode()" function in
623 // libraries/display_tbl.lib.php3
624 $disp_mode = 'urdr111101';
626 if (!isset($dontlimitchars)) {
627 $dontlimitchars = 0;
630 PMA_displayTable($result, $disp_mode, $analyzed_sql);
631 mysql_free_result($result);
633 if ($disp_mode[6] == '1' || $disp_mode[9] == '1') {
634 echo "\n";
635 echo '<p>' . "\n";
637 // Displays "Insert a new row" link if required
638 if ($disp_mode[6] == '1') {
639 $lnk_goto = 'sql.php3?'
640 . PMA_generate_common_url($db, $table)
641 . '&amp;pos=' . $pos
642 . '&amp;session_max_rows=' . $session_max_rows
643 . '&amp;disp_direction=' . $disp_direction
644 . '&amp;repeat_cells=' . $repeat_cells
645 . '&amp;dontlimitchars=' . $dontlimitchars
646 . '&amp;sql_query=' . urlencode($sql_query);
647 $url_query = '?'
648 . PMA_generate_common_url($db, $table)
649 . '&amp;pos=' . $pos
650 . '&amp;session_max_rows=' . $session_max_rows
651 . '&amp;disp_direction=' . $disp_direction
652 . '&amp;repeat_cells=' . $repeat_cells
653 . '&amp;dontlimitchars=' . $dontlimitchars
654 . '&amp;sql_query=' . urlencode($sql_query)
655 . '&amp;goto=' . urlencode($lnk_goto);
657 echo ' <!-- Insert a new row -->' . "\n"
658 . ' <a href="tbl_change.php3' . $url_query . '">' . $strInsertNewRow . '</a>';
659 if ($disp_mode[9] == '1') {
660 echo '<br />';
662 echo "\n";
663 } // end insert new row
665 // Displays "printable view" link if required
666 if ($disp_mode[9] == '1') {
667 $url_query = '?'
668 . PMA_generate_common_url($db, $table)
669 . '&amp;pos=' . $pos
670 . '&amp;session_max_rows=' . $session_max_rows
671 . '&amp;disp_direction=' . $disp_direction
672 . '&amp;repeat_cells=' . $repeat_cells
673 . '&amp;printview=1'
674 . ((isset($dontlimitchars) && $dontlimitchars == '1') ? '&amp;dontlimitchars=1' : '')
675 . '&amp;sql_query=' . urlencode($sql_query);
676 echo ' <!-- Print view -->' . "\n"
677 . ' <a href="sql.php3' . $url_query . '" target="print_view">' . $strPrintView . '</a>' . "\n";
678 } // end displays "printable view"
680 echo '</p>' . "\n";
683 // Export link, if only one table
684 // (the url_query has extra parameters that won't be used to export)
685 if (!isset($printview)) {
686 if (isset($analyzed_sql[0]['table_ref'][0]['table_true_name']) && !isset($analyzed_sql[0]['table_ref'][1]['table_true_name'])) {
687 $single_table = '&amp;single_table=true';
688 } else {
689 $single_table = '';
691 echo ' <!-- Export -->' . "\n"
692 . ' <a href="tbl_properties_export.php3' . $url_query
693 . '&amp;unlim_num_rows=' . $unlim_num_rows
694 . $single_table
695 . '">' . $strExport . '</a>' . "\n";
698 // Bookmark Support if required
699 if ($disp_mode[7] == '1'
700 && ($cfg['Bookmark']['db'] && $cfg['Bookmark']['table'] && empty($id_bookmark))
701 && !empty($sql_query)) {
702 echo "\n";
704 $goto = 'sql.php3?'
705 . PMA_generate_common_url($db, $table)
706 . '&amp;pos=' . $pos
707 . '&amp;session_max_rows=' . $session_max_rows
708 . '&amp;disp_direction=' . $disp_direction
709 . '&amp;repeat_cells=' . $repeat_cells
710 . '&amp;dontlimitchars=' . $dontlimitchars
711 . '&amp;sql_query=' . urlencode($sql_query)
712 . '&amp;id_bookmark=1';
714 <!-- Bookmark the query -->
715 <form action="sql.php3" method="post" onsubmit="return emptyFormElements(this, 'fields[label]');">
716 <?php
717 echo "\n";
718 if ($disp_mode[3] == '1') {
719 echo ' <i>' . $strOr . '</i>' . "\n";
722 <br /><br />
723 <?php echo $strBookmarkLabel; ?>&nbsp;:
724 <?php echo PMA_generate_common_hidden_inputs(); ?>
725 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
726 <input type="hidden" name="fields[dbase]" value="<?php echo htmlspecialchars($db); ?>" />
727 <input type="hidden" name="fields[user]" value="<?php echo $cfg['Bookmark']['user']; ?>" />
728 <input type="hidden" name="fields[query]" value="<?php echo urlencode($sql_query); ?>" />
729 <input type="text" name="fields[label]" value="" />
730 <input type="submit" name="store_bkm" value="<?php echo $strBookmarkThis; ?>" />
731 </form>
732 <?php
733 } // end bookmark support
735 // Do print the page if required
736 if (isset($printview) && $printview == '1') {
737 echo "\n";
739 <script type="text/javascript" language="javascript1.2">
740 <!--
741 // Do print the page
742 if (typeof(window.print) != 'undefined') {
743 window.print();
745 //-->
746 </script>
747 <?php
748 } // end print case
749 } // end rows returned
751 } // end executes the query
752 echo "\n\n";
756 * Displays the footer
758 require('./footer.inc.php3');