<?php
include "scrinit.php";
include "logo.php";
?>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js">
</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>
</script>

</head>

<body>

<?php
require "dbconnect.php";
$dt=$_SESSION['dt'];
$usr=$_SESSION['usr'];
$gym=$_SESSION['gym'];
$tmima=$_GET['tmima'];
$tetramino=$_SESSION['tetramino'];
$p1=40;$p2=60;
$result = mysqli_query($con,"SELECT mitroo,eponimo,onoma FROM allstudentinfo WHERE tmima='$tmima' ORDER BY eponimo,onoma  ");
$cr=0;$m=1;$i=0;
while($row = mysqli_fetch_array($result))
{
	$cr++;
	$mt[$cr]=$row['mitroo'];
	$epo[$cr]=$row['eponimo']." ".$row['onoma'];
	$result1 = mysqli_query($con,"SELECT  * FROM bathmostetr where mitroo='$mt[$cr]' ");
	//$i=0;
	while ($row1=mysqli_fetch_array($result1))
	{
		//$i++;
		$code=$row1['code'];
		$result2 = mysqli_query($con,"select * FROM bathmoposo  where id='$code' and tetramino='$tetramino' ");	
		$row2=mysqli_fetch_array($result2);
		$math=$row2['mathima'];	
		$q=mysqli_query($con,"select mathima from kodikoimathimatos where kodikos='$math' ");
		$rowq=mysqli_fetch_array($q);
		$matx=$rowq['mathima'];
		$mat[$matx]=$matx;
		$bg[$mt[$cr]][$matx]=$row1['bgrapto'];
		$bp[$mt[$cr]][$matx]=$row1['bproforiko'];
		
		//$t=$bg[$i]*$p1/100+$bp[$i]*$p2/100;
		//$tel[$mt[$cr]][$i]=round($t);
	}
}
/*
$n=1;	
foreach($bg as $array){    
    foreach($array as $key=>$value)
	{
        $ar[$n]=$key;
		$n++;
    }
}
*/
print_r($mat);
$m=count($mat);

echo "<table class='myTable' >
<tr style='border:1px solid black' bgcolor='#d6ff73'  >
<th>Α/Α</th>
<th>Μητρώο</th>
<th>Όνομα Μαθητή/τριας</th>";
$k=1;
foreach ($mat as $math)
{	
	/*$result2 = mysqli_query($con,"select * FROM bathmoposo  
	where id='$ar1[$k]' ");	
	$row2=mysqli_fetch_array($result2);
	$math=$row2['mathima'];
	$q=mysqli_query($con,"select mathima from kodikoimathimatos where kodikos='$math'");
	$rowq=mysqli_fetch_array($q);
	$mathima=$rowq['mathima'];
	echo "<th colspan='3'>".$mathima."</th>";
	*/
	echo "<th colspan='3'>".$math."</th>";
	$ar1[$k]=$math;
	echo "<th></th>";
	$k++;
}  
echo "<tr>"; 
for ($j=1;$j<=$cr;$j++) 
{
	echo "<tr>";
	echo "<td align='center'>".$j."</td>";
	echo "<td align='center'>".$mt[$j]."</td>";
	echo "<td align='left'>".$epo[$j]."</td>";
	for ($k=1;$k<=$m;$k++)
	{	
	   echo "<td align='right'>".$bg[$mt[$j]][$ar1[$k]]."</td>";
	   echo "<td align='right'>".$bp[$mt[$j]][$ar1[$k]]."</td>";
	   $t=$bg[$mt[$j]][$ar1[$k]]*$p1/100+$bp[$mt[$j]][$ar1[$k]]*$p2/100;
	   $tel=round($t);
	   echo "<td align='right'><b>".$tel."</b></td>";
	   echo "<td></td>"; 
	}
	
	echo "</tr>";
}    

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

<input type="button" name="epistrofi" value="Επιστροφή" onClick="self.close()"> 
</body>
</html>