<?php
session_start();
if ($_SESSION['islogin']=='' ) { 
  echo "ΠΡΕΠΕΙ ΝΑ ΕΓΓΡΑΦΕΙΤΕ ΓΙΑ ΝΑ ΧΡΗΣΙΜΟΠΟΙΗΣΕΤΕ ΤΟ ΣΥΣΤΗΜΑ"."<BR>";
  sleep(3);
  header("Location: loginguest.php"); /* Redirect browser */
  exit();
  }
//include "logo.php";
?>
<!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>
<?php
$usr=$_SESSION['usr'];
if (isset($_POST['passch'])) {
include "dbconnect.php";
$pname = mysqli_real_escape_string($con, $_POST['pname']);
$sname = mysqli_real_escape_string($con, $_POST['sname']);
$mobn = mysqli_real_escape_string($con, $_POST['mobn']);
$email = mysqli_real_escape_string($con, $_POST['email']);
$password1 = mysqli_real_escape_string($con, $_POST['newpass']);
$password2 = mysqli_real_escape_string($con, $_POST['confpass']);


if ($password1 <> $password2) { 

	// 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();
}
else 
{
$parentname=$sname." ".$pname;
$hash = password_hash($password1, PASSWORD_DEFAULT);
$sq=mysqli_query($con, "INSERT INTO parents (password,name,username,phone_number,email) VALUES ( '$hash','$parentname','$usr','$mobn','$email')");
 
	    $year = date('Y', strtotime($dt));
        $day = date('d', strtotime($dt));
	    $month = date('m', strtotime($dt));
	
	if (($month > 1 and $month < 9) or ($day>=21 AND $month==1)) {$tetramino = 'B';} else {$tetramino = 'A';}
	
	/////////////////////////////////////// GLOBAL VARIABLES //////////////////
	$_SESSION['semester']=$tetramino;
	$_SESSION['studentid']=rtrim($usr,'!');
	$_SESSION['dt']=$dt;
	$_SESSION['islogin']='1';
	$_SESSION['parentname']=$parentname;
    $menu= "indexparent.php";  
    $_SESSION['menu']=$menu;
    include $menu;
	echo "<br>";
    echo "<br>";
    echo "<br>";
    echo "<br>";
    echo "<br>";
	mysqli_close($con);
}}
 ?>
</body>
</html>