<?php
include "scrinit.php";
include "logo.php";
?>
<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 black;padding:2px;font-size:12px; }
.dw{
    width:80px;
    word-wrap:break-word;
 
}
.dw1{
    width:600px;
    word-wrap:break-word;
 
}
<p style="font-size:10px;"></p>
</style>

<h2>ΔΙΟΡΘΩΣΗ ΑΝΑΚΟΙΝΩΣΗΣ</h2>
<?php
require "dbconnect.php";
$usr=$_SESSION['usr'];

$sql = mysqli_query($con,"SELECT * FROM anakoinosi WHERE parents = 0 order by datein DESC  " );
$c=mysqli_num_rows($sql);

echo "<table  class='myTable' >
<tr style='border:1px solid black' bgcolor='#adcd82'  >
<th>Αρ.</th>
<th class='dw'>Αρχίζει</th>
<th class='dw'>Τελιώνει</th>
<th class='dw1'>Περιεχόμενο Ανακοίνωσης</th>
<th>Προς</th>
<th>Αρχείο</th>
<th>Διαγραφή</th>
</tr>";	
if ($c==0)
{ 
  echo "<tr>";
  echo " ΔΕΝ ΥΠΑΡΧΟΥΝ Ανακοινώσεις ";
  echo "</tr>";
}
else
{
	?><form  method="post" > <?php
   $row = mysqli_fetch_array($sql);
   while (!empty($row)) 
	{
		$code=$row['id'];
		$datein= $row['datein'];
		$dateout= $row['dateout'];
		$per=ltrim($row['keimeno']);
		$fname=$row['arxeio'];
		$teach=$row['teacher'];
		echo "<tr>";
		if ($teach==0) 
		{
			$pros="ΟΛΟΥΣ";
			$tc=$code;
			$row = mysqli_fetch_array($sql);
		}
		else
		{	
		   $pros="*";	
		   $ts=$code;
		   $i=1;
		   while ($per==ltrim($row['keimeno']) and  !empty($row))
		   {
		      $tc=$ts."/".$code;
			  $row = mysqli_fetch_array($sql);
			  $code=$row['id'];
			  $i++;
		   }
		}
		echo "<td>" . "<a href=\"editanakoinosi1.php?data=".$tc."\">"."<b>".$tc."</b>". "</a>". "</td>";
		echo "<td class='dw'>". $datein . "</td>";
		echo "<td class='dw'>". $dateout . "</td>";
		echo "<td class='dw1'>". $per. "</td>";
		echo "<td>". $pros . "</td>";
		echo "<td>". $fname. "</td>";
		?><TD><INPUT type="checkbox" name="check_list[]" value="<?php echo $tc ?>" /></TD><?php
	}
}
echo "</tr>"; 
echo "</table>";
?><h4> <b>*</b> Η ανακοίνωση απευθύνεται σε αριθμό εκπαιδευτικών (ΟΧΙ σε όλους) </h4>
<br>
<input type="submit"  name ="delanak" value="ΔΙΑΓΡΑΦΉ ΕΠΙΛΕΓΜΕΝΩΝ ΑΝΑΚΟΙΝΩΣΕΩΝ" >
<?php

if (isset($_POST['delanak']))
{
	$idel=$_POST['chk'];
	echo $idel;
	$aa=explode("/",$idel);
	$ds=$aa[0];
	$de=$aa[1];
	if(!empty($_POST['check_list'])) 
	{
    foreach($_POST['check_list'] as $d) 
	{
        
		mysqli_query($con, "delete from anakoinosi where id='$d'");
	}
	echo "<script>
     alert('Οι ανακοινώσεις έχουν διαγραφεί!');
     window.location.href='editanakoinosi.php';
     </script>";
	}
}
?>
<br><br>
<a  href=<?php echo $menu;?> style="color:blue" > <button style="color:blue"> Επιστροφή στο Μενού </button></a>
</body>
</html>