Fix for the Open in New Window in Patient/Client->Patients search gui, take 2.
[openemr.git] / phpmyadmin / libraries / import / ldi.php
blob00a5df8e0f8784890413db6ac3b2c9dc15e10348
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * CSV import plugin for phpMyAdmin
6 * @version $Id$
7 */
8 if (! defined('PHPMYADMIN')) {
9 exit;
12 /**
15 if ($plugin_param !== 'table') {
16 return;
19 if (isset($plugin_list)) {
20 if ($GLOBALS['cfg']['Import']['ldi_local_option'] == 'auto') {
21 $GLOBALS['cfg']['Import']['ldi_local_option'] = FALSE;
23 if (PMA_MYSQL_INT_VERSION < 32349) {
24 $GLOBALS['cfg']['Import']['ldi_local_option'] = TRUE;
27 if (PMA_MYSQL_INT_VERSION > 40003) {
28 $result = PMA_DBI_try_query('SHOW VARIABLES LIKE \'local\\_infile\';');
29 if ($result != FALSE && PMA_DBI_num_rows($result) > 0) {
30 $tmp = PMA_DBI_fetch_row($result);
31 if ($tmp[1] == 'ON') {
32 $GLOBALS['cfg']['Import']['ldi_local_option'] = TRUE;
35 PMA_DBI_free_result($result);
36 unset($result);
39 $plugin_list['ldi'] = array(
40 'text' => 'strLDI',
41 'extension' => 'ldi', // This is nonsense, however we want to default to our parser for csv
42 'options' => array(
43 array('type' => 'bool', 'name' => 'replace', 'text' => 'strReplaceTable'),
44 array('type' => 'bool', 'name' => 'ignore', 'text' => 'strIgnoreDuplicates'),
45 array('type' => 'text', 'name' => 'terminated', 'text' => 'strFieldsTerminatedBy', 'size' => 2, 'len' => 2),
46 array('type' => 'text', 'name' => 'enclosed', 'text' => 'strFieldsEnclosedBy', 'size' => 2, 'len' => 2),
47 array('type' => 'text', 'name' => 'escaped', 'text' => 'strFieldsEscapedBy', 'size' => 2, 'len' => 2),
48 array('type' => 'text', 'name' => 'new_line', 'text' => 'strLinesTerminatedBy', 'size' => 2),
49 array('type' => 'text', 'name' => 'columns', 'text' => 'strColumnNames'),
50 array('type' => 'bool', 'name' => 'local_option', 'text' => 'strLDILocal'),
52 'options_text' => 'strOptions',
54 /* We do not define function when plugin is just queried for information above */
55 return;
58 if ($import_file == 'none' || $compression != 'none' || $charset_conversion) {
59 // We handle only some kind of data!
60 $message = $strInvalidLDIImport;
61 $show_error_header = TRUE;
62 $error = TRUE;
63 return;
66 $sql = 'LOAD DATA';
67 if (isset($ldi_local_option)) {
68 $sql .= ' LOCAL';
70 $sql .= ' INFILE \'' . PMA_sqlAddslashes($import_file) . '\'';
71 if (isset($ldi_replace)) {
72 $sql .= ' REPLACE';
73 } elseif (isset($ldi_ignore)) {
74 $sql .= ' IGNORE';
76 $sql .= ' INTO TABLE ' . PMA_backquote($table);
78 if (strlen($ldi_terminated) > 0) {
79 $sql .= ' FIELDS TERMINATED BY \'' . $ldi_terminated . '\'';
81 if (strlen($ldi_enclosed) > 0) {
82 $sql .= ' ENCLOSED BY \'' . PMA_sqlAddslashes($ldi_enclosed) . '\'';
84 if (strlen($ldi_escaped) > 0) {
85 $sql .= ' ESCAPED BY \'' . PMA_sqlAddslashes($ldi_escaped) . '\'';
87 if (strlen($ldi_new_line) > 0){
88 if ($ldi_new_line == 'auto') {
89 $ldi_new_line = PMA_whichCrlf() == "\n" ? '\n' : '\r\n';
91 $sql .= ' LINES TERMINATED BY \'' . $ldi_new_line . '\'';
93 if ($skip_queries > 0) {
94 $sql .= ' IGNORE ' . $skip_queries . ' LINES';
95 $skip_queries = 0;
97 if (strlen($ldi_columns) > 0) {
98 $sql .= ' (';
99 $tmp = split(',( ?)', $ldi_columns);
100 $cnt_tmp = count($tmp);
101 for ($i = 0; $i < $cnt_tmp; $i++) {
102 if ($i > 0) {
103 $sql .= ', ';
105 $sql .= PMA_backquote(trim($tmp[$i]));
106 } // end for
107 $sql .= ')';
110 PMA_importRunQuery($sql, $sql);
111 PMA_importRunQuery();
112 $finished = TRUE;