<?php
session_start();
date_default_timezone_set("Europe/Athens"); 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
require "dbconnect.php";

    $usr = $_POST['username']; 
    $pas = $_POST['password'];
    $usr = stripslashes($usr); 
    $pas = stripslashes($pas);
	$dt=date('Y-m-d');
    $_SESSION['islogin']='1';

    //$sql = mysqli_query($con,"SELECT allstudentinfo.*,stuid.omp FROM allstudentinfo,stuid WHERE allstudentinfo.mitroo = stuid.mitroo and allstudentinfo.mitroo='$usr' and stuid.taftotita='$pas' " ); 
    $sql = mysqli_query($con,"SELECT identity,omp,eponimo,onoma,tmima FROM allstudentinfo WHERE mitroo = '$usr' and identity='$pas' " ); 
	if(mysqli_num_rows($sql) == 1)
	{ 
        $row = mysqli_fetch_array($sql); 
        $name= $row['eponimo']." ".$row['onoma'];
		$tmima=$row['tmima'];
		$taxi=mb_substr($tmima, 0, 1, 'utf-8');
		$omp=$row['omp'];
		$_SESSION['omp']=$omp;
	    $_SESSION['name']=$name;
	    $_SESSION['usr']=$usr;
		$_SESSION['taxi']=$taxi;
	    $_SESSION['dt']=$dt;
	    $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'];
	$gym=7;
	switch ($row1['gymnasio']) 
	{
	  case "1":    $gym= 8;    break;
	  case "2":    $gym= 7;    break;
	  case "3":    $gym= 9;    break;
	}
	$_SESSION['gym']=$gym;
	if ( $dt >= $atetrs and $dt <= $atetre ) 
	{
		$tetramino = 'Α';
	} 
	elseif ( $dt >= $btetrs and $dt <= $btetre ) 
	{
		$tetramino = 'Β';
	}
	else
		$tetramino = '**';
	
	/////////////////////////////////////// GLOBAL VARIABLES //////////////////
	$_SESSION['tetramino']=$tetramino;
	/////////////////////////////////////// GLOBAL VARIABLES //////////////////
	$_SESSION['semester']=$tetramino;
		$dt2 = date('Y-m-d h:i:sa');
	    $ip=$_SERVER['REMOTE_ADDR'];
	    mysqli_query($con,"INSERT INTO reacons (id,ip,user,datelog,nots) VALUES (NULL,'$ip','$usr','$dt2','1')");
		/*switch ($taxi) 
		{
          //case "Α":    $menu= "indexatob.php";    break;
		  case "Α":    $menu= "indexstudent.php";    break;
          case "Β":    $menu= "indexbtoc.php";    break;
          case "Γ":    $menu= "indexc.php";    break;
        }*/
		//$menu= "indexstudent.php";
		$menu= "indexstudent.php";
        $_SESSION['menu']=$menu;
		include $menu;
	
    }
	else
	{ 
	$_SESSION['islogin']='';
	echo " ΛΑΘΟΣ ΚΩΔΙΚΟΣ - ΔΟΚΙΜΑΣΤΕ ΞΑΝΑ";
	$dt2 = date('Y-m-d h:i:sa');
	$ip=$_SERVER['REMOTE_ADDR'];
	mysqli_query($con,"INSERT INTO reacons (id,ip,user,datelog,nots) VALUES (NULL,'$ip','$usr','$dt2','0')");
 	include "index.php"; 
    } 
}
?>
</body>
</html>