<?php
$uri ='../../Classes/core_class/consultasDb.php';

include_once($uri);
include "simple_html_dom.php";

// output headers so that the file is downloaded rather than displayed
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=cabpedpalm.csv');

			$sucursales =  "'".implode(",",json_decode($_GET['sucursales']))."'";
			$getEventos = new consultasDb("");
			$query ="call get_pedidos_csv('".trim($_GET['fecha_desde'])."','"
										.trim($_GET['fecha_hasta'])."',"
										.trim($sucursales).","
										.trim($_GET['nombre_operador_movil']).","
										.trim($_GET['numero_dispositivo_movil']).","
										.trim($_GET['cliente']).");";

			$getEventos->setConsulta($query);
			$q = $getEventos->query();
			$getEventos->Desconectar();


						if($q){
							while($row = $getEventos->fetchArray($q)){					
									echo ($row['ClienteID']."|".$row['Vacio']."|".$row['NroPedido']."|".$row['Fecha']."|".$row['Reparto']."|".$row['Sucursal']."|".$row['OrdenCompra']."|"."\n");
			                     }
						} else {
							 echo("No hay datos para mostrar...");
						}

			//echo $json;
			//echo '{"aaData":[["04-04-2014","09:35:15","Jose Perez 1","115","Carga"],["03-04-2014","10:35:15","Joe Perez 8","116","Nuevo"]]}';



?>