Location: PHPKode > projects > TimeSheet4dotProject > ts4dp/timesheet/pgraphs.php
<?php
require_once('session.php');
require_once('global4app.php');
if ($_SESSION['uid'] == "")
{
	echo '<html><head><meta http-equiv="refresh" content="5; URL=index.php"></head><body>';
	echo '<center>Fatal Error. You haven\'t logged in properly<br/><a href=index.php>'.'Click Here To exit and login again </a> (forwarded in 5 sec.)</center></body></html>';
	exit();
}

?>
<html>
<head>
<title>Timesheet4dP : Utilization Report</title>
<link rel=stylesheet type="text/css" href="./css/main.css">
<script language="javascript" type="text/javascript" src="./js/getObj.js"></script>
<script>
var calcMonthDate = 0;

function calculate()
{
	//document.forms[0].selecteduser.options[document.forms[0].selecteduser.selectedIndex].text
	if (document.forms[0].month.selectedIndex == 0)
	{
		document.forms[0].month.focus();
		alert("Select a month");
		return false;
	}
	if (document.forms[0].year.selectedIndex == 0)
	{
		document.forms[0].year.focus();
		alert("Select a year");
		return false;
	}
	//if (document.forms[0].daySelection.selectedIndex == 0)
	//{
		//document.forms[0].daySelection.focus();
		//alert("Select number of non-working ");
	//}

	calcMonthDate = new Date(document.forms[0].year.options[document.forms[0].year.selectedIndex].value,document.forms[0].month.options[document.forms[0].month.selectedIndex].value,0);
	document.forms[0].workingdays.value = calcMonthDate.getDate() - document.forms[0].daySelection.options[document.forms[0].daySelection.selectedIndex].value;
	document.forms[0].workinghours.value = document.forms[0].workingdays.value * 8;
	return true;
}
function calculatePerformance()
{
	if (document.forms[0].workingdays.value == "" )
	{
		alert("Calculate Days & Hours");
		return false;
	}

	userIDs = "";
	count = 0;
	for (var i = 0; i < document.forms[0].selecteduser.options.length; i++)
	{
		if (document.forms[0].selecteduser.options[ i ].selected)
		{
		//alert(document.forms[0].selecteduser.options[ i ].selected);
		//alert ( document.forms[0].selecteduser.options[i].value);
		userIDs = userIDs + document.forms[0].selecteduser.options[i].value + ",";
		count = count + 1;
		}
	}
	if (count > 0)
	{
		userIDs = userIDs.substring(0, userIDs.length-1);
		//alert ("userIDs - " + userIDs);
	}
	var onePercent = (count * document.forms[0].workinghours.value) / 100 ;
	var effectiveness = 'Unknown / Error ';
	var rating =  'Unknown / Error ';

	var http = getHTTPObject();
	var URLString = 'getPerformance.php'
	// always use post, so that IE will not cache the outputs...
	http.open("POST", URLString, true);
	var dt1 =  document.forms[0].year.options[document.forms[0].year.selectedIndex].value + "-" + document.forms[0].month.options[document.forms[0].month.selectedIndex].value + "-01";
	var dt2 =  document.forms[0].year.options[document.forms[0].year.selectedIndex].value + "-" + document.forms[0].month.options[document.forms[0].month.selectedIndex].value + "-" + calcMonthDate.getDate();
	var params = "ids=" + userIDs +"&date1=" +dt1 + "&date2=" + dt2;
	//alert (params);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");
	http.onreadystatechange = function()
	{
		if (http.readyState == 4)
		{
			var reply = http.responseText;
			effectiveness = Math.ceil ( reply / onePercent );
			//alert (effectiveness);
			document.forms[0].actualEffectiveness.value = effectiveness + "%";

			if (effectiveness >= 85 )
			{
				rating = "Doubtful or Excellent Utilisation";
			}
			else if ( (effectiveness <= 85) && (effectiveness >=65))
			{
				rating = "Good Utilisation";
			}
			else if ( (effectiveness <= 65) && (effectiveness >=45))
			{
				rating = "Average Utilisation";
			}
			else if ( (effectiveness <= 45) && (effectiveness >=0))
			{
				rating = "Poor Utilisation";
			}
			document.forms[0].actualRating.value = rating;
			alert ( effectiveness + "%, " + rating);
			//document.forms[0].workingdays.value = "";
			//document.forms[0].workinghours.value = "";
		}
	}
	http.send(params);
	return true;
}

</script>
</head>
<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<br><br>
<table width=55% cellpadding=7 cellspacing=1 border=1 align=center valign=center>
<form>
<tr>
<td>Utilization Report based on task logs</td>
<td align=left colspan=2>Logged in as - <? echo $_SESSION["username"]?></td>
<td align=right><a href="startPage.php"><b><h1>Home</h1></b></a></td>
</tr>
<tr>
<td>Select a month</td>
<td><select size="1" name="month">
<option value="0">Month</option>
<option value="1">Jan</option>
<option value="2">Feb</option>
<option value="3">Mar</option>
<option value="4">Apr</option>
<option value="5">May</option>
<option value="6">Jun</option>
<option value="7">Jul</option>
<option value="8">Aug</option>
<option value="9">Sep</option>
<option value="10">Oct</option>
<option value="11">Nov</option>
<option value="12">Dec</option>
</select>
</td>
<td>Select a year</td>
<td>
<select size="1" name="year">
<option value="0">Year</option>
<option value=2008>2009</option>
<option value=2008>2008</option>
<option value=2007>2007</option>
<option value=2006>2006</option>
</select>
</td>

</tr>
<tr><td>Total Number of Non-Working Days (Weekends, Holidays, Leaves)</td>
<td colspan=3>
<SELECT NAME="daySelection">
   <OPTION> 0 <OPTION> 1 <OPTION> 2 <OPTION> 3 <OPTION> 4 <OPTION> 5
   <OPTION> 6 <OPTION> 7 <OPTION> 8 <OPTION> 9 <OPTION> 10
   <OPTION> 11 <OPTION> 12 <OPTION> 13 <OPTION> 14 <OPTION> 15
   <OPTION> 16 <OPTION> 17 <OPTION> 18 <OPTION> 19 <OPTION> 20
   <OPTION> 21 <OPTION> 22 <OPTION> 23 <OPTION> 24 <OPTION> 25
   <OPTION> 26 <OPTION> 27 <OPTION> 28 <OPTION> 29 <OPTION> 30
   <OPTION> 31
</SELECT>
</td>
</tr>
<tr><td colspan=4 align=center><input type=button value="Calculate Days & Hours" onClick="calculate()"></td></tr>
<tr><td>Total Number of Working Days</td> <td colspan=3> <input name=workingdays type=text value="" disabled> </td></tr>
<tr><td>Total Working hours per person (8 hrs per day)</td> <td colspan=3> <input name=workinghours type=text value="" disabled> </td></tr>
<tr><td>Select Users</td>
<td colspan=3>
<select id=selecteduser name=selecteduser size=10 multiple style="width:150">
<?php
if ($_SESSION["admin"] == "true")
{
	$result = db_loadList('select * from users where user_username != \'admin\'');
	foreach($result as $row)
	{
		echo '<option value='.$row['user_id'].'>'.$row['user_username'].'</option>';
	}
}
else
{
	echo '<option value='.$_SESSION['uid'].'>'.$_SESSION['username'].'</option>';
	$result = db_loadList('select * from users where user_reporting_to = \''.$_SESSION['uid'].'\'');
	foreach($result as $row)
	{
		echo '<option value='.$row['user_id'].'>'.$row['user_username'].'</option>';
	}
}
?>
</select>
</td></tr>
<tr><td align=center colspan=4><input type=button value="Calculate Utilization" onClick="calculatePerformance()"></td></tr>
<tr><td>Effectiveness</td> <td colspan=3> <input name=actualEffectiveness type=text value="" disabled> </td></tr>
<tr><td>Rating</td> <td colspan=3> <input name=actualRating size=40 type=text value="" disabled> </td></tr>
</form></table>
<?php
include ('footer.php');
?>
</body>
</html>
Return current item: TimeSheet4dotProject