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

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

	//Efetuando busca avançada - se passado os parametros
	if(isset($_POST['pesquisar'])) {
		$ds_parametro	    = trim($_POST['ds_parametro']);
		$ds_valor	        = trim($_POST['ds_valor']);
		$ds_descricao	    = trim($_POST['ds_descricao']);


	    $consulta .= (!empty($ds_parametro)  	? " and ds_parametro     like '%$ds_parametro%'"      : '');
		$consulta .= (!empty($ds_valor)         ? " and ds_valor like '%$ds_valor%'"  : '');
		$consulta .= (!empty($ds_descricao)  	? " and ds_descricao   like '%$ds_descricao%'"    : '');

	}

?>
<div class="block">
  <div class="header">
  <h2>Parâmetros</h2>
  </div>
  <div class="content">
    <div class="table-responsive">
      <table class="table table-bordered table-striped table-responsible sortable">
        <thead>
          <tr>
            <th width=10%>ID</th>
            <th width=40%>Parâmetro</th>
			<th width=40%>Valor</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)){

						$id			= $registro['id'];
                        $id_crip	 	= base64_encode($id);
			  		    $ds_valor	    = $registro['ds_valor'];
						$ds_parametro	= $registro['ds_parametro'];

			echo "<tr>";
            echo "<td>$id</td>";
			echo "<td>$ds_parametro</td>";
            echo "<td>$ds_valor</td>";
            
            echo "<td class='text-center'><a href='erpc_parametros_edit.php?id=$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_parametros_remove.php?id=$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';?>
