<?php
include('conexao.php');
session_start();

	if(!isset($_SESSION["login"]) || !isset($_SESSION["senha"])){
		header("Location: cuide.php");
		exit;	
	}
	
if(isset($_COOKIE['login']) && ($_COOKIE['login']<>""))
{
$login_cookie = $_COOKIE['login']; 
$sql = mysqli_query($mysqli,"SELECT * FROM login where login like '$login_cookie'");
$linha = mysqli_fetch_array($sql);
$Nome				= $linha["funcionario"];
}
?><!doctype html>
<html lang="fr">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
  <title>SiGA</title>
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300italic,700,700italic">
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">
  <link rel="stylesheet" href="assets/css/milligram/milligram.min.css">
  <link rel="stylesheet" href="assets/css/omega.css">
  <link rel="stylesheet" href="assets/css/style.css">
  
</head>
<body id="app">
<?php include("menu.php");?>
<main>
    <section>
	Ol&aacute;: <?php echo $Nome;?>
</section>
<div class="container">
<p>&nbsp;&nbsp;&nbsp;&nbsp;<span class="chapter">Alterar senha</span></p>
<div class="bloc">
<div class="bloc--content">
<p>
 <?php 	
	include('conexao.php');
	session_start();

	if(!isset($_SESSION["login"]) || !isset($_SESSION["senha"])){
		header("Location: cuide.php");
		exit;	
	}
	
	if(isset($_COOKIE['login']) && ($_COOKIE['senha']<>""))
	{
	$login_cookie = $_COOKIE['login']; 
	$sql = mysqli_query($mysqli,"SELECT * FROM login where login like '$login_cookie'");
	$linha = mysqli_fetch_array($sql);
	$Nome				= $linha["funcionario"];
	$idd				    = $linha["id"];
	
	if($Nome==''){
		include('logout.php');
	}
	}
	?> 
<?php
	if($_POST)
	{
	$id       = $_POST['id'];
	$login    = $_POST['login'];
	$senha    = $_POST['senha'];
	$cntacto  = $_POST['contacto'];
	
	$cad = mysqli_query($mysqli,"UPDATE login SET login = '$login', senha = '$senha', contacto = $cntacto where id = $id");
	
	if ($cad != '')
		echo("<script language='javascript' type='text/javascript'>alert('Actualizados com sucesso!'); window.location.href='index.php?link=1'</script>");
	}
?>
	<script> 
	function confirmar() 
	{
		if(form.sa.value != form.sas.value){
		window.alert("As senhas sao diferentes");
		form.sas.value = "";
		//document.getElementById("senha").focus();
		//document.getElementById("senha").setAttribute("required","required");
	}
	}
</script>
	<form name="form" method="post" action="">
	<h3 style="color: red;">Por favor, antes de fazer alguma opera&ccedil;&atilde;o solicita-se que actualize os seus dados</h3>
	<br>
	<div class="form-group">
	<label for="usr">Nome do agente:</label>
	<input name="id" class="input" type="hidden" value="<?php echo $linha["id"]?>">
	<input name="nome" class="form-control" type="text" placeholder=" Nome do agente" value="<?php echo $linha["funcionario"]?>" readonly></div>	
	<div class="form-group">
	<label for="usr">Nome de usuario:</label>
	<input name="login" class="form-control" type="text" placeholder=" Nome de usuário" value="<?php echo $linha["login"]?>"></div>	
	<div class="form-group">
	<label for="usr">Contacto:</label>
	<input name="contacto" class="form-control" type="text" placeholder=" Nome de usuário" value="<?php echo $linha["contacto"]?>"></div>	
	<div class="form-group">
	<label for="usr">Senha actual:</label>
	<input name="sa" class="form-control" type="hidden" placeholder=" Senha" value="<?php echo $linha["senha"]?>" autocomplete="off" readonly>
	<input name="sas" class="form-control" type="password" id="senha" placeholder=" Senha" autocomplete="off" onBlur="confirmar()" required></div>
	<div class="form-group">
	<label for="usr">Nova senha:</label>
	<input name="senha" class="form-control" type="password" placeholder=" Nova Senha" autocomplete="off" required></div>
		
	<br>
	<div class="form-group">
	<input name="pgmr" class="btn btn-primary" name="enviar" type="submit" value="Actualizar">
	</div>
	</form>
	</p>
</div>
</div>
</main>
<footer>
  2019 <strong>acliven</strong> - <a href="https://www.acliven.it">www.acliven.it</a>
</footer>
<script defer src="https://use.fontawesome.com/releases/v5.8.1/js/all.js" integrity="sha384-g5uSoOSBd7KkhAMlnQILrecXvzst9TdC09/VM+pjDTCM+1il8RHz5fKANTFFb+gQ" crossorigin="anonymous"></script>
<script src="assets/js/omega.js"></script>
</body>
</html>