<!doctype html>
<html lang="en">
<head>
<title>Tim's Language Helper</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<style>
    table, td {
        border: 1px solid red;
        border-collapse: collapse;
        margin:5px;
    }
   
    li.unverified_file {
        color: orange;
        font-weight: bold;
    }

    li.new_file {
        color: red;
        font-weight: bold;
    }
    li.directory {
        color: brown;
        font-weight: normal;
    }

</style>
<script>
    function show_words() {
        alert("show_words reached")
    }
</script>
</head>
<body>

<h1>Tim's Language Helper</h1>
<h2>Word Check</h2>

    <br/>From Language: <select id="slt_from_language">
        <option value="0">--- Select ---</option>
        <option value="1">English</option>
        <option value="2">Greek</option>
    </select>
    <br/>To Language: <select id="slt_to_language">
        <option value="0">--- Select ---</option>
        <option value="1">English</option>
        <option value="2">Greek</option>
    </select>
    <br/><button onclick="show_words()">Show Words</button>
    
<?php
if ($_GET["debug"]) {
    $debug = TRUE;
} else {
    $debug = FALSE;
}
include "classes/DatabaseConnection.php";
include "classes/Word.php";

$db_conn = DatabaseConnection::getConnection();
if ($debug) {
    echo "<br/>Connection status: " . $db_conn->status;;
}
// default to English
if ($_GET["from_language"]) {
    $from_language = $_GET["from_language"];
} else {
    $from_language = 1;
}
$query = "SELECT fw.word as from_word, tw.word as to_word FROM words fw left join word_meanings wm on fw.id = wm.from_word_id left join words tw on wm.to_word_id = tw.id where fw.language = " . $from_language . " order by fw.word";

if ($debug) {
   echo "<br/>SQL created: " . $query;
}

$result = $db_conn->connection->query($query);
if ($debug) {
    echo "<br/>SQL executed?...";
    echo "<br/>Number of rows in result: " . $result->num_rows;
}
echo "<table>\n";
foreach ($result as $row) {
    echo "<tr><td>" . $row['from_word'] . "</td><td>" . ($row['to_word'] ?$row['to_word']:"none") . "</td></tr>\n";
}
echo "</table>\n";

?>

</body>
</html>