<?php
$title = "Argo WMO";
ini_set('include_path', './' . PATH_SEPARATOR . '../' . PATH_SEPARATOR . '../../' . PATH_SEPARATOR . ini_get('include_path'));
include_once("include/header.php");
include_once("include/normpath.php");
?>

    <!--
   **** start with layout component from http://getbootstrap.com/css/#grid
   Any relative links not in the same directory as the templated file should be prepended with
   <?php /* echo $BASEDIR */ ?>
-->
<?php
$debug = False;

$dom = new DOMDocument;
$dom->loadHTMLFile('index.html');
$dom->formatOutput = true;
$xpath = new DOMXPath($dom);

if ($debug) {
	$stuff = htmlspecialchars($dom->saveXML());
	echo "<p>INPUT<code>$stuff</code></p>";
}

// Extract the body
$xpath = new DOMXPath($dom);
$nodes = $xpath->query('/html/body/*');

$ndom = new DOMDocument;
$ndom->formatOutput = true;

// Copy it to the output document
foreach ($nodes as $rec) {
	$node = $ndom->importNode($rec,true);
	$ndom->appendChild($node);
}

// Fix up the hrefs
foreach($ndom->getElementsByTagName('a') as $link ) {
	if ($link->hasAttribute( 'href' )) {
		$href = $link->getAttribute( 'href' );
		if ( substr($href,-5) === '.html' ) {
			$link->setAttribute( 'href', 'profile.php?link='.$href );
			// Link to new cycle page...
			$d = dirname($href);
			//echo "<code>$d</code>\n";
			$wmoid = $d;
			//echo "<code>$wmoid</code>\n";
			$link->setAttribute('href', "cycle.php?wmoid=$wmoid&cycle=-1&depth=0");

		}
	}   
}

// Chop off the unnecessary stuff (some we will put back in our own way)
$ndom->removeChild($ndom->firstChild); // imos header
$ndom->removeChild($ndom->firstChild); // oceancurrent header
$ndom->removeChild($ndom->firstChild); // click test
$ndom->removeChild($ndom->firstChild); // <br>
$ndom->removeChild($ndom->firstChild); // <br>
$ndom->removeChild($ndom->firstChild); // whatsshown
$ndom->removeChild($ndom->firstChild); // argo australia link


if ($debug) {
	$stuff = htmlspecialchars($ndom->saveXML());
	echo "<p>OUTPUT<code>$stuff</code></p>";
}

// That should leave just the guts of the page so we'll
// write out our new header and the page guts
?>
<h3>Argo temperature and salinity down to 2000m</h3>
<p>
	Click on a WMO number below or a <a href="map.php?link=map/latest.html">[point on the map]</a> 
	to see temperature and salinity data from the selected float compared with satellite-adjusted climatology.<br>
	<a href="whatsshown.php">[What's shown]</a> 
	<a href="http://www.cmar.csiro.au/argo/dmqc/html/Argo_DM.html">[Argo Australia delayed-mode processing]</a>  
<p>
<?php echo $ndom->saveHTML(); ?>


<?php
include("include/sfooter.php");
?>
