Auswahllisten, Text statt IDs, DB UPDATE !!! - breaking change.
This commit is contained in:
parent
3db61b2973
commit
9da209d0d2
5 changed files with 51 additions and 49 deletions
|
|
@ -30,6 +30,9 @@ h1 {
|
||||||
color: var(--dark-color);
|
color: var(--dark-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.debug_hidden {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
/* Container */
|
/* Container */
|
||||||
.container {
|
.container {
|
||||||
max-width: 1600px;
|
max-width: 1600px;
|
||||||
|
|
@ -295,6 +298,14 @@ tr:hover {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.data-notice {
|
||||||
|
background-color: lightgreen;
|
||||||
|
}
|
||||||
|
|
||||||
|
.data-notice.error {
|
||||||
|
background-color: LightCoral;
|
||||||
|
}
|
||||||
|
|
||||||
#cookie-notice.hidden {
|
#cookie-notice.hidden {
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
max-height: 0;
|
max-height: 0;
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Daten abrufen
|
// Daten abrufen
|
||||||
$stmt = $pdo->prepare("SELECT * FROM entries WHERE MONTH(date) = MONTH(CURDATE()) AND YEAR(date) = YEAR(CURDATE())");
|
$sql="WITH user_names AS (SELECT p.id,b_single.username AS zahler,GROUP_CONCAT(b_array.username) AS personen FROM entries p LEFT JOIN users b_single ON p.user_id = b_single.id JOIN JSON_TABLE(p.person,'$[*]' COLUMNS(id INT PATH '$')) AS jt LEFT JOIN users b_array ON jt.id = b_array.id GROUP BY p.id, b_single.username) SELECT e.*, un.zahler, un.personen FROM entries e JOIN user_names un ON e.id = un.id;";
|
||||||
|
$stmt = $pdo->prepare($sql);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$entries = $stmt->fetchAll();
|
$entries = $stmt->fetchAll();
|
||||||
?>
|
?>
|
||||||
|
|
@ -53,6 +54,7 @@ $entries = $stmt->fetchAll();
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Datum</th>
|
<th>Datum</th>
|
||||||
|
<th class="hide-on-mobile">Zahler</th>
|
||||||
<th class="hide-on-mobile">Person</th>
|
<th class="hide-on-mobile">Person</th>
|
||||||
<th class="hide-on-mobile">Kategorie</th>
|
<th class="hide-on-mobile">Kategorie</th>
|
||||||
<th>Zahlweise</th>
|
<th>Zahlweise</th>
|
||||||
|
|
@ -64,7 +66,8 @@ $entries = $stmt->fetchAll();
|
||||||
<?php foreach ($entries as $entry): ?>
|
<?php foreach ($entries as $entry): ?>
|
||||||
<tr>
|
<tr>
|
||||||
<td><?= htmlspecialchars($entry['date']) ?></td>
|
<td><?= htmlspecialchars($entry['date']) ?></td>
|
||||||
<td class="hide-on-mobile"><?= htmlspecialchars($entry['person'] ?? '') ?></td>
|
<td class="hide-on-mobile"><?= htmlspecialchars($entry['zahler'] ?? '') ?></td>
|
||||||
|
<td class="hide-on-mobile"><?= htmlspecialchars($entry['personen'] ?? '') ?></td>
|
||||||
<td class="hide-on-mobile"><?= htmlspecialchars($entry['category'] ?? '') ?></td>
|
<td class="hide-on-mobile"><?= htmlspecialchars($entry['category'] ?? '') ?></td>
|
||||||
<td><?= htmlspecialchars($entry['payment_method'] ?? '') ?></td>
|
<td><?= htmlspecialchars($entry['payment_method'] ?? '') ?></td>
|
||||||
<td><?= htmlspecialchars($entry['subject']) ?></td>
|
<td><?= htmlspecialchars($entry['subject']) ?></td>
|
||||||
|
|
|
||||||
|
|
@ -22,39 +22,54 @@ $users = [];
|
||||||
$categories = [];
|
$categories = [];
|
||||||
|
|
||||||
// save-Logik
|
// save-Logik
|
||||||
if (!empty($_POST) && isset($DEBUG)) { // $_SERVER['REQUEST_METHOD'] === 'POST') {
|
if (!empty($_POST)) { // $_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
echo "<h3>Empfangene POST-Daten:</h3>";
|
echo "<p class=\"debug_hidden\">Empfangene POST-Daten:</p>";
|
||||||
echo "<ul>";
|
echo "<ul class=\"debug_hidden\">";
|
||||||
// Durch alle POST-Variablen iterieren
|
// Durch alle POST-Variablen iterieren
|
||||||
foreach ($_POST as $key => $value) {
|
foreach ($_POST as $key => $value) {
|
||||||
// Wert escapen, um XSS zu vermeiden
|
if (is_array($value)) {
|
||||||
|
// Falls es ein Array ist, z. B. bei Checkboxen oder multiple-Selects
|
||||||
|
$escapedValues = array_map(function($v) {
|
||||||
|
return htmlspecialchars($v, ENT_QUOTES, 'UTF-8');
|
||||||
|
}, $value);
|
||||||
|
echo "<li><strong>$key:</strong> " . implode(', ', $escapedValues) . "</li>";
|
||||||
|
} else {
|
||||||
|
// Standardfall: String escapen
|
||||||
$escapedValue = htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
|
$escapedValue = htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
|
||||||
echo "<li><strong>$key:</strong> $escapedValue</li>";
|
echo "<li><strong>$key:</strong> $escapedValue</li>";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
echo "</ul>";
|
echo "</ul>";
|
||||||
// POST-Daten abrufen und escapen
|
|
||||||
$date = isset($_POST['date']) ? trim($_POST['date']) : '';
|
$date = isset($_POST['date']) ? trim($_POST['date']) : '';
|
||||||
$user_id = isset($_POST['user_id']) ? trim($_POST['user_id']) : '';
|
$user_id = isset($_POST['user_id']) ? trim($_POST['user_id']) : '';
|
||||||
$person = isset($_POST['person']) ? trim($_POST['person']) : '';
|
$person = isset($_POST['person']) ? $_POST['person'] : '';
|
||||||
$category = isset($_POST['category']) ? trim($_POST['category']) : '';
|
$category = isset($_POST['category']) ? trim($_POST['category']) : '';
|
||||||
$subject = isset($_POST['subject']) ? trim($_POST['subject']) : '';
|
$subject = isset($_POST['subject']) ? trim($_POST['subject']) : '';
|
||||||
$amount = isset($_POST['amount']) ? (float)$_POST['amount'] : 0.0;
|
$amount = isset($_POST['amount']) ? (float)$_POST['amount'] : 0.0;
|
||||||
$payment_method = isset($_POST['payment_method']) ? trim($_POST['payment_method']) : '';
|
$payment_method = isset($_POST['payment_method']) ? trim($_POST['payment_method']) : '';
|
||||||
|
$jsonPersonen = json_encode($person);
|
||||||
|
|
||||||
// SQL-Statement vorbereiten
|
// SQL-Statement vorbereiten
|
||||||
try {
|
try {
|
||||||
|
|
||||||
$stmt = $pdo->prepare("
|
$stmt = $pdo->prepare("
|
||||||
INSERT INTO entries (date, user_id, person, category, subject, amount, payment_method)
|
INSERT INTO entries (date, user_id, person, category, subject, amount, payment_method)
|
||||||
VALUES (:date, :user_id, :person, :category, :subject, :amount, :payment_method)
|
VALUES (:date, :user_id, :person, :category, :subject, :amount, :payment_method)
|
||||||
");
|
");
|
||||||
$stmt->bindParam(':date', $date);
|
$stmt->bindParam(':date', $date);
|
||||||
$stmt->bindParam(':user_id', $user_id);
|
$stmt->bindParam(':user_id', $user_id);
|
||||||
$stmt->bindParam(':person', $person);
|
$stmt->bindParam(':person', $jsonPersonen);
|
||||||
$stmt->bindParam(':category', $category);
|
$stmt->bindParam(':category', $category);
|
||||||
$stmt->bindParam(':subject', $subject);
|
$stmt->bindParam(':subject', $subject);
|
||||||
$stmt->bindParam(':amount', $amount);
|
$stmt->bindParam(':amount', $amount);
|
||||||
$stmt->bindParam(':payment_method', $payment_method);
|
$stmt->bindParam(':payment_method', $payment_method);
|
||||||
|
|
||||||
|
ob_start();
|
||||||
|
$stmt->debugDumpParams();
|
||||||
|
$output = ob_get_clean();
|
||||||
|
echo "<p class=\"debug_hidden\">SQL: " . $output . "</p>";
|
||||||
|
|
||||||
// Statement ausführen
|
// Statement ausführen
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$data_saved = "true";
|
$data_saved = "true";
|
||||||
|
|
@ -63,7 +78,7 @@ if (!empty($_POST) && isset($DEBUG)) { // $_SERVER['REQUEST_METHOD'] === 'POST'
|
||||||
// Fehlerbehandlung
|
// Fehlerbehandlung
|
||||||
$data_saved = "Fehler: "; // . $e->getMessage();
|
$data_saved = "Fehler: "; // . $e->getMessage();
|
||||||
}
|
}
|
||||||
|
echo "<p class=\"debug_hidden\">SQL: " . $data_saved . "</p>";
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
@ -93,11 +108,14 @@ try {
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<?php echo "<!-- data_saved:" . $data_saved . " Datum2: " . $currentDate . " -->"; ?>
|
<?php echo "<!-- data_saved:" . $data_saved . " Datum2: " . $currentDate . " -->"; ?>
|
||||||
<?php if ($data_saved != "nix"): ?>
|
<?php if ($data_saved == "true"): ?>
|
||||||
<div id="data-notice" class="data-notice">
|
<div id="data-notice" class="data-notice">
|
||||||
Data
|
Daten gespeichert !
|
||||||
</div>
|
<?php elseif ($data_saved != "nix"): ?>
|
||||||
|
<div id="data-notice" class="data-notice error">
|
||||||
|
<?php echo $data_saved; ?>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
|
||||||
<!-- Navigation -->
|
<!-- Navigation -->
|
||||||
|
|
@ -156,7 +174,7 @@ try {
|
||||||
<input type="text" name="subject" placeholder="Betreff" required>
|
<input type="text" name="subject" placeholder="Betreff" required>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<input type="number" name="amount" placeholder="Betrag" required>
|
<input type="number" name="amount" step="0.01" placeholder="Betrag" required>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<input type="text" name="payment_method" placeholder="Zahlweise">
|
<input type="text" name="payment_method" placeholder="Zahlweise">
|
||||||
|
|
|
||||||
2
init.sql
2
init.sql
|
|
@ -22,7 +22,7 @@ CREATE TABLE IF NOT EXISTS entries (
|
||||||
user_id INT NOT NULL,
|
user_id INT NOT NULL,
|
||||||
person VARCHAR(50),
|
person VARCHAR(50),
|
||||||
date DATE NOT NULL,
|
date DATE NOT NULL,
|
||||||
category VARCHAR(50),
|
category json,
|
||||||
subject VARCHAR(255) NOT NULL,
|
subject VARCHAR(255) NOT NULL,
|
||||||
amount DECIMAL(10,2) NOT NULL,
|
amount DECIMAL(10,2) NOT NULL,
|
||||||
payment_method VARCHAR(50),
|
payment_method VARCHAR(50),
|
||||||
|
|
|
||||||
32
update.sql
32
update.sql
|
|
@ -1,31 +1 @@
|
||||||
USE finanzapp;
|
alter table entries modify column category json;
|
||||||
|
|
||||||
-- Tabelle für Kategorien (Ausgabenarten) anlegen
|
|
||||||
CREATE TABLE IF NOT EXISTS categories (
|
|
||||||
category_id INT AUTO_INCREMENT PRIMARY KEY,
|
|
||||||
name VARCHAR(50) NOT NULL UNIQUE
|
|
||||||
);
|
|
||||||
|
|
||||||
-- Tabelle für Zahlungsmittel anlegen
|
|
||||||
CREATE TABLE IF NOT EXISTS payment_methods (
|
|
||||||
payment_method_id INT AUTO_INCREMENT PRIMARY KEY,
|
|
||||||
name VARCHAR(50) NOT NULL UNIQUE
|
|
||||||
);
|
|
||||||
|
|
||||||
-- Daten in 'categories' einfügen, falls Tabelle leer ist
|
|
||||||
INSERT INTO categories (name)
|
|
||||||
SELECT 'Einkaufen' UNION ALL
|
|
||||||
SELECT 'Essen gehen' UNION ALL
|
|
||||||
SELECT 'Freizeit' UNION ALL
|
|
||||||
SELECT 'PuFra' UNION ALL
|
|
||||||
SELECT 'Urlaub gemeinsam' UNION ALL
|
|
||||||
SELECT 'Urlaub Pössi' UNION ALL
|
|
||||||
SELECT 'Barausgaben'
|
|
||||||
WHERE NOT EXISTS (SELECT 1 FROM categories);
|
|
||||||
|
|
||||||
-- Daten in 'payment_methods' einfügen, falls Tabelle leer ist
|
|
||||||
INSERT INTO payment_methods (name)
|
|
||||||
SELECT 'Bar' UNION ALL
|
|
||||||
SELECT 'Karte' UNION ALL
|
|
||||||
SELECT 'Paypal'
|
|
||||||
WHERE NOT EXISTS (SELECT 1 FROM payment_methods);
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue