acknowledgments update
[openemr.git] / phpmyadmin / tbl_export.php
blobfbc585c6e9763acff661133dfc4faae23cd82388
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @package PhpMyAdmin
6 */
8 /**
11 require_once 'libraries/common.inc.php';
13 $response = PMA_Response::getInstance();
14 $header = $response->getHeader();
15 $scripts = $header->getScripts();
16 $scripts->addFile('export.js');
18 /**
19 * Gets tables informations and displays top links
21 require_once 'libraries/tbl_common.inc.php';
22 $url_query .= '&amp;goto=tbl_export.php&amp;back=tbl_export.php';
23 require_once 'libraries/tbl_info.inc.php';
25 // Dump of a table
27 $export_page_title = __('View dump (schema) of table');
29 // When we have some query, we need to remove LIMIT from that and possibly
30 // generate WHERE clause (if we are asked to export specific rows)
32 if (! empty($sql_query)) {
33 // Parse query so we can work with tokens
34 $parsed_sql = PMA_SQP_parse($sql_query);
35 $analyzed_sql = PMA_SQP_analyze($parsed_sql);
37 // Need to generate WHERE clause?
38 if (isset($where_clause)) {
40 // Regular expressions which can appear in sql query,
41 // before the sql segment which remains as it is.
42 $regex_array = array(
43 '/\bwhere\b/i', '/\bgroup by\b/i', '/\bhaving\b/i', '/\border by\b/i'
46 $first_occurring_regex = PMA_getFirstOccurringRegularExpression(
47 $regex_array, $sql_query
49 unset($regex_array);
51 // The part "SELECT `id`, `name` FROM `customers`"
52 // is not modified by the next code segment, when exporting
53 // the result set from a query such as
54 // "SELECT `id`, `name` FROM `customers` WHERE id NOT IN
55 // ( SELECT id FROM companies WHERE name LIKE '%u%')"
56 if (! is_null($first_occurring_regex)) {
57 $temp_sql_array = preg_split($first_occurring_regex, $sql_query);
58 $sql_query = $temp_sql_array[0];
60 unset($first_occurring_regex, $temp_sql_array);
62 // Append the where clause using the primary key of each row
63 if (is_array($where_clause) && (count($where_clause) > 0)) {
64 $sql_query .= ' WHERE (' . implode(') OR (', $where_clause) . ')';
67 if (!empty($analyzed_sql[0]['group_by_clause'])) {
68 $sql_query .= ' GROUP BY ' . $analyzed_sql[0]['group_by_clause'];
70 if (!empty($analyzed_sql[0]['having_clause'])) {
71 $sql_query .= ' HAVING ' . $analyzed_sql[0]['having_clause'];
73 if (!empty($analyzed_sql[0]['order_by_clause'])) {
74 $sql_query .= ' ORDER BY ' . $analyzed_sql[0]['order_by_clause'];
76 } else {
77 // Just crop LIMIT clause
78 $sql_query = $analyzed_sql[0]['section_before_limit'] . $analyzed_sql[0]['section_after_limit'];
80 echo PMA_Util::getMessage(PMA_Message::success());
83 $export_type = 'table';
84 require_once 'libraries/display_export.lib.php';