<?php
include 'header.php';
include 'erpc_municipios_toolbar.php'; //Nome da tabela _list.php
include_once 'connect.php';

// Método para post de Query Avançada
	$consulta = "select * from erpc_municipios where st_ativo = 1";

	//Efetuando busca avançada - se passado os parametros
	if(isset($_POST['pesquisar'])) {
		$id         = $_POST['id'];
		$ds_municipio	= trim($_POST['ds_municipio']);
		$ds_uf	= trim($_POST['ds_uf']);
		$ds_codigo_ibge	= trim($_POST['ds_codigo_ibge']);

	    $consulta .= (!empty($id)  ? " and id like '%$id%'"            : '');
	    $consulta .= (!empty($ds_municipio)  ? " and ds_municipio like '%$ds_municipio%'"            : '');
			$consulta .= (!empty($ds_uf)  ? " and ds_municipio like '%$ds_uf%'"            : '');
			$consulta .= (!empty($ds_codigo_ibge)  ? " and ds_municipio like '%$ds_codigo_ibge%'"            : '');

	}
?>

<div class="block">
  <div class="header">
  <h2>municipios</h2>
  </div>
  <div class="content">
    <div class="table-responsive">
      <table class="table table-bordered table-striped table-responsible sortable">
        <thead>
          <tr>
            <th width=20%>Cód. IBGE</th>
            <th width=60%>Descrição</th>
						<th width=10%>Estado</th>

            <th width=05%>Editar</th>
						<th width=05%>Excluir</th>
          </tr>
        </thead>
        <tbody>

          <?php

			$resultado = mysqli_query($conexao, $consulta) or die ($erro = mysqli_error($conexao));
			if (mysqli_num_rows($resultado)>0) {
            while ($registro = mysqli_fetch_assoc($resultado)){

            $ds_codigo_ibge	= $registro['ds_codigo_ibge'];
						$id_crip	 			= base64_encode($ds_codigo_ibge);
			  		$ds_municipio		= $registro['ds_municipio'];
						$ds_uf					= $registro['ds_uf'];


			    echo "<tr>";
            // echo "<td class='text-center'><input type='checkbox' /></td>";
            echo "<td>$ds_codigo_ibge</td>";
            echo "<td>$ds_municipio</td>";
						echo "<td>$ds_uf</td>";

            echo "<td class='text-center'><a href='erpc_municipios_edit.php?ds_codigo_ibge=$id_crip'>  <i class='glyphicon glyphicon-pencil' title='Editar'><span class='sr-only'>Editar</span></i></a></td>";
            echo "<td class='text-center'><a href='erpc_municipios_remove.php?ds_codigo_ibge=$id_crip'><i class='glyphicon glyphicon-remove' title='Remover'><span class='sr-only'>Remover</span></i></a></td>";
          echo "</tr>";
            }
          }
          ?>
        </tbody>
      </table>
    </div> <!-- table-responsive -->
  </div> <!-- content -->
</div> <!-- block -->

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