<?php
include 'topo.php';

$msg = "";
$msgClass = "msgErro";
$titulo = "Configurações > Assunto > Alterar";
$pg_voltar = "assunto.php";
$msg_ok = "Alterado com sucesso";
$msg_erro = "Erro ao alterar";
$nomeClasse = "assunto";

##########################
# carregar
##########################
if(isPost($_REQUEST['id'])){
	$obj = new Assunto();
	$obj->id = $_REQUEST['id'];
	$obj->carregar();
}

##########################
# alterar
##########################
if(isPost($_POST['ok'])){
	$obj->carga($_POST[$nomeClasse]);
	if($obj->alterar()){
		$msg = $msg_ok;
		$msgClass = "msgSucesso";
	}
	else{
		$msg = $msg_erro;
	}
}

##########################
# carga inicial do post
##########################
$arrAtributos = ${"arrinforz2$nomeClasse"};
foreach($arrAtributos[INFOCAMPOS] as $atributo){
	if(!isset($_POST[$nomeClasse][$atributo])) $_POST[$nomeClasse][$atributo] = $obj->{$atributo};
}
?>

<h1><?=$titulo?></h1>

<div class="boxAcao">
	<ul>
		<li class="border-none"><a href="<?=URLADMIN.$pg_voltar?>" title="Voltar">> Voltar</a></li>
	</ul>
</div>

<?php include PATHADMIN.'msg.php'; ?>

<div class="boxForm">
	<div class="boxTitulo">Alterar</div>
	<form name="form1" id="form1" action="" method="post">
		<div class="campo3">
			<label for="nome">Nome: <span>(*)</span></label>
			<input class="" type="text" id="nome" name="<?=$nomeClasse?>[nome]" value="<?=$_POST[$nomeClasse]['nome']?>" req="1" />
		</div>
		<div class="campo3 align-right">
			<span class="campo_obrigatorio">(*) Campos obrigatórios</span>
		</div>
		<div class="campo3 align-right">
			<input type="submit" class="botao" name="ok" value="Salvar" title="Salvar" validar="1" />
		</div>
		<input type="hidden" name="id" value="<?=$_REQUEST['id']?>" />
	</form>
</div>

<?php
include 'rodape.php';
?>