<?php
include "scrinit.php";
include $menu;
?><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; }
<p style="font-size:10px;"></p>
</style>

<h2>ΚΑΤΑΓΓΕΛΙΕΣ</h2>
<?php
require "dbconnect.php";
$usr=$_SESSION['usr'];

$sql = mysqli_query($con,"SELECT tmima,bd FROM kataggelia   order by tmima" );
$row=mysqli_fetch_array($sql);
while (!empty($row))
{
	$tm=$row['tmima'];
	$bd=$row['bd'];
	mysqli_query($con,"update kataggelia set katastasi=2 where datetimo > 0");
	$sql1=mysqli_query($con, "select voi_id from voithos where Class_id='$tm'");
	$row1=mysqli_fetch_array($sql1);
	$vd=$row1['voi_id'];
	if ($bd <> $vd )
	{
		mysqli_query($con,"update kataggelia set bd='$vd' where tmima='$tm'");
	}
	
	$row=mysqli_fetch_array($sql);	
}

$sh[1]=" kataggelon='$usr' ";$sh[2]=" (bd='$usr' AND kataggelon <> '$usr') ";
$sm[1]="ΟΙ ΚΑΤΑΓΓΕΛΙΕΣ ΜΟΥ";$sm[2]="ΑΛΛΕΣ ΚΑΤΑΓΓΕΛΙΕΣ";
for ($jj=1;$jj<=2;$jj++)
{
$sql = mysqli_query($con,"SELECT * FROM kataggelia WHERE ".$sh[$jj]." order by katastasi DESC, datekata ASC" );
$c=mysqli_num_rows($sql);

echo $sm[$jj];
echo "<table class='myTable' >
<tr style='border:1px solid black;font-size:9px'  >
<tr>
<th>Αρ.</th>
<th>Ημερομ.</th>
<th>Μαθητής/τρια</th>
<th>Τμήμα</th>
<th>Περιγραφή Παραπτώματος</th>
<th>Ποινή</th>
<th>Ημερ. Ποινής</th>
<th>Είδος </th>
<th>Κατάστ.</th>
</tr>";	
if ($c==0){ 
  echo "<tr>";
  echo " ΔΕΝ ΥΠΑΡΧΟΥΝ ΚΑΤΑΓΓΕΛΙΕΣ ";
  echo "</tr>";}
else
{

while ($row = mysqli_fetch_array($sql)) {
	
$mitroo=$row['mitroo'];
$aranaforas= $row['aranaforas'];	
$vdid=$row['bd'];
$tmima=$row['tmima'];
$kataggelon= $row['kataggelon'];
$datekata= $row['datekata'];
$perigrafi=$row['perigrafi'];
$arsimp = $row['arsimperiforas'];
$datetimo = $row['datetimo'];
$etimo = $row['eidostimo'];
$periodoi = $row['periodoi'];
$katastasi = $row['katastasi'];
$timcode=$row['timoriacode'];

$sql5=mysqli_query($con,"SELECT onoma,eponimo  FROM allstudentinfo  WHERE  mitroo='$mitroo' " );
$row5 = mysqli_fetch_array($sql5);
$stname = $row5['eponimo']."  ".$row5['onoma'];

$sql1=mysqli_query($con,"SELECT Name  FROM teachers  WHERE  PMP='$vdid' " );
$row1 = mysqli_fetch_array($sql1);
$vname = $row1['Name'];

$sql2 = mysqli_query($con,"SELECT Name FROM teachers  WHERE  PMP='$kataggelon'" );
$row2 = mysqli_fetch_array($sql2);
$teacher = $row2['Name'];

$sql3 = mysqli_query($con,"SELECT perigrafi FROM eidostimorias  WHERE  code='$timcode'" );
$row3 = mysqli_fetch_array($sql3);
$eidostimo = $row3['perigrafi'];

$sql4 = mysqli_query($con,"SELECT perigrafi,metro FROM paraptoma  WHERE  code='$arsimp'" );
$row4 = mysqli_fetch_array($sql3);
$perpara = $row4['perigrafi'];
$metro = $row4['metro'];

echo "<tr>";
if ($vdid == $usr)
{
	echo "<td>" . "<a href=\"paraptoma2.php?data=".$aranaforas."\">"."<b>".$aranaforas."</b>". "</a>". "</td>";
}
else
{
	echo "<td>" . "<a href=\"paraptoma3.php?data=".$aranaforas."\">"."<b>".$aranaforas."</b>". "</a>". "</td>";	
}
echo "<td>". $datekata . "</td>";
echo "<td>". $stname . "</td>";
echo "<td>". $tmima . "</td>";
echo "<td>". $perigrafi . "</td>";
echo "<td>". $periodoi ." "."περ.". "</td>";
echo "<td>". $datetimo . "</td>";
if($etimo == 0 )
{
	if ($timcode > 0)
	{
		echo "<td>". "ΜΕ ΑΝΑΣΤΟΛΗ/ΑΛΛΗ" . "</td>"; 
	}
	else
	{
		echo "<td>". "" . "</td>"; 
	}
}
if($etimo == 1 ) echo "<td>". "ΚΑΤ΄ ΟΙΚΟΝ" . "</td>";
if($etimo == 2 ) echo "<td>". "ΑΠΟΒΟΛΗ" . "</td>"; 
$katastasi = $row['katastasi'];
if($katastasi<2)
{echo "<td>". "ΕΚΚΡΕΜΕΙ" . "</td>"; }
else
{echo "<td>". "ΟΛΟΚΛΗΡ." . "</td>";}
echo "</tr>"; 
}
}
$query = mysqli_query($con,"SELECT MAX(aranaforas) FROM kataggelia ");
$results = mysqli_fetch_array($query);
$aranaforas = $results['MAX(aranaforas)'] + 1;
echo "<tr>";
echo "<td>" . $aranaforas. "</td>";
echo "<td colspan= '8' >" . "<a href=\"epilogimathiti.php?data=".$aranaforas."\">"."<b>"."ΝΕΑ ΚΑΤΑΓΓΕΛΙΑ"."</b>". "</a>". "</td>";

echo "</tr>"; 
echo "</table>";
echo "<br>"."<br>";	
}
 ?>

<br /><br /><br /><br />

<a  href=<?php echo $menu;?> style="color:blue "  > <button> Επιστροφή στο Μενού   </a>
</body>
</html>