<?
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method");
header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE");
header("Allow: GET, POST, OPTIONS, PUT, DELETE");
$method = $_SERVER['REQUEST_METHOD'];
if($method == "OPTIONS") {
    die();
}

include 'url_amigable.php';
$ID = (int)$_GET['ID'];

include 'concha.php';

$table_name = 'notas';

$db_conn = mysqli_connect($host, $usuario, $contra) or die('Error: Could not connect.');
mysqli_select_db($db_conn, $basedatos) or die('Error: Could not select database.');
$result = mysqli_query($db_conn, "SELECT * from " . $table_name . " WHERE ID = '" . $ID . "' LIMIT 1") or die('Error: Could not query.');

$json = array();
if (mysqli_num_rows($result)) {
  while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
    $json['nota'] = $row;
  }
}

// for debug
//echo json_encode($json, JSON_NUMERIC_CHECK | JSON_PRETTY_PRINT);

// for production
echo json_encode($json, JSON_NUMERIC_CHECK | JSON_PRETTY_PRINT);

mysqli_close($db_conn);

?>
