<?

//-------------------------------fim da autenticação---------------------//

    include("authentication.php");

	include("conexao_e_agenda.php");

	include("funcoes.php");

	include ("funcao_fonetica.php");

	$id_usuario = $_SESSION["id_usuario"];

    $nome_usuario = $_SESSION["nome_usuario"];	

//-------------------------------fim da autenticação---------------------//

   $text = $_GET['titulo']." ";    

   phonebr($text,$result);

   $nome_fonet = $result;

   $text ="";

   $result = ""; 

  $select_cad = "SELECT * FROM informativo_fila ORDER BY id DESC"; 

//--------

 $data1 = datapadrao_date($_GET["dt1"]);

 $data2 = datapadrao_date($_GET["dt2"]);

 $assunto = $_GET["titulo"];

 if($assunto!=null and $_GET["dt1"]==null){

  $select_cad = "SELECT * FROM informativo_fila where titulo like '%$assunto%' order by titulo asc";

 } elseif($assunto==null and $_GET["dt1"]!=null){

  $select_cad = "SELECT * FROM informativo_fila where dt_cad between '$data1' and '$data2' order by dt_cad,id desc";

 } elseif($assunto!=null and $_GET["dt1"]!=null){

  $select_cad = "SELECT * FROM informativo_fila where titulo like '%$assunto%' and dt_cad between '$data1' and '$data2' order by titulo desc";

 } else {

  $select_cad = "SELECT * FROM informativo_fila ORDER BY id DESC"; 

 } 

//--------  

  $result_cad = mysqli_query($conexao,$select_cad) or die(mysqli_error($conexao));

//-----------------------------------------------------------------------



$mostrar = "100"; // total por pagina

if (!($_GET['pagina'])) {

  $pc=1; 

}

else {

  $pc = $_GET['pagina']; 

}



$inicio = $pc - 1; 

$inicio = $inicio * $mostrar;

$result_cad = mysqli_query($conexao,"$select_cad LIMIT $inicio, $mostrar") or die(mysqli_error($conexao));

$result_cad_total = mysqli_query($conexao,"$select_cad") or die(mysqli_error($conexao));

$tr = mysqli_num_rows($result_cad_total); // verifica o número total de registros 

$tp = ceil($tr / $mostrar);  // verifica o número total de páginas 



//------------------------------------------

$variaveis_get = "";

if (!empty($_GET)){	

  foreach($_GET as $chave=>$valor){

    if ($chave != "pagina" && $chave != "ger")      // para não ficar duplicada a variável 'pagina'

      $variaveis_get = $variaveis_get."&$chave=$valor";

  }

}	



//------------------------------------------

$_SESSION['voltando'] = $_SERVER['REQUEST_URI'];		  

?>

<html>

<head>

<title><? echo $empresa; ?></title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<link href="estilo.css" rel="stylesheet" type="text/css">

<script type="text/javascript" src="js/mascara.js"></script>

<style type="text/css">

<!--

.style1 {

	color: #FFFFFF;

	font-weight: bold;

}

-->

</style>

</head>

<body>

    <?php include("cabecalho_e_clube.php"); ?>

<form id="form1" name="form1" method="get" action="lista_informativo_fila.php">

<table width="550" border="0" align="center" cellpadding="0" cellspacing="0" class="cant_cinza">

  <tr>

    <td class"textosimples"><div align="center">Pesquisa por Per&iacute;odo e/ou Nome</div></td>

  </tr>

  <tr>

    <td class="textosimples" >&nbsp;

      Per&iacute;odo:

            <input name="dt1" type="text" class="caixa_buttun_preto_9" onKeyUp="mascara(this.value, this.id, '##/##/####', event);" id="dt1" size="12" maxlength="10" />

    &agrave; 

    <input name="dt2" type="text" class="caixa_buttun_preto_9" onKeyUp="mascara(this.value, this.id, '##/##/####', event);" id="dt2" size="12" maxlength="10" />

            &nbsp;Nome: 

            <input name="titulo" type="text" class="caixa_buttun_preto_9" id="titulo" size="30" />

            &nbsp;<input type="submit" name="button" id="button" class="botao_busca" value="Buscar" style="cursor:hand" />

        </td>

  </tr>  

</table></form>     

<table width="750" height="149" align="center">

  <tr>

    <td height="143"><!--inicio-->

      

  <div align="center">

          <table width="750" border="0" cellspacing="0" cellpadding="0">

            <tr>

              <td width="438" height="30" bgcolor="#FFFFFF" class="texto"><div align="center">Listagem 

              de  Informativos E-mail cadastrados para receber serem enviados&nbsp;</div></td>

            </tr>

            <tr>

              

            <td height="15" bgcolor="#FFFFFF" class="texto">&nbsp;&nbsp;<? if($tr=='0') echo "Não foi encontrado nenhum registro." ?></td>

            </tr>

            <tr class="verdana1">

              <td height="28" bgcolor="#FFFFFF"><div align="left"><font color="#CC0000">&nbsp;&nbsp;<? echo $tr; ?> Informativo(s) encontrado(s)</font> - p&aacute;gina <? echo $pc; ?> 

                de <? echo $tp; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 

                <? 

                  // ANTERIOR

				  $anterior = $pc - 1; 

				  if ($pc > 1){

			        echo "<a href='lista_informativo_fila.php?$variaveis_get&pagina=$anterior' class='link1'><img src='st_esq.gif' width='4' height='7' border='0'> ANTERIOR</a>&nbsp;| "; 

	  		      }

				  else

				    echo "<img src='st_esq.gif' width='4' height='7' border='0'> <font color='#999999'>ANTERIOR</font>&nbsp;| ";

                  

				  // P&Aacute;GINAS

				  for ($i = 1; $i <= $tp; $i++){

				    echo "<a href='lista_informativo_fila.php?$variaveis_get&pagina=$i' class='link1'>$i</a> ";  

				  }

				  echo "| ";

				  

                  // PR&Oacute;XIMA

				  $proximo = $pc + 1; 

			      if ($pc < $tp){

			        echo "<a href='lista_informativo_fila.php?$variaveis_get&pagina=$proximo' class='link1'>PR&Oacute;XIMA <img src='st_dir.gif' width='4' height='7' border='0'></a>"; 

	  		      }

				  else

				    echo "<font color='#999999'>PR&Oacute;XIMA</font> <img src='st_dir.gif' width='4' height='7' border='0'>";

			    ?>

              </div></td>

            </tr>

          </table>

          <table width="750" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF" class="cant_azul">

            <tr class="verdana1">

            <td width="36" height="21" bgcolor="#003366"><div align="center" class="style1">VER</div></td>

              <td width="62" height="21" bgcolor="#003366"><div align="center" class="style1"><font color="#FFFFFF"><strong>DATA </strong></font></div></td>

              <td width="52" bgcolor="#003366"><font color="#FFFFFF"><strong>HORA </strong></font></td>

              <td width="230" bgcolor="#003366"><font color="#FFFFFF"><strong>T&Iacute;TULO</strong></font></td>

              <td width="198" bgcolor="#003366"><font color="#FFFFFF"><strong>DESTINO</strong></font></td>

              <td width="127" bgcolor="#003366"><div align="center"><font color="#FFFFFF"><strong>SITUA&Ccedil;&Atilde;O</strong></font></div></td>

            </tr>

            <? while ($linha_cad = mysqli_fetch_array($result_cad)){ 

			$qtfila = conta(informativo_hora,id,id_informativo,$linha_cad['id']);

			$qtnexec = conta2(informativo_hora,id,id_informativo,$linha_cad['id'],rodou,n);

			$qtexec = conta2(informativo_hora,id,id_informativo,$linha_cad['id'],rodou,s);

			if($qtexec==$qtfila){ //($qtfila>=1 and ) and $qtnexec==0

			$atual_status = "Execução Completa";

			$reg_status = 1;

			}  // - 

			

			 $diferenca = $qtfila - $qtexec;//$qtnexec;

			if($diferenca>=1){

			  if($qtexec>0){

			  $atual_status = "Em Execução";

			  $reg_status = 2;

			  } else {			

			  $atual_status = "Aguardando Execução";

			  $reg_status = 3;

			  } 

			}

			//."|".$qtfila."|".$qtexec." - ".$diferenca." = ".$atual_status

			?>

            <tr class="verdana1" bgcolor="<? if ($par = !$par) $cor = '#bbc3d3'; else $cor = '#F5F5F5'; echo $cor;?>">

            <td><div align="center"> <a href="cad_informativo_fila_alt.php?id_tcomp=<? echo $linha_cad['id'] ?>" class="link1"><img src="lupa.gif" alt="" border="0"></a></div></td>

              <td><div align="left"><strong>&nbsp;<? echo datapadrao_data($linha_cad['dt_cad']); ?></strong></div></td>

              <td><strong>&nbsp;<? echo $linha_cad['hr_cad']; ?></strong></td>

              <td><div align="left"><strong>&nbsp;&nbsp;<? echo $linha_cad['titulo']; ?></strong></div></td>

              <td><div align="left"><strong>&nbsp;&nbsp;<? echo $linha_cad['tipo']; ?></strong></div></td>

              <td bgcolor="<? if ($reg_status == 1) $cor = '#FF0000'; else if ($reg_status == 2) $cor = '#00FF00'; else $cor = '#FFFF00'; echo $cor;?>"><strong>&nbsp;<? echo desc_status_informativo($reg_status); ?></strong></td>

            </tr>

            <? 

			} 

	  	  ?>

          <tr class="verdana1">

              <td height="21" colspan="6" bgcolor="#FFFFFF">&nbsp;</td>

            </tr>

          </table>

  </div>

    <!--fim--></td>

  </tr>

</table>

</div>

        <br>

</body>

</html>

