<?php
include "scrinit.php";
include "logo.php";
?>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js">
</script>
<script type="text/javascript">
function disx(b)
{
	document.getElementById(sms.b).disabled = true;
	alert(2);
	
}

function enx(x)
{
    document.getElementById(sms.x).disabled = false;
	alert(1);
}

function pop_up(url){
		window.open(url,'win2','toolbar=yes, scrollbars=yes, resizable=yes, top=100, left=200, width=600, height=800') 
	}
function rs(codex) 
	{
        window.open("rs.php?mathid="+codex, "_blank", "toolbar=yes, scrollbars=yes, resizable=yes, top=100, left=100, width=1000, height=800");
    }	
</script>
<style type="text/css">
input.right{  text-align:right;  }
table.myTable { border-collapse:collapse; }
table.myTable td, table.myTable th { border:1px solid black;padding:2px;font-size:10pt; }
</style>
</script>

</head>

<body>
<h3> ΕΛΕΓΧΟΣ ΔΙΑΓΝΩΣΕΩΝ RAPID TEST ΤΜΗΜΑΤΟΣ</h3>

<?php
require "dbconnect.php"; 
$dt=$_SESSION['dt'];

$usr=$_SESSION['usr'];
$yt=0;
$sql = mysqli_query($con,"SELECT * from voithos where yt='$usr'");
if (mysqli_num_rows($sql) > 0)
{
  $yt=1;
  $row=mysqli_fetch_array($sql);
  $tmima= $row['Class_id'];

echo '<p style="color: blue; text-align: left; font-weight: bold;"> ΚΑΤΑΣΤΑΣΗ ΔΙΑΓΝΩΣΕΩΝ ΤΜΗΜΑΤΟΣ  </p>';
echo "ΤΜΗΜΑ:".$tmima."<br>";
$path = 'uploadsr/'; // upload directory
echo "<table class='myTable' >
<tr style='border:1px solid black;font-size:9px' bgcolor='#d6ff73'   >
<th>Α/Α</th>
<th>ΜΗΤΡΩΟ </th>
<th>ΜΑΘΗΤΗΣ/ΤΡΙΑ </th>
<th>ΕΜΒΟΛΙΟ</th>
<th>ΝΟΣΗΣΗ</th>
<th>RAPID TEST</th>
<th>ΕΠΟΜΕΝΟ ΤΕΣΤ</th>
<th>Reset</th>

";	
?>
<form   method='post' >
<?php
$mred=$dcovid=$drapid=$mpoli=array();
$sqlt = mysqli_query($con,"SELECT mitroo,onoma,eponimo from allstudentinfo where tmima='$tmima' order by eponimo,onoma");
 
$j=0;
while($row=mysqli_fetch_array($sqlt))
{
	$j++;
	$m=$row['mitroo'];
	$st[$j]=$m;
	$stn[$j]=$row['eponimo']." ".$row['onoma'];
	
}
For ($i=1;$i <=$j;$i++)
{
	$x=trim($st[$i]);
	$sql = mysqli_query($con,"SELECT mpoli,covid,testdate from rapidimg where mitroo='$x' ");
	$row=mysqli_fetch_array($sql);
	$dcovid[$i]=$row['covid'];
    $drapid[$i]=$row['testdate'];
	$mpol[$i]=$row['mpoli'];
	$date = strtotime("+3 day", strtotime($drapid[$i]));
	$dat[$i]= date('d-m-Y', $date);
	
	echo "<tr>";
	echo "<td>" .$i. "</td>";
	echo "<td>" .$st[$i]. "</td>";
	echo "<td>".$stn[$i]."</td>";
	if($mpol[$i]==1)
	{
	   $chk[$i] = "checked"; 
	   
	}
	else
	{
		$chk[$i] = "";
		
    }
	

	echo "<td ALIGN=center>"."<input type='checkbox'  name='mpoli[]' value='$st[$i]'  {$chk[$i]} >"."</td>";
	$dd=date('Y-m-d', '0000-00-00');
	if ($mpol[$i]==1)
	{
		echo "<td>"." "."</td>";
		echo "<td>"." "."</td>";
		echo "<td>"." "."</td>";
		
		?><input type='hidden' name='drap[]' value='<?php echo $dd;?>' ><?php
		?><input type='hidden' name='dcov[]' value='<?php echo $dd;?>' ><?php
	}
	else
	{
		?><td><input type='date' name='dcov[]' value='<?php echo $dcovid[$i];?>' ></td> <?php
		if (strtotime($dcovid[$i]) > strtotime('0000-00-00'))
		{
			
			echo "<td>"." "."</td>";
			echo "<td>"." "."</td>";
			?><input type='hidden' name='drap[]' value='<?php echo $dd;?>' ><?php
		}
		else
		{
		if (strtotime($drapid[$i]) > strtotime('0000-00-00'))
		{	
		
			?><td><input type='date' name='drap[]' value='<?php echo $drapid[$i]; ?>' ></td> <?php
			
			if(strtotime($dt) >= strtotime($dat[$i]) )
			{
				?><td style='background-color: #FF0000;'><b><?php echo $dat[$i];?></b></td><?php
			}
			else
			{
				echo "<td>".$dat[$i]."</td>";
			}
		
		}
		else
		{
			
			if (strtotime("+3 day", strtotime($drapid[$i])) >= $dt)
			{
				
				?><td style='background-color: #FF0000;'><input type='date' name='drap[]' value='<?php echo $drapid[$i]; ?>' ></td> <?php
			}
			else
			{
				?><td><input type='date' name='drap[]' value='<?php echo $drapid[$i]; ?>' ></td> <?php
			}
			echo "<td>".""."</td>";	
		}
		}
	}
		echo '<td><center><img src="icons/rs.png" onclick="rs(\''.$st[$i].'\')" width="30" height="30" /></center></td>';
		echo "<input type='hidden' name='mit[]' value='$st[$i]'>";
		echo "<input type='hidden' name='nst' value='$j'>";
}

echo "</table>";
echo "<br>";
}

?>
<br>
<input type="submit" name="rapid" value="Καταχώρηση Επιλογών" >
</form>
<?php
if (isset($_POST['rapid']))
{
	$j=$_POST['nst'];
	$mit=$_POST['mit'];print_r($mit);
	$mpoli=$_POST['mpoli']; 
    $cov=$_POST['dcov'];print_r($cov);
	$rap=$_POST['drap'];print_r($rap);
  

	for ($i=0;$i<$j;$i++)
	{
		mysqli_query($con,"delete from rapidimg where mitroo='$mit[$i]'");
		$mp=0;
		if (in_array ($mit[$i],$mpoli)) 
		{
			$mp=1;
			$qi="insert into rapidimg (mitroo,mpoli) values ('$mit[$i]','$mp')";
			if (!mysqli_query($con, $qi)) 
			{
				echo "Error: " . $qi . "<br>" . mysqli_error($con);
			}
		}
		else
		{
			if (strtotime($cov[$i]) > strtotime('0000-00-00'))
			{
				$qi="insert into rapidimg (mitroo,mpoli,covid) values ('$mit[$i]','$mp','$cov[$i]')";
				if (!mysqli_query($con, $qi)) 
				{
					echo "Error: " . $qi . "<br>" . mysqli_error($con);
				}
			}
			else
			{
				if (strtotime($rap[$i]) > strtotime('0000-00-00'))
				{
				$qi="insert into rapidimg (mitroo,mpoli,testdate) values ('$mit[$i]','$mp','$rap[$i]')";
				if (!mysqli_query($con, $qi)) 
				{
					echo "Error: " . $qi . "<br>" . mysqli_error($con);
				}}
			}
		}
				
	}
	header("Location: rapidtmima.php");
	
}
?>
<a  href=<?php echo $menu;?> style="color:blue "  > <button> Επιστροφή στο Μενού   </a>

</body>
</html>