<html>
<link rel="stylesheet" type="text/css" href="css/style.css" />
<?php
include dirname(__FILE__).'/request.php';

function getPageName($acronym) {
    $name = str_replace('+', 'p', $acronym);

    return str_replace(' ', '', strtolower(iconv('UTF-8', 'ASCII//TRANSLIT', $name)));
}

$document = new DOMDocument('1.0', 'utf-8');

$query =
'<?xml version="1.0" encoding="utf-8"?>
<GetRecords outputFormat="application/xml" startPosition="1" maxRecords="500"
    outputSchema="http://www.disy.de/preludio2/nokis"
    service="CSW"
    version="2.0.2"
    resultType="results"
    xmlns="http://www.opengis.net/cat/csw/2.0.2"
    xmlns:csw="http://www.opengis.net/cat/csw/2.0.2"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:ogc="http://www.opengis.net/ogc"
    xmlns:nokis="http://www.disy.de/preludio2/nokis">
  <Query typeNames="nokis:project" xsi:type="csw:QueryType" xmlns:gmd="http://www.isotc211.org/2005/gmd">
    <ElementSetName>full</ElementSetName>
    <Constraint version="1.1.0">
      <ogc:Filter xmlns:gml="http://www.opengis.net/gml">
        <ogc:And>
          <ogc:PropertyIsEqualTo>
            <ogc:PropertyName>AnyText</ogc:PropertyName>
            <ogc:Literal>onGoing</ogc:Literal>
          </ogc:PropertyIsEqualTo>
        </ogc:And>
      </ogc:Filter>
    </Constraint>
  </Query>
</GetRecords>
';

$contents = request($query);
// echo $contents;

if ($contents !== false) {
    $document->loadXML($contents);

    $xslDocument = new DOMDocument('1.0', 'utf-8');
    $xslDocument->load(dirname(__FILE__).'/nokis.xsl');

    $processor = new XSLTProcessor();
    $processor->importStyleSheet($xslDocument);

    $processor->registerPHPFunctions();

    $processor->setParameter('', 'sort', isset($_REQUEST['sort']) ? $_REQUEST['sort'] : 'date');

    header('Content-Type: text/html; charset=utf-8');

    echo $processor->transformToXML($document);
}
?>
</html>
