<?php
session_start();
include "logo.php";
date_default_timezone_set("Europe/Athens");
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

</head>

<body>
<?php 
require("dbconnect.php");
$mitroo=$_SESSION['mitroo']; 
$usr=$_SESSION['pmp'];
$tetramino=$_SESSION['tetramino'];
if (isset($_POST['Submitddk'])) 
{
    $dt = $_SESSION['dt'];
	$dt= date('Y-m-d', strtotime($dt));
	$dt = mysqli_real_escape_string($con, $dt);
	$bathmos =$_POST['bathm'];
	
	$i=1;
	foreach( $bathmos  as $value ) {
		    $key="f".$i; 
            $fields[$i] = "`$key`";
            $values[$i] = $value;
			$i++;
    }
    
	$fields = implode(",", $fields);
    $values = implode(",", $bathmos);
	
	$result = mysqli_query($con,"SELECT * FROM ddkstu WHERE mitroo='$mitroo'");
	$c=mysqli_num_rows($result);
	
	if ($c == 0) 
	 {
	   $sql= "INSERT INTO ddkstu (mitroo,$fields) VALUES ('$mitroo',$values)" ;   
	   if (!mysqli_query($con,$sql)){die('Error: ' . mysqli_error($con));}    
	 }  
     else
	 {
		
       $sql= "DELETE FROM ddkstu WHERE mitroo='$mitroo'" ;
	   if (!mysqli_query($con,$sql)){die('Error: ' . mysqli_error($con));    } 
	   $sql= "INSERT INTO ddkstu (mitroo,$fields) VALUES ('$mitroo',$values)" ;  
	   if (!mysqli_query($con,$sql)){die('Error: ' . mysqli_error($con));    }
	 }
}
// ............ display the total marks
$result = mysqli_query($con,"SELECT * FROM ddkstu WHERE mitroo='$mitroo'");
$row=mysqli_fetch_array($result); 
$n=mysqli_num_fields($result)-1;
$sum=0;
for ($i=1;$i<=$n;$i++)
	{	
	    $field="f".$i;
		$sum=$sum+$row["$field"];
	}
echo "<br>";echo "<br>";
echo " ΣΥΝΟΛΟ ΒΑΘΜΟΛΟΓΙΑΣ ΔΔΚ = ".$sum;
?> 



</body>
</html>