<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/templateControle.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>E-TIcons, empresa de tecnologia</title>
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<link rel="stylesheet" href="./../css/cssCliente.css" media="screen"/>
<link rel="stylesheet" href="./../jquery/skin.css" media="screen" />
<script type="text/javascript" src="./../jquery/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="./../jquery/jquery-ui-1.8.16.custom.min.js"></script>
</head>
<body>
<?php
/*session_id('siscontrole');*/
session_start();
$usuarioLogado = $_SESSION['usuarioRestrito'];
if($usuarioLogado == null or $usuarioLogado == ""){ header('location: ../clientes.php');} else {
$nivel = $_SESSION['nivelRestrito'];
?>
<div class="tudo">
  <div class="topoAdmin">
    <div class="topo_int">
      <div class="opcoes_topo">
        <form action="./../Servico.php" method="post">
          <input type="hidden" name="metodo" value="GerenciadorClientes.sair" />
          <ul>
            <li class="usuario" id="usuario"><?php echo utf8_encode($usuarioLogado); ?></li>
            <li class="separator"></li>
            <li><input type="image" src="./../imagens/exit.gif" title="sair" /></li>
            <li><a href="configuracoes.php" title="Configurações"><img src="./../imagens/config.gif" /></a></li>
            <li class="separator"></li>
            <li><a href="inicio.php" title="Inicio"><img src="./../imagens/home.gif"/></a></li>
          </ul>
        </form>
      </div>
      <!-- opcoes_topo -->
      <div class="logomarca"><img src="./../imagens/controleclientes.png"/></div>
    </div>
    <!-- topo_int --> 
  </div>
  <!-- topo -->
  <div class="menu_sup">
    <ul>
      <li><a href="inicio.php"><img src="./../imagens/home.png" align="absmiddle" /> Home</a></li>
      <li><a href="clientes.php"><img src="./../imagens/clientes.png" align="absmiddle" /> Clientes</a></li>
      <li style="display:<?php echo ($nivel == '2' ? 'block' : 'none'); ?>"><a href="usuarios.php"><img src="./../imagens/usuarios.png" align="absmiddle" /> Usuários</a></li>
      <li><a href="chamados.php"><img src="./../imagens/chamados.png" align="absmiddle" /> Chamados</a></li>
      <li style="display:<?php echo ($nivel == '2' ? 'block' : 'none'); ?>"><a href="registros.php"><img src="./../imagens/registros.gif" align="absmiddle" /> Registros</a></li>
    </ul>
    <div class="titulo_pagina"><!-- InstanceBeginEditable name="titulo" --><div class="ui-widget ui-widget-content ui-corner-all titulo">Todos os Chamados</div><!-- InstanceEndEditable --></div>
  </div>
  <!-- menu_sup -->
  <div class="conteudo"><!-- InstanceBeginEditable name="conteudo" -->
  <script type="text/javascript" src="../../jquery/jquery.maskedinput-1.3.min.js"></script>
  <script type="text/javascript">
  	$(function(){
		$('#data').datepicker({dateFormat:'dd/mm/yy',showOn:"button",buttonImage:"../imagens/calendar.png",buttonImageOnly:true });
		$("#data").mask("99/99/9999");
		$('#todos').button();
		$('#dialogChamado').dialog({autoOpen: false, width: 700, modal:true});
	});
	function verificarCampos(){
		var valor = $('#valor').val();
		var tipo = $('#tipo').val();
		if(valor != "" && tipo == ""){
			alert('Selecione ao menos um tipo de busca!');
			return false;
		} else { return true;}
	}
	function visualizarChamado(codigo){
		$('#dialogChamado').dialog('open');
		$.post('detalheChamado.php',{codigo:codigo},function(data){ $('#chamado').html(data); $('#dialogChamado').dialog('open');});
	}
  </script>
  <div class="formulario">
  <div style="overflow:hidden">
  <button type="button" onclick="javascript: window.location='meusChamados.php'" class="botao"><span class="buscar">Meus Chamados</span></button>
  <img src="../imagens/status/legenda.jpg" align="right"/></div>
<?php
include '../beans/GerenciadorHelpDesk.class.php';
$service = ServiceMessages::getInstancia();
if($service->getMensagem() != ""){
	echo "<div class=\"ui-widget\">
		  <div class=\"ui-state-highlight  ui-corner-all mensagem\" style=\"padding: 0pt 0.7em;\">
		  <p><span class=\"ui-icon ui-icon-info\" style=\"float: left; margin-right: 0.3em;\"></span> 
		  <strong>".utf8_encode($service->getMensagem())."</strong></p></div></div>";
}
$service->destroy();
?>
  	<div class="ui-widget ui-widget-content ui-corner-all menu_extra">
    <?php
	$valor = (!empty($_REQUEST['valor']) ? $_REQUEST['valor'] : "");
	$sistema = (!empty($_REQUEST['sistema']) ? $_REQUEST['sistema'] : "");
	$data = (!empty($_REQUEST['data']) ? $_REQUEST['data'] : "");
	$todos = (!empty($_REQUEST['todos']) ? $_REQUEST['todos'] : "");
	$status = (!empty($_REQUEST['status']) ? $_REQUEST['status'] : "");
	?>
  	<form action="chamados.php" method="get" onsubmit="return verificarCampos();">
    	<table>
        	<tr>
            <td>Busca:</td><td><input type="text" name="valor" id="valor" class="ui-widget ui-widget-content ui-corner-right campoLogin" value="<?php echo $valor; ?>"/></td>
            <td>Sistema:</td><td><select name="sistema" id="sistema" class="ui-widget ui-widget-content campoSelect">
            	<option value="">...</option>
                <?php
					$helpdeskMB = new GerenciadorHelpDesk();
					$sistemas = $helpdeskMB->getSistemas();
					foreach($sistemas as $s){
						if($s->getId() == $sistema){ $sistem = $s; break; } else { $sistem = new Sistema(); }
					}
					foreach($sistemas as $sis){
						if($sis->getId() == $sistem->getId()){
							echo "<option value=\"".$sistem->getId()."\" selected>".utf8_encode($sistem->getNome())."</option>";
						} else { echo "<option value=\"".$sis->getId()."\">".utf8_encode($sis->getNome())."</option>"; }
					}
				?>
                </select></td>
            <td>Status:</td><td><select name="status" id="status" class="ui-widget ui-widget-content campoSelect">
            		<option value="">...</option>
            		<?php 
						$statuss = array(1=>"Novo",2=>"Recebido",3=>"Finalizado",4=>"Cancelado",5=>"Pendente",6=>"Andamento");
						foreach($statuss as $i => $s){
							if($status == $i) { echo "<option value=\"".$status."\" selected>".$s."</option>"; }
							else { echo "<option value=\"".$i."\">".$s."</option>"; }
						}
					?>
            	</select></td>
            <td>Data:</td><td><input type="text" name="data" id="data" maxlength="10" size="10" value="<?php echo $data; ?>"/></td>
            <td></td><td></td>
            <td><input type="checkbox" id="todos" name="todos" value="todos" <?php echo ($todos != "" ? "checked" : ""); ?>/><label for="todos">Todos</label></td>
            	<td align="right"><button type="submit" class="botao"><span class="buscar">Buscar</span></button></td>
            </tr>
        </table>
    </form>
    </div>
    
<?php
if($valor != "" || $sistema != "" || $data != "" || $status != "" || $todos != ""){
	$chamados = $helpdeskMB->buscaChamados($valor, $sistema, $data, $status, $todos);
} else { $chamados = array(); }
?>  
<div class="sistemas" id="chamados">
<ul>
<?php
foreach($chamados as $c){
	echo "<li class=\"ui-widget ui-widget-content ui-corner-all\">
			<div class=\"arquivo\"><img src=\"../imagens/status/".$c->getStatusChamado().".png\"/>
				<span class=\"titulo\">".utf8_encode($c->getUsuario())."</span><br />".utf8_encode($c->getCliente())."
		  	<div class=\"data\">".utf8_encode($c->getDataEnvio())."</div></div>
			<div class=\"download\"><div class=\"versao\"><span class=\"miniTexto\">Código:</span> ".$c->getCodigo()."
			<br /><span class=\"miniTexto\">Sistema:</span> ".utf8_encode($c->getSistema())."</div>
			<img src=\"../imagens/alterar.png\" title=\"Alterar chamado\" onclick=\"visualizarChamado(".$c->getCodigo().");\"/></div></li>";
}
?>
</ul>
</div>
</div>

<div id="dialogChamado" title="Detalhe do chamado">
<p id="chamado">Aguarde...</p>
</div>
  <!-- InstanceEndEditable --></div>
  <!-- conteudo --> 
</div>
<!-- tudo --> 
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-27091929-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
</script>
<?php } ?>
</body>
<!-- InstanceEnd --></html>