feat: Bestand aufteilen und Bildbibliothek in edit_article.php
All checks were successful
Docker Build & Push / build-and-push (push) Successful in 9s
All checks were successful
Docker Build & Push / build-and-push (push) Successful in 9s
This commit is contained in:
@@ -180,6 +180,13 @@ if ($can_edit) {
|
||||
$parent_articles = $stmt_parent_articles->get_result()->fetch_all(MYSQLI_ASSOC);
|
||||
$stmt_parent_articles->close();
|
||||
|
||||
// Lade ALLE Bilder (für Auswahl im Modal) - Limit auf 500
|
||||
$stmt_imgs = $conn->prepare("SELECT DISTINCT image_url FROM articles WHERE user_id IN ($placeholders) AND image_url IS NOT NULL AND image_url != '' AND image_url != '0' ORDER BY created_at DESC LIMIT 500");
|
||||
$stmt_imgs->bind_param($types, ...$household_member_ids);
|
||||
$stmt_imgs->execute();
|
||||
$all_images = $stmt_imgs->get_result()->fetch_all(MYSQLI_ASSOC);
|
||||
$stmt_imgs->close();
|
||||
|
||||
// Lade Tags für Haushalt
|
||||
$stmt_tags_load = $conn->prepare("SELECT name FROM tags WHERE household_id = ? ORDER BY name ASC");
|
||||
$stmt_tags_load->bind_param("i", $household_id_for_user);
|
||||
@@ -201,7 +208,39 @@ if ($can_edit) {
|
||||
$current_tags_value = implode(',', $current_article_tags);
|
||||
}
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST" && $can_edit) {
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['split_quantity']) && $can_edit) {
|
||||
$split_qty = intval($_POST['split_quantity']);
|
||||
$orig_qty = $article_data['quantity_owned'];
|
||||
if ($split_qty > 0 && $split_qty < $orig_qty) {
|
||||
$new_orig_qty = $orig_qty - $split_qty;
|
||||
|
||||
$stmt_upd = $conn->prepare("UPDATE articles SET quantity_owned = ? WHERE id = ?");
|
||||
$stmt_upd->bind_param("ii", $new_orig_qty, $article_id);
|
||||
$stmt_upd->execute();
|
||||
$stmt_upd->close();
|
||||
|
||||
$stmt_ins = $conn->prepare("INSERT INTO articles (name, weight_grams, category_id, image_url, user_id, household_id, consumable, quantity_owned, product_url, manufacturer_id, product_designation, storage_location_id, parent_article_id, owner_id)
|
||||
SELECT name, weight_grams, category_id, image_url, user_id, household_id, consumable, ?, product_url, manufacturer_id, product_designation, storage_location_id, parent_article_id, owner_id FROM articles WHERE id = ?");
|
||||
$stmt_ins->bind_param("ii", $split_qty, $article_id);
|
||||
$stmt_ins->execute();
|
||||
$new_article_id = $conn->insert_id;
|
||||
$stmt_ins->close();
|
||||
|
||||
$stmt_tags = $conn->prepare("INSERT INTO article_tags (article_id, tag_id) SELECT ?, tag_id FROM article_tags WHERE article_id = ?");
|
||||
$stmt_tags->bind_param("ii", $new_article_id, $article_id);
|
||||
$stmt_tags->execute();
|
||||
$stmt_tags->close();
|
||||
|
||||
if ($household_id_for_user) {
|
||||
$log_message = htmlspecialchars($_SESSION['username']) . " hat den Bestand von '" . htmlspecialchars($article_data['name']) . "' aufgeteilt.";
|
||||
log_household_action($conn, $household_id_for_user, $current_user_id, $log_message);
|
||||
}
|
||||
|
||||
header("Location: edit_article.php?id=" . $article_id . "&split_success=1");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
elseif ($_SERVER["REQUEST_METHOD"] == "POST" && $can_edit) {
|
||||
$name = trim($_POST['name']);
|
||||
$weight_grams = intval($_POST['weight_grams']);
|
||||
$consumable = isset($_POST['consumable']) ? 1 : 0;
|
||||
@@ -332,8 +371,70 @@ $conn->close();
|
||||
<link href="https://cdn.jsdelivr.net/npm/tom-select@2.2.2/dist/css/tom-select.bootstrap5.min.css" rel="stylesheet">
|
||||
<script src="https://cdn.jsdelivr.net/npm/tom-select@2.2.2/dist/js/tom-select.complete.min.js"></script>
|
||||
|
||||
<!-- Tagify CSS/JS -->
|
||||
<!-- Split Modal -->
|
||||
<div class="modal fade" id="splitArticleModal" tabindex="-1" aria-labelledby="splitArticleModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="splitArticleModalLabel">Bestand aufteilen</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Schließen"></button>
|
||||
</div>
|
||||
<form action="edit_article.php?id=<?php echo htmlspecialchars($article_id); ?>" method="post">
|
||||
<div class="modal-body">
|
||||
<p>Du hast aktuell <strong><?php echo $quantity_owned; ?></strong> Stück dieses Artikels im Bestand.</p>
|
||||
<div class="mb-3">
|
||||
<label for="split_quantity" class="form-label">Wie viel Menge möchtest du als neuen, eigenständigen Artikel abspalten?</label>
|
||||
<input type="number" class="form-control" id="split_quantity" name="split_quantity" min="1" max="<?php echo $quantity_owned - 1; ?>" value="1" required>
|
||||
</div>
|
||||
<p class="text-muted small">Es wird eine exakte Kopie des Artikels angelegt (inkl. Bild, Tags, etc.) und die eingegebene Menge dorthin übertragen.</p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Abbrechen</button>
|
||||
<button type="submit" class="btn btn-warning"><i class="fas fa-cut me-2"></i>Jetzt aufteilen</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Image Library Modal -->
|
||||
<div class="modal fade" id="imageLibraryModal" tabindex="-1" aria-labelledby="imageLibraryModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-lg modal-dialog-scrollable">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="imageLibraryModalLabel">Bildbibliothek</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Schließen"></button>
|
||||
</div>
|
||||
<div class="modal-body bg-light">
|
||||
<?php if (empty($all_images)): ?>
|
||||
<div class="alert alert-info">Es wurden noch keine Bilder hochgeladen.</div>
|
||||
<?php else: ?>
|
||||
<div class="row g-2">
|
||||
<?php foreach ($all_images as $img): ?>
|
||||
<div class="col-4 col-md-3 col-lg-2">
|
||||
<div class="card h-100 border-0 shadow-sm image-selectable" onclick="selectImage('<?php echo htmlspecialchars($img['image_url']); ?>')" style="cursor: pointer; overflow: hidden;">
|
||||
<img src="<?php echo htmlspecialchars($img['image_url']); ?>" class="card-img-top" alt="Thumbnail" style="height: 100px; object-fit: cover;">
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<p class="text-muted small text-center mt-3">Es werden maximal die 500 neuesten Bilder angezeigt.</p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/@yaireo/tagify"></script>
|
||||
<script>
|
||||
function selectImage(url) {
|
||||
document.getElementById('image_url').value = url;
|
||||
document.getElementById('imagePreview').src = url;
|
||||
const modalEl = document.getElementById('imageLibraryModal');
|
||||
const modal = bootstrap.Modal.getInstance(modalEl);
|
||||
modal.hide();
|
||||
}
|
||||
</script>
|
||||
<link href="https://cdn.jsdelivr.net/npm/@yaireo/tagify/dist/tagify.css" rel="stylesheet" type="text/css" />
|
||||
<style>
|
||||
.tagify {
|
||||
@@ -358,10 +459,18 @@ $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-edit me-2"></i>Artikel bearbeiten</h2>
|
||||
<a href="articles.php" class="btn btn-sm btn-outline-light"><i class="fas fa-arrow-left me-2"></i>Zur Übersicht</a>
|
||||
<div>
|
||||
<?php if ($quantity_owned > 1): ?>
|
||||
<button type="button" class="btn btn-sm btn-outline-warning me-2" data-bs-toggle="modal" data-bs-target="#splitArticleModal"><i class="fas fa-cut me-1"></i>Bestand aufteilen</button>
|
||||
<?php endif; ?>
|
||||
<a href="articles.php" class="btn btn-sm btn-outline-light"><i class="fas fa-arrow-left me-2"></i>Zur Übersicht</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body p-4">
|
||||
<?php if(!empty($message)) echo $message; ?>
|
||||
<?php
|
||||
if(isset($_GET['split_success']) && $_GET['split_success'] == 1) echo '<div class="alert alert-success">Bestand erfolgreich aufgeteilt. Ein neuer Artikel wurde angelegt.</div>';
|
||||
if(!empty($message)) echo $message;
|
||||
?>
|
||||
<?php if ($article_data): ?>
|
||||
<form action="edit_article.php?id=<?php echo htmlspecialchars($article_id); ?>" method="post" enctype="multipart/form-data">
|
||||
<input type="hidden" name="pasted_image_data" id="pasted_image_data">
|
||||
@@ -427,6 +536,12 @@ $conn->close();
|
||||
<div class="mb-3"><label for="image_file" class="form-label">1. Neues Bild hochladen</label><input class="form-control" type="file" id="image_file" name="image_file" accept="image/*"></div>
|
||||
<div class="mb-3"><label for="image_url" class="form-label">2. ODER neue Bild-URL</label><input type="url" class="form-control" id="image_url" name="image_url" value="<?php echo $display_image_url_in_input; ?>" placeholder="https://..."></div>
|
||||
<div class="mb-3"><label class="form-label">3. ODER Bild einfügen (Strg+V)</label><div id="pasteArea" class="paste-area"><i class="fas fa-paste"></i> Hier klicken & einfügen</div></div>
|
||||
<div class="mb-3 text-center border-bottom pb-3">
|
||||
<label class="form-label d-block text-start">4. ODER vorhandenes Bild wählen</label>
|
||||
<button type="button" class="btn btn-outline-secondary w-100" data-bs-toggle="modal" data-bs-target="#imageLibraryModal">
|
||||
<i class="fas fa-images me-2"></i>Bild aus Bibliothek auswählen
|
||||
</button>
|
||||
</div>
|
||||
<div class="text-center mt-auto">
|
||||
<label class="form-label d-block">Vorschau</label>
|
||||
<img id="imagePreview" src="<?php echo $display_current_image_path; ?>" alt="Vorschau" class="mb-2">
|
||||
|
||||
Reference in New Issue
Block a user