added error reporting & fixed things in index3.php
This commit is contained in:
parent
562ff50bb0
commit
4cd969bf87
@ -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)
|
||||
|
@ -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, ';');
|
||||
$maxLoopLen = count($zeile);
|
||||
for ($x = 0; $x < $maxLoopLen; $x++) {
|
||||
$y = 0;
|
||||
while ($zeile = fgetcsv($fp, 100000, ';')) {
|
||||
|
||||
$zeile[$x] = str_replace("\xEF\xBB\xBF", "", $zeile[$x]);
|
||||
$inhalt[$y][$x] = $zeile[$x];
|
||||
if (!in_array($inhalt[1][$x], $allowed)) {
|
||||
$validator->addError(
|
||||
'<br><i style="font-style:normal;color:#990000;">ERROR in column ' . $x
|
||||
. ' created by value: ' . $inhalt[1][$x] . '</i>'
|
||||
);
|
||||
$y++;
|
||||
$maxLoopLen = count($zeile);
|
||||
for ($x = 0; $x < $maxLoopLen; $x++) {
|
||||
$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[$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>';
|
||||
|
Loading…
Reference in New Issue
Block a user