<?php
header('Content-Type: application/json;charset= utf-8');
require("dbinfo.php");
$con = mysqli_connect($sqlname, $username, $password, $db);
if(!$con){exit;}
mysqli_set_charset($con,"utf8");

$res = array();

$sql = "SELECT A.id, A.id_conex AS IDCON, A.descripcion AS DESCR, A.fecha AS FECHA";
$sql .= ", (ST_X(ST_STARTPOINT(B.SHAPE)) + ST_X(ST_ENDPOINT(B.SHAPE))) / 2  AS XC  ";
$sql .= ", (ST_Y(ST_STARTPOINT(B.SHAPE)) + ST_Y(ST_ENDPOINT(B.SHAPE))) / 2  AS YC  ";
$sql .= "FROM log A INNER JOIN conexiones B ";
$sql .= "ON A.id_conex = B.id ";
$sql .= "WHERE B.activo = 1  ";
$sql .= "ORDER BY A.id DESC LIMIT 200";

$resultado = mysqli_query($con,$sql);
if ($resultado != FALSE){
	if (mysqli_num_rows($resultado) > 0){
		while($row = mysqli_fetch_assoc($resultado))
		{
            $elem = array(
                   'id'=>$row['IDCON'],
                   'xc'=>$row['XC'],
                   'yc'=>$row['YC'],
                   'descripcion'=>$row['DESCR'],
                   'fecha'=>$row['FECHA'],
                     );
           array_push($res,$elem);
        }
    }
}            

$resultado = null;


 
mysqli_close($con);
echo json_encode($res);
?>

