From 53a0d5afd13db1cb50c0a22c015100c90dcb3f87 Mon Sep 17 00:00:00 2001 From: xmujay Date: Wed, 24 Jul 2013 22:52:30 +0800 Subject: [PATCH 01/14] refactor display_import.lib.php 1. render html at once 2. split js code --- js/display_import_no_plugin.js | 93 +++++++ libraries/display_import.lib.php | 399 +++++++++++++------------------ 2 files changed, 258 insertions(+), 234 deletions(-) create mode 100644 js/display_import_no_plugin.js diff --git a/js/display_import_no_plugin.js b/js/display_import_no_plugin.js new file mode 100644 index 0000000000..c88cdde127 --- /dev/null +++ b/js/display_import_no_plugin.js @@ -0,0 +1,93 @@ +/* vim: set expandtab sw=4 ts=4 sts=4: */ + +/** + * display import when no plugins loaded + */ + +var finished = false; +var percent = 0.0; +var total = 0; +var complete = 0; +var original_title = parent && parent.document ? parent.document.title : false; +var import_start; + +var perform_upload = function () { + new $.getJSON( + ajax_url, + {}, + function(response) { + finished = response.finished; + percent = response.percent; + total = response.total; + complete = response.complete; + + if (total==0 && complete==0 && percent==0) { + $('#upload_form_status_info').html('ajax clock ' + promotStr); + $('#upload_form_status').css("display", "none"); + } else { + var now = new Date(); + now = Date.UTC( + now.getFullYear(), now.getMonth(), now.getDate(), + now.getHours(), now.getMinutes(), now.getSeconds()) + + now.getMilliseconds() - 1000; + var statustext = $.sprintf(statustext_str, + formatBytes(complete, 1, PMA_messages.strDecimalSeparator), + formatBytes(total, 1, PMA_messages.strDecimalSeparator) + ); + + if ($('#importmain').is(':visible')) { + // show progress UI + $('#importmain').hide(); + $('#import_form_status') + .html('
ajax clock ' + import_str + '
') + .show(); + import_start = now; + } + else if (percent > 9 || complete > 2000000) { + // calculate estimated time + var used_time = now - import_start; + var seconds = parseInt(((total - complete) / complete) * used_time / 1000); + var speed = $.sprintf(second_str + , formatBytes(complete / used_time * 1000, 1, PMA_messages.strDecimalSeparator)); + + var minutes = parseInt(seconds / 60); + seconds %= 60; + var estimated_time; + if (minutes > 0) { + estimated_time = remaining_str1 + .replace('%MIN', minutes).replace('%SEC', seconds); + } + else { + estimated_time = remaining_str2 + .replace('%SEC', seconds); + } + + statustext += '
' + speed + '

' + estimated_time; + } + + var percent_str = Math.round(percent) + '%'; + $('#status').animate({width: percent_str}, 150); + $('.percentage').text(percent_str); + + // show percent in window title + if (original_title !== false) { + parent.document.title = percent_str + ' - ' + original_title; + } + else { + document.title = percent_str + ' - ' + original_title; + } + $('#statustext').html(statustext); + } // else + + if (finished == true) { + if (original_title !== false) { + parent.document.title = original_title; + } + else { + document.title = original_title; + } + $('#importmain').hide(); + $('#import_form_status') + .html('ajax clock' + proceed_str) + .show(); + $('#import_form_status').load('import_status.php?message=true&' + import_url); // loads the message, either success or mysql error diff --git a/libraries/display_import.lib.php b/libraries/display_import.lib.php index 252d2f6637..b0e2ebba9d 100644 --- a/libraries/display_import.lib.php +++ b/libraries/display_import.lib.php @@ -31,174 +31,101 @@ if (empty($import_list)) { )->display(); exit; } -?> - - -
- ajax clock - -
> - +$html .= ' class="ajax"'; +$html .= '>'; +$html .= ' '; + - '."\n"; - ?> +$html .= ' '."\n"; + +$html .= ' '; + +$html .= '
'; +$html .= '

' . __('File to Import:') . '

'; -
-

- '; + $html .= '
'; printf(__('File may be compressed (%s) or uncompressed.'), implode(", ", $compressions)); - echo '
'; - echo __('A compressed file\'s name must end in .[format].[compression]. Example: .sql.zip'); - echo '
'; -}?> + $html .= '
'; + $html .= __('A compressed file\'s name must end in .[format].[compression]. Example: .sql.zip'); + $html .= '
'; +} + +$html .= '
'; + +if ($GLOBALS['is_upload'] && !empty($cfg['UploadDir'])) { + $html .= '
    '; + $html .= '
  • '; + $html .= ' '; + + $html .= PMA_Util::getBrowseUploadFileBlock($max_upload_size); + + $html .= '
  • '; + $html .= '
  • '; + $html .= ' '; + + $html .= PMA_Util::getSelectUploadFileBlock($import_list, $cfg['UploadDir']); + + $html .= '
  • '; + $html .= '
'; -
- -
    -
  • - - -
  • -
  • - - -
  • -
- display(); } elseif (!empty($cfg['UploadDir'])) { - echo PMA_Util::getSelectUploadFileBlock($import_list, $cfg['UploadDir']); + $html .= PMA_Util::getSelectUploadFileBlock($import_list, $cfg['UploadDir']); } // end if (web-server upload directory) -?> -
-
- '; + +$html .= '
'; +// charset of file if ($GLOBALS['PMA_recoding_engine'] != PMA_CHARSET_NONE) { - echo ''; + $html .= ''; reset($cfg['AvailableCharsets']); - echo ''; foreach ($cfg['AvailableCharsets'] as $temp_charset) { - echo ''; + $html .= '>' . htmlentities($temp_charset) . ''; } - echo '
'; + $html .= '
'; } else { - echo '' . "\n"; - echo PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_CHARSET, 'charset_of_file', 'charset_of_file', 'utf8', false); + $html .= '' . "\n"; + $html .= PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_CHARSET, 'charset_of_file', 'charset_of_file', 'utf8', false); } // end if (recoding) - ?> -
-
-
-

- '; + $html .= '
'; + $html .= '
'; + $html .= '

' . __('Partial Import:') . '

'; + + if (isset($timeout_passed) && $timeout_passed) { - echo '
' . "\n"; - echo ''; - echo sprintf(__('Previous import timed out, after resubmitting will continue from position %d.'), $offset) . ''; - echo '
' . "\n"; + $html .= '
' . "\n"; + $html .= ''; + $html .= sprintf(__('Previous import timed out, after resubmitting will continue from position %d.'), $offset); + $html .= '
' . "\n"; } - ?> -
- /> -
-
- '; + $html .= ' '; + $html .= '
'; + $html .= '
'; + + if (! (isset($timeout_passed) && $timeout_passed)) { - ?> -
- - -
- '; + $html .= ' '; + $html .= ' '; + $html .= '
'; + } else { // If timeout has passed, // do not show the Skip dialog to avoid the risk of someone // entering a value here that would interfere with "skip" - ?> - - '; + } - ?> -
+ +$html .= '
'; -
-

- -
-
+$html .= '
'; +$html .= '

' . __('Format:') . '

'; +$html .= PMA_pluginGetChoice('Import', 'format', $import_list); +$html .= '
'; +$html .= '
'; + +$html .= '
'; +$html .= '

' . __('Format-Specific Options:') . '

'; +$html .= '

Scroll down to fill in the options for the selected format and ignore the options for other formats.

'; +$html .= PMA_pluginGetOptions('Import', $import_list); +$html .= '
'; +$html .= '
'; -
-

-

Scroll down to fill in the options for the selected format and ignore the options for other formats.

- -
-
- -
-

- -
- '; + $html .= '

' . __('Encoding Conversion:') . '

'; + $html .= PMA_Kanji_encodingForm(); + $html .= ' '; + } -echo "\n"; - ?> -
- -
- - +$html .= "\n"; + +$html .= '
'; +$html .= ' '; +$html .= '
'; +$html .= ''; +$html .= ''; + +$response = PMA_Response::getInstance(); +$response->addHTML(''); + +?> From 7cbc80d7495d3c3c7c3183c601dbd57a09fc490a Mon Sep 17 00:00:00 2001 From: xmujay Date: Thu, 25 Jul 2013 21:58:21 +0800 Subject: [PATCH 02/14] refactor the js --- js/display_import_no_plugin.js | 20 +++++++++--- libraries/display_import.lib.php | 53 +++++++++++--------------------- 2 files changed, 33 insertions(+), 40 deletions(-) diff --git a/js/display_import_no_plugin.js b/js/display_import_no_plugin.js index c88cdde127..721e419ec7 100644 --- a/js/display_import_no_plugin.js +++ b/js/display_import_no_plugin.js @@ -22,7 +22,7 @@ var perform_upload = function () { complete = response.complete; if (total==0 && complete==0 && percent==0) { - $('#upload_form_status_info').html('ajax clock ' + promotStr); + $('#upload_form_status_info').html('ajax clock ' + promot_str); $('#upload_form_status').css("display", "none"); } else { var now = new Date(); @@ -39,7 +39,7 @@ var perform_upload = function () { // show progress UI $('#importmain').hide(); $('#import_form_status') - .html('
ajax clock ' + import_str + '
') + .html('
ajax clock ' + upload_str + '
') .show(); import_start = now; } @@ -54,11 +54,11 @@ var perform_upload = function () { seconds %= 60; var estimated_time; if (minutes > 0) { - estimated_time = remaining_str1 + estimated_time = remaining_min .replace('%MIN', minutes).replace('%SEC', seconds); } else { - estimated_time = remaining_str2 + estimated_time = remaining_second .replace('%SEC', seconds); } @@ -88,6 +88,16 @@ var perform_upload = function () { } $('#importmain').hide(); $('#import_form_status') - .html('ajax clock' + proceed_str) + .html('ajax clock ' + processed_str) .show(); $('#import_form_status').load('import_status.php?message=true&' + import_url); // loads the message, either success or mysql error + + // reload the left sidebar when the import is finished + + } // if finished + else { + setTimeout(perform_upload, 1000); + } + }); +}; +setTimeout(perform_upload, 1000); \ No newline at end of file diff --git a/libraries/display_import.lib.php b/libraries/display_import.lib.php index b0e2ebba9d..0d75454a64 100644 --- a/libraries/display_import.lib.php +++ b/libraries/display_import.lib.php @@ -32,7 +32,7 @@ if (empty($import_list)) { exit; } -$html = ''; +$html = ''; $html .= ''; $html .= ''; $html .= '
'; @@ -47,39 +47,24 @@ $html .= ' '; - -$html .= '
'; - -if ($import_type == 'server') { - $html .= PMA_generate_common_hidden_inputs('', '', 1); -} elseif ($import_type == 'database') { - $html .= PMA_generate_common_hidden_inputs($db, '', 1); -} else { - $html .= PMA_generate_common_hidden_inputs($db, $table, 1); -} -$html .= ' '."\n"; - -$html .= ' '; - -$html .= '
'; -$html .= '

' . __('File to Import:') . '

'; - -// zip, gzip and bzip2 encode features -$compressions = array(); - -if ($cfg['GZipDump'] && @function_exists('gzopen')) { - $compressions[] = 'gzip'; -} -if ($cfg['BZipDump'] && @function_exists('bzopen')) { - $compressions[] = 'bzip2'; -} -if ($cfg['ZipDump'] && @function_exists('zip_open')) { - $compressions[] = 'zip'; -} -// We don't have show anything about compression, when no supported -if ($compressions != array()) { - $html .= '
'; - $compress_str = sprintf(__('File may be compressed (%s) or uncompressed.'), implode(", ", $compressions)); - $html .= $compress_str; - $html .= '
'; - $html .= __('A compressed file\'s name must end in .[format].[compression]. Example: .sql.zip'); - $html .= '
'; -} - -$html .= '
'; - -if ($GLOBALS['is_upload'] && !empty($cfg['UploadDir'])) { - $html .= '
    '; - $html .= '
  • '; - $html .= ' '; - - $html .= PMA_Util::getBrowseUploadFileBlock($max_upload_size); - - $html .= '
  • '; - $html .= '
  • '; - $html .= ' '; - - $html .= PMA_Util::getSelectUploadFileBlock($import_list, $cfg['UploadDir']); - - $html .= '
  • '; - $html .= '
'; - -} elseif ($GLOBALS['is_upload']) { - $uid = uniqid(''); - $html .= PMA_Util::getBrowseUploadFileBlock($max_upload_size); -} elseif (!$GLOBALS['is_upload']) { - $html .= PMA_Message::notice(__('File uploads are not allowed on this server.'))->getDisplay(); -} elseif (!empty($cfg['UploadDir'])) { - $html .= PMA_Util::getSelectUploadFileBlock($import_list, $cfg['UploadDir']); -} // end if (web-server upload directory) - -$html .= '
'; - -$html .= '
'; -// charset of file -if ($GLOBALS['PMA_recoding_engine'] != PMA_CHARSET_NONE) { - $html .= ''; - reset($cfg['AvailableCharsets']); - $html .= '
'; -} else { - $html .= '' . "\n"; - $html .= PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_CHARSET, 'charset_of_file', 'charset_of_file', 'utf8', false); -} // end if (recoding) + $html .= ' '."\n"; -$html .= '
'; -$html .= '
'; -$html .= '
'; -$html .= '

' . __('Partial Import:') . '

'; - -if (isset($timeout_passed) && $timeout_passed) { - $html .= '
' . "\n"; - $html .= ''; - $html .= sprintf(__('Previous import timed out, after resubmitting will continue from position %d.'), $offset); - $html .= '
' . "\n"; + return $html; } -$html .= '
'; -$html .= ' '; -$html .= '
'; -$html .= '
'; +/** + * Prints Html For Import Javascript + * + * @param int upload_id The selected upload id + * + * @return string + */ +function PMA_getHtmlForImportJS($upload_id) +{ + $html = ''; + $html .= ' '; + + return $html; +} + +/** + * Prints Html For Display Export options + * + * @param String $import_type Import type: server, database, table + * @param String $db Selected DB + * @param String $table Selected Table + * + * @return string + */ +function PMA_getHtmlForExportOptions($import_type, $db, $table) +{ + $html = ' '; + + return $html; +} + +/** + * Prints Html For Display Import options : Compressions + * + * @return string + */ +function PMA_getHtmlForImportCompressions() +{ + global $cfg; + $html = ''; + // zip, gzip and bzip2 encode features + $compressions = array(); + + if ($cfg['GZipDump'] && @function_exists('gzopen')) { + $compressions[] = 'gzip'; + } + if ($cfg['BZipDump'] && @function_exists('bzopen')) { + $compressions[] = 'bzip2'; + } + if ($cfg['ZipDump'] && @function_exists('zip_open')) { + $compressions[] = 'zip'; + } + // We don't have show anything about compression, when no supported + if ($compressions != array()) { + $html .= '
'; + $compress_str = sprintf(__('File may be compressed (%s) or uncompressed.'), implode(", ", $compressions)); + $html .= $compress_str; + $html .= '
'; + $html .= __('A compressed file\'s name must end in .[format].[compression]. Example: .sql.zip'); + $html .= '
'; + } + + return $html; +} + +/** + * Prints Html For Display Import charset + * + * @return string + */ +function PMA_getHtmlForImportCharset() +{ + global $cfg; + $html = '
'; + // charset of file + if ($GLOBALS['PMA_recoding_engine'] != PMA_CHARSET_NONE) { + $html .= ''; + reset($cfg['AvailableCharsets']); + $html .= '
'; + } else { + $html .= '' . "\n"; + $html .= PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_CHARSET, 'charset_of_file', 'charset_of_file', 'utf8', false); + } // end if (recoding) + + $html .= '
'; + + return $html; +} + +/** + * Prints Html For Display Import options : file property + * + * @param int $max_upload_size Max upload size + * @param Array $import_list import list + * + * @return string + */ +function PMA_getHtmlForImportOptionsFile($max_upload_size, $import_list) +{ + global $cfg; + $html = '
'; + $html .= '

' . __('File to Import:') . '

'; + $html .= PMA_getHtmlForImportCompressions(); + $html .= '
'; + + if ($GLOBALS['is_upload'] && !empty($cfg['UploadDir'])) { + $html .= '
    '; + $html .= '
  • '; + $html .= ' '; + $html .= PMA_Util::getBrowseUploadFileBlock($max_upload_size); + $html .= '
  • '; + $html .= '
  • '; + $html .= ' '; + $html .= PMA_Util::getSelectUploadFileBlock($import_list, $cfg['UploadDir']); + $html .= '
  • '; + $html .= '
'; + + } elseif ($GLOBALS['is_upload']) { + $uid = uniqid(''); + $html .= PMA_Util::getBrowseUploadFileBlock($max_upload_size); + } elseif (!$GLOBALS['is_upload']) { + $html .= PMA_Message::notice(__('File uploads are not allowed on this server.'))->getDisplay(); + } elseif (!empty($cfg['UploadDir'])) { + $html .= PMA_Util::getSelectUploadFileBlock($import_list, $cfg['UploadDir']); + } // end if (web-server upload directory) + + $html .= '
'; + $html .= PMA_getHtmlForImportCharset(); + $html .= '
'; + + return $html; +} + +/** + * Prints Html For Display Import options : Partial Import + * + * @param String $timeout_passed timeout passed + * @param String $offset timeout offset + * + * @return string + */ +function PMA_getHtmlForImportOptionsPartialImport($timeout_passed, $offset) +{ + $html = '
'; + $html .= '

' . __('Partial Import:') . '

'; + + if (isset($timeout_passed) && $timeout_passed) { + $html .= '
' . "\n"; + $html .= ''; + $html .= sprintf(__('Previous import timed out, after resubmitting will continue from position %d.'), $offset); + $html .= '
' . "\n"; + } - -if (! (isset($timeout_passed) && $timeout_passed)) { $html .= '
'; - $html .= ' '; - $html .= ' '; + $html .= ' '; + $html .= '
'; $html .= '
'; -} else { - // If timeout has passed, - // do not show the Skip dialog to avoid the risk of someone - // entering a value here that would interfere with "skip" - $html .= ' '; + if (! (isset($timeout_passed) && $timeout_passed)) { + $html .= '
'; + $html .= ' '; + $html .= ' '; + $html .= '
'; + + } else { + // If timeout has passed, + // do not show the Skip dialog to avoid the risk of someone + // entering a value here that would interfere with "skip" + $html .= ' '; + } + + $html .= '
'; + + return $html; } - -$html .= '
'; -$html .= '
'; -$html .= '

' . __('Format:') . '

'; -$html .= PMA_pluginGetChoice('Import', 'format', $import_list); -$html .= '
'; -$html .= '
'; - -$html .= '
'; -$html .= '

' . __('Format-Specific Options:') . '

'; -$html .= '

Scroll down to fill in the options for the selected format and ignore the options for other formats.

'; -$html .= PMA_pluginGetOptions('Import', $import_list); -$html .= '
'; -$html .= '
'; +/** + * Prints Html For Display Import options : Format + * + * @param Array $import_list import list + * + * @return string + */ +function PMA_getHtmlForImportOptionsFormat($import_list) +{ + $html = '
'; + $html .= '

' . __('Format:') . '

'; + $html .= PMA_pluginGetChoice('Import', 'format', $import_list); + $html .= '
'; + $html .= '
'; -// Encoding setting form appended by Y.Kawada -if (function_exists('PMA_Kanji_encodingForm')) { - $html .= '
'; - $html .= '

' . __('Encoding Conversion:') . '

'; - $html .= PMA_Kanji_encodingForm(); - $html .= '
'; + $html .= '
'; + $html .= '

' . __('Format-Specific Options:') . '

'; + $html .= '

Scroll down to fill in the options for the selected format and ignore the options for other formats.

'; + $html .= PMA_pluginGetOptions('Import', $import_list); + $html .= '
'; + $html .= '
'; + // Encoding setting form appended by Y.Kawada + if (function_exists('PMA_Kanji_encodingForm')) { + $html .= '
'; + $html .= '

' . __('Encoding Conversion:') . '

'; + $html .= PMA_Kanji_encodingForm(); + $html .= '
'; + + } + $html .= "\n"; + + return $html; } -$html .= "\n"; -$html .= '
'; -$html .= ' '; -$html .= '
'; -$html .= '
'; -$html .= '
'; +/** + * Prints Html For Display Import options : submit + * + * @return string + */ +function PMA_getHtmlForImportOptionsSubmit() +{ + $html = '
'; + $html .= ' '; + $html .= '
'; -$response = PMA_Response::getInstance(); -$response->addHTML($html); + return $html; +} +/** + * Prints Html For Display Import + * + * @param int $upload_id The selected upload id + * @param String $import_type Import type: server, database, table + * @param String $db Selected DB + * @param String $table Selected Table + * @param int $max_upload_size Max upload size + * @param Array $import_list Import list + * @param String $timeout_passed Timeout passed + * @param String $offset Timeout offset + * + * @return string + */ +function PMA_getHtmlForImport( + $upload_id, $import_type, $db, $table, + $max_upload_size, $import_list, $timeout_passed, $offset +) { + $html = ''; + $html .= ''; + $html .= ''; + $html .= '
'; + $html .= ' ajax clock'; + $html .= PMA_getHtmlForImportJS($upload_id); + + $html .= '
'; + + $html .= PMA_getHtmlForHiddenInput($import_type, $db, $table); + + $html .= PMA_getHtmlForExportOptions($import_type, $db, $table); + + $html .= PMA_getHtmlForImportOptionsFile($max_upload_size, $import_list); + + $html .= PMA_getHtmlForImportOptionsPartialImport($timeout_passed, $offset); + + $html .= PMA_getHtmlForImportOptionsFormat($import_list); + + $html .= PMA_getHtmlForImportOptionsSubmit(); + + $html .= '
'; + $html .= '
'; + + return $html; +} ?> diff --git a/server_import.php b/server_import.php index 2a7d38f7df..b2fbac7a88 100644 --- a/server_import.php +++ b/server_import.php @@ -21,7 +21,7 @@ $scripts->addFile('import.js'); require 'libraries/server_common.inc.php'; $import_type = 'server'; -require 'libraries/display_import.lib.php'; +require 'libraries/display_import.inc.php'; ?> diff --git a/tbl_import.php b/tbl_import.php index 9c399e0bd6..b255ccd48d 100644 --- a/tbl_import.php +++ b/tbl_import.php @@ -24,7 +24,7 @@ $url_query .= '&goto=tbl_import.php&back=tbl_import.php'; require_once 'libraries/tbl_info.inc.php'; $import_type = 'table'; -require_once 'libraries/display_import.lib.php'; +require_once 'libraries/display_import.inc.php'; ?> From 3901ef3b64e8dc74221416e9d4f83fa3093f6767 Mon Sep 17 00:00:00 2001 From: xmujay Date: Sat, 27 Jul 2013 19:17:51 +0800 Subject: [PATCH 07/14] fix the code style of display_import.lib.php --- libraries/display_import.lib.php | 149 +++++++++++++++++++++++-------- 1 file changed, 112 insertions(+), 37 deletions(-) diff --git a/libraries/display_import.lib.php b/libraries/display_import.lib.php index 96977c5862..24691ee248 100644 --- a/libraries/display_import.lib.php +++ b/libraries/display_import.lib.php @@ -31,7 +31,8 @@ function PMA_getHtmlForHiddenInput($import_type, $db, $table) } else { $html .= PMA_generate_common_hidden_inputs($db, $table, 1); } - $html .= ' '."\n"; + $html .= ' '."\n"; return $html; } @@ -39,7 +40,7 @@ function PMA_getHtmlForHiddenInput($import_type, $db, $table) /** * Prints Html For Import Javascript * - * @param int upload_id The selected upload id + * @param int $upload_id The selected upload id * * @return string */ @@ -51,30 +52,57 @@ function PMA_getHtmlForImportJS($upload_id) $html .= ' $( function() {'; $html .= ' // add event when user click on "Go" button'; $html .= ' $("#buttonGo").bind("click", function() {'; - $html .= ' $("#upload_form_form").css("display", "none");'; - $html .= ' $("#upload_form_status").css("display", "inline");'; - $html .= ' $("#upload_form_status_info").css("display", "inline");'; + $html .= ' $("#upload_form_form").css("display", "none");'; + $html .= ' $("#upload_form_status").css("display", "inline");'; + $html .= ' $("#upload_form_status_info").css("display", "inline");'; if ($_SESSION[$SESSION_KEY]["handler"] != "UploadNoplugin") { //output for javascript variable - $ajax_url = "import_status.php?id=" . $upload_id . "&" . PMA_generate_common_url(array('import_status'=>1), '&'); + $ajax_url = "import_status.php?id=" . $upload_id . "&" + . PMA_generate_common_url(array('import_status'=>1), '&'); $html .= " var ajax_url ='" . $ajax_url + "';"; $html .= " var pmaThemeImage ='" . $GLOBALS['pmaThemeImage'] + "';"; - $html .= " var promot_str ='" . 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) + "';"; - $html .= " var statustext_str ='" . PMA_escapeJsString(__('%s of %s')) + "';"; - $html .= " var upload_str ='" . PMA_jsFormat(__('Uploading your import file...'), false) + "';"; - $html .= " var second_str ='" . PMA_jsFormat(__('%s/sec.'), false) + "';"; - $html .= " var remaining_min ='" . PMA_jsFormat(__('About %MIN min. %SEC sec. remaining.'), false) + "';"; - $html .= " var remaining_second ='" . PMA_jsFormat(__('About %SEC sec. remaining.'), false) + "';"; - $html .= " var processed_str ='" . PMA_jsFormat(__('The file is being processed, please be patient.'), false) + "';"; - $html .= " var import_url ='" . PMA_generate_common_url(array('import_status'=>1), '&') + "';"; + $html .= " var promot_str ='" + . 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 + ) + "';"; + $html .= " var statustext_str ='" + . PMA_escapeJsString(__('%s of %s')) + "';"; + $html .= " var upload_str ='" + . PMA_jsFormat(__('Uploading your import file...'), false) + "';"; + $html .= " var second_str ='" + . PMA_jsFormat(__('%s/sec.'), false) + "';"; + $html .= " var remaining_min ='" + . PMA_jsFormat(__('About %MIN min. %SEC sec. remaining.'), false) + "';"; + $html .= " var remaining_second ='" + . PMA_jsFormat(__('About %SEC sec. remaining.'), false) + "';"; + $html .= " var processed_str ='" + . PMA_jsFormat( + __('The file is being processed, please be patient.'), + false + ) + "';"; + $html .= " var import_url ='" + . PMA_generate_common_url(array('import_status'=>1), '&') + "';"; $html .= " $.include('./js/display_import_no_plugin.js'); "; } else { // no plugin available - $image_tag = 'ajax clock ' . PMA_jsFormat(__('Please be patient, the file is being uploaded. Details about the upload are not available.'), false) . PMA_Util::showDocu('faq', 'faq2-9'); - $html .= ' $("#upload_form_status_info").html("' . $image_tag + '");'; - $html .= ' $("#upload_form_status").css("display", "none");'; + $image_tag = 'ajax clock ' + . PMA_jsFormat( + __( + 'Please be patient, the file is being uploaded. ' + . 'Details about the upload are not available.' + ), + false + ) . PMA_Util::showDocu('faq', 'faq2-9'); + $html .= ' $("#upload_form_status_info").html("' . $image_tag + '");'; + $html .= ' $("#upload_form_status").css("display", "none");'; } // else $html .= ' }); // onclick'; @@ -103,10 +131,16 @@ function PMA_getHtmlForExportOptions($import_type, $db, $table) if ($import_type == 'server') { $html .= __('Importing into the current server'); } elseif ($import_type == 'database') { - $import_str = sprintf(__('Importing into the database "%s"'), htmlspecialchars($db)); + $import_str = sprintf( + __('Importing into the database "%s"'), + htmlspecialchars($db) + ); $html .= $import_str; } else { - $import_str = printf(__('Importing into the table "%s"'), htmlspecialchars($table)); + $import_str = printf( + __('Importing into the table "%s"'), + htmlspecialchars($table) + ); $html .= $import_str; } $html .= ' '; @@ -139,10 +173,16 @@ function PMA_getHtmlForImportCompressions() // We don't have show anything about compression, when no supported if ($compressions != array()) { $html .= '
'; - $compress_str = sprintf(__('File may be compressed (%s) or uncompressed.'), implode(", ", $compressions)); + $compress_str = sprintf( + __('File may be compressed (%s) or uncompressed.'), + implode(", ", $compressions) + ); $html .= $compress_str; $html .= '
'; - $html .= __('A compressed file\'s name must end in .[format].[compression]. Example: .sql.zip'); + $html .= __( + 'A compressed file\'s name must end in .[format].[compression]. ' + . 'Example: .sql.zip' + ); $html .= '
'; } @@ -160,7 +200,8 @@ function PMA_getHtmlForImportCharset() $html = '
'; // charset of file if ($GLOBALS['PMA_recoding_engine'] != PMA_CHARSET_NONE) { - $html .= ''; + $html .= ''; reset($cfg['AvailableCharsets']); $html .= '
'; } else { - $html .= '' . "\n"; - $html .= PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_CHARSET, 'charset_of_file', 'charset_of_file', 'utf8', false); + $html .= '' . "\n"; + $html .= PMA_generateCharsetDropdownBox( + PMA_CSDROPDOWN_CHARSET, + 'charset_of_file', + 'charset_of_file', + 'utf8', + false + ); } // end if (recoding) $html .= '
'; @@ -202,11 +250,13 @@ function PMA_getHtmlForImportOptionsFile($max_upload_size, $import_list) if ($GLOBALS['is_upload'] && !empty($cfg['UploadDir'])) { $html .= '
    '; $html .= '
  • '; - $html .= ' '; + $html .= ' '; $html .= PMA_Util::getBrowseUploadFileBlock($max_upload_size); $html .= '
  • '; $html .= '
  • '; - $html .= ' '; + $html .= ' '; $html .= PMA_Util::getSelectUploadFileBlock($import_list, $cfg['UploadDir']); $html .= '
  • '; $html .= '
'; @@ -215,7 +265,9 @@ function PMA_getHtmlForImportOptionsFile($max_upload_size, $import_list) $uid = uniqid(''); $html .= PMA_Util::getBrowseUploadFileBlock($max_upload_size); } elseif (!$GLOBALS['is_upload']) { - $html .= PMA_Message::notice(__('File uploads are not allowed on this server.'))->getDisplay(); + $html .= PMA_Message::notice( + __('File uploads are not allowed on this server.') + )->getDisplay(); } elseif (!empty($cfg['UploadDir'])) { $html .= PMA_Util::getSelectUploadFileBlock($import_list, $cfg['UploadDir']); } // end if (web-server upload directory) @@ -243,27 +295,45 @@ function PMA_getHtmlForImportOptionsPartialImport($timeout_passed, $offset) if (isset($timeout_passed) && $timeout_passed) { $html .= '
' . "\n"; $html .= ''; - $html .= sprintf(__('Previous import timed out, after resubmitting will continue from position %d.'), $offset); + $html .= sprintf( + __( + 'Previous import timed out, after resubmitting ' + . 'will continue from position %d.' + ), + $offset + ); $html .= '
' . "\n"; } $html .= '
'; $html .= ' '; - $html .= '
'; + $html .= ' id="checkbox_allow_interrupt" ' + . PMA_pluginCheckboxCheck('Import', 'allow_interrupt') . '/>'; + $html .= '
'; $html .= '
'; if (! (isset($timeout_passed) && $timeout_passed)) { $html .= '
'; - $html .= ' '; - $html .= ' '; + $html .= ' '; + $html .= ' '; $html .= '
'; } else { // If timeout has passed, // do not show the Skip dialog to avoid the risk of someone // entering a value here that would interfere with "skip" - $html .= ' '; + $html .= ' '; } $html .= ' '; @@ -288,7 +358,9 @@ function PMA_getHtmlForImportOptionsFormat($import_list) $html .= '
'; $html .= '

' . __('Format-Specific Options:') . '

'; - $html .= '

Scroll down to fill in the options for the selected format and ignore the options for other formats.

'; + $html .= '

' + . 'Scroll down to fill in the options for the selected format ' + . 'and ignore the options for other formats.

'; $html .= PMA_pluginGetOptions('Import', $import_list); $html .= '
'; $html .= '
'; @@ -338,14 +410,17 @@ function PMA_getHtmlForImport( $max_upload_size, $import_list, $timeout_passed, $offset ) { $html = ''; - $html .= ''; + $html .= ''; $html .= ''; $html .= '
'; - $html .= ' ajax clock'; + $html .= ' ajax clock'; $html .= PMA_getHtmlForImportJS($upload_id); - $html .= '
Date: Sat, 27 Jul 2013 19:30:31 +0800 Subject: [PATCH 08/14] fix SESSION_KEY --- libraries/display_import.inc.php | 1 + libraries/display_import.lib.php | 2 ++ 2 files changed, 3 insertions(+) diff --git a/libraries/display_import.inc.php b/libraries/display_import.inc.php index 6bc89555ca..0d5d58cee2 100644 --- a/libraries/display_import.inc.php +++ b/libraries/display_import.inc.php @@ -15,6 +15,7 @@ if (! defined('PHPMYADMIN')) { */ require_once './libraries/file_listing.lib.php'; require_once './libraries/plugin_interface.lib.php'; +require_once './libraries/display_import.lib.php'; require_once './libraries/display_import_ajax.lib.php'; /* Scan for plugins */ diff --git a/libraries/display_import.lib.php b/libraries/display_import.lib.php index 24691ee248..781435958b 100644 --- a/libraries/display_import.lib.php +++ b/libraries/display_import.lib.php @@ -46,6 +46,7 @@ function PMA_getHtmlForHiddenInput($import_type, $db, $table) */ function PMA_getHtmlForImportJS($upload_id) { + global $SESSION_KEY; $html = ''; $html .= ' '; return $html; @@ -392,6 +396,7 @@ function PMA_getHtmlForImportOptionsSubmit() return $html; } + /** * Prints Html For Display Import * @@ -433,7 +438,7 @@ function PMA_getHtmlForImport( $html .= $_SESSION[$SESSION_KEY]['handler']::getIdKey(); $html .= '" value="' . $upload_id . '" />'; - $html .= PMA_getHtmlForHiddenInput($import_type, $db, $table); + $html .= PMA_getHtmlForHiddenInputs($import_type, $db, $table); $html .= PMA_getHtmlForExportOptions($import_type, $db, $table); From a1c024737999da85231d86c63ed4b73cf81ef813 Mon Sep 17 00:00:00 2001 From: xmujay Date: Sun, 28 Jul 2013 00:20:04 +0800 Subject: [PATCH 10/14] 1. fix table name after import table 2. using jquery getScript to load js file --- libraries/display_import.lib.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/display_import.lib.php b/libraries/display_import.lib.php index 57e5985afe..e1e96378f3 100644 --- a/libraries/display_import.lib.php +++ b/libraries/display_import.lib.php @@ -92,7 +92,7 @@ function PMA_getHtmlForImportJS($upload_id) $html .= " var import_url ='" . PMA_generate_common_url(array('import_status'=>1), '&') . "';"; - $html .= " $.include('./js/display_import_no_plugin.js'); "; + $html .= " $.getScript('./js/display_import_no_plugin.js'); "; } else { // no plugin available $image_tag = ' Date: Sun, 28 Jul 2013 09:58:13 +0800 Subject: [PATCH 11/14] render javascript on display_import.lib.php or the out variable can't be used --- js/display_import_no_plugin.js | 101 ------------- libraries/display_import.lib.php | 249 ++++++++++++++++++++++--------- 2 files changed, 182 insertions(+), 168 deletions(-) delete mode 100644 js/display_import_no_plugin.js diff --git a/js/display_import_no_plugin.js b/js/display_import_no_plugin.js deleted file mode 100644 index 8eea290179..0000000000 --- a/js/display_import_no_plugin.js +++ /dev/null @@ -1,101 +0,0 @@ -/* vim: set expandtab sw=4 ts=4 sts=4: */ - -/** - * display import when no plugins loaded - */ - -var finished = false; -var percent = 0.0; -var total = 0; -var complete = 0; -var original_title = parent && parent.document ? parent.document.title : false; -var import_start; - -var perform_upload = function () { - new $.getJSON( - ajax_url, - {}, - function(response) { - finished = response.finished; - percent = response.percent; - total = response.total; - complete = response.complete; - - if (total==0 && complete==0 && percent==0) { - $('#upload_form_status_info').html('ajax clock ' + promot_str); - $('#upload_form_status').css("display", "none"); - } else { - var now = new Date(); - now = Date.UTC( - now.getFullYear(), now.getMonth(), now.getDate(), - now.getHours(), now.getMinutes(), now.getSeconds()) - + now.getMilliseconds() - 1000; - var statustext = $.sprintf(statustext_str, - formatBytes(complete, 1, PMA_messages.strDecimalSeparator), - formatBytes(total, 1, PMA_messages.strDecimalSeparator) - ); - - if ($('#importmain').is(':visible')) { - // show progress UI - $('#importmain').hide(); - $('#import_form_status') - .html('
ajax clock ' + upload_str + '
') - .show(); - import_start = now; - } - else if (percent > 9 || complete > 2000000) { - // calculate estimated time - var used_time = now - import_start; - var seconds = parseInt(((total - complete) / complete) * used_time / 1000); - var speed = $.sprintf(second_str - , formatBytes(complete / used_time * 1000, 1, PMA_messages.strDecimalSeparator)); - - var minutes = parseInt(seconds / 60); - seconds %= 60; - var estimated_time; - if (minutes > 0) { - estimated_time = remaining_min - .replace('%MIN', minutes).replace('%SEC', seconds); - } - else { - estimated_time = remaining_second - .replace('%SEC', seconds); - } - - statustext += '
' + speed + '

' + estimated_time; - } - - var percent_str = Math.round(percent) + '%'; - $('#status').animate({width: percent_str}, 150); - $('.percentage').text(percent_str); - - // show percent in window title - if (original_title !== false) { - parent.document.title = percent_str + ' - ' + original_title; - } - else { - document.title = percent_str + ' - ' + original_title; - } - $('#statustext').html(statustext); - } // else - - if (finished == true) { - if (original_title !== false) { - parent.document.title = original_title; - } - else { - document.title = original_title; - } - $('#importmain').hide(); - $('#import_form_status') - .html('ajax clock ' + processed_str) - .show(); - $('#import_form_status').load('import_status.php?message=true&' + import_url); // loads the message, either success or mysql error - - } // if finished - else { - setTimeout(perform_upload, 1000); - } - }); -}; -setTimeout(perform_upload, 1000); \ No newline at end of file diff --git a/libraries/display_import.lib.php b/libraries/display_import.lib.php index e1e96378f3..7d7acfc5dc 100644 --- a/libraries/display_import.lib.php +++ b/libraries/display_import.lib.php @@ -2,13 +2,13 @@ /* vim: set expandtab sw=4 ts=4 sts=4: */ /** - * functions for displaying import for: server, database and table + * functions for displaying import for: server, database and table * * @usedby display_import.inc.php * * @package PhpMyAdmin */ - + if (! defined('PHPMYADMIN')) { exit; } @@ -32,7 +32,7 @@ function PMA_getHtmlForHiddenInputs($import_type, $db, $table) } else { $html .= PMA_generate_common_hidden_inputs($db, $table, 1); } - $html .= ' '."\n"; return $html; @@ -60,48 +60,17 @@ function PMA_getHtmlForImportJS($upload_id) $html .= ' $("#upload_form_status_info").css("display", "inline");'; if ($_SESSION[$SESSION_KEY]["handler"] != "UploadNoplugin") { - //output for javascript variable - $ajax_url = "import_status.php?id=" . $upload_id . "&" - . PMA_generate_common_url(array('import_status'=>1), '&'); - $html .= " var ajax_url ='" . $ajax_url . "';"; - $html .= " var pmaThemeImage ='" . $GLOBALS['pmaThemeImage'] . "';"; - $html .= " var promot_str ='" - . 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 - ) . "';"; - $html .= " var statustext_str ='" - . PMA_escapeJsString(__('%s of %s')) . "';"; - $html .= " var upload_str ='" - . PMA_jsFormat(__('Uploading your import file...'), false) . "';"; - $html .= " var second_str ='" - . PMA_jsFormat(__('%s/sec.'), false) . "';"; - $html .= " var remaining_min ='" - . PMA_jsFormat(__('About %MIN min. %SEC sec. remaining.'), false) . "';"; - $html .= " var remaining_second ='" - . PMA_jsFormat(__('About %SEC sec. remaining.'), false) . "';"; - $html .= " var processed_str ='" - . PMA_jsFormat( - __('The file is being processed, please be patient.'), - false - ) . "';"; - $html .= " var import_url ='" - . PMA_generate_common_url(array('import_status'=>1), '&') . "';"; - $html .= " $.getScript('./js/display_import_no_plugin.js'); "; + $html .= PMA_getHtmlForImportNoPlugin($upload_id); } else { // no plugin available - $image_tag = 'ajax clock ' + $image_tag = 'ajax clock ' . PMA_jsFormat( __( - 'Please be patient, the file is being uploaded. ' + 'Please be patient, the file is being uploaded. ' . 'Details about the upload are not available.' - ), + ), false ) . PMA_Util::showDocu('faq', 'faq2-9'); $html .= " $('#upload_form_status_info').html('" . $image_tag . "');"; @@ -137,13 +106,13 @@ function PMA_getHtmlForExportOptions($import_type, $db, $table) $html .= __('Importing into the current server'); } elseif ($import_type == 'database') { $import_str = sprintf( - __('Importing into the database "%s"'), + __('Importing into the database "%s"'), htmlspecialchars($db) ); $html .= $import_str; } else { $import_str = sprintf( - __('Importing into the table "%s"'), + __('Importing into the table "%s"'), htmlspecialchars($table) ); $html .= $import_str; @@ -179,13 +148,13 @@ function PMA_getHtmlForImportCompressions() if ($compressions != array()) { $html .= '
'; $compress_str = sprintf( - __('File may be compressed (%s) or uncompressed.'), + __('File may be compressed (%s) or uncompressed.'), implode(", ", $compressions) ); $html .= $compress_str; $html .= '
'; $html .= __( - 'A compressed file\'s name must end in .[format].[compression]. ' + 'A compressed file\'s name must end in .[format].[compression]. ' . 'Example: .sql.zip' ); $html .= '
'; @@ -205,7 +174,7 @@ function PMA_getHtmlForImportCharset() $html = '
'; // charset of file if ($GLOBALS['PMA_recoding_engine'] != PMA_CHARSET_NONE) { - $html .= '
' . "\n"; @@ -312,22 +281,22 @@ function PMA_getHtmlForImportOptionsPartialImport($timeout_passed, $offset) $html .= '
'; $html .= ' '; - $html .= '
'; if (! (isset($timeout_passed) && $timeout_passed)) { $html .= '
'; - $html .= '
'; @@ -336,8 +305,8 @@ function PMA_getHtmlForImportOptionsPartialImport($timeout_passed, $offset) // If timeout has passed, // do not show the Skip dialog to avoid the risk of someone // entering a value here that would interfere with "skip" - $html .= ' '; } @@ -363,8 +332,8 @@ function PMA_getHtmlForImportOptionsFormat($import_list) $html .= '
'; $html .= '

' . __('Format-Specific Options:') . '

'; - $html .= '

' - . 'Scroll down to fill in the options for the selected format ' + $html .= '

' + . 'Scroll down to fill in the options for the selected format ' . 'and ignore the options for other formats.

'; $html .= PMA_pluginGetOptions('Import', $import_list); $html .= '
'; @@ -417,16 +386,16 @@ function PMA_getHtmlForImport( ) { global $SESSION_KEY; $html = ''; - $html .= ''; $html .= ''; $html .= '
'; - $html .= ' ajax clock'; $html .= PMA_getHtmlForImportJS($upload_id); - $html .= ' 1), '&'); + $promot_str = 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 + ); + $statustext_str = PMA_escapeJsString(__('%s of %s')); + $upload_str = PMA_jsFormat(__('Uploading your import file...'), false); + $second_str = PMA_jsFormat(__('%s/sec.'), false); + $remaining_min = PMA_jsFormat(__('About %MIN min. %SEC sec. remaining.'), false); + $remaining_second = PMA_jsFormat(__('About %SEC sec. remaining.'), false); + $processed_str = PMA_jsFormat( + __('The file is being processed, please be patient.'), + false + ); + $import_url = PMA_generate_common_url(array('import_status'=>1), '&'); + + //start output + $html = 'var finished = false; '; + $html .= 'var percent = 0.0; '; + $html .= 'var total = 0; '; + $html .= 'var complete = 0; '; + $html .= 'var original_title = ' + . 'parent && parent.document ? parent.document.title : false; '; + $html .= 'var import_start; '; + + $html .= 'var perform_upload = function () { '; + $html .= 'new $.getJSON( '; + $html .= ' "' . $ajax_url . '", '; + $html .= ' {}, '; + $html .= ' function(response) { '; + $html .= ' finished = response.finished; '; + $html .= ' percent = response.percent; '; + $html .= ' total = response.total; '; + $html .= ' complete = response.complete; '; + + $html .= ' if (total==0 && complete==0 && percent==0) { '; + $img_tag = 'ajax clock ' + . $promot_str . '\'); '; + $html .= ' $("#upload_form_status").css("display", "none"); '; + $html .= ' } else { '; + $html .= ' var now = new Date(); '; + $html .= ' now = Date.UTC( '; + $html .= ' now.getFullYear(), now.getMonth(), now.getDate(), '; + $html .= ' now.getHours(), now.getMinutes(), now.getSeconds()) '; + $html .= ' + now.getMilliseconds() - 1000; '; + $html .= ' var statustext = $.sprintf("' . $statustext_str . '", '; + $html .= ' formatBytes(complete, 1, PMA_messages.strDecimalSeparator), '; + $html .= ' formatBytes(total, 1, PMA_messages.strDecimalSeparator) '; + $html .= ' ); '; + + $html .= ' if ($("#importmain").is(":visible")) { '; + $html .= ' $("#importmain").hide(); '; + $html .= ' $("#import_form_status") '; + $html .= ' .html(\'
' + . '
' + . '
' + . '
' + . 'ajax clock ' + . $upload_str . '
\') '; + $html .= ' .show(); '; + $html .= ' import_start = now; '; + $html .= ' } '; + $html .= ' else if (percent > 9 || complete > 2000000) { '; + $html .= ' var used_time = now - import_start; '; + $html .= ' var seconds = ' + . 'parseInt(((total - complete) / complete) * used_time / 1000); '; + $html .= ' var speed = $.sprintf("' . $second_str . '"'; + $html .= ' , formatBytes(complete / used_time * 1000, 1,' + . ' PMA_messages.strDecimalSeparator)); '; + + $html .= ' var minutes = parseInt(seconds / 60); '; + $html .= ' seconds %= 60; '; + $html .= ' var estimated_time; '; + $html .= ' if (minutes > 0) { '; + $html .= ' estimated_time = remaining_min '; + $html .= ' .replace("%MIN", minutes).replace("%SEC", seconds); '; + $html .= ' } '; + $html .= ' else { '; + $html .= ' estimated_time = remaining_second '; + $html .= ' .replace("%SEC", seconds); '; + $html .= ' } '; + + $html .= ' statustext += "
" + speed + "

" ' + . '+ estimated_time; '; + $html .= ' } '; + + $html .= ' var percent_str = Math.round(percent) + "%"; '; + $html .= ' $("#status").animate({width: percent_str}, 150); '; + $html .= ' $(".percentage").text(percent_str); '; + + + $html .= ' if (original_title !== false) { '; + $html .= ' parent.document.title = percent_str + " - " + original_title; '; + $html .= ' } '; + $html .= ' else { '; + $html .= ' document.title = percent_str + " - " + original_title; '; + $html .= ' } '; + $html .= ' $("#statustext").html(statustext); '; + $html .= ' } '; + + $html .= ' if (finished == true) { '; + $html .= ' if (original_title !== false) { '; + $html .= ' parent.document.title = original_title; '; + $html .= ' } '; + $html .= ' else { '; + $html .= ' document.title = original_title; '; + $html .= ' } '; + $html .= ' $("#importmain").hide(); '; + $html .= ' $("#import_form_status") '; + $html .= ' .html(\'ajax clock ' + . $processed_str . '\')'; + $html .= ' .show(); '; + $html .= ' $("#import_form_status").load("import_status.php?' + . 'message=true&' . $import_url . '"); '; + + $html .= ' } '; + $html .= ' else { '; + $html .= ' setTimeout(perform_upload, 1000); '; + $html .= ' } '; + $html .= '}); '; + $html .= '}; '; + $html .= 'setTimeout(perform_upload, 1000); '; + + return $html; +} + ?> From 2660fb048166b42381d4f0b6ae627f8f1a987740 Mon Sep 17 00:00:00 2001 From: xmujay Date: Sun, 28 Jul 2013 10:32:48 +0800 Subject: [PATCH 12/14] add comments to js --- libraries/display_import.lib.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/libraries/display_import.lib.php b/libraries/display_import.lib.php index 7d7acfc5dc..f963bed259 100644 --- a/libraries/display_import.lib.php +++ b/libraries/display_import.lib.php @@ -54,8 +54,11 @@ function PMA_getHtmlForImportJS($upload_id) //with "\n", so that the following lines won't be commented out by //'; //with "\n", so that the following lines won't be commented out by //]]> @@ -493,6 +498,7 @@ function PMA_getHtmlForImportNoPlugin($upload_id) $html .= ' ); '; $html .= ' if ($("#importmain").is(":visible")) { '; + // show progress UI $html .= ' $("#importmain").hide(); '; $html .= ' $("#import_form_status") '; $html .= ' .html(\'
' @@ -506,6 +512,7 @@ function PMA_getHtmlForImportNoPlugin($upload_id) $html .= ' import_start = now; '; $html .= ' } '; $html .= ' else if (percent > 9 || complete > 2000000) { '; + // calculate estimated time $html .= ' var used_time = now - import_start; '; $html .= ' var seconds = ' . 'parseInt(((total - complete) / complete) * used_time / 1000); '; @@ -517,11 +524,11 @@ function PMA_getHtmlForImportNoPlugin($upload_id) $html .= ' seconds %= 60; '; $html .= ' var estimated_time; '; $html .= ' if (minutes > 0) { '; - $html .= ' estimated_time = remaining_min '; + $html .= ' estimated_time = "' . $remaining_min . '"'; $html .= ' .replace("%MIN", minutes).replace("%SEC", seconds); '; $html .= ' } '; $html .= ' else { '; - $html .= ' estimated_time = remaining_second '; + $html .= ' estimated_time = "' . $remaining_second . '"'; $html .= ' .replace("%SEC", seconds); '; $html .= ' } '; @@ -533,7 +540,7 @@ function PMA_getHtmlForImportNoPlugin($upload_id) $html .= ' $("#status").animate({width: percent_str}, 150); '; $html .= ' $(".percentage").text(percent_str); '; - + // show percent in window title $html .= ' if (original_title !== false) { '; $html .= ' parent.document.title = percent_str + " - " + original_title; '; $html .= ' } '; @@ -551,6 +558,7 @@ function PMA_getHtmlForImportNoPlugin($upload_id) $html .= ' document.title = original_title; '; $html .= ' } '; $html .= ' $("#importmain").hide(); '; + // loads the message, either success or mysql error $html .= ' $("#import_form_status") '; $html .= ' .html(\'ajax clock ' @@ -559,6 +567,7 @@ function PMA_getHtmlForImportNoPlugin($upload_id) $html .= ' $("#import_form_status").load("import_status.php?' . 'message=true&' . $import_url . '"); '; + // if finished $html .= ' } '; $html .= ' else { '; $html .= ' setTimeout(perform_upload, 1000); '; From 96c1546b3df13b741ef37372d707bf557b120312 Mon Sep 17 00:00:00 2001 From: xmujay Date: Mon, 29 Jul 2013 20:20:11 +0800 Subject: [PATCH 13/14] refresh navigation panel when upload finished --- libraries/display_import.lib.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libraries/display_import.lib.php b/libraries/display_import.lib.php index f963bed259..89e77e43da 100644 --- a/libraries/display_import.lib.php +++ b/libraries/display_import.lib.php @@ -64,7 +64,7 @@ function PMA_getHtmlForImportJS($upload_id) if ($_SESSION[$SESSION_KEY]["handler"] != "UploadNoplugin") { - $html .= PMA_getHtmlForImportNoPlugin($upload_id); + $html .= PMA_getHtmlForImportWithPlugin($upload_id); } else { // no plugin available $image_tag = ' Date: Mon, 29 Jul 2013 23:31:35 +0800 Subject: [PATCH 14/14] fix code style --- libraries/display_import.lib.php | 34 ++++++++++++++++---------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/libraries/display_import.lib.php b/libraries/display_import.lib.php index 89e77e43da..77814b80b2 100644 --- a/libraries/display_import.lib.php +++ b/libraries/display_import.lib.php @@ -49,18 +49,18 @@ function PMA_getHtmlForImportJS($upload_id) { global $SESSION_KEY; $html = ''; - $html .= ' '; + $html .= ''; return $html; } @@ -489,12 +489,12 @@ function PMA_getHtmlForImportWithPlugin($upload_id) $html .= ' } else { '; $html .= ' var now = new Date(); '; $html .= ' now = Date.UTC( '; - $html .= ' now.getFullYear(), now.getMonth(), now.getDate(), '; - $html .= ' now.getHours(), now.getMinutes(), now.getSeconds()) '; - $html .= ' + now.getMilliseconds() - 1000; '; + $html .= ' now.getFullYear(), now.getMonth(), now.getDate(), '; + $html .= ' now.getHours(), now.getMinutes(), now.getSeconds()) '; + $html .= ' + now.getMilliseconds() - 1000; '; $html .= ' var statustext = $.sprintf("' . $statustext_str . '", '; - $html .= ' formatBytes(complete, 1, PMA_messages.strDecimalSeparator), '; - $html .= ' formatBytes(total, 1, PMA_messages.strDecimalSeparator) '; + $html .= ' formatBytes(complete, 1, PMA_messages.strDecimalSeparator), '; + $html .= ' formatBytes(total, 1, PMA_messages.strDecimalSeparator) '; $html .= ' ); '; $html .= ' if ($("#importmain").is(":visible")) { '; @@ -571,7 +571,7 @@ function PMA_getHtmlForImportWithPlugin($upload_id) // if finished $html .= ' } '; $html .= ' else { '; - $html .= ' setTimeout(perform_upload, 1000); '; + $html .= ' setTimeout(perform_upload, 1000); '; $html .= ' } '; $html .= '}); '; $html .= '}; ';