<?php
session_start();
ob_start();
if ($_SESSION['islogin']=='' ) { 
  echo "ΠΡΕΠΕΙ ΝΑ ΕΓΓΡΑΦΕΙΤΕ ΓΙΑ ΝΑ ΧΡΗΣΙΜΟΠΟΙΗΣΕΤΕ ΤΟ ΣΥΣΤΗΜΑ"."<BR>";
  sleep(3);
  header("Location: loginall.php"); /* Redirect browser */
  exit();
  }
$menu = $_SESSION['menu'];
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 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'];
$tetramino=$_SESSION['semester'];
$dt=$_SESSION['dt'];
if ($dt > '2020-01-10 11:59:00') { 
?>
<h4> ΤΟ ΣΥΣΤΗΜΑ ΒΑΘΜΟΛΟΓΙΩΝ ΘΑ ΕΠΑΝΕΛΘΕΙ ΜΕΤΑ ΤΗΝ ΕΠΙΔΟΣΗ ΤΩΝ ΔΕΛΤΙΩΝ ΠΡΟΟΔΟΥ</h4>
<?php

//header ("Location: indexstudent.php");

} 
else
{
//echo $tetramino;
if (isset($_POST['nameid'])) {$mitr=$_POST['nameid'];}
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>ΑΝΑΦΟΡΑ ΒΑΘΜΟΛΟΓΙΑΣ - ΟΛΟΙ ΟΙ ΒΑΘΜΟΙ ΕΙΝΑΙ ΑΠΟ ΤΟ 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);
echo $n;

$i=1;
while($row = mysqli_fetch_array($sql)) 
{
  $tmima[$i]=$row['tmima'];
  $subject[$i]= $row['subject'];
  $teacher[$i]=$row['pmpteacher'];
  $i++;
} 
$prct=array();
for ($i=1;$i<=$nc;$i++)
{
  $result = mysqli_query($con,"SELECT * FROM aksiologiseis WHERE 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>