Fix for the Open in New Window in Patient/Client->Patients search gui, take 2.
[openemr.git] / phpmyadmin / libraries / import / docsql.php
blob5c051f6f915a388a1d827503aad78ea238979e04
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * DocSQL import plugin for phpMyAdmin
6 * @version $Id$
7 */
8 if (! defined('PHPMYADMIN')) {
9 exit;
12 require_once './libraries/relation.lib.php';
13 $cfgRelation = PMA_getRelationsParam();
15 /**
16 * We need relations enabled and we work only on database
18 if ($plugin_param !== 'database' || $GLOBALS['num_tables'] < 1
19 || ! $cfgRelation['relwork'] || ! $cfgRelation['commwork']) {
20 return;
23 if (isset($plugin_list)) {
24 $plugin_list['docsql'] = array( // set name of your plugin
25 'text' => 'strDocSQL', // text to be displayed as choice
26 'extension' => '', // extension this plugin can handle
27 'options' => array( // array of options for your plugin (optional)
28 array('type' => 'text', 'name' => 'table', 'text' => 'strTableName'),
30 'options_text' => 'strOptions', // text to describe plugin options (must be set if options are used)
32 /* We do not define function when plugin is just queried for information above */
33 return;
36 $tab = $_POST['docsql_table'];
37 $buffer = '';
38 /* Read whole buffer, we except it is small enough */
39 while (!$finished && !$error && !$timeout_passed) {
40 $data = PMA_importGetNextChunk();
41 if ($data === FALSE) {
42 // subtract data we didn't handle yet and stop processing
43 break;
44 } elseif ($data === TRUE) {
45 // nothing to read
46 break;
47 } else {
48 // Append new data to buffer
49 $buffer .= $data;
51 } // End of import loop
52 /* Process the data */
53 if ($data === TRUE && !$error && !$timeout_passed) {
54 $buffer = str_replace("\r\n", "\n", $buffer);
55 $buffer = str_replace("\r", "\n", $buffer);
56 $lines = explode("\n", $buffer);
57 foreach ($lines AS $lkey => $line) {
58 //echo '<p>' . $line . '</p>';
59 $inf = explode('|', $line);
60 if (!empty($inf[1]) && strlen(trim($inf[1])) > 0) {
61 $qry = '
62 INSERT INTO
63 ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . '
64 (db_name, table_name, column_name, ' . PMA_backquote('comment') . ')
65 VALUES (
66 \'' . PMA_sqlAddslashes($GLOBALS['db']) . '\',
67 \'' . PMA_sqlAddslashes(trim($tab)) . '\',
68 \'' . PMA_sqlAddslashes(trim($inf[0])) . '\',
69 \'' . PMA_sqlAddslashes(trim($inf[1])) . '\')';
70 PMA_importRunQuery($qry, $qry . '-- ' . htmlspecialchars($tab) . '.' . htmlspecialchars($inf[0]), true);
71 } // end inf[1] exists
72 if (!empty($inf[2]) && strlen(trim($inf[2])) > 0) {
73 $for = explode('->', $inf[2]);
74 $qry = '
75 INSERT INTO
76 ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['relation']) . '
77 (master_db, master_table, master_field, foreign_db, foreign_table, foreign_field)
78 VALUES (
79 \'' . PMA_sqlAddslashes($GLOBALS['db']) . '\',
80 \'' . PMA_sqlAddslashes(trim($tab)) . '\',
81 \'' . PMA_sqlAddslashes(trim($inf[0])) . '\',
82 \'' . PMA_sqlAddslashes($GLOBALS['db']) . '\',
83 \'' . PMA_sqlAddslashes(trim($for[0])) . '\',
84 \'' . PMA_sqlAddslashes(trim($for[1])) . '\')';
85 PMA_importRunQuery($qry, $qry . '-- ' . htmlspecialchars($tab) . '.' . htmlspecialchars($inf[0]) . '(' . htmlspecialchars($inf[2]) . ')', true);
86 } // end inf[2] exists
87 } // End lines loop
88 } // End import
89 // Commit any possible data in buffers
90 PMA_importRunQuery();