added error reporting & fixed things in index3.php

This commit is contained in:
Nathan Eikermann 2021-07-02 00:32:49 +02:00
parent 562ff50bb0
commit 4cd969bf87
2 changed files with 28 additions and 38 deletions

View File

@ -20,9 +20,9 @@ final class CSVXMLValidator
*/
public function __construct()
{
$error_msgs = [];
$inv_errors = [];
$depcon_errors = [];
$this->error_msgs = [];
$this->inv_errors = [];
$this->depcon_errors = [];
}
public function addError(String $error)

View File

@ -44,11 +44,11 @@ foreach ($availableFields as $categoryName => $fieldCategory) {
}
foreach ($fieldCategory as $key => $value) {
if (!empty($value["dependsOn"])) {
$fieldsWithDependency[$key] = $value['dependsOn'];
if (!empty($value->dependsOn)) {
$fieldsWithDependency[$key] = $value->dependsOn;
}
if (!empty($value["allowedValues"])) {
$fieldsWithAllowedValueSet[$key] = $value['allowedValues'];
if (!empty($value->allowedValues)) {
$fieldsWithAllowedValueSet[$key] = $value->allowedValues;
}
}
@ -68,23 +68,28 @@ echo '</form>';
//echo '<pre>';print_r($allowed);echo '</pre>';
echo '1: Only allowed tags (column names) used?';
$fp = fopen($csv_datei, 'r');
$y = 1;
$zeile = fgetcsv($fp, 100000, ';');
$y = 0;
while ($zeile = fgetcsv($fp, 100000, ';')) {
$y++;
$maxLoopLen = count($zeile);
for ($x = 0; $x < $maxLoopLen; $x++) {
$zeile[$x] = str_replace("\xEF\xBB\xBF", "", $zeile[$x]);
$inhalt[$y][$x] = $zeile[$x];
if (!in_array($inhalt[1][$x], $allowed)) {
$inhalt[$y][$x] = str_replace("'", "\'", $zeile[$x]);
if ($y == 1) {
// remove byte order mark
$inhalt[$y][$x] = str_replace("\xEF\xBB\xBF", "", $inhalt[$y][$x]);
if (!in_array($inhalt[$y][$x], $allowed)) {
$validator->addError(
'<br><i style="font-style:normal;color:#990000;">ERROR in column ' . $x
. ' created by value: ' . $inhalt[1][$x] . '</i>'
. ' created by value: ' . $inhalt[$y][$x] . '</i>'
);
}
//echo '<br/>';var_dump($inhalt[1][$x]);
}
}
}
fclose($fp);
$erstezeile = $zeile;
$erstezeile = $inhalt[1];
if (count($validator->error_msgs) != 0) {
echo '<br><b style="color:#990000;">Not allowed tags found !</b>';
} else {
@ -93,9 +98,9 @@ if (count($validator->error_msgs) != 0) {
//// Check #2
echo '<br><br>2: Not allowed multiple use of tags (column names)?';
$compare = array_unique($zeile);
$compare = array_unique($erstezeile);
if (count($zeile) != count($compare)) {
if (count($erstezeile) != count($compare)) {
$validator->addError(
'<br><b style="color:#990000;">There are duplicate column names !</b>'
);
@ -103,21 +108,6 @@ if (count($zeile) != count($compare)) {
echo '<br><i style="font-style:normal;color:#009900;">No duplicate column names !</i>';
}
//// Get values into memory for following checks
//TODO: Merge with loop on line 74
$fp = fopen($csv_datei, 'r');
$y = 0;
while ($zeile = fgetcsv($fp, 100000, ';')) {
$y++;
$maxLoopLen = count($zeile);
for ($x = 0; $x < $maxLoopLen; $x++) {
$inhalt[$y][$x] = str_replace("'", "\'", $zeile[$x]);
}
}
fclose($fp);
///// Check #3
echo '<br><br>3: Mandatory tags available and always filled in?';
unset($inv_array);
@ -202,7 +192,7 @@ foreach ($fieldsWithDependency as $tField => $tDependentFields) {
if (!empty($depencymessage)) {
echo '<b style="color:#990000;">Dependent columns were not observed !</b>';
foreach ($depencymessage as $tDepMsg) {
$validator->addError('<br>' . $tDepMsg)
$validator->addError('<br>' . $tDepMsg);
}
} else {
echo '<i style="font-style:normal;color:#009900;">Dependent columns were observed !</i>';