#!/usr/bin/perl -w
use CGI qw/:all/;
use CGI::Carp qw(fatalsToBrowser);
use DBI;
my $dbh=DBI->connect('dbi:mysql:TECESS:localhost','arabdemog_com','p2a9r7cd');
#my $dbh=DBI->connect('dbi:mysql:tecess:localhost:3306','root','root') or die "Unable to connect: $DBI::errstr\n";
$str1="";
$tot=0;
$temp=0;
$cnt=0;
$me3=0;
$me5=0;
$tmail=0;
$culr="";
$totmail=0;
$tme3=0;
$tme5=0;
$pe=0;
$per=0;
$pe1=0;
$per1=0;
$dcode=0;
##Parameters - Start
$strSQL="SELECT d.deptcode,d.deptdesc,d.Total,d.ME3,d.ME5,count(*) FROM esdept1 as d, ess_entry as e WHERE d.deptcode=e.dept group by d.deptcode,d.deptdesc,d.Total,d.ME3,d.ME5 order by deptcode";
$sthAT=$dbh->prepare($strSQL);
$sthAT->execute;
print <<blk1;
content-type: text/html

<html>
<head>
<meta name=Author content="Ayyappan Pillai Sujith Kumar/Shebin Jacob">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="refresh" content="150" >
<title>Pan Arab Research Center </title> 
<style type="text/css">
Table{
	width=100%;
	border-width: 0px;
	border-spacing: ;
	border-style: inset;
	border-collapse: collapse;
}
.tbl
{
	width=100%;
	border-width: 1px;
	border-spacing: ;
	border-style: inset;
	border-collapse: collapse;
	border-bottom:solid 1px red;
	border-top:solid 1px red;
	border-left:solid 1px red;
	border-right:solid 1px red;
	margin: auto,auto,auto,auto;
	
}
td
{
	padding-left:10px;
	padding-right:10px;
	padding-top:2px;
	padding-bottom:2px;
	font-family:Verdana;
	font-size:12px;
	white-space:nowrap;
}
.tdn
{
	border-width: 1px;
	border-spacing: ;
	border-style: inset;
	border-collapse: collapse;
	border-bottom:solid 1px red;
	border-top:solid 1px red;
	border-left:solid 1px red;
	border-right:solid 1px red;

}
</STYLE>

</head>
blk1

$str1=$str1 . "<tr bgcolor='#CF001C'><td class='tdn' height='30'><b><font color='white'>Code</font><b></td><td class='tdn' height='30'><b><font color='white'>Department</font><b></td></td><td align='center' class='tdn'><b><font color='white'>Total Emails</font><b></td></td><td align='center' class='tdn'><b><font color='white'>ME3</font><b></td></td><td align='center' class='tdn'><b><font color='white'>ME5</font><b></td><td align='center' class='tdn'><b><font color='white'>Achieved</font><b></td><td align='center' class='tdn'><b><font color='white'> % on (ME3)</font><b></td><td align='center' class='tdn'><b><font color='white'> % on (ME5)</font><b></td></tr>";
while (@strVal=$sthAT->fetchrow_array())
{
	$pe=0;
	$dcode=@strVal[0];
	if($dcode==28)
	{
		$dcode=26;
	}
	elsif($dcode==29)
	{
		$dcode=27;
	}
	elsif($dcode==30)
	{
		$dcode=28;
	}
	elsif($dcode==31)
	{
		$dcode=29;
	}
	elsif($dcode==32)
	{
		$dcode=30;
	}
	$temp=@strVal[5];
	$tmail=@strVal[2];
	$me3=@strVal[3];
	$me5=@strVal[4];
	
	$pe1=$temp/$me5*100;
	$pe1=sprintf("%d", $pe1);
	$pe=$temp/$me3*100;
	$pe=sprintf("%d", $pe);

	$totmail=$totmail+$tmail;
	$tme3=$tme3+$me3;
	$tme5=$tme5+$me5; 
	
	
	if($temp>=$me3)
	{
		$bgculr="#254117";
	}
	elsif($temp>=$me5 & $temp<$me3)
	{
		$bgculr="#0000A0";
	}
	elsif($temp<$me5)
	{	
		$bgculr="#800000";
	}
	$culr="";
	
	$str1=$str1 . "<tr><td  class='tdn'><font color='$bgculr'>$dcode</font></td><td  class='tdn'><font color='$bgculr'>@strVal[1]</font></td><td align=right class='tdn'>$tmail</td><td align=right class='tdn'><font color='#254117'>$me3</font></td><td align=right class='tdn'><font color='#0000A0'>$me5</font></td> <td align=right class='tdn'><font color='$bgculr'><b>$temp</b></font></td></td><td align=right class='tdn'><font color='$bgculr'>$pe</font></td><td align=right class='tdn'><font color='$bgculr'>$pe1</font></td></tr>";
	$cnt=$cnt+@strVal[2];
	$tot=$tot+$temp;
}
$per1=$tot/$tme5*100;
$per1=sprintf("%d", $per1);
$per=$tot/$tme3*100;
$per=sprintf("%d", $per);

$str1=$str1 . "<tr height='30'><td class='tdn' colspan='2' align=center><strong>Total</strong></td><td align=right class='tdn'><strong>$totmail</strong></td><td align=right class='tdn'><strong><font color='#254117'>$tme3</font></strong></td><td align=right class='tdn'><strong><font color='#0000A0'>$tme5</font></strong></td> <td align=right class='tdn'><strong>$tot</strong></td><td align=right class='tdn'><strong>$per</strong></td><td align=right class='tdn'><strong>$per1</strong></td></tr>";

print <<blk2;
<body>
<form  name="frmStat">
<table border="0" width="100%">


<tr><td><table width="100%"> 

<!--<tr><td width="20%" style="border-bottom: solid 2px red;"><img src='images/DG1.JPG' style='vertical-align:middle;' border="0" height="70" width="220"></td><td align="center" style="border-bottom: solid 2px red;"><font size='5' face='Verdana'>Employee Satisfaction Survey - 2013</font></td><td width="20%" style="border-bottom: solid 2px red;"><img src='images/b1.JPG' style='vertical-align:middle;' height="70" border="0" width="220"></td></tr>-->
<tr><td align='center' colspan="3"><img src='images/header2.png' style='height:120px;width:100%;text-align:center;align:middle'></td></tr>
            <tr>
                <td colspan="3" style='text-align:center'><font color='' size=3 >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Employee Satisfaction Survey - 2014</font></td>
            </tr>
<tr><td colspan="3" height="10"></td></tr>


</table></td></tr>

<tr><td><table> 

<tr>
<td width="13%"></td>


<td align="center">

<table class="tbl">
$str1
</table>

</td>

<td width="13%"></td>
</tr>
<tr><td colspan='3'>&nbsp;</td></tr>
<tr><td colspan='3' align="center"><font size='1' face='Verdana' color='#CF001C'><i>Powered by</i> <b>Pan Arab Research Center</b></font></td></tr>

</table></td></tr>


</table>
</form>
</body>
</html>
blk2
