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

<span class="dir">Editar Templates</span>
</div>


<div id="conteudo">

<?php
include("config.php");

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

$id = $_POST['id'];

$nome = $_POST['nome'];
$texto = addslashes($_POST['texto']);
	
   include("utf8.php");
   
   $update = "UPDATE ctd_templates SET t_nome = '$nome', t_texto = '$texto' WHERE t_id = $id";
   mysqli_query($conn, $update);
   mysqli_close($conn);
      
   $local = "ctd_template_alt.php?id=".$id."&alterado=1";
   echo "<script>location.href='$local';</script>";
?>

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

$id = $_GET['id'];

include("utf8.php");

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

?>

<form name="frmbloco" method="POST" action="<?=$_SERVER['PHP_SELF']?>" onSubmit="return valida_template(this);">
  <table align="center" cellspacing="0" cellpadding="0" class="form">
    	  <tr>
            <td>
			Código(ID):
			<?=$result['t_id']?>            
            </td>
          </tr>          
          <tr>            
            <td>
            <img src="imagem/importante.gif" />
            Nome <br />
            <input type="text" name="nome" value="<?=$result['t_nome']?>" maxlength="30" />
            </td>
          </tr>          
          <tr>
            <td>            
            Texto <br />
            <textarea rows="26" name="texto"><?=stripslashes($result['t_texto'])?></textarea>
            </td>
          </tr>
          <tr>
            <td colspan="2" align="center">
            <input type="hidden" value="<?=$id?>" name="id" />
              <input type="button" value="Voltar" name="voltar" onclick="location.href='ctd_template_adm.php'" />
              <input type="submit" value="Salvar" name="submit" /></td>
          </tr>
        </table>
</form>
<?php
}
mysqli_close($conn);
?>
</div>
<? include_once("adm_foot.php"); ?>