<?php
@session_start();

if ( strtolower( $_SESSION[ "benutzer_anmeldename" ] ) <> "superuser" )
{
	$_SESSION[ "benutzer_anmeldename" ] = "";
	header("Location: index.php");
}

$_SESSION[ "title" ] = "Wertemengen-Elemente";
virtual( 'ssi_header.php' );
$_SESSION[ "title" ] = "";

//$wertemengen = liefere_alle_wertemengen_kuerzel( "Standard", false );

$mandant_name = $_GET[ "mandant_name" ];
$wertemengen_kuerzel = $_GET[ "wertemenge_kuerzel" ];

	include( "su_menu.php" );
	
	echo "<div style='margin-left:200px; padding-bottom:30px;  min-height:550px;'>";
	
//echo $mandant_name." ".$wertemengen_kuerzel;

$elemente = liefere_wertemenge_elemente( $mandant_name, $wertemengen_kuerzel );

$wertemenge = liefere_wertemenge( $mandant_name, $wertemengen_kuerzel );

$i = 0;

$html = "<table border='0' style='border:0px solid white; min-width:500px; font-size:90%;  padding: 0px; '><tr>";
foreach( $wertemenge[ 2 ] as $key=>$eigenschaft )
{
	
	if ( substr( $key, 0, 12 ) == "bezeichnung_" )
	{
		if ( strlen( $eigenschaft ) > 0 )
		{
			$html = $html."<th style='text-align:left;' >".$eigenschaft."</th>";
			$enthalten[  ] = substr( $key, 12 );
			$enthalten_string = $enthalten_string.substr( $key, 12 )."|";
			$i++;
		}
	}
}
if ( $wertemenge[ 2 ][ "typ" ] == "static" )
{
	$html = $html."<th>Optionen</th>";
}
$html = $html."</tr><tr>";
//echo count( $enthalten);
if ( count( $elemente[ 2 ] ) > 0 )
{
	foreach ( $elemente[ 2 ] as $element )
	{
		//xlog( 4, "Element ".$element );
		$j = 0;
		foreach( $element as $key=>$value )
		{
			//xlog( 4, "key ".$key." value ".$value );
			foreach ( $enthalten as $ele )
			{
				//xlog( 4, "ele ".$ele." key ".$key );
				if ( $ele == $key )
				{
					$html = $html. "<td style='margin:0px;'>".$element[ $ele ]."</td>";
					$j++;
					//xlog( 4, "treffer ele ".$ele." key ".$key );
				}
			}
			
			
		}
		
		
		if ( bccomp( $j, $i, 0 ) < 0 )
		{
			for ( $k = $j; $k < $i; $k++ )
			{
				$html = $html."<td>&nbsp;</td>";
			}
		}
		
		if ( $wertemenge[ 2 ][ "typ" ] == "static" )
		{
			$html = $html."<td style='margin:0px;min-width: 120px; vertical-align:middle;'><input type='button' value='l&ouml;schen' style='width:60px; height:20px; font-size:.8em;' onclick=\"document.location.href='su_web.php?cmd=wertemengen_element_loeschen&mandant_name=".$mandant_name."&wertemenge_kuerzel=".$wertemengen_kuerzel."&element_id=".$element[ 'element_id' ]."';\" ><input type='button' value='&auml;ndern' style='width:60px; height:20px; font-size:.8em;' onclick=\"ajaxFunction( 'su_web.php?cmd=wertemengen_element_aendern&mandant_name=".$mandant_name."&wertemenge_kuerzel=".$wertemengen_kuerzel."&element_id=".$element[ 'element_id' ]."&elemente=".$enthalten_string."', 'wertemenge_anlegen' ); \" ></td>";
		}
		else
		{
			$html = $html."<td>&nbsp;</td>";
		}
		$html = $html."</tr>";
		
	}
}
else
{
	$html = $html."<td>Es sind keine Elemente vorhanden.</td>";
}

$html = $html."</tr></table>";

echo "<h2>Wertemenge ".$wertemenge[ 2 ][ "bezeichnung" ]."</h2>";

echo "<input type='button' value='Zur&uuml;ck' style='width:150px;' onclick=\"document.location.href='su_wertemenge.php'\" /><input type='button' style='width:150px;' value='Element hinzuf&uuml;gen' onclick=\"ajaxFunction( 'su_web.php?cmd=wertemengen_element_hinzufuegen&wertemenge_kuerzel=".$wertemengen_kuerzel."&mandant_name=".$mandant_name."&elemente=".$enthalten_string."', 'wertemenge_anlegen' );\" >";

echo '<div name="wertemenge_anlegen" id="wertemenge_anlegen" style=" border: 0px solid white; margin-top:10px;" ></div>';
echo $html;
?>
	
	
<?php
	
	echo '<div name="wertemenge_ergebnis_3" id="wertemenge_ergebnis_3" style=" margin-top:10px;" >'.$_SESSION[ "meldung_su" ].'</div>';
	$_SESSION[ "meldung_su" ] = "";
	


//echo "<p style='height:200px;' />";
echo "</div>";
echo "<p style='clear:both;' />";
include( 'ssi_footer.php' );

?>