<?php
include "scrinit.php";
if ($_GET['xn']== 1) include "logo.php";
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
td.right1{text-align: right;}
input.right{  text-align:right;  }
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>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
$(function() {
 $("#tmimaid").bind("change", function() {
     $.ajax({
         url: "change.php",
         data: "tmimaid="+$("#tmimaid").val(),
         success: function(html) {
             $("#nameid").html(html);
         }
     });
 }); 
});

function popupCenter(pageURL, title, w, h) {
    var left = (screen.width / 2)  - (w / 2);
    var top  = (screen.height / 2) - (h / 2);
    var targetWin = window.open(pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=800, height=900, top='+top+', left='+left);
}
</script>
</head>
<body>
<h2> ΔΕΛΤΙΟ ΜΑΘΗΤΗ / ΤΡΙΑΣ</h2>
<?php
require "dbconnect.php";
$usr=$_SESSION['usr'];


if (isset($_POST['nameid'])) {$mitr=$_POST['nameid'];}
else if(isset($_GET['data'])) {$mitr=$_GET['data'];}
else {$mitr=$_SESSION['studentid'];}
  
echo "<table style='width:500px' class='myTable' >
<tr style='border:1px solid black' bgcolor=#81DAF5 >
<th>ΣΤΟΙΧΕΙΑ ΜΑΘΗΤΗ/ΜΑΘΗΤΡΙΑΣ</th>
<th>ΤΜΗΜΑ</th>
<th>ΒΟΗΘΟΣ ΔΙΕΥΘ.</th>
<th>ΥΠΕΥΘΥΝΟΣ ΚΑΘ.</th>
</tr>";

$sql = mysqli_query($con,"SELECT * FROM allstudentinfo WHERE mitroo='$mitr'  " );
$row = mysqli_fetch_array($sql);
$stname=$row['eponimo']." ".$row['onoma'];
$tmimaid=$row['tmima'];
 echo "<tr>";
 echo "<td>".$stname. "</td>";
 echo "<td>".$tmimaid. "</td>";
 $sql = mysqli_query($con,"SELECT v.voi_id,t.Name,v.yt FROM voithos as v,teachers as t WHERE v.Class_id='$tmimaid' AND v.voi_id=t.PMP  " );
 $row = mysqli_fetch_array($sql);
 $vdname=$row['Name'];
 $yt=$row['yt'];
 echo "<td>".$vdname. "</td>";
 $sql = mysqli_query($con,"SELECT Name FROM teachers WHERE PMP='$yt' " );
 $row = mysqli_fetch_array($sql);
 $ytname=$row['Name'];
 echo "<td>".$ytname. "</td>";
 echo "</tr>";
 echo "</table>";
 echo "<br>";
?>
<h4>ΑΝΑΦΟΡΑ ΠΑΡΑΒΙΑΣΗΣ ΠΕΙΘΑΡΧΙΚΟΥ ΚΩΔΙΚΑ</h4>
<?php

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

$sql1 = mysqli_query($con,"SELECT * FROM timoria  WHERE stu_id='$mitr'  " );
$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))
{
$anafora= $row['aranaforas'];	
$kataggelon= $row['kataggelon'];
$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 ('$mitr','$anafora', '$tmimaid', '$datetimo','$stname','$perigrafi','$apovd','$timo')";

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


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

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


$sql=mysqli_query($con,"SELECT anafora,perigrafi,apovd,timo,datetimo  FROM timoreport ORDER BY datetimo ASC" );

echo "<table style='width:1000px' class='myTable' >
<tr style='border:1px solid black' bgcolor='#d6ff73'  >
<th>Α/A</th>
<th>Αναφ.</th>
<th>Ημερομ.</th>
<th>Περιγραφή Παραπτώματος</th>
<th>Καταγγελία από:</th>
<th>Παιδ. Μέτρο</th>
</tr>";	


$sum1=0;
$i=1;

while ($row=mysqli_fetch_array($sql))
{
$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>" .$anafora."</td>";}
echo "<td>". $datetimo . "</td>";
echo "<td>". $perigrafi . "</td>";
echo "<td>". $apovd . "</td>";
echo "<td>". $timo ." "."περ.". "</td>";
echo "</tr>"; 

$i++;

}

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

}
echo "</table>";


//.................................................................
?>
<h4>ΑΝΑΦΟΡΑ ΑΠΟΥΣΙΩΝ  ΚΑΙ ΚΑΘΥΣΤΕΡΗΣΕΩΝ</h4>
<?php
echo "<font face='arial' size='4pt' color='#ff0000'>Για τις χαρακτηρισμένες απουσίες, στο μενού ΑΠΟΥΣΙΕΣ </font> "; 
$sql = mysqli_query($con,"SELECT dateout, period FROM apousies WHERE mitroo='$mitr' AND apousia=1  ORDER BY dateout,period " );

$sqlk= mysqli_query($con,"SELECT dateout, period FROM apousies WHERE mitroo='$mitr' AND apousia=0 AND kath > 0  ORDER BY dateout,period " );	

echo "<table style='width:700px' class='myTable' >
<tr style='border:1px solid black' bgcolor='#d6ff73'  >
<th></th>
<th>Περ1</th>
<th>Περ2</th>
<th>Περ3</th>
<th>Περ4</th>
<th>Περ5</th>
<th>Περ6</th>
<th>Περ7</th>
<th>ΣΥΝΟΛΟ</th>
<th>ΑΝΑΛΥΣΗ</th>
</tr>";
$xx=$mitr."/"."1";	
$sum=0;
for($j=1;$j<=7;$j++){$per1[$j]=0;}

echo "<tr>";echo "<td>". "ΑΠΟΥΣΙΕΣ " . "</td>"; 
while($row = mysqli_fetch_array($sql)) 
{
	  $per1[$row['period']]++;$sum++;
}

     $i=1;    
     while($i<=7){ echo "<td>". $per1[$i] . "</td>";$i++;}
		  
	 echo "<td>". $sum . "</td>";
	 echo "<td>" .  "<a href=\"analapousia.php?data=".$xx."\">"."<b>".Ανάλυση."</b>". "</a>". "</td>";
     echo "</tr>";
//..........................
$sum=0;
for($j=1;$j<=7;$j++){$per1[$j]=0;}
echo "<tr>";echo "<td>". "ΚΑΘΥΣΤΕΡΗΣΕΙΣ " . "</td>";
while($rowk = mysqli_fetch_array($sqlk)) 
{
	  $per1[$rowk['period']]++;$sum++;
}

     $i=1;    
     while($i<=7){ echo "<td>". $per1[$i] . "</td>";$i++;}
		  
	 echo "<td>". $sum . "</td>";
	 echo "<td>" .  "<a href=\"analkath.php?data=".$xx."\">"."<b>"."Ανάλυση"."</b>". "</a>". "</td>";
     echo "</tr>";

echo "</table>";	


 ?>

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