<?php
session_start();
$menu=$_SESSION['menu'];
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>

<h4>ΑΝΑΦΟΡΑ ΠΑΡΑΠΤΩΜΑΤΩΝ/ΤΙΜΩΡΙΩΝ</h4>
<?php
require "dbconnect.php";
$usr=$_SESSION['usr'];

$sql = mysqli_query($con,"SELECT kataggelia.*,allstudentinfo.onoma,allstudentinfo.eponimo,allstudentinfo.tmima FROM kataggelia,allstudentinfo WHERE bd='$usr' AND kataggelia.mitroo=allstudentinfo.mitroo  " );
$c=mysqli_num_rows($sql);

$sql1 = mysqli_query($con,"SELECT timoria.*,allstudentinfo.onoma,allstudentinfo.eponimo,allstudentinfo.tmima  FROM timoria,allstudentinfo  WHERE timoria.stu_id=allstudentinfo.mitroo AND vd='$usr' " );
$c1=mysqli_num_rows($sql1);

if ($c =0 AND $c1==0){ 
      echo " ΔΕΝ ΥΠΑΡΧΟΥΝ ΠΕΙΘΑΡΧΙΚΑ";}
else
{
	mysqli_query($con,'TRUNCATE TABLE timoreport;'); 
	
while ($row=mysqli_fetch_array($sql)){
$mitroo=$row['mitroo'];
$tmima=$row['tmima'];
$student=$row['eponimo']." ".$row['onoma'];
$anafora= $row['aranaforas'];	
$kataggelon= $row['kataggelon'];
$perigrafi=$row['perigrafi'];
$datetimo = $row['datetimo'];
$timo = $row['periodoi'];
$sql3 = mysqli_query($con,"SELECT Name FROM teachers  WHERE  PMP='$kataggelon'" );
$row3 = mysqli_fetch_array($sql3);
$apovd = $row3['Name'];

$sqlin = "INSERT INTO timoreport (mitroo,anafora, tmima, datetimo,student,perigrafi, apovd,timo)
VALUES ('$mitroo','$anafora', '$tmima', '$datetimo','$student','$perigrafi','$apovd','$timo')";

    if (!mysqli_query($con, $sqlin)) {
       echo "Error: " . $sqlin . "<br>" . mysqli_error($con);}
}


while ($row=mysqli_fetch_array($sql1)){
	$tmima=$row['tmima'];
	$mitroo=$row['stu_id'];
	$student=$row['eponimo']." ".$row['onoma'];
	$datetimo=$row['dateappl'];
	$anafora=" ";
	$apovd=" ";
	$timo=$row['peramount'];
	$perigrafi="Συχνή καθυστέρηση και παρενόχληση μαθήματος";
	$sqlin = "INSERT INTO timoreport (mitroo,anafora, tmima, datetimo,student,perigrafi,apovd,timo)
VALUES ('$mitroo','$anafora', '$tmima', '$datetimo','$student','$perigrafi','$apovd','$timo')";

    if (!mysqli_query($con, $sqlin)) {
       echo "Error: " . $sqlin . "<br>" . mysqli_error($con);}
}

$sql=mysqli_query($con,"SELECT *  FROM timoreport ORDER BY tmima,mitroo,datetimo " );
echo "<table class='myTable' >
<tr style='border:1px solid black;font-size:9px'  >
<tr>
<th>Α/A</th>
<th>Αρ.</th>
<th>Τμήμα</th>
<th>Ημερομ.</th>
<th>Μαθητής/τρια</th>
<th>Περιγραφή Παραπτώματος</th>
<th>Καταγγελία από:</th>
<th>Ποινή</th>
</tr>";	

$row = mysqli_fetch_array($sql);
while (!empty($row)){
$sum1=0;
$i=1;
$mitroo=$row['mitroo'];
while ($mitroo==$row['mitroo']) {
$tmima=$row['tmima'];
$student=$row['student'];
$anafora= $row['anafora'];	
$apovd= $row['apovd'];
$perigrafi=$row['perigrafi'];
$datetimo = $row['datetimo'];
$timo = $row['timo'];
$sum1=$sum1+$timo;

echo "<tr>";
echo "<td>" .$i. "</td>";
if ($anafora == 0) {echo "<td>" . " ". "</td>"; } else {
echo "<td>" . "<a href=\"paraptoma2.php?data=".$anafora."\">"."<b>".$anafora."</b>". "</a>". "</td>";}
echo "<td>". $tmima . "</td>";
echo "<td>". $datetimo . "</td>";
echo "<td>". $student . "</td>";
echo "<td>". $perigrafi . "</td>";
echo "<td>". $apovd . "</td>";
echo "<td>". $timo ." "."περ.". "</td>";

echo "</tr>"; 
$mitroo1=$mitroo;
$i++;
$row = mysqli_fetch_array($sql);
}

echo "<tr>";
echo "<td colspan='7'>" .'ΣΥΝΟΛΟ ΑΠΟΒΟΛΩΝ ΜΑΘΗΤΗ/ΤΡΙΑΣ'. "</td>";
echo "<td>". $sum1 ." "."περ.". "</td>";
echo "</tr>"; 
$sum1=0;
$i=1;
}
echo "</table>";
//............
echo "<br>";

//echo "ΣΥΝΟΛΟ ΑΠΟΒΟΛΩΝ: ".$sum;


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