123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- <?php
- ini_set('display_errors', 1);
- ini_set('display_startup_errors', 1);
- error_reporting(E_ALL);
-
- header('Content-Type: application/json');
-
- $url = realpath("./../server/json/ProductCode.json");
- $json = file_get_contents($url);
- $json = json_decode($json);
-
- $productcode = str_replace("/", ".", $_GET["ProductCode"]);
- $productarray = explode(".", $productcode);
-
-
- if($_GET["ProductCode"] == ""){
- echo json_encode (json_decode ("{}"));
- return;
- }
- if(isset($_GET["Semantic"])){
- $fixwerte = 6;
- for($i = 0; $i < $fixwerte; ++$i){
- if(isset($productarray[$i])){
- $asocarray[$json->pattern[$i]->abk] = $productarray[$i];
- /*
- if($json->pattern[$i]->abk == "Zi" && $productarray[$i] == "NI" ){
- $asocarray[$json->pattern[$i]->abk] = "";
-
- }
- */
- }
- else{
- $asocarray[$json->pattern[$i]->abk] = "";
- }
- }
-
- //Search which abk can be linked to the patternpart
- for($i = $fixwerte; $i < count($productarray); ++$i){
- foreach($json->pattern as $node){
- foreach($node->types as $type){
- if($productarray[$i] == $type && $type != "*"){
- if(!array_key_exists($node->abk, $asocarray)){ //Add entry when not set
- $asocarray[$node->abk] = $productarray[$i];
- }
- else if($asocarray[$node->abk] == ""){ //allow to update entry when "empty"
- $asocarray[$node->abk] = $productarray[$i];
- }
- }
- }
- }
- }
- }
- else{
- $i = 0;
- foreach($json->pattern as $node){
- if(isset($productarray[$i])){
- $asocarray[$node->abk] = $productarray[$i];
- }
- ++$i;
- }
-
- }
-
-
-
- if(!array_key_exists("Pf", $asocarray)){
- $asocarray["Pf"] = "KeineAngabePf";
- }
- if(!array_key_exists("Va", $asocarray)){
- $asocarray["Va"] = "KeineAngabeVa";
- }
- if(!array_key_exists("Kf", $asocarray)){
- $asocarray["Kf"] = "KeineAngabeKf";
- }
- if(!array_key_exists("Zi", $asocarray)){
- $asocarray["Zi"] = "KeineAngabeZi";
- }
-
- if($asocarray["Pf"] == ""){
- $asocarray["Pf"] = "KeineAngabePf";
- }
- if($asocarray["Va"] == ""){
- $asocarray["Va"] = "KeineAngabeVa";
- }
- if($asocarray["Kf"] == ""){
- $asocarray["Kf"] = "KeineAngabeKf";
- }
- if($asocarray["Zi"] != ""){ //Replace zylinder innen K with nothing
- $asocarray["Zi"] = str_replace("K", "", $asocarray["Zi"]);
- }
- if($asocarray["Zi"] == ""){
- $asocarray["Zi"] = "KeineAngabeZi";
- }
-
-
- //reorder 4 same ordering
- foreach($json->pattern as $node){
- if(array_key_exists($node->abk, $asocarray)){
- $asocarray2[$node->abk] = $asocarray[$node->abk];
- }
- else{
- $asocarray2[$node->abk] = "";
-
- }
- }
-
- echo json_encode($asocarray2);
- ?>
|