Ran PHPCBF

phpcs-errors:253 phpunit-status:successful
This commit is contained in:
Joshua Ramon Enslin 2019-11-12 21:25:37 +01:00 committed by Stefan Rohde-Enslin
parent bf985ae192
commit d6470110e9
6 changed files with 2477 additions and 2469 deletions

View File

@ -1,376 +1,376 @@
<?PHP <?PHP
declare(strict_types = 1); declare(strict_types = 1);
error_reporting(E_ALL); error_reporting(E_ALL);
ini_set('display_errors', "1"); ini_set('display_errors', "1");
require_once __DIR__ . "/functions/functions.php"; require_once __DIR__ . "/functions/functions.php";
if (session_status() != PHP_SESSION_ACTIVE) { if (session_status() != PHP_SESSION_ACTIVE) {
session_start(); session_start();
} }
// This array contains all available languages // This array contains all available languages
$allowed_langs = ['ar', 'de', 'en', 'hu', 'id', 'it', 'pl','pt']; $allowed_langs = ['ar', 'de', 'en', 'hu', 'id', 'it', 'pl','pt'];
// Some languages are in translation. They will only be available for logged in users. // Some languages are in translation. They will only be available for logged in users.
if (isset($_GET['navlang'])) { if (isset($_GET['navlang'])) {
$_SESSION['lang'] = $_GET['navlang']; $_SESSION['lang'] = $_GET['navlang'];
if (!in_array($_SESSION['lang'], $allowed_langs)) $_SESSION['lang'] = 'de'; if (!in_array($_SESSION['lang'], $allowed_langs)) $_SESSION['lang'] = 'de';
} }
else if (!isset($_SESSION['lang'])) { else if (!isset($_SESSION['lang'])) {
$_SESSION['lang'] = lang_getfrombrowser($allowed_langs, 'en', "", false); $_SESSION['lang'] = lang_getfrombrowser($allowed_langs, 'en', "", false);
} }
$lang = $_SESSION['lang']; $lang = $_SESSION['lang'];
$filename = $_GET['fnam']; $filename = $_GET['fnam'];
$csv_datei = 'csv/' . $filename; $csv_datei = 'csv/' . $filename;
// Get allowed values // Get allowed values
require __DIR__ . "/values/availableFields.php"; require __DIR__ . "/values/availableFields.php";
$allowed = $eventpart = $eventpartsure = $fieldsWithDependency = $fieldsWithAllowedValueSet = []; $allowed = $eventpart = $eventpartsure = $fieldsWithDependency = $fieldsWithAllowedValueSet = [];
foreach ($availableFields as $categoryName => $fieldCategory) { foreach ($availableFields as $categoryName => $fieldCategory) {
$allowed = array_merge($allowed, array_keys($fieldCategory)); $allowed = array_merge($allowed, array_keys($fieldCategory));
// Extended operations for events // Extended operations for events
if (strpos($categoryName, $basis['event']) !== false) { if (strpos($categoryName, $basis['event']) !== false) {
foreach ($fieldCategory as $key => $value) { foreach ($fieldCategory as $key => $value) {
if (strpos($key, "_annotation") !== false) continue; if (strpos($key, "_annotation") !== false) continue;
if (strpos($key, "_sure") !== false) $eventpartsure[] = $key; if (strpos($key, "_sure") !== false) $eventpartsure[] = $key;
else $eventpart[] = $key; else $eventpart[] = $key;
} }
} }
foreach ($fieldCategory as $key => $value) { foreach ($fieldCategory as $key => $value) {
if (!empty($value["dependsOn"])) { if (!empty($value["dependsOn"])) {
$fieldsWithDependency[$key] = $value['dependsOn']; $fieldsWithDependency[$key] = $value['dependsOn'];
} }
if (!empty($value["allowedValues"])) { if (!empty($value["allowedValues"])) {
$fieldsWithAllowedValueSet[$key] = $value['allowedValues']; $fieldsWithAllowedValueSet[$key] = $value['allowedValues'];
} }
} }
} }
$allowed_inclusion_kind_of = array('inclusion_kind_of', 'Schenkung', 'Kauf', 'Grabung', 'Notbergung', 'Erbschaft', 'Stiftung', 'Enteignung', 'Ursprungsbestand', 'Ajándékozás','Vétel','Feltárás','Hivatalos átadás','Csere','Gyűjtés','Saját előállítás','Törzsanyag','Letét', 'endowment', 'dispossession', 'old stock', ''); $allowed_inclusion_kind_of = ['inclusion_kind_of', 'Schenkung', 'Kauf', 'Grabung', 'Notbergung', 'Erbschaft', 'Stiftung', 'Enteignung', 'Ursprungsbestand', 'Ajándékozás','Vétel','Feltárás','Hivatalos átadás','Csere','Gyűjtés','Saját előállítás','Törzsanyag','Letét', 'endowment', 'dispossession', 'old stock', ''];
///// Check #1 ///// Check #1
//echo '<pre>';print_r($allowed);echo '</pre>'; //echo '<pre>';print_r($allowed);echo '</pre>';
echo '1: Only allowed tags (column names) used?'; echo '1: Only allowed tags (column names) used?';
$fp = fopen ( $csv_datei, 'r' ); $fp = fopen ( $csv_datei, 'r' );
$y = 1; $y = 1;
$error = 0; $error = 0;
$zeile = fgetcsv( $fp, 100000, ';' ); $zeile = fgetcsv( $fp, 100000, ';' );
for ($x = 0; $x < count($zeile); $x++) { for ($x = 0; $x < count($zeile); $x++) {
$zeile[$x] = str_replace("\xEF\xBB\xBF", "", $zeile[$x]); $zeile[$x] = str_replace("\xEF\xBB\xBF", "", $zeile[$x]);
$inhalt[$y][$x] = $zeile[$x]; $inhalt[$y][$x] = $zeile[$x];
if (!in_array($inhalt[1][$x], $allowed)) { if (!in_array($inhalt[1][$x], $allowed)) {
echo '<br><i style="font-style:normal;color:#990000;">ERROR in column ' . $x . ' created by value: ' . $inhalt[1][$x] . '</i>'; echo '<br><i style="font-style:normal;color:#990000;">ERROR in column ' . $x . ' created by value: ' . $inhalt[1][$x] . '</i>';
$error = $error + 1; $error = $error + 1;
} }
//echo '<br/>';var_dump($inhalt[1][$x]); //echo '<br/>';var_dump($inhalt[1][$x]);
} }
fclose($fp); fclose($fp);
$erstezeile = $zeile; $erstezeile = $zeile;
if ($error != 0) echo '<br><b style="color:#990000;">Not allowed tags found !</b>'; else echo '<br><i style="font-style:normal;color:#009900;">Only allowed tags used !</i>'; if ($error != 0) echo '<br><b style="color:#990000;">Not allowed tags found !</b>'; else echo '<br><i style="font-style:normal;color:#009900;">Only allowed tags used !</i>';
//// Check #2 //// Check #2
echo '<br><br>2: Not allowed multiple use of tags (column names)?'; echo '<br><br>2: Not allowed multiple use of tags (column names)?';
$compare = array_unique($zeile); $compare = array_unique($zeile);
$result = identical_values($zeile, $compare); $result = identical_values($zeile, $compare);
if ($result == false) { if ($result == false) {
echo '<br><b style="color:#990000;">There are dublicate column names !</b>'; echo '<br><b style="color:#990000;">There are dublicate column names !</b>';
$error = $error + 1; $error = $error + 1;
} }
else { else {
echo '<br><i style="font-style:normal;color:#009900;">No dublicate column names !</i>'; echo '<br><i style="font-style:normal;color:#009900;">No dublicate column names !</i>';
} }
//// Get values into memory for following checks //// Get values into memory for following checks
$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++;
for ($x = 0; $x < count ( $zeile ); $x++) { for ($x = 0; $x < count ( $zeile ); $x++) {
$inhalt[$y][$x] = str_replace("'", "\'", $zeile[$x]); $inhalt[$y][$x] = str_replace("'", "\'", $zeile[$x]);
} }
} }
fclose($fp); fclose($fp);
///// Check #3 ///// Check #3
echo '<br><br>3: Mandatory tags available and always filled in?'; echo '<br><br>3: Mandatory tags available and always filled in?';
unset($inv_array); unset($inv_array);
$inv_error = 0; $inv_error = 0;
function get_duplicates($array) { function get_duplicates($array) {
return array_unique( array_diff_assoc( $array, array_unique( $array ) ) ); return array_unique( array_diff_assoc( $array, array_unique( $array ) ) );
} }
$mandatory = array('inventory_number','object_type','object_title','object_description'); $mandatory = ['inventory_number','object_type','object_title','object_description'];
for ($i = 0; $i < count($mandatory); $i++) { for ($i = 0; $i < count($mandatory); $i++) {
if (!in_array($mandatory[$i], $erstezeile)) { if (!in_array($mandatory[$i], $erstezeile)) {
echo '<br><i style="font-style:normal;color:#990000;">Mandatory: Column <b>' . $mandatory[$i] . '</b> missing</i>'; echo '<br><i style="font-style:normal;color:#990000;">Mandatory: Column <b>' . $mandatory[$i] . '</b> missing</i>';
$error = $error + 1; $error = $error + 1;
$inv_error = $inv_error + 1; $inv_error = $inv_error + 1;
} }
else { else {
$spaltenr = array_search($mandatory[$i], $erstezeile); $spaltenr = array_search($mandatory[$i], $erstezeile);
for ($j = 0; $j < $y; $j++) { for ($j = 0; $j < $y; $j++) {
if ($inhalt[$j + 1][$spaltenr] == '') { if ($inhalt[$j + 1][$spaltenr] == '') {
echo '<br><i style="font-style:normal;color:#990000;">Missing value for <b>' . $mandatory[$i] . '</b> in row ' . ($j + 1) . '</i>'; echo '<br><i style="font-style:normal;color:#990000;">Missing value for <b>' . $mandatory[$i] . '</b> in row ' . ($j + 1) . '</i>';
$error = $error + 1; $error = $error + 1;
$inv_error = $inv_error + 1; $inv_error = $inv_error + 1;
} }
if ($mandatory[$i] == 'inventory_number') { if ($mandatory[$i] == 'inventory_number') {
$inv_array[] = $inhalt[$j + 1][$spaltenr]; $inv_array[] = $inhalt[$j + 1][$spaltenr];
} }
} }
} }
} }
if ($inv_error == 0) echo '<br><i style="font-style:normal;color:#009900;">All mandatory tags available and with values !</i>'; if ($inv_error == 0) echo '<br><i style="font-style:normal;color:#009900;">All mandatory tags available and with values !</i>';
///// Check #4 ///// Check #4
echo '<br><br>4: Inventory_number unique ?'; echo '<br><br>4: Inventory_number unique ?';
if (in_array('inventory_number', $erstezeile)) { if (in_array('inventory_number', $erstezeile)) {
$doppelte_inv = get_duplicates($inv_array); $doppelte_inv = get_duplicates($inv_array);
$doppelte_inv = array_values($doppelte_inv); $doppelte_inv = array_values($doppelte_inv);
if (count($doppelte_inv) > 0) { if (count($doppelte_inv) > 0) {
for ($i = 0; $i < count($doppelte_inv); $i++) for ($i = 0; $i < count($doppelte_inv); $i++)
{ {
echo '<br><i style="font-style:normal;color:#990000;">Multiple use of inventory_number <b>' . $doppelte_inv[$i] . '</b></i>'; echo '<br><i style="font-style:normal;color:#990000;">Multiple use of inventory_number <b>' . $doppelte_inv[$i] . '</b></i>';
$error = $error + 1; $error = $error + 1;
} }
} }
else echo '<br><i style="font-style:normal;color:#009900;">All inventory_numbers are unique !</i>'; else echo '<br><i style="font-style:normal;color:#009900;">All inventory_numbers are unique !</i>';
} }
else else
{ {
echo '<br><b style="font-style:normal;color:#990000;">Aborted, column inventory_number is missing</b>'; echo '<br><b style="font-style:normal;color:#990000;">Aborted, column inventory_number is missing</b>';
$error = $error + 1; $error = $error + 1;
} }
///// Check #5 ///// Check #5
echo '<br><br>5: Dependent colums observed ?<br>'; echo '<br><br>5: Dependent colums observed ?<br>';
// Check for correct handling of dependent fields // Check for correct handling of dependent fields
foreach ($fieldsWithDependency as $tField => $tDependentFields) { foreach ($fieldsWithDependency as $tField => $tDependentFields) {
if (array_search($tField, $erstezeile) === false) continue; if (array_search($tField, $erstezeile) === false) continue;
foreach ($tDependentFields as $tDependentField) { foreach ($tDependentFields as $tDependentField) {
if (array_search($tDependentField, $erstezeile) === false) { if (array_search($tDependentField, $erstezeile) === false) {
$depencymessage[] = "Dependency issue at column $tField: Corresponding column $tDependentField is missing"; $depencymessage[] = "Dependency issue at column $tField: Corresponding column $tDependentField is missing";
} }
} }
} }
if (isset($depencymessage) and $depencymessage != '') { if (isset($depencymessage) and $depencymessage != '') {
echo '<b style="color:#990000;">Dependent columns were not observed !</b>'; echo '<b style="color:#990000;">Dependent columns were not observed !</b>';
for ($i = 0; $i < count ($depencymessage); $i++) for ($i = 0; $i < count ($depencymessage); $i++)
{ {
echo '<br>' . $depencymessage[$i]; echo '<br>' . $depencymessage[$i];
$error = $error + 1; $error = $error + 1;
} }
} }
else { else {
echo '<i style="font-style:normal;color:#009900;">Dependent columns were observed !</i>'; echo '<i style="font-style:normal;color:#009900;">Dependent columns were observed !</i>';
} }
///// Check #6 ///// Check #6
echo '<br><br>6: Dependency of content observed?'; echo '<br><br>6: Dependency of content observed?';
$crosscheck1 = array('object_other_title','detailed_description','detailed_description','inscription','inscription','dimensions_separate_length_value', 'dimensions_separate_width_value', 'dimensions_separate_height_value', 'dimensions_separate_diameter_value', 'dimensions_separate_wall_thickness_value', 'dimensions_separate_weight_value','closer_location','bought_for','worth_value','worth_insurance_value'); $crosscheck1 = ['object_other_title','detailed_description','detailed_description','inscription','inscription','dimensions_separate_length_value', 'dimensions_separate_width_value', 'dimensions_separate_height_value', 'dimensions_separate_diameter_value', 'dimensions_separate_wall_thickness_value', 'dimensions_separate_weight_value','closer_location','bought_for','worth_value','worth_insurance_value'];
$crosscheck2 = array('object_other_title_kind_of','detailed_description_md','detailed_description_extern','inscription_md','inscription_extern','dimensions_separate_length_unit', 'dimensions_separate_width_unit', 'dimensions_separate_height_unit', 'dimensions_separate_diameter_unit', 'dimensions_separate_wall_thickness_unit', 'dimensions_separate_weight_unit','closer_location_as','bought_for_currency','worth_unit','worth_insurance_unit'); $crosscheck2 = ['object_other_title_kind_of','detailed_description_md','detailed_description_extern','inscription_md','inscription_extern','dimensions_separate_length_unit', 'dimensions_separate_width_unit', 'dimensions_separate_height_unit', 'dimensions_separate_diameter_unit', 'dimensions_separate_wall_thickness_unit', 'dimensions_separate_weight_unit','closer_location_as','bought_for_currency','worth_unit','worth_insurance_unit'];
$depcon_error = 0; $depcon_error = 0;
for ($l = 0; $l < count($crosscheck1); $l++) { for ($l = 0; $l < count($crosscheck1); $l++) {
if (in_array($crosscheck1[$l], $erstezeile)) { if (in_array($crosscheck1[$l], $erstezeile)) {
for ($j = 1; $j < ($y + 1); $j++) { for ($j = 1; $j < ($y + 1); $j++) {
if ($inhalt[$j][array_search($crosscheck2[$l], $erstezeile)] !== '' and $inhalt[$j][array_search($crosscheck1[$l], $erstezeile)] == '') { if ($inhalt[$j][array_search($crosscheck2[$l], $erstezeile)] !== '' and $inhalt[$j][array_search($crosscheck1[$l], $erstezeile)] == '') {
echo '<br>Tag <b>' . $crosscheck2[$l] . '</b> given but no entry for <b>' . $crosscheck1[$l] . '</b> (row ' . $j . ')'; echo '<br>Tag <b>' . $crosscheck2[$l] . '</b> given but no entry for <b>' . $crosscheck1[$l] . '</b> (row ' . $j . ')';
$depcon_error = $depcon_error + 1; $depcon_error = $depcon_error + 1;
} }
} }
} }
} }
for ($l = 0; $l < count($eventpart); $l++) { for ($l = 0; $l < count($eventpart); $l++) {
if (in_array($eventpart[$l], $erstezeile)) { if (in_array($eventpart[$l], $erstezeile)) {
for ($j = 1; $j < ($y + 1); $j++) { for ($j = 1; $j < ($y + 1); $j++) {
if ($inhalt[$j][array_search($eventpartsure[$l], $erstezeile)] !== '' and $inhalt[$j][array_search($eventpart[$l], $erstezeile)] == '') { if ($inhalt[$j][array_search($eventpartsure[$l], $erstezeile)] !== '' and $inhalt[$j][array_search($eventpart[$l], $erstezeile)] == '') {
echo '<br>Tag <b>' . $eventpartsure[$l] . '</b> given but no entry for <b>' . $eventpart[$l] . '</b> (row ' . $j . ')'; echo '<br>Tag <b>' . $eventpartsure[$l] . '</b> given but no entry for <b>' . $eventpart[$l] . '</b> (row ' . $j . ')';
$depcon_error = $depcon_error + 1; $depcon_error = $depcon_error + 1;
} }
} }
} }
} }
if (in_array('dimensions_separate_show_md', $erstezeile)) { if (in_array('dimensions_separate_show_md', $erstezeile)) {
for ($j = 1; $j < ($y + 1); $j++) for ($j = 1; $j < ($y + 1); $j++)
{ {
if ($inhalt[$j][array_search('dimensions_separate_show_md', $erstezeile)] !== '' and ($inhalt[$j][array_search('dimensions_separate_length_value', $erstezeile)] == '') and $inhalt[$j][array_search('dimensions_separate_width_value', $erstezeile)] == '' and $inhalt[$j][array_search('dimensions_separate_heigt_value', $erstezeile)] == '' and $inhalt[$j][array_search('dimensions_separate_weight_value', $erstezeile)] == '' and $inhalt[$j][array_search('dimensions_separate_diameter_value', $erstezeile)] == '' and $inhalt[$j][array_search('dimensions_separate_wall_thickness_value', $erstezeile)] == '') { if ($inhalt[$j][array_search('dimensions_separate_show_md', $erstezeile)] !== '' and ($inhalt[$j][array_search('dimensions_separate_length_value', $erstezeile)] == '') and $inhalt[$j][array_search('dimensions_separate_width_value', $erstezeile)] == '' and $inhalt[$j][array_search('dimensions_separate_heigt_value', $erstezeile)] == '' and $inhalt[$j][array_search('dimensions_separate_weight_value', $erstezeile)] == '' and $inhalt[$j][array_search('dimensions_separate_diameter_value', $erstezeile)] == '' and $inhalt[$j][array_search('dimensions_separate_wall_thickness_value', $erstezeile)] == '') {
echo '<br>Tag <b>dimensions_separate_show_md</b> given but no separate values available (row ' . $j . ')'; echo '<br>Tag <b>dimensions_separate_show_md</b> given but no separate values available (row ' . $j . ')';
$depcon_error = $depcon_error + 1; $depcon_error = $depcon_error + 1;
} }
} }
} }
if (in_array('dimensions_separate_show_extern', $erstezeile)) { if (in_array('dimensions_separate_show_extern', $erstezeile)) {
for ($j = 1; $j < ($y + 1); $j++) { for ($j = 1; $j < ($y + 1); $j++) {
if ($inhalt[$j][array_search('dimensions_separate_show_extern', $erstezeile)] !== '' and ($inhalt[$j][array_search('dimensions_separate_length_value', $erstezeile)] == '') and $inhalt[$j][array_search('dimensions_separate_width_value', $erstezeile)] == '' and $inhalt[$j][array_search('dimensions_separate_heigt_value', $erstezeile)] == '' and $inhalt[$j][array_search('dimensions_separate_weight_value', $erstezeile)] == '' and $inhalt[$j][array_search('dimensions_separate_diameter_value', $erstezeile)] == '' and $inhalt[$j][array_search('dimensions_separate_wall_thickness_value', $erstezeile)] == '') { if ($inhalt[$j][array_search('dimensions_separate_show_extern', $erstezeile)] !== '' and ($inhalt[$j][array_search('dimensions_separate_length_value', $erstezeile)] == '') and $inhalt[$j][array_search('dimensions_separate_width_value', $erstezeile)] == '' and $inhalt[$j][array_search('dimensions_separate_heigt_value', $erstezeile)] == '' and $inhalt[$j][array_search('dimensions_separate_weight_value', $erstezeile)] == '' and $inhalt[$j][array_search('dimensions_separate_diameter_value', $erstezeile)] == '' and $inhalt[$j][array_search('dimensions_separate_wall_thickness_value', $erstezeile)] == '') {
echo '<br>Tag <b>dimensions_separate_show_extern</b> given but no separate values available (row ' . $j . ')'; echo '<br>Tag <b>dimensions_separate_show_extern</b> given but no separate values available (row ' . $j . ')';
$depcon_error = $depcon_error + 1; $depcon_error = $depcon_error + 1;
} }
} }
} }
/* /*
for ($im=1;$im<11;$im++) for ($im=1;$im<11;$im++)
{ {
if (in_array('image_name'.$im,$erstezeile)) if (in_array('image_name'.$im,$erstezeile))
{ {
for ($j=1;$j<($y+1);$j++) for ($j=1;$j<($y+1);$j++)
{ {
if ($inhalt[$j][array_search('image_rights'.$im,$erstezeile)]!=='') if ($inhalt[$j][array_search('image_rights'.$im,$erstezeile)]!=='')
{ {
echo '<br>TAG <b>image_name'.$im.'</b> given but no value available for image_rights'.$im.' (row '.$j.')'; echo '<br>TAG <b>image_name'.$im.'</b> given but no value available for image_rights'.$im.' (row '.$j.')';
$depcon_error=$depcon_error+1; $depcon_error=$depcon_error+1;
} }
if ($inhalt[$j][array_search('image_visible'.$im,$erstezeile)]!=='') if ($inhalt[$j][array_search('image_visible'.$im,$erstezeile)]!=='')
{ {
echo '<br>TAG <b>image_name'.$im.'</b> given but no value available for image_visible'.$im.' (row '.$j.')'; echo '<br>TAG <b>image_name'.$im.'</b> given but no value available for image_visible'.$im.' (row '.$j.')';
$depcon_error=$depcon_error+1; $depcon_error=$depcon_error+1;
} }
} }
} }
} }
*/ */
if ($depcon_error == 0) echo '<br><i style="font-style:normal;color:#009900;">Dependency of content was observed !</i>'; if ($depcon_error == 0) echo '<br><i style="font-style:normal;color:#009900;">Dependency of content was observed !</i>';
///// Check #7 ///// Check #7
echo '<br><br>7: Not allowed values in controlled lists?<br>'; echo '<br><br>7: Not allowed values in controlled lists?<br>';
for ($i = 2; $i <= $y; $i++) { for ($i = 2; $i <= $y; $i++) {
foreach ($inhalt[$i] as $key => $value) { foreach ($inhalt[$i] as $key => $value) {
$columnName = $inhalt[1][$key]; $columnName = $inhalt[1][$key];
// If the field is not restricted, then continue // If the field is not restricted, then continue
if (!isset($fieldsWithAllowedValueSet[$columnName])) continue; if (!isset($fieldsWithAllowedValueSet[$columnName])) continue;
// For others: check if the value is from the list of allowed values. // For others: check if the value is from the list of allowed values.
if (!in_array($value, $fieldsWithAllowedValueSet[$columnName])) { if (!in_array($value, $fieldsWithAllowedValueSet[$columnName])) {
// It may be that the value is empty together with all dependent fields, // It may be that the value is empty together with all dependent fields,
// because it's in a repeat field that was needed earlier. // because it's in a repeat field that was needed earlier.
if (empty($value) && !empty($fieldsWithDependency[$columnName])) { if (empty($value) && !empty($fieldsWithDependency[$columnName])) {
$allDependentsEmpty = true; $allDependentsEmpty = true;
foreach ($fieldsWithDependency[$columnName] as $depField) { foreach ($fieldsWithDependency[$columnName] as $depField) {
// Find keys of dependent field // Find keys of dependent field
$depFieldKey = array_search($depField, $inhalt[1]); $depFieldKey = array_search($depField, $inhalt[1]);
if (!empty($inhalt[$i][$depFieldKey])) { if (!empty($inhalt[$i][$depFieldKey])) {
$allDependentsEmpty = false; $allDependentsEmpty = false;
break; break;
} }
} }
if ($allDependentsEmpty === true) continue; if ($allDependentsEmpty === true) continue;
} }
$errormessage[] = "Disallowed value in column <code>{$columnName}</code> on row <code>{$i}</code>: <em>" . $value . "</em> (allowed values: <small>" . implode(", ", $fieldsWithAllowedValueSet[$columnName]) . "</small>)"; $errormessage[] = "Disallowed value in column <code>{$columnName}</code> on row <code>{$i}</code>: <em>" . $value . "</em> (allowed values: <small>" . implode(", ", $fieldsWithAllowedValueSet[$columnName]) . "</small>)";
} }
} }
} }
if (isset($errormessage) and $errormessage != '') { if (isset($errormessage) and $errormessage != '') {
echo '<b style="color:#990000;">Columns with controlled values contain invalid values !</b>'; echo '<b style="color:#990000;">Columns with controlled values contain invalid values !</b>';
for ($i = 0; $i < count ($errormessage); $i++) { for ($i = 0; $i < count ($errormessage); $i++) {
echo '<br>' . $errormessage[$i]; echo '<br>' . $errormessage[$i];
$error = $error + 1; $error = $error + 1;
} }
} }
else else
{ {
echo '<i style="font-style:normal;color:#009900;">Values in controlled fields are all valid !</i>'; echo '<i style="font-style:normal;color:#009900;">Values in controlled fields are all valid !</i>';
} }
///// Check #8 ///// Check #8
unset($errormessage); unset($errormessage);
echo '<br><br>8: Main image or main resource given?<br>'; echo '<br><br>8: Main image or main resource given?<br>';
$hasanyimage = 0; $hasanyimage = 0;
for ($im = 1; $im < 29; $im++) for ($im = 1; $im < 29; $im++)
{ {
if (array_search('image_name' . $im, $erstezeile) != '') {$imagemain[$im]['name'] = array_search('image_name' . $im, $erstezeile);$hasanyimage++; if (array_search('image_name' . $im, $erstezeile) != '') {$imagemain[$im]['name'] = array_search('image_name' . $im, $erstezeile);$hasanyimage++;
} }
if (array_search('image_visible' . $im, $erstezeile) != '') $imagemain[$im]['visible'] = array_search('image_visible' . $im, $erstezeile); if (array_search('image_visible' . $im, $erstezeile) != '') $imagemain[$im]['visible'] = array_search('image_visible' . $im, $erstezeile);
if (array_search('image_main' . $im, $erstezeile) != '') $imagemain[$im]['main'] = array_search('image_main' . $im, $erstezeile); if (array_search('image_main' . $im, $erstezeile) != '') $imagemain[$im]['main'] = array_search('image_main' . $im, $erstezeile);
} }
if ($hasanyimage > 0) { if ($hasanyimage > 0) {
$imagemain = array_values($imagemain); $imagemain = array_values($imagemain);
for ($i = 1; $i <= $y; $i++) for ($i = 1; $i <= $y; $i++)
{ {
if ($i > 1) { if ($i > 1) {
$maimg[$i] = 0; $maimg[$i] = 0;
//check if in a row any image_name is given //check if in a row any image_name is given
$hatimg[$i] = 0; $hatimg[$i] = 0;
for ($im = 0; $im < count($imagemain); $im++) for ($im = 0; $im < count($imagemain); $im++)
{ {
if ($inhalt[$i][$imagemain[$im]['name']] != '') $hatimg[$i]++; if ($inhalt[$i][$imagemain[$im]['name']] != '') $hatimg[$i]++;
} }
if ($hatimg[$i] > 0) { if ($hatimg[$i] > 0) {
// first check: how many main-images? // first check: how many main-images?
for ($im = 0; $im < count($imagemain); $im++) for ($im = 0; $im < count($imagemain); $im++)
{ {
if ($inhalt[$i][$imagemain[$im]['main']] == 'y') {$maimg[$i]++;$merk = $im; if ($inhalt[$i][$imagemain[$im]['main']] == 'y') {$maimg[$i]++;$merk = $im;
} }
} }
// if there is exacly one main-image, is it visible? // if there is exacly one main-image, is it visible?
if ($maimg[$i] == 1) { if ($maimg[$i] == 1) {
if ($inhalt[$i][$imagemain[$merk]['visible']] == 'n') { if ($inhalt[$i][$imagemain[$merk]['visible']] == 'n') {
$errormessage[] = '<b style="font-weight:normal;color:#990000">Main image in row ' . $i . ' is not visible</b>'; $errormessage[] = '<b style="font-weight:normal;color:#990000">Main image in row ' . $i . ' is not visible</b>';
} }
} }
} }
} }
if ($i > 1 and $maimg[$i] == 0 and $hatimg[$i] > 0) $errormessage[] = '<b style="font-weight:normal;color:#990000">There is no visible main image given in row ' . $i . '</b>'; if ($i > 1 and $maimg[$i] == 0 and $hatimg[$i] > 0) $errormessage[] = '<b style="font-weight:normal;color:#990000">There is no visible main image given in row ' . $i . '</b>';
if ($i > 1 and $maimg[$i] > 1 and $hatimg[$i] > 0) $errormessage[] = '<b style="font-weight:normal;color:#990000">There are ' . $maimg[$i] . ' main images given in row ' . $i . '</b>'; if ($i > 1 and $maimg[$i] > 1 and $hatimg[$i] > 0) $errormessage[] = '<b style="font-weight:normal;color:#990000">There are ' . $maimg[$i] . ' main images given in row ' . $i . '</b>';
} }
if (isset($errormessage) and $errormessage != '') { if (isset($errormessage) and $errormessage != '') {
echo '<b style="color:#990000;">There is not one main image for each object !</b>'; echo '<b style="color:#990000;">There is not one main image for each object !</b>';
for ($i = 0; $i < count($errormessage); $i++) { for ($i = 0; $i < count($errormessage); $i++) {
echo '<br>' . $errormessage[$i]; echo '<br>' . $errormessage[$i];
$error++; $error++;
} }
} }
else { else {
echo '<i style="font-style:normal;color:#009900;">For each object that has images attached exactly one main image is given !</i>'; echo '<i style="font-style:normal;color:#009900;">For each object that has images attached exactly one main image is given !</i>';
} }
} }
else { else {
echo '<i style="font-style:normal;color:#009900;">No images to be imported !</i>'; echo '<i style="font-style:normal;color:#009900;">No images to be imported !</i>';
} }
echo '<hr>'; echo '<hr>';
if ($error + $depcon_error > 0) { if ($error + $depcon_error > 0) {
echo ' echo '
<p>Error(s) found: ' . ($error + $depcon_error) . '</p>'; <p>Error(s) found: ' . ($error + $depcon_error) . '</p>';
} }
else { else {
echo '<a href="index6.php?fnam=' . htmlspecialchars($_GET['fnam']) . '" class="buttonLike">Create XML for md:import (utf8)</a><br>'; echo '<a href="index6.php?fnam=' . htmlspecialchars($_GET['fnam']) . '" class="buttonLike">Create XML for md:import (utf8)</a><br>';
} }

View File

@ -1,7 +1,13 @@
<?PHP <?PHP
function transform($transform) /**
{ * Function for sanitizing contents for prospective XML contents.
*
* @param string $transform Input string.
*
* @return string
*/
function transform(string $transform):string {
$transform = str_replace(chr(14), "", $transform); $transform = str_replace(chr(14), "", $transform);
$transform = str_replace('&quot;', '"', $transform); $transform = str_replace('&quot;', '"', $transform);
$transform = str_replace('&', '&amp;', $transform); $transform = str_replace('&', '&amp;', $transform);
@ -24,8 +30,14 @@ function transform($transform)
} }
function tagify($tagify) /**
{ * Function for sanitizing contents for prospective XML contents.
*
* @param string $tagify Input string.
*
* @return string
*/
function tagify(string $tagify):string {
$tagify = str_replace(' ', '_', $tagify); $tagify = str_replace(' ', '_', $tagify);
$tagify = str_replace('/', '_', $tagify); $tagify = str_replace('/', '_', $tagify);
$tagify = str_replace(',', '_', $tagify); $tagify = str_replace(',', '_', $tagify);

View File

@ -11,431 +11,430 @@
* @version 1.1 * @version 1.1
*/ */
class Zip { class Zip {
private $zipMemoryThreshold = 1048576; // Autocreate tempfile if the zip data exceeds 1048576 bytes (1 MB) private $zipMemoryThreshold = 1048576; // Autocreate tempfile if the zip data exceeds 1048576 bytes (1 MB)
private $endOfCentralDirectory = "\x50\x4b\x05\x06\x00\x00\x00\x00"; //end of Central directory record private $endOfCentralDirectory = "\x50\x4b\x05\x06\x00\x00\x00\x00"; //end of Central directory record
private $localFileHeader = "\x50\x4b\x03\x04"; // Local file header signature private $localFileHeader = "\x50\x4b\x03\x04"; // Local file header signature
private $centralFileHeader = "\x50\x4b\x01\x02"; // Central file header signature private $centralFileHeader = "\x50\x4b\x01\x02"; // Central file header signature
private $zipData = null; private $zipData = null;
private $zipFile = null; private $zipFile = null;
private $zipComment = null; private $zipComment = null;
private $cdRec = array(); // central directory private $cdRec = array(); // central directory
private $offset = 0; private $offset = 0;
private $isFinalized = false; private $isFinalized = false;
private $streamChunkSize = 65536; private $streamChunkSize = 65536;
private $streamFilePath = null; private $streamFilePath = null;
private $streamTimeStamp = null; private $streamTimeStamp = null;
private $streamComment = null; private $streamComment = null;
private $streamFile = null; private $streamFile = null;
private $streamData = null; private $streamData = null;
private $streamFileLength = 0; private $streamFileLength = 0;
/** /**
* Constructor. * Constructor.
* *
* @param $useZipFile boolean. Write temp zip data to tempFile? Default false * @param $useZipFile boolean. Write temp zip data to tempFile? Default false
*/ */
function __construct($useZipFile = false) { function __construct($useZipFile = false) {
if ($useZipFile) { if ($useZipFile) {
$this->zipFile = tmpfile(); $this->zipFile = tmpfile();
} else { } else {
$this->zipData = ""; $this->zipData = "";
} }
} }
function __destruct() { function __destruct() {
if (!is_null($this->zipFile)) { if (!is_null($this->zipFile)) {
fclose($this->zipFile); fclose($this->zipFile);
} }
$this->zipData= null; $this->zipData= null;
} }
/** /**
* Set Zip archive comment. * Set Zip archive comment.
* *
* @param string $newComment New comment. null to clear. * @param string $newComment New comment. null to clear.
*/ */
public function setComment($newComment = null) { public function setComment($newComment = null) {
$this->zipComment = $newComment; $this->zipComment = $newComment;
} }
/** /**
* Set zip file to write zip data to. * Set zip file to write zip data to.
* This will cause all present and future data written to this class to be written to this file. * This will cause all present and future data written to this class to be written to this file.
* This can be used at any time, even after the Zip Archive have been finalized. Any previous file will be closed. * This can be used at any time, even after the Zip Archive have been finalized. Any previous file will be closed.
* Warning: If the given file already exists, it will be overwritten. * Warning: If the given file already exists, it will be overwritten.
* *
* @param string $fileName * @param string $fileName
*/ */
public function setZipFile($fileName) { public function setZipFile($fileName) {
if (file_exists($fileName)) { if (file_exists($fileName)) {
unlink ($fileName); unlink ($fileName);
} }
$fd=fopen($fileName, "x+b"); $fd=fopen($fileName, "x+b");
if (!is_null($this->zipFile)) { if (!is_null($this->zipFile)) {
rewind($this->zipFile); rewind($this->zipFile);
while(!feof($this->zipFile)) { while(!feof($this->zipFile)) {
fwrite($fd, fread($this->zipFile, $this->streamChunkSize)); fwrite($fd, fread($this->zipFile, $this->streamChunkSize));
} }
fclose($this->zipFile); fclose($this->zipFile);
} else { } else {
fwrite($fd, $this->zipData); fwrite($fd, $this->zipData);
$this->zipData = null; $this->zipData = null;
} }
$this->zipFile = $fd; $this->zipFile = $fd;
} }
/** /**
* Add an empty directory entry to the zip archive. * Add an empty directory entry to the zip archive.
* Basically this is only used if an empty directory is added. * Basically this is only used if an empty directory is added.
* *
* @param string $directoryPath Directory Path and name to be added to the archive. * @param string $directoryPath Directory Path and name to be added to the archive.
* @param int $timestamp (Optional) Timestamp for the added directory, if omitted or set to 0, the current time will be used. * @param int $timestamp (Optional) Timestamp for the added directory, if omitted or set to 0, the current time will be used.
* @param string $fileComment (Optional) Comment to be added to the archive for this directory. To use fileComment, timestamp must be given. * @param string $fileComment (Optional) Comment to be added to the archive for this directory. To use fileComment, timestamp must be given.
*/ */
public function addDirectory($directoryPath, $timestamp = 0, $fileComment = null) { public function addDirectory($directoryPath, $timestamp = 0, $fileComment = null) {
if ($this->isFinalized) { if ($this->isFinalized) {
return; return;
} }
$this->buildZipEntry($directoryPath, $fileComment, "\x00\x00", "\x00\x00", $timestamp, "\x00\x00\x00\x00", 0, 0, 16); $this->buildZipEntry($directoryPath, $fileComment, "\x00\x00", "\x00\x00", $timestamp, "\x00\x00\x00\x00", 0, 0, 16);
} }
/** /**
* Add a file to the archive at the specified location and file name. * Add a file to the archive at the specified location and file name.
* *
* @param string $data File data. * @param string $data File data.
* @param string $filePath Filepath and name to be used in the archive. * @param string $filePath Filepath and name to be used in the archive.
* @param int $timestamp (Optional) Timestamp for the added file, if omitted or set to 0, the current time will be used. * @param int $timestamp (Optional) Timestamp for the added file, if omitted or set to 0, the current time will be used.
* @param string $fileComment (Optional) Comment to be added to the archive for this file. To use fileComment, timestamp must be given. * @param string $fileComment (Optional) Comment to be added to the archive for this file. To use fileComment, timestamp must be given.
*/ */
public function addFile($data, $filePath, $timestamp = 0, $fileComment = null) { public function addFile($data, $filePath, $timestamp = 0, $fileComment = null) {
if ($this->isFinalized) { if ($this->isFinalized) {
return; return;
} }
$gzType = "\x08\x00"; // Compression type 8 = deflate $gzType = "\x08\x00"; // Compression type 8 = deflate
$gpFlags = "\x02\x00"; // General Purpose bit flags for compression type 8 it is: 0=Normal, 1=Maximum, 2=Fast, 3=super fast compression. $gpFlags = "\x02\x00"; // General Purpose bit flags for compression type 8 it is: 0=Normal, 1=Maximum, 2=Fast, 3=super fast compression.
$dataLength = strlen($data); $dataLength = strlen($data);
$fileCRC32 = pack("V", crc32($data)); $fileCRC32 = pack("V", crc32($data));
$gzData = gzcompress($data); $gzData = gzcompress($data);
$gzData = substr( substr($gzData, 0, strlen($gzData) - 4), 2); // gzcompress adds a 2 byte header and 4 byte CRC we can't use. $gzData = substr( substr($gzData, 0, strlen($gzData) - 4), 2); // gzcompress adds a 2 byte header and 4 byte CRC we can't use.
// The 2 byte header does contain useful data, though in this case the 2 parameters we'd be interrested in will always be 8 for compression type, and 2 for General purpose flag. // The 2 byte header does contain useful data, though in this case the 2 parameters we'd be interrested in will always be 8 for compression type, and 2 for General purpose flag.
$gzLength = strlen($gzData); $gzLength = strlen($gzData);
if ($gzLength >= $dataLength) { if ($gzLength >= $dataLength) {
$gzLength = $dataLength; $gzLength = $dataLength;
$gzData = $data; $gzData = $data;
$gzType = "\x00\x00"; // Compression type 0 = stored $gzType = "\x00\x00"; // Compression type 0 = stored
$gpFlags = "\x00\x00"; // Compression type 0 = stored $gpFlags = "\x00\x00"; // Compression type 0 = stored
} }
if (is_null($this->zipFile) && ($this->offset + $gzLength) > $this->zipMemoryThreshold) { if (is_null($this->zipFile) && ($this->offset + $gzLength) > $this->zipMemoryThreshold) {
$this->zipFile = tmpfile(); $this->zipFile = tmpfile();
fwrite($this->zipFile, $this->zipData); fwrite($this->zipFile, $this->zipData);
$this->zipData = null; $this->zipData = null;
} }
$this->buildZipEntry($filePath, $fileComment, $gpFlags, $gzType, $timestamp, $fileCRC32, $gzLength, $dataLength, 32); $this->buildZipEntry($filePath, $fileComment, $gpFlags, $gzType, $timestamp, $fileCRC32, $gzLength, $dataLength, 32);
if (is_null($this->zipFile)) { if (is_null($this->zipFile)) {
$this->zipData .= $gzData; $this->zipData .= $gzData;
} else { } else {
fwrite($this->zipFile, $gzData); fwrite($this->zipFile, $gzData);
} }
} }
/** /**
* Add a file to the archive at the specified location and file name. * Add a file to the archive at the specified location and file name.
* *
* @param string $dataFile File name/path. * @param string $dataFile File name/path.
* @param string $filePath Filepath and name to be used in the archive. * @param string $filePath Filepath and name to be used in the archive.
* @param int $timestamp (Optional) Timestamp for the added file, if omitted or set to 0, the current time will be used. * @param int $timestamp (Optional) Timestamp for the added file, if omitted or set to 0, the current time will be used.
* @param string $fileComment (Optional) Comment to be added to the archive for this file. To use fileComment, timestamp must be given. * @param string $fileComment (Optional) Comment to be added to the archive for this file. To use fileComment, timestamp must be given.
*/ */
public function addLargeFile($dataFile, $filePath, $timestamp = 0, $fileComment = null) { public function addLargeFile($dataFile, $filePath, $timestamp = 0, $fileComment = null) {
if ($this->isFinalized) { if ($this->isFinalized) {
return; return;
} }
$this->openStream($filePath, $timestamp, $fileComment); $this->openStream($filePath, $timestamp, $fileComment);
$fh = fopen($dataFile, "rb"); $fh = fopen($dataFile, "rb");
while(!feof($fh)) { while(!feof($fh)) {
$this->addStreamData(fread($fh, $this->streamChunkSize)); $this->addStreamData(fread($fh, $this->streamChunkSize));
} }
fclose($fh); fclose($fh);
$this->closeStream(); $this->closeStream();
} }
/** /**
* Create a stream to be used for large entries. * Create a stream to be used for large entries.
* *
* @param string $filePath Filepath and name to be used in the archive. * @param string $filePath Filepath and name to be used in the archive.
* @param int $timestamp (Optional) Timestamp for the added file, if omitted or set to 0, the current time will be used. * @param int $timestamp (Optional) Timestamp for the added file, if omitted or set to 0, the current time will be used.
* @param string $fileComment (Optional) Comment to be added to the archive for this file. To use fileComment, timestamp must be given. * @param string $fileComment (Optional) Comment to be added to the archive for this file. To use fileComment, timestamp must be given.
*/ */
public function openStream($filePath, $timestamp = 0, $fileComment = null) { public function openStream($filePath, $timestamp = 0, $fileComment = null) {
if ($this->isFinalized) { if ($this->isFinalized) {
return; return;
} }
if (is_null($this->zipFile)) { if (is_null($this->zipFile)) {
$this->zipFile = tmpfile(); $this->zipFile = tmpfile();
fwrite($this->zipFile, $this->zipData); fwrite($this->zipFile, $this->zipData);
$this->zipData = null; $this->zipData = null;
} }
if (strlen($this->streamFilePath) > 0) { if (strlen($this->streamFilePath) > 0) {
closeStream(); closeStream();
} }
$this->streamFile = tempnam(sys_get_temp_dir(), 'Zip'); $this->streamFile = tempnam(sys_get_temp_dir(), 'Zip');
$this->streamData = gzopen($this->streamFile, "w9"); $this->streamData = gzopen($this->streamFile, "w9");
$this->streamFilePath = $filePath; $this->streamFilePath = $filePath;
$this->streamTimestamp = $timestamp; $this->streamTimestamp = $timestamp;
$this->streamFileComment = $fileComment; $this->streamFileComment = $fileComment;
$this->streamFileLength = 0; $this->streamFileLength = 0;
} }
public function addStreamData($data) { public function addStreamData($data) {
$length = gzwrite($this->streamData, $data, strlen($data)); $length = gzwrite($this->streamData, $data, strlen($data));
if ($length != strlen($data)) { if ($length != strlen($data)) {
print "<p>Length mismatch</p>\n"; print "<p>Length mismatch</p>\n";
} }
$this->streamFileLength += $length; $this->streamFileLength += $length;
return $length; return $length;
} }
/** /**
* Close the current stream. * Close the current stream.
*/ */
public function closeStream() { public function closeStream() {
if ($this->isFinalized || strlen($this->streamFilePath) == 0) { if ($this->isFinalized || strlen($this->streamFilePath) == 0) {
return; return;
} }
fflush($this->streamData); fflush($this->streamData);
gzclose($this->streamData); gzclose($this->streamData);
$gzType = "\x08\x00"; // Compression type 8 = deflate $gzType = "\x08\x00"; // Compression type 8 = deflate
$gpFlags = "\x02\x00"; // General Purpose bit flags for compression type 8 it is: 0=Normal, 1=Maximum, 2=Fast, 3=super fast compression. $gpFlags = "\x02\x00"; // General Purpose bit flags for compression type 8 it is: 0=Normal, 1=Maximum, 2=Fast, 3=super fast compression.
$file_handle = fopen($this->streamFile, "rb"); $file_handle = fopen($this->streamFile, "rb");
$stats = fstat($file_handle); $stats = fstat($file_handle);
$eof = $stats['size']; $eof = $stats['size'];
fseek($file_handle, $eof-8); fseek($file_handle, $eof-8);
$fileCRC32 = fread($file_handle, 4); $fileCRC32 = fread($file_handle, 4);
$dataLength = $this->streamFileLength;//$gzl[1]; $dataLength = $this->streamFileLength;//$gzl[1];
$gzLength = $eof-10; $gzLength = $eof-10;
$eof -= 9; $eof -= 9;
fseek($file_handle, 10); fseek($file_handle, 10);
$this->buildZipEntry($this->streamFilePath, $this->streamFileComment, $gpFlags, $gzType, $this->streamTimestamp, $fileCRC32, $gzLength, $dataLength, 32); $this->buildZipEntry($this->streamFilePath, $this->streamFileComment, $gpFlags, $gzType, $this->streamTimestamp, $fileCRC32, $gzLength, $dataLength, 32);
while(!feof($file_handle)) { while(!feof($file_handle)) {
fwrite($this->zipFile, fread($file_handle, $this->streamChunkSize)); fwrite($this->zipFile, fread($file_handle, $this->streamChunkSize));
} }
unlink($this->streamFile); unlink($this->streamFile);
$this->streamFile = null; $this->streamFile = null;
$this->streamData = null; $this->streamData = null;
$this->streamFilePath = null; $this->streamFilePath = null;
$this->streamTimestamp = null; $this->streamTimestamp = null;
$this->streamFileComment = null; $this->streamFileComment = null;
$this->streamFileLength = 0; $this->streamFileLength = 0;
} }
/** /**
* Close the archive. * Close the archive.
* A closed archive can no longer have new files added to it. * A closed archive can no longer have new files added to it.
*/ */
public function finalize() { public function finalize() {
if(!$this->isFinalized) { if(!$this->isFinalized) {
if (strlen($this->streamFilePath) > 0) { if (strlen($this->streamFilePath) > 0) {
$this->closeStream(); $this->closeStream();
} }
$cd = implode("", $this->cdRec); $cd = implode("", $this->cdRec);
$cdRec = $cd . $this->endOfCentralDirectory $cdRec = $cd . $this->endOfCentralDirectory
. pack("v", sizeof($this->cdRec)) . pack("v", sizeof($this->cdRec))
. pack("v", sizeof($this->cdRec)) . pack("v", sizeof($this->cdRec))
. pack("V", strlen($cd)) . pack("V", strlen($cd))
. pack("V", $this->offset); . pack("V", $this->offset);
if (!is_null($this->zipComment)) { if (!is_null($this->zipComment)) {
$cdRec .= pack("v", strlen($this->zipComment)) . $this->zipComment; $cdRec .= pack("v", strlen($this->zipComment)) . $this->zipComment;
} else { } else {
$cdRec .= "\x00\x00"; $cdRec .= "\x00\x00";
} }
if (is_null($this->zipFile)) { if (is_null($this->zipFile)) {
$this->zipData .= $cdRec; $this->zipData .= $cdRec;
} else { } else {
fwrite($this->zipFile, $cdRec); fwrite($this->zipFile, $cdRec);
fflush($this->zipFile); fflush($this->zipFile);
} }
$this->isFinalized = true; $this->isFinalized = true;
$cd = null; $cd = null;
$this->cdRec = null; $this->cdRec = null;
} }
} }
/** /**
* Get the handle ressource for the archive zip file. * Get the handle ressource for the archive zip file.
* If the zip haven't been finalized yet, this will cause it to become finalized * If the zip haven't been finalized yet, this will cause it to become finalized
* *
* @return zip file handle * @return zip file handle
*/ */
public function getZipFile() { public function getZipFile() {
if(!$this->isFinalized) { if(!$this->isFinalized) {
$this->finalize(); $this->finalize();
} }
if (is_null($this->zipFile)) { if (is_null($this->zipFile)) {
$this->zipFile = tmpfile(); $this->zipFile = tmpfile();
fwrite($this->zipFile, $this->zipData); fwrite($this->zipFile, $this->zipData);
$this->zipData = null; $this->zipData = null;
} }
rewind($this->zipFile); rewind($this->zipFile);
return $this->zipFile; return $this->zipFile;
} }
/** /**
* Get the zip file contents * Get the zip file contents
* If the zip haven't been finalized yet, this will cause it to become finalized * If the zip haven't been finalized yet, this will cause it to become finalized
* *
* @return zip data * @return zip data
*/ */
public function getZipData() { public function getZipData() {
if(!$this->isFinalized) { if(!$this->isFinalized) {
$this->finalize(); $this->finalize();
} }
if (is_null($this->zipFile)) { if (is_null($this->zipFile)) {
return $this->zipData; return $this->zipData;
} else { } else {
rewind($this->zipFile); rewind($this->zipFile);
$filestat = fstat($this->zipFile); $filestat = fstat($this->zipFile);
return fread($this->zipFile, $filestat['size']); return fread($this->zipFile, $filestat['size']);
} }
} }
/** /**
* Send the archive as a zip download * Send the archive as a zip download
* *
* @param String $fileName The name of the Zip archive, ie. "archive.zip". * @param String $fileName The name of the Zip archive, ie. "archive.zip".
* @return void * @return void
*/ */
function sendZip($fileName) { function sendZip($fileName) {
if(!$this->isFinalized) { if(!$this->isFinalized) {
$this->finalize(); $this->finalize();
} }
if (!headers_sent($headerFile, $headerLine) or die("<p><strong>Error:</strong> Unable to send file $fileName. HTML Headers have already been sent from <strong>$headerFile</strong> in line <strong>$headerLine</strong></p>")) { if (!headers_sent($headerFile, $headerLine) or die("<p><strong>Error:</strong> Unable to send file $fileName. HTML Headers have already been sent from <strong>$headerFile</strong> in line <strong>$headerLine</strong></p>")) {
if (ob_get_contents() === false or die("\n<p><strong>Error:</strong> Unable to send file <strong>$fileName.epub</strong>. Output buffer contains the following text (typically warnings or errors):<br>" . ob_get_contents() . "</p>")) { if (ob_get_contents() === false or die("\n<p><strong>Error:</strong> Unable to send file <strong>$fileName.epub</strong>. Output buffer contains the following text (typically warnings or errors):<br>" . ob_get_contents() . "</p>")) {
if (ini_get('zlib.output_compression')) { if (ini_get('zlib.output_compression')) {
ini_set('zlib.output_compression', 'Off'); ini_set('zlib.output_compression', 'Off');
} }
header('Pragma: public'); header('Pragma: public');
header("Last-Modified: " . gmdate("D, d M Y H:i:s T")); header("Last-Modified: " . gmdate("D, d M Y H:i:s T"));
header("Expires: 0"); header("Expires: 0");
header("Accept-Ranges: bytes"); header("Accept-Ranges: bytes");
header("Connection: close"); header("Connection: close");
header("Content-Type: application/zip"); header("Content-Type: application/zip");
header('Content-Disposition: attachment; filename="' . $fileName . '";' ); header('Content-Disposition: attachment; filename="' . $fileName . '";' );
header("Content-Transfer-Encoding: binary"); header("Content-Transfer-Encoding: binary");
header("Content-Length: ". $this->getArchiveSize()); header("Content-Length: ". $this->getArchiveSize());
if (is_null($this->zipFile)) { if (is_null($this->zipFile)) {
echo $this->zipData; echo $this->zipData;
} else { } else {
rewind($this->zipFile); rewind($this->zipFile);
while(!feof($this->zipFile)) { while(!feof($this->zipFile)) {
echo fread($this->zipFile, $this->streamChunkSize); echo fread($this->zipFile, $this->streamChunkSize);
} }
} }
} }
} }
} }
public function getArchiveSize() { public function getArchiveSize() {
if (is_null($this->zipFile)) { if (is_null($this->zipFile)) {
return strlen($this->zipData); return strlen($this->zipData);
} }
$filestat = fstat($this->zipFile); $filestat = fstat($this->zipFile);
return $filestat['size']; return $filestat['size'];
} }
/** /**
* Calculate the 2 byte dostime used in the zip entries. * Calculate the 2 byte dostime used in the zip entries.
* *
* @param int $timestamp * @param int $timestamp
* @return 2-byte encoded DOS Date * @return 2-byte encoded DOS Date
*/ */
private function getDosTime($timestamp = 0) { private function getDosTime($timestamp = 0) {
$timestamp = (int)$timestamp; $timestamp = (int)$timestamp;
$date = ($timestamp == 0 ? getdate() : getDate($timestamp)); $date = ($timestamp == 0 ? getdate() : getDate($timestamp));
if ($date["year"] >= 1980) { if ($date["year"] >= 1980) {
return pack("V", (($date["mday"] + ($date["mon"] << 5) + (($date["year"]-1980) << 9)) << 16) | return pack("V", (($date["mday"] + ($date["mon"] << 5) + (($date["year"]-1980) << 9)) << 16) |
(($date["seconds"] >> 1) + ($date["minutes"] << 5) + ($date["hours"] << 11))); (($date["seconds"] >> 1) + ($date["minutes"] << 5) + ($date["hours"] << 11)));
} }
return "\x00\x00\x00\x00"; return "\x00\x00\x00\x00";
} }
/** /**
* Build the Zip file structures * Build the Zip file structures
* *
* @param unknown_type $filePath * @param unknown_type $filePath
* @param unknown_type $fileComment * @param unknown_type $fileComment
* @param unknown_type $gpFlags * @param unknown_type $gpFlags
* @param unknown_type $gzType * @param unknown_type $gzType
* @param unknown_type $timestamp * @param unknown_type $timestamp
* @param unknown_type $fileCRC32 * @param unknown_type $fileCRC32
* @param unknown_type $gzLength * @param unknown_type $gzLength
* @param unknown_type $dataLength * @param unknown_type $dataLength
* @param integer $extFileAttr 16 for directories, 32 for files. * @param integer $extFileAttr 16 for directories, 32 for files.
*/ */
private function buildZipEntry($filePath, $fileComment, $gpFlags, $gzType, $timestamp, $fileCRC32, $gzLength, $dataLength, $extFileAttr) { private function buildZipEntry($filePath, $fileComment, $gpFlags, $gzType, $timestamp, $fileCRC32, $gzLength, $dataLength, $extFileAttr) {
$filePath = str_replace("\\", "/", $filePath); $filePath = str_replace("\\", "/", $filePath);
$fileCommentLength = (is_null($fileComment) ? 0 : strlen($fileComment)); $fileCommentLength = (is_null($fileComment) ? 0 : strlen($fileComment));
$dosTime = $this->getDosTime($timestamp); $dosTime = $this->getDosTime($timestamp);
$zipEntry = $this->localFileHeader; $zipEntry = $this->localFileHeader;
$zipEntry .= "\x14\x00"; // Version needed to extract $zipEntry .= "\x14\x00"; // Version needed to extract
$zipEntry .= $gpFlags . $gzType . $dosTime. $fileCRC32; $zipEntry .= $gpFlags . $gzType . $dosTime. $fileCRC32;
$zipEntry .= pack("VV", $gzLength, $dataLength); $zipEntry .= pack("VV", $gzLength, $dataLength);
$zipEntry .= pack("v", strlen($filePath) ); // File name length $zipEntry .= pack("v", strlen($filePath) ); // File name length
$zipEntry .= "\x00\x00"; // Extra field length $zipEntry .= "\x00\x00"; // Extra field length
$zipEntry .= $filePath; // FileName . Extra field $zipEntry .= $filePath; // FileName . Extra field
if (is_null($this->zipFile)) { if (is_null($this->zipFile)) {
$this->zipData .= $zipEntry; $this->zipData .= $zipEntry;
} else { } else {
fwrite($this->zipFile, $zipEntry); fwrite($this->zipFile, $zipEntry);
} }
$cdEntry = $this->centralFileHeader; $cdEntry = $this->centralFileHeader;
$cdEntry .= "\x00\x00"; // Made By Version $cdEntry .= "\x00\x00"; // Made By Version
$cdEntry .= "\x14\x00"; // Version Needed to extract $cdEntry .= "\x14\x00"; // Version Needed to extract
$cdEntry .= $gpFlags . $gzType . $dosTime. $fileCRC32; $cdEntry .= $gpFlags . $gzType . $dosTime. $fileCRC32;
$cdEntry .= pack("VV", $gzLength, $dataLength); $cdEntry .= pack("VV", $gzLength, $dataLength);
$cdEntry .= pack("v", strlen($filePath)); // Filename length $cdEntry .= pack("v", strlen($filePath)); // Filename length
$cdEntry .= "\x00\x00"; // Extra field length $cdEntry .= "\x00\x00"; // Extra field length
$cdEntry .= pack("v", $fileCommentLength); // File comment length $cdEntry .= pack("v", $fileCommentLength); // File comment length
$cdEntry .= "\x00\x00"; // Disk number start $cdEntry .= "\x00\x00"; // Disk number start
$cdEntry .= "\x00\x00"; // internal file attributes $cdEntry .= "\x00\x00"; // internal file attributes
$cdEntry .= pack("V", $extFileAttr ); // External file attributes $cdEntry .= pack("V", $extFileAttr ); // External file attributes
$cdEntry .= pack("V", $this->offset ); // Relative offset of local header $cdEntry .= pack("V", $this->offset ); // Relative offset of local header
$cdEntry .= $filePath; // FileName . Extra field $cdEntry .= $filePath; // FileName . Extra field
if (!is_null($fileComment)) { if (!is_null($fileComment)) {
$cdEntry .= $fileComment; // Comment $cdEntry .= $fileComment; // Comment
} }
$this->cdRec[] = $cdEntry; $this->cdRec[] = $cdEntry;
$this->offset += strlen($zipEntry) + $gzLength; $this->offset += strlen($zipEntry) + $gzLength;
} }
} }
?>

View File

@ -1,88 +1,88 @@
<?PHP <?PHP
declare(strict_types = 1); declare(strict_types = 1);
error_reporting(E_ALL); error_reporting(E_ALL);
ini_set('display_errors', "1"); ini_set('display_errors', "1");
require_once __DIR__ . "/functions/functions.php"; require_once __DIR__ . "/functions/functions.php";
if (session_status() != PHP_SESSION_ACTIVE) { if (session_status() != PHP_SESSION_ACTIVE) {
session_start(); session_start();
} }
// This array contains all available languages // This array contains all available languages
$allowed_langs = ['ar', 'de', 'en', 'hu', 'id', 'it', 'pl','pt']; $allowed_langs = ['ar', 'de', 'en', 'hu', 'id', 'it', 'pl','pt'];
// Some languages are in translation. They will only be available for logged in users. // Some languages are in translation. They will only be available for logged in users.
if (isset($_GET['navlang'])) { if (isset($_GET['navlang'])) {
$_SESSION['lang'] = $_GET['navlang']; $_SESSION['lang'] = $_GET['navlang'];
if (!in_array($_SESSION['lang'], $allowed_langs)) $_SESSION['lang'] = 'de'; if (!in_array($_SESSION['lang'], $allowed_langs)) $_SESSION['lang'] = 'de';
} }
else if (!isset($_SESSION['lang'])) { else if (!isset($_SESSION['lang'])) {
$_SESSION['lang'] = lang_getfrombrowser($allowed_langs, 'en', "", false); $_SESSION['lang'] = lang_getfrombrowser($allowed_langs, 'en', "", false);
} }
$lang = $_SESSION['lang']; $lang = $_SESSION['lang'];
require __DIR__ . "/translation-importer/$lang/csvxml-overview.php"; require __DIR__ . "/translation-importer/$lang/csvxml-overview.php";
require __DIR__ . '/inc/zeichen.php'; require __DIR__ . '/inc/zeichen.php';
if (empty($filename = trim($_GET['fnam'], " ,./"))) { if (empty($filename = trim($_GET['fnam'], " ,./"))) {
echo "Error: Invalid file name"; echo "Error: Invalid file name";
exit; exit;
} }
$csv_datei = __DIR__ . '/csv/' . $filename; $csv_datei = __DIR__ . '/csv/' . $filename;
if (!file_exists($csv_datei)) { if (!file_exists($csv_datei)) {
echo "Error: The CSV file does not exist."; echo "Error: The CSV file does not exist.";
exit; exit;
} }
if (is_dir(__DIR__ . "/xml")) rrmdir(__DIR__ . '/xml'); if (is_dir(__DIR__ . "/xml")) rrmdir(__DIR__ . '/xml');
mkdir(__DIR__ . "/xml", 0755); mkdir(__DIR__ . "/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')) {
echo "Cannot open file ($zieldatei)";exit; echo "Cannot open file ($zieldatei)";exit;
} }
$somecontent = '<?xml version="1.0" encoding="UTF-8"?>' . "\n"; // für Ungarn /////////////////////////////////// $somecontent = '<?xml version="1.0" encoding="UTF-8"?>' . "\n"; // für Ungarn ///////////////////////////////////
$somecontent .= '<record>' . "\n"; $somecontent .= '<record>' . "\n";
$lineCount = count($zeile); $lineCount = count($zeile);
for ($x = 0; $x < $lineCount; $x++) { for ($x = 0; $x < $lineCount; $x++) {
$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 (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 }
} }
$somecontent .= '</record>'; $somecontent .= '</record>';
if (fwrite($handle, $somecontent) === FALSE) { if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($filename)";exit; echo "Cannot write to file ($filename)";exit;
} }
fclose($handle); fclose($handle);
} }
fclose($fp); fclose($fp);
echo printHTMLHead(); echo printHTMLHead();
echo ' echo '
<div> <div>
' . ($y - 1) . ' files created ' . ($y - 1) . ' files created
<hr/> <hr/>
<a href="zipit.php" class="buttonLike">Download as zip</a> <a href="zipit.php" class="buttonLike">Download as zip</a>
</div>'; </div>';
echo ' echo '
</body> </body>
</html> </html>
'; ';

View File

@ -1,94 +1,91 @@
<?PHP <?PHP
declare(strict_types = 1); declare(strict_types = 1);
error_reporting(E_ALL); error_reporting(E_ALL);
ini_set('display_errors', "1"); ini_set('display_errors', "1");
require_once __DIR__ . "/functions/functions.php"; require_once __DIR__ . "/functions/functions.php";
if (session_status() != PHP_SESSION_ACTIVE) { if (session_status() != PHP_SESSION_ACTIVE) {
session_start(); session_start();
} }
// This array contains all available languages // This array contains all available languages
$allowed_langs = ['ar', 'de', 'en', 'hu', 'id', 'it', 'pl','pt']; $allowed_langs = ['ar', 'de', 'en', 'hu', 'id', 'it', 'pl','pt'];
// Some languages are in translation. They will only be available for logged in users. // Some languages are in translation. They will only be available for logged in users.
if (isset($_GET['navlang'])) { if (isset($_GET['navlang'])) {
$_SESSION['lang'] = $_GET['navlang']; $_SESSION['lang'] = $_GET['navlang'];
if (!in_array($_SESSION['lang'], $allowed_langs)) $_SESSION['lang'] = 'de'; if (!in_array($_SESSION['lang'], $allowed_langs)) $_SESSION['lang'] = 'de';
} }
else if (!isset($_SESSION['lang'])) { else if (!isset($_SESSION['lang'])) {
$_SESSION['lang'] = lang_getfrombrowser($allowed_langs, 'en', "", false); $_SESSION['lang'] = lang_getfrombrowser($allowed_langs, 'en', "", false);
} }
$lang = $_SESSION['lang']; $lang = $_SESSION['lang'];
require __DIR__ . '/inc/zeichen.php'; if (empty($filename = trim($_GET['fnam'], " ,./"))) {
echo "Error: Invalid file name";
if (empty($filename = trim($_GET['fnam'], " ,./"))) { exit;
echo "Error: Invalid file name"; }
exit; $csv_datei = __DIR__ . '/csv/' . $filename;
} if (!file_exists($csv_datei)) {
$csv_datei = __DIR__ . '/csv/' . $filename; echo "Error: The CSV file does not exist.";
if (!file_exists($csv_datei)) { exit;
echo "Error: The CSV file does not exist."; }
exit;
} if (is_dir(__DIR__ . "/xml")) rrmdir(__DIR__ . '/xml');
mkdir(__DIR__ . "/xml", 0755);
if (is_dir(__DIR__ . "/xml")) rrmdir(__DIR__ . '/xml');
mkdir(__DIR__ . "/xml", 0755); $fp = fopen ($csv_datei, 'r');
$y = 0;
$fp = fopen ($csv_datei, 'r'); while ($zeile = fgetcsv($fp, 100000, ';')) {
$y = 0;
while ($zeile = fgetcsv($fp, 100000, ';')) { $zeile = str_replace("\xEF\xBB\xBF", '', $zeile);
$zeile = str_replace("\xEF\xBB\xBF", '', $zeile); $y++;
$y++; $zieldatei = 'xml/' . $y . '.xml';
if (!$handle = fopen($zieldatei, 'w')) {
$zieldatei = 'xml/' . $y . '.xml'; echo "Cannot open file ($zieldatei)";exit;
if (!$handle = fopen($zieldatei, 'w')) { }
echo "Cannot open file ($zieldatei)";exit;
} $xmlDoc = new DOMDocument("1.0", "UTF-8");
$xmlDoc->preserveWhiteSpace = false;
$xmlDoc = new DOMDocument("1.0", "UTF-8"); $xmlDoc->formatOutput = true;
$xmlDoc->preserveWhiteSpace = false; # $xmlDoc->encoding = 'utf-8';
$xmlDoc->formatOutput = true; $xmlMainElem = $xmlDoc->createElement("record");
# $xmlDoc->encoding = 'utf-8'; $record_node = $xmlDoc->appendChild($xmlMainElem); //add record element to XML node
$xmlMainElem = $xmlDoc->createElement("record"); # $rss_node->setAttribute("version", "2.0"); //set RSS version
$record_node = $xmlDoc->appendChild($xmlMainElem); //add record element to XML node
# $rss_node->setAttribute("version", "2.0"); //set RSS version $lineCount = count($zeile);
$lineCount = count($zeile); for ($x = 0; $x < $lineCount; $x++) {
$inhalt[$y][$x] = $zeile[$x];
for ($x = 0; $x < $lineCount; $x++) { if ($inhalt[$y][$x] == '') $inhalt[$y][$x] = 'ERSATZ';
$inhalt[$y][$x] = $zeile[$x];
if ($inhalt[$y][$x] == '') $inhalt[$y][$x] = 'ERSATZ'; $record_node->appendChild(createTextDomElement($xmlDoc, trim($inhalt[1][$x]), trim($inhalt[$y][$x])));
$record_node->appendChild(createTextDomElement($xmlDoc, trim($inhalt[1][$x]), trim($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 = '<?xml version="1.0" encoding="UTF-8"?>' . $xmlDoc->saveXML($xmlDoc->documentElement);
}
# $somecontent .= '</record>';
$somecontent = '<?xml version="1.0" encoding="UTF-8"?>' . $xmlDoc->saveXML($xmlDoc->documentElement); //if ($y>1)
//{
# $somecontent .= '</record>'; if (fwrite($handle, $somecontent) === FALSE) {
//if ($y>1) echo "Cannot write to file ($filename)";exit;
//{ }
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($filename)";exit; fclose($handle);
} }
fclose($fp);
fclose($handle);
}
fclose($fp); echo printHTMLHead();
echo '
echo printHTMLHead(); <div>
' . ($y - 1) . ' files created<br />
echo ' <hr/>
<div> <a href="zipit.php" class="buttonLike">Download as ZIP</a>
' . ($y - 1) . ' files created<br /> </div>';
<hr/>
<a href="zipit.php" class="buttonLike">Download as ZIP</a>
</div>';

File diff suppressed because it is too large Load Diff