Current File : /home/inlingua/public_html/faridabad/icentex/attendance/ajax_attendance_report_NEW.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;
if(is_array($arr) )
{
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;
if(is_array($arr) )
{
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 number_format(($percent/$TotalH)*100,2,'.','');
}
}
function getColorPercentage($arr)
{
$percent=0;
if(is_array($arr) )
{
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)
{
if(is_array($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);
$max_tot=array();
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;
$i=1;
echo "<tr class='Attengrey'>";
echo "<td width='5%'><b>S.No.</b></td>";
echo "<td width='32%'><b>Student</b></td>";
echo "<td width='15%'><b>Present</b></td>";
echo "<td width='16%'><b>Late</b></td>";
echo "<td width='16%'><b>Excused</b></td>";
echo "<td width='16%'><b>Present%</b></td>";
echo "</tr>";
while($objectData=@mysqli_fetch_array($resultLWC))
{
$student=$objectData[Student_ID];
//$SattenArray[$objectData[studentName]];
echo "<tr>";
echo "<td>".$i."</td>";
echo "<td><a href='ingl_attendance.select.name.php?courseId=".$_REQUEST[CID]."&STuid=".$objectData[Student_ID]."&tablename=".$num[attendance_table]."&name=".$objectData[studentName]."' class='lightbox' onclick='lightb();'>$objectData[studentName]</a></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 class='".getColorPercentage($SattenArray[$objectData[Student_ID]])."'>".getPercentage($SattenArray[$objectData[Student_ID]])."</td>";
echo"</tr>";
$TotalHours=getTotalHour($SattenArray[$student]);
array_push($max_tot,$TotalHours);
$i++;
}
//$TotalHours=getTotalHour($SattenArray[$student]);
}
if(count($max_tot)>0)
{
echo"<tr><td colspan='6'><b>#Total Hours :".max($max_tot)."</b><br><b>Percentage Calculation</b> ((Present + 50% of Late + Excused)/Total No Of Hours )*100</td></tr>";
}
else
{
echo"<tr><td colspan='6'><b>#Total Hours :0</b><br><b>Percentage Calculation</b> ((Present + 50% of Late + Excused)/Total No Of Hours )*100</td></tr>";
}
}
echo "</table>";
?>