diff --git a/db_import.php b/db_import.php index 8a266293f9..21dfd1aa07 100644 --- a/db_import.php +++ b/db_import.php @@ -6,8 +6,9 @@ * @package PhpMyAdmin */ -use PhpMyAdmin\Response; use PhpMyAdmin\Config\PageSettings; +use PhpMyAdmin\Display\Import; +use PhpMyAdmin\Response; require_once 'libraries/common.inc.php'; @@ -35,10 +36,9 @@ list( $pos ) = PhpMyAdmin\Util::getDbInfo($db, isset($sub_part) ? $sub_part : ''); -require 'libraries/display_import.lib.php'; $response = Response::getInstance(); $response->addHTML( - PMA_getImportDisplay( + Import::getImportDisplay( 'database', $db, $table, $max_upload_size ) ); diff --git a/libraries/classes/Display/Import.php b/libraries/classes/Display/Import.php new file mode 100644 index 0000000000..bd9775fef9 --- /dev/null +++ b/libraries/classes/Display/Import.php @@ -0,0 +1,705 @@ +' . "\n"; + + return $html; + } + + /** + * Prints Html For Import Javascript + * + * @param int $upload_id The selected upload id + * + * @return string + */ + public static function getHtmlForImportJs($upload_id) + { + global $SESSION_KEY; + $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 + */ + public static function getHtmlForImportOptions($import_type, $db, $table) + { + $html = ' '; + + return $html; + } + + /** + * Prints Html For Display Import options : Compressions + * + * @return string + */ + public static function 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 + */ + public static function getHtmlForImportCharset() + { + global $cfg; + $html = '
'; + // charset of file + if (Encoding::isSupported()) { + $html .= ''; + $html .= '
'; + } else { + $html .= '' . "\n"; + $html .= Charsets::getCharsetDropdownBox( + '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 ImportPlugin[] $import_list import list + * @param String $local_import_file from upload directory + * + * @return string + */ + public static function getHtmlForImportOptionsFile( + $max_upload_size, $import_list, $local_import_file + ) { + global $cfg; + $html = '
'; + $html .= '

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

'; + $html .= self::getHtmlForImportCompressions(); + $html .= '
'; + + if ($GLOBALS['is_upload'] && !empty($cfg['UploadDir'])) { + $html .= '
'; + $html .= self::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 + */ + public static function 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"; + } + + $html .= '
'; + $html .= ' '; + $html .= '
'; + $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; + } + + /** + * Prints Html For Display Import options : Other + * + * @return string + */ + public static function getHtmlForImportOptionsOther() + { + $html = '
'; + $html .= '

' . __('Other options:') . '

'; + $html .= '
'; + $html .= Util::getFKCheckbox(); + $html .= '
'; + $html .= '
'; + + return $html; + } + + /** + * Prints Html For Display Import options : Format + * + * @param ImportPlugin[] $import_list import list + * + * @return string + */ + public static function getHtmlForImportOptionsFormat($import_list) + { + $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 .= '
'; + + // Japanese encoding setting + if (Encoding::canConvertKanji()) { + $html .= '
'; + $html .= '

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

'; + $html .= Encoding::kanjiEncodingForm(); + $html .= '
'; + + } + $html .= "\n"; + + return $html; + } + + /** + * Prints Html For Display Import options : submit + * + * @return string + */ + public static function getHtmlForImportOptionsSubmit() + { + $html = '
'; + $html .= ' '; + $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 ImportPlugin[] $import_list Import list + * @param String $timeout_passed Timeout passed + * @param String $offset Timeout offset + * @param String $local_import_file from upload directory + * + * @return string + */ + public static function getHtmlForImport( + $upload_id, $import_type, $db, $table, + $max_upload_size, $import_list, $timeout_passed, $offset, $local_import_file + ) { + global $SESSION_KEY; + $html = ''; + $html .= ''; + $html .= '
'; + $html .= '
'; + $html .= ' ajax clock'; + + $html .= self::getHtmlForImportJs($upload_id); + + $html .= '
'; + + $html .= self::getHtmlForHiddenInputs($import_type, $db, $table); + + $html .= self::getHtmlForImportOptions($import_type, $db, $table); + + $html .= self::getHtmlForImportOptionsFile( + $max_upload_size, $import_list, $local_import_file + ); + + $html .= self::getHtmlForImportOptionsPartialImport($timeout_passed, $offset); + + $html .= self::getHtmlForImportOptionsOther(); + + $html .= self::getHtmlForImportOptionsFormat($import_list); + + $html .= self::getHtmlForImportOptionsSubmit(); + + $html .= '
'; + $html .= '
'; + + return $html; + } + + /** + * Prints javascript for upload with plugin, upload process bar + * + * @param int $upload_id The selected upload id + * + * @return string + */ + public static function getHtmlForImportWithPlugin($upload_id) + { + //some variable for javascript + $ajax_url = "import_status.php?id=" . $upload_id . "&" + . Url::getCommonRaw(array('import_status'=>1)); + $promot_str = Sanitize::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 = Sanitize::escapeJsString(__('%s of %s')); + $upload_str = Sanitize::jsFormat(__('Uploading your import file…'), false); + $second_str = Sanitize::jsFormat(__('%s/sec.'), false); + $remaining_min = Sanitize::jsFormat(__('About %MIN min. %SEC sec. remaining.'), false); + $remaining_second = Sanitize::jsFormat(__('About %SEC sec. remaining.'), false); + $processed_str = Sanitize::jsFormat( + __('The file is being processed, please be patient.'), + false + ); + $import_url = Url::getCommonRaw(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(), '; + $html .= ' now.getMonth(), '; + $html .= ' now.getDate(), '; + $html .= ' now.getHours(), '; + $html .= ' now.getMinutes(), '; + $html .= ' now.getSeconds()) '; + $html .= ' + now.getMilliseconds() - 1000; '; + $html .= ' var statustext = PMA_sprintf('; + $html .= ' "' . $statustext_str . '", '; + $html .= ' formatBytes( '; + $html .= ' complete, 1, PMA_messages.strDecimalSeparator'; + $html .= ' ), '; + $html .= ' formatBytes('; + $html .= ' total, 1, PMA_messages.strDecimalSeparator'; + $html .= ' ) '; + $html .= ' ); '; + + $html .= ' if ($("#importmain").is(":visible")) { '; + // show progress UI + $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) { '; + // calculate estimated time + $html .= ' var used_time = now - import_start; '; + $html .= ' var seconds = ' + . 'parseInt(((total - complete) / complete) * used_time / 1000); '; + $html .= ' var speed = PMA_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)'; + $html .= ' .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); '; + + // show percent in window title + $html .= ' if (original_title !== false) { '; + $html .= ' parent.document.title '; + $html .= ' = percent_str + " - " + original_title; '; + $html .= ' } '; + $html .= ' else { '; + $html .= ' document.title '; + $html .= ' = 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(); '; + // loads the message, either success or mysql error + $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 .= ' PMA_reloadNavigation(); '; + + // if finished + $html .= ' } '; + $html .= ' else { '; + $html .= ' setTimeout(perform_upload, 1000); '; + $html .= ' } '; + $html .= '}); '; + $html .= '}; '; + $html .= 'setTimeout(perform_upload, 1000); '; + + return $html; + } + + /** + * Gets HTML to display import dialogs + * + * @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 + * + * @return string $html + */ + public static function getImportDisplay($import_type, $db, $table, $max_upload_size) + { + global $SESSION_KEY; + include_once './libraries/file_listing.lib.php'; + include_once './libraries/plugin_interface.lib.php'; + + include_once './libraries/display_import_ajax.lib.php'; + list( + $SESSION_KEY, + $upload_id, + ) = PMA_uploadProgressSetup(); + + /* Scan for plugins */ + /* @var $import_list ImportPlugin[] */ + $import_list = PMA_getPlugins( + "import", + 'libraries/classes/Plugins/Import/', + $import_type + ); + + /* Fail if we didn't find any plugin */ + if (empty($import_list)) { + Message::error( + __( + 'Could not load import plugins, please check your installation!' + ) + )->display(); + exit; + } + + if (Core::isValid($_REQUEST['offset'], 'numeric')) { + $offset = intval($_REQUEST['offset']); + } + if (isset($_REQUEST['timeout_passed'])) { + $timeout_passed = $_REQUEST['timeout_passed']; + } + + $local_import_file = ''; + if (isset($_REQUEST['local_import_file'])) { + $local_import_file = $_REQUEST['local_import_file']; + } + + $timeout_passed_str = isset($timeout_passed)? $timeout_passed : null; + $offset_str = isset($offset)? $offset : null; + return self::getHtmlForImport( + $upload_id, + $import_type, + $db, + $table, + $max_upload_size, + $import_list, + $timeout_passed_str, + $offset_str, + $local_import_file + ); + } +} diff --git a/libraries/display_import.lib.php b/libraries/display_import.lib.php deleted file mode 100644 index 7ba314398e..0000000000 --- a/libraries/display_import.lib.php +++ /dev/null @@ -1,698 +0,0 @@ -' . "\n"; - - return $html; -} - -/** - * Prints Html For Import Javascript - * - * @param int $upload_id The selected upload id - * - * @return string - */ -function PMA_getHtmlForImportJS($upload_id) -{ - global $SESSION_KEY; - $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_getHtmlForImportOptions($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 (Encoding::isSupported()) { - $html .= ''; - $html .= '
'; - } else { - $html .= '' . "\n"; - $html .= Charsets::getCharsetDropdownBox( - '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 ImportPlugin[] $import_list import list - * @param String $local_import_file from upload directory - * - * @return string - */ -function PMA_getHtmlForImportOptionsFile( - $max_upload_size, $import_list, $local_import_file -) { - global $cfg; - $html = '
'; - $html .= '

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

'; - $html .= PMA_getHtmlForImportCompressions(); - $html .= '
'; - - if ($GLOBALS['is_upload'] && !empty($cfg['UploadDir'])) { - $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"; - } - - $html .= '
'; - $html .= ' '; - $html .= '
'; - $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; -} - -/** - * Prints Html For Display Import options : Other - * - * @return string - */ -function PMA_getHtmlForImportOptionsOther() -{ - $html = '
'; - $html .= '

' . __('Other options:') . '

'; - $html .= '
'; - $html .= PhpMyAdmin\Util::getFKCheckbox(); - $html .= '
'; - $html .= '
'; - - return $html; -} - -/** - * Prints Html For Display Import options : Format - * - * @param ImportPlugin[] $import_list import list - * - * @return string - */ -function PMA_getHtmlForImportOptionsFormat($import_list) -{ - $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 .= '
'; - - // Japanese encoding setting - if (Encoding::canConvertKanji()) { - $html .= '
'; - $html .= '

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

'; - $html .= Encoding::kanjiEncodingForm(); - $html .= '
'; - - } - $html .= "\n"; - - return $html; -} - -/** - * Prints Html For Display Import options : submit - * - * @return string - */ -function PMA_getHtmlForImportOptionsSubmit() -{ - $html = '
'; - $html .= ' '; - $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 ImportPlugin[] $import_list Import list - * @param String $timeout_passed Timeout passed - * @param String $offset Timeout offset - * @param String $local_import_file from upload directory - * - * @return string - */ -function PMA_getHtmlForImport( - $upload_id, $import_type, $db, $table, - $max_upload_size, $import_list, $timeout_passed, $offset, $local_import_file -) { - global $SESSION_KEY; - $html = ''; - $html .= ''; - $html .= '
'; - $html .= '
'; - $html .= ' ajax clock'; - - $html .= PMA_getHtmlForImportJS($upload_id); - - $html .= '
'; - - $html .= PMA_getHtmlForHiddenInputs($import_type, $db, $table); - - $html .= PMA_getHtmlForImportOptions($import_type, $db, $table); - - $html .= PMA_getHtmlForImportOptionsFile( - $max_upload_size, $import_list, $local_import_file - ); - - $html .= PMA_getHtmlForImportOptionsPartialImport($timeout_passed, $offset); - - $html .= PMA_getHtmlForImportOptionsOther(); - - $html .= PMA_getHtmlForImportOptionsFormat($import_list); - - $html .= PMA_getHtmlForImportOptionsSubmit(); - - $html .= '
'; - $html .= '
'; - - return $html; -} - -/** - * Prints javascript for upload with plugin, upload process bar - * - * @param int $upload_id The selected upload id - * - * @return string - */ -function PMA_getHtmlForImportWithPlugin($upload_id) -{ - //some variable for javascript - $ajax_url = "import_status.php?id=" . $upload_id . "&" - . Url::getCommonRaw(array('import_status'=>1)); - $promot_str = Sanitize::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 = Sanitize::escapeJsString(__('%s of %s')); - $upload_str = Sanitize::jsFormat(__('Uploading your import file…'), false); - $second_str = Sanitize::jsFormat(__('%s/sec.'), false); - $remaining_min = Sanitize::jsFormat(__('About %MIN min. %SEC sec. remaining.'), false); - $remaining_second = Sanitize::jsFormat(__('About %SEC sec. remaining.'), false); - $processed_str = Sanitize::jsFormat( - __('The file is being processed, please be patient.'), - false - ); - $import_url = Url::getCommonRaw(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(), '; - $html .= ' now.getMonth(), '; - $html .= ' now.getDate(), '; - $html .= ' now.getHours(), '; - $html .= ' now.getMinutes(), '; - $html .= ' now.getSeconds()) '; - $html .= ' + now.getMilliseconds() - 1000; '; - $html .= ' var statustext = PMA_sprintf('; - $html .= ' "' . $statustext_str . '", '; - $html .= ' formatBytes( '; - $html .= ' complete, 1, PMA_messages.strDecimalSeparator'; - $html .= ' ), '; - $html .= ' formatBytes('; - $html .= ' total, 1, PMA_messages.strDecimalSeparator'; - $html .= ' ) '; - $html .= ' ); '; - - $html .= ' if ($("#importmain").is(":visible")) { '; - // show progress UI - $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) { '; - // calculate estimated time - $html .= ' var used_time = now - import_start; '; - $html .= ' var seconds = ' - . 'parseInt(((total - complete) / complete) * used_time / 1000); '; - $html .= ' var speed = PMA_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)'; - $html .= ' .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); '; - - // show percent in window title - $html .= ' if (original_title !== false) { '; - $html .= ' parent.document.title '; - $html .= ' = percent_str + " - " + original_title; '; - $html .= ' } '; - $html .= ' else { '; - $html .= ' document.title '; - $html .= ' = 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(); '; - // loads the message, either success or mysql error - $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 .= ' PMA_reloadNavigation(); '; - - // if finished - $html .= ' } '; - $html .= ' else { '; - $html .= ' setTimeout(perform_upload, 1000); '; - $html .= ' } '; - $html .= '}); '; - $html .= '}; '; - $html .= 'setTimeout(perform_upload, 1000); '; - - return $html; -} - -/** - * Gets HTML to display import dialogs - * - * @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 - * - * @return string $html - */ -function PMA_getImportDisplay($import_type, $db, $table, $max_upload_size) -{ - global $SESSION_KEY; - include_once './libraries/file_listing.lib.php'; - include_once './libraries/plugin_interface.lib.php'; - - include_once './libraries/display_import_ajax.lib.php'; - list( - $SESSION_KEY, - $upload_id, - ) = PMA_uploadProgressSetup(); - - /* Scan for plugins */ - /* @var $import_list ImportPlugin[] */ - $import_list = PMA_getPlugins( - "import", - 'libraries/classes/Plugins/Import/', - $import_type - ); - - /* Fail if we didn't find any plugin */ - if (empty($import_list)) { - Message::error( - __( - 'Could not load import plugins, please check your installation!' - ) - )->display(); - exit; - } - - if (Core::isValid($_REQUEST['offset'], 'numeric')) { - $offset = intval($_REQUEST['offset']); - } - if (isset($_REQUEST['timeout_passed'])) { - $timeout_passed = $_REQUEST['timeout_passed']; - } - - $local_import_file = ''; - if (isset($_REQUEST['local_import_file'])) { - $local_import_file = $_REQUEST['local_import_file']; - } - - $timeout_passed_str = isset($timeout_passed)? $timeout_passed : null; - $offset_str = isset($offset)? $offset : null; - return PMA_getHtmlForImport( - $upload_id, - $import_type, - $db, - $table, - $max_upload_size, - $import_list, - $timeout_passed_str, - $offset_str, - $local_import_file - ); -} diff --git a/server_import.php b/server_import.php index b8027ec41a..6c419a2c18 100644 --- a/server_import.php +++ b/server_import.php @@ -6,6 +6,7 @@ * @package PhpMyAdmin */ use PhpMyAdmin\Config\PageSettings; +use PhpMyAdmin\Display\Import; use PhpMyAdmin\Response; /** @@ -25,10 +26,9 @@ $scripts->addFile('import.js'); */ require 'libraries/server_common.inc.php'; -require 'libraries/display_import.lib.php'; $response = Response::getInstance(); $response->addHTML( - PMA_getImportDisplay( + Import::getImportDisplay( 'server', $db, $table, $max_upload_size ) ); diff --git a/tbl_import.php b/tbl_import.php index 477e304562..9a5b908fbb 100644 --- a/tbl_import.php +++ b/tbl_import.php @@ -6,6 +6,7 @@ * @package PhpMyAdmin */ use PhpMyAdmin\Config\PageSettings; +use PhpMyAdmin\Display\Import; use PhpMyAdmin\Response; /** @@ -26,9 +27,8 @@ $scripts->addFile('import.js'); require_once 'libraries/tbl_common.inc.php'; $url_query .= '&goto=tbl_import.php&back=tbl_import.php'; -require 'libraries/display_import.lib.php'; $response->addHTML( - PMA_getImportDisplay( + Import::getImportDisplay( 'table', $db, $table, $max_upload_size ) );