<html>
<head>
<title>Baumdiagramm</title>

<style type="text/css">
#rundrum {
  border-width:5px;
  border-style:outset;
  border-color:grey;
  padding:2px;
  text-align:center;
}
</style>

</head>
<body>
<div align=center style="position:absolute; top:50px; left:10%;">

<?php

include './lib/config.inc.php';
include './lib/MySQL.class.php';

// new mysql instance
$MySQL = new MySQL( MYSQL_HOST, MYSQL_USERNAME, MYSQL_PASSWORD, MYSQL_DATABASE );

function getTree( $herstID, $anzahl, $MySQL ){
	$query = "SELECT * FROM server.herstellung WHERE her_herstellungsid = '$herstID'";
	$result = $MySQL->query($query);
	$item = mysql_fetch_object($result);
	if ($item->name != "")
	{
		$ressourcen = explode(")", $item->ressourcen);
		$cs = sizeof($ressourcen)-1;
		$beschreibung = trim($item->beschreibung);
		$query = "SELECT * FROM server.werkzeug_typen WHERE typ = '$item->werkzeug'"; 
		$result = $MySQL->query($query);
		$werkzeug = mysql_fetch_object($result);
		
		$query = "SELECT * FROM server.container_typen WHERE container_typen_id = '$item->container'"; 
		$result = $MySQL->query($query);
		$container = mysql_fetch_object($result);
		$containername = $container->container_typen_name;
		if ($container->container_typen_id == 4 or $containername =="")
			$containername = Kein;

			
		echo "<table align=middle border='0' frame=void guides=none><tr><td colspan=$cs align=middle valign=top>";
		//echo "$cs<br>";
		echo "<div id='rundrum' onmouseover=\"return escape('$beschreibung<br>Werkzeug: $werkzeug->werkzeug_name <br>Container: $containername')\">";
		if ($item->ressourcen != ""){
		
			echo "$anzahl $item->name</div></td></tr> \r\n";
		
			echo "<tr>";
			//Diagramm-Balken - Murks
			$balken = "<img src='ketten\balken.gif'>";
			if ($cs > 1){
			for ($j = 1; $j <= $cs; $j++){
				if ($cs%2 == 1){
					if ($j == 1){
						echo "<td align=center><img src='ketten/linksende.gif'><div style='position:relative' align='left'><img src='ketten/balken.gif' style='z-index:1; position:absolute; top:-40px; left:50%; width: 100%; height:40px'></div>";
						//echo $balken;
					}
					else if ($j != ceil($cs/2) and $j != $cs and $j != 1) {
						echo "</td><td align=center><img src='ketten/tstueck.gif'><div style='position:relative' align='left'><img src='ketten/balken.gif' style='z-index:1; position:absolute; top:-40px; left:0%; width: 100%; height:40px'></div>";
						//echo $balken;
					}
					else if ($j == ceil($cs/2)){
						//echo $balken;
						echo "</td><td align=center><img src='ketten/kreuz.gif'><div style='position:relative' align='left'><img src='ketten/balken.gif' style='z-index:1; position:absolute; top:-40px; left: -20%; width: 150%; height:40px'></div>";
						//echo $balken;
						//echo $balken;
					}
					else if ($j == $cs) {
						echo "</td><td align=center><img src='ketten/rechtsende.gif'><div style='position:relative' align='left'><img src='ketten/balken.gif' style='z-index:1; position:absolute; top:-40px; left:0%; width: 50%; height:40px'></div></td>";}
					}
					else {
						if ($j == 1){
						echo "<td align=center><img src='ketten/linksende.gif'>";
						//echo $balken;
						}
						else if ($j != $cs and $j != 1) {
							echo "</td><td align=center><img src='ketten/tstueck.gif'>";
							//echo $balken;
						}
						if ($j == $cs/2){
							echo "<img src='ketten/mittebalken.gif'><div style='position:relative' align='left'><img src='ketten/balken.gif' style='z-index:1; position:absolute; top:-40px; left:65%; width: 50%; height:40px'></div></td>";
							//echo $balken;
						}
						if ($j == $cs) {
							echo "</td><td align=center><img src='ketten/rechtsende.gif'><div style='position:relative' align='left'><img src='ketten/balken.gif' style='z-index:1; position:absolute; top:-40px; left:0%; width: 50%; height:40px'></div></td>";}
						}
					}
				}
				else echo "<td align=center><img src='ketten/linie.gif' height=20px width=40px></td>";
				//Ende Diagramm-Balken - Murks
			
			
				echo "</tr><tr>";
				for ($i = 0; $i < $cs; $i++) {
					$temp = explode("(", $ressourcen[$i]);
					echo "<td align=center valign=top>";
					getTree( $temp[0], $temp[1], $MySQL );
					echo "</td>";
				};
				echo "</tr>";
 			}
			else {
				$query = "select count(*) from server.endprodukte where klassenname='MultiItem' and int_0=$item->her_herstellungsid"; 
				$result = $MySQL->query($query);
				$count = mysql_fetch_row($result);
				if ($count[0] != "0")
				{
					echo "<a href='itemsuche.php?a=".$item->name."&profession=-1&min=0&max=50'>$anzahl $item->name</a></div></td></tr> \r\n";
				}
				else
				{
					echo "$anzahl $item->name</div></td></tr> \r\n";
				}
			}
		echo "</table>";
	} else 
		echo "Fehler! Der Name des Items ist leer.";
}

$herstellungsid = mysql_real_escape_string($_GET['p']);
getTree( $herstellungsid, 1, $MySQL);
?>

</div>
<script language="JavaScript" type="text/javascript" src="wz_tooltip.js"></script>
</body>
</html>
