<script type="text/javascript">
function verificaResposta(){
	var mensagem = $('#mensagem').val();
	if(mensagem == ""){ return false;} else { return true;}
}
</script>
<?php
$codigo = (!empty($_POST['codigo']) ? $_POST['codigo'] : "");
if($codigo != ""){
	include '../beans/GerenciadorHelpDesk.class.php';
	$helpdeskMB = new GerenciadorHelpDesk();
	$chamado = $helpdeskMB->getChamado($codigo);
	$mensagens = new Mensagem();
	if($chamado->getStatusChamado() == "1"){
		$mensagens = $helpdeskMB->getMensagem($codigo);
	} else {
		$mensagens = $helpdeskMB->getMensagens($codigo);
	}
	if($chamado->getStatusChamado() == '1'){ $status = "<span class=\"liberado\">NOVO</span>"; }
	else if($chamado->getStatusChamado() == '2'){ $status = "<span class=\"azul\">RECEBIDO</span>"; }
	else if($chamado->getStatusChamado() == '3'){ $status = "<span class=\"cinza\">FINALIZADO</span>"; }
	else if($chamado->getStatusChamado() == '4'){ $status = "<span class=\"bloqueado\">CANCELADO</span>"; }
	else if($chamado->getStatusChamado() == '5'){ $status = "<span>PENDENTE</span>"; }
	else if($chamado->getStatusChamado() == '6'){ $status = "<span class=\"amarelo\">ANDAMENTO</span>"; }
?>
<div align="right" class="formulario">
	<span class="ui-widget ui-widget-content ui-corner-all menus"><strong>Data envio : <span class="bloqueado"><?php echo $chamado->getDataEnvio(); ?></span></strong></span> 
	<span class="ui-widget ui-widget-content ui-corner-all menus"><strong>Status : <img src="../imagens/status/<?php echo $chamado->getStatusChamado(); ?>.png" align="absmiddle"/> <?php echo $status; ?></strong></span>
</div>
<div class="ui-widget ui-widget-content ui-corner-all menus formulario">
<table cellpadding="2">
	<tr><td align="right"><strong>Código :</strong></td><td><?php echo $chamado->getCodigo(); ?></td></tr>
    <tr><td align="right"><strong>Usuário :</strong></td><td><?php echo utf8_encode($chamado->getUsuario()); ?></td></tr>
    <tr><td align="right"><strong>Instituição :</strong></td><td><?php echo utf8_encode($chamado->getCliente()); ?></td></tr>
    <tr><td align="right"><strong>Sistema :</strong></td><td><?php echo utf8_encode($chamado->getSistema()); ?></td></tr>
    <tr><td align="right"><strong>Assunto :</strong></td><td><?php echo utf8_encode($chamado->getAssunto()); ?></td></tr>
    <tr><td>&nbsp;</td><td>&nbsp;</td></tr>
  </table>
  <strong>Mensagem :</strong>
  <div class="ui-widget ui-widget-content ui-corner-all menus">
  	<?php 
		if(!is_array($mensagens)){
			echo $mensagens->getMensagem();
		} else {
			foreach($mensagens as $msg){
				echo "<div class=\"ui-widget ui-widget-content ui-corner-all menus\">".$msg->getMensagem()."
					 <div align=\"right\" class=\"textoMini\">remetente: ".$msg->getRemetente().", enviada: ".$msg->getDataResposta()."</div></div>";
			}
		}
	?>
  </div>
</div>
<div class="ui-widget ui-widget-content ui-corner-all menus formulario" align="center">
<form action="../Servico.php" method="post" onSubmit="return verificaResposta();">
<input type="hidden" name="metodo" value="GerenciadorHelpDesk.addResposta"/>
<input type="hidden" name="chamado" value="<?php echo $chamado->getCodigo(); ?>"/>
<strong>Status :</strong>
<select name="status" id="status" class="ui-widget ui-widget-content">
<option value="<?php echo $chamado->getStatusChamado(); ?>"><?php echo $status; ?></option>
<option value="2">RECEBIDO</option>
<option value="6">ANDAMENTO</option>
<option value="5">PENDENTE</option>
<option value="4">CANCELADO</option>
<option value="3">FINALIZADO</option>
</select>
<div align="left"><strong>Resposta :</strong></div>
<table>
	<tr><td><textarea name="mensagem" id="mensagem" rows="3" cols="120" class="ui-widget ui-widget-content"></textarea></td></tr>
</table>
<button type="button" class="botao" onClick="javascript: $('#dialogChamado').dialog('close');"><span class="cancelar">Cancelar</span></button>
<button type="submit" class="botao"><span class="ok">Responder</span></button>
</form>
</div>
<?php } ?>