<?php
require 'acesso.php';
	$res = array();
	
	//$afirma   = $_POST['afirma'];
	
	/*if ($afirma == '') {
		$ret = $con->prepare("SELECT arcodrot, arnomrot FROM re12 WHERE sr_deleted != 'T'");
	} else {
		$ret = $con->prepare("SELECT arcodrot, arnomrot FROM re12 WHERE afirma = '$afirma' and sr_deleted != 'T'");
	}*/
	$ret = $con->prepare("SELECT a.arcodrot, a.arnomrot, a.codigo_motorista, b.arnomvde as motorista, a.codigo_auxiliar, c.arnomvde as auxiliar
		FROM re12 a
		LEFT JOIN vendedor b ON a.codigo_motorista = b.arcodvde
		LEFT JOIN vendedor c ON a.codigo_auxiliar = c.arcodvde
		WHERE a.sr_deleted != 'T'");
	$ret->execute();
	$mensagem = $ret->errorInfo();
	if ($mensagem[0] = "00000") {
		$res["rotas"] = array();
		if ($ret->rowCount() > 0) {
			$res["contagem"] = $ret->rowCount();
			while ($row = $ret->fetch(PDO::FETCH_ASSOC)) {
				array_push($res["rotas"], $row);
			}
		}
		$res["sucesso"] = 1;
	} else {
		$res["sucesso"] = 0;
	    $res["mensagem"] = $mensagem[2];
	}
	echo json_encode($res);
	$con = null;
?>