<?php
include "scrinit.php";
include $menu;
?>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="style1.css" rel="stylesheet" type="text/css" />

<script type="text/javascript" src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript">

$(function() {
 $("#mathsubid").bind("change", function() {
     $.ajax({
         url: "change1.php",
         data: "mathsubid="+$("#mathsubid").val(),
         success: function(html) {
             $("#codeid").html(html);
         }
     });
 }); 
});

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

</head>

<body>

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

include "selectmath.php";
echo "<p class='p1'>". "ΚΑΤΑΧΩΡΗΣΗ/ΔΙΟΡΘΩΣΗ ΚΩΔΙΚΟΥ ΤΕΑΜΣ ΓΙΑ ΜΑΘΗΜΑΤΑ". "</p>";

$cd=array();
foreach ($mathsubj as $m)
{
	$cd[$m]='';
}
$c=count($mathsubj);
$sqlx=mysqli_query($con,"select * from teams where pmp='$usr' ");
if (mysqli_num_rows($sqlx)>0)
{
  while($row=mysqli_fetch_array($sqlx))
		{
			$cd[$row['mathima']]=$row['code'];
		}
}

	?>
	<form  method='post' >
	<?php
	echo "<p class='p1'>". "ΚΑΤΑΧΩΡΙΣΜΕΝΟΙ ΚΩΔΙΚΟΙ". "</p>";
    echo "<table class='myTable3' id='tablex' >
	<tr> 
	<th>α/α</th>
	<th>Τμήμα/Συνδιδ</th>
	<th>Κωδικός</th>
	</tr>";
	$i=1;
	foreach ($mathsubj as $m)
	{
			echo "<tr>";
			echo "<td>". $i."</td>";
			echo "<td>". $m."</td>";
			echo "<td>". "<input type='text' name='code[".$m."]' value=".$cd[$m].">"."</td>";
			echo "</tr>";
			$i++;
	}
	?>
	</table>
	<br><br>
	<input type="submit" name="submitb" value="Καταχώρηση Κωδικών" >
    </form>	
	<?php
if(isset($_POST['submitb']))
{
	$kod=$_POST['code'];
	print_r($kod);
	mysqli_query($con, "delete from teams where pmp='$usr'");
	foreach($kod as $math => $kodx)
	{
		mysqli_query($con,"insert into teams (pmp,mathima,code) values ('$usr','$math','$kodx')");
	}
  header("Location: teamscode.php");
}

?>
<br /><br />

<a  href=<?php echo $menu;?> style="color:blue "  > <button> Επιστροφή στο Μενού   </a> 
</body>
</html>