<?php
include_once("../class/class.MySQL.php");
include_once("../class/userdefinedfunctions.php");
$db	=new MySQL();
$userfunction	=new userdefinefunctions();
//----------------------------------------retrieving get values--------------------//
$limit=$page_emp;
$page=1; $employees='';
$month=date("m");
$year=date("Y");
if(isset($_GET['page']))
$page=$_GET['page'];
else
$page=1;
if($page) 
		$start = ($page - 1) * $limit;  //first item to display on this page
	else
		$start = 0;			
if(isset($_GET['month']) && ($_GET['month']!='undefined' || $_GET['month']!=''))
{
$month=$_GET['month'];
}
else
{
$month=date("m");
}
if(isset($_GET['year'])  && ($_GET['year']!='undefined'  || $_GET['year']!='' ))
{
$year=$_GET['year'];
}
else
{
$year=date("Y");
}
if(isset($_GET['employees']))
$employees=$_GET['employees'];
//---------------------------------------------------------------------------------------------//
$start=0;
$view="";
if($month=='null')$month=date("m");if($year=='null')$year=date("Y");
$check=$year.'-'.$month;
$sql=" select distinct(a.e_id) as e_id, b.e_fname,b.e_mname,b.e_lname from time as a,employee as b where a.e_id=b.e_id and    DATE_FORMAT(a.e_date,'%m-%Y') = '".$month."-".$year."'";// limit ".$start.",".$limit;
$employees=$db->fetchQuery($sql);
$nummonth=cal_days_in_month(CAL_GREGORIAN,$month,$year);

 $view='<div class="employee-col-01">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td align="center" valign="middle">Date</td>
  </tr>
 ';
  for($s=1;$s<=$nummonth;$s++)
  {
  $view.='<tr>
    <td align="center" valign="middle">'.$s.'</td>
  </tr>';
 }
 
$view.='
  <tr>
    <td align="center" valign="middle" class="employee-row-04">Total</td>
  </tr>
</table>

</div> ';
 $view.=
'<div class="employee-col-02-container"><div class="employee-col-02">
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
     ';
	$arr=array();
	
$i=0;
if($employees)
{
$view.='<tr>';
foreach($employees as $employees)
{
 $view.=
' <td align="center" valign="middle" class="employee-row-01">'.$employees['e_fname'].'</td> ';
$employee=$employees['e_id'];
//$eachdate=$employees['e_date'];
$arr[$i]['e_id']=$employee;
//$arr[$i]['e_date']=$eachdate;
$i++;
}
$view.=' </tr>';
for($s=1;$s<=$nummonth;$s++)
  {
$view.='<tr>';
//---------------------------------------for date 1 of the selected month------------//


  foreach($arr as $arr1)
		{
		
		//echo "<pre>";
		//print_r($datewise);
		
			$empid=$arr1['e_id'];
			$datewise=$check.'-'.$s;
			$totalhours=$userfunction->calldisplay($empid,$datewise,$db);
			$view.=' <td align="center" valign="middle">'.$totalhours.'</td> ';
			$i++;
		}
		
		
            $view.=' </tr>';
			}
			$view.='<tr>';
 //----------------------------------end of date2of selected month----------------//
 
foreach($arr as $tot)
		{
		$empid=$tot['e_id'];
		
		$totqueryval="SELECT * FROM TIME WHERE e_id =".$empid." AND DATE_FORMAT(e_date,'%m-%Y') = '".$month."-".$year."' AND is_late_status ='0'";
		//echo "<br/>";
		$sqlcount=$db->fetchQuery($totqueryval);
		$totcnt = count($sqlcount);
				
		$view.='<td align="center" valign="middle" class="employee-row-03">'.$totcnt.'</td> ';
		}
		$view.=' </tr>';
		}
 $view.='  </table>
</div>
</div>
<div class="clear-float"></div>';

echo $view;
