<?php
// required headers
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");

// include database and object files
include_once '../config/database.php';
include_once '../objects/score.php';

// instantiate database and score object
$db = new Database();

// initialize object
$score = new Score($db, "../../Scores/", "http://ohmj2.free.fr/legacy/Scores");

$id = isset($_GET['id']) ? $_GET['id']: -1;

// read score will be here
// query scores
if ($id == -1)
{
    $payload = $score->read_score_list();
}
else
{
    $payload = $score->read_score($id);
}

// set response code - 200 OK
http_response_code(200);
  
// show scores data in json format
echo json_encode($payload);

?>
