Feature: CSV-Export, UI-Fixes für ToDo-Liste und help.php Absturz behoben
All checks were successful
Docker Build & Push / build-and-push (push) Successful in 38s
All checks were successful
Docker Build & Push / build-and-push (push) Successful in 38s
This commit is contained in:
@@ -127,7 +127,10 @@ $conn->close();
|
||||
<div class="card">
|
||||
<div class="card-header d-flex justify-content-between align-items-center">
|
||||
<h2 class="h4 mb-0"><i class="fas fa-boxes me-2"></i>Artikel im Haushalt</h2>
|
||||
<a href="add_article.php" class="btn btn-sm btn-outline-light"><i class="fas fa-plus me-2"></i>Neuen Artikel hinzufügen</a>
|
||||
<div>
|
||||
<a href="export_articles.php" class="btn btn-sm btn-outline-success me-2"><i class="fas fa-file-export me-2"></i>Export (CSV)</a>
|
||||
<a href="add_article.php" class="btn btn-sm btn-outline-light"><i class="fas fa-plus me-2"></i>Neuen Artikel hinzufügen</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body p-0">
|
||||
<?php echo $message; ?>
|
||||
|
||||
90
src/export_articles.php
Normal file
90
src/export_articles.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
// export_articles.php
|
||||
if (session_status() == PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
}
|
||||
if (!isset($_SESSION['user_id'])) {
|
||||
header("Location: login.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
require_once 'db_connect.php';
|
||||
require_once 'household_actions.php';
|
||||
|
||||
$current_user_id = $_SESSION['user_id'];
|
||||
$household_member_ids = [$current_user_id];
|
||||
$current_user_household_id = get_user_household_id($conn, $current_user_id);
|
||||
if ($current_user_household_id) {
|
||||
$household_member_ids = get_household_members($conn, $current_user_household_id);
|
||||
}
|
||||
|
||||
$placeholders = implode(',', array_fill(0, count($household_member_ids), '?'));
|
||||
$types = str_repeat('i', count($household_member_ids));
|
||||
|
||||
$sql = "SELECT
|
||||
a.name AS 'Artikelname',
|
||||
a.product_designation AS 'Produktbezeichnung',
|
||||
c.name AS 'Kategorie',
|
||||
m.name AS 'Hersteller',
|
||||
a.weight_grams AS 'Gewicht (g)',
|
||||
a.quantity_owned AS 'Anzahl',
|
||||
IF(a.consumable = 1, 'Ja', 'Nein') AS 'Verbrauchsartikel',
|
||||
a.product_url AS 'Produkt-URL',
|
||||
l1.name AS 'Lagerort (Ebene 1)',
|
||||
l2.name AS 'Lagerort (Ebene 2)',
|
||||
u.username AS 'Ersteller'
|
||||
FROM articles a
|
||||
JOIN users u ON a.user_id = u.id
|
||||
LEFT JOIN categories c ON a.category_id = c.id
|
||||
LEFT JOIN manufacturers m ON a.manufacturer_id = m.id
|
||||
LEFT JOIN storage_locations l2 ON a.storage_location_id = l2.id
|
||||
LEFT JOIN storage_locations l1 ON l2.parent_id = l1.id
|
||||
WHERE a.user_id IN ($placeholders) OR a.household_id = ?
|
||||
ORDER BY c.name ASC, a.name ASC";
|
||||
|
||||
$stmt = $conn->prepare($sql);
|
||||
if ($stmt === false) {
|
||||
die("Datenbankfehler.");
|
||||
}
|
||||
|
||||
$all_params = array_merge($household_member_ids, [$current_user_household_id]);
|
||||
$all_types = $types . 'i';
|
||||
$stmt->bind_param($all_types, ...$all_params);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
|
||||
header('Content-Type: text/csv; charset=utf-8');
|
||||
header('Content-Disposition: attachment; filename="artikel_export_' . date('Ymd_His') . '.csv"');
|
||||
|
||||
$output = fopen('php://output', 'w');
|
||||
fprintf($output, chr(0xEF).chr(0xBB).chr(0xBF)); // BOM for Excel
|
||||
|
||||
// Output headers
|
||||
$headers = [
|
||||
'Artikelname', 'Produktbezeichnung', 'Kategorie', 'Hersteller',
|
||||
'Gewicht (g)', 'Anzahl im Besitz', 'Verbrauchsartikel', 'Produkt-URL',
|
||||
'Lagerort (Ebene 1)', 'Lagerort (Ebene 2)', 'Ersteller'
|
||||
];
|
||||
fputcsv($output, $headers, ';');
|
||||
|
||||
// Output rows
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
fputcsv($output, [
|
||||
$row['Artikelname'],
|
||||
$row['Produktbezeichnung'],
|
||||
$row['Kategorie'],
|
||||
$row['Hersteller'],
|
||||
$row['Gewicht (g)'],
|
||||
$row['Anzahl'],
|
||||
$row['Verbrauchsartikel'],
|
||||
$row['Produkt-URL'],
|
||||
$row['Lagerort (Ebene 1)'],
|
||||
$row['Lagerort (Ebene 2)'],
|
||||
$row['Ersteller']
|
||||
], ';');
|
||||
}
|
||||
|
||||
fclose($output);
|
||||
$stmt->close();
|
||||
$conn->close();
|
||||
?>
|
||||
@@ -10,6 +10,7 @@ if (!isset($_SESSION['user_id'])) {
|
||||
exit;
|
||||
}
|
||||
|
||||
require_once 'db_connect.php';
|
||||
require_once 'header.php';
|
||||
?>
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ $active_list_id = isset($_GET['list_id']) ? intval($_GET['list_id']) : (!empty($
|
||||
<h5 class="mb-3"><i class="fas fa-list me-2"></i>Meine Listen</h5>
|
||||
<div class="list-group mb-3 shadow-sm">
|
||||
<?php foreach ($todo_lists as $list): ?>
|
||||
<a href="?list_id=<?php echo $list['id']; ?>" class="list-group-item list-group-item-action d-flex justify-content-between align-items-center <?php echo $active_list_id == $list['id'] ? 'list-group-item-secondary fw-bold border-start border-4 border-dark' : ''; ?>">
|
||||
<a href="?list_id=<?php echo $list['id']; ?>" class="list-group-item list-group-item-action d-flex justify-content-between align-items-center <?php echo $active_list_id == $list['id'] ? 'bg-success text-white fw-bold' : ''; ?>">
|
||||
<?php echo htmlspecialchars($list['name']); ?>
|
||||
<form method="post" style="display:inline;" onsubmit="return confirm('Liste wirklich löschen?');">
|
||||
<input type="hidden" name="list_id" value="<?php echo $list['id']; ?>">
|
||||
|
||||
Reference in New Issue
Block a user