bug 780516
[phpmyadmin/crack.git] / sql.php3
blob3dd87dd02f8a7805f031836c4f1bdeac410b7fb2
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');
12 /**
13 * Defines the url to return to in case of error in a sql statement
15 // Security checkings
16 if (!empty($goto)) {
17 $is_gotofile = ereg_replace('^([^?]+).*$', '\\1', $goto);
18 if (!@file_exists('./' . $is_gotofile)) {
19 unset($goto);
20 } else {
21 $is_gotofile = ($is_gotofile == $goto);
23 } // end if (security checkings)
25 if (empty($goto)) {
26 $goto = (empty($table)) ? $cfg['DefaultTabDatabase'] : $cfg['DefaultTabTable'];
27 $is_gotofile = TRUE;
28 } // end if
29 if (!isset($err_url)) {
30 $err_url = (!empty($back) ? $back : $goto)
31 . '?' . PMA_generate_common_url(isset($db) ? $db : '')
32 . ((strpos(' ' . $goto, 'db_details') != 1 && isset($table)) ? '&amp;table=' . urlencode($table) : '');
33 } // end if
35 // Coming from a bookmark dialog
36 if (isset($fields['query'])) {
37 $sql_query = $fields['query'];
40 // This one is just to fill $db
41 if (isset($fields['dbase'])) {
42 $db = $fields['dbase'];
45 // Now we can check the parameters
46 PMA_checkParameters(array('sql_query', 'db'));
49 /**
50 * Check rights in case of DROP DATABASE
52 * This test may be bypassed if $is_js_confirmed = 1 (already checked with js)
53 * but since a malicious user may pass this variable by url/form, we don't take
54 * into account this case.
56 if (!defined('PMA_CHK_DROP')
57 && !$cfg['AllowUserDropDatabase']
58 && eregi('DROP[[:space:]]+(IF EXISTS[[:space:]]+)?DATABASE[[:space:]]', $sql_query)) {
59 // Checks if the user is a Superuser
60 // TODO: set a global variable with this information
61 // loic1: optimized query
62 $result = @PMA_mysql_query('USE mysql');
63 if (PMA_mysql_error()) {
64 include('./header.inc.php3');
65 PMA_mysqlDie($strNoDropDatabases, '', '', $err_url);
66 } // end if
67 } // end if
70 /**
71 * Bookmark add
73 if (isset($store_bkm)) {
74 include('./libraries/bookmark.lib.php3');
75 PMA_addBookmarks($fields, $cfg['Bookmark']);
76 header('Location: ' . $cfg['PmaAbsoluteUri'] . $goto);
77 } // end if
80 /**
81 * Gets the true sql query
83 // $sql_query has been urlencoded in the confirmation form for drop/delete
84 // queries or in the navigation bar for browsing among records
85 if (isset($btnDrop) || isset($navig)) {
86 $sql_query = urldecode($sql_query);
89 /**
90 * Reformat the query
93 $GLOBALS['unparsed_sql'] = $sql_query;
94 $parsed_sql = PMA_SQP_parse($sql_query);
95 $analyzed_sql = PMA_SQP_analyze($parsed_sql);
96 // Bug #641765 - Robbat2 - 12 January 2003, 10:49PM
97 // Reverted - Robbat2 - 13 January 2003, 2:40PM
98 $sql_query = PMA_SQP_formatHtml($parsed_sql, 'query_only');
100 // old code did not work, for example, when there is a bracket
101 // before the SELECT
102 // so I guess it's ok to check for a real SELECT ... FROM
103 //$is_select = eregi('^SELECT[[:space:]]+', $sql_query);
104 $is_select = isset($analyzed_sql[0]['queryflags']['select_from']);
106 // If the query is a Select, extract the db and table names and modify
107 // $db and $table, to have correct page headers, links and left frame.
108 // db and table name may be enclosed with backquotes, db is optionnal,
109 // query may contain aliases.
111 // (TODO: if there are more than one table name in the Select:
112 // - do not extract the first table name
113 // - do not show a table name in the page header
114 // - do not display the sub-pages links)
116 if ($is_select) {
117 $prev_db = $db;
118 if (isset($analyzed_sql[0]['table_ref'][0]['table_true_name'])) {
119 $table = $analyzed_sql[0]['table_ref'][0]['table_true_name'];
121 if (isset($analyzed_sql[0]['table_ref'][0]['db'])
122 && !empty($analyzed_sql[0]['table_ref'][0]['db'])) {
123 $db = $analyzed_sql[0]['table_ref'][0]['db'];
125 else {
126 $db = $prev_db;
128 $reload = ($db == $prev_db) ? 0 : 1;
132 * Sets or modifies the $goto variable if required
134 if ($goto == 'sql.php3') {
135 $goto = 'sql.php3?'
136 . PMA_generate_common_url($db, $table)
137 . '&amp;pos=' . $pos
138 . '&amp;sql_query=' . urlencode($sql_query);
139 } // end if
143 * Go back to further page if table should not be dropped
145 if (isset($btnDrop) && $btnDrop == $strNo) {
146 if (!empty($back)) {
147 $goto = $back;
149 if ($is_gotofile) {
150 if (strpos(' ' . $goto, 'db_details') == 1 && !empty($table)) {
151 unset($table);
153 $active_page = $goto;
154 include('./' . ereg_replace('\.\.*', '.', $goto));
155 } else {
156 header('Location: ' . $cfg['PmaAbsoluteUri'] . str_replace('&amp;', '&', $goto));
158 exit();
159 } // end if
163 * Displays the confirm page if required
165 * This part of the script is bypassed if $is_js_confirmed = 1 (already checked
166 * with js) because possible security issue is not so important here: at most,
167 * the confirm message isn't displayed.
169 * Also bypassed if only showing php code.or validating a SQL query
171 if (!$cfg['Confirm']
172 || (isset($is_js_confirmed) && $is_js_confirmed)
173 || isset($btnDrop)
174 || !empty($GLOBALS['show_as_php'])
175 || !empty($GLOBALS['validatequery'])) {
176 $do_confirm = FALSE;
177 } else {
178 //$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));
180 $do_confirm = isset($analyzed_sql[0]['queryflags']['need_confirm']);
183 if ($do_confirm) {
184 $stripped_sql_query = $sql_query;
185 include('./header.inc.php3');
186 echo $strDoYouReally . '&nbsp;:<br />' . "\n";
187 echo '<tt>' . htmlspecialchars($stripped_sql_query) . '</tt>&nbsp;?<br/>' . "\n";
189 <form action="sql.php3" method="post">
190 <?php echo PMA_generate_common_hidden_inputs($db, (isset($table)?$table:'')); ?>
191 <input type="hidden" name="sql_query" value="<?php echo urlencode($sql_query); ?>" />
192 <input type="hidden" name="zero_rows" value="<?php echo isset($zero_rows) ? $zero_rows : ''; ?>" />
193 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
194 <input type="hidden" name="back" value="<?php echo isset($back) ? $back : ''; ?>" />
195 <input type="hidden" name="reload" value="<?php echo isset($reload) ? $reload : 0; ?>" />
196 <input type="hidden" name="purge" value="<?php echo isset($purge) ? $purge : ''; ?>" />
197 <input type="hidden" name="cpurge" value="<?php echo isset($cpurge) ? $cpurge : ''; ?>" />
198 <input type="hidden" name="purgekey" value="<?php echo isset($purgekey) ? $purgekey : ''; ?>" />
199 <input type="hidden" name="show_query" value="<?php echo isset($show_query) ? $show_query : ''; ?>" />
200 <input type="submit" name="btnDrop" value="<?php echo $strYes; ?>" />
201 <input type="submit" name="btnDrop" value="<?php echo $strNo; ?>" />
202 </form>
203 <?php
204 echo "\n";
205 } // end if
209 * Executes the query and displays results
211 else {
212 if (!isset($sql_query)) {
213 $sql_query = '';
215 // Defines some variables
216 // loic1: A table has to be created -> left frame should be reloaded
217 if ((!isset($reload) || $reload == 0)
218 && eregi('^CREATE TABLE[[:space:]]+(.*)', $sql_query)) {
219 $reload = 1;
221 // Gets the number of rows per page
222 if (!isset($session_max_rows)) {
223 $session_max_rows = $cfg['MaxRows'];
224 } else if ($session_max_rows != 'all') {
225 $cfg['MaxRows'] = $session_max_rows;
227 // Defines the display mode (horizontal/vertical) and header "frequency"
228 if (empty($disp_direction)) {
229 $disp_direction = $cfg['DefaultDisplay'];
231 if (empty($repeat_cells)) {
232 $repeat_cells = $cfg['RepeatCells'];
235 // SK -- Patch: $is_group added for use in calculation of total number of
236 // rows.
237 // $is_count is changed for more correct "LIMIT" clause
238 // appending in queries like
239 // "SELECT COUNT(...) FROM ... GROUP BY ..."
241 // TODO: detect all this with the parser, to avoid problems finding
242 // those strings in comments or backquoted identifiers
244 $is_explain = $is_count = $is_export = $is_delete = $is_insert = $is_affected = $is_show = $is_maint = $is_analyse = $is_group = $is_func = FALSE;
245 if ($is_select) { // see line 141
246 $is_group = eregi('(GROUP[[:space:]]+BY|HAVING|SELECT[[:space:]]+DISTINCT)[[:space:]]+', $sql_query);
247 $is_func = !$is_group && (eregi('[[:space:]]+(SUM|AVG|STD|STDDEV|MIN|MAX|BIT_OR|BIT_AND)\s*\(', $sql_query));
248 $is_count = !$is_group && (eregi('^SELECT[[:space:]]+COUNT\((.*\.+)?.*\)', $sql_query));
249 $is_export = (eregi('[[:space:]]+INTO[[:space:]]+OUTFILE[[:space:]]+', $sql_query));
250 $is_analyse = (eregi('[[:space:]]+PROCEDURE[[:space:]]+ANALYSE', $sql_query));
251 } else if (eregi('^EXPLAIN[[:space:]]+', $sql_query)) {
252 $is_explain = TRUE;
253 } else if (eregi('^DELETE[[:space:]]+', $sql_query)) {
254 $is_delete = TRUE;
255 $is_affected = TRUE;
256 } else if (eregi('^(INSERT|LOAD[[:space:]]+DATA|REPLACE)[[:space:]]+', $sql_query)) {
257 $is_insert = TRUE;
258 $is_affected = TRUE;
259 } else if (eregi('^UPDATE[[:space:]]+', $sql_query)) {
260 $is_affected = TRUE;
261 } else if (eregi('^SHOW[[:space:]]+', $sql_query)) {
262 $is_show = TRUE;
263 } else if (eregi('^(CHECK|ANALYZE|REPAIR|OPTIMIZE)[[:space:]]+TABLE[[:space:]]+', $sql_query)) {
264 $is_maint = TRUE;
267 // Do append a "LIMIT" clause?
268 if (isset($pos)
269 && (!$cfg['ShowAll'] || $session_max_rows != 'all')
270 && !($is_count || $is_export || $is_func || $is_analyse)
271 && isset($analyzed_sql[0]['queryflags']['select_from'])
272 && !eregi('[[:space:]]LIMIT[[:space:]0-9,-]+$', $sql_query)) {
273 $sql_limit_to_append = " LIMIT $pos, ".$cfg['MaxRows'];
274 if (eregi('(.*)([[:space:]](PROCEDURE[[:space:]](.*)|FOR[[:space:]]+UPDATE|LOCK[[:space:]]+IN[[:space:]]+SHARE[[:space:]]+MODE))$', $sql_query, $regs)) {
275 $full_sql_query = $regs[1] . $sql_limit_to_append . $regs[2];
276 } else {
277 $full_sql_query = $sql_query . $sql_limit_to_append;
279 } else {
280 $full_sql_query = $sql_query;
281 } // end if...else
283 PMA_mysql_select_db($db);
285 // If the query is a DELETE query with no WHERE clause, get the number of
286 // rows that will be deleted (mysql_affected_rows will always return 0 in
287 // this case)
288 if ($is_delete
289 && eregi('^DELETE([[:space:]].+)?([[:space:]]FROM[[:space:]](.+))$', $sql_query, $parts)
290 && !eregi('[[:space:]]WHERE[[:space:]]', $parts[3])) {
291 $cnt_all_result = @PMA_mysql_query('SELECT COUNT(*) as count' . $parts[2]);
292 if ($cnt_all_result) {
293 $num_rows = PMA_mysql_result($cnt_all_result, 0, 'count');
294 mysql_free_result($cnt_all_result);
295 } else {
296 $num_rows = 0;
300 // E x e c u t e t h e q u e r y
302 // Only if we didn't ask to see the php code (mikebeck)
303 if (isset($GLOBALS['show_as_php']) || !empty($GLOBALS['validatequery'])) {
304 unset($result);
305 $num_rows = 0;
307 else {
308 // garvin: Measure query time. TODO-Item http://sourceforge.net/tracker/index.php?func=detail&aid=571934&group_id=23067&atid=377411
309 list($usec, $sec) = explode(' ',microtime());
310 $querytime_before = ((float)$usec + (float)$sec);
312 $result = @PMA_mysql_query($full_sql_query);
314 list($usec, $sec) = explode(' ',microtime());
315 $querytime_after = ((float)$usec + (float)$sec);
317 $GLOBALS['querytime'] = $querytime_after - $querytime_before;
319 // Displays an error message if required and stop parsing the script
320 if (PMA_mysql_error()) {
321 $error = PMA_mysql_error();
322 include('./header.inc.php3');
323 $full_err_url = (ereg('^(db_details|tbl_properties)', $err_url))
324 ? $err_url . '&amp;show_query=1&amp;sql_query=' . urlencode($sql_query)
325 : $err_url;
326 PMA_mysqlDie($error, $full_sql_query, '', $full_err_url);
329 // Gets the number of rows affected/returned
330 // (This must be done immediately after the query because
331 // mysql_affected_rows() reports about the last query done)
333 if (!$is_affected) {
334 $num_rows = ($result) ? @mysql_num_rows($result) : 0;
335 } else if (!isset($num_rows)) {
336 $num_rows = @mysql_affected_rows();
339 // Checks if the current database has changed
340 // This could happen if the user sends a query like "USE `database`;"
341 $res = PMA_mysql_query('SELECT DATABASE() AS "db";');
342 $row = PMA_mysql_fetch_array($res);
343 if ($db != $row['db']) {
344 $db = $row['db'];
345 $reload = 1;
347 @mysql_free_result($res);
348 unset($res);
349 unset($row);
351 // tmpfile remove after convert encoding appended by Y.Kawada
352 if (function_exists('PMA_kanji_file_conv')
353 && (isset($textfile) && file_exists($textfile))) {
354 unlink($textfile);
357 // Counts the total number of rows for the same 'SELECT' query without the
358 // 'LIMIT' clause that may have been programatically added
360 if (empty($sql_limit_to_append)) {
361 $unlim_num_rows = $num_rows;
363 else if ($is_select) {
365 // c o u n t q u e r y
367 // If we are "just browsing", there is only one table,
368 // and no where clause (or just 'WHERE 1 '),
369 // so we do a quick count (which uses MaxExactCount)
370 // because SQL_CALC_FOUND_ROWS
371 // is not quick on large InnoDB tables
373 if (!$is_group
374 && !isset($analyzed_sql[0]['queryflags']['union'])
375 && !isset($analyzed_sql[0]['table_ref'][1]['table_name'])
376 && (empty($analyzed_sql[0]['where_clause'])
377 || $analyzed_sql[0]['where_clause'] == '1 ')) {
379 // "j u s t b r o w s i n g"
380 $unlim_num_rows = PMA_countRecords($db, $table, TRUE);
382 } else { // n o t " j u s t b r o w s i n g "
384 if (PMA_MYSQL_INT_VERSION < 40000) {
385 // TODO: detect DISTINCT in the parser
386 if (eregi('DISTINCT(.*)', $sql_query)) {
387 $count_what = 'DISTINCT ' . $analyzed_sql[0]['select_expr_clause'];
388 } else {
389 $count_what = '*';
392 $count_query = 'SELECT COUNT(' . $count_what . ') AS count';
395 // add the remaining of select expression if there is
396 // a GROUP BY or HAVING clause
397 if (PMA_MYSQL_INT_VERSION < 40000
398 && $count_what =='*'
399 && (!empty($analyzed_sql[0]['group_by_clause'])
400 || !empty($analyzed_sql[0]['having_clause']))) {
401 $count_query .= ' ,' . $analyzed_sql[0]['select_expr_clause'];
404 if (PMA_MYSQL_INT_VERSION >= 40000) {
405 // add select expression after the SQL_CALC_FOUND_ROWS
406 // if (eregi('DISTINCT(.*)', $sql_query)) {
407 // $count_query .= 'DISTINCT ' . $analyzed_sql[0]['select_expr_clause'];
408 // } else {
409 //$count_query .= $analyzed_sql[0]['select_expr_clause'];
411 // for UNION, just adding SQL_CALC_FOUND_ROWS
412 // after the first SELECT works.
414 // take the left part, could be:
415 // SELECT
416 // (SELECT
417 $count_query = PMA_SQP_formatHtml($parsed_sql, 'query_only', 0, $analyzed_sql[0]['position_of_first_select'] + 1);
418 $count_query .= ' SQL_CALC_FOUND_ROWS ';
420 // add everything that was after the first SELECT
421 $count_query .= PMA_SQP_formatHtml($parsed_sql, 'query_only', $analyzed_sql[0]['position_of_first_select']+1);
422 // }
423 } else { // PMA_MYSQL_INT_VERSION < 40000
425 if (!empty($analyzed_sql[0]['from_clause'])) {
426 $count_query .= ' FROM ' . $analyzed_sql[0]['from_clause'];
428 if (!empty($analyzed_sql[0]['where_clause'])) {
429 $count_query .= ' WHERE ' . $analyzed_sql[0]['where_clause'];
431 if (!empty($analyzed_sql[0]['group_by_clause'])) {
432 $count_query .= ' GROUP BY ' . $analyzed_sql[0]['group_by_clause'];
434 if (!empty($analyzed_sql[0]['having_clause'])) {
435 $count_query .= ' HAVING ' . $analyzed_sql[0]['having_clause'];
437 } // end if
439 // if using SQL_CALC_FOUND_ROWS, add a LIMIT to avoid
440 // long delays. Returned count will be complete anyway.
441 // (but a LIMIT would disrupt results in an UNION)
443 if (PMA_MYSQL_INT_VERSION >= 40000
444 && !isset($analyzed_sql[0]['queryflags']['union'])) {
445 $count_query .= ' LIMIT 1';
448 // run the count query
449 //DEBUG echo "trace cq=" . $count_query . "<br/>";
451 if (PMA_MYSQL_INT_VERSION < 40000) {
452 if ($cnt_all_result = PMA_mysql_query($count_query)) {
453 if ($is_group && $count_what == '*') {
454 $unlim_num_rows = @mysql_num_rows($cnt_all_result);
455 } else {
456 $unlim_num_rows = PMA_mysql_result($cnt_all_result, 0, 'count');
458 mysql_free_result($cnt_all_result);
459 } else {
460 if (mysql_error()) {
462 // there are some cases where the generated
463 // count_query (for MySQL 3) is wrong,
464 // so we get here.
465 //TODO: use a big unlimited query to get
466 // the correct number of rows (depending
467 // on a config variable?)
468 $unlim_num_rows = 0;
471 } else {
472 PMA_mysql_query($count_query);
473 if (mysql_error()) {
474 // void. I tried the case
475 // (SELECT `User`, `Host`, `Db`, `Select_priv` FROM `db`)
476 // UNION (SELECT `User`, `Host`, "%" AS "Db",
477 // `Select_priv`
478 // FROM `user`) ORDER BY `User`, `Host`, `Db`;
479 // and although the generated count_query is wrong
480 // the SELECT FOUND_ROWS() work!
482 $cnt_all_result = PMA_mysql_query('SELECT FOUND_ROWS() as count');
483 $unlim_num_rows = PMA_mysql_result($cnt_all_result,0,'count');
485 } // end else "just browsing"
487 } else { // not $is_select
488 $unlim_num_rows = 0;
489 } // end rows total count
491 // garvin: if a table or database gets dropped, check column comments.
492 if (isset($purge) && $purge == '1') {
493 include('./libraries/relation_cleanup.lib.php3');
495 if (isset($table) && isset($db) && !empty($table) && !empty($db)) {
496 PMA_relationsCleanupTable($db, $table);
497 } elseif (isset($db) && !empty($db)) {
498 PMA_relationsCleanupDatabase($db);
499 } else {
500 // garvin: VOID. No DB/Table gets deleted.
501 } // end if relation-stuff
502 } // end if ($purge)
504 // garvin: If a column gets dropped, do relation magic.
505 if (isset($cpurge) && $cpurge == '1' && isset($purgekey)
506 && isset($db) && isset($table)
507 && !empty($db) && !empty($table) && !empty($purgekey)) {
508 include('./libraries/relation_cleanup.lib.php3');
509 PMA_relationsCleanupColumn($db, $table, $purgekey);
511 } // end if column PMA_* purge
512 } // end else "didn't ask to see php code"
515 // No rows returned -> move back to the calling page
516 if ($num_rows < 1 || $is_affected) {
517 if ($is_delete) {
518 $message = $strDeletedRows . '&nbsp;' . $num_rows;
519 } else if ($is_insert) {
520 $message = $strInsertedRows . '&nbsp;' . $num_rows;
521 $insert_id = mysql_insert_id();
522 if ($insert_id != 0) {
523 $message .= '<br />'.$strInsertedRowId . '&nbsp;' . $insert_id;
525 } else if ($is_affected) {
526 $message = $strAffectedRows . '&nbsp;' . $num_rows;
527 } else if (!empty($zero_rows)) {
528 $message = $zero_rows;
529 } else if (!empty($GLOBALS['show_as_php'])) {
530 $message = $strPhp;
531 } else if (!empty($GLOBALS['validatequery'])) {
532 $message = $strValidateSQL;
533 } else {
534 $message = $strEmptyResultSet;
537 $message .= ' ' . (isset($GLOBALS['querytime']) ? '(' . sprintf($strQueryTime, $GLOBALS['querytime']) . ')' : '');
539 if ($is_gotofile) {
540 $goto = ereg_replace('\.\.*', '.', $goto);
541 // Checks for a valid target script
542 if (isset($table) && $table == '') {
543 unset($table);
545 if (isset($db) && $db == '') {
546 unset($db);
548 $is_db = $is_table = FALSE;
549 if (strpos(' ' . $goto, 'tbl_properties') == 1) {
550 if (!isset($table)) {
551 $goto = 'db_details.php3';
552 } else {
553 $is_table = @PMA_mysql_query('SHOW TABLES LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\'');
554 if (!($is_table && @mysql_numrows($is_table))) {
555 $goto = 'db_details.php3';
556 unset($table);
558 } // end if... else...
560 if (strpos(' ' . $goto, 'db_details') == 1) {
561 if (isset($table)) {
562 unset($table);
564 if (!isset($db)) {
565 $goto = 'main.php3';
566 } else {
567 $is_db = @PMA_mysql_select_db($db);
568 if (!$is_db) {
569 $goto = 'main.php3';
570 unset($db);
572 } // end if... else...
574 // Loads to target script
575 if (strpos(' ' . $goto, 'db_details') == 1
576 || strpos(' ' . $goto, 'tbl_properties') == 1) {
577 $js_to_run = 'functions.js';
579 if ($goto != 'main.php3') {
580 include('./header.inc.php3');
582 $active_page = $goto;
583 include('./' . $goto);
584 } // end if file_exist
585 else {
586 header('Location: ' . $cfg['PmaAbsoluteUri'] . str_replace('&amp;', '&', $goto) . '&message=' . urlencode($message));
587 } // end else
588 exit();
589 } // end no rows returned
591 // At least one row is returned -> displays a table with results
592 else {
593 // Displays the headers
594 if (isset($show_query)) {
595 unset($show_query);
597 if (isset($printview) && $printview == '1') {
598 include('./header_printview.inc.php3');
599 } else {
600 $js_to_run = 'functions.js';
601 unset($message);
602 if (!empty($table)) {
603 include('./tbl_properties_common.php3');
604 $url_query .= '&amp;goto=tbl_properties.php3&amp;back=tbl_properties.php3';
605 include('./tbl_properties_table_info.php3');
607 else {
608 include('./db_details_common.php3');
609 include('./db_details_db_info.php3');
611 include('./libraries/relation.lib.php3');
612 $cfgRelation = PMA_getRelationsParam();
615 // Gets the list of fields properties
616 if (isset($result) && $result) {
617 while ($field = PMA_mysql_fetch_field($result)) {
618 $fields_meta[] = $field;
620 $fields_cnt = count($fields_meta);
623 // Display previous update query (from tbl_replace)
624 if (isset($disp_query) && $cfg['ShowSQL'] == TRUE) {
625 $tmp_sql_query = $GLOBALS['sql_query'];
626 $tmp_sql_limit_to_append = (isset($GLOBALS['sql_limit_to_append'])?$GLOBALS['sql_limit_to_append']:'');
627 $GLOBALS['sql_query'] = $disp_query;
628 $GLOBALS['sql_limit_to_append'] = '';
629 PMA_showMessage($disp_message);
630 $GLOBALS['sql_query'] = $tmp_sql_query;
631 $GLOBALS['sql_limit_to_append'] = $tmp_sql_limit_to_append;
634 // Displays the results in a table
635 include('./libraries/display_tbl.lib.php3');
636 if (empty($disp_mode)) {
637 // see the "PMA_setDisplayMode()" function in
638 // libraries/display_tbl.lib.php3
639 $disp_mode = 'urdr111101';
641 if (!isset($dontlimitchars)) {
642 $dontlimitchars = 0;
645 PMA_displayTable($result, $disp_mode, $analyzed_sql);
646 mysql_free_result($result);
648 if ($disp_mode[6] == '1' || $disp_mode[9] == '1') {
649 echo "\n";
650 echo '<p>' . "\n";
652 // Displays "Insert a new row" link if required
653 if ($disp_mode[6] == '1') {
654 $lnk_goto = 'sql.php3?'
655 . PMA_generate_common_url($db, $table)
656 . '&amp;pos=' . $pos
657 . '&amp;session_max_rows=' . $session_max_rows
658 . '&amp;disp_direction=' . $disp_direction
659 . '&amp;repeat_cells=' . $repeat_cells
660 . '&amp;dontlimitchars=' . $dontlimitchars
661 . '&amp;sql_query=' . urlencode($sql_query);
662 $url_query = '?'
663 . PMA_generate_common_url($db, $table)
664 . '&amp;pos=' . $pos
665 . '&amp;session_max_rows=' . $session_max_rows
666 . '&amp;disp_direction=' . $disp_direction
667 . '&amp;repeat_cells=' . $repeat_cells
668 . '&amp;dontlimitchars=' . $dontlimitchars
669 . '&amp;sql_query=' . urlencode($sql_query)
670 . '&amp;goto=' . urlencode($lnk_goto);
672 echo ' <!-- Insert a new row -->' . "\n"
673 . ' <a href="tbl_change.php3' . $url_query . '">' . $strInsertNewRow . '</a>';
674 if ($disp_mode[9] == '1') {
675 echo '<br />';
677 echo "\n";
678 } // end insert new row
680 // Displays "printable view" link if required
681 if ($disp_mode[9] == '1') {
682 $url_query = '?'
683 . PMA_generate_common_url($db, $table)
684 . '&amp;pos=' . $pos
685 . '&amp;session_max_rows=' . $session_max_rows
686 . '&amp;disp_direction=' . $disp_direction
687 . '&amp;repeat_cells=' . $repeat_cells
688 . '&amp;printview=1'
689 . ((isset($dontlimitchars) && $dontlimitchars == '1') ? '&amp;dontlimitchars=1' : '')
690 . '&amp;sql_query=' . urlencode($sql_query);
691 echo ' <!-- Print view -->' . "\n"
692 . ' <a href="sql.php3' . $url_query . '" target="print_view">' . $strPrintView . '</a>' . "\n";
693 } // end displays "printable view"
695 echo '</p>' . "\n";
698 // Export link, if only one table
699 // (the url_query has extra parameters that won't be used to export)
700 if (!isset($printview)) {
701 if (isset($analyzed_sql[0]['table_ref'][0]['table_true_name']) && !isset($analyzed_sql[0]['table_ref'][1]['table_true_name'])) {
702 $single_table = '&amp;single_table=true';
703 } else {
704 $single_table = '';
706 echo ' <!-- Export -->' . "\n"
707 . ' <a href="tbl_properties_export.php3' . $url_query
708 . '&amp;unlim_num_rows=' . $unlim_num_rows
709 . $single_table
710 . '">' . $strExport . '</a>' . "\n";
713 // Bookmark Support if required
714 if ($disp_mode[7] == '1'
715 && ($cfg['Bookmark']['db'] && $cfg['Bookmark']['table'] && empty($id_bookmark))
716 && !empty($sql_query)) {
717 echo "\n";
719 $goto = 'sql.php3?'
720 . PMA_generate_common_url($db, $table)
721 . '&amp;pos=' . $pos
722 . '&amp;session_max_rows=' . $session_max_rows
723 . '&amp;disp_direction=' . $disp_direction
724 . '&amp;repeat_cells=' . $repeat_cells
725 . '&amp;dontlimitchars=' . $dontlimitchars
726 . '&amp;sql_query=' . urlencode($sql_query)
727 . '&amp;id_bookmark=1';
729 <!-- Bookmark the query -->
730 <form action="sql.php3" method="post" onsubmit="return emptyFormElements(this, 'fields[label]');">
731 <?php
732 echo "\n";
733 if ($disp_mode[3] == '1') {
734 echo ' <i>' . $strOr . '</i>' . "\n";
737 <br /><br />
738 <?php echo $strBookmarkLabel; ?>&nbsp;:
739 <?php echo PMA_generate_common_hidden_inputs(); ?>
740 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
741 <input type="hidden" name="fields[dbase]" value="<?php echo htmlspecialchars($db); ?>" />
742 <input type="hidden" name="fields[user]" value="<?php echo $cfg['Bookmark']['user']; ?>" />
743 <input type="hidden" name="fields[query]" value="<?php echo urlencode($sql_query); ?>" />
744 <input type="text" name="fields[label]" value="" />
745 <input type="submit" name="store_bkm" value="<?php echo $strBookmarkThis; ?>" />
746 </form>
747 <?php
748 } // end bookmark support
750 // Do print the page if required
751 if (isset($printview) && $printview == '1') {
752 echo "\n";
754 <script type="text/javascript" language="javascript1.2">
755 <!--
756 // Do print the page
757 if (typeof(window.print) != 'undefined') {
758 window.print();
760 //-->
761 </script>
762 <?php
763 } // end print case
764 } // end rows returned
766 } // end executes the query
767 echo "\n\n";
770 * Displays the footer
772 require('./footer.inc.php3');