Files
CKEditor_4.6.1
Date
backup
bibelpopup
classes
config
fetch_bibel
fetch_chorbuch
images
jpgraph
kalender
language
lib
lieder
livesearch
msd
overlib
pma
doc
examples
js
libraries
cache
certs
classes
Charsets
Command
Config
Controllers
Database
Dbal
Display
Engines
Exceptions
Export
Options.php
Template.php
TemplateModel.php
Gis
Html
Import
Navigation
Plugins
Properties
Providers
Query
Server
Setup
Table
Twig
Utils
Advisor.php
Bookmark.php
BrowseForeigners.php
Charsets.php
CheckUserPrivileges.php
Config.php
Console.php
Core.php
CreateAddField.php
DatabaseInterface.php
DbTableExists.php
Encoding.php
Error.php
ErrorHandler.php
ErrorReport.php
Export.php
File.php
FileListing.php
Font.php
Footer.php
Git.php
Header.php
Import.php
Index.php
IndexColumn.php
InsertEdit.php
InternalRelations.php
IpAllowDeny.php
Language.php
LanguageManager.php
Linter.php
ListAbstract.php
ListDatabase.php
Logging.php
Menu.php
Message.php
Mime.php
Normalization.php
OpenDocument.php
Operations.php
OutputBuffering.php
ParseAnalyze.php
Partition.php
Pdf.php
Plugins.php
Profiling.php
RecentFavoriteTable.php
Relation.php
RelationCleanup.php
Replication.php
ReplicationGui.php
ReplicationInfo.php
Response.php
Routing.php
Sanitize.php
SavedSearches.php
Scripts.php
Session.php
Sql.php
SqlQueryForm.php
StorageEngine.php
SubPartition.php
SystemDatabase.php
Table.php
TablePartitionDefinition.php
Template.php
Theme.php
ThemeManager.php
Tracker.php
Tracking.php
Transformations.php
TwoFactor.php
Types.php
Url.php
UserPassword.php
UserPreferences.php
Util.php
Version.php
VersionInformation.php
ZipExtension.php
advisory_rules_generic.php
advisory_rules_mysql_before80003.php
common.inc.php
config.default.php
config.values.php
language_stats.inc.php
routes.php
services.php
services_controllers.php
services_loader.php
vendor_config.php
locale
setup
sql
templates
themes
tmp
vendor
CONTRIBUTING.md
ChangeLog
LICENSE
README
RELEASE-DATE-5.1.1
babel.config.json
composer.json
composer.lock
config.inc.php
config.sample.inc.php
favicon.ico
index.php
package.json
print.css
robots.txt
show_config_errors.php
url.php
yarn.lock
templates
templates_c
test
validation
vendor
++ Umstellung Luther 2017.sql
.gitattributes
.htaccess
MyOOS-Dumper-master.zip
Version8_bugs.txt
ansicht.php
ansicht2.php
ausgabe.php
bes_gd.php
bibellookup_1984.php
bibellookup_2017.php
changelog.php
composer.json
composer.lock
config.inc.php
copy.js
faq_text.php
faq_text_ber.php
favicon.ico
fetch_data.php
ftp_ansicht.php
func_agent.php
func_ansicht.php
func_genUser.php
func_highlight.php
func_htmlclean.php
func_make_knk.php
func_make_knk_fa.php
func_make_reference_fa.php
func_rollenrechte.php
func_write_lue_kat.php
further_publication.php
getSubCat.php
graph.php
graph_einzel.php
graph_hauptframe.php
graph_user.php
graph_user_hauptframe.php
hauptframe.php
hello.cgi
hello.pl
hilfe.php
historie.php
index.php
index2.php
indexframe.php
info.php
job_mail_delete_neue_user.php
job_mail_inaktiv.php
job_user_delete_neue_user.php
job_user_inaktiv.php
jquery.min.js
kat_cont.php
kat_cont_fa.php
kat_main.php
kat_main_fa.php
katechismus.php
katechismus_fa.php
lesung.php
lieder.php
livesearch.php
livestat.js
livestat.php
livestat2.php
login_log.php
logininfo.php
logout_admin.php
lue_ansicht.php
lue_bearbeiten.php
lue_erfassen.php
lue_inhalt.php
lue_notizen.php
lue_suche.php
lue_wahl.php
mail.php
make_ical.php
menuframe.php
nachsenden.php
notizen.php
outlook.php
outlook.php_20200212
outlook_ics.php
outlook_vcs.php
passwort_switch.php
pdf_gen.php
preview.php
profil.php
rollen.php
search_note.php
stichworte.php
suche.php
suche_change.php
suche_simp.php
systemmail.php
test.php
test2.php
testmail.php
testmail2.php
topframe.php
upload.php
user_anlegen.php
user_bearbeiten.php
useronline.php
verweise.php
wort_bearbeiten.php
wort_erfassen.php
wort_exegese.php
wort_wahl.php
Leitgedanken/pma/libraries/classes/Export/Options.php
2022-11-21 09:47:28 +01:00

243 lines
8.3 KiB
PHP

<?php
declare(strict_types=1);
namespace PhpMyAdmin\Export;
use PhpMyAdmin\Core;
use PhpMyAdmin\Encoding;
use PhpMyAdmin\Plugins;
use PhpMyAdmin\Plugins\ExportPlugin;
use PhpMyAdmin\Query\Utilities;
use PhpMyAdmin\Relation;
use PhpMyAdmin\Table;
use PhpMyAdmin\Util;
use function explode;
use function function_exists;
use function in_array;
use function is_array;
use function mb_strpos;
use function strlen;
use function urldecode;
final class Options
{
/** @var Relation */
private $relation;
/** @var TemplateModel */
private $templateModel;
public function __construct(Relation $relation, TemplateModel $templateModel)
{
$this->relation = $relation;
$this->templateModel = $templateModel;
}
/**
* Outputs appropriate checked statement for checkbox.
*
* @param string $str option name
*
* @return bool
*/
private function checkboxCheck($str)
{
return isset($GLOBALS['cfg']['Export'][$str])
&& $GLOBALS['cfg']['Export'][$str];
}
/**
* Prints Html For Export Selection Options
*
* @param string $tmpSelect Tmp selected method of export
*
* @return array
*/
public function getDatabasesForSelectOptions($tmpSelect = '')
{
// Check if the selected databases are defined in $_POST
// (from clicking Back button on /export page)
if (isset($_POST['db_select'])) {
$_POST['db_select'] = urldecode($_POST['db_select']);
$_POST['db_select'] = explode(',', $_POST['db_select']);
}
$databases = [];
foreach ($GLOBALS['dblist']->databases as $currentDb) {
if (Utilities::isSystemSchema($currentDb, true)) {
continue;
}
$isSelected = false;
if (isset($_POST['db_select'])) {
if (in_array($currentDb, $_POST['db_select'])) {
$isSelected = true;
}
} elseif (! empty($tmpSelect)) {
if (mb_strpos(
' ' . $tmpSelect,
'|' . $currentDb . '|'
)) {
$isSelected = true;
}
} else {
$isSelected = true;
}
$databases[] = [
'name' => $currentDb,
'is_selected' => $isSelected,
];
}
return $databases;
}
/**
* @param string $exportType export type: server|database|table
* @param string $db selected DB
* @param string $table selected table
* @param string $sqlQuery SQL query
* @param int|string $numTables number of tables
* @param int|string $unlimNumRows unlimited number of rows
* @param ExportPlugin[] $exportList
*
* @return array<string, mixed>
*/
public function getOptions(
$exportType,
$db,
$table,
$sqlQuery,
$numTables,
$unlimNumRows,
array $exportList
) {
global $cfg;
$cfgRelation = $this->relation->getRelationsParam();
$templates = [];
if ($cfgRelation['exporttemplateswork']) {
$templates = $this->templateModel->getAll(
$cfgRelation['db'],
$cfgRelation['export_templates'],
$GLOBALS['cfg']['Server']['user'],
$exportType
);
$templates = is_array($templates) ? $templates : [];
}
$dropdown = Plugins::getChoice('Export', 'what', $exportList, 'format');
$tableObject = new Table($table, $db);
$rows = [];
if (strlen($table) > 0 && empty($numTables) && ! $tableObject->isMerge() && $exportType !== 'raw') {
$rows = [
'allrows' => $_POST['allrows'] ?? null,
'limit_to' => $_POST['limit_to'] ?? null,
'limit_from' => $_POST['limit_from'] ?? null,
'unlim_num_rows' => $unlimNumRows,
'number_of_rows' => $tableObject->countRecords(),
];
}
$hasAliases = isset($_SESSION['tmpval']['aliases']) && ! Core::emptyRecursive($_SESSION['tmpval']['aliases']);
$aliases = $_SESSION['tmpval']['aliases'] ?? [];
unset($_SESSION['tmpval']['aliases']);
$filenameTemplate = $this->getFileNameTemplate($exportType, $_POST['filename_template'] ?? null);
$isEncodingSupported = Encoding::isSupported();
$selectedCompression = $_POST['compression'] ?? $cfg['Export']['compression'] ?? 'none';
if (isset($cfg['Export']['as_separate_files']) && $cfg['Export']['as_separate_files']) {
$selectedCompression = 'zip';
}
$hiddenInputs = [
'db' => $db,
'table' => $table,
'export_type' => $exportType,
'export_method' => $_POST['export_method'] ?? $cfg['Export']['method'] ?? 'quick',
'template_id' => $_POST['template_id'] ?? '',
];
if (! empty($GLOBALS['single_table'])) {
$hiddenInputs['single_table'] = true;
}
if (! empty($sqlQuery)) {
$hiddenInputs['sql_query'] = $sqlQuery;
}
return [
'export_type' => $exportType,
'db' => $db,
'table' => $table,
'templates' => [
'is_enabled' => $cfgRelation['exporttemplateswork'],
'templates' => $templates,
'selected' => $_POST['template_id'] ?? null,
],
'sql_query' => $sqlQuery,
'hidden_inputs' => $hiddenInputs,
'export_method' => $_POST['quick_or_custom'] ?? $cfg['Export']['method'] ?? '',
'dropdown' => $dropdown,
'options' => Plugins::getOptions('Export', $exportList),
'can_convert_kanji' => Encoding::canConvertKanji(),
'exec_time_limit' => $cfg['ExecTimeLimit'],
'rows' => $rows,
'has_save_dir' => isset($cfg['SaveDir']) && ! empty($cfg['SaveDir']),
'save_dir' => Util::userDir($cfg['SaveDir'] ?? ''),
'export_is_checked' => $this->checkboxCheck('quick_export_onserver'),
'export_overwrite_is_checked' => $this->checkboxCheck('quick_export_onserver_overwrite'),
'has_aliases' => $hasAliases,
'aliases' => $aliases,
'is_checked_lock_tables' => $this->checkboxCheck('lock_tables'),
'is_checked_asfile' => $this->checkboxCheck('asfile'),
'is_checked_as_separate_files' => $this->checkboxCheck('as_separate_files'),
'is_checked_export' => $this->checkboxCheck('onserver'),
'is_checked_export_overwrite' => $this->checkboxCheck('onserver_overwrite'),
'is_checked_remember_file_template' => $this->checkboxCheck('remember_file_template'),
'repopulate' => isset($_POST['repopulate']),
'lock_tables' => isset($_POST['lock_tables']),
'is_encoding_supported' => $isEncodingSupported,
'encodings' => $isEncodingSupported ? Encoding::listEncodings() : [],
'export_charset' => $cfg['Export']['charset'],
'export_asfile' => $cfg['Export']['asfile'],
'has_zip' => $cfg['ZipDump'] && function_exists('gzcompress'),
'has_gzip' => $cfg['GZipDump'] && function_exists('gzencode'),
'selected_compression' => $selectedCompression,
'filename_template' => $filenameTemplate,
];
}
private function getFileNameTemplate(string $exportType, ?string $filename = null): string
{
global $cfg, $PMA_Config;
if ($filename !== null) {
return $filename;
}
if ($exportType === 'database') {
return (string) $PMA_Config->getUserValue(
'pma_db_filename_template',
$cfg['Export']['file_template_database']
);
}
if ($exportType === 'table') {
return (string) $PMA_Config->getUserValue(
'pma_table_filename_template',
$cfg['Export']['file_template_table']
);
}
return (string) $PMA_Config->getUserValue(
'pma_server_filename_template',
$cfg['Export']['file_template_server']
);
}
}