Zufallsgenerator deaktiviert, reguläre Verben können hinzugefügt werden
This commit is contained in:
parent
7680e7ce51
commit
b3b38dcd14
@ -24,7 +24,7 @@
|
|||||||
<h2 class="seitentitel">pyolingo</h2>
|
<h2 class="seitentitel">pyolingo</h2>
|
||||||
</div>
|
</div>
|
||||||
<div class="inhalt">
|
<div class="inhalt">
|
||||||
<form id="form_hinzufuegenkarte" action="forms/hinzuefuegenKarte.php" method="post">
|
<form id="form_hinzufuegenkarte" action="forms/hinzufuegenKarte.php" method="post">
|
||||||
<div class="hinzufuegenKarteElemente">
|
<div class="hinzufuegenKarteElemente">
|
||||||
<label class="kategorie">
|
<label class="kategorie">
|
||||||
<input class="kategorie" type="radio" name="kategorie" value="substantive"
|
<input class="kategorie" type="radio" name="kategorie" value="substantive"
|
||||||
|
|||||||
@ -1,106 +0,0 @@
|
|||||||
<?php
|
|
||||||
require_once __DIR__ . '/../includes/db_connect.php';
|
|
||||||
|
|
||||||
session_start();
|
|
||||||
|
|
||||||
$_SESSION['old'] = $_POST;
|
|
||||||
|
|
||||||
$return = $_POST['return'] ?? 'allgemein';
|
|
||||||
|
|
||||||
$kategorie = $_POST['kategorie'] ?? 'substantive';
|
|
||||||
$deutsch = trim($_POST['deutsch'] ?? '');
|
|
||||||
|
|
||||||
if($kategorie == 'verben') {
|
|
||||||
for($i = 0; $i < 7; $i++) {
|
|
||||||
$wortstamm[$i] = trim($_POST['wortstamm_' . $i] ?? '');
|
|
||||||
|
|
||||||
$endung[$i] = trim($_POST['endung_' . $i] ?? '');
|
|
||||||
$compareString += $endung[$i];
|
|
||||||
|
|
||||||
$suffix[$i] = trim($_POST['suffix_' . $i] ?? '');
|
|
||||||
}
|
|
||||||
|
|
||||||
if($compareString != '') {
|
|
||||||
$italienisch = $wortstamm;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for($i = 0; $i < 7; $i++) {
|
|
||||||
$italienisch[$i] = trim($_POST['italienisch_' . $i] ?? '');
|
|
||||||
$farbe[$i] = $_POST['farbe_' . $i] ?? 'black';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if($deutsch === '') {
|
|
||||||
$_SESSION['error'] = "Das deutsche Wort darf nicht leer sein!";
|
|
||||||
header("Location: ../$return.php");
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
if($italienisch[0] === '') {
|
|
||||||
$_SESSION['error'] = "Das erste italienische Wort darf nicht leer sein!";
|
|
||||||
header("Location: ../$return.php");
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
insertDB($pdo, $kategorie, $deutsch, $italienisch, $farbe);
|
|
||||||
|
|
||||||
unset($_SESSION['old']);
|
|
||||||
|
|
||||||
function insertDB(PDO $pdo, string $kategorie, string $deutsch, array $italienisch, array $farbe) {
|
|
||||||
try {
|
|
||||||
$pdo->beginTransaction();
|
|
||||||
|
|
||||||
$stmt = $pdo->prepare("SELECT id
|
|
||||||
FROM deutsch
|
|
||||||
WHERE LOWER(wort) = LOWER(:deutsch);");
|
|
||||||
$stmt->execute(['deutsch' => $deutsch]);
|
|
||||||
if($stmt->fetchColumn() != null) throw new Exception('deutsches Wort bereits vorhanden');
|
|
||||||
|
|
||||||
$stmt = $pdo->prepare("SELECT id
|
|
||||||
FROM kategorie
|
|
||||||
WHERE LOWER(name) = LOWER(:kategorie);");
|
|
||||||
$stmt->execute(['kategorie' => $kategorie]);
|
|
||||||
$kategorie_id = $stmt->fetchColumn();
|
|
||||||
|
|
||||||
$stmt = $pdo->query("SELECT id,
|
|
||||||
farbe
|
|
||||||
FROM farbe;");
|
|
||||||
$farbe_array = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
||||||
|
|
||||||
$stmt = $pdo->prepare("INSERT INTO deutsch(wort, kategorie_id, wort_hinzugefuegt)
|
|
||||||
VALUES (:wort, :kategorie_id, (:wort_hinzugefuegt)::timestamp);");
|
|
||||||
$stmt->execute(['wort' => $deutsch,
|
|
||||||
'kategorie_id' => $kategorie_id,
|
|
||||||
'wort_hinzugefuegt' => date('Y-m-d H:i:s')]);
|
|
||||||
|
|
||||||
$stmt = $pdo->prepare("SELECT id
|
|
||||||
FROM deutsch
|
|
||||||
WHERE LOWER(wort) = LOWER(:deutsch);");
|
|
||||||
$stmt->execute(['deutsch' => $deutsch]);
|
|
||||||
$deutsch_id = $stmt->fetchColumn();
|
|
||||||
|
|
||||||
for($i = 0; $i < 7; $i++) {
|
|
||||||
$farbe_id = -1;
|
|
||||||
foreach($farbe_array as $it_farbe) if($it_farbe['farbe'] == $farbe[$i]) $farbe_id = $it_farbe['id'];
|
|
||||||
|
|
||||||
$stmt = $pdo->prepare("INSERT INTO italienisch (wort, deutsch_id, farbe_id)
|
|
||||||
VALUES (:italienisch, :deutsch_id, :farbe_id)");
|
|
||||||
$stmt->execute(['italienisch' => $italienisch[$i],
|
|
||||||
'deutsch_id' => $deutsch_id,
|
|
||||||
'farbe_id' => $farbe_id]);
|
|
||||||
}
|
|
||||||
|
|
||||||
$pdo->commit();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
} catch(Exception $e) {
|
|
||||||
$pdo->rollBack();
|
|
||||||
echo "Fehler: " . $e->getMessage();
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$_SESSION['success'] = "neues Wort gespeichert";
|
|
||||||
header("Location: ../$return.php");
|
|
||||||
exit;
|
|
||||||
?>
|
|
||||||
146
forms/hinzufuegenKarte.php
Normal file
146
forms/hinzufuegenKarte.php
Normal file
@ -0,0 +1,146 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__ . '/../includes/db_connect.php';
|
||||||
|
|
||||||
|
session_start();
|
||||||
|
|
||||||
|
$_SESSION['old'] = $_POST;
|
||||||
|
|
||||||
|
$return = $_POST['return'] ?? 'allgemein';
|
||||||
|
|
||||||
|
$kategorie = $_POST['kategorie'] ?? 'substantive';
|
||||||
|
$deutsch = trim($_POST['deutsch'] ?? '');
|
||||||
|
$suffix = trim($_POST['suffix'] ?? null);
|
||||||
|
|
||||||
|
$italienisch = [];
|
||||||
|
$farbe = [];
|
||||||
|
$wortstamm = [];
|
||||||
|
$endung = [];
|
||||||
|
|
||||||
|
$endungVergleich = '';
|
||||||
|
|
||||||
|
if($kategorie != 'verben') {
|
||||||
|
for($i = 0; $i < 7; $i++) {
|
||||||
|
$italienisch[$i] = trim($_POST['italienisch_' . $i] ?? '');
|
||||||
|
$farbe[$i] = $_POST['farbe_' . $i] ?? 'black';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for($i = 0; $i < 7; $i++) {
|
||||||
|
$wortstamm[$i] = trim($_POST['wortstamm_' . $i] ?? '');
|
||||||
|
|
||||||
|
$endung[$i] = trim($_POST['endung_' . $i] ?? '');
|
||||||
|
$endungVergleich .= $endung[$i];
|
||||||
|
}
|
||||||
|
|
||||||
|
if($endungVergleich == '') $endung = [];
|
||||||
|
|
||||||
|
$return = 'verben';
|
||||||
|
}
|
||||||
|
|
||||||
|
if($deutsch === '') {
|
||||||
|
$_SESSION['error'] = "Das deutsche Wort darf nicht leer sein!";
|
||||||
|
header("Location: ../$return.php");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
if(count($italienisch) == 0 && count($wortstamm) == 0) {
|
||||||
|
$_SESSION['error'] = "Das erste italienische Wort darf nicht leer sein!";
|
||||||
|
header("Location: ../$return.php");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
insertDB($pdo, $kategorie, $deutsch, $italienisch, $farbe, $wortstamm, $endung, $suffix);
|
||||||
|
|
||||||
|
unset($_SESSION['old']);
|
||||||
|
|
||||||
|
function insertDB(PDO $pdo,
|
||||||
|
string $kategorie,
|
||||||
|
string $deutsch,
|
||||||
|
array $italienisch,
|
||||||
|
array $farbe,
|
||||||
|
array $wortstamm,
|
||||||
|
array $endung,
|
||||||
|
string $suffix) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
$pdo->beginTransaction();
|
||||||
|
|
||||||
|
$stmt = $pdo->prepare("SELECT id
|
||||||
|
FROM deutsch
|
||||||
|
WHERE LOWER(wort) = LOWER(:deutsch);");
|
||||||
|
$stmt->execute(['deutsch' => $deutsch]);
|
||||||
|
if($stmt->fetchColumn() != null) throw new Exception('deutsches Wort bereits vorhanden');
|
||||||
|
|
||||||
|
$stmt = $pdo->prepare("SELECT id
|
||||||
|
FROM kategorie
|
||||||
|
WHERE LOWER(name) = LOWER(:kategorie);");
|
||||||
|
$stmt->execute(['kategorie' => $kategorie]);
|
||||||
|
$kategorie_id = $stmt->fetchColumn();
|
||||||
|
|
||||||
|
$stmt = $pdo->query("SELECT id,
|
||||||
|
farbe
|
||||||
|
FROM farbe;");
|
||||||
|
$farbe_array = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
$stmt = $pdo->prepare("INSERT INTO deutsch(wort, kategorie_id, wort_hinzugefuegt)
|
||||||
|
VALUES (:wort, :kategorie_id, (:wort_hinzugefuegt)::timestamp);");
|
||||||
|
$stmt->execute(['wort' => $deutsch,
|
||||||
|
'kategorie_id' => $kategorie_id,
|
||||||
|
'wort_hinzugefuegt' => date('Y-m-d H:i:s')]);
|
||||||
|
|
||||||
|
$stmt = $pdo->prepare("SELECT id
|
||||||
|
FROM deutsch
|
||||||
|
WHERE LOWER(wort) = LOWER(:deutsch);");
|
||||||
|
$stmt->execute(['deutsch' => $deutsch]);
|
||||||
|
$deutsch_id = $stmt->fetchColumn();
|
||||||
|
|
||||||
|
if($kategorie != 'verben') {
|
||||||
|
for($i = 0; $i < 7; $i++) {
|
||||||
|
$farbe_id = -1;
|
||||||
|
foreach($farbe_array as $it_farbe) if($it_farbe['farbe'] == $farbe[$i]) $farbe_id = $it_farbe['id'];
|
||||||
|
|
||||||
|
if($italienisch[$i] != "") {
|
||||||
|
$stmt = $pdo->prepare("INSERT INTO italienisch (wort, deutsch_id, farbe_id)
|
||||||
|
VALUES (:italienisch, :deutsch_id, :farbe_id)");
|
||||||
|
$stmt->execute(['italienisch' => $italienisch[$i],
|
||||||
|
'deutsch_id' => $deutsch_id,
|
||||||
|
'farbe_id' => $farbe_id]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$stmt = $pdo->query("SELECT id FROM personalpronomen;");
|
||||||
|
$personalpronomen = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
for($i = 0; $i < 7; $i++) {
|
||||||
|
$pp = ($i == 0) ? null : $personalpronomen[$i - 1]['id'];
|
||||||
|
|
||||||
|
if(count($endung) == 0) {
|
||||||
|
$stmt = $pdo->prepare("INSERT INTO italienisch (wort, deutsch_id, personalpronomen_id, suffix)
|
||||||
|
VALUES (:wortstamm, :deutsch_id, :personalpronomen_id, :suffix)");
|
||||||
|
$stmt->execute(['wortstamm' => $wortstamm[$i],
|
||||||
|
'deutsch_id' => $deutsch_id,
|
||||||
|
'personalpronomen_id' => $pp,
|
||||||
|
'suffix' => $suffix]);
|
||||||
|
} else {
|
||||||
|
$stmt = $pdo->prepare("INSERT INTO italienisch (wort, deutsch_id, personalpronomen_id, suffix, wortstamm)
|
||||||
|
VALUES (:wort, :deutsch_id, :personalpronomen_id, :suffix, :wortstamm)");
|
||||||
|
$stmt->execute(['wortstamm' => $endung[$i],
|
||||||
|
'deutsch_id' => $deutsch_id,
|
||||||
|
'personalpronomen_id' => $pp,
|
||||||
|
'suffix' => $suffix]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$pdo->commit();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
} catch(Exception $e) {
|
||||||
|
$pdo->rollBack();
|
||||||
|
echo "Fehler: " . $e->getMessage();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$_SESSION['success'] = "neues Wort gespeichert";
|
||||||
|
header("Location: ../$return.php");
|
||||||
|
exit;
|
||||||
@ -112,7 +112,7 @@
|
|||||||
.then(r => r.json())
|
.then(r => r.json())
|
||||||
.then(data => items = data);
|
.then(data => items = data);
|
||||||
|
|
||||||
items.sort(() => Math.random() - 0.5);
|
//items.sort(() => Math.random() - 0.5);
|
||||||
|
|
||||||
document.getElementById("start").onclick = function() {
|
document.getElementById("start").onclick = function() {
|
||||||
if(document.getElementById("start").innerText != "Neustart") {
|
if(document.getElementById("start").innerText != "Neustart") {
|
||||||
@ -120,7 +120,7 @@
|
|||||||
document.getElementById("start").innerText = "Neustart";
|
document.getElementById("start").innerText = "Neustart";
|
||||||
showVorderseite();
|
showVorderseite();
|
||||||
} else {
|
} else {
|
||||||
items.sort(() => Math.random() - 0.5);
|
//items.sort(() => Math.random() - 0.5);
|
||||||
index = 0;
|
index = 0;
|
||||||
showVorderseite();
|
showVorderseite();
|
||||||
document.getElementById("italienisch").style.display = "none";
|
document.getElementById("italienisch").style.display = "none";
|
||||||
|
|||||||
20
verben.php
20
verben.php
@ -24,7 +24,7 @@
|
|||||||
<h2 class="seitentitel">pyolingo</h2>
|
<h2 class="seitentitel">pyolingo</h2>
|
||||||
</div>
|
</div>
|
||||||
<div class="inhalt">
|
<div class="inhalt">
|
||||||
<form id="form_hinzufuegenkarte" action="forms/hinzuefuegenKarte.php" method="post">
|
<form id="form_hinzufuegenkarte" action="forms/hinzufuegenKarte.php" method="post">
|
||||||
<input id="hiddenInputEditTyp" type="hidden" name="kategorie" value="verben">
|
<input id="hiddenInputEditTyp" type="hidden" name="kategorie" value="verben">
|
||||||
<div>
|
<div>
|
||||||
<p class="kategorie" id="p_deutsch">deutsch:</p>
|
<p class="kategorie" id="p_deutsch">deutsch:</p>
|
||||||
@ -35,12 +35,21 @@
|
|||||||
value="<?= htmlspecialchars($old['deutsch'] ?? '') ?>"
|
value="<?= htmlspecialchars($old['deutsch'] ?? '') ?>"
|
||||||
required>
|
required>
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
<p class="kategorie" id="p_deutsch">Suffix:</p>
|
||||||
|
<input class="kategorie"
|
||||||
|
id="input_deutsch"
|
||||||
|
type="text"
|
||||||
|
name="suffix"
|
||||||
|
value="<?= htmlspecialchars($old['suffix'] ?? '') ?>"
|
||||||
|
required>
|
||||||
|
</div>
|
||||||
<table id="table_verben">
|
<table id="table_verben">
|
||||||
<tr>
|
<tr>
|
||||||
<th></th>
|
<th></th>
|
||||||
<th>Wortstamm</th>
|
<th>Wortstamm</th>
|
||||||
<th>Endung</th>
|
<th>Endung</th>
|
||||||
<th>Suffix</th>
|
<!--th>Suffix</th-->
|
||||||
</tr>
|
</tr>
|
||||||
<?php for($i = 0; $i < 7; $i++) { ?>
|
<?php for($i = 0; $i < 7; $i++) { ?>
|
||||||
<tr>
|
<tr>
|
||||||
@ -66,7 +75,6 @@
|
|||||||
name="wortstamm_<?= $i ?>"
|
name="wortstamm_<?= $i ?>"
|
||||||
value="<?= htmlspecialchars(($old['wortstamm_' . $i] ?? '')) ?>"
|
value="<?= htmlspecialchars(($old['wortstamm_' . $i] ?? '')) ?>"
|
||||||
required>
|
required>
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<input class="kategorie"
|
<input class="kategorie"
|
||||||
@ -75,15 +83,13 @@
|
|||||||
name="endung_<?= $i ?>"
|
name="endung_<?= $i ?>"
|
||||||
value="<?= htmlspecialchars(($old['endung_' . $i] ?? '')) ?>">
|
value="<?= htmlspecialchars(($old['endung_' . $i] ?? '')) ?>">
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<!--td>
|
||||||
<input class="kategorie"
|
<input class="kategorie"
|
||||||
id="input_suffix"
|
id="input_suffix"
|
||||||
type="text"
|
type="text"
|
||||||
name="suffix_< ?= $i ?>"
|
name="suffix_< ?= $i ?>"
|
||||||
value="< ?= htmlspecialchars(($old['suffix_' . $i] ?? '')) ?>">
|
value="< ?= htmlspecialchars(($old['suffix_' . $i] ?? '')) ?>">
|
||||||
</td>
|
</td-->
|
||||||
|
|
||||||
|
|
||||||
</tr>
|
</tr>
|
||||||
<?php }; ?>
|
<?php }; ?>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user