summaryrefslogtreecommitdiffstats
path: root/index.php
diff options
context:
space:
mode:
Diffstat (limited to 'index.php')
-rw-r--r--index.php19
1 files changed, 9 insertions, 10 deletions
diff --git a/index.php b/index.php
index a67bd26..ee7431c 100644
--- a/index.php
+++ b/index.php
@@ -3,19 +3,18 @@ header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: Content-Type");
$method = $_SERVER['REQUEST_METHOD'];
$xml = simplexml_load_file("./terc.xml");
-// var_dump($xml);
if ($method === "GET") {
- // $result = $xml->xpath('//row/NAZWA_DOD[text()="województwo"]/ancestor::*/NAZWA/text()');
- $result = $xml->xpath('//NAZWA_DOD[text()="województwo"]/ancestor::*/NAZWA/text() | //NAZWA_DOD[text()="województwo"]/ancestor::*/WOJ/text()');
+ $result = $xml->xpath('//NAZWA_DOD[text()="województwo"]/ancestor::*/NAZWA/text()');
} else if ($method === "POST") {
$body = file_get_contents('php://input');
- // echo $body;
- // echo '//row/NAZWA[text()="' . $body . '"]/ancestor::*/NAZWA_DOD[contains(text(),"miejs")]/ancestor::*/NAZWA/text()';
- $result = $xml->xpath('//row/WOJ[text()="' . $body . '"]/ancestor::*/NAZWA_DOD[contains(text(),"miejs")]/ancestor::*/NAZWA/text()');
-} else {
- $result = $xml->xpath('//row/NAZWA[text()="ŁÓDZKIE"]/ancestor::*/NAZWA_DOD[contains(text(),"miejs")]/ancestor::*/NAZWA/text()');
- $result = $xml->xpath('//WOJ[text()="10"]/ancestor::*/NAZWA_DOD[contains(text(),"miejs")]/ancestor::*/NAZWA/text()');
- $result = $xml->xpath('//NAZWA_DOD[text()="województwo"]/ancestor::*/NAZWA/text() | //NAZWA_DOD[text()="województwo"]/ancestor::*/WOJ/text()');
+ $one_xpath = true;
+ if (!$one_xpath) {
+ $id = $xml->xpath('//row/NAZWA[text()="' . $body . '"]/ancestor::*/WOJ');
+ $id = "{$id[0]}";
+ $result = $xml->xpath('//WOJ[text()=' . $id . ']/ancestor::*/NAZWA_DOD[contains(text(),"miejs")]/ancestor::*/NAZWA/text()');
+ } else {
+ $result = $xml->xpath('//WOJ[text()=//row/NAZWA[text()="' . $body . '"]/ancestor::*/WOJ]/ancestor::*/NAZWA_DOD[contains(text(),"miejs")]/ancestor::*/NAZWA/text()');
+ }
}
$result = array_map(function ($x) {
return "$x";