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

if ($_GET["word"]) {
    $i_word = $_GET["word"];
    echo ',"parm_word":"' . $i_word . '"';
} else {
    $i_word = ""; 
    echo ',"parm_word":""';
}
if ($_GET["language"]) {
    $i_language = $_GET["language"];
    echo ',"parm_language":"' . $i_language . '"';
} else {
    $i_language = 1; // default English
    echo ',"parm_language":"dft-' . $i_language . '"';
}


// get db connection
$db_conn = DatabaseConnection::getConnection();
echo ',"db_status":"' . $db_conn->status . '"';

$word = new Word($i_word, $i_language);

$word->store($db_conn);

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

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