<?php
//Incluimos conexion a la base de 
require_once('../../config/Conexion.php');

    $sql="SELECT idagenda as id, title, start, end, color,idaveria FROM agenda";
    $resultAgenda = ejecutarConsulta($sql);

      $events = [];
      while ($row = $resultAgenda->fetch_assoc()) {

        $start = explode(" ", $row['start']);
        $end = explode(" ", $row['end']);
        if($start[1] == '00:00:00'){
          $start = $start[0];
        }else{
          $start = $row['start'];

        }
        if($end[1] == '00:00:00'){
          $end = $end[0];
        }else{
          $end = $row['end'];
        }
        
      $events[] = [
                'id' => $row['id'],
                'title' => $row['title'],
                'start' => $start, 
                'end' => $end,
                'color' => $row['color'],
                'idaveria' => $row['idaveria']
      ];
    }
      // Respuesta JSON
    echo json_encode($events);

?>