<?php
include "scrinit.php";
include "logo.php";
require "dbconnect.php";
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8" />
<link rel='stylesheet' type='text/css' href='multimcss.css' />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script type="text/javascript">

	 window.onunload = refreshParent;
     function refreshParent() {
        window.opener.location.reload();
     }
</script>
<script type="text/javascript">
function KeepCount()  
{ 
	var elements = document.getElementsByName("mathm[]");
    var total = 0;
	var div = document.getElementById("pn");
    var data = div.textContent;
    for(var i in elements) {
        var element = elements[i];
        if(element.checked) total++;
        if(total <> data) {
            alert("Έχετε  επιλέξει λάθος αριθμό μαθημάτων");
            element.checked = false;
            return false;    
        }
    }
} 

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=1000, height=1000, 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:11pt; }
<p style="font-size:14px;"></p>
</style>
</head>
<body>
<h4> ΟΛΟΚΛΗΡΩΣΗ ΔΙΕΚΠΕΡΑΙΩΣΗΣ ΚΑΤΑΓΓΕΛΙΑΣ</h4>
<?php
echo '<p style="color: red; font-size: 16pt;">
      ΝΑ ΕΚΤΕΛΕΣΕΤΕ ΤΑ ΒΗΜΑΤΑ 2 ΜΕΧΡΙ 4 ΓΙΑ ΟΛΟΚΛΗΡΩΣΗ ΤΗΣ ΔΙΑΔΙΚΑΣΙΑΣ
      </p>';

$nbd=$_SESSION['n'];
$usr=$_SESSION['usr'];
$dt=$_SESSION['dt'];
$gym=$_SESSION['gym'];
$dayar=$_SESSION['dayar'];
$mitroo=$_POST['mitroo'];
$index=$_POST['index'];
$eidostimo=$_POST['etimo'];
$les1=$_SESSION['mathma'];
$pini=$_POST['pini'];
$nd=$_POST['nd'];
$mtim=$_POST['tco'];

$q=mysqli_query($con, "select tmima from allstudentinfo where mitroo='$mitroo'");
$r=mysqli_fetch_array($q);$tmima=$r['mitroo'];

	if ($eidostimo==2)
	{
		$dp=ceil($pini/$gym);
	}
	if ($eidostimo==1)
	{
		$dp=floor($pini/$gym);
	}
	
	mysqli_query($con,"insert into apobolientypo (entypoid,mitroo,date,voithos,timocode) 
	               values(NULL,'$mitroo','$dt','$usr','$mtim')");
	$s1=mysqli_query($con,"select MAX(entypoid) as newid from apobolientypo");
	$row=mysqli_fetch_array($s1);
	$nid=$row['newid'];
	
	if ($eidostimo==1)
	{
		for ($i=0;$i<$dp;$i++)
		{
		  $dx=$dayar[$index[$i]];
		  $dtin=date('Y-m-d',strtotime($dx));
		  mysqli_query($con,"insert into ekdilosi (onoma,katddk,katacode,date,perapo,permexri,teacher)
		   values('ΠΜ ΚΑΤΟΙΚΟΝ','0','$mtim','$dtin','1','$gym','$usr')");
		  $xid= mysqli_insert_id($con);
		  $pp="";$ppp="";
		  for ($k=1;$k<=$gym;$k++)
		  {
			$pp=$pp.'p'.$k.',';
			$ppp=$ppp.'1,';
		  }
		  $pp=trim($pp,',');
		  $ppp=trim($ppp,',');
		  mysqli_query($con,"insert into ekdilosistu (code,pmp,".$pp.") values('$xid','$mitroo',".$ppp.")"); 
		}
	}

	$mathm=$dtin=array();
	$l=1;
	for ($j=1;$j<=$gym;$j++)
	{	
		for ($i=0;$i<$dp;$i++)
		{	
		  $k=($index[$i]-1)+($j-1)*10;
		  $s1=$les1[$k];
		  $ar=explode("/",$s1);
		  $m=$ar[0];
		  $mathm[$l]=$m;
		  $dtin[$l]=$dayar[$index[$i]];
		  $l++;
		}
	}

		$k=1;
		foreach ($mathm as $m)
		{
		  $dti=date('Y-m-d',strtotime($dtin[$k]));
		  mysqli_query($con,"insert into apoboli (mathima,date,entypoid) values('$m','$dti','$nid')");
		  $k++;
		}


 ?>
 <h4>ΣΤΑΔΙΟ 2: ΔΗΜΙΟΥΡΓΙΑ ΕΠΙΣΤΟΛΗΣ</h4>
 <button> <a href="epistoli.php?timcode=<?php echo $mtim; ?>" onclick="window.open(this.href, 'popupwindow2','width=600,height=800,left=30, top=10, scrollbars=yes,resizable=yes');return false;">Δημιουργία Επιστολής</a></button>	
 <h4>ΣΤΑΔΙΟ 3: ΑΠΟΣΤΟΛΗ SMS</h4>
 <button> <a href="smskath.php?timcode=<?php echo $mtim; ?>" onclick="window.open(this.href, 'popupwindow2','width=600,height=800,left=30, top=10, scrollbars=yes,resizable=yes');return false;">Αποστολή SMS</a></button>
 <h4>ΣΤΑΔΙΟ 4: ΔΕΛΤΙΟ ΑΠΟΒΟΛΗΣ ΓΙΑ ΓΡΑΜΜΑΤΕΙΑ</h4>
 <button style="color:blue " onclick="window.open('printdeltk.php?timcode=<?php echo $mtim; ?>','','toolbar=yes, scrollbars=yes, resizable=yes, width=800, height=800')">ΔΕΛΤΙΟ ΑΠΟΒΟΛΗΣ</button>

<br ><br ><br >

<br><br>
<?php
if ($_SESSION['tmkath'] < 1)
{
	?>
<a  href="kathisterisi.php" style="color:blue" > <button style="color:blue"> Επιστροφή στις Καθυστερήσεις </button></a> 
&nbsp&nbsp&nbsp&nbsp<input type="button" name="epistrofi" value="Επιστροφή" onClick="self.close()"> 
<?php
}
else
{
?>	
<input type="button" name="epistrofi" value="Επιστροφή" onClick="self.close()"> 
<?php
}	



