update
[phpmyadmin/crack.git] / sql.php3
blobde7e675ead4abc5f6806eab2e8ecd358c57087c3
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 && !isset($analyzed_sql[0]['table_ref'][1]['table_name'])
359 && (empty($analyzed_sql[0]['where_clause'])
360 || $analyzed_sql[0]['where_clause'] == '1 ')) {
362 // "just browsing"
363 $unlim_num_rows = PMA_countRecords($db, $table, TRUE);
364 } else { // not "just browsing"
366 if (PMA_MYSQL_INT_VERSION < 40000) {
367 if (eregi('DISTINCT(.*)', $sql_query)) {
368 $count_what = 'DISTINCT ' . $analyzed_sql[0]['select_expr_clause'];
369 } else {
370 $count_what = '*';
373 $count_query = 'SELECT COUNT(' . $count_what . ') AS count';
375 else {
376 $count_query = 'SELECT SQL_CALC_FOUND_ROWS ';
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 // add select expression after the SQL_CALC_FOUND_ROWS
389 if (PMA_MYSQL_INT_VERSION >= 40000) {
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'];
398 if (!empty($analyzed_sql[0]['from_clause'])) {
399 $count_query .= ' FROM ' . $analyzed_sql[0]['from_clause'];
402 if (!empty($analyzed_sql[0]['where_clause'])) {
403 $count_query .= ' WHERE ' . $analyzed_sql[0]['where_clause'];
405 if (!empty($analyzed_sql[0]['group_by_clause'])) {
406 $count_query .= ' GROUP BY ' . $analyzed_sql[0]['group_by_clause'];
409 if (!empty($analyzed_sql[0]['having_clause'])) {
410 $count_query .= ' HAVING ' . $analyzed_sql[0]['having_clause'];
413 // if using SQL_CALC_FOUND_ROWS, add a LIMIT to avoid
414 // long delays. Returned count will be complete anyway.
416 if (PMA_MYSQL_INT_VERSION >= 40000) {
417 $count_query .= ' LIMIT 1';
420 // do not put the order_by_clause, it interferes
421 // run the count query
422 if (PMA_MYSQL_INT_VERSION < 40000) {
423 if ($cnt_all_result = PMA_mysql_query($count_query)) {
424 //if ($is_group) {
425 if ($count_what == '*') {
426 $unlim_num_rows = @mysql_num_rows($cnt_all_result);
427 } else {
428 $unlim_num_rows = PMA_mysql_result($cnt_all_result, 0, 'count');
430 mysql_free_result($cnt_all_result);
431 } else {
432 if (mysql_error()) {
433 // there are some cases where the generated
434 // count_query (for MySQL 3) is wrong,
435 // so we get here.
436 //TODO: use a big unlimited query to get
437 // the correct number of rows (depending
438 // on a config variable?)
439 $unlim_num_rows = 0;
442 } else {
443 PMA_mysql_query($count_query);
444 if (mysql_error()) {
445 // void. I tried the case
446 // (SELECT `User`, `Host`, `Db`, `Select_priv` FROM `db`)
447 // UNION (SELECT `User`, `Host`, "%" AS "Db",
448 // `Select_priv`
449 // FROM `user`) ORDER BY `User`, `Host`, `Db`;
450 // and although the generated count_query is wrong
451 // the SELECT FOUND_ROWS() work!
453 $cnt_all_result = PMA_mysql_query('SELECT FOUND_ROWS() as count');
454 $unlim_num_rows = PMA_mysql_result($cnt_all_result,0,'count');
456 } // end else "just browsing"
458 } else { // not $is_select
459 $unlim_num_rows = 0;
460 } // end rows total count
462 // garvin: if a table or database gets dropped, check column comments.
463 if (isset($purge) && $purge == '1') {
464 include('./libraries/relation_cleanup.lib.php3');
466 if (isset($table) && isset($db) && !empty($table) && !empty($db)) {
467 PMA_relationsCleanupTable($db, $table);
468 } elseif (isset($db) && !empty($db)) {
469 PMA_relationsCleanupDatabase($db);
470 } else {
471 // garvin: VOID. No DB/Table gets deleted.
472 } // end if relation-stuff
473 } // end if ($purge)
475 // garvin: If a column gets dropped, do relation magic.
476 if (isset($cpurge) && $cpurge == '1' && isset($purgekey)
477 && isset($db) && isset($table)
478 && !empty($db) && !empty($table) && !empty($purgekey)) {
479 include('./libraries/relation_cleanup.lib.php3');
480 PMA_relationsCleanupColumn($db, $table, $purgekey);
482 } // end if column PMA_* purge
483 } // end else "didn't ask to see php code"
486 // No rows returned -> move back to the calling page
487 if ($num_rows < 1 || $is_affected) {
488 if ($is_delete) {
489 $message = $strDeletedRows . '&nbsp;' . $num_rows;
490 } else if ($is_insert) {
491 $message = $strInsertedRows . '&nbsp;' . $num_rows;
492 $insert_id = mysql_insert_id();
493 if ($insert_id != 0) {
494 $message .= '<br />'.$strInsertedRowId . '&nbsp;' . $insert_id;
496 } else if ($is_affected) {
497 $message = $strAffectedRows . '&nbsp;' . $num_rows;
498 } else if (!empty($zero_rows)) {
499 $message = $zero_rows;
500 } else if (!empty($GLOBALS['show_as_php'])) {
501 $message = $strPhp;
502 } else if (!empty($GLOBALS['validatequery'])) {
503 $message = $strValidateSQL;
504 } else {
505 $message = $strEmptyResultSet;
508 $message .= ' ' . (isset($GLOBALS['querytime']) ? '(' . sprintf($strQueryTime, $GLOBALS['querytime']) . ')' : '');
510 if ($is_gotofile) {
511 $goto = ereg_replace('\.\.*', '.', $goto);
512 // Checks for a valid target script
513 if (isset($table) && $table == '') {
514 unset($table);
516 if (isset($db) && $db == '') {
517 unset($db);
519 $is_db = $is_table = FALSE;
520 if (strpos(' ' . $goto, 'tbl_properties') == 1) {
521 if (!isset($table)) {
522 $goto = 'db_details.php3';
523 } else {
524 $is_table = @PMA_mysql_query('SHOW TABLES LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\'');
525 if (!($is_table && @mysql_numrows($is_table))) {
526 $goto = 'db_details.php3';
527 unset($table);
529 } // end if... else...
531 if (strpos(' ' . $goto, 'db_details') == 1) {
532 if (isset($table)) {
533 unset($table);
535 if (!isset($db)) {
536 $goto = 'main.php3';
537 } else {
538 $is_db = @PMA_mysql_select_db($db);
539 if (!$is_db) {
540 $goto = 'main.php3';
541 unset($db);
543 } // end if... else...
545 // Loads to target script
546 if (strpos(' ' . $goto, 'db_details') == 1
547 || strpos(' ' . $goto, 'tbl_properties') == 1) {
548 $js_to_run = 'functions.js';
550 if ($goto != 'main.php3') {
551 include('./header.inc.php3');
553 $active_page = $goto;
554 include('./' . $goto);
555 } // end if file_exist
556 else {
557 header('Location: ' . $cfg['PmaAbsoluteUri'] . str_replace('&amp;', '&', $goto) . '&message=' . urlencode($message));
558 } // end else
559 exit();
560 } // end no rows returned
562 // At least one row is returned -> displays a table with results
563 else {
564 // Displays the headers
565 if (isset($show_query)) {
566 unset($show_query);
568 if (isset($printview) && $printview == '1') {
569 include('./header_printview.inc.php3');
570 } else {
571 $js_to_run = 'functions.js';
572 unset($message);
573 if (!empty($table)) {
574 include('./tbl_properties_common.php3');
575 $url_query .= '&amp;goto=tbl_properties.php3&amp;back=tbl_properties.php3';
576 include('./tbl_properties_table_info.php3');
578 else {
579 include('./db_details_common.php3');
580 include('./db_details_db_info.php3');
582 include('./libraries/relation.lib.php3');
583 $cfgRelation = PMA_getRelationsParam();
586 // Gets the list of fields properties
587 if (isset($result) && $result) {
588 while ($field = PMA_mysql_fetch_field($result)) {
589 $fields_meta[] = $field;
591 $fields_cnt = count($fields_meta);
594 // Display previous update query (from tbl_replace)
595 if (isset($disp_query) && $cfg['ShowSQL'] == TRUE) {
596 $tmp_sql_query = $GLOBALS['sql_query'];
597 $tmp_sql_limit_to_append = (isset($GLOBALS['sql_limit_to_append'])?$GLOBALS['sql_limit_to_append']:'');
598 $GLOBALS['sql_query'] = $disp_query;
599 $GLOBALS['sql_limit_to_append'] = '';
600 PMA_showMessage($disp_message);
601 $GLOBALS['sql_query'] = $tmp_sql_query;
602 $GLOBALS['sql_limit_to_append'] = $tmp_sql_limit_to_append;
605 // Displays the results in a table
606 include('./libraries/display_tbl.lib.php3');
607 if (empty($disp_mode)) {
608 // see the "PMA_setDisplayMode()" function in
609 // libraries/display_tbl.lib.php3
610 $disp_mode = 'urdr111101';
612 if (!isset($dontlimitchars)) {
613 $dontlimitchars = 0;
616 PMA_displayTable($result, $disp_mode, $analyzed_sql);
617 mysql_free_result($result);
619 if ($disp_mode[6] == '1' || $disp_mode[9] == '1') {
620 echo "\n";
621 echo '<p>' . "\n";
623 // Displays "Insert a new row" link if required
624 if ($disp_mode[6] == '1') {
625 $lnk_goto = 'sql.php3?'
626 . PMA_generate_common_url($db, $table)
627 . '&amp;pos=' . $pos
628 . '&amp;session_max_rows=' . $session_max_rows
629 . '&amp;disp_direction=' . $disp_direction
630 . '&amp;repeat_cells=' . $repeat_cells
631 . '&amp;dontlimitchars=' . $dontlimitchars
632 . '&amp;sql_query=' . urlencode($sql_query);
633 $url_query = '?'
634 . PMA_generate_common_url($db, $table)
635 . '&amp;pos=' . $pos
636 . '&amp;session_max_rows=' . $session_max_rows
637 . '&amp;disp_direction=' . $disp_direction
638 . '&amp;repeat_cells=' . $repeat_cells
639 . '&amp;dontlimitchars=' . $dontlimitchars
640 . '&amp;sql_query=' . urlencode($sql_query)
641 . '&amp;goto=' . urlencode($lnk_goto);
643 echo ' <!-- Insert a new row -->' . "\n"
644 . ' <a href="tbl_change.php3' . $url_query . '">' . $strInsertNewRow . '</a>';
645 if ($disp_mode[9] == '1') {
646 echo '<br />';
648 echo "\n";
649 } // end insert new row
651 // Displays "printable view" link if required
652 if ($disp_mode[9] == '1') {
653 $url_query = '?'
654 . PMA_generate_common_url($db, $table)
655 . '&amp;pos=' . $pos
656 . '&amp;session_max_rows=' . $session_max_rows
657 . '&amp;disp_direction=' . $disp_direction
658 . '&amp;repeat_cells=' . $repeat_cells
659 . '&amp;printview=1'
660 . ((isset($dontlimitchars) && $dontlimitchars == '1') ? '&amp;dontlimitchars=1' : '')
661 . '&amp;sql_query=' . urlencode($sql_query);
662 echo ' <!-- Print view -->' . "\n"
663 . ' <a href="sql.php3' . $url_query . '" target="print_view">' . $strPrintView . '</a>' . "\n";
664 } // end displays "printable view"
666 echo '</p>' . "\n";
669 // Export link, if only one table
670 // (the url_query has extra parameters that won't be used to export)
671 if (!isset($printview)) {
672 if (isset($analyzed_sql[0]['table_ref'][0]['table_true_name']) && !isset($analyzed_sql[0]['table_ref'][1]['table_true_name'])) {
673 $single_table = '&amp;single_table=true';
674 } else {
675 $single_table = '';
677 echo ' <!-- Export -->' . "\n"
678 . ' <a href="tbl_properties_export.php3' . $url_query
679 . '&amp;unlim_num_rows=' . $unlim_num_rows
680 . $single_table
681 . '">' . $strExport . '</a>' . "\n";
684 // Bookmark Support if required
685 if ($disp_mode[7] == '1'
686 && ($cfg['Bookmark']['db'] && $cfg['Bookmark']['table'] && empty($id_bookmark))
687 && !empty($sql_query)) {
688 echo "\n";
690 $goto = 'sql.php3?'
691 . PMA_generate_common_url($db, $table)
692 . '&amp;pos=' . $pos
693 . '&amp;session_max_rows=' . $session_max_rows
694 . '&amp;disp_direction=' . $disp_direction
695 . '&amp;repeat_cells=' . $repeat_cells
696 . '&amp;dontlimitchars=' . $dontlimitchars
697 . '&amp;sql_query=' . urlencode($sql_query)
698 . '&amp;id_bookmark=1';
700 <!-- Bookmark the query -->
701 <form action="sql.php3" method="post" onsubmit="return emptyFormElements(this, 'fields[label]');">
702 <?php
703 echo "\n";
704 if ($disp_mode[3] == '1') {
705 echo ' <i>' . $strOr . '</i>' . "\n";
708 <br /><br />
709 <?php echo $strBookmarkLabel; ?>&nbsp;:
710 <?php echo PMA_generate_common_hidden_inputs(); ?>
711 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
712 <input type="hidden" name="fields[dbase]" value="<?php echo htmlspecialchars($db); ?>" />
713 <input type="hidden" name="fields[user]" value="<?php echo $cfg['Bookmark']['user']; ?>" />
714 <input type="hidden" name="fields[query]" value="<?php echo urlencode($sql_query); ?>" />
715 <input type="text" name="fields[label]" value="" />
716 <input type="submit" name="store_bkm" value="<?php echo $strBookmarkThis; ?>" />
717 </form>
718 <?php
719 } // end bookmark support
721 // Do print the page if required
722 if (isset($printview) && $printview == '1') {
723 echo "\n";
725 <script type="text/javascript" language="javascript1.2">
726 <!--
727 // Do print the page
728 if (typeof(window.print) != 'undefined') {
729 window.print();
731 //-->
732 </script>
733 <?php
734 } // end print case
735 } // end rows returned
737 } // end executes the query
738 echo "\n\n";
742 * Displays the footer
744 require('./footer.inc.php3');