Add a lot of new fields with improved and more integrated checks for

dependencies and allowed values
This commit is contained in:
Joshua Ramon Enslin 2019-09-01 19:54:01 +02:00 committed by Stefan Rohde-Enslin
parent b8a03e1509
commit 13395387a0
11 changed files with 556 additions and 693 deletions

1
.gitignore vendored
View File

@ -4,3 +4,4 @@
*.swp *.swp
*.swo *.swo
commonservices commonservices
/xml

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "mdAvailableLicenses"]
path = mdAvailableLicenses
url = /var/www/vhosts/museum-digital.de/git-base/mdAvailableLicenses

View File

@ -81,11 +81,6 @@ th { padding: .3em .5em; text-align: left; border-bottom: 2px solid #424242; }
tbody > tr:nth-child(2n + 1) { background: #F2F2F2; } tbody > tr:nth-child(2n + 1) { background: #F2F2F2; }
td { padding: .3em .5em; border-bottom: 1px solid #D6D6D6; } td { padding: .3em .5em; border-bottom: 1px solid #D6D6D6; }
@media screen and (min-width:1100px) {
textarea,
body > div > table { width: 1000px; margin-left: -200px; }
}
body > div.uploader { background: #F2F2F2; border: 2px solid #EEE; padding: 1em 1em; } body > div.uploader { background: #F2F2F2; border: 2px solid #EEE; padding: 1em 1em; }
ul.fieldList { display: block; margin: .5em 0; padding: 0 0; list-style: none; } ul.fieldList { display: block; margin: .5em 0; padding: 0 0; list-style: none; }

15
csv.php
View File

@ -38,10 +38,10 @@ require __DIR__ . "/values/availableFields.php";
$line1 = $line2 = $line3 = $line4 = []; $line1 = $line2 = $line3 = $line4 = [];
$tLine1 = $tLine2 = $tLine3 = $tLine4 = [];
foreach ($availableFields as $headline => $fields) { foreach ($availableFields as $headline => $fields) {
$i = 0; $i = 0;
$tLine1 = $tLine2 = $tLine3 = $tLine4 = [];
$tLine1[] = $headline; $tLine1[] = $headline;
foreach($fields as $fieldName => $field) { foreach($fields as $fieldName => $field) {
@ -53,11 +53,14 @@ foreach ($availableFields as $headline => $fields) {
if ($i !== 0) $tLine1[] = ""; if ($i !== 0) $tLine1[] = "";
$tLine2[] = $fieldName; $tLine2[] = $fieldName;
$tLine3[] = $field['name_human_readable']; $tLine3[] = $field['name_human_readable'];
$tLine4[] = $field['remark']; # $tLine4[] = $field['remark'];
if (!empty($field['allowedValues'])) $tLine4[] = end($field['allowedValues']);
else $tLine4[] = $field['name_human_readable'];
$i++; $i++;
} }
if (empty($tLine2)) continue; if (empty($tLine2) or count($tLine2) === 0) continue;
for ($i = 1; $i <= 4; $i++) { for ($i = 1; $i <= 4; $i++) {
${"line$i"} = array_merge(${"line$i"}, ${"tLine$i"}); ${"line$i"} = array_merge(${"line$i"}, ${"tLine$i"});
@ -65,12 +68,12 @@ foreach ($availableFields as $headline => $fields) {
} }
header('Content-Type: text/csv'); header('Content-Type: text/csv; charset=utf-8');
if ($selectionActive === true) if ($selectionActive === true)
header("Content-Disposition: attachment; filename=csvxml_museum-digital_template-{$lang}_selection.csv"); header("Content-Disposition: attachment; filename=csvxml_museum-digital_template-{$lang}_selection.csv");
else else
header("Content-Disposition: attachment; filename=csvxml_museum-digital_template-{$lang}.csv"); header("Content-Disposition: attachment; filename=csvxml_museum-digital_template-{$lang}.csv");
for ($i = 1; $i <= 4; $i++) { for ($i = 2; $i <= 4; $i++) {
echo '"' . implode("\";\"", ${"line$i"}) . '"' . PHP_EOL; echo mb_convert_encoding('"' . implode("\";\"", ${"line$i"}) . '"' . PHP_EOL, 'utf-16','utf-8');;
} }

File diff suppressed because one or more lines are too long

View File

@ -157,3 +157,64 @@ function generateHelpTooltip(string $identifier, string $title, string $explica,
return [$output, $outputTag]; return [$output, $outputTag];
} }
/**
* Outputs a DOMDocument with correct header and then aborts.
* Used mainly for debugging.
*
* @param DOMDocument $xmlDoc XML object.
*
* @return void
*/
function printDOMDocToXML(DOMDocument $xmlDoc) {
return '<?xml version="1.0" encoding="UTF-8"?>' . $xmlDoc->saveXML($xmlDoc->documentElement);
}
/**
* Function for creating a DOMElement with a text node inside.
*
* @param DOMDocument $xmlDoc XML document.
* @param string $tag Tag.
* @param string $content Text content.
*
* @return DOMElement
*/
function createTextDomElement(DOMDocument $xmlDoc, string $tag, string $content):DOMElement {
$element = $xmlDoc->createElement($tag);
$element->appendChild($xmlDoc->createTextNode($content));
return $element;
}
/**
* Function for creating a DOMDocument record channel.
*
* @return array
*/
function getBlankRecordChannel():array {
$xmlDoc = new DOMDocument("1.0", "UTF-8");
$xmlMainElem = $xmlDoc->createElement("record");
$record_node = $xmlDoc->appendChild($xmlMainElem); //add RSS element to XML node
return [$xmlDoc, $record_node];
}
function rrmdir($dir) {
if (is_dir($dir)) {
$objects = scandir($dir);
foreach ($objects as $object) {
if ($object != "." && $object != "..") {
if (filetype($dir . "/" . $object) == "dir") rrmdir($dir . "/" . $object); else unlink($dir . "/" . $object);
}
}
reset($objects);
rmdir($dir);
}
}

View File

@ -1,9 +1,32 @@
<?PHP <?PHP
$semikoma = $_GET['semikoma']; declare(strict_types = 1);
echo '<link rel="stylesheet" type="text/css" href="css/main.css">'; error_reporting(E_ALL);
echo '<div class="title">'; ini_set('display_errors', "1");
echo 'museum-digital CSV to XML converter';
echo '</div>'; require_once __DIR__ . "/functions/functions.php";
if (session_status() != PHP_SESSION_ACTIVE) {
session_start();
}
// This array contains all available languages
$allowed_langs = ['ar', 'de', 'en', 'hu', 'id', 'it', 'pl','pt'];
// 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'])) {
$_SESSION['lang'] = lang_getfrombrowser($allowed_langs, 'en', "", false);
}
$lang = $_SESSION['lang'];
require __DIR__ . "/translation-importer/$lang/csvxml-overview.php";
echo printHTMLHead();
echo '<div class="maincontent">'; echo '<div class="maincontent">';
echo '<table border="0" cellpadding="0" cellspacing="0" summary="" width="100%">'; echo '<table border="0" cellpadding="0" cellspacing="0" summary="" width="100%">';
echo '<tr>'; echo '<tr>';
@ -13,11 +36,11 @@ require_once 'inc/zeichen.php';
$filename = $_GET['fnam']; $filename = $_GET['fnam'];
$csv_datei = 'csv/' . $filename; $csv_datei = 'csv/' . $filename;
mkdir("xml", 0777); mkdir("xml", 0755);
$fp = fopen ( $csv_datei, 'r' ); $fp = fopen ( $csv_datei, 'r' );
$y = 0; $y = 0;
while ( $zeile = fgetcsv ( $fp, 100000, ';' ) ) while ($zeile = fgetcsv($fp, 100000, ';')) {
{
$y++; $y++;
$zieldatei = 'xml/' . $y . '.xml'; $zieldatei = 'xml/' . $y . '.xml';
if (!$handle = fopen($zieldatei, 'w')) { if (!$handle = fopen($zieldatei, 'w')) {
@ -26,8 +49,7 @@ while ( $zeile = fgetcsv ( $fp, 100000, ';' ) )
$somecontent = '<?xml version="1.0" encoding="ISO-8859-1"?>' . "\n"; // normal $somecontent = '<?xml version="1.0" encoding="ISO-8859-1"?>' . "\n"; // normal
$somecontent = $somecontent . '<record>' . "\n"; $somecontent = $somecontent . '<record>' . "\n";
for ($x = 0; $x < count ( $zeile ); $x++) for ($x = 0; $x < count ($zeile); $x++) {
{
$inhalt[$y][$x] = $zeile[$x]; $inhalt[$y][$x] = $zeile[$x];
//if ($inhalt[$y][$x]=='') $inhalt[$y][$x]='ERSATZ'; //if ($inhalt[$y][$x]=='') $inhalt[$y][$x]='ERSATZ';
$somecontent = $somecontent . '<' . tagify(transform($inhalt[1][$x])) . '>' . transform($inhalt[$y][$x]) . '</' . tagify(transform($inhalt[1][$x])) . '>' . "\n"; //normaleinstellung $somecontent = $somecontent . '<' . tagify(transform($inhalt[1][$x])) . '>' . transform($inhalt[$y][$x]) . '</' . tagify(transform($inhalt[1][$x])) . '>' . "\n"; //normaleinstellung
@ -45,3 +67,9 @@ echo '</td>';
echo '</tr>'; echo '</tr>';
echo '</table>'; echo '</table>';
echo '</div>'; echo '</div>';
echo '
</body>
</html>
';

View File

@ -1,27 +1,41 @@
<?PHP <?PHP
//error_reporting(E_ALL); declare(strict_types = 1);
//ini_set('display_errors',1); error_reporting(E_ALL);
$semikoma = $_GET['semikoma']; ini_set('display_errors', "1");
echo '<link rel="stylesheet" type="text/css" href="css/main.css">';
echo '<div class="title">'; require_once __DIR__ . "/functions/functions.php";
echo 'museum-digital CSV to XML converter';
echo '</div>'; if (session_status() != PHP_SESSION_ACTIVE) {
echo '<div class="maincontent">'; session_start();
echo '<table border="0" cellpadding="0" cellspacing="0" summary="" width="100%">'; }
echo '<tr>';
echo '<td width="50%">'; // This array contains all available languages
echo 'Please wait ... (transforming)<hr>'; $allowed_langs = ['ar', 'de', 'en', 'hu', 'id', 'it', 'pl','pt'];
ob_start();
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />'; // für ungarn sonst weg ////////////////////// // 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'])) {
$_SESSION['lang'] = lang_getfrombrowser($allowed_langs, 'en', "", false);
}
$lang = $_SESSION['lang'];
require __DIR__ . "/translation-importer/$lang/csvxml-overview.php";
require 'inc/zeichen.php'; require 'inc/zeichen.php';
$filename = $_GET['fnam']; $filename = $_GET['fnam'];
$csv_datei = 'csv/' . $filename; $csv_datei = 'csv/' . $filename;
mkdir("xml", 0777); if (is_dir(__DIR__ . "/xml")) rrmdir(__DIR__ . '/xml');
$fp = fopen ( $csv_datei, 'r' ); mkdir("xml", 0755);
$fp = fopen ($csv_datei, 'r');
$y = 0; $y = 0;
while ( $zeile = fgetcsv ( $fp, 100000, ';' ) ) while ($zeile = fgetcsv($fp, 100000, ';')) {
{
$y++; $y++;
$zieldatei = 'xml/' . $y . '.xml'; $zieldatei = 'xml/' . $y . '.xml';
if (!$handle = fopen($zieldatei, 'w')) { if (!$handle = fopen($zieldatei, 'w')) {
@ -35,6 +49,7 @@ while ( $zeile = fgetcsv ( $fp, 100000, ';' ) )
$inhalt[$y][$x] = $zeile[$x]; $inhalt[$y][$x] = $zeile[$x];
$inhalt[$y][$x] = preg_replace('/[\x00-\x1F\x7F]/u', '', $inhalt[$y][$x]); $inhalt[$y][$x] = preg_replace('/[\x00-\x1F\x7F]/u', '', $inhalt[$y][$x]);
$inhalt[$y][$x] = str_replace('>', ']', str_replace('<', '[', $inhalt[$y][$x])); $inhalt[$y][$x] = str_replace('>', ']', str_replace('<', '[', $inhalt[$y][$x]));
if (empty($inhalt[$y][$x])) continue;
//if ($y!=1) $inhalt[$y][$x] = '<![CDATA['.$inhalt[$y][$x].']]>'; //if ($y!=1) $inhalt[$y][$x] = '<![CDATA['.$inhalt[$y][$x].']]>';
$somecontent = $somecontent . '<' . tagify(transform($inhalt[1][$x])) . '>' . (($inhalt[$y][$x])) . '</' . tagify(transform($inhalt[1][$x])) . '>' . "\n"; //für ungarn sonst weg } $somecontent = $somecontent . '<' . tagify(transform($inhalt[1][$x])) . '>' . (($inhalt[$y][$x])) . '</' . tagify(transform($inhalt[1][$x])) . '>' . "\n"; //für ungarn sonst weg }
} }
@ -43,11 +58,25 @@ while ( $zeile = fgetcsv ( $fp, 100000, ';' ) )
echo "Cannot write to file ($filename)";exit; echo "Cannot write to file ($filename)";exit;
} }
fclose($handle); fclose($handle);
} }
fclose($fp); fclose($fp);
echo ($y - 1) . ' files created';
echo '<br><a href="zipit.php"><img src="img/go.gif"> Download as zip</a>'; echo printHTMLHead();
echo '</td>';
echo '</tr>'; echo '
echo '</table>'; <div>
echo '</div>'; Please wait ... (transforming)
<hr />
' . ($y - 1) . ' files created
<br/>
<a href="zipit.php"><img src="img/go.gif"> Download as zip</a>
</div>';
echo '
</body>
</html>
';

1
mdAvailableLicenses Submodule

@ -0,0 +1 @@
Subproject commit 1a1f237024dfda63108f1ff84a8d6b4d137642a4

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,8 @@
<?PHP <?PHP
require_once "inc/zip.php"; require_once "inc/zip.php";
require_once __DIR__ . "/functions/functions.php";
$fileTime = date("D, d M Y H:i:s T"); $fileTime = date("D, d M Y H:i:s T");
$fileDir = 'xml/'; $fileDir = 'xml/';
@ -38,20 +41,5 @@ header("Content-Transfer-Encoding: binary");
header("Content-Length: " . $length); header("Content-Length: " . $length);
echo $zipData; echo $zipData;
function rrmdir($dir) { rrmdir(__DIR__ . '/xml');
if (is_dir($dir)) {
$objects = scandir($dir);
foreach ($objects as $object) {
if ($object != "." && $object != "..") {
if (filetype($dir . "/" . $object) == "dir") rrmdir($dir . "/" . $object); else unlink($dir . "/" . $object);
}
}
reset($objects);
rmdir($dir);
}
}
$dir_name = 'xml';
rrmdir($dir_name);