<!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">Usuários</div><!-- InstanceEndEditable --></div>
  </div>
  <!-- menu_sup -->
  <div class="conteudo"><!-- InstanceBeginEditable name="conteudo" -->
  <?php if($nivel == '0' || $nivel == '1'){ header('location: inicio.php'); } ?>
  <script type="text/javascript">
  	$(function(){ 
		$('#radios').buttonset(); 
		$('#todos').button(); 
		$('#checks').buttonset();
		$('#niveis').buttonset(); 
		$('#dialogInativarUser').dialog({autoOpen: false, width: 500, modal:true});
		$('#dialogAtivarUser').dialog({autoOpen: false, width: 500, modal:true});
		$('#dialogLiberarUser').dialog({autoOpen: false, width: 500, modal:true});
		$('#dialogBloquearUser').dialog({autoOpen: false, width: 500, modal:true});
	});
	function inativarUsuario(id){
		$('#idUsuarioExc').val(id);
		$('#dialogInativarUser').dialog('open');
	}
	function ativarUsuario(id){
		$('#idUsuarioAti').val(id);
		$('#dialogAtivarUser').dialog('open');
	}
	function bloquearUsuario(id){
		$('#idUsuarioBloq').val(id);
		$('#dialogBloquearUser').dialog('open');
	}
	function liberarUsuario(id){
		$('#idUsuarioLib').val(id);
		$('#dialogLiberarUser').dialog('open');
	}
  </script>
  <div class="formulario">
  <div class="ui-widget ui-widget-content ui-corner-top menu_extra">
  <?php
  $nome = (!empty($_REQUEST['nome']) ? $_REQUEST['nome'] : "");
  $status = (!empty($_REQUEST['status']) ? $_REQUEST['status'] : "");
  $liberado = (!empty($_REQUEST['liberado']) ? $_REQUEST['liberado'] : "");
  $todos = (!empty($_REQUEST['todos']) ? $_REQUEST['todos'] : "");
  ?>
  	<form action="usuarios.php" method="get">
    <table cellpadding="3">
    	<tr><td>Nome:</td><td><input type="text" name="nome" id="nomeBusca" class="ui-widget ui-widget-content ui-corner-all campoLogin" value="<?php echo $nome;?>"/></td>
            <td>Ativo:</td><td id="radios"><input type="radio" name="status" id="statusA" value="Ativo" <?php echo ($status == "Ativo" ? "checked" : ""); ?>/><label for="statusA">Sim</label><input type="radio" name="status" id="statusI" value="Inativo" <?php echo ($status == "Inativo" ? "checked" : ""); ?>/><label for="statusI">Não</label></td>
            <td>Liberado:</td><td id="checks"><input type="radio" name="liberado" id="liberadoS" value="S" <?php echo ($liberado == "S" ? "checked" : ""); ?>/><label for="liberadoS">Sim</label><input type="radio" name="liberado" id="liberadoN" value="N" <?php echo ($liberado == "N" ? "checked" : ""); ?>/><label for="liberadoN">Não</label></td>
            <td><input type="checkbox" id="todos" name="todos" value="todos" <?php echo ($todos != "" ? "checked" : ""); ?>/><label for="todos">Todos</label></td>
        	<td><button type="submit" class="botao"><span class="buscar">Buscar</span></button></td>
        </tr>
    </table>
   </form>
 </div>
<?php
include '../beans/GerenciadorClientes.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();

$clienteMB = new GerenciadorClientes();
if($nome != "" || $status != "" || $liberado != "" || $todos != ""){
	$usuarios = $clienteMB->buscarUsuarios($nome, $status, $liberado, $todos);
} else { $usuarios = array(); }
  ?> 
  <div class="ui-widget ui-widget-content ui-corner-bottom menu_extra">
  <div class="menu_extra_esq">
    <span class="miniTexto">Total :</span> (<strong> <?php echo count($usuarios); ?> </strong>)
  </div>
</div>
<div class="sistemas">
<ul>
<?php
foreach($usuarios as $u){
	echo "<li class=\"ui-widget ui-widget-content ui-corner-all\">
			<div class=\"arquivo\">";
	if($u->getLiberado() == "N") { echo "<img src=\"../imagens/N.png\"/>"; }
	else { echo "<img src=\"../imagens/S.png\"/>"; }
	echo "<span class=\"titulo\">".utf8_encode($u->getNome())."</span><br />".$u->getUsuario()."
	    	<div class=\"data\">Liberado: ".$u->getLiberado()."</div></div>
		<div class=\"download\"><div class=\"versao\"><span class=\"miniTexto\">Status:</span><br />".$u->getStatusUsuario()."</div>";
	if($u->getStatusUsuario() == "Ativo"){ echo "<img src=\"../imagens/inativar.png\" title=\"Excluir\" onclick=\"inativarUsuario(".$u->getId().")\"/>"; }
	else { echo "<img src=\"../imagens/ativar.png\" title=\"Ativar\" onclick=\"ativarUsuario(".$u->getId().")\"/>";}
	if($u->getLiberado() == "N") { echo "<img src=\"../imagens/liberar.png\" title=\"Liberar\" onclick=\"liberarUsuario(".$u->getId().")\"/>"; }
	else { echo "<img src=\"../imagens/bloquear.png\" title=\"Bloquear\" onclick=\"bloquearUsuario(".$u->getId().")\"/>"; }			
	echo "</div></li>";
}
?>
</ul>
</div>
</div>

<div id="dialogBloquearUser" title="Bloquear usuário">
<p>Você tem certeza que deseja bloquear este usuário?</p>
<form id="formBloqUser" action="../Servico.php" method="post">
<input type="hidden" name="metodo" value="GerenciadorClientes.bloquearUsuario" />
<input type="hidden" name="id" id="idUsuarioBloq" />
<div class="ui-widget ui-widget-content ui-corner-all" align="center">
<button type="button" class="botao" onclick="javascript: $('#dialogBloquearUser').dialog('close');"><span class="excluir">Fechar</span></button>
<button type="submit" class="botao"><span class="cancelar">Bloquear</span></button>
</div>
</form>
</div>

<div id="dialogInativarUser" title="Inativar usuário">
<p>Você tem certeza que deseja inativar este usuário?</p>
<form id="formExcUser" action="../Servico.php" method="post">
<input type="hidden" name="metodo" value="GerenciadorClientes.inativarUsuario" />
<input type="hidden" name="id" id="idUsuarioExc" />
<div class="ui-widget ui-widget-content ui-corner-all" align="center">
<button type="button" class="botao" onclick="javascript: $('#dialogInativarUser').dialog('close');"><span class="cancelar">Cancelar</span></button>
<button type="submit" class="botao"><span class="ok">Inativar</span></button>
</div>
</form>
</div>

<div id="dialogAtivarUser" title="Ativar usuário">
<p>Você tem certeza que deseja Ativar este usuário?</p>
<form id="formAtiUser" action="../Servico.php" method="post">
<input type="hidden" name="metodo" value="GerenciadorClientes.ativarUsuario" />
<input type="hidden" name="id" id="idUsuarioAti" />
<div class="ui-widget ui-widget-content ui-corner-all" align="center">
<button type="button" class="botao" onclick="javascript: $('#dialogAtivarUser').dialog('close');"><span class="cancelar">Cancelar</span></button>
<button type="submit" class="botao"><span class="ok">Ativar</span></button>
</div>
</form>
</div>

<div id="dialogLiberarUser" title="Liberar usuário">
<form id="formLibUser" action="../Servico.php" method="post">
<input type="hidden" name="metodo" value="GerenciadorClientes.liberarUsuario" />
<input type="hidden" name="id" id="idUsuarioLib" />
<strong>Nível:</strong>
<p>
<div align="center" id="niveis">
<input type="radio" name="nivel" id="nivelPadrao" value="0" checked="checked"/><label for="nivelPadrao">Padrão</label>
<input type="radio" name="nivel" id="nivelInter" value="1"/><label for="nivelInter">Intermediário</label>
<input type="radio" name="nivel" id="nivelAdm" value="2"/><label for="nivelAdm">Administrador</label>
</div>
</p>
<div class="ui-widget ui-widget-content ui-corner-all" align="center">
<button type="button" class="botao" onclick="javascript: $('#dialogLiberarUser').dialog('close');"><span class="cancelar">Cancelar</span></button>
<button type="submit" class="botao"><span class="ok">Liberar</span></button>
</div>
</form>
</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>