<?php
session_start();
//include "logo1.php";
?>
<head>
<html xmlns="https://www.w3.org/1999/xhtml">
<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>

<?php

    require "dbconnect.php";
    $usr = trim($_POST['username']); 
    $pas = trim($_POST['password']);
    $dt=date('Y-m-d');
    $_SESSION['islogin']=1;
    $oklogin=0;
    $sql = mysqli_query($con,"SELECT identity,birthday,mitroo FROM allstudentinfo WHERE mitroo = '$usr' and identity='$pas' " ); 
    $row = mysqli_fetch_array($sql); 
    if (!empty($row))
    {
    $name= $row['eponimo']." ".$row['onoma'];echo $name;
    $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']=$usr;
		$_SESSION['usr']=$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 "<script> location.href='indexparent.php'; </script>";
       		 exit;
		echo "<br>";
		echo "<br>";
		echo "<br>";
		echo "<br>";
		echo "<br>";
		mysqli_close($con);	
	}
	else
	{
		// 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");
			echo "<script> location.href='loginguest.php'; </script>";
        		exit;
	}

?>
</body>
</html>