<?php
session_start();
if ($_SESSION['islogin']=='' ) { 
  echo "ΠΡΕΠΕΙ ΝΑ ΕΓΓΡΑΦΕΙΤΕ ΓΙΑ ΝΑ ΧΡΗΣΙΜΟΠΟΙΗΣΕΤΕ ΤΟ ΣΥΣΤΗΜΑ"."<BR>";
  header("Location: loginall.php"); /* Redirect browser */
  exit();
  }
include "logo.php";
if (!(isset($_SESSION['pmp']) || $_SESSION['pmp'] == '')) {
    header("location:loginall.php");}
$menu=$_SESSION['menu'];
?>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8" />
</head>
<body> 

<br >
<br >
<br >

<?php

if (isset($_POST['passch'])) {
include "dbconnect.php";

$password1 = mysqli_real_escape_string($con, $_POST['newpass']);
$password2 = mysqli_real_escape_string($con, $_POST['confpass']);
$teacherid = mysqli_real_escape_string($con, $_SESSION['usr']);

if ($password1 <> $password2) { echo "ΟΙ ΔΥΟ ΚΩΔΙΚΟΙ ΔΕΝ ΣΥΜΠΙΠΤΟΥΝ";}

else 
{
	$sql1 = $dbcon->prepare("SELECT * FROM parameters " );
	$sql1->execute();
	$row1=$sql1->fetch(PDO::FETCH_ASSOC);
	$hpass=$row1['hpass'];
	if ($hpass==1)
	{
       $hash = password_hash($password1, PASSWORD_DEFAULT);
	}
	else
	{
	   $hash = $password1	;
	}
 if (mysqli_query($con, "UPDATE teachers SET pass='$hash' WHERE PMP='$teacherid'"))
    {echo "ΈΧΕΤΕ ΑΛΛΑΞΕΙ ΤΟΝ ΚΩΔΙΚΟ ΣΑΣ ΜΕ ΕΠΙΤΥΧΙΑ";}
 else { mysqli_error($con); }
}
mysqli_close($con);
$menu=$_SESSION['menu'];
//header("location: $menu ");

}

?>
<br /><br /><br />
<a  href=<?php echo $menu;?> style="color:blue "  >  Επιστροφή στο Μενού  </a>
</body>
</html>








