pyolingo/verben.php

132 lines
5.3 KiB
PHP

<?php
require_once __DIR__ . '/includes/db_connect.php';
$system = getenv('POSTGRES_SYSTEM') ?? 'test';
session_start();
$error = $_SESSION['error'] ?? '';
$success = $_SESSION['success'] ?? '';
$old = $_SESSION['old'] ?? [];
unset($_SESSION['error']);
unset($_SESSION['success']);
unset($_SESSION['old']);
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="header">
<h2 class="seitentitel"><a href="index.php" id="homeButton">pyolingo</a></h2>
</div>
<div class="inhalt">
<form id="form_hinzufuegenkarte" action="forms/hinzufuegenKarte.php" method="post">
<input id="hiddenInputEditTyp" type="hidden" name="kategorie" value="verben">
<div>
<p class="kategorie" id="p_deutsch">deutsch:</p>
<input class="kategorie"
id="input_deutsch"
type="text"
name="deutsch"
value="<?= htmlspecialchars($old['deutsch'] ?? '') ?>"
required>
</div>
<table id="table_verben">
<tr>
<th></th>
<th>Wortstamm</th>
<th>Endung</th>
</tr>
<?php for($i = 0; $i < 7; $i++) { ?>
<tr>
<td>
<input id="hiddenInputEditTyp" type="hidden" name="farbe_<?= $i ?>" value="red">
<p class="kategorie" id="p_italienisch">
<?php switch($i) {
case(0): echo 'Grundwort:'; break;
case(1): echo 'io:'; break;
case(2): echo 'tu:'; break;
case(3): echo 'lui, lei, lei:'; break;
case(4): echo 'noi:'; break;
case(5): echo 'voi:'; break;
case(6): echo 'loro:'; break;
}
?>
</p>
</td>
<td>
<input class="kategorie"
id="input_wortstamm"
type="text"
name="wortstamm_<?= $i ?>"
value="<?= htmlspecialchars(($old['wortstamm_' . $i] ?? '')) ?>"
<?php if($i == 0) echo 'required'?>>
</td>
<td>
<input class="kategorie"
id="input_endung"
type="text"
name="endung_<?= $i ?>"
value="<?= htmlspecialchars(($old['endung_' . $i] ?? '')) ?>">
</td>
</tr>
<?php }; ?>
</table>
<div>
<p class="kategorie" id="p_deutsch">Suffix:</p>
<input class="kategorie"
id="input_suffix"
type="text"
name="suffix"
value="<?= htmlspecialchars($old['suffix'] ?? '') ?>">
</div>
<div id="div_speichern">
<?php if ($error): ?>
<p class=fehlermeldung><?= htmlspecialchars($error) ?></p>
<?php endif; ?>
<?php if ($success): ?>
<p class=erfolgsmeldung><?= htmlspecialchars('Speichern erfolgreich') ?></p>
<?php endif; ?>
<button class="button-ellipsoid" id="start">
speichern
</button>
</div>
</form>
</div>
<script>
document.getElementById("input_deutsch").onblur = function() {
let wortAnzahl = 0;
let wort = document.getElementById("input_deutsch").value;
if(wort != '') {
fetch("forms/pruefeDuplikat.php", {
method: "POST",
headers: {"Content-Type": "application/json"},
body: JSON.stringify({ wort: wort})
})
.then(r => r.json())
.then(data => {
item = data;
if(item > 0) doppeltesWortGefunden(true);
else doppeltesWortGefunden(false)
});
function doppeltesWortGefunden(gefunden) {
if(gefunden) {
document.getElementById("input_deutsch").style.color = "red";
document.getElementById("input_deutsch").value = document.getElementById("input_deutsch").value + " ! WORT BEREITS VORHANDEN !";
document.getElementById("div_speichern").style.display = "none";
} else {
document.getElementById("input_deutsch").style.color = "black";
document.getElementById("div_speichern").style.display = "flex";
}
}
}
};
</script>
</body>
</html>