<?php
include "scrinit.php";
include "logo.php";
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
$(function() {
 $("#tmimaid").bind("change", function() {
     $.ajax({
         url: "change.php",
         data: "tmimaid="+$("#tmimaid").val(),
         success: function(html) {
             $("#nameid").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:2px;font-size:12pt; }
<p style="font-size:14px;"></p>
</style>
</head>
<body>
<h3> COVID 19</h3>
  
<?php
require "dbconnect.php";
$dt=$_SESSION['dt'];
$gym=$_SESSION['gym'];
$usr=$_SESSION['usr'];
$dd=date('D', strtotime($dt));

$sql2 = mysqli_query($con,"SELECT DISTINCT tmima FROM allstudentinfo ORDER BY tmima ");
?>
<form method='post'> 

<h4> ΕΠΙΛΟΓΗ  ΜΑΘΗΤΗ/ΤΡΙΑΣ</h4>

    <label>Τμήμα:</label><select name='tmimaid' id='tmimaid'>
     
      <?php
	echo "<option value='---'>select</option>";
    while($row2 = mysqli_fetch_array($sql2) ) {
          echo "<option value='$row2[tmima]'>$row2[tmima]</option>";
      }
      ?>
     </select>
  

<label> Μαθητής/τρια:</label>

      <select name='nameid' id='nameid' value= ></select>

<input type="submit" name="submit1" value="Επιβεβαίωση Επιλογής" >
</form>

<?php 
if (isset($_POST['submit1']))
{
	$mitroo=$_POST['nameid'];
	$dd=date('D', strtotime($dt));
$tm=array();
$dayf=array(" ","Mon","Tue","Wed","Thu","Fri");
$res1=mysqli_query($con,"SELECT * FROM stutimetable WHERE mitroo='$mitroo' ");
$rows1 = mysqli_fetch_array($res1); 
$ind=1;	
for ($x=1;$x<=5;$x++)
{
	for ($per=1;$per<=$gym;$per++)
	{
			$day1=$dayf[$x].$per;
			$math= $rows1["$day1"];
			$tm[$ind]= $math;
			$ind++;
	}
}

$tm1 = array_unique($tm);
print_r($tm1);
$i=0;
foreach ($tm1 as $tmx)
{
	
	$sq=mysqli_query($con,"SELECT mitroo,eponimo,onoma FROM allstudentinfo where tmima='$tmx'");
	$cc=mysqli_num_rows($sq);
	if ($cc == 0)
	{
		$sq=mysqli_query($con,"SELECT a.mitroo,a.eponimo,a.onoma FROM allstudentinfo as a, syndidaskalies as s, syndcodes as sc 
		where sc.synd='$tmx' and sc.syndid=s.syndid and s.mitroo=a.mitroo");
		
	}
	while($row=mysqli_fetch_array($sq))
	{
		$i++;
		$mit[$i]=$row[mitroo];
	}
}
$mitr=array_unique($mit);
print_r($mitr);
$cc=0;
foreach ($mitr as $m)
{
    $sql = mysqli_query($con,"SELECT eponimo,onoma,tmima,kinito FROM allstudentinfo  WHERE mitroo='$m' order by tmima");
    $row=mysqli_fetch_array($sql);
	$cc++;
	$mt[$cc]=$m;
	$tmima[$cc]=$row['tmima'];
	$name[$cc]=$row['eponimo']." ".$row['onoma'];
	$kinito[$cc]=trim($row['kinito']);
}
$i=$cc;echo $i;
?>	
<h3> ΑΠΟΣΤΟΛΗ ΜΗΝΥΜΑΤΩΝ</h3>
<form method="POST"  >
<?php

echo "<BR>"."<b>"."ΚΑΤΑΛΟΓΟΣ ΜΑΘΗΤΩΝ/ΤΡΙΩΝ "."</b>";
echo "<table class='myTable' >
<tr style='border:1px solid black' bgcolor='#d6ff73'  >
<th>Α/Α</th>
<th>Α.Μητρ</th>
<th>Τμήμα</th>
<th>Όνομα</th>
<th>Κιν. Κηδεμόνα</th>
</tr>";

for ($cc=1;$cc<=$i;$cc++)
{

	echo "<td>". $cc . "</td>";
	echo "<td>". $mt[$cc]."</td>";
	echo "<td>". $tmima[$cc]."</td>";
	echo "<td>". $name[$cc]."</td>";
	$kin[$cc]=$kinito[$cc];
	echo "<td>". "<input type='text' name='telefk[]' value='".$kinito[$cc]."' size='10'>"."</td>";
	if (!empty($kin[$cc]))
	{
	   $x=$kin[$cc]."/".$mt[$cc]."/".$name[$cc];
	   echo "<td>". "<input type='checkbox' name='tsms[]' value='$x'  checked>" ."</td>";
	}
	else
	{
		$x=$kin[$cc]."/".$mt[$cc]."/".$name[$cc];
	    echo "<td>". "<input type='checkbox' name='tsms[]' value='$x'  unchecked>" ."</td>";	
	}
	echo "</tr>"; 
}
echo "</table>";
echo "<p>";
$sms=" ";
echo "<br >"."MHNYMA :"."<br >";; 
echo "<textarea id='mes' name='sms' cols='80' rows='3'> $sms </textarea >"."<br >";	
?>
<br>
<input type="submit" value="Αποστολη SMS " name="submit" onsubmit='return validate ()'>
</form>

<?php


if (isset($_POST['submit'])) 
{
	$tm=array();
	$i=0;
	$sms1=$_POST['sms'];
	$tel=$_POST['tsms'];
	echo "<p>"."ΘΑ ΣΤΑΛΕΙ ΤΟ ΑΚΟΛΟΥΘΟ ΜΗΝΥΜΑ ΣΤΟΥΣ ".$rec." :"."</p>";
	echo "<p>".$sms1."</p>";
	echo "<table class='myTable' >
	<tr style='border:1px solid black' bgcolor='#d6ff73'  >
	<th>Α/Α</th>
	<th>Α.Μητρ</th>
	<th>Όνομα</th>
	<th>Τηλέφωνο</th>
	";
	
	foreach ($tel as $t)
	{
	   $ar=explode("/",$t);
	   $tm[$i]=$ar[0];
	   $mit[$i]=$ar[1];
	   $nam[$i]=$ar[2];
	   echo "<tr>"."<td>".$i."<td>".$mit[$i]."<td>".$nam[$i]."<td>".$tm[$i]."</tr>";
	   $i++;
	}	   
	echo "</table>";
	echo "<br>";
	
	$_SESSION['sms1']=$sms1;
	$_SESSION['tel']=$tm;
	include "smssecret.php";
	
}
}
?>
<br /><br />

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