<commit_before><?php require_once "page_auth.php"?>
<?php

//Copyright (c) 2008, California Institute of Technology.
//ALL RIGHTS RESERVED. U.S. Government sponsorship acknowledged.
//
//$Id$

require_once ("login_status.php");
require_once ("XML/RPC.php");
require_once ("classes/Product.class.php");
require_once ("classes/ProductPage.class.php");
require_once ("classes/ProductType.class.php");
require_once ("classes/XmlRpcManager.class.php");
require_once ("config.php");
require_once ("services/ExternalServices.class.php");
require_once ("services/HTTPRequest.class.php");

function decode($str) {
	$string = ereg_replace("%20", " ", $str);
	return $string;
}

function cmp($a, $b)
{
    $a = preg_replace('@^(a|an|the) @', '', $a);
    $b = preg_replace('@^(a|an|the) @', '', $b);
    return strcasecmp($a, $b);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>EDRN ecas user interface</title>
<!-- CSS Includes -->
<link rel="stylesheet" type="text/css" href="assets/edrn-skin/css/edrn-informatics.css"/>
<link rel="stylesheet" type="text/css" href="css/ecas-ui.css" />
<script type="text/javascript">
  function $(id){
    return document.getElementById(id);
  }
  function toggleDetails(id){
    if ($(id + "Contents").style.display != 'none'){
      $(id + "Contents").style.display = 'none';
      $(id + "Toggler").innerHTML = 'more information [+]';
    } else {
      $(id + "Contents").style.display = 'block';
      $(id + "Toggler").innerHTML = 'less information [-]';
    }
  }
</script>
</head>
<body>
<div id="edrninformatics">
	<div id="edrnlogo"><!-- nci logo --></div>
	<div id="edrn-dna"><!-- dna graphic --></div>
	<h2 class="app-title">EDRN Catalog &amp; Archive Service</h2>
	<div class="userdetails">
		<?php checkLoginStatus($_SERVER["REQUEST_URI"])?>
	</div>
</div>

<?php

/**
 * Ensure that a product type ID has been specified.
 */
if (!isset ($_GET['typeID'])) {
	echo "<h4>No typeID specified in the GET parameters</h4>";
	exit ();
}

// Create an XmlRpcManager object to perform the work
$xmlRpcMgr = new XmlRpcManager($filemgrUrl, '/');
// Get the Product from its ProductId
$productType = new ProductType($xmlRpcMgr->getProductTypeById($_GET['typeID']));

if ($productType->getId() == '') {
	echo "<div class=\"error\" style=\"margin-top:60px;margin-left:10px;\">";
	echo "An error was encountered while attempting to retrieve dataset data: <br/>";
	echo "no data found for product type with ID =  $_GET[typeID]<br/><br/>";
	echo "The most likely cause of this error is an invalid or out of date typeID value.<br/>";
	echo "Please check the value and try again.";
	echo "</div>";
	exit ();
}

// Get the Metadata for the product type
$metadata = $productType->getTypeMetadata();
$typeMet = $productType->getTypeMetadata()->toAssocArray();
$typeNameStr = $typeMet["DataSetName"][0];
?>
<!-- Breadcrumbs Area -->
<div id="breadcrumbs"/>
	<a href="./">Home</a>&nbsp/
	Protocol Dataset: <?php echo $productType->getName();?>
</div>
<!-- End Breadcrumbs -->
<h1 class="dataset-name"> <?php echo $typeNameStr; ?> </h1>
<div id="leftSide">
<?php

/**
 * Display the Product-Type Information for this product ID.
 * 
 * 
 */
echo '<div id="typeDetails" class="leftBox">';
echo '<div><h5 class="sectionTitle" style="margin-top:10px;margin-bottom:5px;">Dataset Metadata: </h5></div>';
echo '<div class="detailsToggler" id="metadataDetailsToggler" ';
echo "onclick=\"toggleDetails('metadataDetails');\">less information [-]</div>";
echo '<div class="searchCriteria" id="metadataDetailsContents" style="display:block;">';
echo "<table id=\"metadataTable\" >";
##echo '<tr class="even"><td class="metadata-label">Abstract</td><td>' . $productType->getDescription() . '</td></tr>';
$er = new ExternalServices($externalServicesPath);
$evenOddCounter = 1;
$datasetMetArr = $metadata->toAssocArray();
uksort($datasetMetArr, "cmp");

$abstract = $productType->getDescription();
$specific_order = array (
   "ProtocolName" => array ("Protocol Name", "TBD"),
   "ProtocolID" => array ("Protocol ID", "TBD"),
   "description" => array ("Dataset Abstract", $abstract),
   "DataSetName" => array ("Dataset Name", "TBD"), 
   "LeadPI" => array ("Principal Investigator", "TBD"),
   "SiteName" => array ("Site Name", "TBD"),
   "DataCustodian" => array ("Data Custodian", "TBD"),
   "DataCustodianEmail" => array ("Data Custodian Email", "TBD"),
   "OrganSite" => array ("Organ Site", "TBD"),
   "CollaborativeGroup" => array ("Organ Collaborative Groups", "TBD"),
   "MethodDetails" => array ("Method Details", "TBD"),
   "ResultsAndConclusionSummary" => array ("Analytic Results and Conclusions", "TBD"),
   "PubMedID" => array ("PubMed ID", "TBD"),
   "DateDatasetFrozen" => array ('Date Dataset was "frozen"', "TBD"),
   "Date" => array ("Date", "TBD"),
   "DataDisclaimer" => array ("Disclaimer", "TBD")
);

foreach ($datasetMetArr as $label => $value) {
	if (isset ($er->services[$label])) {
		$r = new HTTPRequest($er->services[$label] . "?id={$value[0]}");
		$str = $r->DownloadToString();
		$value = ($str == '') ? $value : array (
			$str
		);
	}
	##echo '<tr class="' . (($evenOddCounter++ % 2 == 0) ? 'even' : 'odd') . '"><td class="metadata-label">' . $label . '</td><td>';
        $tmp_v = "";
	foreach ($value as $v) {
		#echo "$v ";
                $tmp_v .= $v . " ";
	}
        if ($specific_order[$label]) {
          $specific_order[$label][1] = $tmp_v;
        }
	#echo "</td></tr>";
}

foreach ($specific_order as $key => $value) {
   $label = $value[0];
   $display = $value[1];
   echo '<tr class="' . (($evenOddCounter++ % 2 == 0) ? 'even' : 'odd') . '"><td class="metadata-label">' . $label . '</td><td>' . $display . "</td></tr>";
}

echo "</table>";
echo "</div>";
echo "</div>";

/**<commit_msg>Add special reveal code for <NAME> to view extra metadata mostly for continuous debugging.<commit_after><?php require_once "page_auth.php"?>
<?php

//Copyright (c) 2008, California Institute of Technology.
//ALL RIGHTS RESERVED. U.S. Government sponsorship acknowledged.
//
//$Id$

require_once ("login_status.php");
require_once ("XML/RPC.php");
require_once ("classes/Product.class.php");
require_once ("classes/ProductPage.class.php");
require_once ("classes/ProductType.class.php");
require_once ("classes/XmlRpcManager.class.php");
require_once ("config.php");
require_once ("services/ExternalServices.class.php");
require_once ("services/HTTPRequest.class.php");

function decode($str) {
	$string = ereg_replace("%20", " ", $str);
	return $string;
}

function cmp($a, $b)
{
    $a = preg_replace('@^(a|an|the) @', '', $a);
    $b = preg_replace('@^(a|an|the) @', '', $b);
    return strcasecmp($a, $b);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>EDRN ecas user interface</title>
<!-- CSS Includes -->
<link rel="stylesheet" type="text/css" href="assets/edrn-skin/css/edrn-informatics.css"/>
<link rel="stylesheet" type="text/css" href="css/ecas-ui.css" />
<script type="text/javascript">
  function $(id){
    return document.getElementById(id);
  }
  function toggleDetails(id){
    if ($(id + "Contents").style.display != 'none'){
      $(id + "Contents").style.display = 'none';
      $(id + "Toggler").innerHTML = 'more information [+]';
    } else {
      $(id + "Contents").style.display = 'block';
      $(id + "Toggler").innerHTML = 'less information [-]';
    }
  }
</script>
</head>
<body>
<div id="edrninformatics">
	<div id="edrnlogo"><!-- nci logo --></div>
	<div id="edrn-dna"><!-- dna graphic --></div>
	<h2 class="app-title">EDRN Catalog &amp; Archive Service</h2>
	<div class="userdetails">
		<?php checkLoginStatus($_SERVER["REQUEST_URI"])?>
	</div>
</div>

<?php

/**
 * Ensure that a product type ID has been specified.
 */
if (!isset ($_GET['typeID'])) {
	echo "<h4>No typeID specified in the GET parameters</h4>";
	exit ();
}

// Create an XmlRpcManager object to perform the work
$xmlRpcMgr = new XmlRpcManager($filemgrUrl, '/');
// Get the Product from its ProductId
$productType = new ProductType($xmlRpcMgr->getProductTypeById($_GET['typeID']));

if ($productType->getId() == '') {
	echo "<div class=\"error\" style=\"margin-top:60px;margin-left:10px;\">";
	echo "An error was encountered while attempting to retrieve dataset data: <br/>";
	echo "no data found for product type with ID =  $_GET[typeID]<br/><br/>";
	echo "The most likely cause of this error is an invalid or out of date typeID value.<br/>";
	echo "Please check the value and try again.";
	echo "</div>";
	exit ();
}

// Get the Metadata for the product type
$metadata = $productType->getTypeMetadata();
$typeMet = $productType->getTypeMetadata()->toAssocArray();
$typeNameStr = $typeMet["DataSetName"][0];
?>
<!-- Breadcrumbs Area -->
<div id="breadcrumbs"/>
	<a href="./">Home</a>&nbsp/
	Protocol Dataset: <?php echo $productType->getName();?>
</div>
<!-- End Breadcrumbs -->
<h1 class="dataset-name"> <?php echo $typeNameStr; ?> </h1>
<div id="leftSide">
<?php

/**
 * Display the Product-Type Information for this product ID.
 * 
 * 
 */
echo '<div id="typeDetails" class="leftBox">';
echo '<div><h5 class="sectionTitle" style="margin-top:10px;margin-bottom:5px;">Dataset Metadata: </h5></div>';
echo '<div class="detailsToggler" id="metadataDetailsToggler" ';
echo "onclick=\"toggleDetails('metadataDetails');\">less information [-]</div>";
echo '<div class="searchCriteria" id="metadataDetailsContents" style="display:block;">';
echo "<table id=\"metadataTable\" >";
##echo '<tr class="even"><td class="metadata-label">Abstract</td><td>' . $productType->getDescription() . '</td></tr>';
$er = new ExternalServices($externalServicesPath);
$evenOddCounter = 1;
$datasetMetArr = $metadata->toAssocArray();
uksort($datasetMetArr, "cmp");

$abstract = $productType->getDescription();
$specific_order = array (
   "ProtocolName" => array ("Protocol Name", "TBD"),
   "ProtocolID" => array ("Protocol ID", "TBD"),
   "description" => array ("Dataset Abstract", $abstract),
   "DataSetName" => array ("Dataset Name", "TBD"), 
   "LeadPI" => array ("Principal Investigator", "TBD"),
   "SiteName" => array ("Site Name", "TBD"),
   "DataCustodian" => array ("Data Custodian", "TBD"),
   "DataCustodianEmail" => array ("Data Custodian Email", "TBD"),
   "OrganSite" => array ("Organ Site", "TBD"),
   "CollaborativeGroup" => array ("Organ Collaborative Groups", "TBD"),
   "MethodDetails" => array ("Method Details", "TBD"),
   "ResultsAndConclusionSummary" => array ("Analytic Results and Conclusions", "TBD"),
   "PubMedID" => array ("PubMed ID", "TBD"),
   "DateDatasetFrozen" => array ('Date Dataset was "frozen"', "TBD"),
   "Date" => array ("Date", "TBD"),
   "DataDisclaimer" => array ("Disclaimer", "TBD")
);

if ($_GET["reveal"]) {
  $reveal_all_flag = true; 
} else {
  $reveal_all_flag = false;
}

foreach ($datasetMetArr as $label => $value) {
	if (isset ($er->services[$label])) {
		$r = new HTTPRequest($er->services[$label] . "?id={$value[0]}");
		$str = $r->DownloadToString();
		$value = ($str == '') ? $value : array (
			$str
		);
	}
	##echo '<tr class="' . (($evenOddCounter++ % 2 == 0) ? 'even' : 'odd') . '"><td class="metadata-label">' . $label . '</td><td>';
        $tmp_v = "";
	foreach ($value as $v) {
		#echo "$v ";
                $tmp_v .= $v . " ";
	}
        if (! $specific_order[$label] && $reveal_all_flag == true) {
          $specific_order[$label][0] = $label;
          $specific_order[$label][1] = $tmp_v;
        } 
        if ($specific_order[$label]) {
          $specific_order[$label][1] = $tmp_v;
        }

	#echo "</td></tr>";
}

foreach ($specific_order as $key => $value) {
   $label = $value[0];
   $display = $value[1];
   echo '<tr class="' . (($evenOddCounter++ % 2 == 0) ? 'even' : 'odd') . '"><td class="metadata-label">' . $label . '</td><td>' . $display . "</td></tr>";
}

echo "</table>";
echo "</div>";
echo "</div>";

/**
{'fraction_non_alphanumeric': 0.217196048011758, 'fraction_numerical': 0.007838654364334122, 'mean_word_length': 4.489914836396235, 'pattern_counts': {'":': 0, '<': 162, '<?xml version=': 0, '>': 220, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5845830', 'n_tokens_mistral': 4247, 'n_tokens_neox': 4113, 'n_words': 998}