Location: PHPKode > projects > Kudos > nirap/RankingUpdate.php
<?php 

include ("includes/kudos.php");

$GroupID = $_GET['group'];
$CatID = $_GET['category'];
$row = 1;
$m= date("n");
$Date = $_GET['date'];

$GroupName_Results = mysql_query("Select GroupName from Team where GroupID ='$GroupID'");

if (is_nan($CatID) and isset($GroupID) and isset($Date)){
$RankingResults = mysql_query(" select EmployeeGroup.EmpID, FirstName, LastName, CatName as Name, Category.CatID, CatName,  sum(if (month(timestamp)='$Date',pointValue,0)) as Total  from Employee join EmployeeGroup on Employee.EmpID = EmployeeGroup.EmpID  left join GroupCategory on EmployeeGroup.GroupID = GroupCategory.GroupID left join History on GroupCategory.CatID = History.CatID and History.GroupID = GroupCategory.GroupID and EmployeeGroup.EmpID = History.EmpReceiver join Team on GroupCategory.GroupID = Team.GroupID join Category on Category. CatID  = GroupCategory.CatID  where  Team.GroupID ='$GroupID' and Category.CatID='$CatID' group by Team.GroupID, EmpID order by sum(pointValue) DESC;") or die(mysql_error());
}elseif (isset($CatID) and isset($GroupID) and isset($Date)){
$RankingResults = mysql_query(" select EmployeeGroup.EmpID, FirstName, LastName, CatName as Name, Category.CatID, CatName,  sum(if (month(timestamp)='$Date',pointValue,0)) as Total  from Employee join EmployeeGroup on Employee.EmpID = EmployeeGroup.EmpID  left join GroupCategory on EmployeeGroup.GroupID = GroupCategory.GroupID left join History on GroupCategory.CatID = History.CatID and History.GroupID = GroupCategory.GroupID and EmployeeGroup.EmpID = History.EmpReceiver join Team on GroupCategory.GroupID = Team.GroupID join Category on Category. CatID  = GroupCategory.CatID  where  Team.GroupID ='$GroupID' and Category.CatID='$CatID' group by Team.GroupID, EmpID order by sum(pointValue) DESC;") or die(mysql_error());
}
elseif (isset($CatID) and isset($GroupID)){
$RankingResults = mysql_query(" select EmployeeGroup.EmpID, FirstName, LastName, CatName as Name, Category.CatID, CatName, ifnull(sum(pointValue),0) as Total from Employee join EmployeeGroup on Employee.EmpID = EmployeeGroup.EmpID  left join GroupCategory on EmployeeGroup.GroupID = GroupCategory.GroupID left join History on GroupCategory.CatID = History.CatID and History.GroupID = GroupCategory.GroupID and EmployeeGroup.EmpID = History.EmpReceiver join Team on GroupCategory.GroupID = Team.GroupID join Category on Category. CatID  = GroupCategory.CatID  where  Team.GroupID ='$GroupID' and Category.CatID='$CatID' group by Team.GroupID, EmpID order by sum(pointValue) DESC;") or die(mysql_error());
}
elseif (isset($GroupID)){
$RankingResults = mysql_query("select EmployeeGroup.EmpID, FirstName, LastName, GroupName as Name, Category.CatID, CatName, ifnull(sum(pointValue),0) as Total from Employee join EmployeeGroup on Employee.EmpID = EmployeeGroup.EmpID  left join GroupCategory on EmployeeGroup.GroupID = GroupCategory.GroupID left join History on GroupCategory.CatID = History.CatID and History.GroupID = GroupCategory.GroupID and EmployeeGroup.EmpID = History.EmpReceiver join Team on GroupCategory.GroupID = Team.GroupID join Category on Category. CatID  = GroupCategory.CatID  where  Team.GroupID ='$GroupID' group by Team.GroupID, EmpID order by sum(pointValue) DESC;") or die(mysql_error());
}
$count = mysql_num_rows($RankingResults);


?><html><head><script src= update.js></script>




</head><body>



<?php 

$GroupName = mysql_fetch_array($GroupName_Results);

echo "<h2>Current Ranking: " .$GroupName['GroupName'] . "</h2>"; ?>
<h3>Group Categories:</h3>
<?php 
$CategoriesResults = mysql_query("Select CatName, Category.CatID from Category join GroupCategory on Category.CatID = GroupCategory.CatID where GroupID = '$GroupID';");
while($categories=mysql_fetch_array($CategoriesResults)){ 
$category = $categories['CatID'];?>
 <a onClick="getRankingUpdate('RankingUpdate.php?group=' + <?php echo $GroupID ?> + '&category='+ <?php echo $category ?>);"><?php echo $categories['CatName'] ?></a> 
<?php echo "|"; ?>
<?php } ?>

<select id = "date" onChange= "getRankingUpdate('RankingUpdate.php?group=' + <?php echo $GroupID ?>  +'&category=' + <?php echo $CatID ?>  + '&date=' + this.value );">
<option value = ''> Select month</option>
<?php while( $i <=$m){ 
$month = array('','January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'Decemeber');
?>
<option value= "<?php echo $i ?> "><?php echo $month[$i] ?></option>
<?php $i++; } ?></select>
 

<? 

if ($count == 0) { ?>
        <h2 align="center">Please Select Category.</h2>
<?php } else { ?>
<table BORDER=0 CELLSPACING=2 CELLPADDING=5 WIDTH="100%">
	<tr bgcolor="#000000">
		<th>Rank</th>
		<?php if (isset($CatID)){ ?><th>Category</th> <?php }else{ ?><th>Group</th> <?php } ?>    		
		<th>Name</th>
		<th>Points</th>
		
	</tr><tr>


<?php while($ranking=mysql_fetch_array($RankingResults)) { ?>
				 <tr><td><?php echo $row ?></td>
				<td><?php echo $ranking['Name'] ?></td>
				<td> <?php echo  $ranking['FirstName'], " ", $ranking['LastName']; ?></td>
				  <td><?php echo $ranking['Total'] ?></td></tr>
<?php $row++; }
 ?>
</table>
<?php }?>

</body>
</html>
Return current item: Kudos