<?php
session_start();
include "logo1.php";
?>
<html xmlns="https://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
<script language="JavaScript" type="text/javascript">
function changeDate(i)
{
var e = document.getElementById('day');
while(e.length>0)
e.remove(e.length-1);
var j=-1;
if(i=="na")
k=0;
else if(i==2)
k=28;
else if(i==4||i==6||i==9||i==11)
k=30;
else
k=31;
while(j++<k){
var s=document.createElement('option');
var e=document.getElementById('day');
if(j==0){
s.text="Ημέρα";
s.value="na";
try{
e.add(s,null);}
catch(ex){
e.add(s);}}
else{
s.text=j;
s.value=j;
try{
e.add(s,null);}
catch(ex){
e.add(s);}}}
y = 1995;
g = 2005;
while (y++<g){
var s = document.createElement('option');
var e = document.getElementById('year');
s.text=y;
s.value=y;
try{
e.add(s,null);}
catch(ex){
e.add(s);}}
}
</script>
</head>
<body>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') 
{
    require "dbconnect.php";
    $usr = $_POST['username']; 
    $pas = $_POST['password'];
    $usr = mysqli_real_escape_string($con, $usr);
    $pas = mysqli_real_escape_string($con, $pas);
	$dt=date('Y-m-d');
	
	    
    $_SESSION['islogin']=1;
	$sql = mysqli_query($con,"SELECT * FROM parents WHERE username='$usr' " ); 
	$row = mysqli_fetch_array($sql);
	$hash=trim($row['password']);
	if (! password_verify($pas, $hash)) 
	{
   	    $sql = mysqli_query($con,"SELECT * FROM parents WHERE username='$usr' " ); 
		if(mysqli_num_rows($sql) == 1)
	    {
			
			// DISPALY A MESSAGE BOX and return
          echo '<script type="text/javascript">';
          echo 'alert("ΕΙΣΤΕ ΕΓΓΕΓΡΑΜΜΕΝΟΣ ΧΡΗΣΤΗΣ - ΕΙΣΑΓΕΤΕ ΤΟ ΟΝΟΜΑ ΚΑΙ ΤΟΝ ΚΩΔΙΚΟ ΧΡΗΣΤΗ")';
          echo '</script>';
		  $_SESSION['islogin']=' ';	
          $time = 1; //Time (in seconds) to wait. 
          $url = "loginguest.php"; //Location to send to. 
          header("Refresh: $time; url=$url");
		  exit();
		}
		$usr1=rtrim($usr,'!');
		$_SESSION['usr']=$usr;
	    $sql = mysqli_query($con,"SELECT mitroo,eponimo,onoma FROM allstudentinfo WHERE mitroo='$usr1' " );
		$row=mysqli_fetch_array($sql);
		if(mysqli_num_rows($sql) != 1)
	    {
			// DISPALY A MESSAGE BOX and return
			echo '<script type="text/javascript">';
			echo 'alert("ΛΑΘΟΣ ΣΤΟΙΧΕΙΑ")';
			echo '</script>';
			$_SESSION['islogin']='';	
			$time = 1; //Time (in seconds) to wait. 
			$url = "loginguest.php"; //Location to send to. 
			header("Refresh: $time; url=$url");
		}
		else
		{
			

?>
<br> <br>
<h3>ΕΙΣΟΔΟΣ ΧΡΗΣΤΗ ΓΙΑ ΠΡΩΤΗ ΦΟΡΑ - ΕΛΕΓΧΟΣ ΣΤΟΙΧΕΙΩΝ  </h3>
<br> 
<h4>ΗΜΕΡΟΜΗΝΙΑ ΓΕΝΝΗΣΗΣ ΤΟΥ ΠΑΙΔΙΟΥ ΣΑΣ </h4>
<br>
<form action="checkloginguest1.php" method="post">
Αριθμός Μητρώου μαθητή/τριας: <?php echo $usr1;?><br /><br />

<select name="month" onChange="changeDate(this.options[selectedIndex].value);">
<option value="na">Μήνας</option>
<option value="1">Ιανουάριος</option>
<option value="2">Φεβρουάριος</option>
<option value="3">Μάρτιος</option>
<option value="4">Απρίλιος</option>
<option value="5">Μάιος</option>
<option value="6">Ιούνιος</option>
<option value="7">Ιούλιος</option>
<option value="8">Αύγουστος</option>
<option value="9">Σεπτέμβριος</option>
<option value="10">Οκτώβριος</option>
<option value="11">Νοέμβριος</option>
<option value="12">Δεκέμβριος</option>
</select>
<select name="day" id="day" >
<option value="na">Ημέρα</option>
</select>
<select name="year" id="year" >
<option value="na">Χρονιά</option>
</select>

<input type="submit" name="submit" value="Υποβολή Ημερομηνίας">

</form>

<?php

}
}
else
{
	$_SESSION['usr']=rtrim($usr,'!');
	$sql1 = $dbcon->prepare("SELECT * FROM parameters " );
	$sql1->execute();
	$row1=$sql1->fetch(PDO::FETCH_ASSOC);
	
	$atetrs=$row1['atetrs'];
	$atetre=$row1['atetre'];
	$btetrs=$row1['btetrs'];
	$btetre=$row1['btetre'];
	    $parentname=$row['name'];
		$year = date('Y', strtotime($dt));
        $day = date('d', strtotime($dt));
	    $month = date('m', strtotime($dt));
	
	if ( $dt >= $atetrs and $dt <= $atetre ) 
	{
		$tetramino = 'Α';
	} 
	elseif ( $dt >= $btetrs and $dt <= $btetre ) 
	{
		$tetramino = 'Β';
		
		}
	else
		$tetramino = '**';
	$gym=7;
	switch ($row1['gymnasio']) 
	{
	  case "1":    $gym= 8;    break;
	  case "2":    $gym= 7;    break;
	  case "3":    $gym= 9;    break;
	}
	/////////////////////////////////////// GLOBAL VARIABLES //////////////////
	$_SESSION['semester']=$tetramino;
	$_SESSION['tetramino']=$tetramino;
	$_SESSION['studentid']=rtrim($usr,'!');
	$_SESSION['dt']=$dt;
	$_SESSION['islogin']='1';
	$_SESSION['parentname']=$parentname;
	
	$_SESSION['gym']=$gym;
    $menu= "indexparent.php"; 
    $menup=	"indexparentp.php";

    $_SESSION['menu']=$menu;
	$_SESSION['menup']=$menup;
	header( "Location: indexparent.php" );
    
	echo "<br>";
    echo "<br>";
    echo "<br>";
    echo "<br>";
    echo "<br>";
	mysqli_close($con);	
	
}
}
?>
</body>
</html>