124 lines
3.4 KiB
PHP
124 lines
3.4 KiB
PHP
<?php
|
|
require 'config.php';
|
|
error_log('Session user_id: ' . (isset($_SESSION['user_id']) ? $_SESSION['user_id'] : 'nicht gesetzt'));
|
|
// 1. Session-Prüfung (nur für geschützte Seiten)
|
|
if (!isset($_SESSION['user_id'])) {
|
|
header('Location: index.php');
|
|
exit;
|
|
}
|
|
|
|
// Ab hier: Nur für angemeldete Benutzer
|
|
error_log($_SESSION['user_id']);
|
|
|
|
// Prüfen, ob die user_id im Admin-Array ist
|
|
if (in_array($_SESSION['user_id'], $admin_ids, true)) {
|
|
$is_admin = "true";
|
|
}
|
|
|
|
// 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,
|
|
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
|
|
WHERE
|
|
EXTRACT(YEAR FROM e.date) = EXTRACT(YEAR FROM CURRENT_DATE())
|
|
AND EXTRACT(MONTH FROM e.date) = EXTRACT(MONTH FROM CURRENT_DATE())
|
|
ORDER BY
|
|
e.date DESC, id desc;
|
|
";
|
|
|
|
$stmt = $pdo->prepare($sql);
|
|
$stmt->execute();
|
|
$entries = $stmt->fetchAll();
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="de">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=0.8">
|
|
<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>
|
|
<?php if ($is_admin === "true") echo '<li><a href="register.php">Neue User</a></li>'; ?>
|
|
<li><a href="rep-month.php">Report Monat</a></li>
|
|
<li><a href="rep-person.php">Report Personen</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">Zahler</th>
|
|
<th class="hide-on-mobile">Person</th>
|
|
<th class="hide-on-mobile">Kategorie</th>
|
|
<th>Zahlweise</th>
|
|
<th>Betreff</th>
|
|
<th>Betrag</th>
|
|
<th class="hide-on-mobile">Hinweis</th>
|
|
<th> </th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($entries as $entry): ?>
|
|
<tr>
|
|
<td><?= htmlspecialchars($entry['date']) ?></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['kategorie'] ?? '') ?></td>
|
|
<td><?= htmlspecialchars($entry['zahlweise'] ?? '') ?></td>
|
|
<td><?= htmlspecialchars($entry['subject']) ?></td>
|
|
<td class="align-right"><?= htmlspecialchars( number_format($entry['amount'], 2, ',', '.')) ?></td>
|
|
<td class="hide-on-mobile"><?= htmlspecialchars($entry['note']) ?></td>
|
|
<td class="hide-on-mobile">
|
|
<a href="edit_entry.php?id=<?= $entry['id'] ?>">
|
|
<img class="pencil" src="/assets/img/pencil.png" width="20px" />
|
|
</a>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
|
|
<!-- Neu-Button -->
|
|
<a href="new_entry.php" class="btn-xr">+</a>
|
|
</div>
|
|
|
|
<script>
|
|
// Hamburger-Menü-Funktion
|
|
document.querySelector('.hamburger').addEventListener('click', function() {
|
|
document.querySelector('.nav-list').classList.toggle('show');
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|