<?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:14px; }
<p style="font-size:14px;"></p>
</style>
</head>
<body>
<h3> ΔΕΛΤΙΟ ΚΑΤΑΓΓΕΛΙΩΝ ΚΑΙ ΠΟΙΝΩΝ ΜΑΘΗΤΗ / ΤΡΙΑΣ</h3>
<?php
require "dbconnect.php";
$tetramino=$_SESSION['tetramino'];
$gym=$_SESSION['gym'];

if(isset($_POST['submit1']))
{  

$mitroo=$_POST['nameid'];

echo "<table style='width:500px' class='myTable' >
<tr style='border:1px solid black' bgcolor=#F5F9F0 >
<th>ΜΑΘΗΤΗΣ/ΜΑΘΗΤΡΙΑ</th>
<th>ΤΜΗΜΑ</th>
<th>ΜΗΤΡΩΟ</th>
</tr>";

$sql = mysqli_query($con,"SELECT * FROM allstudentinfo WHERE mitroo='$mitroo'  " );
$row = mysqli_fetch_array($sql);
$stname=$row['eponimo']." ".$row['onoma'];
$tmimaid=$row['tmima'];
echo "<tr>";
echo "<td>".$stname. "</td>";
echo "<td>".$tmimaid. "</td>";
echo "<td>".$mitroo. "</td>"; 
 echo "</tr>";
 echo "</table>";
 echo "<br>";


$sql = mysqli_query($con,"SELECT k.*,a.onoma,a.eponimo,a.tmima FROM kataggelia as k,allstudentinfo as a WHERE  k.mitroo=a.mitroo and k.mitroo='$mitroo' " );
$c=mysqli_num_rows($sql);

$sql1 = mysqli_query($con,"SELECT t.*,a.onoma,a.eponimo,a.tmima  FROM timoria as t,allstudentinfo as a  WHERE t.stu_id=a.mitroo and t.stu_id='$mitroo'  " );
$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'];
if(is_null($datetimo))$datetimo='0000-00-00';
$timo = $row['periodoi'];
$eidosx=$row['eidostimo'];echo "xxxxx".$eidosx; 
if (empty($eidosx) or is_null($eidosx)) $eidos=0;
$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,eidostimo)
VALUES ('$mitroo','$anafora', '$tmima', '$datetimo','$student','$perigrafi','$apovd','$timo','$eidos')";

    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=0;
	$apovd=" ";
	$timo=$row['peramount'];
	$eidosx=$row['eidostimo'];
	if (empty($eidosx) or is_null($eidosx)) $eidos=0;
	$perigrafi="Συχνή καθυστέρηση και παρενόχληση μαθήματος";
	$sqlin = "INSERT INTO timoreport (mitroo,anafora, tmima, datetimo,student,perigrafi,apovd,timo,eidostimo)
VALUES ('$mitroo','$anafora', '$tmima', '$datetimo','$student','$perigrafi','$apovd','$timo','$eidos')";

    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:14px' bgcolor='#ffcc00'  >
<th>Α/A</th>
<th>Αρ.</th>
<th>Ημερομ.</th>
<th style='width: 700px' >Περιγραφή Παραπτώματος</th>
<th>Καταγγελία από:</th>
<th>ΑΝΣΤΛΗ</th>
<th>ΑΛΛΗ</th>
<th>ΣΠΙΤΙ</th>
<th>ΑΠΒΛΗ</th>
</tr>";	

$row = mysqli_fetch_array($sql);
while (!empty($row)){
$sum1=0;$sumk=0;$suma=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'];
$eidos=$row['eidostimo'];

echo "<tr>";
echo "<td>" .$i. "</td>";
if ($anafora == 0) 
{
	echo "<td>" . " ". "</td>"; 
} 
else
{
	echo "<td>".$anafora."</td>";	
}
echo "<td>". $datetimo . "</td>";
echo "<td style='width: 700px' >". $perigrafi . "</td>";
echo "<td>". $apovd . "</td>";

if ($eidos==0 and $timo==0)
{
	echo "<td>". " ". "</td>";
	echo "<td>". "x" ."</td>";
	echo "<td>". " ". "</td>";
	echo "<td>". " ". "</td>";
}
elseif ($eidos==0 and $timo>0)
{
	echo "<td>". $timo. "</td>";
	echo "<td>". " ". "</td>";
	echo "<td>". " ". "</td>";
	echo "<td>". " ". "</td>";
	$sum1=$sum1+$timo;
}
elseif ($eidos==1)
{
	echo "<td>". " ". "</td>";
	echo "<td>". " ". "</td>";
	echo "<td>". $timo ."</td>";
	echo "<td>". " ". "</td>";
	$sumk=$sumk+$timo;
}
else
{
	echo "<td>". " ". "</td>";
	echo "<td>". " ". "</td>";
	echo "<td>". " ". "</td>";
	echo "<td>". $timo ."</td>";
	$suma=$suma+$timo;	
}
echo "</tr>"; 
$mitroo1=$mitroo;
$i++;
$row = mysqli_fetch_array($sql);
}

echo "<tr>";
echo "<td colspan='5' align='right'><font color='#0000FF'>" .'ΣΥΝΟΛΟ ΑΠΟΒΟΛΩΝ ΜΑΘΗΤΗ/ΤΡΙΑΣ'. "</font></td>";
echo "<td><font color='#0000FF'>"."<b>".$sum1."</b>"."</font></td>";
echo "<td><font color='#0000FF'>"."<b>"." "."</b>"."</font></td>";
echo "<td><font color='#0000FF'>"."<b>". $sumk ."</b>"."</font></td>";
echo "<td><font color='#0000FF'>"."<b>".$suma."</b>"."</font></td>";
echo "</tr>"; 
//$sum1=0;
//$sumk=0;
//$i=1;
}
echo "</table>";
//............
echo "<br>";



}
}
 ?>
<br /><br /><br />
<a  href=<?php echo $menu;?> style="color:blue "  > <button>Επιστροφή στο Μενού</button></a> 
<button onClick="window.print()">	Εκτύπωση Σελίδας</button>
</body>
</html>