<?php
include "scrinit.php";
include "logo.php";
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="style1.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php

require("dbconnect.php");
$usr = $_SESSION['usr'];
$tetramino=$_SESSION['tetramino'];
$xronia=$_SESSION['xronia'];
$flagtaxi=$_SESSION['flagtaxi'];
$amiges=$_SESSION['amiges'];
$dt= date("Y-m-d h:i:sa");
 function rangeWeek($datestr) {
    date_default_timezone_set(date_default_timezone_get());
    $dt = strtotime($datestr);
    $res['start'] = date('N', $dt)==1 ? date('Y-m-d', $dt) : date('Y-m-d', strtotime('last monday', $dt));
    $res['end'] = date('N', $dt)==7 ? date('Y-m-d', $dt) : date('Y-m-d', strtotime('next sunday', $dt));
    return $res;
    }

if (isset($_POST['epilogi3'])) 
{
	$dt = date('Y-m-d H:i:s');
	$perapo=$_POST['perapo'];
	$permexri=$_POST['permexri'];
	$math=$_POST['mathx'];
	$thema=$_POST['themax'];
    $duration=$_POST['duration'];
    $subject=$_POST['subject'];
    $testd=	date('Y-m-d', strtotime($_POST['testd']));
	$karfi=$_SESSION['karfi'];
///////////////////////////////////////////////////
$dates=rangeWeek($testd);
$startdate=$dates['start'];
$enddate=$dates['end'];
$q = mysqli_query($con,"SELECT class FROM declarations WHERE class='$math' and (testdate>='$startdate' and testdate<= '$enddate')");
$cc = mysqli_num_rows($q) + 1;

if ($cc <= 3) 
{
    $query="INSERT INTO declarations (acayear,tetramino,subject,testdate,decladate,teacher,class,thema,perapo,permexri,duration,karfi)
	VALUES ('$xronia','$tetramino','$subject','$testd','$dt','$usr','$math','$thema','$perapo','$permexri','$duration','$karfi')";
	
	if (mysqli_query($con, $query)) 
		{
			echo "**** Η δήλωση διαγωνίσματος έγινε με επιτυχία ****";
        } 
		else 
		{
            echo "Error: " . $query . "<br>" . mysqli_error($con);
        }

	?>
<form>
<br>
<fieldset class="fx">
<legend class="l1"> ΕΠΙΒΕΒΑΙΩΣΗ ΣΤΟΙΧΕΙΩΝ ΔΙΑΓΩΝΙΣΜΑΤΟΣ</legend>
<br > Ημερομηνία Δήλωσης:<input type="text"  name = 'dt' value= <?php echo date('d-m-Y', strtotime($dt)); ?> readonly="readonly"> 
&nbsp;&nbsp;&nbspΗμερομηνία Διαγωνίσματος : <input type="text"  name = 'testd'  value= <?php echo date('d-m-Y', strtotime($testd)); ?> readonly="readonly"><br >
<br >Τμήμα/Συνδιδασκαλία :<input type='text' name='mathx' size = '20' value="<?php echo $math; ?>" readonly="readonly"/>
ΜΑΘΗΜΑ  :<input type='text' name='subject' size = '20' value="<?php echo $subject; ?>" readonly="readonly"/><br>
<br> ΘΕΜΑ:<input type='text' name='thema' size = '50' value="<?php echo $thema; ?>" readonly="readonly"/><br >
<br >Διάρκεια  :<input type='text' name='duration' size = '3' value=<?php echo $duration; ?> readonly='readonly'/> λεπτά
&nbsp;&nbsp;&nbsp&nbsp;&nbsp;&nbspΑπό περίοδο :<input type='text' name='perapo' size = '3' value="<?php echo $perapo; ?>" /> 
 μέχρι :<input type='text' name='permexri' size = '3' value="<?php echo $permexri; ?>" readonly='readonly'/> <br>
<br >Καρφωτή Ημερομηνία; :<input type='text' value="<?php if ($karfi==1) echo "ΝΑΙ"; else echo "ΟΧΙ"; ?>" readonly="readonly"/>	
<br ><br >
</fieldset>
<br ><br >
<?php
}
else
{
	echo "Η δήλωση διαγωνίσματος ακυρώθηκε - Αριθμός Διαγωνισμάτων > 3 ";
}	
}
else
{
	echo "Η δήλωση διαγωνίσματος ακυρώθηκε ";
}
?>	
<br> <br>
<a  href='<?php echo $menu;?>'><button  type="button" class="sb1">Επιστροφή στο Μενού</button></a>
</body>
</html>