<?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 src="script.js"></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'];
$eidostimo=$_SESSION['eidostimo'];
$flagk=$_SESSION['flagk'];
if (isset($_POST['apoboli1']))
{
	$mitroo=$_POST['mitroo'];
	$index=$_POST['index'];
	$mth=$_POST['mth'];
	$les1=$_SESSION['xx1'];
	$pini=$_POST['pini'];
	$nd=$_POST['nd'];
	$aranaforas=$_SESSION['aranaforas'];
	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','$aranaforas')");
	$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','$aranaforas','$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++;
		}
}
if ($flagk=="argoporia")
{
	$mtim=$_SESSION['aranaforas'];
 ?>
 <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('printdelt.php?timcode=<?php echo $mtim; ?>','','toolbar=yes, scrollbars=yes, resizable=yes, width=800, height=800')">ΔΕΛΤΙΟ ΑΠΟΒΟΛΗΣ</button>
<?php
}
else
{
?>

<button style="color:blue " onclick="window.open('epistolipara.php','','toolbar=yes, scrollbars=yes, resizable=yes, width=900, height=900')">ΔΗΜΙΟΥΡΓΙΑ ΕΠΙΣΤΟΛΗΣ</button>
<?php
}
?>
<h4>ΣΤΑΔΙΟ 3: ΑΠΟΣΤΟΛΗ SMS</h4>
<button style="color:blue " onclick="window.open('smspara.php','','toolbar=yes, scrollbars=yes, resizable=yes, width=700, height=500')">ΑΠΟΣΤΟΛΗ SMS</button>
<h4>ΣΤΑΔΙΟ 4: ΔΕΛΤΙΟ ΑΠΟΒΟΛΗΣ ΓΙΑ ΓΡΑΜΜΑΤΕΙΑ</h4>
<button style="color:blue " onclick="window.open('printdelt.php','','toolbar=yes, scrollbars=yes, resizable=yes, width=800, height=800')">ΔΕΛΤΙΟ ΑΠΟΒΟΛΗΣ</button>
<br><br><br>
<h4>ΣΤΑΔΙΟ 5: ΟΛΟΚΛΗΡΩΣΗ ΔΙΕΚΠΕΡΑΙΩΣΗΣ ΚΑΤΑΓΓΕΛΙΑΣ</h4>
<?php
$sql1=mysqli_query($con,"SELECT oktel,oksms,okletter FROM kataggelia WHERE aranaforas='$aranaforas'");
$row = mysqli_fetch_array($sql1);

$x=0;$x1=0;$x2=0;
if ($row['okletter'] == '0000-00-00') {$dateep=date('Y-m-d');} else {$dateep=$row['okletter'];$x=1; } 
if ($row['oksms'] == '0000-00-00') {$datesms=date('Y-m-d');} else {$datesms=$row['oksms'];$x1=1; } 
if ($row['oktel'] == '0000-00-00') {$datetel=date('Y-m-d');} else {$datetel=$row['oktel'];$x2=1; } 
?>
<form action="addkata1.php" method="post">
<?php
echo "<table class='myTable' >
<tr style='border:1px solid black;font-size:9px'  >
<tr>
<th>ΕΠΙΣΤΟΛΗ</th>
<th>ΤΗΛΕΦΩΝΟ</th>
<th>ΜΗΝΥΜΑ/SMS</th>
</tr>";	

echo "<tr>";
?>
<td> <input type='checkbox' name='epistoli' <?php if ($x == 1) echo 'checked'; ?> /> </td>
<td> <input type='checkbox' name='tel' <?php if ($x2 == 1) echo 'checked'; ?> /> </td>
<td> <input type='checkbox' name='sms' <?php if ($x1 == 1) echo 'checked'; ?> /> </td>
</tr>

<tr>
<td> <input type='date' name='dateep' value=<?php echo $dateep;?> /> </td>
<td> <input type='date' name='datetel' value=<?php echo $datetel;?> /> </td>
<td> <input type='date' name='datesms' value=<?php echo $datesms;?> /> </td>
</tr> 

<input type="text" name="aranaforas" hidden value=<?php echo $aranaforas;?> > 
<br ></table><br ><br > 
<b>Η ΚΑΤΑΓΓΕΛΙΑ ΟΛΟΚΛΗΡΩΘΗΚΕ:</b> <input type="checkbox" name="olo" checked > 
<input type="submit" name="submit" value="Καταχώρηση" >
</form>
<br ><br ><br >

</form>
  
<br><br>
<br>
<a  href="pitharxika.php" style="color:blue" > <button style="color:blue"> Επιστροφή στις Καταγγελίες </button></a> 
&nbsp&nbsp&nbsp&nbsp<a  href=<?php echo $menu;?> style="color:blue "  ><button>Επιστροφή στο Μενού</button></a>



