<?php
	require_once("../config/connect.php");
	require_once("../config/pageConfig.php");
	require_once("../global_functions.php");
	//require_once("../ajax_funktionen.php");
	
	#$page = $_SERVER['PHP_SELF'];
	#$sec = "2";
	
?>
<html> 
<head> 

    <meta charset="UTF-8"> 
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>sITpos Kundenmonitor</title>
	<script >
		
	
	
	
	</script>
	
	<style type="text/css">
	<?php include '../include/main.css'; ?>
	
	#slideshow {  margin: 2px auto;  position:absolute;  width:38%;  height:80%; padding:2px; box-shadow: 0 0 0px rgba(0,0,0,0.4);  }
	#slideshow > div {  position: absolute;  top: 0px;  left: 5px;  right: 5px;  bottom: 5px;  }
	.div_left { float:left; width:30%; }
	.div_right { float:right; width:60%; }	
	.div_leftNull { position:relative; float:left; width:0%;					}
	.div_rightFull { position:relative; float:left; width:100%;			}
	
	
	
	</style>
</head>
<?php
	
	$run_slideshow=false;
	$cssLeft="";
		
		# KPE Dez 2020 -> Abdrehen von "Werbe"Bilder im Kundenmonitor
		#   !!!!!   der images Folder ist NICHT root/images sondern -> sitpos/display/images

	function show_slideshow()
	{
		global $run_slideshow;
		global $cssLeft;
		global $cssRight;

		$imagedir="images/";
		echo '<div id="slideshow">';
		$files=glob($imagedir.'*');
		
		#writeLog(basename( __FILE__)." ". __LINE__ . "Files: ".$files."_");

		
		if (count($files)>1)
		{
			$run_slideshow=true;
			$cssLeft="div_left";
			$cssRight="div_right";
			
			foreach($files as $filename){
			//echo basename($filename) . "\n";
				echo '<div>';
				echo '<img src="'.$filename.'" style="width:100%; margin-top:2%;">';
				echo '</div>';
			}
		}
		else{
			$cssLeft="div_leftNull";
			$cssRight="div_rightFull";
		}
		
		
		echo '</div>';
		
		if($run_slideshow == true){
			
		}
		else{
			
		}
		
		
	}
	
	$tisch_id=null;
	if (isset($_REQUEST['tisch_id']))
	{
		$tisch_id=$_REQUEST['tisch_id'];
	}
	
	else if (file_exists('tisch_id_anzeigen.txt'))
	{
		if ($tisch_id=file_get_contents('tisch_id_anzeigen.txt'))
		{
			//echo $tisch_id;
		}
	}
	else
	{
		
		$sql = mysql_fetch_array(mysql_query("SELECT * FROM offener_bon ORDER BY update_ts DESC LIMIT 1 "));
		if (!$sql) echo mysql_error();
		if(isset($sql['bon_id']))
		{
			$tisch_id = $sql['bon_id'];
		}
	}
	
	//echo $tisch_id;
	
	echo '<div class="'.$cssLeft.'">';
		show_slideshow();
	echo '</div>';
	echo '<div id="kdMonRight" class="'.$cssRight.'">';
	#echo '<iframe marginwidth="0" marginheight="0" width="100%" height="100%" scrolling="no" frameborder=0 
	#	src="kundenmonitor_rechts.php?tisch_id='.$tisch_id.'">
	#	</iframe>';
	echo '</div>';

?>
<script src="../jquery/jquery-2.1.1.min.js"></script>
<script>

	var curTischId="<?php echo $tisch_id; ?>";

	function reloadCustMonitor(){
		$.ajax({
				type: "POST",
				url: "../ajax_funktionen_kp.php",
				dataType : "json",
				data: {	functionKey:'reloadCustMonitor', curTischId:curTischId 	},
				async: true,
				success:function(ajaxResponse){
					//console.log("ajax Resp -> "+ajaxResponse);
					curTischId = ajaxResponse[0];
					$("#kdMonRight").html(ajaxResponse[1]);
					
				//	var xHeight = $('#artikelContainer').height();
				//	$('#artikelContainer').scrollTop(xHeight);
				var objDiv = document.getElementById("artikelContainer");
				objDiv.scrollTop = objDiv.scrollHeight;

				}
			});	
	}
	

	setInterval(function(){ reloadCustMonitor(); }, 1000);



<?php
	if ($run_slideshow){
			echo '
			$("#slideshow > div:gt(0)").hide();
				setInterval(function() { 
				  $("#slideshow > div:first")
					.fadeOut(1000)
					.next()
					.fadeIn(1000)
					.end()
					.appendTo("#slideshow");
				},  5000);
			';
	}
	

?>
	//var objDiv = document.getElementById("artikelContainer");
	//	objDiv.scrollTop = objDiv.scrollHeight;
		
		
		
		//console.log(" scrollTop: "+objDiv.scrollTop+"\n");
		//console.log(" scrollHeight: "+objDiv.scrollHeight+"\n");
</script>
<?php



?>
</html>
