<? 
include_once("valida_sessao.php");
protegePagina(); 
include_once("adm_head.php");
?>

<span class="dir">Alterar Senha</span>
</div>

<div id="conteudo">

<?
include("config.php");

if (isset($_POST['submit'])) {

$id = $_POST['id'];
$senha = $_POST['senha'];
	
   include("utf8.php");
   
   $insere = "UPDATE usuarios SET senha = md5('$senha') WHERE ID = $id";
   mysqli_query($conn, $insere);
   mysqli_close($conn);   
   
   $local = "alterar_senha.php?id=".$id."&alterado=1";
   echo "<script>location.href='$local';</script>";
   
?>

<?
} else {
	
if(isset($_GET['alterado'])){
	echo "<p class=\"sucesso\">Alterado Com Sucesso!</p>";
}

$id = $_SESSION['usuarioID'];

include("utf8.php");

$qry = "SELECT * FROM usuarios WHERE id = $id";
$consulta = mysqli_query($conn, $qry);
$result = mysqli_fetch_array($consulta);

?>

<form name="frmsenha" method="POST" action="alterar_senha.php" onSubmit="return valida(this);">
  <table align="center" cellspacing="0" cellpadding="0">
          <tr>            
            <td>
            <img src="imagem/importante.gif" />
            Nova Senha <br />
            <input type="password" name="senha" size="40" /></td>
          </tr>  
          <tr>            
            <td>
            <img src="imagem/importante.gif" />
            Confirmar Nova Senha <br />
            <input type="password" name="senha2" size="40" /></td>
          </tr>
          <tr>
            <td align="center">
            <input type="hidden" value="<?=$id?>" name="id" />  
              <input type="submit" value="Salvar" class="botao" name="submit" /></td>
          </tr>
        </table>
</form>
<?php
}
mysqli_close($conn);
?>
</div>
<? include_once("adm_foot.php"); ?>

