<?php
include "classes/DatabaseConnection.php";
include "classes/Word_Test_Stat.php";
// return JSON string of the request and results for adding word_test_stat
echo '{"request_type":"add_word_test_stat"';

if ($_GET["debug"]) {
    $debug = TRUE;
    echo ',"parm_debug":"TRUE"';
} else {
    $debug = FALSE;
}

$error = FALSE;
$error_text = "";

if ($_GET["user_id"]) {
    $i_user_id = $_GET["user_id"];
    echo ',"parm_user_id":"' . $i_user_id . '"';
} else {
    $error = TRUE;
    $error_text .= "user_id not supplied, ";
}
if ($_GET["meaning_id"]) {
    $i_meaning_id = $_GET["meaning_id"];
    echo ',"parm_meaning_id":"' . $i_meaning_id . '"';
} else {
    $error = TRUE;
    $error_text .= "meaning_id not supplied, ";
}

if ($error) {
    echo ',"status":"error_found : ' . $error_text . '"}';
    exit;
}
// get db connection
$db_conn = DatabaseConnection::getConnection();
if ($debug) {
    echo ',"db_status":"' . $db_conn->status . '"';
}

// create Word_Test_Stat object, store on Db and return object as JSON
$word_test_stat = new Word_Test_Stat($i_user_id, $i_meaning_id);

$word_test_stat->store($db_conn);

echo ',"word_test_stat":' . $word_test_stat->toJson();

// close request object
echo '}';
?>