<?php
@session_start();

include( "f_admin.php" );
include( "f_wfl.php" );

if ( ( $_SESSION[ "benutzer_anmeldename" ] == "superuser" ) and ( $_SESSION[ "mandant_name" ] == "Standard" ) )
{
	header( "Location: su_uebersicht.php" );
	exit;
}

//$benutzer_anmeldename = $_SESSION[ "benutzer_anmeldename" ];

if ( strlen( $_SESSION[ "benutzer_anmeldename" ] ) > 0 )
{
	$anzahl_recherche_tabs = liefere_konfig( $_SESSION[ "mandant_name" ], "anzahl_recherche_tabs" );
	
	
	
	
	////////////////////////////////////////
	// Javascript-Dateien
	$_SESSION[ "javascript_dateien" ] = "jquery.dataTables.min.js|globalize.js|globalize.culture.de-DE.js|jquery.fancybox.pack.js?v=2.1.5|jstree.min.js";
	////////////////////////////////////////
	
	////////////////////////////////////////
	// Javascript-Startup
	$_SESSION[ "javascript_startup" ] = "";
	////////////////////////////////////////
	
	////////////////////////////////////////
	// CSS-Dateien
	$_SESSION[ "css_dateien" ] = "jquery.fancybox.css?v=2.1.5|style.jstree.css|jquery.dataTables_themeroller.css|jquery.dataTables.min.css";
	////////////////////////////////////////
	
	
	
	
	$_SESSION[ "title" ] = "Recherche von Dokumenten und Akten";
	include( 'ssi_header.php' );
	$_SESSION[ "title" ] = "";
	
	////////////////////////////////////////
	// Javascript-Dateien
	$_SESSION[ "javascript_dateien" ] = "";
	////////////////////////////////////////
	
	////////////////////////////////////////
	// Javascript-Startup
	$_SESSION[ "javascript_startup" ] = "";
	////////////////////////////////////////
	
	////////////////////////////////////////
	// CSS-Dateien
	$_SESSION[ "css_dateien" ] = "";
	////////////////////////////////////////
	
	
	
	$ergebnis	= welche_dokaktenarten_darf_benutzer_lesen( $mandant_name, $benutzer_anmeldename );
	//$options	= "<option value='' /><option value='SCHABLONE' >****Übergreifend</option>";
	$options	= "<option value='' />";
	$js_liste	= "";
	
	if ( $ergebnis[ 0 ] > 0 )
	{
		foreach( $ergebnis[ 1 ] as $dokart_kuerzel )
		{
			$erg		= liefere_dokartinformationen( $_SESSION[ "mandant_name" ], $dokart_kuerzel );
			//$options	= $options."<option value='".$dokart_kuerzel."'>".$erg[ 2 ][ "dokart_name" ]."</option>";
			if ( $erg[ 2 ][ "dokart_typ" ] == "A" )
			{
				if ( $erg[ 2 ][ "dokart_kuerzel" ] == "SCHABLONE" )
				{
					$options	= $options."<option value='SCHABLONE' >".$erg[ 2 ][ "dokart_name" ]."</option>";
				}
				else
				{
					$akten[ $dokart_kuerzel ] = $erg[ 2 ][ "dokart_name" ];
				}
			}
			else
			{
				$dokarten[ $dokart_kuerzel ] = $erg[ 2 ][ "dokart_name" ];
			}
			$js_liste	= $js_liste."'".$dokart_kuerzel."', '".$erg[ 2 ][ "dokart_name" ]."', ";
		}
		
		if ( count( $akten ) > 0 )
		{
			$akten_opts = "<optgroup label='Aktenarten'>";
			
			asort( $akten );
			
			foreach( $akten as $dokart_kurz => $dokart_nam )
			{
				$akten_opts = $akten_opts."<option value='".$dokart_kurz."'>".$dokart_nam."</option>";;
			}
			$akten_opts = $akten_opts."</optgroup>";
		}
		
		if ( count( $dokarten ) > 0 )
		{
			$dokarten_opts = "<optgroup label='Dokumentarten'>";
			
			asort( $dokarten );
			
			foreach( $dokarten as $dokart_kurz => $dokart_nam )
			{
				$dokarten_opts = $dokarten_opts."<option value='".$dokart_kurz."'>".$dokart_nam."</option>";;
			}
			$dokarten_opts = $dokarten_opts."</optgroup>";
		}
		
	}
	else
	{
		header( "Location: us_uebersicht.php" );
	}
	
	$options = $options.$akten_opts.$dokarten_opts;
	
	$js_arr = "var dokuarten = [ ".substr( $js_liste, 0, strlen( $js_liste ) - 2 )." ];";
	
	
	$us_rech_imp_button = liefere_benutzerspezifische_einstellung( $_SESSION[ "mandant_name" ], $_SESSION[ "benutzer_anmeldename" ], "us_rech_imp_button" );
	
	
	
	if ( $us_rech_imp_button == "ja" )
	{
		echo "<div style='margin-left:200px; padding-bottom:30px;  min-height:550px;'  >";
		include( "us_menu.php" );
	}
	else
	{
		echo "<div style='margin-left:20px; padding-bottom:30px;  min-height:550px;'  >";
	}
	
	?>
	<script>
	
	function loesche_leeroption( i )
	{
	  var elSel = document.getElementById( 'select_'+i );
	  if (elSel.options[ 0 ].value == "" )
	  {
		elSel.remove( 0 );
	  }
	}
	
	function aendere_bezeichnung( id, neu )
	{
		<?php echo $js_arr."\n"; ?>
		var k = $("#"+id).html();
		
		var idx = dokuarten.indexOf( neu );
		
		$("#"+id).html( dokuarten[ idx + 1 ] );
		
	}
	</script>
	<div style='margin-bottom:10px; margin-top:5px; '>
	
	<div id="tabs">
	<ul>
	<?php
	for ( $j = 1; $j <= $anzahl_recherche_tabs; $j++ )
	{
		echo '<li><a id="li_'.$j.'" href="#rech_'.$j.'">Recherche '.$j.'</a></li>';
	}
	?>
	</ul>
	
	<script>
		$(function() {
		$( "#tabs" ).tabs();
		});
	</script>
	
	
	<?php
	
	
	
	
	//echo "<a name='top' />";
	//<!--input type="button" value="Trefferliste ausblenden" style="margin-right:10px;" />
	//<input type="button" value="Trefferliste einblenden" style="margin-right:10px;" /--></div>
	
	
	
	
	//$( \'#auswahl\' ).hide();
	//<div id="button_div" ><input type="button" id="but_maske_ausbl_'.$i.'" value="Maske ausblenden" style="margin-right:10px;" onclick=" $( \'#maske_'.$i.'\' ).hide(); $( \'#but_maske_ausbl_'.$i.'\' ).hide(); $( \'#but_maske_einbl_'.$i.'\' ).show(); " />
	
	
	// Recherchemaske </div>
	
	// Select-Box zur Auswahl der Dokument-/Aktenart in einem Div-Element, dass dann zur Anzeige der Maske ausgeblendet werden soll.
	//, document.getElementById (\'rech_1\').style.height = \'700px\'
		
	
	for ( $i = 1; $i <= $anzahl_recherche_tabs; $i++ )
	{
		$select = '<select name="alpha_03"  id="select_'.$i.'" size="1" style="height:100%; width:225px;" onchange="$( \'#trefferliste_'.$i.'\' ).html( \'\' ); $( \'#maske_'.$i.'\' ).load( \'su_web.php?cmd=liefere_recherchemaske&notiz_typ='.$i.'&mandant_name='.urlencode( $_SESSION[ "mandant_name" ] ).'&element_typ=\'+this.value,  function() { $( \'.date-pickr\' ).datepicker({ showAnim: \'clip\', buttonImageOnly: true,  showOn: \'both\', changeMonth: true, changeYear: true, yearRange: \'1990:2029\', buttonImage: \'img/kalender.png\', showWeek: true }) } ),  $( \'#maske_'.$i.'\' ).show(), aendere_bezeichnung( \'li_'.$i.'\', this.value ), loesche_leeroption( \''.$i.'\' ); " >';
		
		
		$button = '<input type="button" id="but_maske_einbl_'.$i.'" value="Maske einblenden" style="margin-right:10px;display:none;" onclick=" $( \'#maske_'.$i.'\' ).show(); $( \'#but_maske_ausbl_'.$i.'\' ).show(); $( \'#but_maske_einbl_'.$i.'\' ).hide();"/><input type="button" id="but_maske_ausbl_'.$i.'" value="Maske ausblenden" style="margin-right:10px; display:none;" onclick=" $( \'#maske_'.$i.'\' ).hide(); $( \'#but_maske_ausbl_'.$i.'\' ).hide(); $( \'#but_maske_einbl_'.$i.'\' ).show(); " />';
		
		$select_komplett = $select.$options."</select>".$button;
		$maskeauswahl		= "<div id='maskeauswahl_".$i."' style='margin-top:12px; margin-bottom:12px;' >".$select_komplett."</div>";
		$maske				= "<div id='maske_".$i."'  style='width:415px;margin-bottom:12px;'></div>";
		$trefferliste		= "<div id='ergebnis".$i."' style='display:relative;' ></div>";
		$dokumentanzeige	= "<div id='dokumentanzeige".$i."' style='display:relative;' ></div>";
		
		//border-width:1px;border-style:solid;border-color:blue;
		
		echo "<div id='rech_".$i."'><div id='ausknipsen_".$i."'>";
		echo $maskeauswahl.$maske.$trefferliste;
		echo "</div>";
		echo $dokumentanzeige."</div>";
	}
	
	
	
	
	
	
	
	
	
	
	
	
	echo '</div>'; // div tabs
	
	echo '</div>'.$_SESSION[ "ERGEBNIS_DOK_LOESCHEN" ];
	$_SESSION[ "ERGEBNIS_DOK_LOESCHEN" ] = "";
	echo '</div>'; // div gesamt
	
	
	echo "<p style='clear:both;' />";
	include( 'ssi_footer.php' );

}
else
{
	header("Location: index.php");
}
?>