<?php
//////// ensomatosi anapliroseon
$sql=$dbcon->prepare("SELECT * FROM anaplirosi where date=? order by tid,period");
$sql->execute([$dt]);
$n=$sql->rowCount();
if ($n > 0)
{
$row=$sql->fetch(PDO::FETCH_ASSOC);

while (!empty($row))
{
	$tmima=array();
	$tid=$row['tid'];
	$aponid=$row['aponid'];
	$pmpapon=$row['pmpapon'];
	$per=$row['period'];
	$k=1;
	if(mb_substr($tid,-1)=='+')
	{
		while($tid==$row['tid'] and $per==$row['period'] )
		{
				$tidx=trim($tid,mb_substr($tid, -1));
				$ar = explode("[",$row['mathima']);
				$tmima[$k]=$ar[0];
				$k++;
				$room=$row['room'];
				$row=$sql->fetch(PDO::FETCH_ASSOC);
		}
		if(!empty($tprog[$tidx][$per]) or $tprog[$tidx][$per] <> " ")
		{
			$tmima[$k]=$tprog[$tidx][$per];
		}
		$mix=trim(implode("@",$tmima));
		$mix=rtrim($mix,"@");
		$tprog[$tidx][$per]=trim($mix);
		$tidx2=$tidx+1;
		$aponid2=$aponid+1;
		$ar = explode("/",$tprog[$aponid2][$per]);
		$tprog[$aponid][$per]="";
		$tprog[$tidx2][$per]=$room."/"."ΕΠΙΒΛΕΨΗ";	
		include "createsynd.php";
	}
	else
	{
	if ($tid <> "!")
	{
		$ar = explode("[",$row['mathima']);
		$tprog[$tid][$row['period']]=$ar[0];	
		$room=$row['room'];
		$tid=$tid+1;
		$aponid=$aponid+1;
		$ar = explode("/",$tprog[$aponid][$row['period']]);
		$tprog[$aponid][$row['period']]="";
		if ($room <> 0 or $room <>""){$rm=$room;} else {$rm=$ar[0];}
		$tprog[$tid][$row['period']]=$rm."/"."ΑΝΑΠΛΗΡΩΣΗ";	
	}
	$row=$sql->fetch(PDO::FETCH_ASSOC);
	}
}
}