diff --git a/public/index3.php b/public/index3.php index 99ddd4f..57dceb9 100644 --- a/public/index3.php +++ b/public/index3.php @@ -14,8 +14,7 @@ $allowed_langs = ['ar', 'de', 'en', 'hu', 'id', 'it', 'pl','pt']; if (isset($_GET['navlang'])) { $_SESSION['lang'] = $_GET['navlang']; 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); } $lang = $_SESSION['lang']; @@ -88,19 +87,20 @@ if ($error != 0) echo '
Not allowed tags found !
2: Not allowed multiple use of tags (column names)?'; +//TODO: only check if the sizes are the same $compare = array_unique($zeile); $result = identical_values($zeile, $compare); if ($result == false) { echo '
There are dublicate column names !'; $error = $error + 1; -} -else { +} else { echo '
No dublicate column names !'; } //// 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, ';')) { @@ -125,19 +125,20 @@ $inv_error = 0; * * @return array */ -function get_duplicates(array $array):array { +function get_duplicates(array $array):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']; foreach ($mandatory as $tMandatoryField) { if (!in_array($tMandatoryField, $erstezeile)) { echo '
Mandatory: Column ' . $tMandatoryField . ' missing'; $error = $error + 1; $inv_error = $inv_error + 1; - } - else { + } else { $spaltenr = array_search($tMandatoryField, $erstezeile); for ($j = 0; $j < $y; $j++) { if ($inhalt[$j + 1][$spaltenr] == '') { @@ -151,7 +152,10 @@ foreach ($mandatory as $tMandatoryField) { } } } -if ($inv_error == 0) echo '
All mandatory tags available and with values !'; + +if ($inv_error == 0) { + echo '
All mandatory tags available and with values !'; +} ///// Check #4 @@ -164,10 +168,10 @@ if (in_array('inventory_number', $erstezeile)) { echo '
Multiple use of inventory_number ' . $tDublicateInvNo . ''; $error = $error + 1; } + } else { + echo '
All inventory_numbers are unique !'; } - else echo '
All inventory_numbers are unique !'; -} -else { +} else { echo '
Aborted, column inventory_number is missing'; $error = $error + 1; } @@ -178,8 +182,11 @@ echo '

5: Dependent colums observed ?
'; // Check for correct handling of dependent fields 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) { if (array_search($tDependentField, $erstezeile) === false) { @@ -195,14 +202,14 @@ if (!empty($depencymessage)) { echo '
' . $tDepMsg; $error = $error + 1; } -} -else { +} else { echo 'Dependent columns were observed !'; } ///// Check #6 echo '

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']; $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; } } + + //TODO: reverse the IF and use it before the error message if ($allDependentsEmpty === true) continue; } @@ -315,8 +324,7 @@ if (isset($errormessage) and $errormessage != '') { echo '
' . $tMsg; $error++; } -} -else { +} else { echo 'Values in controlled fields are all valid !'; } @@ -324,18 +332,21 @@ else { unset($errormessage); echo '

8: Main image or main resource given?
'; $hasanyimage = 0; -for ($im = 1; $im < 29; $im++) -{ - if (array_search('image_name' . $im, $erstezeile) != '') {$imagemain[$im]['name'] = array_search('image_name' . $im, $erstezeile);$hasanyimage++; +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_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) { $imagemain = array_values($imagemain); - for ($i = 1; $i <= $y; $i++) - { + for ($i = 1; $i <= $y; $i++) { if ($i > 1) { //check if in a row any image_name is given $maimg = $hatimg = 0; @@ -357,8 +368,12 @@ if ($hasanyimage > 0) { } } } - if ($maimg == 0 and $hatimg > 0) $errormessage[] = 'There is no visible main image given in row ' . $i . ''; - if ($maimg > 1 and $hatimg > 0) $errormessage[] = 'There are ' . $maimg . ' main images given in row ' . $i . ''; + if ($maimg == 0 and $hatimg > 0) { + $errormessage[] = 'There is no visible main image given in row ' . $i . ''; + } + if ($maimg > 1 and $hatimg > 0) { + $errormessage[] = 'There are ' . $maimg . ' main images given in row ' . $i . ''; + } } } @@ -368,12 +383,10 @@ if ($hasanyimage > 0) { echo '
' . $tMsg; $error++; } - } - else { + } else { echo 'For each object that has images attached exactly one main image is given !'; } -} -else { +} else { echo 'No images to be imported !'; } @@ -382,8 +395,7 @@ if ($error + $depcon_error > 0) { echo '

Error(s) found: ' . ($error + $depcon_error) . '

'; echo 'Create XML for md:import (utf8)
'; -} -else { +} else { echo 'Create XML for md:import (utf8)
'; } echo '';