Current File : /home/inlingua/public_html/icentex/attendance/old_ajax_attendance.php
<?php
// Include the database connection details
require('../dbConnection.php');

// Include common functions
require('../commonFunc.php');

// Include common functions
require('../globalVars.php');

// Include the table handler class
require('../dbHandler.class.php');

// Init and connect to database
$dbObject = new dbHandler();
$dbObject->connect();

//$query="select * from ingl_course where recNo='".$_REQUEST[CID]."'";

$query="select * from ingl_course where recNo='".$_REQUEST[CID]."'";
$result=mysqli_query($conn,$query);
$num=mysqli_fetch_array($result);
if($num['attendance_table']=="")
			{
			$num['attendance_table']='ingl_attendances_2011';
			}
			
	 $queryM="select * from ".$num['attendance_table']." where courseIdrecNo='".$_REQUEST[CID]."' ";
	$resultM=mysqli_query($conn,$queryM);
	$StudentTotalEntered=@mysqli_num_rows($resultM);
	while($numM=@mysqli_fetch_array($resultM))
	{
	$studentrecNo=$numM['studentrecNo'];
	$SattenArray[$studentrecNo][] = $numM['attendance_status'];
	}
	
	
  function getPresentBySymbol($arr,$symbol)
	{
	$present=0;
	foreach($arr as $key=>$val)
		{
		$exp=explode('~#',$val);
		foreach($exp as $keys=>$vals)
			{
			if($vals==$symbol) 	$present+=1;
			}
		}
		return $present;
	}
	
 function getPercentage($arr)
	{
	$percent=0;
	foreach($arr as $key=>$val)
		{
		$exp=explode('~#',$val);
		foreach($exp as $keys=>$vals)
			{
			if($vals=='P') 	$percent+=1;
			if($vals=='L') 	$percent+=.5;
			if($vals=='E') 	$percent+=1;
			}
			$TotalH=$TotalH+count($exp);
		}
		return ($percent/$TotalH)*100;
	}

 function getColorPercentage($arr)
	{
	$percent=0;
	foreach($arr as $key=>$val)
		{
		$exp=explode('~#',$val);
		foreach($exp as $keys=>$vals)
			{
			if($vals=='P') 	$percent+=1;
			if($vals=='L') 	$percent+=.5;
			if($vals=='E') 	$percent+=1;
			}
			$TotalH=$TotalH+count($exp);
		}
		$percentage =($percent/$TotalH)*100;
		if($percentage < 75) $class="AttenRed";
		else $class="AttenGreen";
		return $class;
	}

	function getTotalHour($arr)
	{
	
		foreach($arr as $key=>$val)
		{
		$exp=explode('~#',$val);
		 
			$TotalH=$TotalH+count($exp);
		}
		
		return $TotalH;
	}

	
	//$atten=$numM['attendance_status'];

$sqlQuery = "SELECT s.*,s.recNo as Student_ID,c.courseid as course_name,c.recNo as courseRecNo, c.* FROM ingl_student s left join ingl_course c on c.recNo = s.courseId where s.courseId='".$_REQUEST['CID']."' order by s.studentName Asc";
// Select records from table
//$selectedRecords = $dbObject->Select($sqlQuery);
$resultLWC=mysqli_query($conn,$sqlQuery);
$selectedRecords=mysqli_num_rows($resultLWC);
//$numLWC=mysqli_fetch_array($resultLWC);

echo "<table border='1' align='center' class='ajxAtten' cellspacing='0' width='100%'>";
// If no records selected, print message
if (!$selectedRecords)
{	echo "<tr><td colspan='5'>There are no student added in this course</td></tr>"; }
else{	
	if (!$StudentTotalEntered)
		{	echo "<tr><td colspan='5'>There are no entered attendance</td></tr>"; }
	else{
			$counter=0;
			echo "<tr class='Attengrey'>";
			echo "<td><b>Student</b></td>";
			echo "<td><b>Present</b></td>";
			echo "<td><b>Late</b></td>";
			echo "<td><b>Excused</b></td>";
			echo "<td><b>Present%</b></td>";
			echo "</tr>";
			
			while($objectData=@mysqli_fetch_array($resultLWC))
			{	
			
			$student=$objectData[Student_ID];
			
				//$SattenArray[$objectData[studentName]];
			echo "<tr class='".getColorPercentage($SattenArray[$objectData[Student_ID]])."'>";
			echo "<td>$objectData[studentName]</td>";
			echo "<td>".getPresentBySymbol($SattenArray[$objectData[Student_ID]],'P')."</td>";
			echo "<td>".getPresentBySymbol($SattenArray[$objectData[Student_ID]],'L')."</td>";
			echo "<td>".getPresentBySymbol($SattenArray[$objectData[Student_ID]],'E')."</td>";
			echo "<td>".getPercentage($SattenArray[$objectData[Student_ID]])."</td>";
			echo"</tr>";
			}
			$TotalHours=getTotalHour($SattenArray[$student]);
		}
		
	echo"<tr><td colspan='5'><b>#Total Hours :".$TotalHours."</b><br><b>Percentage Calculation</b> ((Present + 50% of Late + Excused)/Total No Of Hours )*100</td></tr>";		
}


echo "</table>";
?>