<?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'];
$teacher=$_SESSION['usr'];
$tetramino=$_SESSION['tetramino'];
//////////////// get data //////////////

$less=$_GET['mathid'];
$arr = explode("/", $less);
$tmima=$arr[0];
$mathima=trim($arr[1]);
if (mb_substr($mathima,0,5,'UTF-8')=='Γυμν-') $mathima='Γυμν';
$ml=$tmima."/".$mathima;

$q=mysqli_query($con,"select * from bathmoiab where tetramino='$tetramino' and mathima='$ml'");
if (mysqli_num_rows($q) > 0)
{
	while ($row=mysqli_fetch_array($q))
	{
		$m=$row['mitroo'];
		if ($tetramino=='Α') 
		{
			$gr[$m]=$row['ba'];
		}
		else
		{
			$gr[$m]=$row['bb'];
		}

	}
}


?>
<fieldset class="fieldset" >
<legend style="color: red; font-size: 14pt;"><?php echo $ml;?></legend>
<pre><b>ΚΑΤΑΧΩΡΙΖΟΥΜΕ ΒΑΘΜΟ ΓΙΑ ΤΗΝ ΑΞΙΟΛΟΓΗΣΗ ΤΕΤΡΑΜΗΝΟΥ ΣΕ ΜΗ ΕΞΕΤΑΖΟΜΕΝΟ ΜΑΘΗΜΑ</b></pre>
</fieldset>
<br>
<form method="post" > 
<?php
$result = mysqli_query($con,"SELECT DISTINCT s.mitroo,a.eponimo,a.onoma,a.tmima 
FROM syndidaskalies as s,allstudentinfo as a, syndcodes as sc 
WHERE sc.synd = '$tmima' AND s.mitroo=a.mitroo AND sc.syndid=s.syndid ORDER BY a.eponimo,a.onoma");
$crow1=mysqli_num_rows($result);

if ($crow1 > 0)
{
	$cr=0;
	while($row=mysqli_fetch_array($result))
	{	
		$cr++;
		$mt[$cr]=$row['mitroo'];
	    $epo[$cr]=$row['eponimo']." ".$row['onoma'];	
		$tmim[$cr]=$row['tmima'];
	}
}
else
{	
$result = mysqli_query($con,"SELECT mitroo,eponimo,onoma,omp FROM allstudentinfo WHERE tmima='$tmima' ORDER BY eponimo,onoma  ");
$crow1=mysqli_num_rows($result);
    $cr=0;
    while($row = mysqli_fetch_array($result))
     {
	 $cr++;
	 $mt[$cr]=$row['mitroo'];
	 $epo[$cr]=$row['eponimo']." ".$row['onoma'];
	 $tmim[$cr]=$tmima;
	 } 
}
// number of students
$ns=$cr;	

$i=0;

echo "<table class='myTable' >
<tr style='border:1px solid black' bgcolor='#d6ff73'  >
<th>α/α</th>
<th>Α.Μ</th>
<th>Τμήμα</th>
<th>Όνοματεπώνυμο</th>
<th>Βαθμός</th>
</tr>";
$i=1;
while($i <=$ns){
  echo "<tr>";
  echo "<td>" .$i;
  echo "<td>". $mt[$i] . "</td>";
  $m=$mt[$i];
  echo "<td>". $tmim[$i] . "</td>";
  echo "<td>". $epo[$i] . "</td>";
  echo "<td >". "<input type='number' class='right' name='gr[$m]' value='$gr[$m]' min=0 max=20 step=1>" ."</td>";
  echo "</tr>";
  $i++;
}
echo "</table>";


echo "<br>";

echo "<input type='hidden' name='code' value='$ml' >";
echo "<input type='hidden' name='ar' value='$ns' >";

?>
<input type="Submit" name="bathmos" value="Καταχώρηση Βαθμολογίας" class="sb">
<!--&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button style="color:blue " onclick="window.open('bathgram.php?code=<?php echo $code;?>','','width=600,height=500')">Εκτύπωση κατάστασης για Γραμματεία</button>-->
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" name="epistrofi" value="Επιστροφή" onClick="self.close()"> 
</form>
<?php
if (isset($_POST['bathmos']))
{
	$teacher=$_SESSION['usr'];
	$tetramino=$_SESSION['tetramino'];
	$mathima=$_POST['code'];
	$gr=$_POST['gr']; 
	$ns=$_POST['ar'];
print_r($gr);
	$sql=mysqli_query($con,"delete from bathmoiab where mathima='$mathima'");
	foreach($gr as $mitroo=>$bg) 
	{
			if ($bg > 0)
			{
				if ($tetramino=='Α')
				{
					$sql="insert into bathmoiab (mathima,mitroo,ba,tetramino) values ('$mathima','$mitroo','$bg','$tetramino')";
				}
				else
				{
					$sql="insert into bathmoiab (mathima,mitroo,bb,tetramino) values ('$mathima','$mitroo','$bg','$tetramino')";
				}
						
				if (!mysqli_query($con, $sql)) 
				{
					echo "Error: " . $sql . "<br>" . mysqli_error($con);
				}
			}
		
	}
header("Location:bathola3.php?mathid=".$less);
}


?>
</body>
</html>
