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

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="style1.css" rel="stylesheet" type="text/css" />
<title>Βαθμολόγιο Καθηγητή</title>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $(".floatNumberField").change(function() {
            $(this).val(parseFloat($(this).val()).toFixed(2));
        });
    });

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>

<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:1px;font-size:12pt; }
.fieldset
{
    width:900px;
	background: #F5F9F0;
	border:2px solid green;
    -moz-border-radius:4px;
    -webkit-border-radius:4px;	
    border-radius:4px;	
}
</style>

</head>
  
<body>
<p class='p1'>ΣΥΝΟΛΙΚΗ ΒΑΘΜΟΛΟΓΙΑ ΜΑΘΗΜΑΤΟΣ</p>
<?php
require "dbconnect.php"; 
$dt=$_SESSION['dt'];
$mit=array();
////
echo "<table class='myTable' >
<tr style='border:1px solid black' bgcolor='#d6ff73'  >
<th>α/α</th>
<th>Α.Μ</th>
<th>Τμήμα</th>
<th>Μάθημα</th>
<th>Όνοματεπώνυμο</th>
<th>Α προφ</th>
<th>Α εξετ</th>
<th>Β προφ</th>
<th>Β εξετ</th>
<th>Τελικός</th>";
////

$q1=mysqli_query($con,"SELECT b.*,p.* FROM bathmosexet as b,bathmoposo as p where b.code=p.id order by b.mitroo,p.mathima,p.tmima,p.tetramino");
$row = mysqli_fetch_array($q1);

while(!empty($row))
{
	$pexet=40;
	$pta=60;
	$ptb=60;
	$mitroo=$row['mitroo'];
	$gra=$row['bexet'];
	$st=mysqli_query($con,"select * from stasimoi where mitroo='$mitroo'");
	if (mysqli_num_rows($st) == 1 or $gra==0)
	{
		$row = mysqli_fetch_array($q1);
	}
	else
	{
		
	$result = mysqli_query($con,"SELECT eponimo,onoma,tmima,omp FROM allstudentinfo WHERE mitroo='$mitroo' ");
	$rw = mysqli_fetch_array($result);
	$epo=$rw['eponimo']." ".$rw['onoma'];
	$tmima=$rw['tmima'];
	$omp=trim($rw['omp']);
	$mathima=$row['mathima'];
	$codea=$row['code'];
	
	$q3=mysqli_query($con,"select * from kodikoimathimatos where kodikos='$mathima'");
	$row3=mysqli_fetch_array($q3);
	$cl=mb_substr($tmima,0,1,'UTF-8'); 
	$ekset=$row3['ekset'];
	$p1=$row3['pgrapto'];
	$p2=$row3['pproforiko'];
	include "pososta.php";
	$q5=mysqli_query($con,"SELECT bgrapto,bproforiko FROM bathmostetr WHERE code='$codea' and mitroo='$mitroo'");
	$rw5=mysqli_fetch_array($q5);
	$grat=$rw5['bgrapto'];
	$prat=$rw5['bproforiko'];

	$ba=round($grat*$p1/100+$prat*$p2/100);
	$t1=round($ba*$pta/100+$gra*$pexet/100);
	
	$row=mysqli_fetch_array($q1);
	$codeb=$row['code'];
	$grb=$row['bexet'];
	$q5=mysqli_query($con,"SELECT bgrapto,bproforiko FROM bathmostetr WHERE code='$codeb' and mitroo='$mitroo'");
	$rw5=mysqli_fetch_array($q5);
	$grbt=$rw5['bgrapto'];
	$prbt=$rw5['bproforiko'];
	
	
	$bb=round($grbt*$p1/100+$prbt*$p2/100);
	$t2=round($bb*$ptb/100+$grb*$pexet/100);
	
    $telikos=round(($t1+$t2)/2);
	
	if ($telikos < 10)
	{
		$i++;
		$mit[$mitroo]=$mit[$mitroo]+1;
		echo "<tr>";
		echo "<td>" .$i;
		echo "<td>". $mitroo. "</td>";
	    echo "<td>". $tmima . "</td>";
	    echo "<td>". $mathima . "</td>";
	   	echo "<td>". $epo. "</td>";
	    echo "<td>". $ba . "</td>";
	    echo "<td>". $gra . "</td>";
	    echo "<td>". $bb . "</td>";
	    echo "<td>". $grb . "</td>";
	    echo "<td style='text-align:right'><b>".$telikos."</b></td>";
		echo "</tr>";
	}
    $row = mysqli_fetch_array($q1); 
	}

}

echo "</table>";
echo "<br>"."ΣΤΑΣΙΜΟΙ";
echo "<table>";
foreach ($mit as $m => $c)
{
	if ($c>=3)
	{
	    $result = mysqli_query($con,"SELECT eponimo,onoma,tmima,omp FROM allstudentinfo WHERE mitroo='$m' ");
	    $rw = mysqli_fetch_array($result);
	    $epo=$rw['eponimo']." ".$rw['onoma'];
	    $tmima=$rw['tmima'];
	    echo "<tr>";
	    echo "<td>". $tmima . "</td>";
	    echo "<td>". $epo. "</td>";
	    echo "</tr>";
	}
}
echo "</table>";
//print_r($mit);
?>
<br ><br ><br >
<a  href=<?php echo $menu;?>  style="color:blue "  > <button> Επιστροφή στο Μενού  </a>
</body>
</html>
