Location: PHPKode > projects > TimeSheet4dotProject > ts4dp/timesheet/drawCompany.php
<?php
// GRAPHS PAGE ONLY WORKS FOR MYSQL DB, WE NEED TO CHANGE mysql_query TO db_loadList, delayed due to object array to json conversion bug
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();
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Timesheet4dP : User Graphs</title>
<style type="text/css">
	.chart
	{
		float: left;
		width: 250px;
		height: 200px;
	}
</style>
<link rel=stylesheet type="text/css" href="./css/main.css">
<link rel="stylesheet" type="text/css" href="./yui/fonts/fonts-min.css?_yuiversion=2.5.0" />
<script type="text/javascript" src="./yui/yahoo-dom-event/yahoo-dom-event.js?_yuiversion=2.5.0"></script>
<script type="text/javascript" src="./yui/json/json-beta.js?_yuiversion=2.5.0"></script>
<script type="text/javascript" src="./yui/element/element-beta.js?_yuiversion=2.5.0"></script>
<script type="text/javascript" src="./yui/datasource/datasource-beta.js?_yuiversion=2.5.0"></script>
<script type="text/javascript" src="./yui/charts/charts-experimental.js?_yuiversion=2.5.0"></script>
<script language="javascript" type="text/javascript" src="./js/getObj.js"></script> 
</head>
<body class=" yui-skin-sam" bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<br><br>
<script>
<?
$currentUser = "";
$currentUserName = "";
if ($_REQUEST["selecteduser"] == "")
{
	// no selected user, then draw for the current user
	$s1_query = 'select ceil(sum(task_log_hours)) as total_time, company_name from dotproject.task_log, dotproject.tasks, dotproject.projects, dotproject.companies where task_log_creator = '.$_SESSION["uid"].' and task_log_date <= \''.$_POST["s1d1"].'\'  and task_log_task = task_id and task_project = project_id and project_company = company_id group by company_name order by total_time desc';
	$s2_query = 'select ceil(sum(task_log_hours)) as total_time, company_name from dotproject.task_log, dotproject.tasks, dotproject.projects, dotproject.companies where task_log_creator = '.$_SESSION["uid"].' and task_log_date <= \''.$_POST["s2d2"].'\'  and task_log_task = task_id and task_project = project_id and project_company = company_id group by company_name order by total_time desc';
	$s3_query = 'select ceil(sum(task_log_hours)) as total_time, company_name from dotproject.task_log, dotproject.tasks, dotproject.projects, dotproject.companies where task_log_creator = '.$_SESSION["uid"].' and task_log_date between \''.$_POST["s1d1"].'\' and \''.$_POST["s2d2"].'\'  and task_log_task = task_id and task_project = project_id and project_company = company_id group by company_name order by total_time desc';
	$currentUser = $_SESSION["uid"];
	$currentUserName = $_SESSION["username"];
	
}
else
{
	$currentUser = $_REQUEST["selecteduser"];
	$currentUserName =  $_REQUEST["selectedUsername"];
	if ($_REQUEST["selecteduser"] == "0")
	{
	// for all users , company and projects, tasks
	// DATE_SUB(SYSDATE(), INTERVAL 31 DAY)
	$s1_query = 'select ceil(sum(task_log_hours)) as total_time, company_name from dotproject.task_log, dotproject.tasks, dotproject.projects, dotproject.companies where task_log_date <= \''.$_POST["s1d1"].'\'  and task_log_task = task_id and task_project = project_id and project_company = company_id group by company_name order by total_time desc';
	$s2_query = 'select ceil(sum(task_log_hours)) as total_time, company_name from dotproject.task_log, dotproject.tasks, dotproject.projects, dotproject.companies where task_log_date <= \''.$_POST["s2d2"].'\'  and task_log_task = task_id and task_project = project_id and project_company = company_id group by company_name order by total_time desc';
	$s3_query = 'select ceil(sum(task_log_hours)) as total_time, company_name from dotproject.task_log, dotproject.tasks, dotproject.projects, dotproject.companies where task_log_date between \''.$_POST["s1d1"].'\' and \''.$_POST["s2d2"].'\'  and task_log_task = task_id and task_project = project_id and project_company = company_id group by company_name order by total_time desc';
		
	}
	else
	{
	//for selected person only
	$s1_query = 'select ceil(sum(task_log_hours)) as total_time, company_name from dotproject.task_log, dotproject.tasks, dotproject.projects, dotproject.companies where task_log_creator = '.$_REQUEST["selecteduser"].' and task_log_date <= \''.$_POST["s1d1"].'\'  and task_log_task = task_id and task_project = project_id and project_company = company_id group by company_name order by total_time desc';
	$s2_query = 'select ceil(sum(task_log_hours)) as total_time, company_name from dotproject.task_log, dotproject.tasks, dotproject.projects, dotproject.companies where task_log_creator = '.$_REQUEST["selecteduser"].' and task_log_date <= \''.$_POST["s2d2"].'\'  and task_log_task = task_id and task_project = project_id and project_company = company_id group by company_name order by total_time desc';
	$s3_query = 'select ceil(sum(task_log_hours)) as total_time, company_name from dotproject.task_log, dotproject.tasks, dotproject.projects, dotproject.companies where task_log_creator = '.$_REQUEST["selecteduser"].' and task_log_date between \''.$_POST["s1d1"].'\' and \''.$_POST["s2d2"].'\'  and task_log_task = task_id and task_project = project_id and project_company = company_id group by company_name order by total_time desc';

	}
}
	//echo "//" . $s1_query ."\n";
	//echo "//" . $s2_query ."\n";
	//echo "//" . $s3_query ."\n";
	$result =mysql_query($s1_query);
	$returnArray = array();
	while($row = mysql_fetch_assoc($result))
	{
		array_push($returnArray, $row);
	}
	if (json_encode($returnArray) == "[]")
	print "ResultSet1 = [{\"total_time\":\"100\",\"company_name\":\"Company\"}]\n";
	else
	print 'ResultSet1 = '.json_encode($returnArray)."\n";
	
	$result = mysql_query($s2_query);
	$returnArray = array();
	while($row = mysql_fetch_assoc($result))
	{
		array_push($returnArray, $row);
		//echo $row['company_name'].'-'.$row['total_time'].'<br>';
	}
	if (json_encode($returnArray) == "[]")
	print "ResultSet2 = [{\"total_time\":\"100\",\"company_name\":\"Company\"}]\n";
	else
	print 'ResultSet2 = '.json_encode($returnArray)."\n";

	$result = mysql_query($s3_query);
	$returnArray = array();
	while($row = mysql_fetch_assoc($result))
	{
		array_push($returnArray, $row);
		//echo $row['company_name'].'-'.$row['total_time'].'<br>';
	}
	if (json_encode($returnArray) == "[]")
	print "ResultSet3 = [{\"total_time\":\"100\",\"company_name\":\"Company\"}]\n";
	else
	print 'ResultSet3 = '.json_encode($returnArray)."\n";

?>
//end php , start java script
// data to intialize project and task charts

ResultSet1p = [{"total_time":"100","project_name":"Select a Company"}]
ResultSet2p = [{"total_time":"100","project_name":"Select a Company"}]
ResultSet3p = [{"total_time":"100","project_name":"Select a Company"}]
ResultSet1t = [{"total_time":"100","task_name":"Select a Project"}]
ResultSet2t = [{"total_time":"100","task_name":"Select a Project"}]
ResultSet3t = [{"total_time":"100","task_name":"Select a Project"}]


function changeTask()
{
	//view project - means viewing its task
	document.forms[1].projectNameText.value = getObj("projectName")[getObj("projectName").selectedIndex].text;
	var selectedProjectID = getObj('projectName')[getObj('projectName').selectedIndex].value;
	var selectedCompanyID = getObj('companyID')[getObj('companyID').selectedIndex].value;
	var http = getHTTPObject();
	var URLString = 'drawTasks.php'
	http.open("POST", URLString, true); 
	var params = "companyID=" + selectedCompanyID +"&projectID="+ selectedProjectID + "&s1d1=" + document.forms[1].s1d1.value + "&s2d2=" + document.forms[1].s2d2.value + "&selecteduser=" + <?php print $currentUser ?>;
	//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) 
		{ 
			//alert(http.responseText); 
			var reply = http.responseText;
			//alert (reply);
			getObj("TitleProjectName").innerHTML = "<b>Time utilization for " + document.forms[1].projectNameText.value  + " by Tasks </b>"
			eval(reply);
			//alert (ResultSet1p[0].project_name);
			opinionData1t = new YAHOO.util.DataSource( ResultSet1t );
			opinionData1t.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
			opinionData1t.responseSchema = { fields: [ "task_name", "total_time" ] };
		
			opinionData2t = new YAHOO.util.DataSource( ResultSet2t );
			opinionData2t.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
			opinionData2t.responseSchema = { fields: [ "task_name", "total_time" ] };
			
			opinionData3t = new YAHOO.util.DataSource( ResultSet3t );
			opinionData3t.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
			opinionData3t.responseSchema = { fields: [ "task_name", "total_time" ] };		
		
			mychart1p = new YAHOO.widget.PieChart( "chart1t", opinionData1t,
			{
				dataField: "total_time",
				categoryField: "task_name",
				series: [{}]
			});
		
			mychart2p = new YAHOO.widget.PieChart( "chart2t", opinionData2t,
			{
				dataField: "total_time",
				categoryField: "task_name",
				series: [{}]
			});
			
			mychart3p = new YAHOO.widget.PieChart( "chart3t", opinionData3t,
			{
				dataField: "total_time",
				categoryField: "task_name",     
				series: [{}]
			});
	
		} 
	} 
	http.send(params);	
}

function changeProjects()
{
	var selectedCompanyID = getObj('companyID')[getObj('companyID').selectedIndex].value;
	if (selectedCompanyID > 0)
	{
		// populate projects
		var http = getHTTPObject();
      		var URLString = 'getProjects.php'
		// always use post, so that IE will not cache the outputs...
      		http.open("POST", URLString, true); 
		var params = "companyId=" + selectedCompanyID;
		//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) 
              		{ 
                    		//alert(http.responseText); 
                    		getObj("projectList").innerHTML = " Select a Project (P.S. To view time utilization by Tasks) "+http.responseText;
              		} 
      		} 
      		http.send(params);
	}
	else
	{
		alert("Select a valid company");
		return false;
	}
}

function viewCompany()
{                     
	document.forms[1].companyName.value = document.forms[1].companyID[document.forms[1].companyID.selectedIndex].text;
	//alert (document.forms[1].companyName.value);	
	//get data, redraw graphs..
	var selectedCompanyID = getObj('companyID')[getObj('companyID').selectedIndex].value;
	//alert (selectedCompanyID);
	// populate projects
	var http = getHTTPObject();
	var URLString = 'drawProjects.php'
	// always use post, so that IE will not cache the outputs...
	http.open("POST", URLString, true); 
	var params = "companyID=" + selectedCompanyID + "&s1d1=" + document.forms[1].s1d1.value + "&s2d2=" + document.forms[1].s2d2.value + "&selecteduser=" + <?php print $currentUser ?>;
	//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) 
		{ 
			//alert(http.responseText); 
			var reply = http.responseText;
			//alert (reply);
			getObj("TitleCompanyName").innerHTML = "<b>Time utilization for " + document.forms[1].companyName.value  + " by Projects </b> "
			eval(reply);
			//alert (ResultSet1p[0].project_name);
			opinionData1p = new YAHOO.util.DataSource( ResultSet1p );
			opinionData1p.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
			opinionData1p.responseSchema = { fields: [ "project_name", "total_time" ] };
		
			opinionData2p = new YAHOO.util.DataSource( ResultSet2p );
			opinionData2p.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
			opinionData2p.responseSchema = { fields: [ "project_name", "total_time" ] };
			
			opinionData3p = new YAHOO.util.DataSource( ResultSet3p );
			opinionData3p.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
			opinionData3p.responseSchema = { fields: [ "project_name", "total_time" ] };		
		
			mychart1p = new YAHOO.widget.PieChart( "chart1p", opinionData1p,
			{
				dataField: "total_time",
				categoryField: "project_name",
				series: [{}]
			});
		
			mychart2p = new YAHOO.widget.PieChart( "chart2p", opinionData2p,
			{
				dataField: "total_time",
				categoryField: "project_name",
				series: [{}]
			});
			
			mychart3p = new YAHOO.widget.PieChart( "chart3p", opinionData3p,
			{
				dataField: "total_time",
				categoryField: "project_name",     
				series: [{}]
			});
	
		} 
	} 
	http.send(params);
	changeProjects();
	
}
</script>

<table border=0 align=center cellpadding=4 cellspacing=1>
<tr><td colspan=4><a href="javascript:history.back();">Back</a> &nbsp; &nbsp; <a href=startPage.php>Home</a></td><td align=right><font color=red>Graphs for <? echo $currentUserName ?></font></td></tr>
<tr><td colspan=5 align=center><b>Time utilization by Company (Mouseover on pie for details) </b></td></tr>
<form method=POST action=drawCompany.php name=userform id=userform>
<input type=hidden id=selectedUsername name=selectedUsername value="All Users">
<input type=hidden size=12 name=s2d2 id=s2d2 value=<?php print $_POST['s2d2']; ?>>
<input type=hidden size=12 name=s1d1 id=s1d1 value=<?php print $_POST['s1d1']; ?>>
<tr><td colspan=5 align=center> Select User 
<select id=selecteduser name=selecteduser onChange="javascript:document.forms[0].selectedUsername.value =document.forms[0].selecteduser.options[document.forms[0].selecteduser.selectedIndex].text;document.forms[0].submit();"><option value=0>Select Option</option>
<?php
if ($_SESSION["admin"] == "true")
{
	echo '<option value=0>All Users</option>';
	$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>';
	}
}
?>
</td></tr>
</form>

<tr><td align=center>Subject 1 (Date 1) <? echo $_POST["s1d1"] ?></td><td></td><td align=center>Subject 2 (Date 2) <? echo $_POST["s2d2"] ?></td><td></td><td>Difference Graph <br> (i.e If the below graph is blank/white,<br> Then it means "No Activity")</td></tr>
<tr><td><div id="chart1" class="chart">Unable to load Flash content. The YUI Charts Control requires Flash Player 9.0.45 or higher. You can download the latest version of Flash Player from the <a href="http://www.adobe.com/go/getflashplayer">Adobe Flash Player Download Center</a>.</div></td><td>Vs</td><td><div id="chart2" class="chart">Unable to load Flash content. The YUI Charts Control requires Flash Player 9.0.45 or higher. You can download the latest version of Flash Player from the <a href="http://www.adobe.com/go/getflashplayer">Adobe Flash Player Download Center</a>.</div></td><td>=</td><td><div id="chart3" class="chart">Unable to load Flash content. The YUI Charts Control requires Flash Player 9.0.45 or higher. You can download the latest version of Flash Player from the <a href="http://www.adobe.com/go/getflashplayer">Adobe Flash Player Download Center</a>.</div></td></tr>
<form method=post action=drawProjects.php>
<input type=hidden id=s1d1 name=s1d1 value="<? echo $_POST["s1d1"] ?>">
<input type=hidden id=s2d2 name=s2d2  value="<? echo $_POST["s2d2"] ?>">
<input type=hidden id=companyName name=companyName  value="">
<input type=hidden id=projectNameText name=projectNameText value="">
<tr>
	<td colspan=5 align=center>Select a Company (P.S. To view time utilization by Projects)
	<select name=companyID id=companyID style="{width:275}" onChange="viewCompany();"><option id=0>Select a Company</option>
	<?php
	$result = mysql_query('select	* from companies');
	while($row = mysql_fetch_assoc($result))
	{
		echo '<option value='.$row['company_id'].'>'.$row['company_name'].'</option>';
	}	                                   
	?>
	</select></td>
</tr>
<tr><td colspan=5 align=center><div id=TitleCompanyName name=TitleCompanyName>Time utilization for a Company by Projects</div></td></tr>
<tr><td><div id="chart1p" class="chart">Unable to load Flash content. The YUI Charts Control requires Flash Player 9.0.45 or higher. You can download the latest version of Flash Player from the <a href="http://www.adobe.com/go/getflashplayer">Adobe Flash Player Download Center</a>.</div></td><td>Vs</td><td><div id="chart2p" class="chart">Unable to load Flash content. The YUI Charts Control requires Flash Player 9.0.45 or higher. You can download the latest version of Flash Player from the <a href="http://www.adobe.com/go/getflashplayer">Adobe Flash Player Download Center</a>.</div></td><td>=</td><td><div id="chart3p" class="chart">Unable to load Flash content. The YUI Charts Control requires Flash Player 9.0.45 or higher. You can download the latest version of Flash Player from the <a href="http://www.adobe.com/go/getflashplayer">Adobe Flash Player Download Center</a>.</div></td></tr>
<tr><td colspan=5 align=center><div id=projectList>Select a Project (P.S. To view time utilization by its Tasks) <select name=projectName id=projectName style="{width:275}" onChange=changeTask();><option id=0>Select a Project</option></select></div></td>
</tr>
<tr><td colspan=5 align=center><div id=TitleProjectName name=TitleProjectName>Time utilization for a Project by Tasks</div></td></tr>
<tr><td><div id="chart1t" class="chart">Unable to load Flash content. The YUI Charts Control requires Flash Player 9.0.45 or higher. You can download the latest version of Flash Player from the <a href="http://www.adobe.com/go/getflashplayer">Adobe Flash Player Download Center</a>.</div></td><td>Vs</td><td><div id="chart2t" class="chart">Unable to load Flash content. The YUI Charts Control requires Flash Player 9.0.45 or higher. You can download the latest version of Flash Player from the <a href="http://www.adobe.com/go/getflashplayer">Adobe Flash Player Download Center</a>.</div></td><td>=</td><td><div id="chart3t" class="chart">Unable to load Flash content. The YUI Charts Control requires Flash Player 9.0.45 or higher. You can download the latest version of Flash Player from the <a href="http://www.adobe.com/go/getflashplayer">Adobe Flash Player Download Center</a>.</div></td></tr>
</form>
</table>

<script type="text/javascript">
	YAHOO.widget.Chart.SWFURL = "./yui/charts/assets/charts.swf?_yuiversion=2.5.0";

	var opinionData1c = new YAHOO.util.DataSource( ResultSet1 );
	opinionData1c.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
	opinionData1c.responseSchema = { fields: [ "company_name", "total_time" ] };

	var opinionData2c = new YAHOO.util.DataSource( ResultSet2 );
	opinionData2c.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
	opinionData2c.responseSchema = { fields: [ "company_name", "total_time" ] };
	
	var opinionData3c = new YAHOO.util.DataSource( ResultSet3 );
	opinionData3c.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
	opinionData3c.responseSchema = { fields: [ "company_name", "total_time" ] };	
	
	//--- chart

	var mychart1c = new YAHOO.widget.PieChart( "chart1", opinionData1c,
	{
		dataField: "total_time",
		categoryField: "company_name",
		series: [{}]
	});

	var mychart2c = new YAHOO.widget.PieChart( "chart2", opinionData2c,
	{
		dataField: "total_time",
		categoryField: "company_name",
		series: [{}]
	});
	
	var mychart3c = new YAHOO.widget.PieChart( "chart3", opinionData3c,
	{
		dataField: "total_time",
		categoryField: "company_name",
		series: [{}]
	});
	
	var opinionData1p = new YAHOO.util.DataSource( ResultSet1p );
	opinionData1p.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
	opinionData1p.responseSchema = { fields: [ "project_name", "total_time" ] };

	var opinionData2p = new YAHOO.util.DataSource( ResultSet2p );
	opinionData2p.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
	opinionData2p.responseSchema = { fields: [ "project_name", "total_time" ] };
	
	var opinionData3p = new YAHOO.util.DataSource( ResultSet3p );
	opinionData3p.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
	opinionData3p.responseSchema = { fields: [ "project_name", "total_time" ] };		

	var mychart1p = new YAHOO.widget.PieChart( "chart1p", opinionData1p,
	{
		dataField: "total_time",
		categoryField: "project_name",
		series: [{}]
	});

	var mychart2p = new YAHOO.widget.PieChart( "chart2p", opinionData2p,
	{
		dataField: "total_time",
		categoryField: "project_name",
		series: [{}]
	});
	
	var mychart3p = new YAHOO.widget.PieChart( "chart3p", opinionData3p,
	{
		dataField: "total_time",
		categoryField: "project_name",
		series: [{}]
	});
	
	var opinionData1t = new YAHOO.util.DataSource( ResultSet1t );
	opinionData1t.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
	opinionData1t.responseSchema = { fields: [ "task_name", "total_time" ] };

	var opinionData2t = new YAHOO.util.DataSource( ResultSet2t );
	opinionData2t.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
	opinionData2t.responseSchema = { fields: [ "task_name", "total_time" ] };
	
	var opinionData3t = new YAHOO.util.DataSource( ResultSet3t );
	opinionData3t.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
	opinionData3t.responseSchema = { fields: [ "task_name", "total_time" ] };		

	var mychart1t = new YAHOO.widget.PieChart( "chart1t", opinionData1t,
	{
		dataField: "total_time",
		categoryField: "task_name",
		series: [{}]
	});

	var mychart2t = new YAHOO.widget.PieChart( "chart2t", opinionData2t,
	{
		dataField: "total_time",
		categoryField: "task_name",
		series: [{}]
	});
	
	var mychart3t = new YAHOO.widget.PieChart( "chart3t", opinionData3t,
	{
		dataField: "total_time",
		categoryField: "task_name",
		series: [{}]
	});	
</script>
<center><b>Graphs will work only with Flash 9.0 r115 or higher </b></center>
</body>
</html>

Return current item: TimeSheet4dotProject