<?php
date_default_timezone_set("Europe/Athens");

?><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="style1.css" rel="stylesheet" type="text/css" />
<style type="text/css">
table.myTable { border-collapse:collapse; }
table.myTable td, table.myTable th { border:1px solid black;padding:2px;font-size:11px; }
<p style="font-size:09px;"></p>
</style>
<?php

echo "<p class='p1'>"."ΚΑΤΑΓΡΑΦΗ ΔΕΙΧΤΩΝ/ΥΛΗΣ"."</p> ";

$sql1 = mysqli_query($con,"SELECT PMP,Name FROM teachers WHERE idikotita='$eidikotita' order by access,Name" );	
$i=0;
while ($row1 = mysqli_fetch_array($sql1)) 
{
   	$i++;
	$did[$i]=$row1['PMP'];
	$didn[$i]=$row1['Name'];
}
$cc=$i;
//select mathimata
$l=1;
for ($k=1;$k<=$cc;$k++)
{
	$sql2 = $dbcon->prepare("SELECT * FROM timetable where pmp=?");
	$sql2->execute([$did[$k]]);
	$row2=$sql2->fetch(PDO::FETCH_ASSOC);
	$idx=$row2['id']+1;
	$sql3 = $dbcon->prepare("SELECT * FROM timetable where id=?");
	$sql3->execute([$idx]);
	$row3=$sql3->fetch(PDO::FETCH_ASSOC);

	$x2=array_slice($row3, 3);
	$x1=array_slice($row2, 3);
	$subj=array_filter($x2,"filter");
	$tmim=array_filter($x1,"filter");
	//print_r($tmim);
	$p=0;
	foreach ($tmim as $t)
	{
		$cl=mb_substr($t, 0, 1, 'utf-8');
		$p++;
		$tm[$p]=$cl;
		
	}
	$p=0;
	foreach ($subj as $s)
	{
		$ar=explode('/',$s);
		$p++;
		$sbj[$p]=trim($ar[1]);
		$meach[$did[$k]][$p]=$tm[$p]." Λυκείου/".$sbj[$p];
		$mathsubj[$l]=$tm[$p]." Λυκείου/".$sbj[$p];
		$l++;
	}	
}
	$ms=array_unique($mathsubj);
	sort($ms);
	$ll=count($ms);
	$ylix=array();

// read old sintonismos
for($i=1;$i<=$cc;$i++)
{
	for($j=0;$j<$ll;$j++)
	{
		$ylix[$did[$i]][$ms[$j]]="";
	}
}

$sqls = mysqli_query($con,"SELECT * FROM sintdeiktes WHERE sintcode='$code' order by pmp,subj" );
$cs=mysqli_num_rows($sqls);
$d=$subs=array();
if ($cs>0)
{
	while($rows = mysqli_fetch_array($sqls))
	{
		$ylix[$rows['pmp']][$rows['subj']]=$rows['deiktes'];
	}
}
/////////////////

echo "<table class='myTable3' >
<tr style='border:1px solid black;font-size:12px'  >
<tr>
<th>A/A</th>
<th>ΔΙΔΑΣΚΩΝ</th>";
for ($i=0;$i<$ll;$i++)
{
	$titm=$ms[$i];
	echo "<th>".$titm."</th>";
}
echo "</tr>";
for ($k=1;$k<=$cc;$k++)
{
	echo "<tr>";
	echo "<td>".$k."</td>";
	echo "<td>".$didn[$k]."</td>";
	
	for ($i=0;$i<$ll;$i++)
	{
		
		if (in_array(trim($ms[$i]),$meach[$did[$k]]))
		{
			?><td><textarea rows="2" cols="30" name='<?php echo "yli[$did[$k]][$ms[$i]]";?>' > <?php echo $ylix[$did[$k]][$ms[$i]];?> </textarea></td><?php
		}
		else
		{
				echo "<td>"."========"."</td>";
		}
		
		
		
	}
	echo "</tr>";
	
}
echo "</table>";
?>
<br /><br /> 

<?php
function filter($elmnt) 
{
    if ($elmnt != "null" && $elmnt != "" && $elmnt!='---' ) {
        return $elmnt;
    }
}
?>
</body>
</html>