<?php 

error_reporting(E_ERROR | E_PARSE); 

$years = array("batch1YEAR2SEM" => "I Year II Sem", "batch2YEAR1SEM" => "II Year I Sem", "batch2YEAR2SEM" => "II Year II Sem", "batch3YEAR1SEM" => "III Year I Sem", "batch3YEAR2SEM" => "III Year II Sem", "batch4YEAR1SEM" => "IV Year I Sem", "batch4YEAR2SEM" => "IV Year II Sem");

$branch = array(

	"A01" => "Civil Engineering", 

	"A04" => "Electronics & Communications Engineering", 

	"A02" => "Electrical & Electronics Engineering", 

	"A03" => "Mechanical Engineering", 

	"A05" => "Computer Science & Engineering",  

	"A44" => "Computer Science & Engineering (Data Science)",  

	"A49" => "Computer Science & Engineering (IoT)", 

	"A42" => "Computer Science & Engineering (AI & ML)",  

	"A46" => "Computer Science & Engineering (Cyber Security)",

	"D04" => "Mechanical Engineering (CAD/CAM)",

	"D55" => "Electronics & Communications Engineering (Embedded Systems)",

	"D58" => "Computer Science & Engineering",

	"D43" => "Electrical & Electronics Engineering (Power Electronics)"

);

$branchgradepoints = array('AR17A01' => array ('batch1YEAR1SEM' => 25, 'batch1YEAR2SEM' => 25, 'batch2YEAR1SEM' => 23, 'batch2YEAR2SEM' => 25, 'batch3YEAR1SEM' => 23, 'batch3YEAR2SEM' => 24, 'batch4YEAR1SEM' => 22, 'batch4YEAR2SEM' => 23 ), 'AR17A05' => array('batch1YEAR1SEM' => 25, 'batch1YEAR2SEM' => 25, 'batch2YEAR1SEM' => 23, 'batch2YEAR2SEM' => 25, 'batch3YEAR1SEM' => 23, 'batch3YEAR2SEM' => 24, 'batch4YEAR1SEM' => 22, 'batch4YEAR2SEM' => 23), 'AR17A04' => array('batch1YEAR1SEM' => 25, 'batch1YEAR2SEM' => 25, 'batch2YEAR1SEM' => 23, 'batch2YEAR2SEM' => 25, 'batch3YEAR1SEM' => 23, 'batch3YEAR2SEM' => 24, 'batch4YEAR1SEM' => 22, 'batch4YEAR2SEM' => 23), 'AR17A02' => array('batch1YEAR1SEM' => 25, 'batch1YEAR2SEM' => 25, 'batch2YEAR1SEM' => 23, 'batch2YEAR2SEM' => 23, 'batch3YEAR1SEM' => 25, 'batch3YEAR2SEM' => 24, 'batch4YEAR1SEM' => 22, 'batch4YEAR2SEM' => 23), 'AR17A03' => array('batch1YEAR1SEM' => 25, 'batch1YEAR2SEM' => 25, 'batch2YEAR1SEM' => 23, 'batch2YEAR2SEM' => 23, 'batch3YEAR1SEM' => 25, 'batch3YEAR2SEM' => 22, 'batch4YEAR1SEM' => 24, 'batch4YEAR2SEM' => 23), 'AR20all' => array ('batch1YEAR1SEM' => 19.5, 'batch1YEAR2SEM' => 19.5, 'batch2YEAR1SEM' => 21.5, 'batch2YEAR2SEM' => 21.5, 'batch3YEAR1SEM' => 21.5, 'batch3YEAR2SEM' => 21.5, 'batch4YEAR1SEM' => 23, 'batch4YEAR2SEM' => 12 ), 'AR17D04' => array ('batch1YEAR1SEM' => 20, 'batch1YEAR2SEM' => 20, 'batch2YEAR1SEM' => 20, 'batch2YEAR2SEM' => 20 ), 'AR17D43' => array ('batch1YEAR1SEM' => 20, 'batch1YEAR2SEM' => 20, 'batch2YEAR1SEM' => 20, 'batch2YEAR2SEM' => 20 ), 'AR17D55' => array ('batch1YEAR1SEM' => 20, 'batch1YEAR2SEM' => 20, 'batch2YEAR1SEM' => 20, 'batch2YEAR2SEM' => 20 ), 'AR17D58' => array ('batch1YEAR1SEM' => 20, 'batch1YEAR2SEM' => 20, 'batch2YEAR1SEM' => 20, 'batch2YEAR2SEM' => 20 ) );

$rollnum = $_GET["rollnum"];

$branchcode = $_GET["branchcode"];

$syear = $_GET["syear"];

$sdegree = $_GET["sdegree"];

$acyears = 4;

$sdegreename = "B.Tech";

if($sdegree == 'M.Tech'){

	$acyears = 2;

	$sdegreename = "M.Tech";

}

$sentry = $_GET["sentry"];

$regulation = $_GET["regulation"];	

if( $sentry == 'regularentry'){

	$batch = '20'. $syear. ' - ' . ($syear + $acyears);

	$sem = 'batch1YEAR1SEM';

	$semcount = 0;

	$semdata = "I Year I Sem";

} else{

	$batch = '20'. ($syear + 1). ' - ' . ($syear + $acyears);

	$sem = 'batch2YEAR1SEM';

	$semcount = 2;

	$semdata = "II Year I Sem";

}

$filename = $syear.$branchcode;

$totalcredits = 0;

include('student-name.php');

$file_to_read = fopen('results/'.$filename.'.csv', 'r');

$tabsdata = '';

$nodata = false;

$passstatus = "Pass";

if($file_to_read !== FALSE){

	$tabsdata .= '<div class="sem_tabs noprint"><a data-href="#'.$sem.'" class="tab active">'.$semdata.'</a>';

	$resultdata =  "<div id='".$sem."' class='".$sem." tabcont active'><div class='result_head'><h2>Raghu Engineering College (Autonomous)</h2><h4><span>".$branch[$branchcode]." </span><span>Batch: ".$batch."</span></h4><h4><span>".$sdegreename.' '.$semdata." Result</span><span>Reg. No. : ".$rollnum."</span></h4><h4><span>Name: ".$studentname."</span></h4></div><table><tr><td>Code</td><td>Subject</td><td>Grade</td><td>Credit</td><td>Examination</td><td>Result</td></tr>";

	while(($data = fgetcsv($file_to_read, 10000, ',')) !== FALSE){

		if (in_array($rollnum, $data)){

			//print_r($data);

			$nodata = true;

			$cursem = 'batch'.substr(str_replace(' ', '', $data[1]), 0, 9);

			if($regulation == 'AR20'){

				$sgpdp = $branchgradepoints['AR20all'][$sem];

			}else{

				$sgpdp = $branchgradepoints['AR17'.$branchcode][$sem];

			}

			if($sem != $cursem){ 

				$sgp = $totalcreditspoints / $sgpdp;

				$sgp = number_format((float)$sgp, 2, '.', '');

				$resultdata .=  "</table><h4><span>Total Credits: ".$totalcredits."</span> <span>Status: $passstatus</span> <span>SGPA: ".$sgp."</span></h4></div>\n<div id='".$cursem."' class='".$cursem." tabcont '><div class='result_head'><h2>Raghu Engineering College (Autonomous)</h2><h4><span>".$branch[$branchcode]." </span><span>Batch: ".$batch."</span></h4><h4><span>B.TECH ".$years[$cursem]." Result</span><span>Reg. No. : ".$rollnum."</span></h4><h4><span>Name: ".$studentname."</span></h4></div><table><tr><td>Code</td><td>Subject</td><td>Grade</td><td>Credit</td><td>Examination</td><td>Result</td></tr>"; 

				$tabsdata .= '<a data-href="#'.$cursem.'" class="tab">'.$years[$cursem].'</a>';

				$semcount++;

				$totalcredits = 0;

				$totalcreditspoints = 0;

				$passstatus = "Pass";

			}

			$month = substr($data[2], 4, 6);

			$year = substr($data[2], 0, 2);

			

			// if($data[5] ==  ){

				$totalcredits += $data[6];

				$totalcreditspoints += ($data[6] * $data[8]);

				$resultdata .= "<tr>";

				$resultdata .= "<td>".$data[4]."</td>";

				$resultdata .= "<td>".$data[5]."</td>";

				$resultdata .= "<td>".$data[7]."</td>";

				$resultdata .= "<td>".$data[6]."</td>"; 

				$resultdata .= "<td>".$data[2];

				if($sdegree){

					$resultdata .= ":";

				}

				$resultdata .= substr($data[1], 13, 16)."</td>"; 

				if($data[7] == "F"){

					$resultdata .= "<td>Fail</td>";

					$passstatus = "Fail";

				}else{

					$resultdata .= "<td>Pass</td>";

				}

				$resultdata .= "</tr>\n";

			// }

			$sem = 'batch'.substr(str_replace(' ', '', $data[1]), 0, 9);

		}

	}

	$sgp = $totalcreditspoints / $sgpdp;

	$sgp = number_format((float)$sgp, 2, '.', '');

	$resultdata .= "</table><h4><span>Total Credits: ".$totalcredits."</span> <span>Status: $passstatus</span> <span>SGPA: ".$sgp."</span></h4></div>\n";

	if($nodata == true){

		echo $tabsdata.'</div><div class="tabcont_sec">'.$resultdata.'</div>';

	}else{

		echo "<h4>No Result Found</h4>";

	}

	fclose($file_to_read);
}

?>