<?php require_once('../topo.php');?>
<?php require_once('../lateral.php');?>
<br><br><br>
<table width="100%" border="0" cellspacing="0" cellpadding="0">

    <?php if($_GET['idobra'] == ""){ ?>
    <tr>
        <td height="50" colspan="4" align="left" valign="middle">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td width="311" height="40" valign="top"><span class="TituloPagina" style="padding-left: 5px;">SELECIONE UMA OBRA</span></td>
                    <td align="left">
                        <table width="100" border="0" align="center" cellpadding="2" cellspacing="0">
                            <tr>
                                <td width="167" align="left">
                                    <table width="160" border="0" cellspacing="0" cellpadding="2" class="BoxMenuCinzaEscuro" onclick="location.href='listar_operacional.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">Todas as Obras</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="get" action="index.php" enctype="multipart/form-data">
                                            <input type="hidden" name="pagina" value="listar_operacional.php" />
                                            <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>
                </tr>
                <tr>
                    <td height="40" colspan="2" valign="top">
                        <!-- INICIO DIV -->

                        <table width="99%" border="0" align="center" cellpadding="3" cellspacing="0" id="tabela_obra" class="display">
                            <thead>
                                <tr class="TextoCinzaPequeno">
                                    <td bgcolor="#CCCCCC">CÓD.</td>
                                    <td bgcolor="#CCCCCC">Nº PROP.</td>
                                    <td height="30" bgcolor="#CCCCCC">CLIENTE</td>
                                    <td align="left" bgcolor="#CCCCCC">TITULO PROJETO</td>
                                    <td align="center" bgcolor="#CCCCCC">INICIO</td>
                                    <td align="center" bgcolor="#CCCCCC">FIM</td>
                                    <td align="right" bgcolor="#CCCCCC">&nbsp;</td>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
		$busca = $_GET['busca'];
			$cor_fundo = "#FFFFFF";			  
		  if(empty($busca)){
			  if($_SESSION['idfilial_usuario'] == 1){
				if($_SESSION['cargo'] == "1" || $_SESSION['cargo'] == "2"){  
			 		$seleciona = Seleciona("obras", "WHERE oculta IS NULL", "ORDER BY idobra DESC");
				}else{
					$seleciona = Seleciona("obras", "WHERE oculta IS NULL", "ORDER BY idobra DESC");
				}
			  }else{
				if($_SESSION['cargo'] == "1" || $_SESSION['cargo'] == "2"){
				 	$seleciona = Seleciona("obras", "WHERE idfilial='".$_SESSION['idfilial_usuario']."' AND oculta IS NULL", "ORDER BY idobra DESC"); 
				}else{
					$seleciona = Seleciona("obras", "WHERE idfilial='".$_SESSION['idfilial_usuario']."' AND oculta IS NULL", "ORDER BY idobra DESC"); 
				}
			  }
				//$seleciona = Seleciona("obras", "WHERE YEAR('datafim') > '2017'", "ORDER BY idobra DESC");
		  }else{
 			  if($_SESSION['idfilial_usuario'] == 1){
				if($_SESSION['cargo'] == "1" || $_SESSION['cargo'] == "2"){				  
				  	$seleciona = Seleciona("obras", "WHERE titulo LIKE '%".$busca."%' AND oculta IS NULL", "ORDER BY idobra DESC");
				}else{
					$seleciona = Seleciona("obras", "WHERE titulo LIKE '%".$busca."%' AND oculta IS NULL", "ORDER BY idobra DESC");
				}
			  }else{
				if($_SESSION['cargo'] == "1" || $_SESSION['cargo'] == "2"){							  
					 $seleciona = Seleciona("obras", "WHERE titulo LIKE '%".$busca."%' AND idfilial='".$_SESSION['idfilial_usuario']."' AND oculta IS NULL", "ORDER BY idobra DESC"); 
				}else{
					$seleciona = Seleciona("obras", "WHERE titulo LIKE '%".$busca."%' AND idfilial='".$_SESSION['idfilial_usuario']."' AND oculta IS NULL", "ORDER BY idobra DESC"); 
				}
			  }
		  }
			while($linha=mysql_fetch_array($seleciona)){
				$id_obra = $linha['idobra'];
				$id_cliente = $linha['idcliente'];
				
				//SELECIONA NOME CATEGORIA
				
			 	$SelecionaCliente = Seleciona("clientes", "WHERE idcliente='$id_cliente'", "");	
				while($clientes=mysql_fetch_array($SelecionaCliente)){
					$NomeCliente = $clientes['nome'];
				}
			
			
			if($cor_fundo == "#FFFFFF"){
				$cor_fundo = "#E4E4E4";
			}else{
				$cor_fundo = "#FFFFFF";
			}
			
			//CALCULA QTDE DE SERVIÇOS
			
			$SelecionaServicosTotal = Seleciona("obras_servicos", "WHERE idobra='$id_obra'", "");	
			$TotalServico = mysql_num_rows($SelecionaServicosTotal);

			$SelecionaServicosConcluido = Seleciona("obras_servicos", "WHERE idobra='$id_obra' AND status='Concluido'", "");	
			$TotalServicoConcluido = mysql_num_rows($SelecionaServicosConcluido);			
			
			$PercentualAtual = 100 - ((($TotalServico - $TotalServicoConcluido) / $TotalServico) * 100);
			$PercentualFinal = intval($PercentualAtual);
			
			if($PercentualFinal == 100){
				$cor_percentual = "#7AE846";
			}else{
				$cor_percentual = "#BD3739";
			}
			
$SelecionaOrcamento = Seleciona("vendas", "WHERE idvenda='".$linha['idvenda']."'", "");
while($DadosOrcamento = mysql_fetch_array($SelecionaOrcamento)){
	
//CÓD VENDA        
if($DadosOrcamento['idorcamento'] == "" or $DadosOrcamento['idorcamento'] == "0"){
$CodVenda = substr($DadosOrcamento['dataorcamento'], 0, 4) ."-".$DadosOrcamento['idvenda'];
}else{
$CodVenda = substr($DadosOrcamento['dataorcamento'], 0, 4) ."-".$DadosOrcamento['idvenda']."- A: ".$DadosOrcamento['aditivo'];			
}   

if($DadosOrcamento['idvenda_revisao'] != ""){
	$CodVenda = substr($DadosOrcamento['dataorcamento'], 0, 4) . "-".$DadosOrcamento['idvenda_revisao']."- R: ".$DadosOrcamento['revisao'];			
}
}
			
			
			
		?>
                                    <tr class="TextoCinzaPequeno" bgcolor="<?php echo $cor_fundo;?>" onmouseover="javascript:this.style.backgroundColor='#CCCCCC'" onmouseout="javascript:this.style.backgroundColor='<?php echo $cor_fundo;?>'" style="cursor:pointer;" onclick="location.href='listar_operacional.php?idobra=<?php echo $linha['idobra'];?>';">
                                        <td>
                                            <?php echo $linha['codmax'];?>
                                        </td>
                                        <td><?php echo $CodVenda;?></td>
                                        <td height="30">
                                            <?php echo $NomeCliente;?>
                                        </td>
                                        <td align="left">
                                            <?php echo $linha['titulo'];?>
                                        </td>
                                        <td align="center">
                                            <?php echo InverteDataNovoSeparador($linha['datainicio'], "-", "/");?>
                                        </td>
                                        <td align="center">
                                            <?php echo InverteDataNovoSeparador($linha['datafim'], "-", "/");?>
                                        </td>
                                        <td align="right"><img src="img/icone_detalhe.gif" width="22" height="24" border="0" /></td>
                                    </tr>
									<?php 
                                    $NomeCliente = "";
                                    $PercentualAtual = "";
                                    $CodVenda = "";
                                    }?>
                            </tbody>
                        </table>
                    </td>
                </tr>
            </table>
            <table width="100%" border="0" cellspacing="4" cellpadding="5">
                <tr>
                    <td><span class="TituloCinzaEscuro" style="font-size: 14px;"><strong>RELATÓRIOS</strong></span></td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                </tr>
                <tr>
                    <td bgcolor="#CCCCCC"><strong>NOME RELATÓRIO</strong></td>
                    <td bgcolor="#CCCCCC"><strong>OBSERVAÇÃO</strong></td>
                    <td align="center" bgcolor="#CCCCCC"><strong>ABRIR</strong></td>
                </tr>
                <tr>
                    <td bgcolor="#FFFFFF"><strong>Relatório de Obras</strong></td>
                    <td bgcolor="#FFFFFF">Listagem de Obras, com percentual e Status da Obra em Andamento</td>
                    <td align="center" bgcolor="#FFFFFF">
                        <a href="relatorio_obras.php" target="_blank"><img src="img/icone_detalhe_novo.png" width="27" height="35" alt="Relatório de Propostas" /></a>
                    </td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                </tr>
            </table>
        </td>
    </tr>
    <?php }?>
    <!-- LINHA DADOS -->
    <?php if($_GET['idobra'] != ""){ 
	
//PEGA ALBUM
    $seleciona_album = Seleciona("albuns", "WHERE idobra='".$_GET['idobra']."'", "");
    while($album = mysql_fetch_array($seleciona_album)){
    $idalbum = $album['album_id'];
    }		
	
  
$idobra = $_GET['idobra'];	  
$SelecionaObra = Seleciona("obras", "WHERE idobra='$idobra'", "LIMIT 0,1");
while($linha_obras = mysql_fetch_array($SelecionaObra)){

$idobra = $linha_obras['idobra']; 
$codmax = $linha_obras['codmax']; 
$idobra_origem = $linha_obras['idobra_origem']; 
$idcliente = $linha_obras['idcliente']; 
$idorcamento = $linha_obras['idorcamento']; 
$idvenda = $linha_obras['idvenda']; 
$titulo = $linha_obras['titulo']; 
$observacao = $linha_obras['observacao']; 
$valorprojeto = $linha_obras['valorprojeto']; 
$valormaximo = $linha_obras['valormaximo']; 
$lucro = $linha_obras['lucro']; 
$datainicio = $linha_obras['datainicio']; 
$datafim = $linha_obras['datafim']; 
$status = $linha_obras['status']; 
$idprofissional = $linha_obras['idprofissional']; 
$segunda = $linha_obras['segunda']; 
$terca = $linha_obras['terca']; 
$quarta = $linha_obras['quarta']; 
$quinta = $linha_obras['quinta']; 
$sexta = $linha_obras['sexta']; 
$sabado = $linha_obras['sabado']; 
$domingo = $linha_obras['domingo']; 
$horario_obra = $linha_obras['horario_obra']; 
$itens_obrigatorios = $linha_obras['itens_obrigatorios']; 
$local_obra = $linha_obras['local_obra']; 
$engenheiro_responsavel = $linha_obras['engenheiro_responsavel']; 
$arquiteto_responsavel = $linha_obras['arquiteto_responsavel']; 
$cordenador1 = $linha_obras['cordenador1']; 
$cordenador2 = $linha_obras['cordenador2']; 
$supervisor1 = $linha_obras['supervisor1']; 
$supervisor2 = $linha_obras['supervisor2']; 
$tecnicoseguranca = $linha_obras['tecnicoseguranca']; 
$descricao_obra = $linha_obras['descricao_obra']; 
$observacao_obra = $linha_obras['observacao_obra']; 
$listadeacesso = $linha_obras['listadeacesso']; 
$rrt = $linha_obras['rrt']; 
$seguro_obra = $linha_obras['seguro_obra']; 
$doc_segurancatrabalho = $linha_obras['doc_segurancatrabalho']; 

}  
$SelecionaClientes = Seleciona("clientes", "WHERE idcliente='$idcliente'", "LIMIT 0,1");
while($Clientes = mysql_fetch_array($SelecionaClientes)){
  $cliente = $Clientes['nome'];
}  
  ?>
    <tr>
        <td colspan="4" align="center" valign="top">
            <table width="100%" border="0" cellspacing="5" cellpadding="5">
                <tbody>
                    <tr>
                        <td colspan="5" align="center">
                            <table width="98%" border="0" cellspacing="2" cellpadding="0">
                                <tr>
                                    <td width="404" height="40" align="left" bgcolor="#CCCCCC"><strong class="TextoCinzaGrande">Nº <?php echo $codmax;?> - CLIENTE : <?php echo $cliente;?></strong></td>
                                    <td width="786" align="right">
                                        <table width="70" border="0" cellspacing="0" cellpadding="2" class="BoxMenuCinza" onclick="location.href='listar_operacional.php?idobra=<?php $_GET['idobra'];?>';">
                                            <tr>
                                                <td height="25" align="center" class="TextoMenuBranco">Voltar</td>
                                            </tr>
                                        </table>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="5" align="center">
                            <table width="200" border="0" cellspacing="0" cellpadding="5" style="background-color: #FFFFFF; border:1px solid #AFAFAF; float:left; margin:10px;">
                                <tbody>
                                    <tr>
                                        <td height="100" align="center">
                                            <a href="listar_operacional_obra.php?idobra=<?php echo $_GET['idobra'];?>"><img src="img/icone_obras.png" width="77" height="85" alt="" /></a>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td height="50" align="center"><span class="TituloCinzaEscuro" style="font-size: 14px;">SOBRE A OBRA</span></td>
                                    </tr>
                                </tbody>
                            </table>
                        
							<?php 													
                            if($_SESSION['cargo'] != "14"){
                            ?>
                            <table width="200" border="0" cellspacing="0" cellpadding="5" style="background-color: #FFFFFF; border:1px solid #AFAFAF; float:left; margin:10px;" >
                                <tbody>
                                    <tr>
                                        <td height="100" align="center">
                                            <a href="listar_operacional_termoabertura.php?idobra=<?php echo $_GET['idobra'];?>"><img src="img/icone24.png" width="75" height="85" alt="" /></a>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td height="50" align="center"><span class="TituloCinzaEscuro" style="font-size: 14px;">TERMO DE ABERTURA</span></td>
                                    </tr>
                                </tbody>
                            </table>
                            <?php }?>
                            

							<?php 													
                            if($_SESSION['cargo'] != "14"){
                            ?>
                            <table width="200" border="0" cellspacing="0" cellpadding="5" style="background-color: #FFFFFF; border:1px solid #AFAFAF; float:left; margin:10px;">
                              <tbody>
                                <tr>
                                  <td height="100" align="center"><a href="listar_obras_listadeacessos.php?idobra=<?php echo $_GET['idobra'];?>"><img src="img/icone_14.fw.png" width="77" height="85" alt="" /></a></td>
                                </tr>
                                <tr>
                                  <td height="50" align="center"><span class="TituloCinzaEscuro" style="font-size: 14px;">LISTA DE ACESSO</span></td>
                                </tr>
                              </tbody>
                            </table>
                            <table width="200" border="0" cellspacing="0" cellpadding="5" style="background-color: #FFFFFF; border:1px solid #AFAFAF; float:left; margin:10px;" >
                                <tbody>
                                    <tr>
                                        <td height="100" align="center">
                                            <a href="listar_operacional_checklist.php?idobra=<?php echo $_GET['idobra'];?>"><img src="img/icone_orcamentos.png" width="77" height="85" alt="" /></a>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td height="50" align="center"><span class="TituloCinzaEscuro" style="font-size: 14px;">CHECK LIST</span></td>
                                    </tr>
                                </tbody>
                            </table>
                            <?php }?>
                        
							<?php 													
                            if($_SESSION['cargo'] != "14"){
                            ?>
                            <table width="200" border="0" cellspacing="0" cellpadding="5" style="background-color: #FFFFFF; border:1px solid #AFAFAF; float:left; margin:10px;">
                                <tbody>
                                    <tr>
                                        <td height="100" align="center">
                                            <a href="listar_operacional_planilhas_compra.php?idobra=<?php echo $_GET['idobra'];?>"><img src="img/icone_compra_detalhe.png" width="77" height="85" alt="" /></a>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td height="50" align="center"><span class="TituloCinzaEscuro" style="font-size: 14px;">PLANILHA DE COMPRAS</span></td>
                                    </tr>
                                </tbody>
                            </table>
                            <?php }?>
                        
							<?php 													
                            if($_SESSION['cargo'] != "14" ){
                            ?>
                            <table width="200" border="0" cellspacing="0" cellpadding="5" style="background-color: #FFFFFF; border:1px solid #AFAFAF; float:left; margin:10px;">
                                <tbody>
                                    <tr>
                                        <td height="100" align="center">
                                            <a href="listar_operacional_produtos.php?idobra=<?php echo $_GET['idobra'];?>"><img src="img/icone_produtos.png" width="77" height="85" alt="" /></a>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td height="50" align="center"><span class="TituloCinzaEscuro" style="font-size: 14px;">PRODUTOS</span></td>
                                    </tr>
                                </tbody>
                            </table>
                            <?php }?>
                        
							<?php 													
                            if($_SESSION['cargo'] != "14"){
                            ?>
                            <table width="200" border="0" cellspacing="0" cellpadding="5" style="background-color: #FFFFFF; border:1px solid #AFAFAF; float:left; margin:10px;">
                                <tbody>
                                    <tr>
                                        <td height="100" align="center">
                                            <a href="listar_operacional_contatos.php?idobra=<?php echo $_GET['idobra'];?>"><img src="img/icone_clientes.png" width="77" height="85" alt="" /></a>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td height="50" align="center"><span class="TituloCinzaEscuro" style="font-size: 14px;">CONTATOS DESTA OBRA</span></td>
                                    </tr>
                                </tbody>
                            </table>
                            <?php }?>
                        
					    
                        <table width="200" border="0" cellspacing="0" cellpadding="5" style="background-color: #FFFFFF; border:1px solid #AFAFAF; float:left; margin:10px;">
                          <tbody>
                            <tr>
                              <td height="100" align="center"><a href="listar_operacional_custo_orcamento.php?idobra=<?php echo $_GET['idobra'];?>"><img src="img/icone21.png" width="75" height="85" alt="" /></a></td>
                            </tr>
                            <tr>
                              <td height="50" align="center"><span class="TituloCinzaEscuro" style="font-size: 14px;">CUSTOS ORÇAMENTO</span></td>
                            </tr>
                          </tbody>
                        </table>
                        
                        <?php if($_SESSION['cargo'] != "14"){ ?>
                        <table width="200" border="0" cellspacing="0" cellpadding="5" style="background-color: #FFFFFF; border:1px solid #AFAFAF; float:left; margin:10px;">
                          <tbody>
                            <tr>
                              <td height="100" align="center"><a href="listar_comercial_status.php?idobra=<?php echo $_GET['idobra'];?>"><img src="img/icone_status.png" width="77" height="85" alt="" /></a></td>
                            </tr>
                            <tr>
                              <td height="50" align="center"><span class="TituloCinzaEscuro" style="font-size: 14px;">STATUS</span></td>
                            </tr>
                          </tbody>
                        </table>
                        <?php }?>
                        <?php if($_SESSION['cargo'] != "14"){ ?>
                        <table width="200" border="0" cellspacing="0" cellpadding="5" style="background-color: #FFFFFF; border:1px solid #AFAFAF; float:left; margin:10px;">
                          <tbody>
                            <tr>
                              <td height="100" align="center"><a href="https://maxlayouts.minhaempresa.online/cliente/index.php?idobra=<?php echo $_GET['idobra'];?>" target="_blank"><img src="img/icone24.png" width="75" height="85" alt="" /></a></td>
                            </tr>
                            <tr>
                              <td height="50" align="center"><span class="TituloCinzaEscuro" style="font-size: 14px;">AREA CLIENTE</span></td>
                            </tr>
                          </tbody>
                        </table>
                        <?php }?>
					  <?php
					  //TRAVA CRIADA POR ROQUE CARGO OPERACIONAL
					  if($_SESSION['cargo'] != "3"){  if( $_SESSION['cargo'] != "15"){ if( $_SESSION['cargo'] != "16"){ if( $_SESSION['cargo'] != "14"){ if( $_SESSION['cargo'] != "13"){
					  ?>					  
					 
                        <table width="200" border="0" cellspacing="0" cellpadding="5" style="background-color: #FFFFFF; border:1px solid #AFAFAF; float:left; margin:10px;">
                          <tbody>
                            <tr>
                              <td height="100" align="center"><a href="listar_operacional_despesas_obra.php?idobra=<?php echo $_GET['idobra'];?>"><img src="img/icone_compras.fw.png" width="65" height="65" alt="" /></a></td>
                            </tr>
                            <tr>
                              <td height="50" align="center"><span class="TituloCinzaEscuro" style="font-size: 14px;">DESPESAS DA OBRA</span></td>
                            </tr>
                          </tbody>
                        </table>
                        <?php }} } } } ?>
                        
					  <?php if( $_SESSION['cargo'] != "14"){ ?>
                      
                        <table width="200" border="0" cellspacing="0" cellpadding="5" style="background-color: #FFFFFF; border:1px solid #AFAFAF; float:left; margin:10px;">
                          <tbody>
                            <tr>
                              <td height="100" align="center"><a href="listar_operacional_cronograma_novo.php?idobra=<?php echo $_GET['idobra'];?>"><img src="img/icone_cronograma.png" width="77" height="85" alt="" /></a></td>
                            </tr>
                            <tr>
                              <td height="50" align="center"><span class="TituloCinzaEscuro" style="font-size: 14px;">CRONOGRAMA OBRA</span></td>
                            </tr>
                          </tbody>
                        </table>
                        <?php }?>					  
                        <table width="200" border="0" cellspacing="0" cellpadding="5" style="background-color: #FFFFFF; border:1px solid #AFAFAF; float:left; margin:10px;">
                          <tbody>
                            <tr>
                              <td height="100" align="center"><a class="fancybox fancybox.iframe" href="listar_albuns_obra.php?idobra=<?php echo $_GET['idobra'];?>" style="color:#FFF;"><img src="img/icone_fotos.png" width="77" height="85" alt="" /></a></td>
                            </tr>
                            <tr>
                              <td height="50" align="center"><span class="TituloCinzaEscuro" style="font-size: 14px;">FOTOS DA OBRA</span></td>
                            </tr>
                          </tbody>
                        </table>
                        <table width="200" border="0" cellspacing="0" cellpadding="5" style="background-color: #FFFFFF; border:1px solid #AFAFAF; float:left; margin:10px;">
                          <tbody>
                            <tr>
                              <td height="100" align="center"><a class="fancybox fancybox.iframe" href="listar_pastas_obra.php?origem=Obra&idobra=<?php echo $_GET['idobra'];?>&idvenda=<?php echo $idvenda;?>"><img src="img/icone_arquivos.png" width="40" height="35" alt="" /></a></td>
                            </tr>
                            <tr>
                              <td height="50" align="center"><span class="TituloCinzaEscuro" style="font-size: 14px;">ARQUIVOS DA OBRA</span></td>
                            </tr>
                          </tbody>
                        </table>                      </td>
                    </tr>
                </tbody>
            </table>
        </td>
    </tr>
    <?php } ?>
    <!-- LINHA DADOS -->
    <?php if($_GET['exibir'] == "sim"){ ?>
    <tr>
        <td colspan="4" align="center" valign="middle">
            <table width="100%" border="0" cellspacing="0" cellpadding="2">
                <tbody>
                    <tr>
                        <td width="200" height="30" align="center" <?php if($_GET[ 'Obras']=="" ){ echo 'bgcolor="#FFFFFF"';}else{ echo 'bgcolor="#E3E3E3"'; }?> style="cursor:pointer;" onclick="location.href='listar_operacional.php';"><span class="TituloCinzaEscuro" style="font-size: 14px;">NOVAS OBRAS</span></td>
                        <td width="200" align="center" <?php if($_GET[ 'Obras']=="Andamento" ){ echo 'bgcolor="#FFFFFF"';}else{ echo 'bgcolor="#E3E3E3"'; }?> onclick="location.href='listar_operacional.php?Obras=Andamento';" style="cursor:pointer;"><span class="TituloCinzaEscuro" style="font-size: 14px;"><strong>OBRAS EM ANDAMENTO</strong></span></td>
                        <td width="240" align="center" <?php if($_GET[ 'Obras']=="Finalizadas" ){ echo 'bgcolor="#FFFFFF"';}else{ echo 'bgcolor="#E3E3E3"'; }?> onclick="location.href='listar_operacional.php?Obras=Finalizadas';" style="cursor:pointer;"><span class="TituloCinzaEscuro" style="font-size: 14px;"><strong>OBRAS FINALIZADAS</strong></span></td>
                        <td bgcolor="#E3E3E3">&nbsp;</td>
                    </tr>
                    <tr>
                        <td colspan="4" bgcolor="#FFFFFF" class="TituloCinzaEscuro">
                            <div style="height:300px; overflow:scroll">
                                <table width="100%" border="0" align="center" cellpadding="3" cellspacing="0">
                                    <tr class="TextoCinzaEscuro">
                                        <td width="2%" bgcolor="#A6A6A6" class="TextoCinzaEscuro"><strong>CÓD.</strong></td>
                                        <td width="20%" height="30" bgcolor="#A6A6A6" class="TextoCinzaEscuro"><strong>TITÚLO</strong></td>
                                        <td width="10%" align="left" bgcolor="#A6A6A6"><strong>CLIENTE</strong></td>
                                        <td width="10%" align="left" bgcolor="#A6A6A6"><strong>DATA INICIO</strong></td>
                                        <td width="10%" align="left" bgcolor="#A6A6A6"><strong>DATA FIM</strong></td>
                                        <td width="20%" align="left" bgcolor="#A6A6A6"><strong>STATUS</strong></td>
                                        <td width="5%" align="center" bgcolor="#A6A6A6">&nbsp;</td>
                                    </tr>
                                    <?php
		$busca = $_POST['busca'];
			$cor_fundo = "#FFFFFF";			  
		  if(empty($busca)){
			 	$seleciona = Seleciona("obras", "WHERE oculta IS NULL", "ORDER BY titulo ASC");
		  }else{
			  	$seleciona = Seleciona("obras", "WHERE titulo LIKE '%".$busca."%' AND oculta IS NULL", "ORDER BY titulo ASC");
		  }
		  
		  if($_GET['Obras'] == ""){
		 	 $seleciona = Seleciona("obras", "WHERE status='Gerado' AND oculta IS NULL", "ORDER BY titulo ASC");
		  //echo "ESTOU AQUI 1";
		  }
		  
		  if($_GET['Obras'] == "Andamento"){
		 	 $seleciona = Seleciona("obras", "WHERE status <> 'Gerado' OR status <> '' AND oculta IS NULL", "ORDER BY titulo ASC");
		  //echo "ESTOU AQUI 2";		  
		  }		  
		  
		  if($_GET['Obras'] == "Finalizadas"){
		 	 $seleciona = Seleciona("obras", "WHERE status='Entregue' AND oculta IS NULL", "ORDER BY titulo ASC");
		  //echo "ESTOU AQUI 3";		  
		  }		  		  
		  
			while($linha=mysql_fetch_array($seleciona)){
				$id_obra = $linha['idobra'];
				$id_cliente = $linha['idcliente'];
				
				//SELECIONA NOME CATEGORIA
				
			 	$SelecionaCliente = Seleciona("clientes", "WHERE idcliente='$id_cliente'", "");	
				while($clientes=mysql_fetch_array($SelecionaCliente)){
					$NomeCliente = $clientes['nome'];
				}
			
			
			if($cor_fundo == "#FFFFFF"){
				$cor_fundo = "#E4E4E4";
			}else{
				$cor_fundo = "#FFFFFF";
			}
			
			//CALCULA QTDE DE SERVIÇOS
			
			$SelecionaServicosTotal = Seleciona("obras_servicos", "WHERE idobra='$id_obra'", "");	
			$TotalServico = mysql_num_rows($SelecionaServicosTotal);

			$SelecionaServicosConcluido = Seleciona("obras_servicos", "WHERE idobra='$id_obra' AND status='Concluido'", "");	
			$TotalServicoConcluido = mysql_num_rows($SelecionaServicosConcluido);			
			
			$PercentualAtual = 100 - ((($TotalServico - $TotalServicoConcluido) / $TotalServico) * 100);
			$PercentualFinal = intval($PercentualAtual);
			
			if($PercentualFinal == 100){
				$cor_percentual = "#7AE846";
			}else{
				$cor_percentual = "#BD3739";
			}
		?>
                                        <tr class="TextoCinzaPequeno" bgcolor="<?php echo $cor_fundo;?>" onmouseover="javascript:this.style.backgroundColor='#CCCCCC'" onmouseout="javascript:this.style.backgroundColor='<?php echo $cor_fundo;?>'" style="cursor:pointer;" onclick="location.href='listar_operacional.php?idobra=<?php echo $linha['idobra'];?>';">
                                            <td width="2%">
                                                <?php echo $linha['codmax'];?>
                                            </td>
                                            <td width="20%" height="30">
                                                <?php echo $linha['titulo'];?>
                                            </td>
                                            <td width="10%" align="left">
                                                <?php echo $NomeCliente;?>
                                            </td>
                                            <td width="10%" align="left">
                                                <?php echo InverteDataNovoSeparador($linha['datainicio'], "-", "/");?>
                                            </td>
                                            <td width="10%" align="left">
                                                <?php echo InverteDataNovoSeparador($linha['datafim'], "-", "/");?>
                                            </td>
                                            <td width="20%" align="left">
                                                <?php echo $linha['status'];?>
                                            </td>
                                            <td width="5%" align="right"><img src="img/icone_detalhe.gif" width="22" height="24" border="0" /></td>
                                        </tr>
                                        <?php 
		$PercentualAtual = "";
		}?>
                                </table>
                            </div>
                        </td>
                    </tr>
                </tbody>
            </table>
        </td>
    </tr>
    <?php }?>
</table>
<?php require_once('../rodape.php');?>