<?php
	if(!isset($_SESSION)) session_start();
	include 'sparql.php';
	require_once("demosettings.php");
	require_once("parseUtils.php");
	
	$id = $_REQUEST["id"];
	$doc = $_REQUEST["doc"];
	
	$basicAttrs = "<table width=\"100%\">";
	$directory = getDocMetadataFolder($dcid);
	$file = fopen($directory . "\doc$doc" . "_slot_$id" . ".txt", "r");
	if ($file){
		while(!feof($file)){
			$basicAttrs .= "<tr>";
		    $line = fgets($file);
		    $e = explode("=", $line);
		    $basicAttrs .= "<td valign=\"top\"><b>$e[0]</b></td><td>" .
								$e[1] . "</td></tr>";	    
		}
		fclose($file);		
	}
	$basicAttrs .= "</table>";
/*	$aaa = "<" . qualifyName($id, $doc) . ">";
	$sparql = buildBasicSparql("SELECT ?att ?value ?vcap ?st ?stcap
				WHERE
  				{" .
  					$aaa . " ?att ?value .
  					OPTIONAL { ?value iv:caption ?vcap . FILTER(langMatches(lang(?vcap),\"EN\")|| (!langMatches(lang(?vcap),\"*\")) )} .
  					OPTIONAL { ?value rdf:type rdf:Seq .
  							   ?value ?s ?st . FILTER(!regex(str(?s), \"type\"))
  							   OPTIONAL { ?st iv:caption ?stcap . FILTER(langMatches(lang(?stcap),\"EN\")|| (!langMatches(lang(?stcap),\"*\")) )} .
  							 }
  				}");
	$json = executeSparql($sparql);

	//echo $sparql . "<br>";
	//print_r($json);

	$sparql = buildBasicSparql("SELECT ?t
				WHERE
  				{" .
  					$aaa . " rdf:type ?t .
  				}");
	$typeJson = executeSparql($sparql, "ontp");

	//print_r($json);

	$basicAttrs = "<table width=\"100%\">";
	$links = "<table width=\"100%\">";
	foreach($typeJson[results][bindings] as $entry){
		$name = unqualifyName($entry[t][value]);
		$basicAttrs = $basicAttrs . "<tr>";
		$basicAttrs = $basicAttrs . "<td valign=\"top\"><b>type</b></td><td>" .
							$name . "</td></tr>";
		break;
	}

	foreach($json[results][bindings] as $entry){
		$name = unqualifyName($entry[att][value]);
		if($entry[value][type] == "literal"){
			if($name == "context" || $name == "batch-context"){
				continue;
			}
			$basicAttrs = $basicAttrs . "<tr>";
			$basicAttrs = $basicAttrs . "<td valign=\"top\"><b>" . $name . "</b></td><td>" . $entry[value][value] . "</td></tr>";
		}else if($entry[value][type] == "uri"){
			if($name == "type"){
				continue;
			}
			$links = $links . "<tr>";
			$links = $links . "<td valign=\"top\"><b>" . $name . "</b></td><td>";
			if(strlen($entry[vcap][value]) > 0)
				$links = $links . $entry[vcap][value];
			else{
				$unqName = unqualifyName($entry[value][value]);
				$links = $links . "<a href=\"javascript:showElement('" . $unqName . "');\">" . $unqName . "</a>";
			}
			$links = $links . "</td></tr>";
		}else if(strlen($entry[st][value]) > 0){
			$links = $links . "<tr>";
			$links = $links . "<td valign=\"top\"><b>" . $name . "</b></td><td>";
			if(strlen($entry[stcap][value]) > 0)
				$links = $links . $entry[stcap][value];
			else{
				$unqName = unqualifyName($entry[st][value]);
				$links = $links . "<a href=\"javascript:showElement('" . $unqName . "');\">" . $unqName . "</a>";
			}
			$links = $links . "</td></tr>";
		}
	}
	$basicAttrs = $basicAttrs . "</table>";
	$links = $links . "</table>";
*/
?>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>jQuery UI Accordion - Customize icons</title>
	<!--<link rel="stylesheet" href="jquery-ui/development-bundle/themes/base/jquery.ui.all.css">
	<script src="jquery-ui/development-bundle/jquery-1.7.1.js"></script>
	<script src="jquery-ui/development-bundle/ui/jquery.ui.core.js"></script>
	<script src="jquery-ui/development-bundle/ui/jquery.ui.widget.js"></script>
	<script src="jquery-ui/development-bundle/ui/jquery.ui.accordion.js"></script>
	<script src="jquery-ui/development-bundle/ui/jquery.ui.button.js"></script>
	<link rel="stylesheet" href="jquery-ui/development-bundle/demos/demos.css">-->
	<!--<script>
	$(function() {
		var icons = {
			header: "ui-icon-circle-arrow-e",
			headerSelected: "ui-icon-circle-arrow-s"
		};
		$( "#accordion" ).accordion({
			icons: icons
		});
		$( "#toggle" ).button().toggle(function() {
			$( "#accordion" ).accordion( "option", "icons", false );
		}, function() {
			$( "#accordion" ).accordion( "option", "icons", icons );
		});
	});
	</script>-->
</head>
<body>
<h2 class="star"><span>Properties</span></h2>
<p style="font-size:10px; color:gray;"><i><?= $id ?></i></p>
<div id="accordion" width="100%">
	<h3><a href="#">Basic Attributes</a></h3>
	<div style="padding: 0 0 0 0;">
		<p><?php echo $basicAttrs ?></p>
	</div>	
</div>
</body>