fix for export to windows, take 2.
[openemr.git] / phpmyadmin / tbl_export.php
blobf49b7eff5e56b49359fcb110012a9ba7213224f4
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Table export
6 * @package PhpMyAdmin
7 */
9 /**
12 require_once 'libraries/common.inc.php';
14 $response = PMA_Response::getInstance();
15 $header = $response->getHeader();
16 $scripts = $header->getScripts();
17 $scripts->addFile('export.js');
19 /**
20 * Gets tables informations and displays top links
22 require_once 'libraries/tbl_common.inc.php';
23 $url_query .= '&amp;goto=tbl_export.php&amp;back=tbl_export.php';
24 require_once 'libraries/tbl_info.inc.php';
26 // Dump of a table
28 $export_page_title = __('View dump (schema) of table');
30 // When we have some query, we need to remove LIMIT from that and possibly
31 // generate WHERE clause (if we are asked to export specific rows)
33 if (! empty($sql_query)) {
34 // Parse query so we can work with tokens
35 $parsed_sql = PMA_SQP_parse($sql_query);
36 $analyzed_sql = PMA_SQP_analyze($parsed_sql);
38 // Need to generate WHERE clause?
39 if (isset($where_clause)) {
41 // Regular expressions which can appear in sql query,
42 // before the sql segment which remains as it is.
43 $regex_array = array(
44 '/\bwhere\b/i', '/\bgroup by\b/i', '/\bhaving\b/i', '/\border by\b/i'
47 $first_occurring_regex = PMA_Util::getFirstOccurringRegularExpression(
48 $regex_array, $sql_query
50 unset($regex_array);
52 // The part "SELECT `id`, `name` FROM `customers`"
53 // is not modified by the next code segment, when exporting
54 // the result set from a query such as
55 // "SELECT `id`, `name` FROM `customers` WHERE id NOT IN
56 // ( SELECT id FROM companies WHERE name LIKE '%u%')"
57 if (! is_null($first_occurring_regex)) {
58 $temp_sql_array = preg_split($first_occurring_regex, $sql_query);
59 $sql_query = $temp_sql_array[0];
61 unset($first_occurring_regex, $temp_sql_array);
63 // Append the where clause using the primary key of each row
64 if (is_array($where_clause) && (count($where_clause) > 0)) {
65 $sql_query .= ' WHERE (' . implode(') OR (', $where_clause) . ')';
68 if (!empty($analyzed_sql[0]['group_by_clause'])) {
69 $sql_query .= ' GROUP BY ' . $analyzed_sql[0]['group_by_clause'];
71 if (!empty($analyzed_sql[0]['having_clause'])) {
72 $sql_query .= ' HAVING ' . $analyzed_sql[0]['having_clause'];
74 if (!empty($analyzed_sql[0]['order_by_clause'])) {
75 $sql_query .= ' ORDER BY ' . $analyzed_sql[0]['order_by_clause'];
77 } else {
78 // Just crop LIMIT clause
79 $sql_query = $analyzed_sql[0]['section_before_limit']
80 . $analyzed_sql[0]['section_after_limit'];
82 echo PMA_Util::getMessage(PMA_Message::success());
85 $export_type = 'table';
86 require_once 'libraries/display_export.inc.php';