<?php
session_start();
include 'dbc.php';

date_default_timezone_set("Asia/Karachi");
$today=date("Y-m-d");
$month = date("m",strtotime($today));
		$year = date("Y",strtotime($today));
		 $month_name = date("F", mktime(0, 0, 0, $month, 10));
		 $my=$month_name . " " . $year;
$username=$_SESSION["username"];
$userid=$_SESSION["userid"];


$size = count($_POST['tmark1']);
$i = 0;
while ($i < $size) {
$id= $_POST['id'][$i];
$std_rollno= $_POST['std_rollno'][$i];
	$omark1= $_POST['omark1'][$i];
	$omark2 = $_POST['omark2'][$i];
	 $omark3 = $_POST['omark3'][$i];
	  $omark4 = $_POST['omark4'][$i];
	  $omark5 = $_POST['omark5'][$i];
	  $omark6 = $_POST['omark6'][$i];
	  $omark7 = $_POST['omark7'][$i];
	  $omark8 = $_POST['omark8'][$i];
	   $omark9 = $_POST['omark9'][$i];
	    $omark10 = $_POST['omark10'][$i];
	 $tmark1= $_POST['tmark1'][$i];
	$tmark2 = $_POST['tmark2'][$i];
	 $tmark3 = $_POST['tmark3'][$i];
	  $tmark4 = $_POST['tmark4'][$i];
	  $tmark5 = $_POST['tmark5'][$i];
	  $tmark6 = $_POST['tmark6'][$i];
	  $tmark7 = $_POST['tmark7'][$i];
	  $tmark8 = $_POST['tmark8'][$i];
	  $tmark9 = $_POST['tmark9'][$i];
	  $tmark10 = $_POST['tmark10'][$i];
	
	  $per1 = $omark1 / $tmark1 * 100;
	  $per2 = $omark2 / $tmark2 * 100;
	  $per3 = $omark3 / $tmark3 * 100;
	  $per4 = $omark4 / $tmark4 * 100;
	  $per5 = $omark5 / $tmark5 * 100;
	  $per6 = $omark6 / $tmark6 * 100;
	  $per7 = $omark7 / $tmark7 * 100;
	  $per8 = $omark8 / $tmark8 * 100;
	   $per9 = $omark9 / $tmark9 * 100;
	    $per10 = $omark10 / $tmark10 * 100;
	  $per1 = round($per1,2);
	   $per2 = round($per2,2);
	  $per3 = round($per3,2);
	  $per4 = round($per4,2);
	  $per5 = round($per5,2);
	  $per6 = round($per6,2);
	  $per7 = round($per7,2);
	  $per8 = round($per8,2);
	   $per9 = round($per9,2);
	    $per10 = round($per10,2);
	   $obtmark=$omark1 + $omark2 + $omark3 + $omark4 + $omark5 + $omark6 + $omark7 + $omark8 + $omark9 + $omark10;
	  $totalmark=$tmark1 + $tmark2 + $tmark3 + $tmark4 + $tmark5 + $tmark6 + $tmark7 + $tmark8 + $tmark9 + $tmark10;
	  $per = $obtmark / $totalmark * 100;
	  $per = round($per,2);
			if ($per >= 33)
{
$status="Pass";
}
else
{
$status="Fail";
}

if ($per >= 90)
{
$grd="A+";
$remk="Exceptional, Exceeds expectations with the quality of his /her work & Keep it up.";
}
elseif ($per >= 80)
{
$grd="A";
$remk="Excellent, Admirable progress in all academic area";
}
elseif ($per >= 70)
{
$grd="B+";
$remk="Very Good, Making Steady Progress Academically";
}
elseif ($per >= 60)
{
$grd="B";
$remk="Good,  Needs to pay attention for the quality of work";
}
elseif ($per >= 50)
{
$grd="C+";
$remk="Fair,Needs to increase skills in all written work & reading";
}
elseif ($per >= 40)
{
$grd="C";
$remk="Undertaking,Needs to demonstrate improvement in academic work ";
}
elseif ($per >= 33)
{
$grd="D";
$remk="Result is Unsatisfactory & the student is required to work hard";
}

else
{
$grd="E";
$remk="Fail";
}


	$sql = "update result set 
omark1='$omark1', omark2='$omark2' , omark3='$omark3', omark4='$omark4', omark5='$omark5', omark6='$omark6', omark7='$omark7', omark8='$omark8', per1='$per1', per2='$per2', per3='$per3', per4='$per4', per5='$per5', per6='$per6', per7='$per7', per8='$per8', omark9='$omark9', omark10='$omark10', per9='$per9', per10='$per10', obtmark='$obtmark' , per='$per', status='$status', grade='$grd', remarks='$remk' where id='$id'";
$conn->query($sql);

	++$i;

// do the update and print out some info just to provide some visual feedback


} 

echo "Record Update";
//echo"<td> <a href ='open_customers.php?areaname=$party_area'>Click to Main Dashboard</a>";
echo"<td> <a href ='Genrate_Exam.php'>Back</a>";
?>
