Updated e-mail address
[phpmyadmin/crack.git] / db_details_importdocsql.php3
blob09e90e30a76c9802046af8c7432dcdb53664ca38
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');
18 //require common added for string importing - Robbat2, 15 January 2003 9.34PM
19 //all hardcoded strings converted by Robbat2, 15 January 2003 9.34PM
20 require('./libraries/common.lib.php3');
23 /**
24 * Executes import if required
26 if (isset($do) && $do == 'import') {
27 // echo '<h1>Starting Import</h1>';
28 if (substr($docpath, strlen($docpath) - 2, 1) != '/') {
29 $docpath = $docpath . '/';
31 if (is_dir($docpath)) {
32 // Get relation settings
33 include('./libraries/relation.lib.php3');
34 $cfgRelation = PMA_getRelationsParam();
36 // Do the work
37 $handle = opendir($docpath);
38 while ($file = @readdir($handle)) {
39 $filename = basename($file);
40 // echo '<p>Working on file ' . $filename . '</p>';
41 if (strpos(' ' . $filename, '_field_comment.txt')) {
42 $tab = substr($filename, 0, strlen($filename) - strlen('_field_comment.txt'));
43 //echo '<h1>Working on Table ' . $_tab . '</h1>';
44 $fd = fopen($docpath . $file, 'r');
45 if ($fd) {
46 while (!feof($fd)) {
47 $line = fgets($fd, 4096);
48 //echo '<p>' . $line . '</p>';
49 $inf = explode('|',$line);
50 if (!empty($inf[1]) && strlen(trim($inf[1])) > 0) {
51 $qry = 'INSERT INTO ' . PMA_backquote($cfgRelation['column_comments'])
52 . ' (db_name, table_name, column_name, ' . PMA_backquote('comment') . ') '
53 . ' VALUES('
54 . '\'' . PMA_sqlAddslashes($db) . '\','
55 . '\'' . PMA_sqlAddslashes(trim($tab)) . '\','
56 . '\'' . PMA_sqlAddslashes(trim($inf[0])) . '\','
57 . '\'' . PMA_sqlAddslashes(trim($inf[1])) . '\')';
58 if (PMA_query_as_cu($qry)) {
59 echo '<p>' . $strAddedColumnComment . ' ' . htmlspecialchars($tab) . '.' . htmlspecialchars($inf[0]) . '</p>';
60 } else {
61 echo '<p>' . $strWritingCommentNotPossible . '</p>';
63 echo "\n";
64 } // end inf[1] exists
65 if (!empty($inf[2]) && strlen(trim($inf[2])) > 0) {
66 $for = explode('->', $inf[2]);
67 $qry = 'INSERT INTO ' . PMA_backquote($cfgRelation['relation'])
68 . '(master_db, master_table, master_field, foreign_db, foreign_table, foreign_field)'
69 . ' VALUES('
70 . '\'' . PMA_sqlAddslashes($db) . '\', '
71 . '\'' . PMA_sqlAddslashes(trim($tab)) . '\', '
72 . '\'' . PMA_sqlAddslashes(trim($inf[0])) . '\', '
73 . '\'' . PMA_sqlAddslashes($db) . '\', '
74 . '\'' . PMA_sqlAddslashes(trim($for[0])) . '\','
75 . '\'' . PMA_sqlAddslashes(trim($for[1])) . '\')';
76 if (PMA_query_as_cu($qry)) {
77 echo '<p>' . $strAddedColumnRelation . ' ' . htmlspecialchars($tab) . '.' . htmlspecialchars($inf[0]) . ' to ' . htmlspecialchars($for) . '</p>';
78 } else {
79 echo '<p>' . $strWritingRelationNotPossible . '</p>';
81 echo "\n";
82 } // end inf[2] exists
84 echo '<p><font color="green">' . $strImportFinished . '</font></p>' . "\n";
85 } else {
86 echo '<p><font color="red">' . $strFileCouldNotBeRead . '</font></p>' . "\n";
88 } else {
89 echo '<p><font color="yellow">' . sprintf($strIgnoringFile, ' ' . $file) . '</font></p>' . "\n";
90 } // end working on table
91 } // end while
92 } else {
93 echo $strThisNotDirectory . "\n";
98 /**
99 * Try to get the "$DOCUMENT_ROOT" variable whatever is the register_globals
100 * value
102 if (empty($DOCUMENT_ROOT)) {
103 if (!empty($_SERVER) && isset($_SERVER['DOCUMENT_ROOT'])) {
104 $DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
106 else if (!empty($HTTP_SERVER_VARS) && isset($HTTP_SERVER_VARS['DOCUMENT_ROOT'])) {
107 $DOCUMENT_ROOT = $HTTP_SERVER_VARS['DOCUMENT_ROOT'];
109 else if (!empty($_ENV) && isset($_ENV['DOCUMENT_ROOT'])) {
110 $DOCUMENT_ROOT = $_ENV['DOCUMENT_ROOT'];
112 else if (!empty($HTTP_ENV_VARS) && isset($HTTP_ENV_VARS['DOCUMENT_ROOT'])) {
113 $DOCUMENT_ROOT = $HTTP_ENV_VARS['DOCUMENT_ROOT'];
115 else if (@getenv('DOCUMENT_ROOT')) {
116 $DOCUMENT_ROOT = getenv('DOCUMENT_ROOT');
118 else {
119 $DOCUMENT_ROOT = '';
121 } // end if
125 * Displays the form
129 <form method="post" action="db_details_importdocsql.php3">
130 <?php echo PMA_generate_common_hidden_inputs($db); ?>
131 <input type="hidden" name="submit_show" value="true" />
132 <input type="hidden" name="do" value="import" />
133 <b><?php echo $strAbsolutePathToDocSqlDir; ?>:</b>
134 <br /><br />
135 &nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="docpath" size="50" value="<?php echo htmlspecialchars($DOCUMENT_ROOT); ?>" />
136 &nbsp;<input type="submit" value="<?php echo $strImportFiles; ?>" />
137 </form>
139 <?php
141 * Displays the footer
143 echo "\n";
144 require('./footer.inc.php3');