<?php require_once('../topo.php');?>
<?php require_once('../lateral.php');?>
<br><br><br>
 <table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="50" colspan="4" align="left" valign="middle"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="40"><span class="TituloPagina" style="padding-left: 5px;">OBRAS</span></td>
        <td align="right"><table width="100" border="0" align="right" 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_obras.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;">Todos as Obras</span></td>
                </tr>
              </table></td>
            <td width="150" align="left">
            <?php if($_SESSION['cargo'] != "3"){ ?>
            <table width="150" border="0" cellspacing="0" cellpadding="2" class="BoxMenuCinzaEscuro" onclick="location.href='manutencao_obras.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 Obra</span></td>
                </tr>
              </table>
              <?php }?>
              </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_obras.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 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>
    <td width="250" rowspan="2" align="left" valign="top"><?php require_once('lateral_geral.php');?></td>
  </tr>
  <tr>
    <td colspan="4" align="center" valign="top">
    <div style="width: 100%; height: 500px; overflow:auto;">
    <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="15%" align="center" bgcolor="#A6A6A6"><strong>CONCLUSÃO</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", "", "ORDER BY titulo ASC");
		  }else{
			  	$seleciona = Seleciona("obras", "WHERE titulo LIKE '%".$busca."%'", "ORDER BY titulo ASC");
		  }
			while($linha=mysql_fetch_array($seleciona)){
				$id_obra = $linha['idobra'];
				$id_cliente = $linha['idcliente'];
				
				//SELECIONA NOME CATEGORIA
				
			 	$SelecionaCliente = Seleciona("clientes", "WHERE CodCli='$id_cliente'", "");	
				while($clientes=mysql_fetch_array($SelecionaCliente)){
					$NomeCliente = $clientes['Fantasia'];
				}
			
			
			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='manutencao_obras.php?idobra=<?php echo $linha['idobra'];?>';">
        <td width="2%"><?php echo $linha['idobra'];?></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="15%" align="center" bgcolor="<?php echo $cor_percentual;?>" valign="middle"><div style="height: 30px; width: <?php echo $PercentualFinal;?>%; background-color:#7AE846; color:#FFFFFF; font-weight:bold;"><?php echo $PercentualFinal;?>%</div></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>
  <tr>
    <td colspan="5" align="center" valign="middle">
</td>
  </tr>
</table>
<?php require_once('../rodape.php');?>