Path: C:\
<?php
date_default_timezone_set('America/Fortaleza');
$DT=date('d-m-Y G:i:s');
$inicio= date('d-m-Y');
require_once("../conexao_srvtms.php");
function horas($hora){
list($h, $m) = explode(':', $hora);
$segundos = 0;
$segundos += $h * 3600;
$segundos += $m * 60;
return $segundos;
}
$json = file_get_contents('JSON/espera-3.json');
$reg = json_decode($json, true);
$lin=count($reg);
$body='
<table width="700"align="left" cellpadding="1" cellspacing="1" border="1">
<tr height="30" style="size=3; font-weight:bold; background:#ff0000;" >
<td align="center" colspan="5" style="background:#ffffff;"><strong>MOTORISTAS EM ESPERA A MAIS DE UMA HORA</strong></td>
</tr>
<tr style="size=3; font-weight:bold; color:white; background:#ff0000;">
<td align="center" rowspan="2" width="270"><strong>MOTORISTA</strong></td>
<td align="center" rowspan="2" width="80"><strong>PLACA</strong></td>
<td align="center" rowspan="2" width="100"><strong>MANIFESTO</strong></td>
<td align="center" width="120"><strong>CHEGADA</strong></td>
<td align="center" width="80"><strong>TEMPO</strong></td>
</tr>
<tr style="size=3; font-weight:bold; color:white; background:#ff0000;">
<td align="center"><strong>H:M:S</strong></td>
<td align="center"><strong>H:M</strong></td>
</tr>
';
foreach ($reg as $value => $x)
{ if($x['evento']=='TE' and horas($x['tempo'])>=3600)
{ $sql="SELECT top 1 a.id_Manifesto as manif, max(a.dt_Saida) as dia
FROM tbdManifesto as a
left join tbdVeiculo as b on b.id_Veiculo = a.id_Veiculo
where b.cd_Placa='".$x['placa']."' group by a.id_Manifesto
order by dia DESC";
$manifesto='';
$result= sqlsrv_query($conn, $sql, array(), array("Scrollable"=>"buffered"));
while ($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC))
{ $manifesto=$row['manif'];}
$nome=$value;
$celular=$x['celular'];
$body .='
<tr height="30" style="size=3; color:black; background:#ffffff;">';
if ($x['ini']=='SEM REGISTRO NESSE DIA')
{ $body .='
<td align="center"colspan="5">'.$x['ini'].'</td>';
}
else
{ $body .='
<td align="center"><strong> '.$nome.'</strong></td>
<td align="center">'.$x['placa'].'</td>
<td align="center">'.$manifesto.'</td>
<td align="center">'.$x['ini'].'</td>
<td align="center"><strong>'.$x['tempo'].'</strong></td>';
}
$body .='
</tr>
';
}
}
$body .='
</table>';
echo 'Atualizado em: '.$DT.'<br>'.$body;
?>