<?php
header('Content-Type: application/json;charset= utf-8');
ini_set('memory_limit','5024M');
set_time_limit(0);
require("../../dbinfo.php");
$con = mysqli_connect($sqlname, $username, $password, $db);
mysqli_set_charset($con,"utf8");
if(!$con){exit;}
$res = array();
$sql = "SELECT astext(SHAPE) AS geom, elemred,tiposec, (SELECT codigo FROM adm_clases WHERE id = cat_tramos.tiposec LIMIT 1) as descsec,";
$sql .= " tipotra, (SELECT codigo FROM adm_tipos WHERE id = cat_tramos.tipotra LIMIT 1) as desctra,";
$sql .= " id_psig_aa, id_psig_ab, dim1, dim2, dim3, dim4, material,zarriba, zabajo, z_tapa_aa, z_tapa_ab, prof_aa, prof_ab,";
$sql .= " longitud, estado, accion, ccz, cuenca,alta_fuente,alta_fecha, calle, comentarios, etapa,";
$sql .= " contrato, (SELECT nombre FROM adm_contratos WHERE id = cat_tramos.contrato LIMIT 1) as desccon,";
$sql .= " proyecto, (SELECT nombre FROM adm_proyectos WHERE id = cat_tramos.proyecto LIMIT 1) as descpro";
$sql .= " FROM cat_tramos WHERE activo = 1";
if($_SERVER['REQUEST_METHOD'] == 'GET')
{
	if(isset($_GET["filtro"]))
	{
		if ($_GET["filtro"] == 1)
		{
		$sql .= " AND  (etapa = 'Proyectado' OR etapa = 'En construccion')";
		}
	}
}
$resultado = mysqli_query($con,$sql);
if ($resultado != FALSE){
	if (mysqli_num_rows($resultado) > 0){
		while($row = mysqli_fetch_assoc($resultado))
		{
			$elem = array( 
			    'geom' => $row["geom"],
                'elemred' => $row["elemred"],
                'tiposec' => $row["tiposec"],
				'descsec' => $row["descsec"],
				'tipotra' => $row["tipotra"],
				'desctra' => $row["desctra"],
				'id_psig_aa' => $row["id_psig_aa"],
				'id_psig_ab' => $row["id_psig_ab"],
				'dim1' => $row["dim1"],
				'dim2' => $row["dim2"],
				'dim3' => $row["dim3"],
				'dim4' => $row["dim4"],
				'material' => $row["material"],
				'zarriba' => $row["zarriba"],
				'zabajo' => $row["zabajo"],
				'z_tapa_aa' => $row["z_tapa_aa"],
				'z_tapa_ab' => $row["z_tapa_ab"],
				'prof_aa' => $row["prof_aa"],
				'prof_ab' => $row["prof_ab"],
				'longitud' => $row["longitud"],
				'estado' => $row["estado"],
				'accion' => $row["accion"],
				'ccz' => $row["ccz"],
				'cuenca' => $row["cuenca"],
				'alta_fuente' => $row["alta_fuente"],
				'alta_fecha' => $row["alta_fecha"],
				'calle' => $row["calle"],
				'comentarios' => $row["comentarios"],
				'etapa' => $row["etapa"],
				'contrato' => $row["contrato"],
				'desccon' => $row["desccon"],
				'proyecto' => $row["proyecto"],
				'descpro' => $row["descpro"]
				);
				array_push($res,$elem);
		}
	}
}

echo json_encode($res, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK);
?>

