<?
ob_start();
session_start();
if(isset($_SESSION['ses_name']))
{
$user=$_SESSION['ses_name'];
}else{
header("location:index.php");
}
$tyrenum_veh='';$client_main='';
$cclient_name='';$rproduct_client_code='';
include("include/config.php");
require_once "include/Database_functions.php";
$sqlObj=new sqlclass();

$rproduct_name='';$rproduct_category='';
	

$tablename='cf_time_approval';
            
		 $pdate=date("Y-m-d");
						
			if(isset($_POST['recdate'])){
			$recdate=date(('Y-m-d'),strtotime($_POST['recdate']));
			}
			
			
			
			if(isset($_POST['timepicker_in'])){
			$timerin=addslashes($_POST['timepicker_in']);
			}
			
			if(isset($_POST['timepicker_out'])){
			$timerout=addslashes($_POST['timepicker_out']);
			}
			
			/*$timerin = $_POST['timepicker_in'];
			$timerout = $_POST['timepicker_out'];*/
			
			
			
			if(isset($_POST['save'])){	
			
			if(isset($_POST['emp_driver'])){
			$emp_driver=addslashes($_POST['emp_driver']);
			}
			
			if($emp_driver == 'driver')
			{
				$emp_type = '1';
				$empid=addslashes($_POST['driver_id']);
			}else
			{
				$emp_type = '0';
				$empid=addslashes($_POST['empid']);
			}
			
			$rbranchid='';
			//mysql_query("DELETE FROM cf_time_approval where e_id = '$empid' and e_date ='$recdate'");
			
			$time1 = strtotime($timerin);
			$time2 = strtotime($timerout);
			
			$diff = $time2 - $time1;
			
			$totalWorkTime = date('H:i:s',strtotime("-6 hours 30 minutes",$diff));
	
			$LogTimeIn =  date("H:i",strtotime($timerin));  
			$dt_frtIn =  date('A', strtotime($timerin));
			
			$LogTimeOut =  date("H:i",strtotime($timerout));  
			$dt_frtOut =  date('A', strtotime($timerout));
			
			
			if(!empty($_REQUEST['timehidden_id']))
			{
				$rbranchid = $_REQUEST['timehidden_id'];
			}		
			$sqlObj->tablename=$tablename;
			
			$sqlObj->fieldname='(e_date,e_id,emp_type,e_in,e_out,e_work,time_in,time_inloc,time_out,time_outloc,total_worked_hours)';
			$sqlObj->fieldvalue='"'.$recdate.'","'.$empid.'","'.$emp_type.'","'.$timerin.'","'.$timerout.'","'.$totalWorkTime.'","'.$LogTimeIn.'","'.$dt_frtIn.'","'.$LogTimeOut.'","'.$dt_frtOut.'","'.$totalWorkTime.'"';
			if($rbranchid==""){
			$qsy= "insert into ".$tablename.$sqlObj->fieldname." values(".$sqlObj->fieldvalue.")";
			$CreateClient 	= mysql_query($qsy);
			$lastid = mysql_insert_id();
			}else{
			$updata="e_id='".$empid."',e_in='".$timerin."',emp_type='".$emp_type."',e_out='".$timerout."',e_work='".$totalWorkTime."',time_in='".$LogTimeIn."',time_inloc='".$dt_frtIn."',time_out='".$LogTimeOut."',time_outloc='".$dt_frtOut."',total_worked_hours='".$totalWorkTime."'";
			$qsy= "update ".$tablename." set ".$updata." where id='".$rbranchid."'";
			$CreateClient 	= mysql_query($qsy);
			$lastid = $rbranchid;
						
			}
			
			header("location:timesheet_employee-list.php?msg=You Have Successfully Saved");
			
		}

$branchname='';
$brchaddress='';
$brchphno='';			
if(isset($_REQUEST['timehidden_id'])){
	$time_ids=mysql_escape_string($_REQUEST['timehidden_id']);
	$rqry="SELECT *  FROM cf_branch where branch_id='".$brid."'";
	
	$sqry=mysql_query($rqry);
	if($sqry && mysql_num_rows($sqry)>0)
	{
		while($sobj=mysql_fetch_object($sqry))
		{
			$branchname=$sobj->branch_name;
			$brchaddress=$sobj->brch_address;
			$brchphno=$sobj->brch_phno;
			
		}
		}
	}		
			
		
					

?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>OIL FILL</title>
<link href="css/styles.css" rel="stylesheet"  />
<link type="text/css" href="css_date/ui-lightness/jquery-ui-1.7.2.custom.css" rel="stylesheet" />
<link rel="stylesheet" type="text/css" href="assets/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="dist/bootstrap-clockpicker.min.css">
<link rel="stylesheet" type="text/css" href="assets/css/github.min.css">

<script type="text/javascript">
<!--
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->


</script>

<script type='text/javascript'>	
function validationprod()
{

	if(document.prodfrmname.clientname.value=='')
	{
		alert("Enter Client Name");
		document.prodfrmname.clientname.focus();
		return false;
	}
	if(document.prodfrmname.productname.value=='')
	{
		alert("Enter Product Name");
		document.prodfrmname.productname.focus();
		return false;
	}
}
//--client code dropdown

</script>

<script type="text/javascript">

	function get_time(){

		var val = document.getElementById("recdate").value;
		var e = document.getElementById("empid");
		var strUser = e.options[e.selectedIndex].value;
		$.get("timer_ajax.php?dts="+val+"&empid="+strUser,function(data){
			$('.clockpicker input').val(data);
		});
	get_timeout();
	}

	function get_timeout(){
	
		var val = document.getElementById("recdate").value;
		var e = document.getElementById("empid");
		var strUser = e.options[e.selectedIndex].value;
		$.get("timer_ajax_out.php?dts="+val+"&empid="+strUser,function(data){
			$('.clockpickerout input').val(data);
		});
	
	}
	//function get_time(val){
		
		
		//alert(strUser);
	//}
	
	
</script>
<style>
.lableentrytext{
font-size: 12px;
color: #505050;
clear: both;
margin-bottom: 5px;
text-transform: capitalize;
}
.addimgs{
font-size: 12px;
color: #505050;
clear: both;
margin-bottom: 5px;
text-transform: capitalize;
cursor:hand;
cursor:pointer;
}
.addimgs a:hover{
color: #000;
}
.rimg{
font-size: 12px;
color: #505050;
clear: both;
margin-bottom: 5px;
text-transform: capitalize;
cursor:hand;
cursor:pointer;
}
.rimg a:hover{
color: #000;
}


</style>
</head>

<body>
<div class="wrapper">
  <div>
<?php 
	include("header.php");
?>
 
</div>
 
 
 <div class="tabbedArea">
  
  <div class="tabBody">
   <h1>Add Timesheet</h1>
   <form name="prodfrmname" method="post" action="">
   <?php 
   		$edate = '';
		$drv_id = '';
		$emp_id = '';
		$timein = '';
		$timeout = '';
		$emptype = '';
		
   		if(!empty($_REQUEST['timeid']))
		{
			$timeid = $_REQUEST['timeid'];
			//echo "select * from cf_time_approval where id = '$timeid'";
			$sql_time = mysql_query("select * from cf_time_approval where id = '$timeid'");
			$row = mysql_fetch_array($sql_time);
			
			$edate = date(('d-m-Y'),strtotime($row['e_date']));
			
			$timein = date("H:i",strtotime($row['e_in']));
			$timeout = date("H:i",strtotime($row['e_out']));
			$emptype = $row['emp_type'];
			if($emptype==1){
				$drv_id=$row['e_id'];
				$emp_id = "";
			}else{
				$emp_id = $row['e_id'];
				$drv_id="";
			}
		}
   ?>
   
    <div class="addEmp" style="margin-bottom:0px; border-bottom:0px solid;width:1000px;">
        <table width="70%" border="0" cellspacing="0" cellpadding="10">
          <tr>
            <td valign="top">
      <div class="form1">
        <p class="input1">Date<span style="color:#FF3300">*</span></p><input type="text" name="recdate" id="recdate" class="input1 input3" onChange="get_time()" value="<?=$edate?>" >
     </div>
     
      <div class="form1">
      <br/><br/>	
       <input type="radio" name="emp_driver" value="driver" checked onChange="change_dropdown('driver')">
			 Driver
				<input type="radio" name="emp_driver" value="employee" <?php if($emptype == '0'){?> checked <?php }?>  onChange="change_dropdown('employee')">
				Employee
			
     </div>
     
     <div class="form1">
     <br/>
    
	<?php
		$displaystyle=''; 
	 	if($emptype == ''){
	  		$displaystyle = 'style="display:none ;"';
	   }
	   else if($emptype == '0')
	   {
	   		$displaystyle = 'style="display: block;"';
	   }
	   
	   ?>	  
	
	  <div id="emplyeediv" style="display:none ;"> 
	  
        <p class="input1">Employee Name<span style="color:#FF3300">*</span></p>
        
        <?php $sqlemp = mysql_query("select * from cf_employee where user_type != 'Superadmin' and status = 1 order by e_fname asc");  ?>
                               <select name="empid" id="empid" class="input1 input3" onChange="get_time()" >  
                               <option value="">-Select-</option>
                               <?php while($rw = mysql_fetch_array($sqlemp)){ ?>                            
                               <option value="<?=$rw['e_id']?>" <?php if($emp_id == $rw['e_id']){?> selected <?php } ?>><?=$rw['e_fname']?></option>
                               <?php } ?>
                               </select>
							   
						 
                               </div>
                             
       <div id="driverdiv" >
	   <?php 
	 	//if($emptype == '1'){
	   ?>
        <p class="input1">Driver Name<span style="color:#FF3300">*</span></p>
        
        <?php $sqlemp = mysql_query("select * from cf_driver order by drivername asc ");  ?>
                               <select name="driver_id" id="driver_id" class="input1 input3" onChange="get_time()" >  
                               <option value="">-Select-</option>
                               <?php while($rw = mysql_fetch_array($sqlemp)){ ?>                            
                               <option value="<?=$rw['driver_id']?>" <?php if($drv_id == $rw['driver_id']){?> selected <?php } ?>><?=$rw['drivername']?></option>
                               <?php } ?>
                               </select>
	  <?php //} ?>						   
                               </div>
     </div>
        </td>
            <td valign="top">
           <div>     
      			<p class="input1">Time In<span style="color:#FF3300">*</span></p>
                <div class="picker-cell">      
                  <div class="form-group" style="float:left;">
                    <div class="input-group clockpicker" data-placement="top" data-align="left" data-donetext="Done" id="">
                    <input type="text" name="timepicker_in" class="form-control" value="<?=$timein?>">
                    <span class="input-group-addon">
                    <span class="glyphicon glyphicon-time"></span>
                    </span>		
                    </div>
                    </div>                       
     			<div class="clear-float"></div>
     		</div>
     	   </div>
           
      <div class="picker-cell">      
       <p class="input1">Time Out<span style="color:#FF3300">*</span></p>
        <div class="form-group" style="float:left;">
		<div class="input-group clockpickerout" data-placement="top" data-align="left" data-donetext="Done" id="">
		<input type="text" name="timepicker_out" class="form-control" value="<?=$timeout?>">
		<span class="input-group-addon">
		<span class="glyphicon glyphicon-time"></span>
        </span>		
        </div>
        </div>                       
     <div class="clear-float"></div>
     
      </div>       
            
            </td>
          </tr>
        </table>
	
	<table width="70%" border="0" cellspacing="0" cellpadding="10">
       <tr>
         <td colspan="2"><div class="searchField1">
        <?php
	 	if(isset($_REQUEST['timeid'])){
		$rbrchid = $_REQUEST['timeid'];
	  ?><input name="timehidden_id" type="hidden" value="<?=$rbrchid?>">  
	 
      <input name="save" type="submit" class="input1" value="Edit" onClick="return validationprod();"/>
      <?php }else { ?>   
     <input name="save" type="submit" class="input1" value="Save" onClick="return validationprod();"/>
	  
     <?php } ?>

         <input type="button" class="input1" value="Cancel" >
        </div>
        </td>
          </tr>
        </table>
       

<div class="mand"><p>Fields marked <span style="color:#FF3300">*</span> are Mandatory</p></div>
</div>
   </form>
   </div>
 </div>
 <div class="footer"><p>Powered by <a href="http://www.aadhocc.co.uk/" target="_blank">Aadhocc</a></p></div>
 
</div>
<div class="quicLInksCover">
  <?php 
	include("leftlink.php");
?>

</div>
</body>
<script type="text/javascript" src="assets/js/jquery.min.js"></script>
<script type="text/javascript" src="assets/js/bootstrap.min.js"></script>
<script type="text/javascript" src="dist/bootstrap-clockpicker.min.js"></script>
<script type="text/javascript">
/*if($('#driver_id').val()>0){
	alert(1);
}else*/ if($('#empid').val()>0){
	 document.getElementById('driverdiv').style.display = 'none';
	 document.getElementById('emplyeediv').style.display = 'block';
}

$('.clockpickerout').clockpicker()
	.find('input').change(function(){
		console.log(this.value);
	});

$('.clockpicker').clockpicker()
	.find('input').change(function(){
		console.log(this.value);
	});
var input = $('#single-input').clockpicker({
	placement: 'bottom',
	align: 'left',
	autoclose: true,
	'default': 'now'
});

// Manually toggle to the minutes view
$('#check-minutes').click(function(e){
	// Have to stop propagation here
	e.stopPropagation();
	input.clockpicker('show')
			.clockpicker('toggleView', 'minutes');
});
if (/mobile/i.test(navigator.userAgent)) {
	$('input').prop('readOnly', true);
}

function change_dropdown(val){
	
   if (val == "driver") {
    document.getElementById('emplyeediv').style.display = 'none';
            document.getElementById('driverdiv').style.display = 'block';
          
        } 
        else if (val == "employee") {
		  document.getElementById('emplyeediv').style.display = 'block';
			 document.getElementById('driverdiv').style.display = 'none';
        }   
		
		
}
</script>
<script type="text/javascript" src="assets/js/highlight.min.js"></script>
<script type="text/javascript">
hljs.configure({tabReplace: '    '});
hljs.initHighlightingOnLoad();
</script>


<script type="text/javascript" src="scripts_date/jquery.js"></script>
<script type="text/javascript" src="scripts_date/jquery-calendar-1.7.2.js"></script>
<script type="text/javascript" src="js/sliding.form.js"></script>
<script type="text/javascript" >
$('#recdate').live('click',function(){
		 $(this).datepicker({dateFormat:"dd-mm-yy"}).focus();	
	});
</script>

</html>


		






