<?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:11px; }
<p style="font-size:09px;"></p>
</style>

<?php
require "dbconnect.php";

$usr=$_SESSION['usr'];

if (isset($_GET['pmp'])){$mitr=$_GET['pmp'];}

if (isset($_POST['nameid'])) {$mitr=$_POST['nameid'];}

$sql = mysqli_query($con,"SELECT eponimo,onoma,tmima FROM allstudentinfo WHERE mitroo='$mitr'  " );
$row = mysqli_fetch_array($sql);
$stname=$row['eponimo']." ".$row['onoma'];
$tmimaid=$row['tmima'];


$sql = $dbcon->prepare("SELECT Name  FROM teachers  WHERE  PMP=? " );
$sql->execute([$usr]);
$row=$sql->fetch(PDO::FETCH_ASSOC);
$vdname=$row['Name'];

$_SESSION['stname']=$stname;
$_SESSION['vdnamek']=$vdname;
$_SESSION['tmimaid']=$tmimaid;

$sql = mysqli_query($con,"SELECT * FROM kataggelia WHERE mitroo='$mitr'  " );
$c=mysqli_num_rows($sql);

if ($c == 0){ //..............................................
    echo " ΔΕΝ ΕΧΕΙ ΑΛΛΕΣ ΚΑΤΑΓΓΕΛΙΕΣ";}
else
{

echo " ΚΑΤΑΓΓΕΛΙΕΣ ΓΙΑ ". " "."<b>".$stname."</b>"." "." του τμήματος ".$tmimaid."<br>"."<br>";	
	
	
//******************************* pinakas me istoriko kataggelion gia ton mathiti
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>
</tr>";	
while ($row = mysqli_fetch_array($sql)) 
{
$aranaforas= $row['aranaforas'];	
$vdidk=   $row['bd'];
$kataggelon= $row['kataggelon'];
$datekata= $row['datekata'];
$perigrafi=$row['perigrafi'];
$arsimp = $row['arsimperiforas'];
$timcode=$row['timoriacode'];
$datetimo = $row['datetimo'];
$etimo = $row['eidostimo'];
$periodoi = $row['periodoi'];
$katastasi = $row['katastasi'];

$sql1=mysqli_query($con,"SELECT Name  FROM teachers  WHERE  PMP='$vdidk' " );
$row1 = mysqli_fetch_array($sql1);
$vdnamek = $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'];

echo "<tr>";
echo "<td>" . "<a href=\"paraptoma1.php?data=".$aranaforas."\">".$aranaforas. "</a>". "</td>";
echo "<td>". $datekata . "</td>";
echo "<td>". $perigrafi . "</td>";
echo "<td>". $teacher . "</td>";
echo "<td>". $vdnamek . "</td>";
echo "<td>". $periodoi ." "."περ.". "</td>";

if($etimo==0) echo "<td>". "ΜΕ ΑΝΑΣΤΟΛΗ" . "</td>"; 
if($etimo==1) echo "<td>". "ΚΑΤ΄ ΟΙΚΟΝ" . "</td>";
if($etimo==2) echo "<td>". "ΑΛΛΗ" . "</td>"; 
echo "</tr>"; 
} // END WHILE
$query = mysqli_query($con,"SELECT MAX(aranaforas) FROM kataggelia ");
$results = mysqli_fetch_array($query);
$aranaforas = $results['MAX(aranaforas)'] + 1;
$aranaf=$aranaforas;
$_SESSION['aranaf']=$aranaf;
echo "<tr>";
echo "</tr>"; 
echo "</table>";
echo "<br>"."<br>";	
$result = mysqli_query($con,"SELECT SUM(periodoi) AS per_sum FROM kataggelia WHERE mitroo='$mitr'  "); 
$row = mysqli_fetch_assoc($result); 
echo "ΣΥΝΟΛΟ ΑΠΟΒΟΛΩΝ: ".$row['per_sum'];
} //END ELSE
//****************************************************telos pinaka ***************

$query = mysqli_query($con,"SELECT MAX(aranaforas) FROM kataggelia ");
$results = mysqli_fetch_array($query);
$aranaforas = $results['MAX(aranaforas)'] + 1;
$_SESSION['aranaf']=$aranaforas;

$sqlvd=mysqli_query($con,"SELECT Class_id FROM voithos WHERE Class_id='$tmimaid' AND voi_id='$usr'");
$plithos = mysqli_num_rows($sqlvd);

if ($plithos > 0) // mathitis sto tmima tou voithou
{
   include "paraptoma1.php";}
else 
{ 
//include  "dispkataggeliakath.php";
	include "paraptoma1kath.php";
}


echo "<br>";
echo  "<a href=\"kataggelia.php?pmp=".$mitr."\"> <button> Επιστροφή". "</a>";
 ?>

</body>
</html>