<?php
function enableCORS() { 
    // Allow from any origin
    if (isset($_SERVER['HTTP_ORIGIN'])) {
        header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
    } 
    return true;
}

enableCORS();

include("../configuracao.php");//confirma no banco de dados
include("../inclusos/funcoes.php");
include("../seguranca.php"); // Inclui o arquivo com o sistema de seguran?a
protegePagina(); // Protege a página

$SQL = "
    SELECT 
    V.idvenda, F.nome AS NomeFilial, C.nome AS NomeCliente, U.nome AS NomeProfissional
    FROM vendas AS V
    INNER JOIN filiais AS F ON V.idfilial = F.idfilial
    INNER JOIN clientes AS C ON V.idcliente = C.idcliente
    INNER JOIN usuarios AS U ON V.idprofissional = U.idusuario
    WHERE V.idfilial='".$_SESSION['idfilial_usuario']."'    
    ORDER BY V.idvenda DESC  LIMIT 0,10   
    ";

$table = mysql_query($SQL, $conexao) or die(mysql_error());
 
while ($row = mysql_fetch_array($table))  
{
 
    $i=0;
                 
    foreach($row as $key => $value)    
    {
 
        if (is_string($key)) 
        {
         $fields[mysql_field_name($table,$i++)] = $value;
        }
 
    }
 
    $json_result["data"] [ ] =  $fields;
 
}
 
$JSON = json_encode($json_result);

print_r($JSON);

 ?> 
