<?php require_once('../topo.php');?>
<?php require_once('../lateral.php');?>
<br><br><br>
<?php 
$idobra = $_GET['idobra']; 

$SelecionaObra = Seleciona("obras", "WHERE idobra='$idobra'", "LIMIT 0,1");
while($linha_obras = mysql_fetch_array($SelecionaObra)){
$codmax = $linha_obras['codmax']; 

}
?>

<?php
//GERADOR DE CAMPOS POST

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

$idobra_listadeacesso		= $_GET['idobra_listadeacesso'];

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

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

//Recebendo Dados do Formulário

$idobra_listadeacesso .= $_POST['idobra_listadeacesso'];
$titulo = $_POST['titulo'];
$observacao = addslashes(htmlentities($_POST['observacao']));
$datainicio = $_POST['datainicio'];
$datafim = $_POST['datafim'];


//Dados da Tabela
$tabela                 ="obras_listadeacesso";
$campos_tabela = "titulo, datainicio, datafim, observacao, idusuario_cadastro, datacadastro, idfilial, idobra";

$campos_value = "'$titulo', '$datainicio', '$datafim', '$observacao', '".$_SESSION['usuarioID']."', '".date("Y-m-d")."', '".$_SESSION['idfilial_usuario']."', '$idobra'";

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

// RETORNA ULTIMO ID INSERIDO
	$id_insert = mysql_insert_id();
	$redireciona = VerificaSqlSemAlert($salvar, "manutencao_obras_listadeacessos.php?idobra_listadeacesso=".$id_insert."&idobra=".$idobra."", "listar_obras_listadeacessos.php?idobra=".$idobra."");
}

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

$campos_alterar = "titulo='$titulo', datainicio='$datainicio', datafim='$datafim', observacao='$observacao', idusuario_cadastro='".$_SESSION['usuarioID']."', datacadastro='".date("Y-m-d")."', idfilial='".$_SESSION['idfilial_usuario']."', idobra='$idobra'";

    $atualizar = Alterar($tabela, $campos_alterar, "idobra_listadeacesso", $idobra_listadeacesso);
	$redireciona = VerificaSqlSemAlert($atualizar, "manutencao_obras_listadeacessos.php?idobra_listadeacesso=".$idobra_listadeacesso."&idobra=".$idobra."", "manutencao_obras_listadeacessos.php?idobra_listadeacesso=".$idobra_listadeacesso."&idobra=".$idobra."");
}

//EXCLUINDO REGISTRO
if($_GET['excluir'] == "sim"){
    $deletar = Excluir($tabela, "idobra_listadeacesso", $idobra_listadeacesso);	
	$redireciona = VerificaSqlSemAlert($deletar, "listar_obras_listadeacessos.php?idobra=".$idobra."", "manutencao_obras_listadeacessos.php?idobra_listadeacesso=".$idobra_listadeacesso."&idobra=".$idobra."");
} 


if($acao == "Alterar"){

	$selecionar_categorias = Seleciona($tabela, "WHERE idobra_listadeacesso='".$idobra_listadeacesso."'", "") or die(mysql_error());
	while($linha_categorias=mysql_fetch_array($selecionar_categorias)){
		
$titulo = $linha_categorias['titulo']; 
$observacao = $linha_categorias['observacao']; 
$datainicio = $linha_categorias['datainicio']; 
$datafim = $linha_categorias['datafim']; 

	}
}
?>
<script type="text/javascript" src="js/tinymce/tinymce.min.js"></script>    
<script type="text/javascript">
tinymce.init({
selector: "textarea",
plugins: [
	"advlist autolink lists link image charmap print preview anchor",
	"searchreplace visualblocks code fullscreen"
],
toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image"
});
</script>
<script type="text/javascript">
function EnviarFormulario()
{
    document.forms["cadastro"].submit();
}
</script>
<div id="box-toggle">
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td colspan="2"><table width="100%" border="0" align="center" cellpadding="5" cellspacing="0">
      <tr>
        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="237" height="40" class="TituloPagina" style="padding-left: 5px;">DETALHE LISTA DE ACESSO #<?php echo $codmax;?></td>
            <td width="722" 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="200" border="0" cellspacing="0" cellpadding="2" class="BoxMenuAzul" onclick="location.href='listar_obras_listadeacessos.php?idobra=<?php echo $idobra;?>';">
                  <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 Listas</span></td>
                    </tr>
                  </table></td>
                <td width="150" align="left"><table width="190" border="0" cellspacing="0" cellpadding="2" class="BoxMenuAzul" onclick="location.href='manutencao_obras_listadeacessos.php?idobra=<?php echo $idobra;?>';">
                  <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 Lista</span></td>
                    </tr>
                  </table></td>
                <td width="125" align="left">&nbsp;</td>
                <td width="370" align="right">&nbsp;</td>
                </tr>
              </table></td>
            <td width="5" 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_obras_listadeacessos.php?idobra=<?php echo $idobra;?>" enctype="multipart/form-data">
<input type="hidden" name="acao" value="<?php echo $acao;?>">
<input type="hidden" name="idobra_listadeacesso" value="<?php echo $idobra_listadeacesso;?>">
      <tr>
        <td width="25%" valign="top" bgcolor="#D9D9D9"><table width="100%" border="0" cellspacing="0" cellpadding="4">
          <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>
                <tr>
                  <td style="color: #676767; font-size: 12px;"><strong style="color: #676767;  font-size: 12px;">Data Inicio</strong></td>
                  <td style="color: #676767; font-size: 12px;"><strong style="color: #676767;  font-size: 12px;">Data Fim</strong></td>
                </tr>
                <tr>
                  <td style="color: #676767; font-size: 12px;"><input type="date" name="datainicio" id="datainicio" class="form-campos"  style="width:100%; height: 30px; font-weight: bold"  value="<?php echo $datainicio;?>" /></td>
                  <td style="color: #676767; font-size: 12px;"><input type="date" name="datafim" id="datafim" class="form-campos"  style="width:100%; height: 30px; font-weight: bold"  value="<?php echo $datafim;?>" /></td>
                </tr>
                </table>
              <!-- FIM DIV --></td>
            </tr>
          </table>
          <table width="100%" border="0" cellspacing="0" cellpadding="7">
            <tr>
              <td colspan="3" align="right">
              <?php if($acao == "Alterar"){ ?>
              <table width="100%" bgcolor="#FFFFFF" border="0" cellspacing="0" cellpadding="4" style="border:4px #FFFFFF solid; border-radius:10px; -moz-border-radius:10px; -webkit-border-radius:10px;">
                <tr>
                  <td valign="top" ><strong style="font-family: 'Trebuchet MS'">PESSOAS</strong></td>
                </tr>
                <tr>
                  <td valign="top" ><table width="100%" border="0" align="center" cellpadding="3" cellspacing="0">
                    <tr class="TextoCinzaEscuro">
                      <td height="30" bgcolor="#A6A6A6" class="TextoCinzaEscuro"><strong>Nome</strong></td>
                      <td align="left" bgcolor="#A6A6A6"><strong>Telefone</strong></td>
                      <td align="left" bgcolor="#A6A6A6"><strong>CPF</strong></td>
                      <td align="left" bgcolor="#A6A6A6"><strong>RG</strong></td>
                      <td align="left" bgcolor="#A6A6A6"><strong>Função</strong></td>
                      <td align="left" bgcolor="#A6A6A6"><strong>Veiculo</strong></td>
                      <td align="center" bgcolor="#A6A6A6">&nbsp;</td>
                    </tr>
                    <?php
			$cor_fundo = "#FFFFFF";			  
			 	$seleciona = Seleciona("obras_listadeacesso_pessoas", "WHERE idobra_listadeacesso='$idobra_listadeacesso'", "ORDER BY nome ASC");
			while($linha=mysql_fetch_array($seleciona)){
			
			if($cor_fundo == "#FFFFFF"){
				$cor_fundo = "#E4E4E4";
			}else{
				$cor_fundo = "#FFFFFF";
			}
		?>
                    <tr class="TextoCinzaPequeno" bgcolor="<?php echo $cor_fundo;?>" onmouseover="javascript:this.style.backgroundColor='#CCCCCC'" onmouseout="javascript:this.style.backgroundColor='<?php echo $cor_fundo;?>'">
                      <td height="30"><?php echo  $linha['nome'];?></td>
                      <td align="left"><?php echo $linha['telefone'];?></td>
                      <td align="left"><?php echo $linha['cpf'];?></td>
                      <td align="left"><?php echo $linha['rg'];?></td>
                      <td align="left"><?php echo $linha['funcao'];?></td>
                      <td align="left"><?php echo $linha['carro'];?></td>
                      <td align="right"><a class="fancybox fancybox.iframe" href="cadastro_listadeacessos_pessoas.php?idobra_listadeacesso=<?php echo $idobra_listadeacesso;?>&idobra=<?php echo $idobra;?>&Pessoa=Atualizar&idobra_listadeacesso_pessoas=<?php echo $linha['idobra_listadeacesso_pessoas'];?>" style="color:#FFF;"><img src="img/icone_detalhe.gif" width="22" height="24" border="0" /></a></td>
                    </tr>
                    <?php }?>
                  </table></td>
                </tr>
                <tr>
                  <td align="right" valign="top" ><table width="150" border="0" cellspacing="0" cellpadding="2" class="BoxMenuVermelho" style="height: 35px; color:#FFFFFF;">
                    <tr>
                      <td height="25" align="center" class="TextoMenuBranco"><a class="fancybox fancybox.iframe" href="cadastro_listadeacessos_pessoas.php?idobra_listadeacesso=<?php echo $idobra_listadeacesso;?>&idobra=<?php echo $idobra;?>" style="color:#FFF;">NOVA PESSOA</a></td>
                    </tr>
                  </table>
                    <table width="150" border="0" cellspacing="0" cellpadding="2" class="BoxMenuVermelho" style="height: 35px; color:#FFFFFF;">
                    <tr>
                      <td height="25" align="center" class="TextoMenuBranco"><a class="fancybox fancybox.iframe" href="adicionarmaodeobra_listadeacesso.php?idobra_listadeacesso=<?php echo $idobra_listadeacesso;?>&idobra=<?php echo $idobra;?>" style="color:#FFF;">NOVA LISTA</a></td>
                    </tr>
                  </table></td>
                </tr>
              </table>
              <?php }?>
              </td>
              </tr>
            <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="50" align="right"><table width="70" border="0" cellspacing="0" cellpadding="2" class="BoxMenuVermelho" onclick="location.href='manutencao_obras_listadeacessos.php?idobra_listadeacesso=<?php echo $idobra_listadeacesso;?>&excluir=sim&idobra=<?php echo $idobra;?>';" style="width: 100px; height: 35px; color:#FFFFFF;">
                <tr>
                  <td height="25" align="center" class="TextoMenuBranco">Excluir</td>
                  </tr>
                </table></td>
              <td width="50" align="right"><table width="70" border="0" cellspacing="0" cellpadding="2" class="BoxMenuLaranja" style="width: 100px; height: 35px;">
                <tr>
                  <td height="25" align="center" class="TextoMenuBranco"><a href="imprimir_lista_acesso.php?idobra_listadeacesso=<?php echo $idobra_listadeacesso;?>&idobra=<?php echo $idobra;?>" target="_blank" style="color:#FFF;">IMPRIMIR</a></td>
                </tr>
              </table></td>
              <?php } ?>
              </tr>
          </table></td>
        </tr>
      </form>
      <!-- FIM FORM -->    
      </table>      
      </td>
  </tr>
  </table>
 </div>
<?php require_once('../rodape.php');?>