2 /* vim: set expandtab sw=4 ts=4 sts=4: */
7 if (! defined('PHPMYADMIN')) {
14 require_once './libraries/file_listing.lib.php';
15 require_once './libraries/plugin_interface.lib.php';
16 require_once './libraries/display_import_ajax.lib.php';
18 /* Scan for plugins */
19 $import_list = PMA_getPlugins(
21 'libraries/plugins/import/',
25 /* Fail if we didn't find any plugin */
26 if (empty($import_list)) {
29 'Could not load import plugins, please check your installation!'
36 <iframe id
="import_upload_iframe" name
="import_upload_iframe" width
="1" height
="1" style
="display: none;"></iframe
>
37 <div id
="import_form_status" style
="display: none;"></div
>
39 <img src
="<?php echo $GLOBALS['pmaThemeImage'];?>ajax_clock_small.gif" width
="16" height
="16" alt
="ajax clock" style
="display: none;" />
40 <script type
="text/javascript">
43 // add event when user click on "Go" button
44 $
('#buttonGo').bind('click', function() {
45 $
('#upload_form_form').css("display", "none"); // hide form
46 $
('#upload_form_status').css("display", "inline"); // show progress bar
47 $
('#upload_form_status_info').css("display", "inline"); // - || -
49 if ($_SESSION[$SESSION_KEY]["handler"] != "UploadNoplugin") {
55 var original_title
= parent
&& parent
.document ? parent
.document
.title
: false;
58 var perform_upload
= function () {
60 'import_status.php?id=<?php echo $upload_id ; ?>&<?php echo PMA_generate_common_url(array('import_status
'=>1), '&'); ?>',
63 finished
= response
.finished
;
64 percent
= response
.percent
;
65 total
= response
.total
;
66 complete
= response
.complete
;
68 if (total
==0 && complete
==0 && percent
==0) {
69 $
('#upload_form_status_info').html('<img src="<?php echo $GLOBALS['pmaThemeImage
'];?>ajax_clock_small.gif" width="16" height="16" alt="ajax clock" /> <?php echo PMA_jsFormat(__('The file being uploaded is probably larger than the maximum allowed size
or this is a known bug in webkit
based (Safari
, Google Chrome
, Arora etc
.) browsers
.'), false); ?>');
70 $
('#upload_form_status').css("display", "none");
74 now
.getFullYear(), now
.getMonth(), now
.getDate(),
75 now
.getHours(), now
.getMinutes(), now
.getSeconds())
76 + now
.getMilliseconds() - 1000;
77 var statustext
= $
.sprintf('<?php echo PMA_escapeJsString(__('%s of %s
')); ?>',
78 formatBytes(complete
, 1, PMA_messages
.strDecimalSeparator
),
79 formatBytes(total
, 1, PMA_messages
.strDecimalSeparator
)
82 if ($
('#importmain').is(':visible')) {
84 $
('#importmain').hide();
85 $
('#import_form_status')
86 .html('<div class="upload_progress"><div class="upload_progress_bar_outer"><div class="percentage"></div><div id="status" class="upload_progress_bar_inner"><div class="percentage"></div></div></div><div><img src="<?php echo $GLOBALS['pmaThemeImage
'];?>ajax_clock_small.gif" width="16" height="16" alt="ajax clock" /> <?php echo PMA_jsFormat(__('Uploading your import fileā¦
'), false); ?></div><div id="statustext"></div></div>')
90 else if (percent
> 9 || complete
> 2000000) {
91 // calculate estimated time
92 var used_time
= now
- import_start
;
93 var seconds
= parseInt(((total
- complete
) / complete
) * used_time
/ 1000);
94 var speed
= $
.sprintf('<?php echo PMA_jsFormat(__('%s
/sec
.'), false); ?>'
95 , formatBytes(complete
/ used_time
* 1000, 1, PMA_messages
.strDecimalSeparator
));
97 var minutes
= parseInt(seconds
/ 60);
101 estimated_time
= '<?php echo PMA_jsFormat(__('About %MIN min
. %SEC sec
. remaining
.'), false); ?>'
102 .replace('%MIN', minutes
).replace('%SEC', seconds
);
105 estimated_time
= '<?php echo PMA_jsFormat(__('About %SEC sec
. remaining
.'), false); ?>'
106 .replace('%SEC', seconds
);
109 statustext +
= '<br />' + speed +
'<br /><br />' + estimated_time
;
112 var percent_str
= Math
.round(percent
) +
'%';
113 $
('#status').animate({width
: percent_str
}, 150);
114 $
('.percentage').text(percent_str
);
116 // show percent in window title
117 if (original_title
!== false) {
118 parent
.document
.title
= percent_str +
' - ' + original_title
;
121 document
.title
= percent_str +
' - ' + original_title
;
123 $
('#statustext').html(statustext
);
126 if (finished
== true) {
127 if (original_title
!== false) {
128 parent
.document
.title
= original_title
;
131 document
.title
= original_title
;
133 $
('#importmain').hide();
134 $
('#import_form_status')
135 .html('<img src="<?php echo $GLOBALS['pmaThemeImage
'];?>ajax_clock_small.gif" width="16" height="16" alt="ajax clock" /> <?php echo PMA_jsFormat(__('The file is being processed
, please be patient
.'), false); ?> ')
137 $
('#import_form_status').load('import_status.php?message=true&<?php echo PMA_generate_common_url(array('import_status
'=>1), '&'); ?>'); // loads the message, either success or mysql error
139 // reload the left sidebar when the import is finished
140 $GLOBALS['reload'] = true;
145 setTimeout(perform_upload
, 1000);
149 setTimeout(perform_upload
, 1000);
152 } else { // no plugin available
154 $
('#upload_form_status_info').html('<img src="<?php echo $GLOBALS['pmaThemeImage
'];?>ajax_clock_small.gif" width="16" height="16" alt="ajax clock" /> <?php echo PMA_jsFormat(__('Please be patient
, the file is being uploaded
. Details about the upload are not available
.'), false) . PMA_Util::showDocu('faq
', 'faq2
-9'); ?>');
155 $
('#upload_form_status').css("display", "none");
163 <form action
="import.php" method
="post" enctype
="multipart/form-data"
165 if ($_SESSION[$SESSION_KEY]["handler"] != "UploadNoplugin") {
166 echo ' target="import_upload_iframe"';
168 echo ' class="ajax"';
170 <input type
="hidden" name
="<?php
171 echo call_user_func($_SESSION[$SESSION_KEY]['handler'] . '::getIdKey');
172 ?>" value
="<?php echo $upload_id ; ?>" />
175 if ($import_type == 'server') {
176 echo PMA_generate_common_hidden_inputs('', '', 1);
177 } elseif ($import_type == 'database') {
178 echo PMA_generate_common_hidden_inputs($db, '', 1);
180 echo PMA_generate_common_hidden_inputs($db, $table, 1);
182 echo ' <input type="hidden" name="import_type" value="' . $import_type . '" />'."\n";
185 <div
class="exportoptions" id
="header">
187 <?php
echo PMA_Util
::getImage('b_import.png', __('Import')); ?
>
189 if ($import_type == 'server') {
190 echo __('Importing into the current server');
191 } elseif ($import_type == 'database') {
192 printf(__('Importing into the database "%s"'), htmlspecialchars($db));
194 printf(__('Importing into the table "%s"'), htmlspecialchars($table));
199 <div
class="importoptions">
200 <h3
><?php
echo __('File to Import:'); ?
></h3
>
202 // zip, gzip and bzip2 encode features
203 $compressions = array();
205 if ($cfg['GZipDump'] && @function_exists
('gzopen')) {
206 $compressions[] = 'gzip';
208 if ($cfg['BZipDump'] && @function_exists
('bzopen')) {
209 $compressions[] = 'bzip2';
211 if ($cfg['ZipDump'] && @function_exists
('zip_open')) {
212 $compressions[] = 'zip';
214 // We don't have show anything about compression, when no supported
215 if ($compressions != array()) {
216 echo '<div class="formelementrow" id="compression_info">';
217 printf(__('File may be compressed (%s) or uncompressed.'), implode(", ", $compressions));
219 echo __('A compressed file\'s name must end in <b>.[format].[compression]</b>. Example: <b>.sql.zip</b>');
223 <div
class="formelementrow" id
="upload_form">
225 if ($GLOBALS['is_upload'] && !empty($cfg['UploadDir'])) { ?
>
228 <input type
="radio" name
="file_location" id
="radio_import_file" />
230 echo PMA_Util
::getBrowseUploadFileBlock($max_upload_size);
234 <input type
="radio" name
="file_location" id
="radio_local_import_file" />
236 echo PMA_Util
::getSelectUploadFileBlock($import_list, $cfg['UploadDir']);
241 } elseif ($GLOBALS['is_upload']) {
243 echo PMA_Util
::getBrowseUploadFileBlock($max_upload_size);
244 } elseif (!$GLOBALS['is_upload']) {
245 PMA_Message
::notice(__('File uploads are not allowed on this server.'))->display();
246 } elseif (!empty($cfg['UploadDir'])) {
247 echo PMA_Util
::getSelectUploadFileBlock($import_list, $cfg['UploadDir']);
248 } // end if (web-server upload directory)
252 <div
class="formelementrow" id
="charaset_of_file">
253 <?php
// charset of file
254 if ($GLOBALS['PMA_recoding_engine'] != PMA_CHARSET_NONE
) {
255 echo '<label for="charset_of_file">' . __('Character set of the file:') . '</label>';
256 reset($cfg['AvailableCharsets']);
257 echo '<select id="charset_of_file" name="charset_of_file" size="1">';
258 foreach ($cfg['AvailableCharsets'] as $temp_charset) {
259 echo '<option value="' . htmlentities($temp_charset) . '"';
260 if ((empty($cfg['Import']['charset']) && $temp_charset == 'utf-8')
261 ||
$temp_charset == $cfg['Import']['charset']
263 echo ' selected="selected"';
265 echo '>' . htmlentities($temp_charset) . '</option>';
267 echo ' </select><br />';
269 echo '<label for="charset_of_file">' . __('Character set of the file:') . '</label>' . "\n";
270 echo PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_CHARSET
, 'charset_of_file', 'charset_of_file', 'utf8', false);
271 } // end if (recoding)
275 <div
class="importoptions">
276 <h3
><?php
echo __('Partial Import:'); ?
></h3
>
279 if (isset($timeout_passed) && $timeout_passed) {
280 echo '<div class="formelementrow">' . "\n";
281 echo '<input type="hidden" name="skip" value="' . $offset . '" />';
282 echo sprintf(__('Previous import timed out, after resubmitting will continue from position %d.'), $offset) . '';
283 echo '</div>' . "\n";
286 <div
class="formelementrow">
287 <input type
="checkbox" name
="allow_interrupt" value
="yes"
288 id
="checkbox_allow_interrupt" <?php
echo PMA_pluginCheckboxCheck('Import', 'allow_interrupt'); ?
>/>
289 <label
for="checkbox_allow_interrupt"><?php
echo __('Allow the interruption of an import in case the script detects it is close to the PHP timeout limit. <i>(This might be a good way to import large files, however it can break transactions.)</i>'); ?
></label
><br
/>
293 if (! (isset($timeout_passed) && $timeout_passed)) {
295 <div
class="formelementrow">
296 <label
for="text_skip_queries"><?php
echo __('Number of rows to skip, starting from the first row:'); ?
></label
>
297 <input type
="text" name
="skip_queries" value
="<?php echo PMA_pluginGetDefault('Import', 'skip_queries');?>" id
="text_skip_queries" />
301 // If timeout has passed,
302 // do not show the Skip dialog to avoid the risk of someone
303 // entering a value here that would interfere with "skip"
305 <input type
="hidden" name
="skip_queries" value
="<?php echo PMA_pluginGetDefault('Import', 'skip_queries');?>" id
="text_skip_queries" />
311 <div
class="importoptions">
312 <h3
><?php
echo __('Format:'); ?
></h3
>
313 <?php
echo PMA_pluginGetChoice('Import', 'format', $import_list); ?
>
314 <div id
="import_notification"></div
>
317 <div
class="importoptions" id
="format_specific_opts">
318 <h3
><?php
echo __('Format-Specific Options:'); ?
></h3
>
319 <p
class="no_js_msg" id
="scroll_to_options_msg">Scroll down to fill in the options
for the selected format
and ignore the options
for other formats
.</p
>
320 <?php
echo PMA_pluginGetOptions('Import', $import_list); ?
>
322 <div
class="clearfloat"></div
>
324 // Encoding setting form appended by Y.Kawada
325 if (function_exists('PMA_set_enc_form')) { ?
>
326 <div
class="importoptions" id
="kanji_encoding">
327 <h3
><?php
echo __('Encoding Conversion:'); ?
></h3
>
328 <?php
echo PMA_set_enc_form(' '); ?
>
334 <div
class="importoptions" id
="submit">
335 <input type
="submit" value
="<?php echo __('Go'); ?>" id
="buttonGo" />