typo
[phpmyadmin/crack.git] / sql.php3
blobd3a5ea42ad9a1822482a17479cf33289233aea7a
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 PMA_checkParameters(array('sql_query', 'db'));
13 /**
14 * Defines the url to return to in case of error in a sql statement
16 // Security checkings
17 if (!empty($goto)) {
18 $is_gotofile = ereg_replace('^([^?]+).*$', '\\1', $goto);
19 if (!@file_exists('./' . $is_gotofile)) {
20 unset($goto);
21 } else {
22 $is_gotofile = ($is_gotofile == $goto);
24 } // end if (security checkings)
26 if (empty($goto)) {
27 $goto = (empty($table)) ? $cfg['DefaultTabDatabase'] : $cfg['DefaultTabTable'];
28 $is_gotofile = TRUE;
29 } // end if
30 if (!isset($err_url)) {
31 $err_url = (!empty($back) ? $back : $goto)
32 . '?' . PMA_generate_common_url(isset($db) ? $db : '')
33 . ((strpos(' ' . $goto, 'db_details') != 1 && isset($table)) ? '&amp;table=' . urlencode($table) : '');
34 } // end if
36 // Coming from a bookmark dialog
37 if (isset($fields['query'])) {
38 $sql_query = $fields['query'];
41 /**
42 * Check rights in case of DROP DATABASE
44 * This test may be bypassed if $is_js_confirmed = 1 (already checked with js)
45 * but since a malicious user may pass this variable by url/form, we don't take
46 * into account this case.
48 if (!defined('PMA_CHK_DROP')
49 && !$cfg['AllowUserDropDatabase']
50 && eregi('DROP[[:space:]]+(IF EXISTS[[:space:]]+)?DATABASE[[:space:]]', $sql_query)) {
51 // Checks if the user is a Superuser
52 // TODO: set a global variable with this information
53 // loic1: optimized query
54 $result = @PMA_mysql_query('USE mysql');
55 if (PMA_mysql_error()) {
56 include('./header.inc.php3');
57 PMA_mysqlDie($strNoDropDatabases, '', '', $err_url);
58 } // end if
59 } // end if
62 /**
63 * Bookmark add
65 if (isset($store_bkm)) {
66 include('./libraries/bookmark.lib.php3');
67 PMA_addBookmarks($fields, $cfg['Bookmark']);
68 header('Location: ' . $cfg['PmaAbsoluteUri'] . $goto);
69 } // end if
72 /**
73 * Gets the true sql query
75 // $sql_query has been urlencoded in the confirmation form for drop/delete
76 // queries or in the navigation bar for browsing among records
77 if (isset($btnDrop) || isset($navig)) {
78 $sql_query = urldecode($sql_query);
81 /**
82 * Reformat the query
85 $parsed_sql = PMA_SQP_parse($sql_query);
86 $analyzed_sql = PMA_SQP_analyze($parsed_sql);
87 // Bug #641765 - Robbat2 - 12 January 2003, 10:49PM
88 // Reverted - Robbat2 - 13 January 2003, 2:40PM
89 $sql_query = PMA_SQP_formatHtml($parsed_sql, 'query_only');
91 // old code did not work, for example, when there is a bracket
92 // before the SELECT
93 // so I guess it's ok to check for a real SELECT ... FROM
94 //$is_select = eregi('^SELECT[[:space:]]+', $sql_query);
95 $is_select = isset($analyzed_sql[0]['queryflags']['select_from']);
97 // If the query is a Select, extract the db and table names and modify
98 // $db and $table, to have correct page headers, links and left frame.
99 // db and table name may be enclosed with backquotes, db is optionnal,
100 // query may contain aliases.
102 // (TODO: if there are more than one table name in the Select:
103 // - do not extract the first table name
104 // - do not show a table name in the page header
105 // - do not display the sub-pages links)
107 if ($is_select) {
108 $prev_db = $db;
109 if (isset($analyzed_sql[0]['table_ref'][0]['table_true_name'])) {
110 $table = $analyzed_sql[0]['table_ref'][0]['table_true_name'];
112 if (isset($analyzed_sql[0]['table_ref'][0]['db'])
113 && !empty($analyzed_sql[0]['table_ref'][0]['db'])) {
114 $db = $analyzed_sql[0]['table_ref'][0]['db'];
116 else {
117 $db = $prev_db;
119 $reload = ($db == $prev_db) ? 0 : 1;
123 * Sets or modifies the $goto variable if required
125 if ($goto == 'sql.php3') {
126 $goto = 'sql.php3?'
127 . PMA_generate_common_url($db, $table)
128 . '&amp;pos=' . $pos
129 . '&amp;sql_query=' . urlencode($sql_query);
130 } // end if
134 * Go back to further page if table should not be dropped
136 if (isset($btnDrop) && $btnDrop == $strNo) {
137 if (!empty($back)) {
138 $goto = $back;
140 if ($is_gotofile) {
141 if (strpos(' ' . $goto, 'db_details') == 1 && !empty($table)) {
142 unset($table);
144 $active_page = $goto;
145 include('./' . ereg_replace('\.\.*', '.', $goto));
146 } else {
147 header('Location: ' . $cfg['PmaAbsoluteUri'] . str_replace('&amp;', '&', $goto));
149 exit();
150 } // end if
154 * Displays the confirm page if required
156 * This part of the script is bypassed if $is_js_confirmed = 1 (already checked
157 * with js) because possible security issue is not so important here: at most,
158 * the confirm message isn't displayed.
160 * Also bypassed if only showing php code.or validating a SQL query
162 if (!$cfg['Confirm']
163 || (isset($is_js_confirmed) && $is_js_confirmed)
164 || isset($btnDrop)
165 || !empty($GLOBALS['show_as_php'])
166 || !empty($GLOBALS['validatequery'])) {
167 $do_confirm = FALSE;
168 } else {
169 //$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));
171 $do_confirm = isset($analyzed_sql[0]['queryflags']['need_confirm']);
174 if ($do_confirm) {
175 $stripped_sql_query = $sql_query;
176 include('./header.inc.php3');
177 echo $strDoYouReally . '&nbsp;:<br />' . "\n";
178 echo '<tt>' . htmlspecialchars($stripped_sql_query) . '</tt>&nbsp;?<br/>' . "\n";
180 <form action="sql.php3" method="post">
181 <?php echo PMA_generate_common_hidden_inputs($db, (isset($table)?$table:'')); ?>
182 <input type="hidden" name="sql_query" value="<?php echo urlencode($sql_query); ?>" />
183 <input type="hidden" name="zero_rows" value="<?php echo isset($zero_rows) ? $zero_rows : ''; ?>" />
184 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
185 <input type="hidden" name="back" value="<?php echo isset($back) ? $back : ''; ?>" />
186 <input type="hidden" name="reload" value="<?php echo isset($reload) ? $reload : 0; ?>" />
187 <input type="hidden" name="purge" value="<?php echo isset($purge) ? $purge : ''; ?>" />
188 <input type="hidden" name="cpurge" value="<?php echo isset($cpurge) ? $cpurge : ''; ?>" />
189 <input type="hidden" name="purgekey" value="<?php echo isset($purgekey) ? $purgekey : ''; ?>" />
190 <input type="hidden" name="show_query" value="<?php echo isset($show_query) ? $show_query : ''; ?>" />
191 <input type="submit" name="btnDrop" value="<?php echo $strYes; ?>" />
192 <input type="submit" name="btnDrop" value="<?php echo $strNo; ?>" />
193 </form>
194 <?php
195 echo "\n";
196 } // end if
200 * Executes the query and displays results
202 else {
203 if (!isset($sql_query)) {
204 $sql_query = '';
206 // Defines some variables
207 // loic1: A table has to be created -> left frame should be reloaded
208 if ((!isset($reload) || $reload == 0)
209 && eregi('^CREATE TABLE[[:space:]]+(.*)', $sql_query)) {
210 $reload = 1;
212 // Gets the number of rows per page
213 if (!isset($session_max_rows)) {
214 $session_max_rows = $cfg['MaxRows'];
215 } else if ($session_max_rows != 'all') {
216 $cfg['MaxRows'] = $session_max_rows;
218 // Defines the display mode (horizontal/vertical) and header "frequency"
219 if (empty($disp_direction)) {
220 $disp_direction = $cfg['DefaultDisplay'];
222 if (empty($repeat_cells)) {
223 $repeat_cells = $cfg['RepeatCells'];
226 // SK -- Patch: $is_group added for use in calculation of total number of
227 // rows.
228 // $is_count is changed for more correct "LIMIT" clause
229 // appending in queries like
230 // "SELECT COUNT(...) FROM ... GROUP BY ..."
231 $is_explain = $is_count = $is_export = $is_delete = $is_insert = $is_affected = $is_show = $is_maint = $is_analyse = $is_group = $is_func = FALSE;
232 if ($is_select) { // see line 141
233 $is_group = eregi('(GROUP[[:space:]]+BY|HAVING|SELECT[[:space:]]+DISTINCT)[[:space:]]+', $sql_query);
234 $is_func = !$is_group && (eregi('[[:space:]]+(SUM|AVG|STD|STDDEV|MIN|MAX|BIT_OR|BIT_AND)\s*\(', $sql_query));
235 $is_count = !$is_group && (eregi('^SELECT[[:space:]]+COUNT\((.*\.+)?.*\)', $sql_query));
236 $is_export = (eregi('[[:space:]]+INTO[[:space:]]+OUTFILE[[:space:]]+', $sql_query));
237 $is_analyse = (eregi('[[:space:]]+PROCEDURE[[:space:]]+ANALYSE', $sql_query));
238 } else if (eregi('^EXPLAIN[[:space:]]+', $sql_query)) {
239 $is_explain = TRUE;
240 } else if (eregi('^DELETE[[:space:]]+', $sql_query)) {
241 $is_delete = TRUE;
242 $is_affected = TRUE;
243 } else if (eregi('^(INSERT|LOAD[[:space:]]+DATA|REPLACE)[[:space:]]+', $sql_query)) {
244 $is_insert = TRUE;
245 $is_affected = TRUE;
246 } else if (eregi('^UPDATE[[:space:]]+', $sql_query)) {
247 $is_affected = TRUE;
248 } else if (eregi('^SHOW[[:space:]]+', $sql_query)) {
249 $is_show = TRUE;
250 } else if (eregi('^(CHECK|ANALYZE|REPAIR|OPTIMIZE)[[:space:]]+TABLE[[:space:]]+', $sql_query)) {
251 $is_maint = TRUE;
254 // Do append a "LIMIT" clause?
255 if (isset($pos)
256 && (!$cfg['ShowAll'] || $session_max_rows != 'all')
257 && !($is_count || $is_export || $is_func || $is_analyse)
258 && isset($analyzed_sql[0]['queryflags']['select_from'])
259 && !eregi('[[:space:]]LIMIT[[:space:]0-9,-]+$', $sql_query)) {
260 $sql_limit_to_append = " LIMIT $pos, ".$cfg['MaxRows'];
261 if (eregi('(.*)([[:space:]](PROCEDURE[[:space:]](.*)|FOR[[:space:]]+UPDATE|LOCK[[:space:]]+IN[[:space:]]+SHARE[[:space:]]+MODE))$', $sql_query, $regs)) {
262 $full_sql_query = $regs[1] . $sql_limit_to_append . $regs[2];
263 } else {
264 $full_sql_query = $sql_query . $sql_limit_to_append;
266 } else {
267 $full_sql_query = $sql_query;
268 } // end if...else
270 PMA_mysql_select_db($db);
272 // If the query is a DELETE query with no WHERE clause, get the number of
273 // rows that will be deleted (mysql_affected_rows will always return 0 in
274 // this case)
275 if ($is_delete
276 && eregi('^DELETE([[:space:]].+)?([[:space:]]FROM[[:space:]](.+))$', $sql_query, $parts)
277 && !eregi('[[:space:]]WHERE[[:space:]]', $parts[3])) {
278 $cnt_all_result = @PMA_mysql_query('SELECT COUNT(*) as count' . $parts[2]);
279 if ($cnt_all_result) {
280 $num_rows = PMA_mysql_result($cnt_all_result, 0, 'count');
281 mysql_free_result($cnt_all_result);
282 } else {
283 $num_rows = 0;
287 // E x e c u t e t h e q u e r y
289 // Only if we didn't ask to see the php code (mikebeck)
290 if (isset($GLOBALS['show_as_php']) || !empty($GLOBALS['validatequery'])) {
291 unset($result);
292 $num_rows = 0;
294 else {
295 // garvin: Measure query time. TODO-Item http://sourceforge.net/tracker/index.php?func=detail&aid=571934&group_id=23067&atid=377411
296 list($usec, $sec) = explode(' ',microtime());
297 $querytime_before = ((float)$usec + (float)$sec);
299 $result = @PMA_mysql_query($full_sql_query);
301 list($usec, $sec) = explode(' ',microtime());
302 $querytime_after = ((float)$usec + (float)$sec);
304 $GLOBALS['querytime'] = $querytime_after - $querytime_before;
306 // Displays an error message if required and stop parsing the script
307 if (PMA_mysql_error()) {
308 $error = PMA_mysql_error();
309 include('./header.inc.php3');
310 $full_err_url = (ereg('^(db_details|tbl_properties)', $err_url))
311 ? $err_url . '&amp;show_query=1&amp;sql_query=' . urlencode($sql_query)
312 : $err_url;
313 PMA_mysqlDie($error, $full_sql_query, '', $full_err_url);
316 // Gets the number of rows affected/returned
317 // (This must be done immediately after the query because
318 // mysql_affected_rows() reports about the last query done)
320 if (!$is_affected) {
321 $num_rows = ($result) ? @mysql_num_rows($result) : 0;
322 } else if (!isset($num_rows)) {
323 $num_rows = @mysql_affected_rows();
326 // Checks if the current database has changed
327 // This could happen if the user sends a query like "USE `database`;"
328 $res = PMA_mysql_query('SELECT DATABASE() AS "db";');
329 $row = PMA_mysql_fetch_array($res);
330 if ($db != $row['db']) {
331 $db = $row['db'];
332 $reload = 1;
334 @mysql_free_result($res);
335 unset($res);
336 unset($row);
338 // tmpfile remove after convert encoding appended by Y.Kawada
339 if (function_exists('PMA_kanji_file_conv')
340 && (isset($textfile) && file_exists($textfile))) {
341 unlink($textfile);
344 // Counts the total number of rows for the same 'SELECT' query without the
345 // 'LIMIT' clause that may have been programatically added
347 if (empty($sql_limit_to_append)) {
348 $unlim_num_rows = $num_rows;
350 else if ($is_select) {
352 // c o u n t q u e r y
354 // If we are "just browsing", there is only one table,
355 // and no where clause (or just 'WHERE 1 '),
356 // so we do a quick count (which uses MaxExactCount)
357 // because SQL_CALC_FOUND_ROWS
358 // is not quick on large InnoDB tables
360 if (!$is_group
361 && !isset($analyzed_sql[0]['queryflags']['union'])
362 && !isset($analyzed_sql[0]['table_ref'][1]['table_name'])
363 && (empty($analyzed_sql[0]['where_clause'])
364 || $analyzed_sql[0]['where_clause'] == '1 ')) {
366 // "j u s t b r o w s i n g"
367 $unlim_num_rows = PMA_countRecords($db, $table, TRUE);
369 } else { // n o t " j u s t b r o w s i n g "
371 if (PMA_MYSQL_INT_VERSION < 40000) {
372 if (eregi('DISTINCT(.*)', $sql_query)) {
373 $count_what = 'DISTINCT ' . $analyzed_sql[0]['select_expr_clause'];
374 } else {
375 $count_what = '*';
378 $count_query = 'SELECT COUNT(' . $count_what . ') AS count';
381 // add the remaining of select expression if there is
382 // a GROUP BY or HAVING clause
383 if (PMA_MYSQL_INT_VERSION < 40000
384 && $count_what =='*'
385 && (!empty($analyzed_sql[0]['group_by_clause'])
386 || !empty($analyzed_sql[0]['having_clause']))) {
387 $count_query .= ' ,' . $analyzed_sql[0]['select_expr_clause'];
390 if (PMA_MYSQL_INT_VERSION >= 40000) {
391 // add select expression after the SQL_CALC_FOUND_ROWS
392 // if (eregi('DISTINCT(.*)', $sql_query)) {
393 // $count_query .= 'DISTINCT ' . $analyzed_sql[0]['select_expr_clause'];
394 // } else {
395 //$count_query .= $analyzed_sql[0]['select_expr_clause'];
397 // for UNION, just adding SQL_CALC_FOUND_ROWS
398 // after the first SELECT works.
400 // take the left part, could be:
401 // SELECT
402 // (SELECT
403 $count_query = PMA_SQP_formatHtml($parsed_sql, 'query_only', 0, $analyzed_sql[0]['position_of_first_select'] + 1);
404 $count_query .= ' SQL_CALC_FOUND_ROWS ';
406 // add everything that was after the first SELECT
407 $count_query .= PMA_SQP_formatHtml($parsed_sql, 'query_only', $analyzed_sql[0]['position_of_first_select']+1);
408 // }
409 } else { // PMA_MYSQL_INT_VERSION < 40000
411 if (!empty($analyzed_sql[0]['from_clause'])) {
412 $count_query .= ' FROM ' . $analyzed_sql[0]['from_clause'];
414 if (!empty($analyzed_sql[0]['where_clause'])) {
415 $count_query .= ' WHERE ' . $analyzed_sql[0]['where_clause'];
417 if (!empty($analyzed_sql[0]['group_by_clause'])) {
418 $count_query .= ' GROUP BY ' . $analyzed_sql[0]['group_by_clause'];
420 if (!empty($analyzed_sql[0]['having_clause'])) {
421 $count_query .= ' HAVING ' . $analyzed_sql[0]['having_clause'];
423 } // end if
425 // if using SQL_CALC_FOUND_ROWS, add a LIMIT to avoid
426 // long delays. Returned count will be complete anyway.
427 // (but a LIMIT would disrupt results in an UNION)
429 if (PMA_MYSQL_INT_VERSION >= 40000
430 && !isset($analyzed_sql[0]['queryflags']['union'])) {
431 $count_query .= ' LIMIT 1';
434 // run the count query
435 //DEBUG echo "trace cq=" . $count_query . "<br/>";
437 if (PMA_MYSQL_INT_VERSION < 40000) {
438 if ($cnt_all_result = PMA_mysql_query($count_query)) {
439 if ($is_group) {
440 // if ($count_what == '*') {
441 $unlim_num_rows = @mysql_num_rows($cnt_all_result);
442 } else {
443 $unlim_num_rows = PMA_mysql_result($cnt_all_result, 0, 'count');
445 mysql_free_result($cnt_all_result);
446 } else {
447 if (mysql_error()) {
449 // there are some cases where the generated
450 // count_query (for MySQL 3) is wrong,
451 // so we get here.
452 //TODO: use a big unlimited query to get
453 // the correct number of rows (depending
454 // on a config variable?)
455 $unlim_num_rows = 0;
458 } else {
459 PMA_mysql_query($count_query);
460 if (mysql_error()) {
461 // void. I tried the case
462 // (SELECT `User`, `Host`, `Db`, `Select_priv` FROM `db`)
463 // UNION (SELECT `User`, `Host`, "%" AS "Db",
464 // `Select_priv`
465 // FROM `user`) ORDER BY `User`, `Host`, `Db`;
466 // and although the generated count_query is wrong
467 // the SELECT FOUND_ROWS() work!
469 $cnt_all_result = PMA_mysql_query('SELECT FOUND_ROWS() as count');
470 $unlim_num_rows = PMA_mysql_result($cnt_all_result,0,'count');
472 } // end else "just browsing"
474 } else { // not $is_select
475 $unlim_num_rows = 0;
476 } // end rows total count
478 // garvin: if a table or database gets dropped, check column comments.
479 if (isset($purge) && $purge == '1') {
480 include('./libraries/relation_cleanup.lib.php3');
482 if (isset($table) && isset($db) && !empty($table) && !empty($db)) {
483 PMA_relationsCleanupTable($db, $table);
484 } elseif (isset($db) && !empty($db)) {
485 PMA_relationsCleanupDatabase($db);
486 } else {
487 // garvin: VOID. No DB/Table gets deleted.
488 } // end if relation-stuff
489 } // end if ($purge)
491 // garvin: If a column gets dropped, do relation magic.
492 if (isset($cpurge) && $cpurge == '1' && isset($purgekey)
493 && isset($db) && isset($table)
494 && !empty($db) && !empty($table) && !empty($purgekey)) {
495 include('./libraries/relation_cleanup.lib.php3');
496 PMA_relationsCleanupColumn($db, $table, $purgekey);
498 } // end if column PMA_* purge
499 } // end else "didn't ask to see php code"
502 // No rows returned -> move back to the calling page
503 if ($num_rows < 1 || $is_affected) {
504 if ($is_delete) {
505 $message = $strDeletedRows . '&nbsp;' . $num_rows;
506 } else if ($is_insert) {
507 $message = $strInsertedRows . '&nbsp;' . $num_rows;
508 $insert_id = mysql_insert_id();
509 if ($insert_id != 0) {
510 $message .= '<br />'.$strInsertedRowId . '&nbsp;' . $insert_id;
512 } else if ($is_affected) {
513 $message = $strAffectedRows . '&nbsp;' . $num_rows;
514 } else if (!empty($zero_rows)) {
515 $message = $zero_rows;
516 } else if (!empty($GLOBALS['show_as_php'])) {
517 $message = $strPhp;
518 } else if (!empty($GLOBALS['validatequery'])) {
519 $message = $strValidateSQL;
520 } else {
521 $message = $strEmptyResultSet;
524 $message .= ' ' . (isset($GLOBALS['querytime']) ? '(' . sprintf($strQueryTime, $GLOBALS['querytime']) . ')' : '');
526 if ($is_gotofile) {
527 $goto = ereg_replace('\.\.*', '.', $goto);
528 // Checks for a valid target script
529 if (isset($table) && $table == '') {
530 unset($table);
532 if (isset($db) && $db == '') {
533 unset($db);
535 $is_db = $is_table = FALSE;
536 if (strpos(' ' . $goto, 'tbl_properties') == 1) {
537 if (!isset($table)) {
538 $goto = 'db_details.php3';
539 } else {
540 $is_table = @PMA_mysql_query('SHOW TABLES LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\'');
541 if (!($is_table && @mysql_numrows($is_table))) {
542 $goto = 'db_details.php3';
543 unset($table);
545 } // end if... else...
547 if (strpos(' ' . $goto, 'db_details') == 1) {
548 if (isset($table)) {
549 unset($table);
551 if (!isset($db)) {
552 $goto = 'main.php3';
553 } else {
554 $is_db = @PMA_mysql_select_db($db);
555 if (!$is_db) {
556 $goto = 'main.php3';
557 unset($db);
559 } // end if... else...
561 // Loads to target script
562 if (strpos(' ' . $goto, 'db_details') == 1
563 || strpos(' ' . $goto, 'tbl_properties') == 1) {
564 $js_to_run = 'functions.js';
566 if ($goto != 'main.php3') {
567 include('./header.inc.php3');
569 $active_page = $goto;
570 include('./' . $goto);
571 } // end if file_exist
572 else {
573 header('Location: ' . $cfg['PmaAbsoluteUri'] . str_replace('&amp;', '&', $goto) . '&message=' . urlencode($message));
574 } // end else
575 exit();
576 } // end no rows returned
578 // At least one row is returned -> displays a table with results
579 else {
580 // Displays the headers
581 if (isset($show_query)) {
582 unset($show_query);
584 if (isset($printview) && $printview == '1') {
585 include('./header_printview.inc.php3');
586 } else {
587 $js_to_run = 'functions.js';
588 unset($message);
589 if (!empty($table)) {
590 include('./tbl_properties_common.php3');
591 $url_query .= '&amp;goto=tbl_properties.php3&amp;back=tbl_properties.php3';
592 include('./tbl_properties_table_info.php3');
594 else {
595 include('./db_details_common.php3');
596 include('./db_details_db_info.php3');
598 include('./libraries/relation.lib.php3');
599 $cfgRelation = PMA_getRelationsParam();
602 // Gets the list of fields properties
603 if (isset($result) && $result) {
604 while ($field = PMA_mysql_fetch_field($result)) {
605 $fields_meta[] = $field;
607 $fields_cnt = count($fields_meta);
610 // Display previous update query (from tbl_replace)
611 if (isset($disp_query) && $cfg['ShowSQL'] == TRUE) {
612 $tmp_sql_query = $GLOBALS['sql_query'];
613 $tmp_sql_limit_to_append = (isset($GLOBALS['sql_limit_to_append'])?$GLOBALS['sql_limit_to_append']:'');
614 $GLOBALS['sql_query'] = $disp_query;
615 $GLOBALS['sql_limit_to_append'] = '';
616 PMA_showMessage($disp_message);
617 $GLOBALS['sql_query'] = $tmp_sql_query;
618 $GLOBALS['sql_limit_to_append'] = $tmp_sql_limit_to_append;
621 // Displays the results in a table
622 include('./libraries/display_tbl.lib.php3');
623 if (empty($disp_mode)) {
624 // see the "PMA_setDisplayMode()" function in
625 // libraries/display_tbl.lib.php3
626 $disp_mode = 'urdr111101';
628 if (!isset($dontlimitchars)) {
629 $dontlimitchars = 0;
632 PMA_displayTable($result, $disp_mode, $analyzed_sql);
633 mysql_free_result($result);
635 if ($disp_mode[6] == '1' || $disp_mode[9] == '1') {
636 echo "\n";
637 echo '<p>' . "\n";
639 // Displays "Insert a new row" link if required
640 if ($disp_mode[6] == '1') {
641 $lnk_goto = 'sql.php3?'
642 . PMA_generate_common_url($db, $table)
643 . '&amp;pos=' . $pos
644 . '&amp;session_max_rows=' . $session_max_rows
645 . '&amp;disp_direction=' . $disp_direction
646 . '&amp;repeat_cells=' . $repeat_cells
647 . '&amp;dontlimitchars=' . $dontlimitchars
648 . '&amp;sql_query=' . urlencode($sql_query);
649 $url_query = '?'
650 . PMA_generate_common_url($db, $table)
651 . '&amp;pos=' . $pos
652 . '&amp;session_max_rows=' . $session_max_rows
653 . '&amp;disp_direction=' . $disp_direction
654 . '&amp;repeat_cells=' . $repeat_cells
655 . '&amp;dontlimitchars=' . $dontlimitchars
656 . '&amp;sql_query=' . urlencode($sql_query)
657 . '&amp;goto=' . urlencode($lnk_goto);
659 echo ' <!-- Insert a new row -->' . "\n"
660 . ' <a href="tbl_change.php3' . $url_query . '">' . $strInsertNewRow . '</a>';
661 if ($disp_mode[9] == '1') {
662 echo '<br />';
664 echo "\n";
665 } // end insert new row
667 // Displays "printable view" link if required
668 if ($disp_mode[9] == '1') {
669 $url_query = '?'
670 . PMA_generate_common_url($db, $table)
671 . '&amp;pos=' . $pos
672 . '&amp;session_max_rows=' . $session_max_rows
673 . '&amp;disp_direction=' . $disp_direction
674 . '&amp;repeat_cells=' . $repeat_cells
675 . '&amp;printview=1'
676 . ((isset($dontlimitchars) && $dontlimitchars == '1') ? '&amp;dontlimitchars=1' : '')
677 . '&amp;sql_query=' . urlencode($sql_query);
678 echo ' <!-- Print view -->' . "\n"
679 . ' <a href="sql.php3' . $url_query . '" target="print_view">' . $strPrintView . '</a>' . "\n";
680 } // end displays "printable view"
682 echo '</p>' . "\n";
685 // Export link, if only one table
686 // (the url_query has extra parameters that won't be used to export)
687 if (!isset($printview)) {
688 if (isset($analyzed_sql[0]['table_ref'][0]['table_true_name']) && !isset($analyzed_sql[0]['table_ref'][1]['table_true_name'])) {
689 $single_table = '&amp;single_table=true';
690 } else {
691 $single_table = '';
693 echo ' <!-- Export -->' . "\n"
694 . ' <a href="tbl_properties_export.php3' . $url_query
695 . '&amp;unlim_num_rows=' . $unlim_num_rows
696 . $single_table
697 . '">' . $strExport . '</a>' . "\n";
700 // Bookmark Support if required
701 if ($disp_mode[7] == '1'
702 && ($cfg['Bookmark']['db'] && $cfg['Bookmark']['table'] && empty($id_bookmark))
703 && !empty($sql_query)) {
704 echo "\n";
706 $goto = 'sql.php3?'
707 . PMA_generate_common_url($db, $table)
708 . '&amp;pos=' . $pos
709 . '&amp;session_max_rows=' . $session_max_rows
710 . '&amp;disp_direction=' . $disp_direction
711 . '&amp;repeat_cells=' . $repeat_cells
712 . '&amp;dontlimitchars=' . $dontlimitchars
713 . '&amp;sql_query=' . urlencode($sql_query)
714 . '&amp;id_bookmark=1';
716 <!-- Bookmark the query -->
717 <form action="sql.php3" method="post" onsubmit="return emptyFormElements(this, 'fields[label]');">
718 <?php
719 echo "\n";
720 if ($disp_mode[3] == '1') {
721 echo ' <i>' . $strOr . '</i>' . "\n";
724 <br /><br />
725 <?php echo $strBookmarkLabel; ?>&nbsp;:
726 <?php echo PMA_generate_common_hidden_inputs(); ?>
727 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
728 <input type="hidden" name="fields[dbase]" value="<?php echo htmlspecialchars($db); ?>" />
729 <input type="hidden" name="fields[user]" value="<?php echo $cfg['Bookmark']['user']; ?>" />
730 <input type="hidden" name="fields[query]" value="<?php echo urlencode($sql_query); ?>" />
731 <input type="text" name="fields[label]" value="" />
732 <input type="submit" name="store_bkm" value="<?php echo $strBookmarkThis; ?>" />
733 </form>
734 <?php
735 } // end bookmark support
737 // Do print the page if required
738 if (isset($printview) && $printview == '1') {
739 echo "\n";
741 <script type="text/javascript" language="javascript1.2">
742 <!--
743 // Do print the page
744 if (typeof(window.print) != 'undefined') {
745 window.print();
747 //-->
748 </script>
749 <?php
750 } // end print case
751 } // end rows returned
753 } // end executes the query
754 echo "\n\n";
758 * Displays the footer
760 require('./footer.inc.php3');