<?php require_once('../topo.php');?>
<?php require_once('../lateral.php');?>
<br><br><br>
<?php
//GERADOR DE CAMPOS POST

//echo GerarCamposPost("categorias", "linha_categorias");

$idservicosubcategoria		= $_GET['idservicosubcategoria'];

if($idservicosubcategoria == ""){
	$acao		 	= "Salvar";
}else{
	$acao 			= "Alterar";	
}

//Recebe Ação
$acao_bd		    = $_GET['acao'];
$acao_bd		   .= $_POST['acao'];

//Recebendo Dados do Formulário

$idservicosubcategoria .= $_POST['idservicosubcategoria'];
$titulo = $_POST['titulo'];


//Dados da Tabela
$tabela                 ="servicos_subcategorias";
$campos_tabela = "titulo,idfilial";

$campos_value = "'$titulo', '".$_SESSION['idfilial_usuario']."'";

//INSERIR REGISTROS
if($acao_bd == "Salvar"){
	$salvar = Salvar($tabela,  $campos_tabela, $campos_value);

// RETORNA ULTIMO ID INSERIDO
	$id_insert = mysql_insert_id();
	$redireciona = VerificaSql($salvar, "listar_subcategorias.php", "listar_subcategorias.php");
}

//ATUALIZANDO REGISTRO
if($acao_bd == "Alterar"){

$campos_alterar = "titulo='$titulo', idfilial='".$_SESSION['idfilial_usuario']."'";

    $atualizar = Alterar($tabela, $campos_alterar, "idservicosubcategoria", $idservicosubcategoria);
	$redireciona = VerificaSql($atualizar, "manutencao_subcategorias.php?idservicosubcategoria=".$idservicosubcategoria."", "manutencao_subcategorias.php?idservicosubcategoria=".$idservicosubcategoria."");
}

//EXCLUINDO REGISTRO
if($_GET['excluir'] == "sim"){
    $deletar = Excluir($tabela, "idservicosubcategoria", $idservicosubcategoria);	
	$redireciona = VerificaSql($deletar, "listar_subcategorias.php", "manutencao_subcategorias.php?idservicosubcategoria=".$idservicosubcategoria."");
} 


if($acao == "Alterar"){

	$selecionar_subcategorias = Seleciona("servicos_subcategorias", "WHERE idservicosubcategoria='".$idservicosubcategoria."'", "") or die(mysql_error());
	while($linha_subcategorias=mysql_fetch_array($selecionar_subcategorias)){
		
$titulo = $linha_subcategorias['titulo']; 
	}
}
?>
<script type="text/javascript">
function EnviarFormulario()
{
    document.forms["cadastro"].submit();
}
</script>
<table width="100%" border="0" cellspacing="0" cellpadding="2">
  <tbody>
    <tr>
      <td valign="top"><table width="100%" border="0" align="center" cellpadding="5" cellspacing="0">
        <tr>
          <td colspan="2"><table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td height="40" class="TituloPagina" style="padding-left: 5px;">INFORMAÇÃO DA SUBCATEGORIA</td>
              <td align="left" class="TituloPagina" style="padding-left: 5px;"><table width="100" border="0" align="right" cellpadding="2" cellspacing="0">
                <tr>
                  <td width="167" align="left"><table width="190" border="0" cellspacing="0" cellpadding="2" class="BoxMenuAzul" onclick="location.href='listar_subcategorias.php';">
                    <tr>
                      <td height="25" align="center" class="TextoMenuCinza"><img src="img/icone_novo.gif" width="29" height="21" /></td>
                      <td align="left"><span class="TextoMenuBranco" style="font-weight:normal; color:#FFF;">Todas as SubCategorias</span></td>
                      </tr>
                    </table></td>
                  <td width="150" align="left"><table width="170" border="0" cellspacing="0" cellpadding="2" class="BoxMenuAzul" onclick="location.href='manutencao_subcategorias.php';">
                    <tr>
                      <td height="25" align="center" class="TextoMenuCinza"><img src="img/icone_novo.gif" width="29" height="21" /></td>
                      <td align="left"><span class="TextoMenuBranco" style="font-weight:normal; color:#FFF;">Nova SubCategoria</span></td>
                      </tr>
                    </table></td>
                  <td width="125" align="left">&nbsp;</td>
                  <td width="370" align="right"><table width="180" border="0" align="right" cellpadding="0" cellspacing="0" class="BoxMenuBranco">
                    <form method="post" action="listar_subcategorias.php" enctype="multipart/form-data">
                      <tr>
                        <td width="148" align="left" bgcolor="#FFFFFF"><input type="text" name="busca" id="busca" style="width: 100%; height: 20px;" class="InputBranco" /></td>
                        <td width="28" align="center" bgcolor="#FFFFFF"><input type="image" src="img/icone_buscar.gif" /></td>
                        </tr>
                      </form>
                    </table></td>
                  </tr>
                </table></td>
              <td align="right">&nbsp;</td>
              <td width="80" align="right" style="padding-right: 8px;"><table width="70" border="0" cellspacing="0" cellpadding="2" class="BoxMenuCinza" onclick="history.go(-1);">
                <tr>
                  <td height="25" align="center" class="TextoMenuBranco">Voltar</td>
                  </tr>
                </table></td>
              </tr>
            </table></td>
        </tr>
        <!-- INICIO FORM -->
        <form name="cadastro" id="cadastro" method="post" action="manutencao_subcategorias.php" enctype="multipart/form-data">
          <input type="hidden" name="acao" value="<?php echo $acao;?>">
          <input type="hidden" name="idservicosubcategoria" value="<?php echo $idservicosubcategoria;?>">
          <tr>
            <td width="50%" valign="top" bgcolor="#D9D9D9"><table width="100%" border="0" cellspacing="0" cellpadding="4">
              <tr>
                <td valign="top"><strong>INFORMAÇÕES DA SUBCATEGORIA</strong></td>
              </tr>
              <tr>
                <td valign="top"><!-- INICIO DIV -->
                  <table width="100%" border="0" cellspacing="0" cellpadding="7">
                    <tr>
                      <td width="50%" align="left"><strong style="color: #676767;  font-size: 12px;">Titulo</strong></td>
                      <td width="1600" style="color: #676767;  font-size: 12px;">&nbsp;</td>
                    </tr>
                    <tr>
                      <td colspan="2" style="color: #676767; font-size: 12px;"><input type="text" name="titulo" id="titulo" class="form-campos"  style="width:100%; height: 30px; font-weight: bold"  value="<?php echo $titulo;?>" /></td>
                    </tr>
                  </table>
                  <!-- FIM DIV --></td>
              </tr>
            </table>
              <table width="100%" border="0" cellspacing="0" cellpadding="7">
                <tr>
                  <td align="right"><input name="button" type="submit" class="BoxVerde" id="button" value="Salvar" style="width: 100px; height: 35px;" onclick="EnviarFormulario()"></td>
                  <?php if($acao == "Alterar"){ ?>
                  <td width="100" align="right"><table width="70" border="0" cellspacing="0" cellpadding="2" class="BoxMenuVermelho" onclick="location.href='manutencao_subcategorias.php?idservicosubcategoria=<?php echo $idservicosubcategoria;?>&amp;excluir=sim';" style="width: 100px; height: 35px; color:#FFFFFF;">
                    <tr>
                      <td height="25" align="center" class="TextoMenuBranco">Excluir</td>
                    </tr>
                  </table></td>
                  <?php } ?>
                </tr>
              </table></td>
            <td width="50%" valign="top" bgcolor="#D9D9D9">&nbsp;</td>
          </tr>
        </form>
        <!-- FIM FORM -->
      </table></td>
      <td width="250" valign="top"><?php require_once('lateral_geral.php');?></td>
    </tr>
  </tbody>
</table>
<?php require_once('../rodape.php');?>