<?php
include "scrinit.php";
include "logo.php";
?><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Kathisteriseis</title>
</head>

<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript">


function atleast_onecheckbox(e) 
{
  var empt = document.forms["selectpoini"]["pini"].value;
  if ($("input[type=checkbox]:checked").length === 0) {
      e.preventDefault();
      alert('Πρέπει να επιλέξετε τις καθυστερήσεις που θα τιμωρηθούν');
      return false;
  }
  if (empt == "")
  {
     alert("Το πεδίο της ποινής δεν μπορεί να είναι κενό!");
     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=800, height=800, top='+top+', left='+left);
}

function pop_up(url)
{
window.open(url,'win2','status=no,toolbar=no,scrollbars=yes,titlebar=no,menubar=no,resizable=yes,width=800,height=800,directories=no,location=no') 
}
</script>

<style type="text/css">
table.myTable { border-collapse:collapse; }
table.myTable td, table.myTable th { border:1px solid black;padding:2px;font-size:9pt; }
<p style="font-size:09px;"></p>
</style>
</head>
<body>
<?php
require("dbconnect.php");
$dt=$_SESSION['dt'];
	$pini=$_POST['pini'];
	$mitroo=$_POST['mitroo'];
	$mitr=$mitroo;
	$argo=$_POST['kath'];
	$vd=$_SESSION['usr'];
	$etimo = $_POST['etimo'];
    $_SESSION['eidostimo']=$etimo;
	if ($etimo == 0 and $pini==0) {$epini='ΠΑΙΔ. ΔΙΑΛΟΓΟΣ';}
		 if ($etimo == 0 and $pini > 0) {$epini='ΜΕ ΑΝΑΣΤΟΛΗ';}
		 if ($etimo ==1 ){$epini='ΚΑΤ΄ ΟΙΚΟΝ';}
		 if ($etimo == 2) {$epini='ΑΠΟΒΟΛΗ';}
	?>
	<h4>ΘΑ ΤΙΜΩΡΗΘΟΥΝ ΟΙ ΠΙΟ ΚΑΤΩ ΚΑΘΥΣΤΕΡΗΣΕΙΣ ΜΕ ΠΟΙΝΗ : <?php echo $pini." ΠΕΡΙΟΔΩΝ ".$epini; ?>   </h4>
	<?php
	$per=$datet=$kath=$dat=array();
	echo "<table class='myTable' >
	<tr style='border:1px solid black' >
	<th>Α/Α</th>
	<th>Ημερομηνία</th>
	<th>Περίοδ.</th>
	<th>Καθυστ.</th>
	</tr>";
	$i=0;
	foreach ($argo as $t)
	{
	 $i++;
	 $ar=explode("/",$t);
	 $per[$i]=$ar[1];
	 $datet[$i]=$ar[2];
	 $dat[$i]=date('d-m-Y', strtotime($ar[2]));
	 $kath[$i]=$ar[0];
	 echo "<tr>";
	 echo "<td>" .$i;
	 echo "<td>" .$dat[$i];
	 echo "<td>" .$per[$i];
	 echo "<td>". $kath[$i];
     echo  "</tr>";
	}
	echo "</table>";	
	?>
	
    <?php
	$sql = mysqli_query($con,"SELECT MAX(timoriacode) FROM timoria " );
    $row = mysqli_fetch_array($sql);
    $mtim=$row['MAX(timoriacode)']+1;

    $q="INSERT INTO timoria (timoriacode, stu_id, dateappl, peramount,vd,eidostimo) 
	             VALUES ('$mtim', '$mitroo','$dt', '$pini','$vd','$etimo') ";
				 
	if (mysqli_query($con, $q)) 
		{
			echo "<p>"."Η ποινή ".$pini." περιόδων έχει καταχωρηθεί "."</p>";
        } 
		else 
		{
            echo "Error: " . $query . "<br>" . mysqli_error($con);
		}
    for ($k=1;$k<=$i;$k++) 
	{
        $q="UPDATE apousies SET timoriacode='$mtim' 
		WHERE mitroo='$mitroo' AND dateout='$datet[$k]' AND period='$per[$k]' AND kath > 0 " ; 
		if (mysqli_query($con, $q)) 
		{
			
        } 
		else 
		{
            echo "Error: " . $query . "<br>" . mysqli_error($con);
        }
    }

    
	$eidostimo=$etimo;
	     if ($etimo == 0 and $pini==0) 
	     {
	     	$epini='ΠΑΙΔ. ΔΙΑΛΟΓΟΣ'; 
	     	?><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>
             <?php
	     }
		 if ($etimo == 0 and $pini > 0) 
		 {
		 	$epini='ΜΕ ΑΝΑΣΤΟΛΗ';
		 		?><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>
             <?php
		 }
		 if ($etimo == 2) 
		 {
		     $epini='ΑΠΟΒΟΛΗ';
		     	include "diagomathiti.php";
		 	include "mathitisp2dk.php";
		     
		 }
		 if ($etimo == 1 )
		 {
		 	$epini='ΚΑΤ΄ ΟΙΚΟΝ';
			include "diagomathiti.php";
		 	include "mathitisp2dk.php";
		 }
		 



?>
<br /><br />
<input type="button" name="epistrofi" value="Επιστροφή" onClick="self.close()"> 
</body>
</html>