added error reporting & fixed things in index3.php
This commit is contained in:
		| @@ -20,9 +20,9 @@ final class CSVXMLValidator | |||||||
|      */  |      */  | ||||||
|     public function __construct() |     public function __construct() | ||||||
|     { |     { | ||||||
|         $error_msgs = []; |         $this->error_msgs = []; | ||||||
|         $inv_errors = []; |         $this->inv_errors = []; | ||||||
|         $depcon_errors = []; |         $this->depcon_errors = []; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public function addError(String $error) |     public function addError(String $error) | ||||||
|   | |||||||
| @@ -44,11 +44,11 @@ foreach ($availableFields as $categoryName => $fieldCategory) { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     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; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @@ -68,23 +68,28 @@ echo '</form>'; | |||||||
| //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 = 0; | ||||||
| $zeile = fgetcsv($fp, 100000, ';'); | while ($zeile = fgetcsv($fp, 100000, ';')) { | ||||||
| $maxLoopLen = count($zeile); |  | ||||||
| for ($x = 0; $x < $maxLoopLen; $x++) { |  | ||||||
| 
 | 
 | ||||||
|     $zeile[$x] = str_replace("\xEF\xBB\xBF", "", $zeile[$x]); |     $y++; | ||||||
|     $inhalt[$y][$x] = $zeile[$x]; |     $maxLoopLen = count($zeile); | ||||||
|     if (!in_array($inhalt[1][$x], $allowed)) { |     for ($x = 0; $x < $maxLoopLen; $x++) { | ||||||
|         $validator->addError( |         $inhalt[$y][$x] = str_replace("'", "\'", $zeile[$x]); | ||||||
|             '<br><i style="font-style:normal;color:#990000;">ERROR in column ' . $x  |         if ($y == 1) { | ||||||
|             . ' created by value: ' . $inhalt[1][$x] . '</i>' |             // 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); | fclose($fp); | ||||||
| $erstezeile = $zeile; | 
 | ||||||
|  | $erstezeile = $inhalt[1]; | ||||||
| if (count($validator->error_msgs) != 0) { | if (count($validator->error_msgs) != 0) { | ||||||
|     echo '<br><b style="color:#990000;">Not allowed tags found !</b>'; |     echo '<br><b style="color:#990000;">Not allowed tags found !</b>'; | ||||||
| } else { | } else { | ||||||
| @@ -93,9 +98,9 @@ if (count($validator->error_msgs) != 0) { | |||||||
| 
 | 
 | ||||||
| //// 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($erstezeile); | ||||||
| 
 | 
 | ||||||
| if (count($zeile) != count($compare)) { | if (count($erstezeile) != count($compare)) { | ||||||
|     $validator->addError( |     $validator->addError( | ||||||
|         '<br><b style="color:#990000;">There are duplicate column names !</b>' |         '<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>'; |     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
 | ///// 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); | ||||||
| @@ -202,7 +192,7 @@ foreach ($fieldsWithDependency as $tField => $tDependentFields) { | |||||||
| if (!empty($depencymessage)) { | if (!empty($depencymessage)) { | ||||||
|     echo '<b style="color:#990000;">Dependent columns were not observed !</b>'; |     echo '<b style="color:#990000;">Dependent columns were not observed !</b>'; | ||||||
|     foreach ($depencymessage as $tDepMsg) { |     foreach ($depencymessage as $tDepMsg) { | ||||||
|         $validator->addError('<br>' . $tDepMsg) |         $validator->addError('<br>' . $tDepMsg); | ||||||
|     } |     } | ||||||
| } 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>'; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user