diff --git a/db_import.php b/db_import.php index f8ea8097ac..436136a1f2 100644 --- a/db_import.php +++ b/db_import.php @@ -22,7 +22,7 @@ require 'libraries/db_common.inc.php'; require 'libraries/db_info.inc.php'; $import_type = 'database'; -require 'libraries/display_import.lib.php'; +require 'libraries/display_import.inc.php'; ?> diff --git a/libraries/display_export.lib.php b/libraries/display_export.lib.php index 9630e427e9..f7730601c8 100644 --- a/libraries/display_export.lib.php +++ b/libraries/display_export.lib.php @@ -4,7 +4,7 @@ /** * functions for displaying server, database and table export * - * @usedby server_export.php and display_export.inc.php + * @usedby display_export.inc.php * * @package PhpMyAdmin */ diff --git a/libraries/display_import.inc.php b/libraries/display_import.inc.php new file mode 100644 index 0000000000..248149e644 --- /dev/null +++ b/libraries/display_import.inc.php @@ -0,0 +1,54 @@ +display(); + exit; +} + +$timeout_passed_str = isset($timeout_passed)? $timeout_passed : null; +$offset_str = isset($offset)? $offset : null; +$html = PMA_getHtmlForImport( + $upload_id, + $import_type, + $db, + $table, + $max_upload_size, + $import_list, + $timeout_passed_str, + $offset_str +); + +$response = PMA_Response::getInstance(); +$response->addHTML($html); + +?> diff --git a/libraries/display_import.lib.php b/libraries/display_import.lib.php index 252d2f6637..77814b80b2 100644 --- a/libraries/display_import.lib.php +++ b/libraries/display_import.lib.php @@ -1,338 +1,583 @@ display(); - exit; -} -?> - - - -
- ajax clock - -
> - - - '."\n"; - ?> - - - -
-

- '; - 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 '
'; -}?> - -
- -
    -
  • - - -
  • -
  • - - -
  • -
- display(); -} elseif (!empty($cfg['UploadDir'])) { - echo PMA_Util::getSelectUploadFileBlock($import_list, $cfg['UploadDir']); -} // end if (web-server upload directory) -?> -
- -
- ' . __('Character set of the file:') . ''; - reset($cfg['AvailableCharsets']); - echo '
'; -} else { - echo '' . "\n"; - echo PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_CHARSET, 'charset_of_file', 'charset_of_file', 'utf8', false); -} // end if (recoding) - ?> -
-
-
-

+ $html .= ' '."\n"; - ' . "\n"; - echo ''; - echo sprintf(__('Previous import timed out, after resubmitting will continue from position %d.'), $offset) . ''; - echo '
' . "\n"; + return $html; } - ?> -
- /> -
-
- -
- - -
- - - '; + $html .= ' // ' + . 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 + + // onclick + $html .= ' });'; + // domready + $html .= ' });'; + $html .= ' //]]>'; + //with "\n", so that the following lines won't be commented out by //]]> + $html .= "\n"; + $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; } -echo "\n"; - ?> -
- -
- - + +/** + * 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 .= ' '; + + } 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"; + } + + $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 : 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 .= '
'; + + $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; +} + +/** + * 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 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 +) { + 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_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; +} + +/** + * 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 javasript + $ajax_url = "import_status.php?id=" . $upload_id . "&" + . PMA_generate_common_url(array('import_status'=>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")) { '; + // 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 = $.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); '; + + // show percent in window title + $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(); '; + // 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; +} + +?> diff --git a/libraries/import.lib.php b/libraries/import.lib.php index fa80b5bdd1..72657b17db 100644 --- a/libraries/import.lib.php +++ b/libraries/import.lib.php @@ -139,6 +139,9 @@ function PMA_importRunQuery($sql = '', $full = '', $controluser = false, } $sql_query = $import_run_buffer['sql']; $sql_data['valid_sql'][] = $import_run_buffer['sql']; + if(! isset($sql_data['valid_queries'])) { + $sql_data['valid_queries'] = 0; + } $sql_data['valid_queries']++; // If a 'USE ' SQL-clause was found, @@ -189,6 +192,9 @@ function PMA_importRunQuery($sql = '', $full = '', $controluser = false, if (($a_num_rows > 0) || $is_use_query) { $sql_data['valid_sql'][] = $import_run_buffer['sql']; + if(! isset($sql_data['valid_queries'])) { + $sql_data['valid_queries'] = 0; + } $sql_data['valid_queries']++; } 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'; ?>