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