TransformProductCode.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. else{
  22. $asocarray[$json->pattern[$i]->abk] = "";
  23. }
  24. }
  25. //Search which abk can be linked to the patternpart
  26. for($i = $fixwerte; $i < count($productarray); ++$i){
  27. foreach($json->pattern as $node){
  28. foreach($node->types as $type){
  29. if($productarray[$i] == $type && $type != "*"){
  30. if(!array_key_exists($node->abk, $asocarray)){ //Add entry when not set
  31. $asocarray[$node->abk] = $productarray[$i];
  32. }
  33. else if($asocarray[$node->abk] == ""){ //allow to update entry when "empty"
  34. $asocarray[$node->abk] = $productarray[$i];
  35. }
  36. }
  37. }
  38. }
  39. }
  40. }
  41. else{
  42. $i = 0;
  43. foreach($json->pattern as $node){
  44. if(isset($productarray[$i])){
  45. $asocarray[$node->abk] = $productarray[$i];
  46. }
  47. ++$i;
  48. }
  49. }
  50. if(!array_key_exists("Pf", $asocarray)){
  51. $asocarray["Pf"] = "KeineAngabePf";
  52. }
  53. if(!array_key_exists("Va", $asocarray)){
  54. $asocarray["Va"] = "KeineAngabeVa";
  55. }
  56. if(!array_key_exists("Kf", $asocarray)){
  57. $asocarray["Kf"] = "KeineAngabeKf";
  58. }
  59. if(!array_key_exists("Zi", $asocarray)){
  60. $asocarray["Zi"] = "KeineAngabeZi";
  61. }
  62. if($asocarray["Pf"] == ""){
  63. $asocarray["Pf"] = "KeineAngabePf";
  64. }
  65. if($asocarray["Va"] == ""){
  66. $asocarray["Va"] = "KeineAngabeVa";
  67. }
  68. if($asocarray["Kf"] == ""){
  69. $asocarray["Kf"] = "KeineAngabeKf";
  70. }
  71. if($asocarray["Zi"] != ""){ //Replace zylinder innen K with nothing
  72. $asocarray["Zi"] = str_replace("K", "", $asocarray["Zi"]);
  73. }
  74. if($asocarray["Zi"] == ""){
  75. $asocarray["Zi"] = "KeineAngabeZi";
  76. }
  77. //reorder 4 same ordering
  78. foreach($json->pattern as $node){
  79. if(array_key_exists($node->abk, $asocarray)){
  80. $asocarray2[$node->abk] = $asocarray[$node->abk];
  81. }
  82. else{
  83. $asocarray2[$node->abk] = "";
  84. }
  85. }
  86. echo json_encode($asocarray2);
  87. ?>