<?php
include "scrinit.php";
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";
$tetramino=$_SESSION['tetramino'];
$gym=$_SESSION['gym'];

if (isset($_POST['nameid'])) {$mitr=$_POST['nameid'];}
else if(isset($_GET['data'])) {$mitr=$_GET['data'];}
else {$mitr=$_SESSION['studentid'];}

$studentid=$_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>";
//....................................
include "pomada.php";
 
?>
<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=$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 ('$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>";
	
$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=".$mitr."\">"."<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=".$mitr."\">"."<b>"."Ανάλυση"."</b>". "</a>". "</td>";
     echo "</tr>";

echo "</table>";	
echo "<br><br>"
//***********************************************************************************
?>
<h4>ΑΝΑΦΟΡΑ ΒΑΘΜΟΛΟΓΙΑΣ - ΟΛΟΙ ΟΙ ΒΑΘΜΟΙ ΕΙΝΑΙ ΑΠΟ ΤΟ 20</h4>
<?php
$sql = mysqli_query($con,"SELECT DISTINCT(CONCAT(i.tmima,i.subject)) AS ts, i.tmima,i.subject,i.pmpteacher FROM aksiologisi as a,aksinfo as i 
WHERE a.mitroo='$mitr' and a.code=i.code and i.tetramino='$tetramino'  group by (ts) order by i.pmpteacher" );	   
$nc=mysqli_num_rows($sql);

$tmima=$subject=$teacher=array();
$i=1;
while($row = mysqli_fetch_array($sql)) 
{
  $tmima[$i]=$row['tmima'];
  $subject[$i]= trim($row['subject']);
  $teacher[$i]=$row['pmpteacher'];
  $i++;
} 
$prct=array();
for ($i=1;$i<=$nc;$i++)
{
  $result = mysqli_query($con,"SELECT * FROM aksiologiseis WHERE trim(subject)='$subject[$i]'  " ); 
  $c = mysqli_num_rows($result);	
  $k=1;
  while ($rowk=mysqli_fetch_array($result)) 
  {
	$tp[$k]=$rowk['type'];
	$prc[$k]=$rowk['percent'];
	$prct[$tp[$k]]=$prc[$k];
	$k++;
  }
  $sql1=mysqli_query($con,"select *,COUNT(type) as cnt from aksinfo where pmpteacher='$teacher[$i]' 
      and tmima='$tmima[$i]' and subject='$subject[$i]' and tetramino='$tetramino' group by type order by type");
  if (mysqli_num_rows($sql1)>0)
  {
     $l=1;$type=$code=$maxmark=array();
     while ($rowl=mysqli_fetch_array($sql1))
     {
	   $type[$l]=$rowl['type'];
	   $cnt[$l]=$rowl['cnt'];
	   $prct[$type[$l]]=$prct[$type[$l]]/$cnt[$l];
	   $l++;
     }

  $sql1=mysqli_query($con,"select * from aksinfo where pmpteacher='$teacher[$i]' 
      and tmima='$tmima[$i]' and subject='$subject[$i]' and tetramino='$tetramino' order by type");
  $z=1;$type=$code=$percent=$maxmark=array();
  while ($rowz=mysqli_fetch_array($sql1))
  {
	$type[$z]=$rowz['type'];
	$code[$z]=$rowz['code'];
	$maxmark[$z]=$rowz['maxmark'];
	$z++;
  }
  $m=$z-1;
$bathmos=array();

for ($n=1;$n<=$m;$n++)
{
  $sqln=mysqli_query($con,"SELECT * FROM aksiologisi WHERE code='$code[$n]' and mitroo='$mitr' ");
  $ns=mysqli_num_rows($sqln);
  if ($ns > 0) 
  { 
	$rown=mysqli_fetch_array($sqln);
	$bathmos[$n]=$rown['bathmos'];	
  }
}

echo "<table class='myTable' >
<tr style='border:1px solid black' bgcolor='#d6ff73'  >
<th>No.</th>
<th>ΤΜΗΜΑ</th>
<th>ΜΑΘΗΜΑ</th>
<th>ΔΙΔΑΣΚΩΝ</th>";
// print titles
for ($x=1;$x<=$m;$x++)
{ 
  echo "<th>".$type[$x]."</th>";
  $percent[$x]=$prct[$type[$x]];
}
  echo "<th>ΟΛΙΚΟ</th> </tr>";
//..............................
echo "<tr>"; 
echo "<td colspan='4'>". " " . "</td>";
$totalp=0;
for ($x=1;$x<=$m;$x++)
{	
  echo "<td>"."<b>"."<p align=right>".number_format($percent[$x],2)."%"."</b>"."</td>";
  $totalp=$totalp+$percent[$x];  
}
  echo "<td>"."<b>"."<p align=right>".number_format($totalp,2)."%"."</b>"."</td>";
  echo "</tr>"; 
  
  echo "<tr>";
  echo "<td>". $i;
  echo "<td>". $tmima[$i] . "</td>";
  echo "<td><FONT COLOR='RED'>".$subject[$i]."</FONT></td>";
  $sqlt=mysqli_query($con,"select Name from teachers where PMP='$teacher[$i]'");
  $rowt=mysqli_fetch_array($sqlt);$tname=$rowt['Name'];
  echo "<td>".$tname."</td>";
  $tot=0;
  for ($j=1;$j<=$m;$j++)
  {
	$bx=$bathmos[$j]*20/$maxmark[$j];  
    echo "<td>"."<p align=right>". number_format($bx,2)."</td>"; 
    $tot=$tot+$bx*$percent[$j]/100;
  }
  echo "<td>"."<p align=right>".number_format($tot,2)."</td>";echo "</tr>"; 

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

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