} while (false); // End of fake loop if ($save_on_server && !empty($message)) { PMA_showExportPage($db, $table, $export_type); } /** * Send the dump as a file... */ if (empty($asfile)) { echo PMA_getHtmlForDisplayedExportFooter($back_button); return; } // end if // Convert the charset if required. if ($output_charset_conversion) { $dump_buffer = Encoding::convertString('utf-8', $GLOBALS['charset'], $dump_buffer); } // Compression needed? if ($compression) { if (!empty($separate_files)) { $dump_buffer = PMA_compressExport($dump_buffer_objects, $compression, $filename); } else { $dump_buffer = PMA_compressExport($dump_buffer, $compression, $filename); } } /* If we saved on server, we have to close file now */ if ($save_on_server) { $message = PMA_closeExportFile($file_handle, $dump_buffer, $save_filename); PMA_showExportPage($db, $table, $export_type); } else { echo $dump_buffer;
/** * Prints Html For Export Options * * @param String $export_type Selected Export Type * * @return string */ function PMA_getHtmlForExportOptionsOutput($export_type) { global $cfg; $html = '<div class="exportoptions" id="output">'; $html .= '<h3>' . __('Output:') . '</h3>'; $html .= '<ul id="ul_output">'; $html .= '<li><input type="checkbox" id="btn_alias_config" '; if (isset($_SESSION['tmpval']['aliases']) && !PMA_emptyRecursive($_SESSION['tmpval']['aliases'])) { $html .= 'checked="checked"'; } unset($_SESSION['tmpval']['aliases']); $html .= '/>'; $html .= '<label for="btn_alias_config">'; $html .= __('Rename exported databases/tables/columns'); $html .= '</label></li>'; if ($export_type != 'server') { $html .= '<li>'; $html .= '<input type="checkbox" name="lock_tables"'; $html .= ' value="something" id="checkbox_lock_tables"'; if (!isset($_GET['repopulate'])) { $html .= PMA_exportCheckboxCheck('lock_tables') . '/>'; } elseif (isset($_GET['lock_tables'])) { $html .= ' checked="checked"'; } $html .= '<label for="checkbox_lock_tables">'; $html .= sprintf(__('Use %s statement'), '<code>LOCK TABLES</code>'); $html .= '</label></li>'; } $html .= '<li>'; $html .= '<input type="radio" name="output_format" value="sendit" '; $html .= 'id="radio_dump_asfile" '; if (!isset($_GET['repopulate'])) { $html .= PMA_exportCheckboxCheck('asfile'); } $html .= '/>'; $html .= '<label for="radio_dump_asfile">' . __('Save output to a file') . '</label>'; $html .= '<ul id="ul_save_asfile">'; if (isset($cfg['SaveDir']) && !empty($cfg['SaveDir'])) { $html .= PMA_getHtmlForExportOptionsOutputSaveDir(); } $html .= PMA_getHtmlForExportOptionsOutputFormat($export_type); // charset of file if (Encoding::isSupported()) { $html .= PMA_getHtmlForExportOptionsOutputCharset(); } // end if $html .= PMA_getHtmlForExportOptionsOutputCompression(); if ($export_type == 'server' || $export_type == 'database') { $html .= PMA_getHtmlForExportOptionsOutputSeparateFiles($export_type); } $html .= '</ul>'; $html .= '</li>'; $html .= PMA_getHtmlForExportOptionsOutputRadio(); $html .= '</ul>'; /* * @todo use sprintf() for better translatability, while keeping the * <label></label> principle (for screen readers) */ $html .= '<label for="maxsize">' . __('Skip tables larger than') . '</label>'; $html .= '<input type="text" id="maxsize" name="maxsize" size="4">' . __('MiB'); $html .= '</div>'; return $html; }
/** * Prints Html For Display Import options : Format * * @param ImportPlugin[] $import_list import list * * @return string */ function PMA_getHtmlForImportOptionsFormat($import_list) { $html = ' <div class="importoptions">'; $html .= ' <h3>' . __('Format:') . '</h3>'; $html .= PMA_pluginGetChoice('Import', 'format', $import_list); $html .= ' <div id="import_notification"></div>'; $html .= ' </div>'; $html .= ' <div class="importoptions" id="format_specific_opts">'; $html .= ' <h3>' . __('Format-specific options:') . '</h3>'; $html .= ' <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>'; $html .= PMA_pluginGetOptions('Import', $import_list); $html .= ' </div>'; $html .= ' <div class="clearfloat"></div>'; // Japanese encoding setting if (Encoding::canConvertKanji()) { $html .= ' <div class="importoptions" id="kanji_encoding">'; $html .= ' <h3>' . __('Encoding Conversion:') . '</h3>'; $html .= Encoding::kanjiEncodingForm(); $html .= ' </div>'; } $html .= "\n"; return $html; }
} // use isset() because zip compression type does not use a handle if (!$error && isset($import_handle) && $import_handle === false) { $message = PMA\libraries\Message::error(__('File could not be read!')); PMA_stopImport($message); } } elseif (!$error) { if (!isset($import_text) || empty($import_text)) { $message = PMA\libraries\Message::error(__('No data was received to import. Either no file name was ' . 'submitted, or the file size exceeded the maximum size permitted ' . 'by your PHP configuration. See [doc@faq1-16]FAQ 1.16[/doc].')); PMA_stopImport($message); } } // so we can obtain the message //$_SESSION['Import_message'] = $message->getDisplay(); // Convert the file's charset if necessary if (Encoding::isSupported() && isset($charset_of_file)) { if ($charset_of_file != 'utf-8') { $charset_conversion = true; } } elseif (isset($charset_of_file) && $charset_of_file != 'utf-8') { $GLOBALS['dbi']->query('SET NAMES \'' . $charset_of_file . '\''); // We can not show query in this case, it is in different charset $sql_query_disabled = true; $reset_charset = true; } // Something to skip? (because timeout has passed) if (!$error && isset($_POST['skip'])) { $original_skip = $skip = $_POST['skip']; while ($skip > 0) { PMA_importGetNextChunk($skip < $read_limit ? $skip : $read_limit); // Disable read progressivity, otherwise we eat all memory!
/** * Test for PMA_getHtmlForSqlQueryForm * * @return void */ public function testPMAGetHtmlForSqlQueryForm() { //Call the test function $GLOBALS['is_upload'] = true; $GLOBALS['lang'] = 'ja'; $query = "select * from PMA"; $html = PMA_getHtmlForSqlQueryForm($query); //validate 1: query $this->assertContains(htmlspecialchars($query), $html); //validate 2: $enctype $enctype = ' enctype="multipart/form-data"'; $this->assertContains($enctype, $html); //validate 3: sqlqueryform $this->assertContains('id="sqlqueryform" name="sqlform">', $html); //validate 4: $db, $table $table = $GLOBALS['table']; $db = $GLOBALS['db']; $this->assertContains(URL::getHiddenInputs($db, $table), $html); //validate 5: $goto $goto = empty($GLOBALS['goto']) ? 'tbl_sql.php' : $GLOBALS['goto']; $this->assertContains(htmlspecialchars($goto), $html); //validate 6: Kanji encoding form $this->assertContains(Encoding::kanjiEncodingForm(), $html); $GLOBALS['lang'] = 'en'; }
/** * return HTML for the sql query boxes * * @param boolean|string $query query to display in the textarea * or true to display last executed * @param boolean|string $display_tab sql|full|false * what part to display * false if not inside querywindow * @param string $delimiter delimiter * * @return string * * @usedby server_sql.php * @usedby db_sql.php * @usedby tbl_sql.php * @usedby tbl_structure.php * @usedby tbl_tracking.php */ function PMA_getHtmlForSqlQueryForm($query = true, $display_tab = false, $delimiter = ';') { $html = ''; if (!$display_tab) { $display_tab = 'full'; } // query to show if (true === $query) { $query = $GLOBALS['sql_query']; } // set enctype to multipart for file uploads if ($GLOBALS['is_upload']) { $enctype = ' enctype="multipart/form-data"'; } else { $enctype = ''; } $table = ''; $db = ''; if (strlen($GLOBALS['db']) === 0) { // prepare for server related $goto = empty($GLOBALS['goto']) ? 'server_sql.php' : $GLOBALS['goto']; } elseif (strlen($GLOBALS['table']) === 0) { // prepare for db related $db = $GLOBALS['db']; $goto = empty($GLOBALS['goto']) ? 'db_sql.php' : $GLOBALS['goto']; } else { $table = $GLOBALS['table']; $db = $GLOBALS['db']; $goto = empty($GLOBALS['goto']) ? 'tbl_sql.php' : $GLOBALS['goto']; } // start output $html .= '<form method="post" action="import.php" ' . $enctype; $html .= ' class="ajax lock-page"'; $html .= ' id="sqlqueryform" name="sqlform">' . "\n"; $html .= '<input type="hidden" name="is_js_confirmed" value="0" />' . "\n" . URL::getHiddenInputs($db, $table) . "\n" . '<input type="hidden" name="pos" value="0" />' . "\n" . '<input type="hidden" name="goto" value="' . htmlspecialchars($goto) . '" />' . "\n" . '<input type="hidden" name="message_to_show" value="' . __('Your SQL query has been executed successfully.') . '" />' . "\n" . '<input type="hidden" name="prev_sql_query" value="' . htmlspecialchars($query) . '" />' . "\n"; // display querybox if ($display_tab === 'full' || $display_tab === 'sql') { $html .= PMA_getHtmlForSqlQueryFormInsert($query, $delimiter); } // Bookmark Support if ($display_tab === 'full') { $cfgBookmark = Bookmark::getParams(); if ($cfgBookmark) { $html .= PMA_getHtmlForSqlQueryFormBookmark(); } } // Japanese encoding setting if (Encoding::canConvertKanji()) { $html .= Encoding::kanjiEncodingForm(); } $html .= '</form>' . "\n"; // print an empty div, which will be later filled with // the sql query results by ajax $html .= '<div id="sqlqueryresultsouter"></div>'; return $html; }
/** * Returns next part of imported file/buffer * * @param int $size size of buffer to read * (this is maximal size function will return) * * @return string part of file/buffer * @access public */ function PMA_importGetNextChunk($size = 32768) { global $compression, $import_handle, $charset_conversion, $charset_of_file, $read_multiply; // Add some progression while reading large amount of data if ($read_multiply <= 8) { $size *= $read_multiply; } else { $size *= 8; } $read_multiply++; // We can not read too much if ($size > $GLOBALS['read_limit']) { $size = $GLOBALS['read_limit']; } if (PMA_checkTimeout()) { return false; } if ($GLOBALS['finished']) { return true; } if ($GLOBALS['import_file'] == 'none') { // Well this is not yet supported and tested, // but should return content of textarea if (mb_strlen($GLOBALS['import_text']) < $size) { $GLOBALS['finished'] = true; return $GLOBALS['import_text']; } else { $r = mb_substr($GLOBALS['import_text'], 0, $size); $GLOBALS['offset'] += $size; $GLOBALS['import_text'] = mb_substr($GLOBALS['import_text'], $size); return $r; } } $result = $import_handle->read($size); $GLOBALS['finished'] = $import_handle->eof(); $GLOBALS['offset'] += $size; if ($charset_conversion) { return Encoding::convertString($charset_of_file, 'utf-8', $result); } /** * Skip possible byte order marks (I do not think we need more * charsets, but feel free to add more, you can use wikipedia for * reference: <https://en.wikipedia.org/wiki/Byte_Order_Mark>) * * @todo BOM could be used for charset autodetection */ if ($GLOBALS['offset'] == $size) { // UTF-8 if (strncmp($result, "", 3) == 0) { $result = mb_substr($result, 3); // UTF-16 BE, LE } elseif (strncmp($result, "þÿ", 2) == 0 || strncmp($result, "ÿþ", 2) == 0) { $result = mb_substr($result, 2); } } return $result; }
/** * Output handler for all exports, if needed buffering, it stores data into * $dump_buffer, otherwise it prints them out. * * @param string $line the insert statement * * @return bool Whether output succeeded */ function PMA_exportOutputHandler($line) { global $time_start, $dump_buffer, $dump_buffer_len, $save_filename; // Kanji encoding convert feature if ($GLOBALS['output_kanji_conversion']) { $line = Encoding::kanjiStrConv($line, $GLOBALS['knjenc'], isset($GLOBALS['xkana']) ? $GLOBALS['xkana'] : ''); } // If we have to buffer data, we will perform everything at once at the end if ($GLOBALS['buffer_needed']) { $dump_buffer .= $line; if ($GLOBALS['onfly_compression']) { $dump_buffer_len += strlen($line); if ($dump_buffer_len > $GLOBALS['memory_limit']) { if ($GLOBALS['output_charset_conversion']) { $dump_buffer = Encoding::convertString('utf-8', $GLOBALS['charset'], $dump_buffer); } if ($GLOBALS['compression'] == 'gzip' && PMA_gzencodeNeeded()) { // as a gzipped file // without the optional parameter level because it bugs $dump_buffer = gzencode($dump_buffer); } if ($GLOBALS['save_on_server']) { $write_result = @fwrite($GLOBALS['file_handle'], $dump_buffer); // Here, use strlen rather than mb_strlen to get the length // in bytes to compare against the number of bytes written. if ($write_result != strlen($dump_buffer)) { $GLOBALS['message'] = Message::error(__('Insufficient space to save the file %s.')); $GLOBALS['message']->addParam($save_filename); return false; } } else { echo $dump_buffer; } $dump_buffer = ''; $dump_buffer_len = 0; } } else { $time_now = time(); if ($time_start >= $time_now + 30) { $time_start = $time_now; header('X-pmaPing: Pong'); } // end if } } else { if ($GLOBALS['asfile']) { if ($GLOBALS['output_charset_conversion']) { $line = Encoding::convertString('utf-8', $GLOBALS['charset'], $line); } if ($GLOBALS['save_on_server'] && mb_strlen($line) > 0) { $write_result = @fwrite($GLOBALS['file_handle'], $line); // Here, use strlen rather than mb_strlen to get the length // in bytes to compare against the number of bytes written. if (!$write_result || $write_result != strlen($line)) { $GLOBALS['message'] = Message::error(__('Insufficient space to save the file %s.')); $GLOBALS['message']->addParam($save_filename); return false; } $time_now = time(); if ($time_start >= $time_now + 30) { $time_start = $time_now; header('X-pmaPing: Pong'); } // end if } else { // We export as file - output normally echo $line; } } else { // We export as html - replace special chars echo htmlspecialchars($line); } } return true; }
/** * Test for Encoding::kanjiEncodingForm * * @return void * @test */ public function testEncodingForm() { $actual = Encoding::kanjiEncodingForm(); $this->assertContains('<input type="radio" name="knjenc"', $actual); $this->assertContains('type="radio" name="knjenc"', $actual); $this->assertContains('<input type="radio" name="knjenc" value="EUC-JP" id="kj-euc" />', $actual); $this->assertContains('<input type="radio" name="knjenc" value="SJIS" id="kj-sjis" />', $actual); $this->assertContains('<input type="checkbox" name="xkana" value="kana" id="kj-kana" />', $actual); }