<?php



//Report Version For Tiba
session_start();
header("Content-type: text/html; charset=".$_SESSION['encodingmode']);
if($_SESSION['dbName']==""){
header("location:../index.php");
}

print <<< HERE
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<TITLE> Staff Report </TITLE>

<style type="text/css">

table.master th { font-size: 14px; 
                  font-weight: bold;
                  font-family:Times-New-Roman;
                }				 
table.master td { font-size: 14px; 
                  font-family:Times-New-Roman;
                 }
table.detail th { font-size: 13px; 
                  font-weight: bold;
                  font-family:Times-New-Roman;
				  border-top:1px solid black;
				  border-bottom:1px solid black;
				  border-left:1px solid black;
                }				 
				 
table.detail td { font-size: 12px; 
                  font-family:Times-New-Roman;
				  border-left:1px solid black;
                 }			
h1.breakhere { page-break-after: auto;}				 
</style>
</HEAD>
<BODY>
HERE;

include("config.inc.php");

$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass'],true,65536)	or die("Could not connect to DB");
mysql_select_db($_SESSION['dbName'],$connection) or die("Could not find DB");

$connection1 = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass'],true,65536)	or die("Could not connect to DB");
mysql_select_db($config['dbName_log'],$connection1) or die("Could not find DB");

if(	$_SESSION['encodingmode'] == 'utf8' || $_SESSION['encodingmode'] == 'utf-8'){
	mysql_query("SET NAMES 'utf8'"); 
	mysql_query('SET CHARACTER SET utf8'); 
	mysql_set_charset('utf8', $connection);
}

//mysql_set_charset('utf8',$connection);

//Read From Setup Table							
$querysetup= " select DecimalBase, DecimalBase1, DecimalBase2, base1, base2, grid_color1, grid_color2, Setup_vatno, ".
             " Date_Format(Setup_VatStartDate,'%Y%m%d') As Setup_VatStartDate, ifNull(Setup_VatPercentage,0) As Setup_VatPercentage, ".
			 " Company_Name, Company_NameF, Company_Memo, Company_MemoF, Company_Capital, Company_CapitalF ".
			 " from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}





function formatdate($dateval){
	if($dateval != ''){
	$ndate = explode("-", $dateval);
	$dateval = $ndate[2]."-".$ndate[1]."-".$ndate[0];
}
	return $dateval;
}
	


$querysetup ="select base1, base2 from ".$config['dbName_log'].".setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultsetup)){
	extract($rowmodule);
}
$stafffrom = $_POST['stafffrom']; if($stafffrom == '') $stafffrom = $_GET['stafffrom'];	
$staffto = $_POST['staffto']; if($staffto == '') $staffto = $_GET['staffto'];	
$dateto = $_POST['dateto']; if($dateto == '') $dateto = $_GET['dateto'];	
$datefrom = $_POST['datefrom']; if($datefrom == '') $datefrom = $_GET['datefrom'];	
$cartype = $_POST['cartype']; if($dateto == '') $cartype = $_GET['cartype'];
$expireoption = $_POST['expireoption']; if($expireoption == '') $expireoption = $_GET['expireoption'];	
$dateto=formatdate($dateto);
$datefrom=formatdate($datefrom);


if ($expireoption=='1'){
	
	$title="Passport";
	$staff_listquery="select staff_code,Staff_firstName,Staff_lastName,Date_Format(Staff_PassExpDate,'%d/%m/%Y') from staff 
	where staff_code between '$stafffrom' and '$staffto' 
	and Staff_PassExpDate between '$datefrom' and '$dateto' ";
	}
else if ($expireoption=='2'){
	$title="Inssurance";
	$staff_listquery="select staff_code,Staff_firstName,Staff_lastName,Date_Format(Staff_InsExpDate,'%d/%m/%Y') from staff 
	where staff_code between '$stafffrom' and '$staffto' 
	and Staff_InsExpDate between '$datefrom' and '$dateto' ";
	}
	else if ($expireoption=='3'){
		$title="Re-Visa";
	$staff_listquery="select staff_code,Staff_firstName,Staff_lastName,Date_Format(Staff_visaExpDate,'%d/%m/%Y') from staff 
	where staff_code between '$stafffrom' and '$staffto' 
	and Staff_visaExpDate between '$datefrom' and '$dateto' ";
	}
	else if ($expireoption==' 4'){
		$title="Resident Permit";
	$staff_listquery="select staff_code,Staff_firstName,Staff_lastName,Date_Format(Staff_rpexpdate,'%d/%m/%Y') from staff 
	where staff_code between '$stafffrom' and '$staffto' 
	and Staff_rpexpdate between '$datefrom' and '$dateto' ";
	}
	else if ($expireoption=='5'){
		$title="Quota";
	$staff_listquery="select staff_code,Staff_firstName,Staff_lastName,Date_Format(Staff_quotaExpired,'%d/%m/%Y') from staff 
	where staff_code between '$stafffrom' and '$staffto' 
	and Staff_quotaExpired between '$datefrom' and '$dateto' ";
	}
	//echo $staff_listquery;
	
$style="style='border:1px solid black; text-align:right;'";
echo"<table width='750px' border='0'  cellspacing=0 cellpadding=0 class='master' style='table-layout:fixed;' >
		<col width='150px'>
        <col width='300px'>
        <col width='200px'>
		<col width='100px'>";
		//T-header
echo"	<tr>
			<td align=' left' valign='top' style='font-size:14px; font-style:italic; font-weight:bold;' colspan=3>
			
			<tr>
			<td rowspan=2><img src='LogoFile.php' ></td>
			<td style='vertical-align: top;'><br><span style='font-size: 20px; font-weight: bold'>$Company_Name</span><br>
			<span style='font-size: 11px;'><pre>".str_replace( '\n', '<br>', $Company_Memo)."</pre></span></td>
			</tr>
			
			</table>
			<td>
			
		<tr>";
		
		//2nd row
echo"<table width='750px' border='0'  cellspacing=0 cellpadding=0 class='master' style='table-layout:fixed;' >
		<col width='500px'>
        <col width='125px'>
		<col width='125px'>";	

		echo "	<tr>";
		echo "<td style='font-size:20px; font-weight:bold;' align='right'> List of Expired $title</td>";
		echo "<td align='right'> Printed Date: </td>";
		echo "<td align='center'> ".date("d/m/Y")."</td>";
		echo "	</tr>";
		
		echo "	<tr>";
		echo "<td style='font-size:20px; font-weight:bold;'> </td>";
		echo "<td align='right'> Time:</td>";
		echo "<td align='center'> ".date("h:i:sa")."</td>";
       	echo "	</tr>";
		
		
		//<td align='center'  valign='top' style='font-size:20px; font-weight:bold;'>List of Expired $title<td>
		//	<td align='center'  valign='top' style='font-size:20px; font-weight:bold;'>List of Expired $title<td> </tr> ";
			
			
			
						
			
		//table header
		echo "</table>";
echo "	</tr>

		<tr>
			<td>
			
					
			
				<table style=' border: 1px solid black;' width='750px'>
					<col width='150px'>
        <col width='300px'>
        <col width='250px'>
					<tr style='background-color:#d3d3d3'>
						
						<td  >staff code</td>
						<td  >Staff Name</td>
						<td  >Expiry Date</td>
						
					</tr>";

					
	//echo $staff_listquery;
				
					$getstaff=mysql_query($staff_listquery,$connection);
					
					while($resultgetstaff=mysql_fetch_array($getstaff)){
	                  if($i%2==0){
	                 	$color = "style='background-color:#ABD4F1'";
	                    }else{
	                    	$color = "style='background-color:#EFF1F3'";
	                       }
						
						echo "<tr $color>	
							
							
						</tr>
						
						<tr $color'>
							
							<td  >$resultgetstaff[0]</td>
							<td >$resultgetstaff[1]  $resultgetstaff[2]</td>
							"
							;
							echo "	
							<td >$resultgetstaff[3]</td>
						</tr>
						
						<tr style='background-color:white; border: 1px solid black;'>
							
						</tr><h1 CLASS='breakhere'>";
							$i++;
					}
					
echo "			</table>
			</td>
		</tr>
	</table>";
print <<< HERE

<script language=javascript>
if (typeof(window.print) != 'undefined')
{
    window.print();
}
</script>
</BODY>
</HTML>
HERE;
	