bug 636553
[phpmyadmin/crack.git] / db_details_importdocsql.php3
blobcf25ccf55547afdc0e971246233762aad86d5b3b
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
6 /**
7 * This script imports relation infos from docSQL (www.databay.de)
8 */
11 /**
12 * Get the values of the variables posted or sent to this script and display
13 * the headers
15 require('./libraries/grab_globals.lib.php3');
16 require('./header.inc.php3');
19 /**
20 * Executes import if required
22 if (isset($do) && $do == 'import') {
23 // echo '<h1>Starting Import</h1>';
24 if (substr($docpath, strlen($docpath) - 2, 1) != '/') {
25 $docpath = $docpath . '/';
27 if (is_dir($docpath)) {
28 // Get relation settings
29 include('./libraries/relation.lib.php3');
30 $cfgRelation = PMA_getRelationsParam();
32 // Do the work
33 $handle = opendir($docpath);
34 while ($file = @readdir($handle)) {
35 $filename = basename($file);
36 // echo '<p>Working on file ' . $filename . '</p>';
37 if (strpos(' ' . $filename, '_field_comment.txt')) {
38 $tab = substr($filename, 0, strlen($filename) - strlen('_field_comment.txt'));
39 //echo '<h1>Working on Table ' . $_tab . '</h1>';
40 $fd = fopen($docpath . $file, 'r');
41 if ($fd) {
42 while (!feof($fd)) {
43 $line = fgets($fd, 4096);
44 //echo '<p>' . $line . '</p>';
45 $inf = explode('|',$line);
46 if (!empty($inf[1]) && strlen(trim($inf[1])) > 0) {
47 $qry = 'INSERT INTO ' . PMA_backquote($cfgRelation['column_comments'])
48 . ' (db_name, table_name, column_name, comment) '
49 . ' VALUES('
50 . '\'' . PMA_sqlAddslashes($db) . '\','
51 . '\'' . PMA_sqlAddslashes(trim($tab)) . '\','
52 . '\'' . PMA_sqlAddslashes(trim($inf[0])) . '\','
53 . '\'' . PMA_sqlAddslashes(trim($inf[1])) . '\')';
54 if (PMA_query_as_cu($qry)) {
55 echo '<p>Added comment for column ' . htmlspecialchars($tab) . '.' . htmlspecialchars($inf[0]) . '</p>';
56 } else {
57 echo '<p>Writing of comment not possible</p>';
59 echo "\n";
60 } // end inf[1] exists
61 if (!empty($inf[2]) && strlen(trim($inf[2])) > 0) {
62 $for = explode('->', $inf[2]);
63 $qry = 'INSERT INTO ' . PMA_backquote($cfgRelation['relation'])
64 . '(master_db, master_table, master_field, foreign_db, foreign_table, foreign_field)'
65 . ' VALUES('
66 . '\'' . PMA_sqlAddslashes($db) . '\', '
67 . '\'' . PMA_sqlAddslashes(trim($tab)) . '\', '
68 . '\'' . PMA_sqlAddslashes(trim($inf[0])) . '\', '
69 . '\'' . PMA_sqlAddslashes($db) . '\', '
70 . '\'' . PMA_sqlAddslashes(trim($for[0])) . '\','
71 . '\'' . PMA_sqlAddslashes(trim($for[1])) . '\')';
72 if (PMA_query_as_cu($qry)) {
73 echo '<p>Added relation for column ' . htmlspecialchars($tab) . '.' . htmlspecialchars($inf[0]) . ' to ' . htmlspecialchars($for) . '</p>';
74 } else {
75 echo "<p>writing of Relation not possible</p>";
77 echo "\n";
78 } // end inf[2] exists
80 echo '<p><font color="green">Import finished</font></p>' . "\n";
81 } else {
82 echo '<p><font color="red">File could not be read</font></p>' . "\n";
84 } else {
85 echo '<p><font color="yellow">Ignoring file ' . $file . '</font></p>' . "\n";
86 } // end working on table
87 } // end while
88 } else {
89 echo 'This was not a Directory' . "\n";
94 /**
95 * Try to get the "$DOCUMENT_ROOT" variable whatever is the register_globals
96 * value
98 if (empty($DOCUMENT_ROOT)) {
99 if (!empty($_SERVER) && isset($_SERVER['DOCUMENT_ROOT'])) {
100 $DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
102 else if (!empty($HTTP_SERVER_VARS) && isset($HTTP_SERVER_VARS['DOCUMENT_ROOT'])) {
103 $DOCUMENT_ROOT = $HTTP_SERVER_VARS['DOCUMENT_ROOT'];
105 else if (!empty($_ENV) && isset($_ENV['DOCUMENT_ROOT'])) {
106 $DOCUMENT_ROOT = $_ENV['DOCUMENT_ROOT'];
108 else if (!empty($HTTP_ENV_VARS) && isset($HTTP_ENV_VARS['DOCUMENT_ROOT'])) {
109 $DOCUMENT_ROOT = $HTTP_ENV_VARS['DOCUMENT_ROOT'];
111 else if (@getenv('DOCUMENT_ROOT')) {
112 $DOCUMENT_ROOT = getenv('DOCUMENT_ROOT');
114 else {
115 $DOCUMENT_ROOT = '';
117 } // end if
121 * Displays the form
125 <form method="post" action="db_details_importdocsql.php3">
126 <input type="hidden" name="lang" value="<?php echo $lang; ?>" />
127 <input type="hidden" name="server" value="<?php echo $server; ?>" />
128 <input type="hidden" name="db" value="<?php echo $db; ?>" />
129 <input type="hidden" name="submit_show" value="true" />
130 <input type="hidden" name="do" value="import" />
131 <b>Please enter absolute path on webserver to docSQL Directory:</b>
132 <br /><br />
133 &nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="docpath" size="50" value="<?php echo htmlspecialchars($DOCUMENT_ROOT); ?>" />
134 &nbsp;<input type="submit" value="Import files" />
135 </form>
137 <?php
139 * Displays the footer
141 echo "\n";
142 require('./footer.inc.php3');