display_import.lib.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. *
  5. * @package PhpMyAdmin
  6. */
  7. if (! defined('PHPMYADMIN')) {
  8. exit;
  9. }
  10. /**
  11. *
  12. */
  13. require_once './libraries/file_listing.lib.php';
  14. require_once './libraries/plugin_interface.lib.php';
  15. require_once './libraries/display_import_ajax.lib.php';
  16. /* Scan for plugins */
  17. $import_list = PMA_getPlugins(
  18. "import",
  19. 'libraries/plugins/import/',
  20. $import_type
  21. );
  22. /* Fail if we didn't find any plugin */
  23. if (empty($import_list)) {
  24. PMA_Message::error(
  25. __(
  26. 'Could not load import plugins, please check your installation!'
  27. )
  28. )->display();
  29. exit;
  30. }
  31. ?>
  32. <iframe id="import_upload_iframe" name="import_upload_iframe" width="1" height="1" style="display: none;"></iframe>
  33. <div id="import_form_status" style="display: none;"></div>
  34. <div id="importmain">
  35. <img src="<?php echo $GLOBALS['pmaThemeImage'];?>ajax_clock_small.gif" width="16" height="16" alt="ajax clock" style="display: none;" />
  36. <script type="text/javascript">
  37. //<![CDATA[
  38. $( function() {
  39. // add event when user click on "Go" button
  40. $('#buttonGo').bind('click', function() {
  41. $('#upload_form_form').css("display", "none"); // hide form
  42. $('#upload_form_status').css("display", "inline"); // show progress bar
  43. $('#upload_form_status_info').css("display", "inline"); // - || -
  44. <?php
  45. if ($_SESSION[$SESSION_KEY]["handler"] != "UploadNoplugin") {
  46. ?>
  47. var finished = false;
  48. var percent = 0.0;
  49. var total = 0;
  50. var complete = 0;
  51. var original_title = parent && parent.document ? parent.document.title : false;
  52. var import_start;
  53. var perform_upload = function () {
  54. new $.getJSON(
  55. 'import_status.php?id=<?php echo $upload_id ; ?>&<?php echo PMA_generate_common_url(array('import_status'=>1), '&'); ?>',
  56. {},
  57. function(response) {
  58. finished = response.finished;
  59. percent = response.percent;
  60. total = response.total;
  61. complete = response.complete;
  62. if (total==0 && complete==0 && percent==0) {
  63. $('#upload_form_status_info').html('<img src="<?php echo $GLOBALS['pmaThemeImage'];?>ajax_clock_small.gif" width="16" height="16" alt="ajax clock" /> <?php echo PMA_jsFormat(__('The file being uploaded is probably larger than the maximum allowed size or this is a known bug in webkit based (Safari, Google Chrome, Arora etc.) browsers.'), false); ?>');
  64. $('#upload_form_status').css("display", "none");
  65. } else {
  66. var now = new Date();
  67. now = Date.UTC(
  68. now.getFullYear(), now.getMonth(), now.getDate(),
  69. now.getHours(), now.getMinutes(), now.getSeconds())
  70. + now.getMilliseconds() - 1000;
  71. var statustext = $.sprintf('<?php echo PMA_escapeJsString(__('%s of %s')); ?>',
  72. formatBytes(complete, 1, PMA_messages.strDecimalSeparator),
  73. formatBytes(total, 1, PMA_messages.strDecimalSeparator)
  74. );
  75. if ($('#importmain').is(':visible')) {
  76. // show progress UI
  77. $('#importmain').hide();
  78. $('#import_form_status')
  79. .html('<div class="upload_progress"><div class="upload_progress_bar_outer"><div class="percentage"></div><div id="status" class="upload_progress_bar_inner"><div class="percentage"></div></div></div><div><img src="<?php echo $GLOBALS['pmaThemeImage'];?>ajax_clock_small.gif" width="16" height="16" alt="ajax clock" /> <?php echo PMA_jsFormat(__('Uploading your import file…'), false); ?></div><div id="statustext"></div></div>')
  80. .show();
  81. import_start = now;
  82. }
  83. else if (percent > 9 || complete > 2000000) {
  84. // calculate estimated time
  85. var used_time = now - import_start;
  86. var seconds = parseInt(((total - complete) / complete) * used_time / 1000);
  87. var speed = $.sprintf('<?php echo PMA_jsFormat(__('%s/sec.'), false); ?>'
  88. , formatBytes(complete / used_time * 1000, 1, PMA_messages.strDecimalSeparator));
  89. var minutes = parseInt(seconds / 60);
  90. seconds %= 60;
  91. var estimated_time;
  92. if (minutes > 0) {
  93. estimated_time = '<?php echo PMA_jsFormat(__('About %MIN min. %SEC sec. remaining.'), false); ?>'
  94. .replace('%MIN', minutes).replace('%SEC', seconds);
  95. }
  96. else {
  97. estimated_time = '<?php echo PMA_jsFormat(__('About %SEC sec. remaining.'), false); ?>'
  98. .replace('%SEC', seconds);
  99. }
  100. statustext += '<br />' + speed + '<br /><br />' + estimated_time;
  101. }
  102. var percent_str = Math.round(percent) + '%';
  103. $('#status').animate({width: percent_str}, 150);
  104. $('.percentage').text(percent_str);
  105. // show percent in window title
  106. if (original_title !== false) {
  107. parent.document.title = percent_str + ' - ' + original_title;
  108. }
  109. else {
  110. document.title = percent_str + ' - ' + original_title;
  111. }
  112. $('#statustext').html(statustext);
  113. } // else
  114. if (finished == true) {
  115. if (original_title !== false) {
  116. parent.document.title = original_title;
  117. }
  118. else {
  119. document.title = original_title;
  120. }
  121. $('#importmain').hide();
  122. $('#import_form_status')
  123. .html('<img src="<?php echo $GLOBALS['pmaThemeImage'];?>ajax_clock_small.gif" width="16" height="16" alt="ajax clock" /> <?php echo PMA_jsFormat(__('The file is being processed, please be patient.'), false); ?> ')
  124. .show();
  125. $('#import_form_status').load('import_status.php?message=true&<?php echo PMA_generate_common_url(array('import_status'=>1), '&'); ?>'); // loads the message, either success or mysql error
  126. <?php
  127. // reload the left sidebar when the import is finished
  128. $GLOBALS['reload'] = true;
  129. ?>
  130. } // if finished
  131. else {
  132. setTimeout(perform_upload, 1000);
  133. }
  134. });
  135. };
  136. setTimeout(perform_upload, 1000);
  137. <?php
  138. } else { // no plugin available
  139. ?>
  140. $('#upload_form_status_info').html('<img src="<?php echo $GLOBALS['pmaThemeImage'];?>ajax_clock_small.gif" width="16" height="16" alt="ajax clock" /> <?php echo PMA_jsFormat(__('Please be patient, the file is being uploaded. Details about the upload are not available.'), false) . PMA_Util::showDocu('faq', 'faq2-9'); ?>');
  141. $('#upload_form_status').css("display", "none");
  142. <?php
  143. } // else
  144. ?>
  145. }); // onclick
  146. }); // domready
  147. //]]>
  148. </script>
  149. <form action="import.php" method="post" enctype="multipart/form-data"
  150. name="import"<?php
  151. if ($_SESSION[$SESSION_KEY]["handler"] != "UploadNoplugin") {
  152. echo ' target="import_upload_iframe"';
  153. }
  154. echo ' class="ajax"';
  155. ?>>
  156. <input type="hidden" name="<?php
  157. echo call_user_func($_SESSION[$SESSION_KEY]['handler'] . '::getIdKey');
  158. ?>" value="<?php echo $upload_id ; ?>" />
  159. <?php
  160. if ($import_type == 'server') {
  161. echo PMA_generate_common_hidden_inputs('', '', 1);
  162. } elseif ($import_type == 'database') {
  163. echo PMA_generate_common_hidden_inputs($db, '', 1);
  164. } else {
  165. echo PMA_generate_common_hidden_inputs($db, $table, 1);
  166. }
  167. echo ' <input type="hidden" name="import_type" value="' . $import_type . '" />'."\n";
  168. ?>
  169. <div class="exportoptions" id="header">
  170. <h2>
  171. <?php echo PMA_Util::getImage('b_import.png', __('Import')); ?>
  172. <?php
  173. if ($import_type == 'server') {
  174. echo __('Importing into the current server');
  175. } elseif ($import_type == 'database') {
  176. printf(__('Importing into the database "%s"'), htmlspecialchars($db));
  177. } else {
  178. printf(__('Importing into the table "%s"'), htmlspecialchars($table));
  179. }?>
  180. </h2>
  181. </div>
  182. <div class="importoptions">
  183. <h3><?php echo __('File to Import:'); ?></h3>
  184. <?php
  185. // zip, gzip and bzip2 encode features
  186. $compressions = array();
  187. if ($cfg['GZipDump'] && @function_exists('gzopen')) {
  188. $compressions[] = 'gzip';
  189. }
  190. if ($cfg['BZipDump'] && @function_exists('bzopen')) {
  191. $compressions[] = 'bzip2';
  192. }
  193. if ($cfg['ZipDump'] && @function_exists('zip_open')) {
  194. $compressions[] = 'zip';
  195. }
  196. // We don't have show anything about compression, when no supported
  197. if ($compressions != array()) {
  198. echo '<div class="formelementrow" id="compression_info">';
  199. printf(__('File may be compressed (%s) or uncompressed.'), implode(", ", $compressions));
  200. echo '<br />';
  201. echo __('A compressed file\'s name must end in <b>.[format].[compression]</b>. Example: <b>.sql.zip</b>');
  202. echo '</div>';
  203. }?>
  204. <div class="formelementrow" id="upload_form">
  205. <?php
  206. if ($GLOBALS['is_upload'] && !empty($cfg['UploadDir'])) { ?>
  207. <ul>
  208. <li>
  209. <input type="radio" name="file_location" id="radio_import_file" />
  210. <?php
  211. echo PMA_Util::getBrowseUploadFileBlock($max_upload_size);
  212. ?>
  213. </li>
  214. <li>
  215. <input type="radio" name="file_location" id="radio_local_import_file" />
  216. <?php
  217. echo PMA_Util::getSelectUploadFileBlock($import_list, $cfg['UploadDir']);
  218. ?>
  219. </li>
  220. </ul>
  221. <?php
  222. } elseif ($GLOBALS['is_upload']) {
  223. $uid = uniqid('');
  224. echo PMA_Util::getBrowseUploadFileBlock($max_upload_size);
  225. } elseif (!$GLOBALS['is_upload']) {
  226. PMA_Message::notice(__('File uploads are not allowed on this server.'))->display();
  227. } elseif (!empty($cfg['UploadDir'])) {
  228. echo PMA_Util::getSelectUploadFileBlock($import_list, $cfg['UploadDir']);
  229. } // end if (web-server upload directory)
  230. ?>
  231. </div>
  232. <div class="formelementrow" id="charaset_of_file">
  233. <?php // charset of file
  234. if ($GLOBALS['PMA_recoding_engine'] != PMA_CHARSET_NONE) {
  235. echo '<label for="charset_of_file">' . __('Character set of the file:') . '</label>';
  236. reset($cfg['AvailableCharsets']);
  237. echo '<select id="charset_of_file" name="charset_of_file" size="1">';
  238. foreach ($cfg['AvailableCharsets'] as $temp_charset) {
  239. echo '<option value="' . htmlentities($temp_charset) . '"';
  240. if ((empty($cfg['Import']['charset']) && $temp_charset == 'utf-8')
  241. || $temp_charset == $cfg['Import']['charset']
  242. ) {
  243. echo ' selected="selected"';
  244. }
  245. echo '>' . htmlentities($temp_charset) . '</option>';
  246. }
  247. echo ' </select><br />';
  248. } else {
  249. echo '<label for="charset_of_file">' . __('Character set of the file:') . '</label>' . "\n";
  250. echo PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_CHARSET, 'charset_of_file', 'charset_of_file', 'utf8', false);
  251. } // end if (recoding)
  252. ?>
  253. </div>
  254. </div>
  255. <div class="importoptions">
  256. <h3><?php echo __('Partial Import:'); ?></h3>
  257. <?php
  258. if (isset($timeout_passed) && $timeout_passed) {
  259. echo '<div class="formelementrow">' . "\n";
  260. echo '<input type="hidden" name="skip" value="' . $offset . '" />';
  261. echo sprintf(__('Previous import timed out, after resubmitting will continue from position %d.'), $offset) . '';
  262. echo '</div>' . "\n";
  263. }
  264. ?>
  265. <div class="formelementrow">
  266. <input type="checkbox" name="allow_interrupt" value="yes"
  267. id="checkbox_allow_interrupt" <?php echo PMA_pluginCheckboxCheck('Import', 'allow_interrupt'); ?>/>
  268. <label for="checkbox_allow_interrupt"><?php echo __('Allow the interruption of an import in case the script detects it is close to the PHP timeout limit. <i>(This might be a good way to import large files, however it can break transactions.)</i>'); ?></label><br />
  269. </div>
  270. <?php
  271. if (! (isset($timeout_passed) && $timeout_passed)) {
  272. ?>
  273. <div class="formelementrow">
  274. <label for="text_skip_queries"><?php echo __('Number of rows to skip, starting from the first row:'); ?></label>
  275. <input type="text" name="skip_queries" value="<?php echo PMA_pluginGetDefault('Import', 'skip_queries');?>" id="text_skip_queries" />
  276. </div>
  277. <?php
  278. } else {
  279. // If timeout has passed,
  280. // do not show the Skip dialog to avoid the risk of someone
  281. // entering a value here that would interfere with "skip"
  282. ?>
  283. <input type="hidden" name="skip_queries" value="<?php echo PMA_pluginGetDefault('Import', 'skip_queries');?>" id="text_skip_queries" />
  284. <?php
  285. }
  286. ?>
  287. </div>
  288. <div class="importoptions">
  289. <h3><?php echo __('Format:'); ?></h3>
  290. <?php echo PMA_pluginGetChoice('Import', 'format', $import_list); ?>
  291. <div id="import_notification"></div>
  292. </div>
  293. <div class="importoptions" id="format_specific_opts">
  294. <h3><?php echo __('Format-Specific Options:'); ?></h3>
  295. <p class="no_js_msg" id="scroll_to_options_msg">Scroll down to fill in the options for the selected format and ignore the options for other formats.</p>
  296. <?php echo PMA_pluginGetOptions('Import', $import_list); ?>
  297. </div>
  298. <div class="clearfloat"></div>
  299. <?php
  300. // Encoding setting form appended by Y.Kawada
  301. if (function_exists('PMA_set_enc_form')) { ?>
  302. <div class="importoptions" id="kanji_encoding">
  303. <h3><?php echo __('Encoding Conversion:'); ?></h3>
  304. <?php echo PMA_set_enc_form(' '); ?>
  305. </div>
  306. <?php
  307. }
  308. echo "\n";
  309. ?>
  310. <div class="importoptions" id="submit">
  311. <input type="submit" value="<?php echo __('Go'); ?>" id="buttonGo" />
  312. </div>
  313. </form>
  314. </div>