diff --git a/src/articles.php b/src/articles.php index 417d7a4..6e75849 100644 --- a/src/articles.php +++ b/src/articles.php @@ -634,36 +634,52 @@ document.addEventListener('DOMContentLoaded', function () { updateBulkUI(); }); }); - - const selectAllCb = document.getElementById('bulk-select-all'); - if (selectAllCb) { - // Remove old listeners if any by cloning - const newSelectAll = selectAllCb.cloneNode(true); - selectAllCb.parentNode.replaceChild(newSelectAll, selectAllCb); - newSelectAll.checked = false; - newSelectAll.addEventListener('change', function() { - const isChecked = this.checked; - document.querySelectorAll('.bulk-select-checkbox').forEach(cb => { - cb.checked = isChecked; - if (isChecked) bulkSelectedArticles.add(cb.value); - else bulkSelectedArticles.delete(cb.value); - }); - updateBulkUI(); - }); - } updateBulkUI(); } + const selectAllCb = document.getElementById('bulk-select-all'); + if (selectAllCb) { + selectAllCb.addEventListener('change', function() { + const isChecked = this.checked; + document.querySelectorAll('.bulk-select-checkbox').forEach(cb => { + cb.checked = isChecked; + if (isChecked) { + bulkSelectedArticles.add(cb.value); + } else { + bulkSelectedArticles.delete(cb.value); + } + }); + updateBulkUI(); + }); + } + function updateBulkUI() { const count = bulkSelectedArticles.size; - document.getElementById('bulk-selected-count').textContent = count; + const countEl = document.getElementById('bulk-selected-count'); + if (countEl) countEl.textContent = count; + const container = document.getElementById('bulk-action-container'); - if (count > 0 && currentView === 'list') { - container.style.display = ''; - const idsInput = document.getElementById('bulk_article_ids_input'); - if(idsInput) idsInput.value = Array.from(bulkSelectedArticles).join(','); - } else { - container.style.display = 'none'; + if (container) { + if (count > 0 && currentView === 'list') { + container.style.display = 'flex'; + const idsInput = document.getElementById('bulk_article_ids_input'); + if(idsInput) idsInput.value = Array.from(bulkSelectedArticles).join(','); + } else { + container.style.display = 'none'; + } + } + + if (selectAllCb) { + const allCheckboxes = document.querySelectorAll('.bulk-select-checkbox'); + if (allCheckboxes.length > 0) { + const allChecked = Array.from(allCheckboxes).every(cb => cb.checked); + const someChecked = Array.from(allCheckboxes).some(cb => cb.checked); + selectAllCb.checked = allChecked; + selectAllCb.indeterminate = someChecked && !allChecked; + } else { + selectAllCb.checked = false; + selectAllCb.indeterminate = false; + } } } diff --git a/src/storage_locations.php b/src/storage_locations.php index e3ea380..76b0e3e 100644 --- a/src/storage_locations.php +++ b/src/storage_locations.php @@ -13,22 +13,6 @@ if (!isset($_SESSION['user_id'])) { } require_once 'db_connect.php'; -// AKTION: BARCODE GENERIEREN -if (isset($_GET['action']) && $_GET['action'] == 'generate_barcode' && isset($_GET['id'])) { - $location_id = intval($_GET['id']); - $token = bin2hex(random_bytes(16)); - $stmt_token = $conn->prepare("UPDATE storage_locations SET public_token = ? WHERE id = ? AND user_id IN ($placeholders)"); - $all_params = array_merge([$token, $location_id], $household_member_ids); - $all_types = 'si' . $types; - $stmt_token->bind_param($all_types, ...$all_params); - $stmt_token->execute(); - $stmt_token->close(); - header("Location: storage_locations.php"); - exit; -} - -require_once 'header.php'; - $current_user_id = $_SESSION['user_id']; $message = ''; @@ -55,6 +39,44 @@ if ($household_id) { $placeholders = implode(',', array_fill(0, count($household_member_ids), '?')); $types = str_repeat('i', count($household_member_ids)); +// AKTION: BARCODE GENERIEREN +if (isset($_GET['action']) && $_GET['action'] == 'generate_barcode' && isset($_GET['id'])) { + $location_id = intval($_GET['id']); + $token = bin2hex(random_bytes(16)); + $stmt_token = $conn->prepare("UPDATE storage_locations SET public_token = ? WHERE id = ? AND user_id IN ($placeholders)"); + $all_params = array_merge([$token, $location_id], $household_member_ids); + $all_types = 'si' . $types; + $stmt_token->bind_param($all_types, ...$all_params); + $stmt_token->execute(); + $stmt_token->close(); + header("Location: storage_locations.php"); + exit; +} + +// AKTION: ALLE BARCODES FÜR EBENE 2 GENERIEREN +if (isset($_GET['action']) && $_GET['action'] == 'generate_all_barcodes' && isset($_GET['parent_id'])) { + $parent_id = intval($_GET['parent_id']); + $stmt_children = $conn->prepare("SELECT id FROM storage_locations WHERE parent_id = ? AND user_id IN ($placeholders) AND public_token IS NULL"); + $all_params_sel = array_merge([$parent_id], $household_member_ids); + $all_types_sel = 'i' . $types; + $stmt_children->bind_param($all_types_sel, ...$all_params_sel); + $stmt_children->execute(); + $res = $stmt_children->get_result(); + + while ($row = $res->fetch_assoc()) { + $token = bin2hex(random_bytes(16)); + $stmt_token = $conn->prepare("UPDATE storage_locations SET public_token = ? WHERE id = ?"); + $stmt_token->bind_param("si", $token, $row['id']); + $stmt_token->execute(); + $stmt_token->close(); + } + $stmt_children->close(); + header("Location: storage_locations.php"); + exit; +} + +require_once 'header.php'; + // Formularverarbeitung if ($_SERVER["REQUEST_METHOD"] == "POST") { // AKTION: ORT HINZUFÜGEN @@ -210,18 +232,24 @@ foreach ($all_locations as $location) {