<? 
include("si_confi.php");
$seleect_employee=mysql_query("select * from `employee_mng`");
while($fetch_employee=mysql_fetch_array($seleect_employee))
{ 
	  $emid=$fetch_employee['emp_id']; 
	  $emname=$fetch_employee['name']; 
		
     $selmm=mysql_query("select * from  `leave` where `empid`='$emid' and `req`='1' ");
	 while($fetcdata=mysql_fetch_array($selmm))
	 {
     $leavefor=$fetcdata['leavefor'];
	 $fdate=$fetcdata['fdate'];
	  $todate=$fetcdata['tdate']; 
	 $id=$fetcdata['id'];
	 
     $datt=date("Y-m-d");
	 
$time1 = strtotime($fdate);
$time2 = strtotime($todate);
$diff=floor( ($time2-$time1) /(60*60*24))+1;

for($ii=0;$ii<$diff;$ii++)
{
	/*strtotime($date)*/
	
	if($ii>=1)
	{
		  $datecc = strtotime("+1 day", strtotime($fdate123));
		  $fdate123 =  date("Y-m-d", $datecc);
	}
	else
	{
	  $fdate123= $fdate;
	}
	  
      $expldat=explode('-',$fdate123);
	  
	  $yr=$expldat[0];
	  $mn=$expldat[1];
	  $dt=$expldat[2];
	  
	  $cdt=$dt[0];
	  if($cdt==0)
	  {
		  $cdatt=$dt[1];
	  }
	  else
	  {
		 $cdatt=$expldat[2]; 
	  }
	  
    $mnth=date("F",mktime(0, 0, 0, $mn, 10));
	$year=$yr;
	
    $weekday = date('l', strtotime($fdate123));

    if($weekday!='Sunday')
	{
		
	  $ckkqu=mysql_query("select * from emp_attendance where empid='$emid' and  month='$mnth' and year='$year'  ");
	  $chknum=mysql_num_rows($ckkqu);
	  
	  if($chknum==0)
	  {
	    $insf=mysql_query("insert into emp_attendance(`empid`,`emp_name`,`year`,`month`,`$cdatt`) values('$emid','$emname','$year','$mnth','1')");
	  }
	  else
	  {
	    $insfup=mysql_query("update emp_attendance set `$cdatt`='1' where empid='$emid' and  month='$mnth' and year='$year' ");
	  }
	}
	else
	{
		$mns=$mnus-1;
	}
}

$diff=$diff-$mns;

$upd=mysql_query("update `leave` set `count`='$diff' where `id`='$id'");

	 }
	 
		}


?>