<?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>
<style type="text/css">
table.myTable { border-collapse:collapse; }
table.myTable td, table.myTable th { border:1px solid black;padding:5px;font-size:14px; }
table.myTable tr {border-width: 1px;padding: 5px;border-color: black;border-style: solid;background-color: #fffae6;	}
</style>

</head>

<body>

<?php
require "dbconnect.php";
require "functions1.php"; 
$dt=$_SESSION['dt'];
$name = $_SESSION['n'];
$usr=$_SESSION['usr'];

$res = isYT($usr);
$tmima=$res[0]; // $var1
$yt=$res[1]; // $var2
if ($yt === false)
{
	echo "<p class='p1'>". "ΔΕΝ ΕΧΕΤΕ ΥΠΕΥΘΥΝΟΤΗΤΑ ΤΜΗΜΑΤΟΣ". "</p>";
}
else
{
echo "<p class='p2'>". "ΚΩΔΙΚΟΙ ΤΕΑΜΣ ΚΑΙ ΑΝΑΓΚΕΣ ΓΙΑ ΤΟ ΤΜΗΜΑ: ".$tmima."</p>";
echo "<p class='p1'>". "Να σημειώνετε (τικάρετε) τους μαθητές που έχουν ανάγκη στο αντίστοιχο κουτάκι. Αν δεν υπάρχει ανάγκη πατήστε απλά καταχώρηση"."</p>";
echo "<table style='width:1200px' class='myTable'  >
<tr style='border:1px solid black' bgcolor='#d6ff73'  >
<th>α/α</th>
<th>Α.Μ</th>
<th>Όνοματεπώνυμο</th>
<th>Χρήστης TEAMS</th>
<th>Pswd TEAMS</th>
<th>Συσκευή για ΤΕΑΜS</th>
<th>Σύνδεση inet</th>
</tr>";
	$result = mysqli_query($con,"SELECT mitroo,eponimo,onoma FROM allstudentinfo WHERE tmima='$tmima' ORDER BY eponimo,onoma  ");
  
?>
<form  method='post' > 
<?php
  $cr=1;
  while($row = mysqli_fetch_array($result))
  {
	echo "<tr>";
	echo "<td>".$cr."</td>";
	$mt=$row['mitroo'];
	echo "<td>".$mt."</td>";
	echo "<input type='hidden' name='mt[]' value='".$mt."'>";
	$r = mysqli_query($con,"SELECT * FROM kodikoi WHERE mitroo='$mt'  ");
	$rr= mysqli_fetch_array($r,MYSQL_NUM);
	$epo=$row['eponimo']." ".$row['onoma'];
	echo "<td>".$epo."</td>";
	$user=$rr[1];
	echo "<td ALIGN=center>"."<input type='text' name='user[]' value='".$user."' >"."</td>";
	$pass=$rr[2];
	echo "<td ALIGN=center>"."<input type='text' name='pass[]' size='12'value='".$pass."' >"."</td>";
	$pc=$rr[3];
	if ($pc > 0) {$chpc="checked";} else {$chpc="";}
	echo "<td ALIGN=center>"."<input type='checkbox' name='pc[]' size='10' ".$chpc." value='".$mt."' >"."</td>";
	$net=$rr[4];
	if ($net> 0) {$chnet="checked";} else {$chnet="";}
	echo "<td ALIGN=center>"."<input type='checkbox' name='net[]' size='10' ".$chnet." value='".$mt."' >"."</td>";
	//$allo=$rr[5];
	//echo "<td>"."<input type='text' name='other[]' value='".$allo."' >"."</td>";
	echo "</tr>";
    $cr++;
  } 
echo "</table>";
?>
<br>
<input type="submit" name="anagkes" value="Καταχώρηση Αναγκών"/>
<br>
</form>
<?php
if(isset($_POST['anagkes']))
{
	$user=$_POST['user'];
	$pass=$_POST['pass'];
	$pc=$_POST['pc'];print_r($pc);
	$net=$_POST['net'];print_r($net);
	//$other=$_POST['other'];
	$mt=$_POST['mt'];
	$i=0;
	foreach ($mt as $mitroo)
	{
		if (in_array($mitroo,$pc)) $pcin=1; else $pcin=0;
		if (in_array($mitroo,$net)) $netin=1; else $netin=0;
		$r = mysqli_query($con,"SELECT * FROM kodikoi WHERE mitroo='$mitroo'  ");
		if(mysqli_num_rows($r) > 0)
		{
			mysqli_query($con,"update kodikoi set user='$user[$i]', pass='$pass[$i]',pc='$pcin',net='$netin'
			 where mitroo='$mitroo'");
		}
		else
		{
			mysqli_query($con,"insert into kodikoi (mitroo,user,pass,pc) values ('$mitroo','$user[$i]','$pass[$i]'
			'$pcin','$netin')");
		}
		$i++;
	}
	header("Location: anagkes.php"); 
}
}
?>
<br><br>
<a  href='<?php echo $menu;?>' ><button  type="button" class="sb1" >Επιστροφή</button> </a>
</body>
</html>