<?php
	require_once("config/connect.php");
	require_once("config/sIT_global_db_functions.php");
	require_once("config/pageConfig.php");
	require_once("global_functions.php");
	check_login('', '', 'ENABLERKEY_ARBEITSZEITEN_SCHREIBEN');
	
?>
<head>
	<title>SITPOS Benutzer</title>
	<?php 	echo META_DATA_ADMIN;  ?>
	<style type="text/css">
		<?php include 'include/main.css'; ?>
		<?php include 'include/menue.css'; ?>
		
	</style>
	<link rel="stylesheet" type="text/css" href="jquery/jquery-ui.css">
	<link rel="stylesheet" href="jquery/jquery.ui.timepicker.css">
	
	<script src="jquery/jquery-2.1.1.min.js"></script>
	<script src="jquery/jquery-ui1.11.4.js"></script>
	<script src="jquery/jquery.ui.timepicker.js"></script>
	<script>
		$(window).keypress(function(e) {
				var key = e.which;												// pressed Key wird inizialisiert
				if(key == 13){	
					var sStr = $("#getKeyCode").html();
					sStr = sStr.replace("out", "");
					$("input[name='PME_data_autologincode']").val(sStr);
					$("#getKeyCode").html("");
				}				
				else {														
				var res = String.fromCharCode(key);					
				var tmpX=$("#getKeyCode").html();											
				var newVal= tmpX+res;										
				$("#getKeyCode").html(newVal);
				
				}			
		});
		
		$( document ).ready(
		
			function() { 
			$("input[name='PME_data_name'], input[name='PME_data_passwort']").focusout(function(){
				$("#getKeyCode").html("");
				console.log("xxxxxxxxxxxxxxxx\n");
				
			})
			
			$("#arbeitszeit_form").submit(function(e) 
			{
				e.preventDefault(); // avoid to execute the actual submit of the form.

				var form = $(this);
				var url = form.attr('action');

				$.ajax({
				   type: "POST",
				   url: url,
				   data: form.serialize(), // serializes the form's elements.
				   success: function(data)
				   {
					   alert(data); // show response from the php script.
				   }
				 });
			});
			
			}
		
			
		);
	
	

	$( function() {
			$( ".timepicker" ).timepicker({
				hourText: 'Stunden',
				minuteText: 'Minuten',
				defaultTime: '10:00',
				amPmText: ['', ''],
				timeSeparator: ':',
				atPosition: 'right top', 
				showPeriod: false,
				showPeriodLabels: false,
				showCloseButton: false,
			});

		});
	</script>
	
</head>
<body>
	<div id="wrapper_admin" class="wrapper_admin">
	
	

<?php
	$con=sIT_mysql_connect(SQL_HOST, SQL_USER, SQL_PW, SQL_DB);
	
	function get_arbeitszeiten_for_user($benutzer_id)
	{
		global $con;
		$datum=date("Y-m-d");
		
		$absenz_name="Arbeit";
		$az_beginn="00:00";
		$az_ende="00:00";
		$az_beginn2="";
		$az_ende2="";
		$Q1=sIT_mysql_run_query($con, "SELECT ID, benutzer_id, datum, absenz_name, az_beginn, az_ende, az_beginn2, az_ende2
										FROM arbeitszeit_schreiben
										WHERE datum='$datum' AND benutzer_id='$benutzer_id'", true);
		while ($row1=sIT_mysql_get_row($Q1))
		{
			$absenz_name=$row1['absenz_name'];
			$az_beginn=$row1['az_beginn'];
			$az_ende=$row1['az_ende'];
			$az_beginn2=$row1['az_beginn2'];
			$az_ende2=$row1['az_ende2'];
		}
		return(array($absenz_name,$az_beginn,$az_ende,$az_beginn2,$az_ende2));
	}
	
	function absenzen_select_ausgeben($id, $default_absenz_name)
	{
		global $con;
		echo "<TD><SELECT name='tag_typ[]'><OPTION>Arbeit</OPTION>";
		$Q1=sIT_mysql_run_query($con, "SELECT absenz_name from arbeitszeit_absenz", true);
		while ($row1=sIT_mysql_get_row($Q1))
		{
			$selected="";
			if ($row1['absenz_name']===$default_absenz_name) $selected=" selected ";
			echo "<OPTION $selected>".$row1['absenz_name']."</OPTION>";
		}
		echo "</SELECT></TD>";
	}
	
	menue_anzeigen();
	
	$Q1=sIT_mysql_run_query($con, "SELECT id,name from benutzer WHERE arbeitszeit_schreiben=1", true);
	
	echo "<FORM action='arbeitszeiten_schreiben_ajax.php' id='arbeitszeit_form'>";
	echo "<TABLE  id='bonjournal' class='auswertungen' border 5 >";
	echo "<TR>	<TH class='ueberschrift width200'>Benutzer</TH><TH class='ueberschrift width200'>Absenz</TH>
				<TH class='ueberschrift'>Beginn</TH><TH class='ueberschrift'>Ende</TH>
				<TH class='ueberschrift'>Beginn</TH><TH class='ueberschrift'>Ende</TH></TR>";
	while ($row1=sIT_mysql_get_row($Q1))
	{
		$id=$row1['id'];
		list($absenz_name, $az_von, $az_bis, $az_von2, $az_bis2)=get_arbeitszeiten_for_user($id);
		echo "<TR>";
		echo "<TD><input type='text' name='benutzer_name[]' value='".$row1['name']."' readonly> 
				<input type='hidden' name='benutzer_id[]' value='".$id."' /></TD>";
		absenzen_select_ausgeben($id, $absenz_name);
		
		echo "<TD><input type='text' name='az_von[]' class='timepicker' value='$az_von' /></TD>";
		echo "<TD><input type='text' name='az_bis[]' class='timepicker' value='$az_bis' /></TD>";
		echo "<TD><input type='text' name='az_von2[]' class='timepicker' value='$az_von2' /></TD>";
		echo "<TD><input type='text' name='az_bis2[]' class='timepicker' value='$az_bis2' /></TD>";
		echo "</TR>";
	}
	echo "</TABLE>";
	echo "<input type='hidden' name='funktion' value='az_speichern'>"; 
	echo "<input type='submit' class='button orange'>"; 
	echo "</FORM>";
?>
</div>  <!-- end of wrapper div -->
</body>
