FSCash/html/dashboard.php

88 lines
2.4 KiB
PHP

<?php
require 'config.php';
//if (!isset($_SESSION['user_id'])) {
// header('Location: index.php');
// exit;
//}
// echo $_SESSION['user_id'];
error_log($_SESSION['user_id']);
// Login-Logik
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$stmt = $pdo->prepare("SELECT * FROM users WHERE username = ?");
$stmt->execute([$_POST['username']]);
$user = $stmt->fetch();
if ($user && password_verify($_POST['password'], $user['password'])) {
$_SESSION['user_id'] = $user['id'];
} else {
header('Location: index.php');
exit;
}
}
// Daten abrufen
$stmt = $pdo->prepare("SELECT * FROM entries WHERE MONTH(date) = MONTH(CURDATE()) AND YEAR(date) = YEAR(CURDATE())");
$stmt->execute();
$entries = $stmt->fetchAll();
?>
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>FSCash - Dashboard</title>
<link rel="stylesheet" href="assets/css/style.css">
</head>
<body>
<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>
<!-- Tabelle -->
<table>
<thead>
<tr>
<th>Datum</th>
<th class="hide-on-mobile">Person</th>
<th class="hide-on-mobile">Kategorie</th>
<th>Zahlweise</th>
<th>Betreff</th>
<th>Betrag</th>
</tr>
</thead>
<tbody>
<?php foreach ($entries as $entry): ?>
<tr>
<td><?= htmlspecialchars($entry['date']) ?></td>
<td class="hide-on-mobile"><?= htmlspecialchars($entry['person'] ?? '') ?></td>
<td class="hide-on-mobile"><?= htmlspecialchars($entry['category'] ?? '') ?></td>
<td><?= htmlspecialchars($entry['payment_method'] ?? '') ?></td>
<td><?= htmlspecialchars($entry['subject']) ?></td>
<td><?= htmlspecialchars($entry['amount']) ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<!-- Neu-Button -->
<a href="new_entry.php" class="btn-xr">Neu</a>
</div>
<script>
// Hamburger-Menü-Funktion
document.querySelector('.hamburger').addEventListener('click', function() {
document.querySelector('.nav-list').classList.toggle('show');
});
</script>
</body>
</html>