3.3.10-rc1
[phpmyadmin/crack.git] / libraries / display_import.lib.php
blobb5eab108faa993392f3642f97fcd2b59f9a2d090
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @version $Id$
6 * @package phpMyAdmin
7 */
8 if (! defined('PHPMYADMIN')) {
9 exit;
12 /**
15 require_once './libraries/file_listing.php';
16 require_once './libraries/plugin_interface.lib.php';
17 require_once './libraries/display_import_ajax.lib.php';
19 /* Scan for plugins */
20 $import_list = PMA_getPlugins('./libraries/import/', $import_type);
22 /* Fail if we didn't find any plugin */
23 if (empty($import_list)) {
24 PMA_Message::error('strCanNotLoadImportPlugins')->display();
25 require './libraries/footer.inc.php';
29 <iframe id="import_upload_iframe" name="import_upload_iframe" width="1" height="1" style="display: none"></iframe>
30 <div id="import_form_status" style="display: none;"></div>
31 <div id="importmain">
32 <img src="<?php echo $GLOBALS['pmaThemeImage'];?>ajax_clock_small.gif" alt="ajax clock" style="display: none;" />
33 <script type="text/javascript">
34 //<![CDATA[
35 window.addEvent('domready', function() {
36 // add event when user click on "Go" button
37 $('buttonGo').addEvent('click', function() {
38 $('upload_form_form').setStyle("display", "none"); // hide form
39 $('upload_form_status').setStyle("display", "inline"); // show progress bar
40 $('upload_form_status_info').setStyle("display", "inline"); // - || -
41 <?php
42 if ($_SESSION[$SESSION_KEY]["handler"]!="noplugin") {
44 $('upload_form_status').set('html', '<div class="upload_progress_bar_outer"><div id="status" class="upload_progress_bar_inner"></div></div>'); // add the progress bar
46 var finished = false;
47 var percent = 0.0;
48 var total = 0;
49 var complete = 0;
51 var perform_upload;
52 var periodical_upload;
54 var request_upload = new Request({
55 url: 'import_status.php?id=<?php echo $upload_id ; ?>&<?php echo PMA_generate_common_url(); ?>', // the "&" is causing problems for webkit browsers
56 method: 'get',
57 update: 'upload_form_status',
58 onComplete: function(response) {
59 objectsReturned = JSON.decode(response);
61 $each(objectsReturned, function(item, index) {
63 if (index=="finished") {
64 finished = item;
65 if (finished==true) {
66 $clear(periodical_upload);
67 $('importmain').setStyle('display', 'none');
68 $('import_form_status').setStyle('display', 'inline');
69 $('import_form_status').set('html', '<img src="<?php echo $GLOBALS['pmaThemeImage'];?>ajax_clock_small.gif" alt="ajax clock" /> <?php echo PMA_jsFormat($strImportProceedingFile); ?> ');
70 $('import_form_status').load('import_status.php?message=true&<?php echo PMA_generate_common_url(); ?>'); // loads the message, either success or mysql error
71 <?php
72 // reload the left sidebar when the import is finished
73 $GLOBALS['reload']=true;
74 PMA_reloadNavigation(true);
76 } // if finished==item
77 } // if index==finished
78 if (index=="percent")
79 percent = item;
80 if (index=="total")
81 total = item;
82 if (index=="complete")
83 complete = item;
84 }); // $each
85 if (total==0 && complete==0 && percent==0) {
86 $('upload_form_status_info').set('html', '<img src="<?php echo $GLOBALS['pmaThemeImage'];?>ajax_clock_small.gif" alt="ajax clock" /> <?php echo PMA_jsFormat($strImportLargeFileUploading); ?>');
87 $('upload_form_status').setStyle("display", "none");
88 } else {
89 $('upload_form_status_info').set('html', ' '+Math.round(percent)+'%, '+complete+'/'+total);
90 $('status').tween('width', Math.round(percent)*2+'px');
91 } // else
92 } // onComplete
93 }); // [equest
94 perform_upload = function () {
95 request_upload.send('r=' + $time() + $random(0, 100)); // hack for IE7,8 & webkit (Safari, Chrome, Arora...)
97 periodical_upload = perform_upload.periodical(1000);
98 <?php
99 } else {
101 $('upload_form_status_info').set('html', '<img src="<?php echo $GLOBALS['pmaThemeImage'];?>ajax_clock_small.gif" alt="ajax clock" /> <?php echo PMA_jsFormat($strImportUploadInfoNotAvailable) . PMA_showDocu('faq2_9'); ?>');
102 $('upload_form_status').setStyle("display", "none");
103 <?php
104 } // else
106 }); // if click
107 }); // domready
109 document.write('<form action="import.php" method="post" enctype="multipart/form-data" name="import"<?php if ($_SESSION[$SESSION_KEY]["handler"]!="noplugin") echo ' target="import_upload_iframe"'; ?>>');
110 //]]>
111 </script>
112 <noscript>
113 <form action="import.php" method="post" enctype="multipart/form-data" name="import">
114 </noscript>
115 <input type="hidden" name="<?php echo $ID_KEY; ?>" value="<?php echo $upload_id ; ?>" />
116 <?php
117 if ($import_type == 'server') {
118 echo PMA_generate_common_hidden_inputs('', '', 1);
119 } elseif ($import_type == 'database') {
120 echo PMA_generate_common_hidden_inputs($db, '', 1);
121 } else {
122 echo PMA_generate_common_hidden_inputs($db, $table, 1);
124 echo ' <input type="hidden" name="import_type" value="' . $import_type . '" />'."\n";
125 echo PMA_pluginGetJavascript($import_list);
127 <fieldset class="options">
128 <legend><?php echo $strFileToImport; ?></legend>
130 <?php
132 if ($GLOBALS['is_upload']) {
133 $uid = uniqid("");
135 <div class="formelementrow" id="upload_form">
136 <div id="upload_form_status" style="display: none;"></div>
137 <div id="upload_form_status_info" style="display: none;"></div>
138 <div id="upload_form_form">
139 <label for="input_import_file"><?php echo $strLocationTextfile; ?></label>
140 <input style="margin: 5px" type="file" name="import_file" id="input_import_file" onchange="match_file(this.value);" />
141 <?php
142 echo PMA_displayMaximumUploadSize($max_upload_size) . "\n";
143 // some browsers should respect this :)
144 echo PMA_generateHiddenMaxFileSize($max_upload_size) . "\n";
146 </div>
147 </div>
148 <?php
149 } else {
150 PMA_Message::warning('strUploadsNotAllowed')->display();
152 if (!empty($cfg['UploadDir'])) {
153 $extensions = '';
154 foreach ($import_list as $key => $val) {
155 if (!empty($extensions)) {
156 $extensions .= '|';
158 $extensions .= $val['extension'];
160 $matcher = '@\.(' . $extensions . ')(\.(' . PMA_supportedDecompressions() . '))?$@';
162 $files = PMA_getFileSelectOptions(PMA_userDir($cfg['UploadDir']), $matcher, (isset($timeout_passed) && $timeout_passed && isset($local_import_file)) ? $local_import_file : '');
163 echo '<div class="formelementrow">' . "\n";
164 if ($files === FALSE) {
165 PMA_Message::error('strWebServerUploadDirectoryError')->display();
166 } elseif (!empty($files)) {
167 echo "\n";
168 echo ' <i>' . $strOr . '</i><br/><label for="select_local_import_file">' . $strWebServerUploadDirectory . '</label>&nbsp;: ' . "\n";
169 echo ' <select style="margin: 5px" size="1" name="local_import_file" onchange="match_file(this.value)" id="select_local_import_file">' . "\n";
170 echo ' <option value="">&nbsp;</option>' . "\n";
171 echo $files;
172 echo ' </select>' . "\n";
174 echo '</div>' . "\n";
175 } // end if (web-server upload directory)
177 // charset of file
178 echo '<div class="formelementrow">' . "\n";
179 if ($cfg['AllowAnywhereRecoding']) {
180 echo '<label for="charset_of_file">' . $strCharsetOfFile . '</label>';
181 reset($cfg['AvailableCharsets']);
182 echo '<select id="charset_of_file" name="charset_of_file" size="1">';
183 foreach ($cfg['AvailableCharsets'] as $temp_charset) {
184 echo '<option value="' . htmlentities($temp_charset) . '"';
185 if ((empty($cfg['Import']['charset']) && $temp_charset == $charset)
186 || $temp_charset == $cfg['Import']['charset']) {
187 echo ' selected="selected"';
189 echo '>' . htmlentities($temp_charset) . '</option>';
191 echo ' </select><br />';
192 } else {
193 echo '<label for="charset_of_file">' . $strCharsetOfFile . '</label>' . "\n";
194 echo PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_CHARSET, 'charset_of_file', 'charset_of_file', 'utf8', FALSE);
195 } // end if (recoding)
196 echo '</div>' . "\n";
198 // zip, gzip and bzip2 encode features
199 $compressions = $strNone;
201 if ($cfg['GZipDump'] && @function_exists('gzopen')) {
202 $compressions .= ', gzip';
204 if ($cfg['BZipDump'] && @function_exists('bzopen')) {
205 $compressions .= ', bzip2';
207 if ($cfg['ZipDump'] && @function_exists('zip_open')) {
208 $compressions .= ', zip';
211 // We don't have show anything about compression, when no supported
212 if ($compressions != $strNone) {
213 echo '<div class="formelementrow">' . "\n";
214 printf($strCompressionWillBeDetected, $compressions);
215 echo '</div>' . "\n";
217 echo "\n";
219 </fieldset>
220 <fieldset class="options">
221 <legend><?php echo $strPartialImport; ?></legend>
223 <?php
224 if (isset($timeout_passed) && $timeout_passed) {
225 echo '<div class="formelementrow">' . "\n";
226 echo '<input type="hidden" name="skip" value="' . $offset . '" />';
227 echo sprintf($strTimeoutInfo, $offset) . '';
228 echo '</div>' . "\n";
231 <div class="formelementrow">
232 <input type="checkbox" name="allow_interrupt" value="yes"
233 id="checkbox_allow_interrupt" <?php echo PMA_pluginCheckboxCheck('Import', 'allow_interrupt'); ?>/>
234 <label for="checkbox_allow_interrupt"><?php echo $strAllowInterrupt; ?></label><br />
235 </div>
237 <?php
238 if (! (isset($timeout_passed) && $timeout_passed)) {
240 <div class="formelementrow">
241 <label for="text_skip_queries"><?php echo $strSkipQueries; ?></label>
242 <input type="text" name="skip_queries" value="<?php echo PMA_pluginGetDefault('Import', 'skip_queries');?>" id="text_skip_queries" />
243 </div>
244 <?php
245 } else {
246 // If timeout has passed,
247 // do not show the Skip dialog to avoid the risk of someone
248 // entering a value here that would interfere with "skip"
250 <input type="hidden" name="skip_queries" value="<?php echo PMA_pluginGetDefault('Import', 'skip_queries');?>" id="text_skip_queries" />
251 <?php
254 </fieldset>
256 <fieldset class="options">
257 <legend><?php echo $strImportFormat; ?></legend>
258 <?php
259 // Let's show format options now
260 echo '<div style="float: left;">';
261 echo PMA_pluginGetChoice('Import', 'format', $import_list);
262 echo '</div>';
264 echo '<div style="float: left;">';
265 echo PMA_pluginGetOptions('Import', $import_list);
266 echo '</div>';
268 <div class="clearfloat"></div>
269 </fieldset>
270 <?php
271 // Encoding setting form appended by Y.Kawada
272 if (function_exists('PMA_set_enc_form')) {
273 echo PMA_set_enc_form(' ');
275 echo "\n";
277 <fieldset class="tblFooters">
278 <input type="submit" value="<?php echo $strGo; ?>" id="buttonGo" />
279 </fieldset>
280 </form>
281 </div>
282 <script type="text/javascript">
283 //<![CDATA[
284 init_options();
285 //]]>
286 </script>