summaryrefslogtreecommitdiffstats
path: root/index.php
blob: cb50f699ee08b005960be611b7b062d08f16d065 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: Content-Type");
$method = $_SERVER['REQUEST_METHOD'];
$xml = simplexml_load_file("./terc.xml");
if ($method === "GET") {
  $result = $xml->xpath('//NAZWA_DOD[text()="województwo"]/ancestor::*/NAZWA/text()');
} else if ($method === "POST") {
  $body = file_get_contents('php://input');
  $one_xpath = false;
  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 {
    set_time_limit(200);
    $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";
}, $result);
echo json_encode($result);
// print_r($result);