Spaltenerweiterung und Anzeigeverbesserungen. DBUPDATE !!!
This commit is contained in:
parent
1d9ba5d0ae
commit
01e0281e75
4 changed files with 350 additions and 139 deletions
|
|
@ -21,7 +21,34 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Daten abrufen
|
// Daten abrufen
|
||||||
$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 order by date desc;";
|
$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,
|
||||||
|
c.name AS kategorie,
|
||||||
|
pm.name AS zahlweise
|
||||||
|
FROM
|
||||||
|
entries e
|
||||||
|
JOIN user_names un ON e.id = un.id
|
||||||
|
LEFT JOIN categories c ON e.category = c.category_id
|
||||||
|
LEFT JOIN payment_methods pm ON e.payment_method = pm.payment_method_id
|
||||||
|
ORDER BY
|
||||||
|
date DESC;
|
||||||
|
";
|
||||||
|
|
||||||
$stmt = $pdo->prepare($sql);
|
$stmt = $pdo->prepare($sql);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$entries = $stmt->fetchAll();
|
$entries = $stmt->fetchAll();
|
||||||
|
|
@ -35,15 +62,6 @@ $entries = $stmt->fetchAll();
|
||||||
<link rel="stylesheet" href="assets/css/style.css">
|
<link rel="stylesheet" href="assets/css/style.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<script>
|
|
||||||
// JavaScript: Aktuelle Fensterbreite an PHP übergeben
|
|
||||||
function updateWidth() {
|
|
||||||
var width = window.innerWidth;
|
|
||||||
document.getElementById('width').textContent = width + 'px';
|
|
||||||
}
|
|
||||||
window.onload = updateWidth;
|
|
||||||
</script>
|
|
||||||
<p id="width" class="hide-on-mobile"></p>
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<!-- Navigation -->
|
<!-- Navigation -->
|
||||||
<nav class="nav">
|
<nav class="nav">
|
||||||
|
|
@ -77,8 +95,8 @@ window.onload = updateWidth;
|
||||||
<td><?= htmlspecialchars($entry['date']) ?></td>
|
<td><?= htmlspecialchars($entry['date']) ?></td>
|
||||||
<td class="hide-on-mobile"><?= htmlspecialchars($entry['zahler'] ?? '') ?></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['personen'] ?? '') ?></td>
|
||||||
<td class="hide-on-mobile"><?= htmlspecialchars($entry['category'] ?? '') ?></td>
|
<td class="hide-on-mobile"><?= htmlspecialchars($entry['kategorie'] ?? '') ?></td>
|
||||||
<td><?= htmlspecialchars($entry['payment_method'] ?? '') ?></td>
|
<td><?= htmlspecialchars($entry['zahlweise'] ?? '') ?></td>
|
||||||
<td><?= htmlspecialchars($entry['subject']) ?></td>
|
<td><?= htmlspecialchars($entry['subject']) ?></td>
|
||||||
<td class="align-right"><?= htmlspecialchars( number_format($entry['amount'], 2, ',', '.')) ?></td>
|
<td class="align-right"><?= htmlspecialchars( number_format($entry['amount'], 2, ',', '.')) ?></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
@ -87,7 +105,7 @@ window.onload = updateWidth;
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<!-- Neu-Button -->
|
<!-- Neu-Button -->
|
||||||
<a href="new_entry.php" class="btn-xr">Neu</a>
|
<a href="new_entry.php" class="btn-xr">+</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,10 @@ if (!isset($_SESSION['user_id'])) {
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="de">
|
<html lang="de">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=0.8">
|
<meta name="viewport" content="width=device-width, initial-scale=0.8">
|
||||||
<title>FSCash - Neuer Eintrag</title>
|
<title>FSCash - Neuer Eintrag</title>
|
||||||
<link rel="stylesheet" href="assets/css/style.css">
|
<link rel="stylesheet" href="assets/css/style.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<?php
|
<?php
|
||||||
|
|
@ -20,21 +20,19 @@ $loggedInUserId = "nix";
|
||||||
$debug = "";
|
$debug = "";
|
||||||
$users = [];
|
$users = [];
|
||||||
$categories = [];
|
$categories = [];
|
||||||
|
$pay_methods = [];
|
||||||
|
|
||||||
// save-Logik
|
// save-Logik
|
||||||
if (!empty($_POST)) { // $_SERVER['REQUEST_METHOD'] === 'POST') {
|
if (!empty($_POST)) {
|
||||||
echo "<p class=\"debug_hidden\">Empfangene POST-Daten:</p>";
|
echo "<p class=\"debug_hidden\">Empfangene POST-Daten:</p>";
|
||||||
echo "<ul class=\"debug_hidden\">";
|
echo "<ul class=\"debug_hidden\">";
|
||||||
// Durch alle POST-Variablen iterieren
|
|
||||||
foreach ($_POST as $key => $value) {
|
foreach ($_POST as $key => $value) {
|
||||||
if (is_array($value)) {
|
if (is_array($value)) {
|
||||||
// Falls es ein Array ist, z. B. bei Checkboxen oder multiple-Selects
|
|
||||||
$escapedValues = array_map(function($v) {
|
$escapedValues = array_map(function($v) {
|
||||||
return htmlspecialchars($v, ENT_QUOTES, 'UTF-8');
|
return htmlspecialchars($v, ENT_QUOTES, 'UTF-8');
|
||||||
}, $value);
|
}, $value);
|
||||||
echo "<li><strong>$key:</strong> " . implode(', ', $escapedValues) . "</li>";
|
echo "<li><strong>$key:</strong> " . implode(', ', $escapedValues) . "</li>";
|
||||||
} else {
|
} 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>";
|
||||||
}
|
}
|
||||||
|
|
@ -50,9 +48,7 @@ if (!empty($_POST)) { // $_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
$payment_method = isset($_POST['payment_method']) ? trim($_POST['payment_method']) : '';
|
$payment_method = isset($_POST['payment_method']) ? trim($_POST['payment_method']) : '';
|
||||||
$jsonPersonen = json_encode($person);
|
$jsonPersonen = json_encode($person);
|
||||||
|
|
||||||
// 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)
|
||||||
|
|
@ -70,119 +66,127 @@ if (!empty($_POST)) { // $_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
$output = ob_get_clean();
|
$output = ob_get_clean();
|
||||||
echo "<p class=\"debug_hidden\">SQL: " . $output . "</p>";
|
echo "<p class=\"debug_hidden\">SQL: " . $output . "</p>";
|
||||||
|
|
||||||
// Statement ausführen
|
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$data_saved = "true";
|
$data_saved = "true";
|
||||||
|
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
// Fehlerbehandlung
|
$data_saved = "Fehler: ";
|
||||||
$data_saved = "Fehler: "; // . $e->getMessage();
|
|
||||||
}
|
}
|
||||||
echo "<p class=\"debug_hidden\">SQL: " . $data_saved . "</p>";
|
echo "<p class=\"debug_hidden\">SQL: " . $data_saved . "</p>";
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Alle Benutzer aus der Tabelle 'users' laden
|
// Alle Benutzer aus der Tabelle 'users' laden
|
||||||
$stmtUsers = $pdo->prepare("SELECT * FROM users;");
|
$stmtUsers = $pdo->prepare("SELECT * FROM users order by id;");
|
||||||
$stmtUsers->execute();
|
$stmtUsers->execute();
|
||||||
$users = $stmtUsers->fetchAll(PDO::FETCH_ASSOC);
|
$users = $stmtUsers->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
foreach ($users as $user) {
|
foreach ($users as $user) {
|
||||||
if ($user['id'] == $_SESSION['user_id']) {
|
if ($user['id'] == $_SESSION['user_id']) {
|
||||||
$loggedInUserId = $user['id'];
|
$loggedInUserId = $user['id'];
|
||||||
break; // Schleife beenden, sobald gefunden
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Alle Kategorien aus der Tabelle 'categories' laden
|
// Alle Kategorien aus der Tabelle 'categories' laden
|
||||||
$stmtCategories = $pdo->prepare("SELECT * FROM categories");
|
$stmtCategories = $pdo->prepare("select * from categories order by category_id;");
|
||||||
$debug = $stmtCategories->queryString; // Enthält das reine SQL-Statement
|
$debug = $stmtCategories->queryString;
|
||||||
$stmtCategories->execute();
|
$stmtCategories->execute();
|
||||||
$categories = $stmtCategories->fetchAll(PDO::FETCH_ASSOC);
|
$categories = $stmtCategories->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
// Alle Zahlweisen aus der Tabelle 'pay_method' laden
|
||||||
|
$stmtPayMethods = $pdo->prepare("SELECT payment_method_id, name FROM payment_methods ORDER BY name;");
|
||||||
|
$stmtPayMethods->execute();
|
||||||
|
$pay_methods = $stmtPayMethods->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
$data_saved = "Fehler: "; // . $e->getMessage();
|
$data_saved = "Fehler: ";
|
||||||
}
|
}
|
||||||
// Aktuelles Datum im Format YYYY-MM-DD erzeugen
|
|
||||||
$currentDate = date('Y-m-d');
|
|
||||||
|
|
||||||
|
|
||||||
|
// Aktuelles Datum im Format YYYY-MM-DD erzeugen
|
||||||
|
$currentDate = date('Y-m-d');
|
||||||
?>
|
?>
|
||||||
<?php echo "<!-- data_saved:" . $data_saved . " Datum2: " . $currentDate . " -->"; ?>
|
|
||||||
<?php if ($data_saved == "true"): ?>
|
|
||||||
<div id="data-notice" class="data-notice">
|
|
||||||
Daten gespeichert !
|
|
||||||
<?php elseif ($data_saved != "nix"): ?>
|
|
||||||
<div id="data-notice" class="data-notice error">
|
|
||||||
<?php echo $data_saved; ?>
|
|
||||||
<?php endif; ?>
|
|
||||||
</div>
|
|
||||||
<div class="container">
|
|
||||||
|
|
||||||
<!-- Navigation -->
|
<?php echo "<!-- data_saved:" . $data_saved . " Datum2: " . $currentDate . " -->"; ?>
|
||||||
<nav class="nav">
|
<?php if ($data_saved == "true"): ?>
|
||||||
<button class="hamburger">☰</button>
|
<div id="data-notice" class="data-notice">
|
||||||
<ul class="nav-list">
|
Daten gespeichert !
|
||||||
<li><a href="dashboard.php">Start</a></li>
|
<?php elseif ($data_saved != "nix"): ?>
|
||||||
<li><a href="register.php">Neue User</a></li>
|
<div id="data-notice" class="data-notice error">
|
||||||
<li><a href="menu3.php" style="display: none;">Menüpunkt 3</a></li>
|
<?php echo $data_saved; ?>
|
||||||
<li><a href="menu4.php" style="display: none;">Menüpunkt 4</a></li>
|
<?php endif; ?>
|
||||||
<li><a href="menu5.php" style="display: none;">Menüpunkt 5</a></li>
|
</div>
|
||||||
</ul>
|
<div class="container">
|
||||||
<a href="logout.php" class="logout">Logout</a>
|
|
||||||
</nav>
|
|
||||||
|
|
||||||
<!-- <h1>Neuer Eintrag</h1> -->
|
<!-- Navigation -->
|
||||||
<form action="new_entry.php" method="post" class="form-container">
|
<nav class="nav">
|
||||||
<div class="form-group">
|
<button class="hamburger">☰</button>
|
||||||
<input type="date" name="date" value="<?php echo $currentDate; ?>" required>
|
<ul class="nav-list">
|
||||||
</div>
|
<li><a href="dashboard.php">Start</a></li>
|
||||||
<div class="form-group">
|
<li><a href="register.php">Neue User</a></li>
|
||||||
<select name="user_id" id="user_id">
|
<li><a href="menu3.php" style="display: none;">Menüpunkt 3</a></li>
|
||||||
<?php foreach ($users as $user): ?>
|
<li><a href="menu4.php" style="display: none;">Menüpunkt 4</a></li>
|
||||||
<option value="<?php echo htmlspecialchars($user['id']); ?>"
|
<li><a href="menu5.php" style="display: none;">Menüpunkt 5</a></li>
|
||||||
<?php if ($user['id'] == $loggedInUserId): ?> selected <?php endif; ?>
|
</ul>
|
||||||
>
|
<a href="logout.php" class="logout">Logout</a>
|
||||||
<?php echo htmlspecialchars($user['username']); ?>
|
</nav>
|
||||||
</option>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<!-- Person (Multiselect, alle vorselektiert) -->
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="person">für wen</label>
|
|
||||||
<select name="person[]" id="person" multiple required size="4">
|
|
||||||
<?php foreach ($users as $user): ?>
|
|
||||||
<option value="<?php echo htmlspecialchars($user['id']); ?>" selected>
|
|
||||||
<?php echo htmlspecialchars($user['username']); ?>
|
|
||||||
</option>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<!-- Category (Einkaufen vorselektiert) -->
|
|
||||||
<div class="form-group">
|
|
||||||
<!-- label for="category">Kategorie</label -->
|
|
||||||
<select name="category" id="category" required>
|
|
||||||
<?php foreach ($categories as $category): ?>
|
|
||||||
<option value="<?php echo htmlspecialchars($category['category_id']); ?>"
|
|
||||||
<?php echo ($category['name'] === 'Einkaufen' ? 'selected' : ''); ?>>
|
|
||||||
<?php echo htmlspecialchars($category['name']); ?>
|
|
||||||
</option>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<input type="text" name="subject" placeholder="Betreff" required>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<input type="number" name="amount" step="0.01" placeholder="Betrag" required>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<input type="text" name="payment_method" placeholder="Zahlweise">
|
|
||||||
</div>
|
|
||||||
<button type="submit" class="btn-xr">Speichern</button>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
</div>
|
<form action="new_entry.php" method="post" class="form-container">
|
||||||
<script src="assets/js/script.js"></script>
|
<div class="form-group">
|
||||||
|
<input type="date" name="date" value="<?php echo $currentDate; ?>" required>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<select name="user_id" id="user_id">
|
||||||
|
<?php foreach ($users as $user): ?>
|
||||||
|
<option value="<?php echo htmlspecialchars($user['id']); ?>"
|
||||||
|
<?php if ($user['id'] == $loggedInUserId): ?> selected <?php endif; ?>
|
||||||
|
>
|
||||||
|
<?php echo htmlspecialchars($user['username']); ?>
|
||||||
|
</option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<!-- Person (Multiselect, alle vorselektiert) -->
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="person">für wen</label>
|
||||||
|
<select name="person[]" id="person" multiple required size="4">
|
||||||
|
<?php foreach ($users as $user): ?>
|
||||||
|
<option value="<?php echo htmlspecialchars($user['id']); ?>" selected>
|
||||||
|
<?php echo htmlspecialchars($user['username']); ?>
|
||||||
|
</option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<!-- Category (Einkaufen vorselektiert) -->
|
||||||
|
<div class="form-group">
|
||||||
|
<select name="category" id="category" required>
|
||||||
|
<?php foreach ($categories as $category): ?>
|
||||||
|
<option value="<?php echo htmlspecialchars($category['category_id']); ?>"
|
||||||
|
<?php echo ($category['name'] === 'Einkaufen' ? 'selected' : ''); ?>>
|
||||||
|
<?php echo htmlspecialchars($category['name']); ?>
|
||||||
|
</option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<input type="text" name="subject" placeholder="Betreff" required>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<input type="number" name="amount" step="0.01" placeholder="Betrag" required>
|
||||||
|
</div>
|
||||||
|
<!-- Zahlweise (Dropdown) -->
|
||||||
|
<div class="form-group">
|
||||||
|
<select name="payment_method" id="payment_method" required>
|
||||||
|
<?php foreach ($pay_methods as $method): ?>
|
||||||
|
<option value="<?php echo htmlspecialchars($method['payment_method_id']); ?>">
|
||||||
|
<?php echo htmlspecialchars($method['name']); ?>
|
||||||
|
</option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn-xr">Speichern</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<script src="assets/js/script.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
188
html/new_entry_old.php
Normal file
188
html/new_entry_old.php
Normal file
|
|
@ -0,0 +1,188 @@
|
||||||
|
<?php
|
||||||
|
require 'config.php';
|
||||||
|
if (!isset($_SESSION['user_id'])) {
|
||||||
|
header('Location: index.php');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="de">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=0.8">
|
||||||
|
<title>FSCash - Neuer Eintrag</title>
|
||||||
|
<link rel="stylesheet" href="assets/css/style.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<?php
|
||||||
|
$data_saved = "nix";
|
||||||
|
$loggedInUserId = "nix";
|
||||||
|
$debug = "";
|
||||||
|
$users = [];
|
||||||
|
$categories = [];
|
||||||
|
|
||||||
|
// save-Logik
|
||||||
|
if (!empty($_POST)) { // $_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
|
echo "<p class=\"debug_hidden\">Empfangene POST-Daten:</p>";
|
||||||
|
echo "<ul class=\"debug_hidden\">";
|
||||||
|
// Durch alle POST-Variablen iterieren
|
||||||
|
foreach ($_POST as $key => $value) {
|
||||||
|
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');
|
||||||
|
echo "<li><strong>$key:</strong> $escapedValue</li>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
echo "</ul>";
|
||||||
|
|
||||||
|
$date = isset($_POST['date']) ? trim($_POST['date']) : '';
|
||||||
|
$user_id = isset($_POST['user_id']) ? trim($_POST['user_id']) : '';
|
||||||
|
$person = isset($_POST['person']) ? $_POST['person'] : '';
|
||||||
|
$category = isset($_POST['category']) ? trim($_POST['category']) : '';
|
||||||
|
$subject = isset($_POST['subject']) ? trim($_POST['subject']) : '';
|
||||||
|
$amount = isset($_POST['amount']) ? (float)$_POST['amount'] : 0.0;
|
||||||
|
$payment_method = isset($_POST['payment_method']) ? trim($_POST['payment_method']) : '';
|
||||||
|
$jsonPersonen = json_encode($person);
|
||||||
|
|
||||||
|
// SQL-Statement vorbereiten
|
||||||
|
try {
|
||||||
|
|
||||||
|
$stmt = $pdo->prepare("
|
||||||
|
INSERT INTO entries (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(':user_id', $user_id);
|
||||||
|
$stmt->bindParam(':person', $jsonPersonen);
|
||||||
|
$stmt->bindParam(':category', $category);
|
||||||
|
$stmt->bindParam(':subject', $subject);
|
||||||
|
$stmt->bindParam(':amount', $amount);
|
||||||
|
$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
|
||||||
|
$stmt->execute();
|
||||||
|
$data_saved = "true";
|
||||||
|
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
// Fehlerbehandlung
|
||||||
|
$data_saved = "Fehler: "; // . $e->getMessage();
|
||||||
|
}
|
||||||
|
echo "<p class=\"debug_hidden\">SQL: " . $data_saved . "</p>";
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Alle Benutzer aus der Tabelle 'users' laden
|
||||||
|
$stmtUsers = $pdo->prepare("SELECT * FROM users order by id;");
|
||||||
|
$stmtUsers->execute();
|
||||||
|
$users = $stmtUsers->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
foreach ($users as $user) {
|
||||||
|
if ($user['id'] == $_SESSION['user_id']) {
|
||||||
|
$loggedInUserId = $user['id'];
|
||||||
|
break; // Schleife beenden, sobald gefunden
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Alle Kategorien aus der Tabelle 'categories' laden
|
||||||
|
$stmtCategories = $pdo->prepare("select * from categories order by category_id;");
|
||||||
|
$debug = $stmtCategories->queryString; // Enthält das reine SQL-Statement
|
||||||
|
$stmtCategories->execute();
|
||||||
|
$categories = $stmtCategories->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
$data_saved = "Fehler: "; // . $e->getMessage();
|
||||||
|
}
|
||||||
|
// Aktuelles Datum im Format YYYY-MM-DD erzeugen
|
||||||
|
$currentDate = date('Y-m-d');
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
|
<?php echo "<!-- data_saved:" . $data_saved . " Datum2: " . $currentDate . " -->"; ?>
|
||||||
|
<?php if ($data_saved == "true"): ?>
|
||||||
|
<div id="data-notice" class="data-notice">
|
||||||
|
Daten gespeichert !
|
||||||
|
<?php elseif ($data_saved != "nix"): ?>
|
||||||
|
<div id="data-notice" class="data-notice error">
|
||||||
|
<?php echo $data_saved; ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
<div class="container">
|
||||||
|
|
||||||
|
<!-- Navigation -->
|
||||||
|
<nav class="nav">
|
||||||
|
<button class="hamburger">☰</button>
|
||||||
|
<ul class="nav-list">
|
||||||
|
<li><a href="dashboard.php">Start</a></li>
|
||||||
|
<li><a href="register.php">Neue User</a></li>
|
||||||
|
<li><a href="menu3.php" style="display: none;">Menüpunkt 3</a></li>
|
||||||
|
<li><a href="menu4.php" style="display: none;">Menüpunkt 4</a></li>
|
||||||
|
<li><a href="menu5.php" style="display: none;">Menüpunkt 5</a></li>
|
||||||
|
</ul>
|
||||||
|
<a href="logout.php" class="logout">Logout</a>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<!-- <h1>Neuer Eintrag</h1> -->
|
||||||
|
<form action="new_entry.php" method="post" class="form-container">
|
||||||
|
<div class="form-group">
|
||||||
|
<input type="date" name="date" value="<?php echo $currentDate; ?>" required>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<select name="user_id" id="user_id">
|
||||||
|
<?php foreach ($users as $user): ?>
|
||||||
|
<option value="<?php echo htmlspecialchars($user['id']); ?>"
|
||||||
|
<?php if ($user['id'] == $loggedInUserId): ?> selected <?php endif; ?>
|
||||||
|
>
|
||||||
|
<?php echo htmlspecialchars($user['username']); ?>
|
||||||
|
</option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<!-- Person (Multiselect, alle vorselektiert) -->
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="person">für wen</label>
|
||||||
|
<select name="person[]" id="person" multiple required size="4">
|
||||||
|
<?php foreach ($users as $user): ?>
|
||||||
|
<option value="<?php echo htmlspecialchars($user['id']); ?>" selected>
|
||||||
|
<?php echo htmlspecialchars($user['username']); ?>
|
||||||
|
</option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<!-- Category (Einkaufen vorselektiert) -->
|
||||||
|
<div class="form-group">
|
||||||
|
<!-- label for="category">Kategorie</label -->
|
||||||
|
<select name="category" id="category" required>
|
||||||
|
<?php foreach ($categories as $category): ?>
|
||||||
|
<option value="<?php echo htmlspecialchars($category['category_id']); ?>"
|
||||||
|
<?php echo ($category['name'] === 'Einkaufen' ? 'selected' : ''); ?>>
|
||||||
|
<?php echo htmlspecialchars($category['name']); ?>
|
||||||
|
</option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<input type="text" name="subject" placeholder="Betreff" required>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<input type="number" name="amount" step="0.01" placeholder="Betrag" required>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<input type="text" name="payment_method" placeholder="Zahlweise">
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn-xr">Speichern</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<script src="assets/js/script.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
@ -1 +1,2 @@
|
||||||
alter table entries modify column category json;
|
UPDATE entries SET payment_method = '1' WHERE LOWER(payment_method) = 'bar';
|
||||||
|
alter table entries modify column payment_method int(11);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue