3 // vim: expandtab sw=4 ts=4 sts=4:
5 require_once('./libraries/common.lib.php');
8 * This script imports relation infos from docSQL (www.databay.de)
13 * Get the values of the variables posted or sent to this script and display
16 require_once('./libraries/read_dump.lib.php');
17 require_once('./libraries/header.inc.php');
20 PMA_checkParameters(array('db'));
22 // We do any work, only if docSQL import was enabled in config
23 if (isset($cfg['docSQLDir']) && !empty($cfg['docSQLDir'])) {
25 if (substr($cfg['docSQLDir'], -1) != '/') {
26 $cfg['docSQLDir'] .= '/';
30 * Imports docSQL files
32 * @param string the basepath
33 * @param string the filename
34 * @param string the complete filename
35 * @param string the content of a file
38 * @return boolean always true
40 * @global array GLOBAL variables
42 function docsql_check($docpath = '', $file = '', $filename = '', $content = 'none') {
45 if (preg_match('@^(.*)_field_comment\.(txt|zip|bz2|bzip).*$@i', $filename)) {
46 $tab = preg_replace('@^(.*)_field_comment\.(txt|zip|bz2|bzip).*@si', '\1', $filename);
47 //echo '<h1>Working on Table ' . $_tab . '</h1>';
48 if ($content == 'none') {
50 $fd = fopen($docpath . $file, 'r');
53 $lines[] = fgets($fd, 4096);
57 $content = str_replace("\r\n", "\n", $content);
58 $content = str_replace("\r", "\n", $content);
59 $lines = explode("\n", $content);
62 if (isset($lines) && is_array($lines) && count($lines) > 0) {
63 foreach ($lines AS $lkey => $line) {
64 //echo '<p>' . $line . '</p>';
65 $inf = explode('|', $line);
66 if (!empty($inf[1]) && strlen(trim($inf[1])) > 0) {
69 ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['column_info']) . '
70 ( db_name, table_name, column_name, ' . PMA_backquote('comment') . ' )
72 \'' . PMA_sqlAddslashes($GLOBALS['db']) . '\',
73 \'' . PMA_sqlAddslashes(trim($tab)) . '\',
74 \'' . PMA_sqlAddslashes(trim($inf[0])) . '\',
75 \'' . PMA_sqlAddslashes(trim($inf[1])) . '\')';
76 if (PMA_query_as_cu($qry)) {
77 echo '<p>' . $GLOBALS['strAddedColumnComment'] . ' ' . htmlspecialchars($tab) . '.' . htmlspecialchars($inf[0]) . '</p>';
79 echo '<p>' . $GLOBALS['strWritingCommentNotPossible'] . '</p>';
82 } // end inf[1] exists
83 if (!empty($inf[2]) && strlen(trim($inf[2])) > 0) {
84 $for = explode('->', $inf[2]);
87 ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['relation']) . '
88 ( master_db, master_table, master_field, foreign_db, foreign_table, foreign_field)
90 \'' . PMA_sqlAddslashes($GLOBALS['db']) . '\',
91 \'' . PMA_sqlAddslashes(trim($tab)) . '\',
92 \'' . PMA_sqlAddslashes(trim($inf[0])) . '\',
93 \'' . PMA_sqlAddslashes($GLOBALS['db']) . '\',
94 \'' . PMA_sqlAddslashes(trim($for[0])) . '\',
95 \'' . PMA_sqlAddslashes(trim($for[1])) . '\')';
96 if (PMA_query_as_cu($qry)) {
97 echo '<p>' . $GLOBALS['strAddedColumnRelation'] . ' ' . htmlspecialchars($tab) . '.' . htmlspecialchars($inf[0]) . ' to ' . htmlspecialchars($inf[2]) . '</p>';
99 echo '<p>' . $GLOBALS['strWritingRelationNotPossible'] . '</p>';
102 } // end inf[2] exists
104 echo '<p><font color="green">' . sprintf($GLOBALS['strImportSuccessfullyFinished'], count($lines)) . '</font></p>' . "\n";
106 echo '<p><font color="red">' . $GLOBALS['strFileCouldNotBeRead'] . '</font></p>' . "\n";
111 if ($content != 'none') {
112 echo '<p><font color="orange">' . sprintf($GLOBALS['strIgnoringFile'], ' ' . htmlspecialchars($file)) . '</font></p>' . "\n";
114 // garvin: disabled. Shouldn't impose ANY non-submitted files ever.
115 echo '<p><font color="orange">' . sprintf($GLOBALS['strIgnoringFile'], ' ' . '...') . '</font></p>' . "\n";
118 } // end working on table
122 * Executes import if required
124 if (isset($do) && $do == 'import') {
125 $orig_docpath = $docpath;
127 if (empty($sql_file)) {
131 // Get relation settings
132 require_once('./libraries/relation.lib.php');
133 $cfgRelation = PMA_getRelationsParam();
135 // Gets the query from a file if required
136 if ($sql_file != 'none') {
137 if (file_exists($sql_file)
138 && is_uploaded_file($sql_file)) {
140 $open_basedir = @ini_get
('open_basedir');
142 // If we are on a server with open_basedir, we must move the file
143 // before opening it. The doc explains how to create the "./tmp"
146 if (!empty($open_basedir)) {
148 $tmp_subdir = (PMA_IS_WINDOWS ?
'.\\tmp\\' : './tmp/');
150 // function is_writeable() is valid on PHP3 and 4
151 if (!is_writeable($tmp_subdir)) {
152 $docsql_text = PMA_readFile($sql_file, $sql_file_compression);
153 if ($docsql_text == FALSE) {
154 echo $strFileCouldNotBeRead;
158 $sql_file_new = $tmp_subdir . basename($sql_file);
159 move_uploaded_file($sql_file, $sql_file_new);
160 $docsql_text = PMA_readFile($sql_file_new, $sql_file_compression);
161 unlink($sql_file_new);
164 // read from the normal upload dir
165 $docsql_text = PMA_readFile($sql_file, $sql_file_compression);
168 // Convert the file's charset if necessary
169 if ($cfg['AllowAnywhereRecoding'] && $allow_recoding
170 && isset($charset_of_file) && $charset_of_file != $charset) {
171 $docsql_text = PMA_convert_string($charset_of_file, $charset, $docsql_text);
174 if (!isset($docsql_text) ||
$docsql_text == FALSE ||
$docsql_text == '') {
175 echo '<p><font color="red">' . $GLOBALS['strFileCouldNotBeRead'] . '</font></p>' . "\n";
177 docsql_check('', $sql_file_name, $sql_file_name, $docsql_text);
179 } // end uploaded file stuff
182 // echo '<h1>Starting Import</h1>';
183 $docpath = $cfg['docSQLDir'] . PMA_securePath($docpath);
184 if (substr($docpath, -1) != '/') {
190 if (is_dir($docpath)) {
192 $handle = opendir($docpath);
193 while ($file = @readdir
($handle)) {
194 $filename = basename($file);
195 // echo '<p>Working on file ' . $filename . '</p>';
196 $matched_files +
= docsql_check($docpath, $file, $filename);
199 echo '<p><font color="red">' .$docpath . ': ' . $strThisNotDirectory . "</font></p>\n";
210 <form method
="post" action
="db_importdocsql.php" <?php
if ($is_upload) { echo ' enctype="multipart/form-data"'; } ?
>>
211 <?php
echo PMA_generate_common_hidden_inputs($db); ?
>
212 <input type
="hidden" name
="submit_show" value
="true" />
213 <input type
="hidden" name
="do" value
="import" />
214 <b
><?php
echo $strAbsolutePathToDocSqlDir; ?
>:</b
>
216 <?php
echo $cfg['docSQLDir']; ?
>/<input
class="textfield" type
="text" name
="docpath" size
="15" value
="<?php echo (isset($orig_docpath) ? $orig_docpath : ''); ?>" />
218 // garvin: displays import dump feature only if file upload available
221 echo ' <i>' . $strOr . '</i> ' . $strLocationTextfile . ':<br />' . "\n";
223 <div style
="margin-bottom: 5px">
224 <input type
="file" name
="sql_file" class="textfield" /><br
/>
226 if ($cfg['AllowAnywhereRecoding'] && $allow_recoding) {
227 $temp_charset = reset($cfg['AvailableCharsets']);
228 echo $strCharsetOfFile . "\n"
229 . ' <select name="charset_of_file" size="1">' . "\n"
230 . ' <option value="' . $temp_charset . '"';
231 if ($temp_charset == $charset) {
232 echo ' selected="selected"';
234 echo '>' . $temp_charset . '</option>' . "\n";
235 while ($temp_charset = next($cfg['AvailableCharsets'])) {
236 echo ' <option value="' . $temp_charset . '"';
237 if ($temp_charset == $charset) {
238 echo ' selected="selected"';
240 echo '>' . $temp_charset . '</option>' . "\n";
242 echo ' </select><br />' . "\n" . ' ';
244 $is_gzip = ($cfg['GZipDump'] && @function_exists
('gzopen'));
245 $is_bzip = ($cfg['BZipDump'] && @function_exists
('bzdecompress'));
246 if ($is_bzip ||
$is_gzip) {
247 echo ' ' . $strCompression . ':' . "\n"
248 . ' <input type="radio" id="radio_sql_file_compression_auto" name="sql_file_compression" value="" checked="checked" /><label for="radio_sql_file_compression_auto">' . $strAutodetect . '</label> ' . "\n"
249 . ' <input type="radio" id="radio_sql_file_compression_plain" name="sql_file_compression" value="text/plain" /><label for="radio_sql_file_compression_plain">' . $strNone . '</label> ' . "\n";
251 echo ' <input type="radio" id="radio_sql_file_compression_gzip" name="sql_file_compression" value="application/x-gzip" /><label for="radio_sql_file_compression_gzip">' . $strGzip . '</label> ' . "\n";
254 echo ' <input type="radio" id="radio_sql_file_compression_bzip" name="sql_file_compression" value="application/x-bzip" /><label for="radio_sql_file_compression_bzip">' . $strBzip . '</label> ' . "\n";
257 echo ' <input type="hidden" name="sql_file_compression" value="text/plain" />' . "\n";
266  
;<input type
="submit" value
="<?php echo $strImportFiles; ?>" />
271 } // End if use docSQL
274 * Displays the footer
277 require_once('./libraries/footer.inc.php');