<?php
/**
* Input DNA data
* <br/><br/>
* Getting specimen data from original provider via wrapper
* <br/><br/>
* Entering new DNA data, setting reference to voucher/specimen
* <br/><br/>
* Access to all user except of guests
* @author Gabriele Droege, DNA Bank Network <contact@dnabank-network.org>
* @version 2.0
* @package Input
* @copyright Copyright © 2011 DNA Bank Network http://www.dnabank-network.org<br>The contents of this file are subject to the Mozilla Public License Version 1.1
* @filesource
* @license http://www.mozilla.org/MPL/ MPL
*/

    /**
    * calling connection to database
    */
    include ("../config/head.php");

    /**
    * calling authorisation script
    */
    include ("../auth.php");
?>

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>DNA Module - Search Results</title>
<link rel="stylesheet" type="text/css" href="../format.css">
<link rel="stylesheet" type="text/css" href="../input/XSLT/Styles.css">
<SCRIPT LANGUAGE="JavaScript1.1" src="../Functions.js"></SCRIPT>
<NOSCRIPT>Please enable Javascript!</NOSCRIPT>

</head>

<body>
<div align="center">
<?php

  /**
  * including navigation menu
  */
  include("../tablenavi.php"); ?>
<form name="form" method="POST" action="input.php">
<table id="tablemain" class="main">
	<tr>
  <td id="tdLogo"><a href="<?php echo $Path_Wiki."/Input_DNA_Data"; ?>" target="_blank"><img border="0" src="../images/Logo-Wiki.png" height="78"></a></td>
		<td id="tdtitle">
		<h1>DNA Data Input</h1></td>
    <td id="tdLogo2"><?php echo $Path_Logo; ?></td>
	</tr>
  <tr>
  <td colspan="3"><?php

    echo "Logged in as: ";
    $log = $_SESSION["log"];
    echo $log;

    if(file_exists("../config/loadconfig.php")) { 
    /**
    * calling general settings
    */
    include("../config/loadconfig.php"); }
    
    ?></td></tr>


<?php

echo "JSON-Test<br/>";
$jsonfile = file_get_contents('http://api.gbif.org/v0.9/occurrence/search?catalogNumber='.urlencode('B 10 0426933').'&limit=50');

// endpoint holen : http://api.gbif.org/v0.9/dataset/85714c48-f762-11e1-a439-00145eb45e9a/endpoint
// die GUID is datasetKey aus der Occurrence

$json_array = json_decode($jsonfile, true);

foreach ($json_array as $key1 => $list1) {


    //  Check type
    if ($key1 == "results" and is_array($list1)) {
	
      //  Scan through inner loop
	echo '<tr><td colspan="4">
		<table id="table2">
    <tr><td colspan="6"><hr /></td></tr>
	<tr><td colspan="6"><div class="voucher"><table width="100%">
    <tr><td colspan="6"><h6>Specimen details (voucher)</h6></td></tr><tr></td>';
	echo '<table width="100%"><tr>
    <td valign="top">
      
      <span class="label">Preferred Taxon Name: </span>
      <span class="prefered">'.$list1[0]["scientificName"].'</span>
      <br/>
      <span class="label">Unit ID: </span>
      <span class="details">'.$list1[0]["catalogNumber"].'</span>
      <br/>
      <span class="label">Record Basis: </span>
      <span class="details">'.$list1[0]["basisOfRecord"].'</span>
      <br/>';
	  if(isset($list1[0]["occurrenceID"])) { echo
      '<span class="label">Unit GUID: </span>
      <span class="details">'.$list1[0]["occurrenceID"].'</span>'; }
	  
    echo '</td>
    <td align="right" valign="top">
      <span class="label">Institution Code: </span>
      <span class="details">'.$list1[0]["institutionCode"].'</span>
      <br/>
      <span class="label">Collection Code: </span>
      <span class="details">'.$list1[0]["collectionCode"].'</span>
      <br/>
    </td>
  </tr></table>';
	echo '<h3 class="background">Identification(s): </h3>
	<table id="tabledetails">
  <tr class="prefered"><td><span class="label">Name: </span></td><td>
      <span class="prefered">'.$list1[0]["scientificName"].'</span></td></tr>
   <tr class="prefered"><td>
   <span class="label">Identifier: </span></td><td>'.$list1[0]["identifiedBy"].'</td></tr>
  <tr class="prefered"><td><span class="label">Taxonomy: </span></td>
    <td><span class="details">'.$list1[0]["family"].'</span><span class="details2"> (familia)</span></td></tr>
	</table>';
	echo '<h3 class="background1">Collection Info:</h3><table id="tabledetails">
  <tr valign="top">
    <td colspan="2"><span class="label">Collector(s): </span><span class="details">'.$list1[0]["recordedBy"].'</span>
      <br/>';
	  if(isset($list1[0]["recordNumber"])) { echo 
      '<span class="label">Field number: </span>
      <span class="details">2011-14</span>
      <br/>'; }
	  echo '<span class="label">Collection Date: </span><span class="details">'.$list1[0]["eventDate"].'</span>
      <br/>
    </td>
  </tr>
  <tr>
    
    </tr>
  <tr><th width="70%">Locality </th><th>Other info </th>
    </tr>
  <tr valign="top"><td>
    <span class="label">Country: </span><span class="details">'.$list1[0]["country"].'</span><span class="details"> '.$list1[0]["countryCode"].'</span>
    <br/>
    <span class="label">Locality: </span><span class="details">'.$list1[0]["locality"].'</span>
    <br/><span class="label">Coordinates (Lat|Lon): </span><span class="details">'.$list1[0]["decimalLatitude"].' | '.$list1[0]["decimalLongitude"].'</span></td><td><span class="label">';
	if(isset($list1[0]["elevation"])) { echo
                 'Altitude: </span><span class="details">'.$list1[0]["elevation"].' m</span><br/>'; }
 echo '</td>
    </tr>
</table></td>
    </tr>
</table></div></td>
    </tr>
</table>';
		
        foreach ($list1 as $key2 => $list2) {
		
		
//		echo "Parameter: " . $list2 . "\n";
		
		
			if (is_array($list2)) {
        //  Scan through inner loop

		
			foreach($list2 as $key3 => $list3) {
		
			if(!is_array($list3)) { 
			
			echo "<tr><td>Parameter: " . $key3; 
			echo " Value: " . $list3 . "</td></tr>"; }
			else {} // nicht auflösende Arrays unterdrücken
			}  // foreach($list2 as $key3 => $list3) 
			

			} // if (is_array($list2))

		} //foreach ($list1 as $key2 => $list2)
				
      } //if ($key1 == "results" and is_array($list1))
		
   } //foreach ($json_array as $key1 => $list1) 
	


?>
</td></tr></table>
</div>
</body>
</html>