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