﻿<html>
<link rel="stylesheet" type="text/css" href="css/style2.css" />
<h3>COPERNICUS WMS-Dienste - CSW-Schnittstelle</h3>
<?php
include dirname(__FILE__).'/requestcop.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"?>
<csw:GetRecords xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" service="CSW" version="2.0.2" maxRecords="200" resultType="results" outputSchema="http://www.isotc211.org/2005/gmd">
  <csw:Query typeNames="gmd:MD_Metadata">
    <csw:Constraint version="1.1.0">
      <Filter xmlns="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml">
        <PropertyIsLike wildCard="%" singleChar="_" escape="\\">
          <PropertyName>AnyText</PropertyName>
          <Literal>%Baltic%</Literal>
        </PropertyIsLike>
      </Filter>
    </csw:Constraint>
  </csw:Query>
</csw:GetRecords>
';
$contents = request($query);

// Konfiguration: CSV-Tabelle auslesen
$csvFile = "copernicus_dienste.csv";
$firstRowHeader = true;
$maxRows = 100;
 
// Daten auslesen und Tabelle generieren
$handle = fopen($csvFile, "r");
$counter = 0;
echo "<table class=\"csvTable\">";
while(($data = fgetcsv($handle, 999, ";")) && ($counter < $maxRows)) {
	
if ($contents !== false) {
    $document->loadXML($contents);
    $xslDocument = new DOMDocument('1.0', 'utf-8');
    $xslDocument->load(dirname(__FILE__).'/cop.xsl');
    $processor = new XSLTProcessor();
    $processor->importStyleSheet($xslDocument);
    $processor->registerPHPFunctions();
    $processor->setParameter('', 'uuid', $data[5]);
   // header('Content-Type: text/html; charset=utf-8');
}
 
echo "<tr>";
if(($counter == 0) && $firstRowHeader) {
echo "<th>Info</th>";
echo "<th>MD-Viewer</th>";
echo "<th>".$data[0]."</th>";
echo "<th>".$data[1]."</th>";
echo "<th>".$data[3]."</th>";
echo "<th>".$data[2]."</th>";
}
else {
echo "<td><a href=".$data[6]." target=\"_blank\"><img src=\"img/pdf-symbol.png\"></a></td>";
echo "<td><a href=\"http://www.ifremer.fr/geonetwork-myocean-ro/srv/fre/metadata.formatter.html?uuid=".$data[5]."&xsl=mdviewer\" target=\"_blank\"><img src=\"img/html.jpg\"></a></td>";
echo "<td>".$data[0]."</td>";
echo "<td>".$data[1]."</td>";
echo "<td>".$data[3]."</td>";
echo "<td><a href=".$data[2]." target=\"_blank\">".$data[2]."</a></td>";
}
echo "</tr>";
if($counter > 0) {
	echo "<tr>";
	echo "<td colspan='6'>".$processor->transformToXML($document)."</td>";
	echo "</tr>";
}
$counter++;
}
echo "</table>"; 
fclose($handle);

?>
<p>Credits to E.U. Copernicus Marine Service Information.</p>
</html>