<?php
include "scrinit.php";
include "logo.php";
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Βαθμολόγιο Καθηγητή</title>

</script>
<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=800, top='+top+', left='+left);
}

function submitform()
{
    document.forms["bath"].submit();
}

function pop_up(url){
window.open(url,'win2','status=no,toolbar=no,scrollbars=yes,titlebar=no,menubar=no,resizable=yes,width=800,height=800,directories=no,location=no') 
}

</script>

<script type="text/javascript">
var prompt=true;

		$(document).ready(function() {

				$('input:not(:button,:submit),textarea,select').change(function () {
					window.onbeforeunload = function () {
						if (prompt == true) 
							return 'Δεν έχετε αποθηκεύσει τους βαθμούς που έχετε καταχωρίσει';
						}
					});


				$('input:submit').click(function(e) {
					prompt = false;
					});
	    });
		
</script>
<script language="javascript" type="text/javascript"> 
function windowClose() { 
window.open('','_parent',''); 
window.close();
} 
</script>

<style type="text/css">
input.right{  text-align:right;  }
table.myTable { border-collapse:collapse; }
table.myTable td, table.myTable th { border:1px solid black;padding:2px;font-size:10pt; }
</style>

</head>
  
<body>

<?php
require "dbconnect.php"; 
$dt=$_SESSION['dt'];

if (isset($_POST['submitb']))
{
$teacher=$_POST['pmp1'];
}
else
{
$teacher=$_SESSION['pmp'];
}
$tetramino=$_SESSION['tetramino'];
$less=$_POST['mathsubid'];

?>
<h3>ΣΥΝΟΠΤΙΚΟ ΒΑΘΜΟΛΟΓΙΟ ΜΑΘΗΜΑΤΟΣ:  <?php echo " ". $less; ?> </h3>
<?php
$arr = explode("/", $less);
$tmima = trim($arr[0]);
$subject = trim($arr[1]);

$result = mysqli_query($con,"SELECT * FROM aksiologiseis WHERE subject='$subject'  " ); 
$c = mysqli_num_rows($result);	

echo '<p style="color: blue; text-align: left; font-weight: bold;"> ΚΡΙΤΗΡΙΑ ΑΞΙΟΛΟΓΗΣΗΣ  </p>';
echo "<table class='myTable' >
<tr style='border:1px solid black' bgcolor='#d6ff73'  >
<th>ΤΥΠΟΣ ΑΞΙΟΛΟΓΗΣΗΣ</th>
<th>ΠΟΣΟΣΤΟ %</th>
</tr>";
$i=1;
while ($row=mysqli_fetch_array($result)) 
{
	$tp[$i]=$row['type'];
	$prc[$i]=$row['percent'];
	$prct[$tp[$i]]=$prc[$i];
	if ($prc[$i] > 0)
	{
    echo "<tr>";echo "<td>" .$tp[$i]."</td>";
    echo "<td>". $prc[$i]."</td>";
    $i++;
	}
}
echo "</tr>";
echo "</table>"; 
//echo "<br>"."<br>";

// number of students
$result = mysqli_query($con,"SELECT distinct s.mitroo,a.eponimo,a.onoma,a.tmima FROM syndcodes as c,syndidaskalies as s,allstudentinfo as a 
WHERE c.synd = '$tmima' AND c.syndid=s.syndid AND s.mitroo=a.mitroo ORDER BY a.eponimo,a.onoma");
$crow1=mysqli_num_rows($result);
if ($crow1 > 0)
{
	$cr=1;
	while($row=mysqli_fetch_array($result))
	{	
		$mt[$cr]=$row['mitroo'];
	    $epo[$cr]=$row['eponimo']." ".$row['onoma'];	
		$tmim[$cr]=$row['tmima'];
		$cr++;
	}
}
else
{	
$result = mysqli_query($con,"SELECT mitroo,eponimo,onoma FROM allstudentinfo WHERE tmima='$tmima' ORDER BY eponimo,onoma  ");
$crow1=mysqli_num_rows($result);
    $cr=1;
    while($row = mysqli_fetch_array($result))
     {
	 $mt[$cr]=$row['mitroo'];
	 $epo[$cr]=$row['eponimo']." ".$row['onoma'];
	 $tmim[$cr]=$tmima;
	 $cr++;
	 } 
}
$ns=$cr-1;	
//...................................................
$sql1=mysqli_query($con,"select *,COUNT(type) as cnt from aksinfo where pmpteacher='$teacher' 
      and tmima='$tmima' and subject='$subject' and tetramino='$tetramino' group by type order by type");
if (mysqli_num_rows($sql1)>0)
{
  $i=1;$type=$code=$percent=$maxmark=array();
  while ($row=mysqli_fetch_array($sql1))
  {
	$type[$i]=$row['type'];
	$cnt[$i]=$row['cnt'];
	$prct[$type[$i]]=$prct[$type[$i]]/$cnt[$i];
	$i++;
  }
  $k=$i-1;

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

$ntype=count($tp);
for ($i=1;$i<=$k;$i++)
{
  $sql=mysqli_query($con,"SELECT * FROM aksiologisi WHERE code='$code[$i]' ");
  $nsk=mysqli_num_rows($sql);
  if ($nsk > 0) 
  { 
	$l=1;
	
	while($row=mysqli_fetch_array($sql))
	{
	   $mit=$row['mitroo'];
	   $bathmos[$i][$mit]=$row['bathmos'];
	   $l++;
    }
  }
}
echo '<p style="color: blue; text-align: left; font-weight: bold;"> ΑΝΑΛΥΤΙΚΗ ΒΑΘΜΟΛΟΓΙΑ ΜΑΘΗΜΑΤΟΣ  </p>';
echo "<table class='myTable' >
<tr style='border:1px solid black' bgcolor='#d6ff73'  >
<th>No.</th>
<th>A/M</th>
<th>Τ/ΜΑ</th>
<th>ΜΑΘΗΤΗΣ/ΤΡΙΑ</th>";
// print titles
for ($i=1;$i<=$k;$i++)
{ 
  echo "<th>".$type[$i]."</th>";
  $percent[$i]=$prct[$type[$i]];
}
  echo "<th>ΟΛΙΚΟ</th> </tr>";
//..............................
echo "<tr>"; 
echo "<td colspan='4'>". " " . "</td>";
for ($i=1;$i<=$k;$i++)
{	
  echo "<td>"."<b>"."<p align=right>".number_format($percent[$i],2)."%"."</b>"."</td>";
  $totalp=$totalp+$percent[$i];  
}
  echo "<td>"."<b>"."<p align=right>".number_format($totalp,2)."%"."</b>"."</td>";
  echo "</tr>"; 
echo "<tr>"; 
echo "<td colspan='4'>"."<p align=right>"." Μέγιστη βαθμολογία:". "</td>";
for ($i=1;$i<=$k;$i++)
{
	  echo "<td>"."<p align=right>".$maxmark[$i]."--> 20". "</td>";
}
echo "<td>"."<p align=right>". '20' . "</td>";
echo "<tr>"; 	
for ($i=1;$i<=$ns;$i++)
{	
  echo "<tr>";
  echo "<td>". $i;
  echo "<td>". $mt[$i] . "</td>";
  echo "<td>". $tmim[$i] . "</td>";
  echo "<td>". $epo[$i] . "</td>";
  $tot=0;
  $tot1=$perc=$cnt=array(); 
  for ($j=1;$j<=$k;$j++)
  {
  	$b=$bathmos[$j][$mt[$i]];
	if ($b==-1) {$b=0;}
    
    if ($maxmark[$j]==0){$maxmark[$j]=20;}
	$b=(float)$b/($maxmark[$j]/20);
	echo "<td>"."<p align=right>". round($b)."</td>";
	$tot1[$type[$j]]=$tot1[$type[$j]]+$b;
	$perc[$type[$j]]=$perc[$type[$j]]+$prct[$type[$j]];
	$cnt[$type[$j]]=$cnt[$type[$j]]+1;
  }
  for ($m=1;$m<=$ntype;$m++)
  {
	  if ($cnt[$tp[$m]] > 0)
	  {
		$xx= $tot1[$tp[$m]]*((float)$perc[$tp[$m]]/($cnt[$tp[$m]]*100));
		$tot=$tot+$xx;
	  }
  }
  
  echo "<td>"."<p align=right>".round($tot)."</td>"."</tr>"; 
}
echo "</table>";
}


?>
<br><br>
<input type="button" value="ΚΛΕΙΣΙΜΟ ΠΑΡΑΘΥΡΟΥ ΚΑΙ ΕΠΙΣΤΡΟΦΗ" onclick="windowClose();">

</body>
</html>