Add Texy! markup export.
[phpmyadmin/crack.git] / tbl_export.php
blob0faedcb81591eb0bc80cd41921e2462bd35f5742
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @version $Id$
6 */
8 /**
11 require_once './libraries/common.inc.php';
13 /**
14 * Gets tables informations and displays top links
16 require_once './libraries/tbl_common.php';
17 $url_query .= '&amp;goto=tbl_export.php&amp;back=tbl_export.php';
18 require_once './libraries/tbl_info.inc.php';
20 // Dump of a table
22 $export_page_title = $strViewDump;
24 // When we have some query, we need to remove LIMIT from that and possibly
25 // generate WHERE clause (if we are asked to export specific rows)
27 if (! empty($sql_query)) {
28 // Parse query so we can work with tokens
29 $parsed_sql = PMA_SQP_parse($sql_query);
31 // Need to generate WHERE clause?
32 if (isset($primary_key)) {
33 // Yes => rebuild query from scracts, this doesn't work with nested
34 // selects :-(
35 $analyzed_sql = PMA_SQP_analyze($parsed_sql);
36 $sql_query = 'SELECT ';
38 if (isset($analyzed_sql[0]['queryflags']['distinct'])) {
39 $sql_query .= ' DISTINCT ';
42 $sql_query .= $analyzed_sql[0]['select_expr_clause'];
44 if (!empty($analyzed_sql[0]['from_clause'])) {
45 $sql_query .= ' FROM ' . $analyzed_sql[0]['from_clause'];
48 $wheres = array();
50 if (isset($primary_key) && is_array($primary_key)
51 && count($primary_key) > 0) {
52 $wheres[] = '(' . implode(') OR (',$primary_key) . ')';
55 if (!empty($analyzed_sql[0]['where_clause'])) {
56 $wheres[] = $analyzed_sql[0]['where_clause'];
59 if (count($wheres) > 0) {
60 $sql_query .= ' WHERE (' . implode(') AND (', $wheres) . ')';
63 if (!empty($analyzed_sql[0]['group_by_clause'])) {
64 $sql_query .= ' GROUP BY ' . $analyzed_sql[0]['group_by_clause'];
66 if (!empty($analyzed_sql[0]['having_clause'])) {
67 $sql_query .= ' HAVING ' . $analyzed_sql[0]['having_clause'];
69 if (!empty($analyzed_sql[0]['order_by_clause'])) {
70 $sql_query .= ' ORDER BY ' . $analyzed_sql[0]['order_by_clause'];
72 } else {
73 // Just crop LIMIT clause
74 $inside_bracket = FALSE;
75 for ($i = $parsed_sql['len'] - 1; $i >= 0; $i--) {
76 if ($parsed_sql[$i]['type'] == 'punct_bracket_close_round') {
77 $inside_bracket = TRUE;
78 continue;
80 if ($parsed_sql[$i]['type'] == 'punct_bracket_open_round') {
81 $inside_bracket = FALSE;
82 continue;
84 if (!$inside_bracket && $parsed_sql[$i]['type'] == 'alpha_reservedWord' && strtoupper($parsed_sql[$i]['data']) == 'LIMIT') {
85 // We found LIMIT to remove
87 $sql_query = '';
89 // Concatenate parts before
90 for ($j = 0; $j < $i; $j++) {
91 $sql_query .= $parsed_sql[$j]['data'] . ' ';
94 // Skip LIMIT
95 $i++;
96 while ($i < $parsed_sql['len'] &&
97 ($parsed_sql[$i]['type'] != 'alpha_reservedWord' ||
98 ($parsed_sql[$i]['type'] == 'alpha_reservedWord' && $parsed_sql[$i]['data'] == 'OFFSET'))) {
99 $i++;
102 // Add remaining parts
103 while ($i < $parsed_sql['len']) {
104 $sql_query .= $parsed_sql[$i]['data'] . ' ';
105 $i++;
107 break;
111 $message = PMA_Message::success();
115 * Displays top menu links
117 require './libraries/tbl_links.inc.php';
119 $export_type = 'table';
120 require_once './libraries/display_export.lib.php';
124 * Displays the footer
126 require_once './libraries/footer.inc.php';