<?php 
include "scrinit.php";
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 black;padding:1px;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'];
$gym=$_SESSION['gym'];
if ($access <3 ) { echo " *** ΜΗ ΔΙΑΘΕΣΙΜΕΣ ΑΝΑΦΟΡΕΣ *** ";}
{

  $sql=mysqli_query($con,"SELECT  b.mitroo,a.kinito,a.eponimo,a.onoma,a.tmima,sum(b.bathmosa) as suma,
  count(b.bathmosa) as cnta,sum(b.bathmosa) as sumb,count(b.bathmosb) as cntb,sum(b.exetasi) as sume,
  count(b.exetasi) as cnte from  bthis as b,allstudentinfo as a 
  where b.mathima not like ' %' and b.bathmosa <> 0 and b.mitroo=a.mitroo group by b.mitroo order by a.tmima,a.mitroo");
 

?>	
<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>";
$i=1;	
while($row = mysqli_fetch_array($sql))
{  
   $cn=$row['cnta'];
   
   if ($cn > 0) 
   {
     $mesos=$row['suma']/$cn;
   }
   
   if ($mesos >=18.5 and $row['cnta'] > 5)
   {
	
	   $mit[$i]=$row['mitroo'];
	   $name[$i]=$row['eponimo'] ." ".$row['onoma'];
	   $fname[$i]=$row['onoma'];
	   $kinito[$i]=$row['kinito'];
	   $x=$kinito[$i]."/".$mit[$i]."/".$fname[$i];
	   echo "<tr>";
	   echo "<td>".$i."</td>";
	   echo "<td>".$mit[$i] . "</td>";
	   echo "<td>".$row['tmima']."</td>";
	   echo "<td>".$name[$i]."</td>";
	   echo "<td>". round($mesos, 2). "</td>";
	   echo "<td>". "<input type='text' name='telef[]' value='$kinito[$i]' size='10'>"."<td>";
	   echo "<td>". "<input type='checkbox' name='tsms[]' value='$x'  checked>" ."</td>";
	   $i++;
   } 
   echo "</tr>"; 
   
}
echo "</table>";	
$bname=" Αποστολη SMS ";

?>
<br>
<input type="submit" value="<?php echo $bname ; ?>" name="submit">
</form>


<?php
if (isset($_POST['submit'])) 
{
	
	$tm=array();
	$i=0;
	echo "<p>"."ΘΑ ΣΤΑΛΟΥΝ ΜΗΝΥΜΑΤΑ ΣΤΟΥΣ:"."</p>";
	echo "<table class='myTable' >
	<tr style='border:1px solid black' bgcolor='#d6ff73'  >
	<th>Α/Α</th>
	<th>Α.Μητρ</th>
	<th>Όνομα</th>";
	$tel=$_POST['tsms'];
	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]."</tr>";
	   $i++;
	}	   
	echo "</table>";
	echo "<br>";
	$sql=mysqli_query($con,"SELECT tel from generalinfo");
	$row=mysqli_fetch_array($sql); 
	$telef=$row['tel'];
	$sm1="ΤΟ ΠΑΙΔΙ ΣΑΣ ";
	$sm2=" ΕΧΕΙ ΑΡΙΣΤΕΥΣΕΙ ΣΤΟ Α ΤΕΤΡΑΜΗΝΟ. ΣΥΓΧΑΡΗΤΗΡΙΑ ΚΑΙ ΚΑΛΗ ΕΠΙΤΥΧΙΑ ΣΤΗΝ ΣΥΝΕΧΕΙΑ";
	$sms=$sm1.$sm2;
	echo "<br >"."MHNYMA :"."<br >";; 
	echo "<textarea name='sms' cols='80' rows='2'> $sms </textarea >"."<br >";
	$_SESSION['tel']=$tm;
	$_SESSION['onoma']=$nam;
	$_SESSION['sm1']=trim($sm1);
	$_SESSION['sm2']=trim($sm2);
	$_SESSION['fl']="proi";
	include "smssecret.php";
        
}	
}

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