<?php session_start();?>

<?php
	if($_SESSION ["role"]=="Evaluator")
	{
		$role = $_SESSION["role"];
		$email = $_SESSION["email"];
		// header('location:form.php');
	}
	else
	{
		header('location:index.php?expired session please login back');
		// $userName = $_SESSION["userName"]; $userRole = $_SESSION["userRole"];
		}
		
require ("../_common/global.php");
require ("../_common/conn.php");
//require ("_common/function.php");
require ("../_common/check_session.php");
?>
<?php

	$conn = mysql_connect('localhost', 'dvsvigov_vacc', 'DVSvacdos123');
	 if (!$conn)
    {
	 die('Could not connect: ' . mysql_error());
	}
	mysql_select_db("dvsvigov_vacdos", $conn);
$result = mysql_query("SELECT * FROM user WHERE email  = '$email'");
$test = mysql_fetch_array($result);
if (!$result)
		{
		die("Error: Data not found..");
		}
				$Assess=$test['name'] ;
				
							
mysql_close($conn);

?>
<?php
/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
$link = mysqli_connect("localhost", "dvsvigov_vacc", "DVSvacdos123", "dvsvigov_vacdos");
 
// Check connection
if($link === false){
    die("ERROR: Could not connect. " . mysqli_connect_error());
}
// Escape user inputs for security
// $fName = mysqli_real_escape_string($link, $_POST['fName']);


$idvac = mysqli_real_escape_string ($link, $_POST['idvac']);
$vacctype = mysqli_real_escape_string ($link, $_POST['vacctype']);
$Assess = mysqli_real_escape_string($link, $_POST['Assess']);
//$datesubmit = mysqli_real_escape_string($link, $_POST['datesubmit']);
$gencomm = mysqli_real_escape_string($link, $_POST['gencomm']);
$recomm = mysqli_real_escape_string($link, $_POST['recomm']);


// attempt insert query execution
$sql = "UPDATE dossierform SET gencomm = '$gencomm',recomm = '$recomm' WHERE idvac='$idvac' AND Assess='$Assess'";
	
mysqli_query($link, $sql);

//mysqli_query($link, $sql3);
//CALCULATION PART
$conn = mysql_connect('localhost', 'dvsvigov_vacc', 'DVSvacdos123');
	 if (!$conn)
    {
	 die('Could not connect: ' . mysql_error());
	}
	mysql_select_db("dvsvigov_vacdos", $conn);
$result = mysql_query("SELECT * FROM dossierform WHERE idvac='$idvac' AND Assess='$Assess'");
$test = mysql_fetch_array($result);
if (!$result)
		{
		die("Error: Data not found..");
		}
				$vacctype= mysql_real_escape_string($test['vacctype']) ;
				$Q1=$test['Q1'] ;
				$Q2=$test['Q2'] ;
				$Q3=$test['Q3'] ;
				$Q4=$test['Q4'] ;
				$Q5=$test['Q5'] ;
				$Q6=$test['Q6'] ;
				$Q7=$test['Q7'] ;
				$Q8=$test['Q8'] ;
				$Q9=$test['Q9'] ;
				$Q10=$test['Q10'] ;
				$Q11=$test['Q11'] ;
				$Q12=$test['Q12'] ;
				$Q13=$test['Q13'] ;
				$Q14=$test['Q14'] ;
				$Q15=$test['Q15'] ;
				$Q16=$test['Q16'] ;
				$Q17=$test['Q17'] ;
				$Q18=$test['Q18'] ;
				$Q19=$test['Q19'] ;
				$Q20=$test['Q20'] ;
				$Q21=$test['Q21'] ;
				$Q22=$test['Q22'] ;
				$Q23=$test['Q23'] ;
				$Q24=$test['Q24'] ;
				$Q25=$test['Q25'] ;
				$Q26=$test['Q26'] ;
				$Q27=$test['Q27'] ;
				$Q28=$test['Q28'] ;
				$Q29=$test['Q29'] ;
				$Q30=$test['Q30'] ;
				$Q31=$test['Q31'] ;
				$Q32=$test['Q32'] ;
				$Q33=$test['Q33'] ;
				$Q34=$test['Q34'] ;
				$Q35=$test['Q35'] ;
				$Q36=$test['Q36'] ;
				$Q37=$test['Q37'] ;
				$Q38=$test['Q38'] ;
				$Q39=$test['Q39'] ;
				$Q40=$test['Q40'] ;
				$Q41=$test['Q41'] ;
				
if ($vacctype=='Recombinant') {

//$campurA == $Q1a;
$campurA = ($Q1 + $Q2 + $Q3)/18*100;
$campurB = ($Q4 + $Q5 + $Q6)/18*100;
$campurC = ($Q7 + $Q8 + $Q9)/18*100;
$campurD = ($Q10)/6*100;
$campurE = ($Q11 + $Q12 + $Q13 + $Q14 + $Q15 + $Q16 + $Q17 + $Q18 + $Q19)/54*100;
$campurF = ($Q20 + $Q21 + $Q22 + $Q23 + $Q24 + $Q25 + $Q26 + $Q27)/48*100;
$campurG = ($Q28 + $Q29 + $Q30 + $Q31 + $Q32 + $Q33 + $Q34 + $Q35 + $Q36)/54*100;
$campurH = ($Q37 + $Q38 + $Q39 + $Q40 + $Q41)/30*100;
//$campurB = ($Q4 + $Q5 + $Q6)*100;
}

else if ($vacctype=='Killed'){
//$campurA == $Q1a;
$campurA = ($Q1 + $Q2 + $Q3)/18*100;
$campurB = ($Q4 + $Q5 + $Q6)/18*100;
$campurC = ($Q7 + $Q8 + $Q9)/18*100;
$campurD = ($Q10)/6*100;
$campurE = ($Q12 + $Q13 + $Q14 + $Q15 + $Q16 + $Q17 + $Q18 + $Q19)/48*100;
$campurF = ($Q20 + $Q21 + $Q22 + $Q23 + $Q24 + $Q25 + $Q26 + $Q27)/48*100;
$campurG = ($Q29 + $Q30 + $Q31 + $Q32 + $Q33 + $Q34 + $Q35)/42*100;
$campurH = ($Q37 + $Q38 + $Q39 + $Q40 + $Q41)/30*100;
//$campurB = ($Q4 + $Q5 + $Q6)*100;
}

else if ($vacctype=='Live'){
//$campurA == $Q1a;
$campurA = ($Q1 + $Q2 + $Q3)/18*100;
$campurB = ($Q4 + $Q5 + $Q6)/18*100;
$campurC = ($Q7 + $Q8 + $Q9)/18*100;
$campurD = ($Q10)/6*100;
$campurE = ($Q11 + $Q12 + $Q13 + $Q14 + $Q15 + $Q16 + $Q17 + $Q18 + $Q19)/54*100;
$campurF = ($Q20 + $Q22 + $Q23 + $Q25 + $Q26 + $Q27)/36*100;
$campurG = ($Q28 + $Q30 + $Q31 + $Q32 + $Q33 + $Q34 + $Q35 + $Q36)/48*100;
$campurH = ($Q37 + $Q38 + $Q39 + $Q40 + $Q41)/30*100;
//$campurB = ($Q4 + $Q5 + $Q6)*100;
}

$sql2= "UPDATE IGNORE dossierform SET sumA='$campurA', sumB='$campurB',sumC='$campurC',sumD='$campurD',sumE='$campurE',sumF='$campurF',sumG='$campurG',sumH='$campurH' WHERE idvac='$idvac' AND Assess='$Assess'";
mysqli_query($link, $sql2);
header('location: recommendation.php?idvac='.$idvac.'');
mysqli_close($link);
?>
