2019-11-12 21:25:37 +01:00
|
|
|
<?PHP
|
|
|
|
declare(strict_types = 1);
|
2020-10-31 00:00:26 +01:00
|
|
|
require_once __DIR__ . "/../functions/functions.php";
|
2019-11-12 21:25:37 +01:00
|
|
|
|
|
|
|
if (session_status() != PHP_SESSION_ACTIVE) {
|
|
|
|
session_start();
|
|
|
|
}
|
|
|
|
|
|
|
|
// This array contains all available languages
|
2022-03-15 10:29:19 +01:00
|
|
|
$allowed_langs = ['ar', 'de', 'en', 'hu', 'id', 'it', 'pl', 'pt'];
|
2019-11-12 21:25:37 +01:00
|
|
|
|
|
|
|
// Some languages are in translation. They will only be available for logged in users.
|
|
|
|
|
|
|
|
if (isset($_GET['navlang'])) {
|
|
|
|
$_SESSION['lang'] = $_GET['navlang'];
|
|
|
|
if (!in_array($_SESSION['lang'], $allowed_langs)) $_SESSION['lang'] = 'de';
|
|
|
|
}
|
|
|
|
else if (!isset($_SESSION['lang'])) {
|
2020-08-10 20:13:16 +02:00
|
|
|
$_SESSION['lang'] = MD_STD::lang_getfrombrowser($allowed_langs, 'en', "", false);
|
2019-11-12 21:25:37 +01:00
|
|
|
}
|
|
|
|
$lang = $_SESSION['lang'];
|
|
|
|
|
|
|
|
if (empty($filename = trim($_GET['fnam'], " ,./"))) {
|
|
|
|
echo "Error: Invalid file name";
|
|
|
|
exit;
|
|
|
|
}
|
2020-10-31 00:00:26 +01:00
|
|
|
$csv_datei = MD_STD::realpath(__DIR__ . '/../csv/' . $filename);
|
2019-11-12 21:25:37 +01:00
|
|
|
|
2020-10-31 00:00:26 +01:00
|
|
|
if (is_dir(__DIR__ . "/../xml")) rrmdir(__DIR__ . '/../xml');
|
2020-11-08 14:30:14 +01:00
|
|
|
mkdir(__DIR__ . "/../xml", CACHE_DIR_PERMS);
|
2019-11-12 21:25:37 +01:00
|
|
|
|
2020-09-06 00:08:07 +02:00
|
|
|
if (!($fp = fopen($csv_datei, 'r'))) {
|
|
|
|
throw new MDmainEntityNotExistentException("Failed opening file");
|
|
|
|
}
|
2019-11-12 21:25:37 +01:00
|
|
|
$y = 0;
|
2022-03-15 10:29:19 +01:00
|
|
|
while ($zeile = fgetcsv($fp, 100000, ';', "\"")) {
|
2019-11-12 21:25:37 +01:00
|
|
|
|
|
|
|
$zeile = str_replace("\xEF\xBB\xBF", '', $zeile);
|
|
|
|
|
|
|
|
$y++;
|
|
|
|
|
2020-11-08 14:44:06 +01:00
|
|
|
$zieldatei = __DIR__ . '/../xml/' . $y . '.xml';
|
2019-11-12 21:25:37 +01:00
|
|
|
if (!$handle = fopen($zieldatei, 'w')) {
|
2022-03-15 10:29:19 +01:00
|
|
|
echo "Cannot open file ($zieldatei)";
|
|
|
|
exit;
|
2019-11-12 21:25:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$xmlDoc = new DOMDocument("1.0", "UTF-8");
|
|
|
|
$xmlDoc->preserveWhiteSpace = false;
|
|
|
|
$xmlDoc->formatOutput = true;
|
|
|
|
# $xmlDoc->encoding = 'utf-8';
|
|
|
|
$xmlMainElem = $xmlDoc->createElement("record");
|
|
|
|
$record_node = $xmlDoc->appendChild($xmlMainElem); //add record element to XML node
|
|
|
|
# $rss_node->setAttribute("version", "2.0"); //set RSS version
|
|
|
|
|
2022-03-15 10:29:19 +01:00
|
|
|
if (empty($lineCount)) $lineCount = count($zeile);
|
2019-11-12 21:25:37 +01:00
|
|
|
|
|
|
|
for ($x = 0; $x < $lineCount; $x++) {
|
|
|
|
$inhalt[$y][$x] = $zeile[$x];
|
|
|
|
if ($inhalt[$y][$x] == '') $inhalt[$y][$x] = 'ERSATZ';
|
|
|
|
|
2022-03-15 10:29:19 +01:00
|
|
|
if (!isset($inhalt[1][$x])) {
|
|
|
|
echo "Error at position $x";
|
|
|
|
}
|
|
|
|
|
|
|
|
$record_node->appendChild(createTextDomElement($xmlDoc, trim($inhalt[1][$x] ?? ""), trim($inhalt[$y][$x] ?? "")));
|
2019-11-12 21:25:37 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$somecontent = '<?xml version="1.0" encoding="UTF-8"?>' . $xmlDoc->saveXML($xmlDoc->documentElement);
|
|
|
|
|
|
|
|
# $somecontent .= '</record>';
|
|
|
|
//if ($y>1)
|
|
|
|
//{
|
2022-03-15 10:29:19 +01:00
|
|
|
if (fwrite($handle, $somecontent) === false) {
|
|
|
|
echo "Cannot write to file ($filename)";
|
|
|
|
exit;
|
2019-11-12 21:25:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fclose($handle);
|
|
|
|
}
|
|
|
|
fclose($fp);
|
|
|
|
|
|
|
|
|
|
|
|
echo printHTMLHead();
|
|
|
|
|
|
|
|
echo '
|
|
|
|
<div>
|
|
|
|
' . ($y - 1) . ' files created<br />
|
|
|
|
<hr/>
|
|
|
|
<a href="zipit.php" class="buttonLike">Download as ZIP</a>
|
|
|
|
</div>';
|