<?php
include '../config.php';
include '../configuracao/modelo.php';
$message = isset($_GET['msg']) ? htmlspecialchars($_GET['msg'], ENT_QUOTES, 'UTF-8') : '';

?>
<style type="text/css">
.tg  {border-collapse:collapse;border-color:#93a1a1;border-spacing:0;margin:0px auto;}
.tg td{background-color:#fdf6e3;border-color:#93a1a1;border-style:solid;border-width:1px;color:#002b36;
  font-family:Arial, sans-serif;font-size:14px;overflow:hidden;padding:10px 5px;word-break:normal;}
.tg th{background-color:#657b83;border-color:#93a1a1;border-style:solid;border-width:1px;color:#fdf6e3;
  font-family:Arial, sans-serif;font-size:14px;font-weight:normal;overflow:hidden;padding:10px 5px;word-break:normal;}
.tg .tg-ul38{position:-webkit-sticky;position:sticky;text-align:left;top:-1px;vertical-align:top;will-change:transform}
.tg .tg-0lax{text-align:left;vertical-align:top}
.tg .tg-kqm2{background-color:#ff0000;text-align:center;vertical-align:top}
.tg-sort-header::-moz-selection{background:0 0}
.tg-sort-header::selection{background:0 0}.tg-sort-header{cursor:pointer}
.tg-sort-header:after{content:'';float:right;margin-top:7px;border-width:0 5px 5px;border-style:solid;
  border-color:#404040 transparent;visibility:hidden}
.tg-sort-header:hover:after{visibility:visible}
.tg-sort-asc:after,.tg-sort-asc:hover:after,.tg-sort-desc:after{visibility:visible;opacity:.4}
.tg-sort-desc:after{border-bottom:none;border-width:5px 5px 0}@media screen and (max-width: 767px) {.tg {width: auto !important;}.tg col {width: auto !important;}.tg-wrap {overflow-x: auto;-webkit-overflow-scrolling: touch;margin: auto 0px;}}</style>
<div class="tg-wrap"><table id="tg-dBc64" class="tg" style="width:100%">
<thead>
      <tr>
       <td class="tg-message" colspan="5"><?php echo $message; ?></td>
      </tr>
      <tr>
	   <td class="tg-rules" colspan="5">

		 		Regras para nome de Campo:  
				(1) Mínimo de 2 a 25 caracteres  
				(2) Caracteres válidos: "a-z", "0-9", "_"  
				(3) Campos padrão: codigo, ativo, enumsistema, data
		</td>
	  </tr>

  <tr>
    <th class="tg-0lax" colspan="2" >
    Nome Campo<br>
    <form action="executa.php" method="GET" >
    <input  name="nomecampo" style="width:97%;background-color:#FFFFE0;" value=""  pattern="[a-z0-9_]{2,25}"+type="text"   required>
    <input type="hidden" name="tabela" value="<?php echo $_GET['tabela']?>" >
		<input type="hidden" name="acao" value="adicionarcampo" >
    </th>
    <th class="tg-0lax" colspan="2">
    Tipo Campo<br>
    <select name="vlr_filtro" style="width:99%;background-color:#FFFFE0;">
    <?php
    $stmt = $mysqli->prepare("SELECT dominio_tipo,dominio_tipo_n FROM dominio where ativo='S' order by dominio_tipo");
    $stmt->execute(); // Executa a query preparada.
    $stmt->store_result();
    $stmt->bind_result($codigo_tab,$codigo_tab_n);
    while ($stmt->fetch()){  
    echo"<option value=\"$codigo_tab_n-$codigo_tab\">".$codigo_tab_n."-".$codigo_tab."</option>";}
    echo"</select>";?>    
    </th>
    <th class="tg-ul38"><BR>
    <input type="submit" value="Inserir" style="width:95%" > 
    </form>
    </th>
  </tr>
</thead>
<tbody>
   <?php
    $stmt = $mysqli->prepare("SELECT campo_nome,campo_tipo FROM campo WHERE  campo_tabela = '".$_GET['tabela']."' order by campo_nome;");
    $stmt->execute(); // Executa a query preparada.
    $stmt->store_result();
    $stmt->bind_result($codigo_tab,$data);
    while ($stmt->fetch()){?>
    <tr>
    <td class="tg-0lax" colspan="2">
    <input  name="tabela" style="width:95%"  value="<?php echo $codigo_tab?>" type="text" disabled>
    </td>
    <td class="tg-0lax">
    <input  name="tabela" style="width:95%"  value="<?php echo $data?>" type="text" disabled>
    </td>
    <td class="tg-0lax">
    <form action="executa.php" method="GET" >
    <input type="hidden" name="nomecampo" value="<?php echo $codigo_tab?>" >
    <input type="hidden" name="tabela" value="<?php echo $_GET['tabela']?>" >
		<input type="hidden" name="acao" value="apagacampo" >
    <input type="submit" value="Apagar" style="width:100%" class="botared">
    </form>
    </td>
    <td class="tg-0lax">
    <form action="camp_config.php" method="GET">
    <input type="hidden" name="nomecampo" value="<?php echo $codigo_tab?>" >
    <input type="hidden" name="tabela" value="<?php echo $_GET['tabela']?>" >
    <input type="submit" value="Config" style="width:100%" class="botared">
    </form>
    </td>
  </tr>
    <?php } ?>
  <tr>
    <td class="tg-kqm2" colspan="5">FIM</td>
  </tr>
</tbody>
</table></div>
