<? session_start();

include("../funcoes.inc");
include("config.php");
include("conexao_sinsweb.php");
$registros=1;
$Titulo='AGENDAMENTOS';

?>
<html>
<link rel="stylesheet" type="text/css" href="../css/print.css" media="print" /> 
<SCRIPT LANGUAGE="javascript">
  window.status='SINSWeb ';

function fImprimir(){
    window.print();
}
  
 </script>

 
 <head> 
<STYLE TYPE="text/css"> 
thead { display: table-header-group; } 
tfoot { display: table-footer-group; 
		overflow: visible;
	   } 

.folha { 
page-break-after: always; 
} 
</STYLE>
</head> 
<body>
<thead>
<table class=MsoNormalTable border=0 cellpadding=0 width="98%"
 style='width:98.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 0cm 0cm 0cm'>
  <tr style='mso-yfti-irow:5'>
    <td style='padding:0cm 0cm 0cm 0cm'><p class=MsoNormal><span style='font-size:7.5pt;font-family:Verdana;
  color:#333333'> <img width=1 height=5
  src="../../imagens/image002.gif" v:shapes="_x0000_i1033">
      <o:p></o:p>
    </span><? echo $Titulo?></p></td>
  </tr>
  <tr style='mso-yfti-irow:6'>
    <td style='background:#A8B7BF;padding:0cm 0cm 0cm 0cm'><p class=MsoNormal><span style='font-size:7.5pt;font-family:Verdana;
  color:#333333'> <img width=1 height=1
  src="../../imagens/image003.gif" v:shapes="_x0000_i1034">
      <o:p></o:p>
    </span></p></td>
  </tr>
</table>
</thead>


<tbody>
<?
$dataInicial=$_GET[data1];
$dataInicial = implode("-",array_reverse(explode("/",$dataInicial))); // O resultado será:  31/04/2010 para 2010-31-04
$dataInicial=$dataInicial.' 00:00';


$dataFinal=$_GET[data2];
$dataFinal = implode("-",array_reverse(explode("/",$dataFinal)));
$dataFinal=$dataFinal.' 23:59';

$sql=("
	select distinct(a.codigo) as protocolo, a.*, 
		   e.cnpj as empresa_cnpj, e.nome as empresa_nome, e.cnae as empresa_cnae, 
		   cnae.atividade_principal
	from agendamento a
	inner join empresa e on (a.empresa = e.cnpj)
	inner join cnae on (e.cnae = cnae.cod_cnae)
	where (a.data_hora between '$dataInicial' and '$dataFinal') and (a.trabalhador_nome <> '') and (a.cod_cancelamento = 0)
	order by a.data_hora, a.codigo
");
	$query=mysql_query($sql)
		or die (header("Location:erro.php?txtmensagem="."ERRO NA LEITURA DOS AGENDAMENTOS"));

   $escrever=mysql_fetch_array($query);
    {
echo 'Entre '.$_GET[data1].' e '.$_GET[data2];
echo "<table width='100%' border='1' cellpadding='0' cellspacing='0' bordercolor='#000000'>";

/*Enquanto houver dados na tabela para serem mostrados será executado tudo que esta dentro do while */

	$query=mysql_query($sql);
while($escrever=mysql_fetch_array($query)){
/*Escreve cada linha da tabela*/
?>

<table width='100%' border='1' cellpadding='0' cellspacing='0' bordercolor='#000000'>
<tr bgcolor='#FFFF00'>
<td width="10%">&nbsp;Data Agenda:</td>
<td  width="60%" colspan="2">&nbsp;<? echo mascara(DataHoraNormal($escrever[data_hora]),'##/##/#### ##:##');?>hs</td>
<td width="10%">&nbsp;Protocolo:</td>
<td width="7%">&nbsp;<? echo $escrever[protocolo];?></td>
<td bgcolor='#FFFFFF' width="10%" rowspan="3" >&nbsp;</td>
</tr>
<tr>
<td>&nbsp;Empresa:</td>
<td width="60%">&nbsp;<? echo $escrever[empresa_nome];?></td>
<td>&nbsp;CNAE:<? echo $escrever[empresa_cnae];?></td>
<td>&nbsp;CNPJ:</td>
<td>&nbsp;<? echo $escrever[empresa_cnpj];?></td>
</tr>
<tr>
<td>&nbsp;Trabalhador:</td>
<td colspan="2">&nbsp;<? echo $escrever[trabalhador_nome];?></td>
<td>&nbsp;CPF:</td>
<td>&nbsp;<? echo $escrever[trabalhador_cpf];?></td>
</tr>
</table>
      <tr>
    <td><div align="center">-------------------------------------------------------------------------------------------------------------<br />
    </div></td>
    
  </tr>
    <p>
  <?

}/*Fim do while*/

echo "</table>"; /*fecha a tabela apos termino de impressão das linhas*/


}
?>
</div>
</tbody>
<tfoot>
<table class=MsoNormalTable border=0 cellpadding=0 width="98%"
 style='width:98.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 0cm 0cm 0cm'>
  <tr style='mso-yfti-irow:5'>
    <td style='padding:0cm 0cm 0cm 0cm'><p class=MsoNormal><span style='font-size:7.5pt;font-family:Verdana;
  color:#333333'> <img width=1 height=5
  src="../../imagens/image002.gif" v:shapes="_x0000_i1033">
      <o:p></o:p>
    </span></p></td>
  </tr>
  <tr style='mso-yfti-irow:6'>
    <td style='background:#A8B7BF;padding:0cm 0cm 0cm 0cm'><p class=MsoNormal><span style='font-size:7.5pt;font-family:Verdana;
  color:#333333'> <img width=1 height=1
  src="../../imagens/image003.gif" v:shapes="_x0000_i1034">
      <o:p></o:p>
    </span></p></td>
  </tr>
</table>
</tfoot>
  
</p>
  <div align="center" id="naoimprime">
  <table class=MsoNormalTable border=0 cellpadding=0 width="98%"
 style='width:98.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 0cm 0cm 0cm'>
  <tr style='mso-yfti-irow:7'>
    <td style='padding:0cm 0cm 0cm 0cm'><p class=MsoNormal align=right style='text-align:right'><span
  style='font-size:8.5pt;font-family:Verdana;color:black'> <img width=1 height=5
  src="../../imagens/image002.gif" v:shapes="_x0000_i1035">
      <o:p></o:p>
    </span></p></td>
  </tr>
  <tr style='mso-yfti-irow:8;mso-yfti-lastrow:yes'>
    <td><div align="center"><input name="btnImprimir" type="button" style="font-family: Tahoma; font-size: 8 pt; color: #FF0000" onClick="fImprimir();" value="Imprimir">
    <a href="javascript:window.close()"><img border=0 src="../../imagens/bt_fechar.gif" alt=Fechar> </a></div></td>
  </tr>
</table>
</div>
<p>&nbsp;</p>
</html>