<?php 
include "scrinit.php";
require_once ("functions.php");
include $menu;
?>
<!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" />
<style type="text/css">
table.myTable { border-collapse:collapse; }
table.myTable td, table.myTable th { border:1px solid green;padding:2px;font-size:10pt; }
<p style="font-size:10px;"></p>
</style>

<?php 
require("dbconnect.php");
$usr=$_SESSION['usr'];
$access=$_SESSION['access'];
$dt=$_SESSION['dt'];
$dtx= date('d-m-Y', strtotime($dt));
$result = mysqli_query($con,"SELECT Name,kinito,PMP FROM teachers where kinito > ' ' order BY Name ");
$c=mysqli_num_rows($result);
echo $c;
$t=round($c/5,0)+2;

$res1 = mysqli_query($con,"SELECT * from rapidtest order by name");
$i=1;
$chk=$n=$dtc=array();
while ($row = mysqli_fetch_array($res1))
{
	$name=$row['name'];
	$n[$name]=$name;
	$dtc[$name]=$row['date'];
	$apo[$name]=$row['slip'];
	$r=$row['result'];
	if ($r==1) $chk[$name]=1;
	
}

?>
<form  method='post' >

<h4>ΕΠΕΛΕΞΕ ΟΣΟΥΣ/ΕΣ ΕΚΑΝΑΝ ΤΟ ΤΕΣΤ</h4>
<div style="overflow:scroll; border:1px solid black;background:#F5F9F0;width:720px; height: 600px">
<p>
ΗΜΕΡΟΜΗΝΙΑ ΤΕΣΤ: <input type='date' name='testd' required>
</p>
<?php

echo "<table style='width:700px' class='myTable' >
<tr style='border:1px solid black' bgcolor='#adcd82'  >

<th>Α/Α</th>
<th>ΟΝΟΜΑ</th>
<th>ΗΜΕΡΟΜΗΝΙΑ</th>
<th>ΤΕΣΤ NAI</th>
<th>ΤΕΣΤ OXI</th>
<th>ΑΠΟΔΕΙΞΗ</th>
</tr>";
$i=1;
while ($row = mysqli_fetch_array($result)) 
{ 
    $name=$row['Name'];
	$ch='';
	$datc='';
	echo "<tr>";
	echo "<td>".$i."</td>";
	echo "<td>".$name."</td>";
	if ($n[$name]==$name)
	{
		$datc=date('d-m-Y', strtotime($dtc[$name]));
		$ap=$apo[$name];
	
		if ($chk[$name]==1) 
		{
			$ch='checked';
		}
	}
	
	echo "<td>".$datc."</td>";
	echo "<td>"."<input type='checkbox' name='test[]' value='$name' {$ch}>"."</td>";
	echo "<td>"."<input type='checkbox' name='testno[]' value='$name' >"."</td>";
	echo "<td>".$ap."</td>";
	echo "</tr>";
    $i++;
}
echo "</table>";
?>
</div>
<br>
<input type="submit" name="subrapid" value="Καταχώρηση δεδομένων" >
</form>
<?php
if (isset($_POST['subrapid']))
{
	$test=$_POST['test'];
	$testno=$_POST['testno'];
	$td=$_POST['testd'];
	print_r($test);
	foreach ($test as $name)
	{
		$q=mysqli_query($con,"select * from rapidtest where name='$name'");
		$r=mysqli_num_rows($q);
		if ($r > 0)
		{
		mysqli_query($con,"update rapidtest set date='$td', result=1 where name='$name'");
		}
		else
		{
		mysqli_query($con,"insert into rapidtest (date,name,result) values ('$td','$name',1)");	
		}
	}
	foreach($testno as $name)
	{
	mysqli_query($con,"update rapidtest set date='000-00-00', result=NULL where name='$name'");	
	}
	header("Location:rapid1.php");
}

?>
<br /><br />
<a  href=<?php echo $menu;?> style="color:blue "  > <button> Επιστροφή στο Μενού  </a>
</body>
</html>