TransformProductCode.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. ini_set('display_errors', 1);
  3. ini_set('display_startup_errors', 1);
  4. error_reporting(E_ALL);
  5. header('Content-Type: application/json');
  6. $url = realpath("./../server/json/ProductCode.json");
  7. $json = file_get_contents($url);
  8. $json = json_decode($json);
  9. $productcode = str_replace("/", ".", $_GET["ProductCode"]);
  10. $productarray = explode(".", $productcode);
  11. if($_GET["ProductCode"] == ""){
  12. echo json_encode (json_decode ("{}"));
  13. return;
  14. }
  15. if(isset($_GET["Semantic"])){
  16. $fixwerte = 6;
  17. for($i = 0; $i < $fixwerte; ++$i){
  18. if(isset($productarray[$i])){
  19. $asocarray[$json->pattern[$i]->abk] = $productarray[$i];
  20. /*
  21. if($json->pattern[$i]->abk == "Zi" && $productarray[$i] == "NI" ){
  22. $asocarray[$json->pattern[$i]->abk] = "";
  23. }
  24. */
  25. }
  26. else{
  27. $asocarray[$json->pattern[$i]->abk] = "";
  28. }
  29. }
  30. //Search which abk can be linked to the patternpart
  31. for($i = $fixwerte; $i < count($productarray); ++$i){
  32. foreach($json->pattern as $node){
  33. foreach($node->types as $type){
  34. if($productarray[$i] == $type && $type != "*"){
  35. if(!array_key_exists($node->abk, $asocarray)){ //Add entry when not set
  36. $asocarray[$node->abk] = $productarray[$i];
  37. }
  38. else if($asocarray[$node->abk] == ""){ //allow to update entry when "empty"
  39. $asocarray[$node->abk] = $productarray[$i];
  40. }
  41. }
  42. }
  43. }
  44. }
  45. }
  46. else{
  47. $i = 0;
  48. foreach($json->pattern as $node){
  49. if(isset($productarray[$i])){
  50. $asocarray[$node->abk] = $productarray[$i];
  51. }
  52. ++$i;
  53. }
  54. }
  55. if(!array_key_exists("Pf", $asocarray)){
  56. $asocarray["Pf"] = "KeineAngabePf";
  57. }
  58. if(!array_key_exists("Va", $asocarray)){
  59. $asocarray["Va"] = "KeineAngabeVa";
  60. }
  61. if(!array_key_exists("Kf", $asocarray)){
  62. $asocarray["Kf"] = "KeineAngabeKf";
  63. }
  64. if(!array_key_exists("Zi", $asocarray)){
  65. $asocarray["Zi"] = "KeineAngabeZi";
  66. }
  67. if($asocarray["Pf"] == ""){
  68. $asocarray["Pf"] = "KeineAngabePf";
  69. }
  70. if($asocarray["Va"] == ""){
  71. $asocarray["Va"] = "KeineAngabeVa";
  72. }
  73. if($asocarray["Kf"] == ""){
  74. $asocarray["Kf"] = "KeineAngabeKf";
  75. }
  76. if($asocarray["Zi"] != ""){ //Replace zylinder innen K with nothing
  77. $asocarray["Zi"] = str_replace("K", "", $asocarray["Zi"]);
  78. }
  79. if($asocarray["Zi"] == ""){
  80. $asocarray["Zi"] = "KeineAngabeZi";
  81. }
  82. //reorder 4 same ordering
  83. foreach($json->pattern as $node){
  84. if(array_key_exists($node->abk, $asocarray)){
  85. $asocarray2[$node->abk] = $asocarray[$node->abk];
  86. }
  87. else{
  88. $asocarray2[$node->abk] = "";
  89. }
  90. }
  91. echo json_encode($asocarray2);
  92. ?>