<?php 
include "scrinit.php";
$menu = $_SESSION['menu'];
include $menu;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
table.myTable { border-collapse:collapse; }
table.myTable td, table.myTable th { border:1px solid green;padding:2px;font-size:10pt; }
<p style="font-size:10px;"></p>
</style>
<title>ΔΕΛΤΙΟ ΕΠΙΚΟΙΝΩΝΙΑΣ ΣΧΟΛΕΙΟΥ'ΓΟΝΕΩΝ ΜΕ SMS</title>

<?php 

require("dbconnect.php");
$usr=$_SESSION['usr'];
$access=$_SESSION['access'];
$dt=$_SESSION['dt'];
$dtc= date('d-m-Y', strtotime($dt));

$result = mysqli_query($con,"SELECT tmima,sex,mitroo,eponimo,onoma,kinito FROM allstudentinfo ORDER BY tmima,eponimo,onoma");
$logos = mysqli_query($con,"SELECT id,perigrafi FROM poiotika ORDER BY id");
?>
<form  method='post'>

<TABLE>
<TR>
<TD>
<h4>ΕΠΕΛΕΞΕ ΜΑΘΗΤΗ/ΤΕΣ ΓΙΑ ΑΠΟΣΤΟΛΗ ΜΗΝΥΜΑΤΟΣ </h4>
<div style="overflow:scroll; border:1px solid black;background:#F5F9F0;width:500px; height: 450px">
<?php
echo "<table style='width:480px' class='myTable' >
<tr style='border:1px solid black' bgcolor='#adcd82'  >
<th>ΤΜΗΜΑ</th>
<th>ΜΗΤΡΩΟ</th>
<th>ΜΑΘΗΤΗΣ/ΜΑΘΗΤΡΙΑ</th>
<th> </th>
<th>ΜΗΝΥΜΑ</th>
</tr>";
$i=1;
while ($row = mysqli_fetch_array($result)) 
  { 
    $name=$row['eponimo']." ".$row['onoma'];
	$mitroo=$row['mitroo'];
	$sex=$row['sex'];
	$tmima=$row['tmima'];
	$tel = $row['kinito'];
	$tn=$tel."/".$row['onoma']."/".$sex;
	echo "<tr>";
	echo "<td>".$tmima."</td>";
	echo "<td>".$mitroo."</td>";
	echo "<td>".$name."</td>";
	echo "<td>"." "."</td>";
    echo "<td ALIGN=center>"."<input type='checkbox' name='smsx[]' value='$tn' >"."</td>";
	echo "</tr>";
    $i++;
}
echo "</table>";
?>
</div>
</TD>
<td> </td>
<TD>
<h4> ΕΠΕΛΕΞΕ ΤΟΥΣ ΛΟΓΟΥΣ </h4>
<div style="overflow:scroll; border:1px solid black;background:#F5F9F0;width:400px; height: 450px">
<?php
echo "<table style='width:380px' class='myTable' >
<tr style='border:1px solid black' bgcolor='#adcd82'  >
<th>A/A</th>
<th>ΠΕΡΙΓΡΑΦΗ ΣΥΜΠΕΡΙΦΟΡΑΣ </th>
<th> </th>
<th>ΕΠΙΛΟΓΗ</th>
</tr>";
$i=1;
while ($row1 = mysqli_fetch_array($logos)) 
  { 
    $perigrafi=$row1['perigrafi'];
	$id=$row1['id'];
	echo "<tr>";
	echo "<td>".$id."</td>";
	echo "<td>".$perigrafi."</td>";
	echo "<td>"." "."</td>";
    echo "<td ALIGN=center>"."<input type='checkbox' name='smsl[]' value='$perigrafi' >"."</td>";
	echo "</tr>";
    $i++;
}
echo "</table>";
?>
</div>
</TD>
</TR>
</TABLE>
<input type="submit" name="sendsms" value="Επιβεβαίωση Επιλογών" >
</form>
<?php
if (isset($_POST['sendsms']))
{
    $usr=$_SESSION['usr'];
	$sql = $dbcon->prepare("SELECT Name FROM teachers WHERE PMP = ? ");
	$sql->execute([$usr]);$row=$sql->fetch(PDO::FETCH_ASSOC);
	$teacher=$row['Name'];
	$tel=$name=$sex=array();
	$tname=$_POST['smsx'];
	$logoi=$_POST['smsl'];
	$i=0;
	foreach ($tname as $tn)
	{
		$arr=explode("/",$tn);
		$tel[$i]=$arr[0];
		$name[$i]=$arr[1];
		$sex[$i]=$arr[2];
		$i++; 
	}
	
    
	for ($k=0;$k<$i;$k++)
	{
		$sms="";
		if ($sex[$k]=="Α") {$s="Ο ";} else {$s="Η ";}
		$sms=$s.$name[$k]." ";
		foreach ($logoi as $lg)
		{
			$sms=$sms.$lg.",";
		}
		$smsx[$k] = rtrim($sms, ","). ". Επικοινωνήστε με ".$teacher;
		//$smsx[$k] = rtrim($sms, ",");
	}
	
	echo "<br>"."ΔΕΙΓΜΑ - MHNYMA ΠΡΩΤΟΥ ΜΑΘΗΤΗ:"."<br >";
    echo "<textarea name='smsκ' cols='100' rows='3'>". $smsx[0]." </textarea >"."<br >";
	
	$_SESSION['sms1']=$smsx;
	$_SESSION['ph']=$tel;
	echo "<br>";
	print_r($_POST['sms']);
	echo " {Έτοιμότητα αποστολής}";
    $_SESSION['fl']="home";
	include "smssecret.php";
}	


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