<?php


include_once( "su_web.php" );


$dokart				= liefere_benutzerspezifische_einstellung( $_SESSION[ "mandant_name" ], $_SESSION[ "benutzer_anmeldename" ], "us_plugin_zufallsdok_dokart" );

$wertemenge = liefere_wertemenge_elemente( $_SESSION[ "mandant_name" ], "dokarten_liste" );

if ( $wertemenge[ 0 ] > 0 )
{
	foreach( $wertemenge[ 2 ] as $element )
	{
		if ( $element[ "alpha_01" ] == $dokart )
		{
			$dokart_kuerzel = $element[ "alpha_02" ];
			break;
		}
	}
}


$liste = variable_recherche( $_SESSION[ "mandant_name" ], $dokart_kuerzel, $_SESSION[ "benutzer_anmeldename" ], array( array( "feld"=>"alpha_01", "operator"=>"LIKE", "wert"=>"*" ) ), array(), 0 );

if ( $liste[ 0 ] > 0 )
{
	//xlog( 3, "liste ".$liste[ 0 ] );
	
	
	
	$doknr = rand( 0, bcsub( $liste[ 0 ], 1, 0 ) );
	
	$element = $liste[ 2 ][ $doknr ];
	
	//xlog( 4, "plugin: ".$element[ "dok_id" ] );
	
}


echo "<center><h2>Zufälliges Dokument</h2>";
echo "<div style='max-width:900px;'>";
//echo _web_liefere_dok_binary( $element[ "dok_id" ], "h" );
$obj = _web_verpacke_dok_in_tags( $element[ "dok_id" ], $element[ "mime_type" ], 7 );
echo $obj;
echo "</div></center>";

?>