<?php
include "scrinit.php";
date_default_timezone_set("Europe/Athens");
require "dbconnect.php";
$usr=$_SESSION['usr'];
$dt=$_SESSION['dt'];  
?><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
table.myTable { border-collapse:collapse; }
table.myTable th.ex1 {width: 20px; }
table.myTable th.ex3 {width: 40px; }
table.myTable th { border:1px solid black;padding:6px;font-size:12px; }
<p style="font-size:09px;"></p>
</style>
<body>

<?php
$date=$dt;
$day = date('D', strtotime($dt));
if ($day=="Mon")
    {
		$dbf = date( 'Y-m-d', strtotime( $dt . ' -3 day' ) );
    }
    else 
    { 
		$dbf = date( 'Y-m-d', strtotime( $dt . ' -1 day' ) );
	}
$q=$dbcon->prepare("SELECT * FROM anakoinosi 
WHERE (datein >=? or datein = ?) AND ((teacher=0 OR teacher=?) AND parents <> 1) ");
$q->execute([$dbf,$dt,$usr]);
$c=$q->rowCount();

$q1=$dbcon->prepare("SELECT * FROM anakoinosi 
WHERE (datein<=? and dateout >=?) AND ((teacher=0 OR teacher=?) AND parents <> 1) ");
$q1->execute([$dt,$dt,$usr]);
$c1=$q1->rowCount();
if ($c > 0 or $c1>0) {
echo "<b>"."ΑΝΑΚΟΙΝΩΣΕΙΣ"."</b>";
?>
<TABLE>
<TR>
<TD>
<div style="overflow:scroll; border:1px solid black;background:#F5F9F0;width:520px; height: 350px">
<?php
echo "<table style='width:500px' class='myTable' >
<tr style='border:1px solid black'  bgcolor='#FF0000'  padding='6px'>
<th style='color:white'>Αρ.</th>
<th style='color:white'> ΑΝΑΚΟΙΝΩΣΕΙΣ ΗΜΕΡΑΣ </th>
<th style='color:white'> ΑΡΧΕΙΟ </th>
</tr>";
$i=1;
while ($row = $q->fetch(PDO::FETCH_ASSOC))
{
	$keimeno=$row['keimeno'];
	$fname=trim($row['arxeio']);
	
    echo "<tr>";
    echo "<td>".$i."</td>";
    echo "<td>".$keimeno."</td>";
	echo "<td align='center'>";
	if (!empty($fname))
	{
	$arr=explode(".",$fname);
	$extns=$arr[1];
	switch ($extns)
	{
	case "pdf":
        $imgx="files/imgpdf.jpg";
        break;
	case "docx":
        $imgx="files/imgdocx.jpg";
        break;
	case "txt":
        $imgx="files/imgtxt.jpg";
        break;	
	}
	
	$lnk="files/".$fname;
	
	?>
	<a href="<?php echo $lnk;?>" target="_blank"><img src="<?php echo $imgx;?>" width="40" height="40" /></a>
	<?php
	}
	echo "</td>";
	echo "</tr>";
    $i++;
}
echo "</table>";
?>
</div>
</TD>
<td> </td>
<TD>
<div style="overflow:scroll; border:1px solid black;background:#F5F9F0;width:520px; height: 350px">
<?php
echo "<table style='width:500px' class='myTable' >
<tr style='border:1px solid black' bgcolor='#01DF74' padding='6px'>
<th class='ex1'>Αρ.</th>
<th> ΜΟΝΙΜΕΣ ΑΝΑΚΟΙΝΩΣΕΙΣ </th>
<th class='ex3'> ΑΡΧΕΙΟ </th>
</tr>";
$i=1;
while ($row1 = $q1->fetch(PDO::FETCH_ASSOC))
{
	$keimeno=$row1['keimeno'];
	$fname=trim($row1['arxeio']);
	
    echo "<tr>";
    echo "<td>".$i."</td>";
    echo "<td>".$keimeno."</td>";
	echo "<td align='center'>";
	if (!empty($fname))
	{
	$arr=explode(".",$fname);
	$extns=$arr[1];
	switch ($extns)
	{
	case "pdf":
        $imgx="files/imgpdf.jpg";
        break;
	case "docx":
        $imgx="files/imgdocx.jpg";
        break;
	case "txt":
        $imgx="files/imgtxt.jpg";
        break;	
	}
	
	$lnk="files/".$fname;
	
	?>
	<a href="<?php echo $lnk;?>" target="_blank"><img src="<?php echo $imgx;?>" width="40" height="40" /></a>
	<?php
	}
	echo "</td>";
	echo "</tr>";
    $i++;
	}
echo "</table>";
?>
</div>
</td>
</tr>
</table>
<?php
}
?>

</body>
</html>