<?php

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


include("config.inc.php");

$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass']) or die("Could not connect to DB");
mysql_select_db($_SESSION['dbName'],$connection) 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);
}

$query1="select grid_color1,grid_color2, company_name from setup";
$result1=mysql_query($query1,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($result1)){
extract($rows);

}

$top = "border-top: 1px solid black";
$bottom = "border-bottom: 1px solid black";
$right = "border-right: 1px solid black";
$left = "border-left: 1px solid black";

echo "<html>";
echo "<head>";
echo "<title>Staff List</title>";
echo "<style>";
echo " 
	.styleh1 {
	font-size: 12px;
    font-weight: bold;
    font-family: arial,sans-serif;
	} ";
echo ".styleh2 {
	font-size: 12px;
    font-weight: bold;
    font-family: arial,sans-serif;
	} ";
echo "</style>";
echo "</head>";

echo "<body>";
echo "<table width='800px' cellspacing=0 cellpadding=0>
<col width='150px'>
<col width='300px'>
<col width='200px'>
<col width='150px'>";
echo "<tr><td rowspan=2><img src='LogoFile.php' ></td></tr>";
echo "<tr><td colspan='4' align='center'><span style='font-size:24px;font-weight:bold;'>$company_name</span></td></tr>";
echo "<tr height='30px'><td colspan='4'></td></tr>";
echo "<tr height='30px'><td colspan='4' align='right'><span style='font-size:12px;'><b>Printed Date:</b> ";
echo date("d/m/Y")."<br>";
echo " <b>Time:</b> ".date("h:i:sa");
echo "</span></td></tr>";
echo "<tr height='20px'><td colspan='4'></td></tr>";
if ($grpby != ''){
echo "<tr height='25px'>
		<td align='left' colspan'2'><span class='styleh1'>Group By: ";
if ($grpby == 1) echo " Project ";		
		"</span></td>
	</tr>";
echo "<tr height='20px'><td colspan='2'></td></tr>";	
}

echo "<tr bgcolor='#d3d3d3' height='25px'>
		<td align='center' style='$top;$bottom;$right;$left;'><span class='styleh1'>Staff Code</span></td>
		<td align='center' style='$top;$bottom;$right;'><span class='styleh1'>Staff Name</span></td>
		<td align='center' style='$top;$bottom;$right;'><span class='styleh1'>Allowance</span></td>
		<td align='center' style='$top;$bottom;$right;'><span class='styleh1'>Total Children</span></td>
	</tr>";

$query = "select Staff_code, Staff_firstName, Staff_lastName,Staff_defaulAll,Staff_totalChildren, staff.project_code, project_name from staff
		left join project on project.project_code = staff.project_code ";

if ($grpby == 1) $query .= " order by staff.project_code, staff_code ";		
else $query .= " order by staff_code ";

$temprjt = '';
$i = 0;
$res = mysql_query($query, $connection);
while ($rw = mysql_fetch_array($res)){
	
	if($i%2==0){
		$color = "style='background-color:#ABD4F1'";
	}else{
		$color = "style='background-color:#EFF1F3'";
	}
	
	if (( $i == 0 || $temprjt != $rw[3]) && $grpby == 1){
		if ($i != 0) echo "<tr height='15px'><td colspan='2' align='center'><hr></td></tr>";
		echo "<tr height='20px'><td colspan='2' align='left' style='padding-left: 40px;'><span class='styleh1'> Project: $rw[3] - $rw[4]</span></td></tr>";
	}
	echo "<tr $color >
			<td align='left' ><span class='styleh2'>$rw[0]</span></td>
			<td align='left' ><span class='styleh2'>$rw[1] $rw[2]</span></td>
			<td align='center' ><span class='styleh2'>".number_format($rw[3], $DecimalBase)."</span></td>
			<td align='center' ><span class='styleh2'>".number_format($rw[4], $DecimalBase)."</span></td>
		</tr>";
	$i++;
	$temprjt = $rw[3];
}
echo "</table>";

print <<< HERE

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

echo "</body>";	
echo "</html>"


?>