added TODOs for the validator

This commit is contained in:
Nathan Eikermann 2021-05-26 01:08:52 +02:00
parent c774ff9d70
commit 60c5265358

View File

@ -14,8 +14,7 @@ $allowed_langs = ['ar', 'de', 'en', 'hu', 'id', 'it', 'pl','pt'];
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'] = MD_STD::lang_getfrombrowser($allowed_langs, 'en', "", false); $_SESSION['lang'] = MD_STD::lang_getfrombrowser($allowed_langs, 'en', "", false);
} }
$lang = $_SESSION['lang']; $lang = $_SESSION['lang'];
@ -88,19 +87,20 @@ if ($error != 0) echo '<br><b style="color:#990000;">Not allowed tags found !</b
//// 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)?';
//TODO: only check if the sizes are the same
$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
//TODO: Merge with loop on line 74
$fp = fopen($csv_datei, 'r'); $fp = fopen($csv_datei, 'r');
$y = 0; $y = 0;
while ($zeile = fgetcsv($fp, 100000, ';')) { while ($zeile = fgetcsv($fp, 100000, ';')) {
@ -125,19 +125,20 @@ $inv_error = 0;
* *
* @return array * @return array
*/ */
function get_duplicates(array $array):array { function get_duplicates(array $array):array
{
return array_unique(array_diff_assoc($array, array_unique($array))); return array_unique(array_diff_assoc($array, array_unique($array)));
} }
//TODO: function for returning the error strings & counting errors
$mandatory = ['inventory_number','object_type','object_title','object_description']; $mandatory = ['inventory_number','object_type','object_title','object_description'];
foreach ($mandatory as $tMandatoryField) { foreach ($mandatory as $tMandatoryField) {
if (!in_array($tMandatoryField, $erstezeile)) { if (!in_array($tMandatoryField, $erstezeile)) {
echo '<br><i style="font-style:normal;color:#990000;">Mandatory: Column <b>' . $tMandatoryField . '</b> missing</i>'; echo '<br><i style="font-style:normal;color:#990000;">Mandatory: Column <b>' . $tMandatoryField . '</b> missing</i>';
$error = $error + 1; $error = $error + 1;
$inv_error = $inv_error + 1; $inv_error = $inv_error + 1;
} } else {
else {
$spaltenr = array_search($tMandatoryField, $erstezeile); $spaltenr = array_search($tMandatoryField, $erstezeile);
for ($j = 0; $j < $y; $j++) { for ($j = 0; $j < $y; $j++) {
if ($inhalt[$j + 1][$spaltenr] == '') { if ($inhalt[$j + 1][$spaltenr] == '') {
@ -151,7 +152,10 @@ foreach ($mandatory as $tMandatoryField) {
} }
} }
} }
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
@ -164,10 +168,10 @@ if (in_array('inventory_number', $erstezeile)) {
echo '<br><i style="font-style:normal;color:#990000;">Multiple use of inventory_number <b>' . $tDublicateInvNo . '</b></i>'; echo '<br><i style="font-style:normal;color:#990000;">Multiple use of inventory_number <b>' . $tDublicateInvNo . '</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;
} }
@ -178,8 +182,11 @@ 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; //TODO: change order
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) {
@ -195,14 +202,14 @@ if (!empty($depencymessage)) {
echo '<br>' . $tDepMsg; echo '<br>' . $tDepMsg;
$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?';
//TODO: get the values for these arrays dynamically?
$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']; $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 = ['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'];
@ -299,6 +306,8 @@ for ($i = 2; $i <= $y; $i++) {
break; break;
} }
} }
//TODO: reverse the IF and use it before the error message
if ($allDependentsEmpty === true) continue; if ($allDependentsEmpty === true) continue;
} }
@ -315,8 +324,7 @@ if (isset($errormessage) and $errormessage != '') {
echo '<br>' . $tMsg; echo '<br>' . $tMsg;
$error++; $error++;
} }
} } 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>';
} }
@ -324,18 +332,21 @@ else {
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) != '') {
if (array_search('image_name' . $im, $erstezeile) != '') {$imagemain[$im]['name'] = array_search('image_name' . $im, $erstezeile);$hasanyimage++; $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_main' . $im, $erstezeile) != '') {
$imagemain[$im]['main'] = array_search('image_main' . $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 ($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) {
//check if in a row any image_name is given //check if in a row any image_name is given
$maimg = $hatimg = 0; $maimg = $hatimg = 0;
@ -357,8 +368,12 @@ if ($hasanyimage > 0) {
} }
} }
} }
if ($maimg == 0 and $hatimg > 0) $errormessage[] = '<b style="font-weight:normal;color:#990000">There is no visible main image given in row ' . $i . '</b>'; if ($maimg == 0 and $hatimg > 0) {
if ($maimg > 1 and $hatimg > 0) $errormessage[] = '<b style="font-weight:normal;color:#990000">There are ' . $maimg . ' main images given in row ' . $i . '</b>'; $errormessage[] = '<b style="font-weight:normal;color:#990000">There is no visible main image given in row ' . $i . '</b>';
}
if ($maimg > 1 and $hatimg > 0) {
$errormessage[] = '<b style="font-weight:normal;color:#990000">There are ' . $maimg . ' main images given in row ' . $i . '</b>';
}
} }
} }
@ -368,12 +383,10 @@ if ($hasanyimage > 0) {
echo '<br>' . $tMsg; echo '<br>' . $tMsg;
$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>';
} }
@ -382,8 +395,7 @@ if ($error + $depcon_error > 0) {
echo ' echo '
<p>Error(s) found: ' . ($error + $depcon_error) . '</p>'; <p>Error(s) found: ' . ($error + $depcon_error) . '</p>';
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>';
} } 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>';
} }
echo '</div>'; echo '</div>';