TransformProductCode.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. $asocarray[$node->abk] = $productarray[$i];
  31. }
  32. }
  33. }
  34. }
  35. }
  36. else{
  37. $i = 0;
  38. foreach($json->pattern as $node){
  39. if(isset($productarray[$i])){
  40. $asocarray[$node->abk] = $productarray[$i];
  41. }
  42. ++$i;
  43. }
  44. }
  45. if(!array_key_exists("Pf", $asocarray)){
  46. $asocarray["Pf"] = "KeineAngabePf";
  47. }
  48. if(!array_key_exists("Va", $asocarray)){
  49. $asocarray["Va"] = "KeineAngabeVa";
  50. }
  51. if(!array_key_exists("Kf", $asocarray)){
  52. $asocarray["Kf"] = "KeineAngabeKf";
  53. }
  54. if(!array_key_exists("Zi", $asocarray)){
  55. $asocarray["Zi"] = "KeineAngabeZi";
  56. }
  57. if($asocarray["Pf"] == ""){
  58. $asocarray["Pf"] = "KeineAngabePf";
  59. }
  60. if($asocarray["Va"] == ""){
  61. $asocarray["Va"] = "KeineAngabeVa";
  62. }
  63. if($asocarray["Kf"] == ""){
  64. $asocarray["Kf"] = "KeineAngabeKf";
  65. }
  66. if($asocarray["Zi"] == ""){
  67. $asocarray["Zi"] = "KeineAngabeZi";
  68. }
  69. echo json_encode($asocarray);
  70. ?>