<?php
include 'header.php';
include 'erpc_cfop_toolbar.php';
include 'connect.php';

$ds_cfop_crip = $_GET['ds_cfop'];
$ds_cfop = base64_decode($ds_cfop_crip);
?>

<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
  <li role="presentation" class="active"><a href="#form1" aria-controls="form1" role="tab" data-toggle="tab">Dados Cadastrais</a></li>
  <!--
  <li role="presentation"><a href="#form2" aria-controls="form2" role="tab" data-toggle="tab">Form #2</a></li>
  <li role="presentation"><a href="#form3" aria-controls="form3" role="tab" data-toggle="tab">Form #3</a></li>
  <li role="presentation"><a href="#form4" aria-controls="form4" role="tab" data-toggle="tab">Form #4</a></li>
  -->
</ul>

<!-- Tab panes -->
<div class="tab-content">
  <div role="tabpanel" class="tab-pane fade in active" id="form1">
  <form id=validate_custom method=POST action="erpc_cfop_ws.php">
  <input type="hidden" value="<?php echo $ds_cfop; ?>" name="id" id="id">

  <div class=block>
    <div class=header>
      <h1>Editar cfop : <?echo $ds_cfop;?></h1>
      <div class="side pull-right"> <button class="btn btn-default btn-clean" onClick="clear_form('#validate_custom');" type=button>Clear form</button>      </div>
    </div>

    <div class="content controls">
	<?php
		$consulta = "select * from erpc_cfop where ds_cfop = '$ds_cfop' and st_ativo =1";

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

			  $ds_titulo	= $registro['ds_titulo'];
              $id_categoria=rtrim($registro['id_categoria']);
              $ds_complementar_nfe=$registro['ds_detalhe'];

			}
		}
	?>
	<div class=form-row>
        <div class=col-md-3>Título do cfop:</div>
        <div class=col-md-6><input type=text name="ds_cfop" value="<? echo $ds_titulo?>" class="form-control" class="validate[required]" maxlength=100 /> </div>
    </div>

    <div class="form-row">
        <div class="col-md-3">Categoria:</div>
        <div class="col-md-6">
          <select id="id_categoria" type=text name="id_categoria" class="form-control" class="validate[required]">
          <?php
          //echo "*** Função sgcws_combo_table não está setando o valor : $id_categoria";
            
          $sql = "select * from erpc_cfop_categorias where st_ativo = 1";
          $result = mysqli_query($conexao, $sql) or die (mysqli_error($conexao));
          if(mysqli_num_rows($result) > 0){
              while($registro = mysqli_fetch_assoc($result)){
                  $id_cat = $registro['id'];
                  $ds_categoria = $registro['ds_categoria'];
                  if($id_cat == $id_categoria) {
                      echo "<option selected value=$id_cat>$ds_categoria</Option>";
                  }else{
                      echo "<option value=$id_cat>$ds_categoria</Option>";
                  }
                  
                  
              }
          }
          //  $name, $id, $valorAtual, $table, $keyField, $valueField, $where='st_ativo=1', $canBeEmpty=true
          //sgcws_combo_table( 'id_categoria', 'id_categoria',$id_categoria, 'erpc_cfop_categorias', 'id', 'ds_categoria', '', false);
          ?>
          </select>
        </div>
    </div>

    <div class="form-row">
      <div class="col-md-3">Informações Complementar para Nfe:</div>
      <div class="col-md-6">
        <textarea rows="4" required type=text name="ds_complementar_nfe" class="form-control" maxlength=5000/>
        	<?php echo rtrim($ds_complementar_nfe);?>
		</textarea>
      </div>
    </div>

    <div class=footer>
      <div class="side pull-right">
        <div class=btn-group>
          <button class="btn btn-success" type="submit" value="editar" onClick="$('#validate_custom').validationEngine('hide');" name="editar">EDITAR</button>
          <button class="btn btn-default" type="button" onClick="window.history.go(-1)" value="Voltar">Voltar</button>

			  <!--botao antigo
		<button class="btn btn-default" type=button onClick="$('#validate_custom').validationEngine('hide');">Hide prompts</button>            <button class="btn btn-success" type=submit>Submit</button>
		-->
		</div>
      </div>
    </div>
  </div>
</form>

  </div>

</div>

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