diff --git a/src/add_article.php b/add_article.php
similarity index 100%
rename from src/add_article.php
rename to add_article.php
diff --git a/src/add_packing_list.php b/add_packing_list.php
similarity index 100%
rename from src/add_packing_list.php
rename to add_packing_list.php
diff --git a/src/api_packing_list_handler.php b/api_packing_list_handler.php
similarity index 100%
rename from src/api_packing_list_handler.php
rename to api_packing_list_handler.php
diff --git a/src/articles.php b/articles.php
similarity index 100%
rename from src/articles.php
rename to articles.php
diff --git a/src/assets/css/style.css b/assets/css/style.css
similarity index 100%
rename from src/assets/css/style.css
rename to assets/css/style.css
diff --git a/src/backpack_utils.php b/backpack_utils.php
similarity index 97%
rename from src/backpack_utils.php
rename to backpack_utils.php
index 9000edf..90aa3fc 100644
--- a/src/backpack_utils.php
+++ b/backpack_utils.php
@@ -54,7 +54,7 @@ function get_available_backpacks_for_user($conn, $target_user_id, $household_id)
}
$bps = [];
- $sql_bp = "SELECT id, name, user_id FROM backpacks WHERE user_id = ?";
+ $sql_bp = "SELECT id, name, user_id, image_url FROM backpacks WHERE user_id = ?";
if ($household_id) {
$sql_bp .= " OR household_id = ?";
$stmt_bp = $conn->prepare($sql_bp);
diff --git a/src/backpacks.php b/backpacks.php
similarity index 91%
rename from src/backpacks.php
rename to backpacks.php
index 105352c..75cbbe4 100755
--- a/src/backpacks.php
+++ b/backpacks.php
@@ -95,6 +95,12 @@ while ($row = $result->fetch_assoc()) {
+
+
+
+
+
+
diff --git a/src/categories.php b/categories.php
similarity index 100%
rename from src/categories.php
rename to categories.php
diff --git a/src/db_connect.php b/db_connect.php
similarity index 93%
rename from src/db_connect.php
rename to db_connect.php
index 97e8292..536ff00 100755
--- a/src/db_connect.php
+++ b/db_connect.php
@@ -4,7 +4,7 @@
// NEU: Lade Zugangsdaten aus einer sicheren Konfigurationsdatei.
// Diese Datei sollte außerhalb deines öffentlichen Web-Verzeichnisses liegen!
// z.B. in /var/www/config/packliste.ini
-$config_path = __DIR__ . '/../config.ini'; // Annahme: die Datei liegt ein Verzeichnis höher
+$config_path = __DIR__ . '/config.ini'; // Pfad für flache Struktur angepasst
if (!file_exists($config_path)) {
die("Kritischer Fehler: Die Konfigurationsdatei wurde nicht gefunden. Bitte erstellen Sie die 'config.ini'.");
diff --git a/src/delete_article.php b/delete_article.php
similarity index 100%
rename from src/delete_article.php
rename to delete_article.php
diff --git a/src/delete_packing_list.php b/delete_packing_list.php
similarity index 100%
rename from src/delete_packing_list.php
rename to delete_packing_list.php
diff --git a/src/duplicate_packing_list.php b/duplicate_packing_list.php
similarity index 100%
rename from src/duplicate_packing_list.php
rename to duplicate_packing_list.php
diff --git a/src/edit_article.php b/edit_article.php
similarity index 100%
rename from src/edit_article.php
rename to edit_article.php
diff --git a/edit_backpack.php b/edit_backpack.php
new file mode 100755
index 0000000..ea8d8c6
--- /dev/null
+++ b/edit_backpack.php
@@ -0,0 +1,394 @@
+ 0) {
+ $max_size = ini_get('post_max_size');
+ die("Fehler: Die hochgeladene Datei überschreitet das Server-Limit von $max_size. Bitte wählen Sie ein kleineres Bild.");
+}
+
+// edit_backpack.php - Erstellen und Bearbeiten von Rucksäcken und Fächern
+$page_title = "Rucksack bearbeiten";
+require_once 'db_connect.php';
+
+if (session_status() == PHP_SESSION_NONE) {
+ session_start();
+}
+if (!isset($_SESSION['user_id'])) {
+ header("Location: login.php");
+ exit;
+}
+
+$user_id = $_SESSION['user_id'];
+$backpack_id = isset($_GET['id']) ? intval($_GET['id']) : 0;
+$backpack = null;
+$compartments = [];
+$message = '';
+$image_url = '';
+
+// Check Household
+$household_id = null;
+$stmt_hh = $conn->prepare("SELECT household_id FROM users WHERE id = ?");
+$stmt_hh->bind_param("i", $user_id);
+$stmt_hh->execute();
+$res_hh = $stmt_hh->get_result();
+if ($row = $res_hh->fetch_assoc()) {
+ $household_id = $row['household_id'];
+}
+
+// Image Upload Config
+$upload_dir = 'uploads/images/';
+if (!is_dir($upload_dir)) { @mkdir($upload_dir, 0777, true); }
+
+function save_image_from_url($url, $upload_dir) {
+ $context_options = ["http" => ["header" => "User-Agent: Mozilla/5.0\r\n", "timeout" => 10]];
+ $context = stream_context_create($context_options);
+ $image_data = @file_get_contents($url, false, $context);
+ if ($image_data === false) return [false, "Bild-Download fehlgeschlagen."];
+ $image_info = @getimagesizefromstring($image_data);
+ if ($image_info === false) return [false, "Ungültiges Bild."];
+ $allowed = ['image/jpeg', 'image/png', 'image/gif', 'image/webp'];
+ if (!in_array($image_info['mime'], $allowed)) return [false, "Format nicht unterstützt."];
+ $ext = image_type_to_extension($image_info[2], false);
+ $name = uniqid('bp_url_', true) . '.' . $ext;
+ if (file_put_contents($upload_dir . $name, $image_data)) return [true, $upload_dir . $name];
+ return [false, "Speicherfehler."];
+}
+
+function save_image_from_base64($base64_string, $upload_dir) {
+ if (preg_match('/^data:image\/(\w+);base64,/', $base64_string, $type)) {
+ $data = substr($base64_string, strpos($base64_string, ',') + 1);
+ $type = strtolower($type[1]);
+ if (!in_array($type, ['jpg', 'jpeg', 'png', 'gif'])) return [false, "Format nicht unterstützt."];
+ $data = base64_decode($data);
+ if ($data === false) return [false, "Dekodierfehler."];
+ $name = uniqid('bp_paste_', true) . '.' . $type;
+ if (file_put_contents($upload_dir . $name, $data)) return [true, $upload_dir . $name];
+ }
+ return [false, "Ungültiges Base64."];
+}
+
+// Load existing data
+if ($backpack_id > 0) {
+ $stmt = $conn->prepare("SELECT * FROM backpacks WHERE id = ? AND user_id = ?");
+ $stmt->bind_param("ii", $backpack_id, $user_id);
+ $stmt->execute();
+ $result = $stmt->get_result();
+ if ($result->num_rows > 0) {
+ $backpack = $result->fetch_assoc();
+ $image_url = $backpack['image_url'];
+
+ // Load Compartments
+ $stmt_c = $conn->prepare("SELECT * FROM backpack_compartments WHERE backpack_id = ? ORDER BY sort_order ASC");
+ $stmt_c->bind_param("i", $backpack_id);
+ $stmt_c->execute();
+ $res_c = $stmt_c->get_result();
+ while ($row = $res_c->fetch_assoc()) {
+ $compartments[] = $row;
+ }
+ } else {
+ $message = 'Rucksack nicht gefunden oder keine Berechtigung.
';
+ $backpack_id = 0; // Reset to create mode
+ }
+}
+
+// Handle Form Submission BEFORE loading header
+if ($_SERVER['REQUEST_METHOD'] == 'POST') {
+ $name = trim($_POST['name']);
+ $manufacturer = trim($_POST['manufacturer']);
+ $model = trim($_POST['model']);
+ $weight = intval($_POST['weight_grams']);
+ $volume = intval($_POST['volume_liters']);
+ $share_household = isset($_POST['share_household']) ? 1 : 0;
+
+ // Image Handling
+ $image_url_for_db = $image_url; // Keep existing by default
+ $pasted_image = $_POST['pasted_image_data'] ?? '';
+ $url_image = trim($_POST['image_url_input'] ?? '');
+
+ if (!empty($pasted_image)) {
+ list($ok, $res) = save_image_from_base64($pasted_image, $upload_dir);
+ if ($ok) {
+ $image_url_for_db = $res;
+ } else {
+ $message .= 'Fehler beim Speichern des eingefügten Bildes: ' . htmlspecialchars($res) . '
';
+ }
+ } elseif (isset($_FILES['image_file']) && $_FILES['image_file']['error'] != UPLOAD_ERR_NO_FILE) {
+ // User attempted to upload a file
+ if ($_FILES['image_file']['error'] == UPLOAD_ERR_OK) {
+ $ext = strtolower(pathinfo($_FILES['image_file']['name'], PATHINFO_EXTENSION));
+ $allowed_exts = ['jpg', 'jpeg', 'png', 'gif', 'webp'];
+ if (in_array($ext, $allowed_exts)) {
+ $name_file = uniqid('bp_img_', true) . '.' . $ext;
+ if (move_uploaded_file($_FILES['image_file']['tmp_name'], $upload_dir . $name_file)) {
+ $image_url_for_db = $upload_dir . $name_file;
+ } else {
+ $message .= 'Fehler beim Verschieben der Datei. Schreibrechte prüfen.
';
+ }
+ } else {
+ $message .= 'Ungültiges Dateiformat. Erlaubt: JPG, PNG, GIF, WEBP.
';
+ }
+ } else {
+ // Handle upload errors
+ $err_code = $_FILES['image_file']['error'];
+ $err_msg = 'Unbekannter Fehler';
+ switch ($err_code) {
+ case UPLOAD_ERR_INI_SIZE: $err_msg = 'Datei ist zu groß (php.ini limit).'; break;
+ case UPLOAD_ERR_FORM_SIZE: $err_msg = 'Datei ist zu groß (HTML form limit).'; break;
+ case UPLOAD_ERR_PARTIAL: $err_msg = 'Datei wurde nur teilweise hochgeladen.'; break;
+ case UPLOAD_ERR_NO_TMP_DIR: $err_msg = 'Kein temporärer Ordner gefunden.'; break;
+ case UPLOAD_ERR_CANT_WRITE: $err_msg = 'Fehler beim Schreiben auf die Festplatte.'; break;
+ }
+ $message .= 'Upload-Fehler: ' . $err_msg . '
';
+ }
+ } elseif (!empty($url_image)) {
+ list($ok, $res) = save_image_from_url($url_image, $upload_dir);
+ if ($ok) {
+ $image_url_for_db = $res;
+ } else {
+ $message .= 'Fehler beim Laden von URL: ' . htmlspecialchars($res) . '
';
+ }
+ }
+
+ $final_household_id = ($share_household && $household_id) ? $household_id : NULL;
+
+ if ($backpack_id > 0) {
+ // Update
+ $stmt = $conn->prepare("UPDATE backpacks SET name=?, manufacturer=?, model=?, weight_grams=?, volume_liters=?, household_id=?, image_url=? WHERE id=? AND user_id=?");
+ $stmt->bind_param("sssiissii", $name, $manufacturer, $model, $weight, $volume, $final_household_id, $image_url_for_db, $backpack_id, $user_id);
+ $stmt->execute();
+ } else {
+ // Insert
+ $stmt = $conn->prepare("INSERT INTO backpacks (user_id, household_id, name, manufacturer, model, weight_grams, volume_liters, image_url) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
+ $stmt->bind_param("iisssiis", $user_id, $final_household_id, $name, $manufacturer, $model, $weight, $volume, $image_url_for_db);
+ $stmt->execute();
+ $backpack_id = $stmt->insert_id;
+ }
+
+ // Handle Compartments
+ if (isset($_POST['compartment_names'])) {
+ $comp_names = $_POST['compartment_names'];
+ $comp_ids = $_POST['compartment_ids'] ?? [];
+
+ // Get existing IDs to know what to delete
+ $existing_ids = [];
+ if($backpack_id > 0){
+ $stmt_check = $conn->prepare("SELECT id FROM backpack_compartments WHERE backpack_id = ?");
+ $stmt_check->bind_param("i", $backpack_id);
+ $stmt_check->execute();
+ $res_check = $stmt_check->get_result();
+ while($row = $res_check->fetch_assoc()) $existing_ids[] = $row['id'];
+ }
+
+ $kept_ids = [];
+
+ for ($i = 0; $i < count($comp_names); $i++) {
+ $c_name = trim($comp_names[$i]);
+ $c_id = intval($comp_ids[$i] ?? 0);
+
+ if (empty($c_name)) continue;
+
+ if ($c_id > 0 && in_array($c_id, $existing_ids)) {
+ // Update
+ $stmt_up = $conn->prepare("UPDATE backpack_compartments SET name = ?, sort_order = ? WHERE id = ?");
+ $stmt_up->bind_param("sii", $c_name, $i, $c_id);
+ $stmt_up->execute();
+ $kept_ids[] = $c_id;
+ } else {
+ // Insert
+ $stmt_in = $conn->prepare("INSERT INTO backpack_compartments (backpack_id, name, sort_order) VALUES (?, ?, ?)");
+ $stmt_in->bind_param("isi", $backpack_id, $c_name, $i);
+ $stmt_in->execute();
+ }
+ }
+
+ // Delete removed
+ foreach ($existing_ids as $ex_id) {
+ if (!in_array($ex_id, $kept_ids)) {
+ $conn->query("DELETE FROM backpack_compartments WHERE id = $ex_id");
+ }
+ }
+ }
+
+ header("Location: backpacks.php");
+ exit;
+}
+
+require_once 'header.php';
+?>
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/edit_packing_list_details.php b/edit_packing_list_details.php
similarity index 55%
rename from src/edit_packing_list_details.php
rename to edit_packing_list_details.php
index 70b3fd1..5a8b33b 100755
--- a/src/edit_packing_list_details.php
+++ b/edit_packing_list_details.php
@@ -186,31 +186,56 @@ if ($_SERVER["REQUEST_METHOD"] == "POST" && $can_edit) {
Wähle hier, wer welchen Rucksack trägt. Bereits vergebene Rucksäcke werden ausgeblendet.
$my_current_bp_id,
+ 'backpacks' => $user_backpacks
+ ];
+
+ // Find current backpack details for display
+ $current_bp_details = null;
+ foreach ($user_backpacks as $bp) {
+ if ($bp['id'] == $my_current_bp_id) {
+ $current_bp_details = $bp;
+ break;
+ }
+ }
?>
-
-
-
- -- Kein Rucksack --
-
- >
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Kein Rucksack zugewiesen
+
+
+
+
+
+
@@ -229,4 +254,116 @@ if ($_SERVER["REQUEST_METHOD"] == "POST" && $can_edit) {
-
\ No newline at end of file
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/footer.php b/footer.php
similarity index 100%
rename from src/footer.php
rename to footer.php
diff --git a/src/header.php b/header.php
similarity index 100%
rename from src/header.php
rename to header.php
diff --git a/src/help.php b/help.php
similarity index 100%
rename from src/help.php
rename to help.php
diff --git a/src/household.php b/household.php
similarity index 100%
rename from src/household.php
rename to household.php
diff --git a/src/household_actions.php b/household_actions.php
similarity index 100%
rename from src/household_actions.php
rename to household_actions.php
diff --git a/src/index.php b/index.php
similarity index 100%
rename from src/index.php
rename to index.php
diff --git a/src/keinbild.png b/keinbild.png
similarity index 100%
rename from src/keinbild.png
rename to keinbild.png
diff --git a/src/login.php b/login.php
similarity index 100%
rename from src/login.php
rename to login.php
diff --git a/src/logo.png b/logo.png
similarity index 100%
rename from src/logo.png
rename to logo.png
diff --git a/src/logout.php b/logout.php
similarity index 100%
rename from src/logout.php
rename to logout.php
diff --git a/src/manage_packing_list_items.php b/manage_packing_list_items.php
similarity index 100%
rename from src/manage_packing_list_items.php
rename to manage_packing_list_items.php
diff --git a/src/manufacturers.php b/manufacturers.php
similarity index 100%
rename from src/manufacturers.php
rename to manufacturers.php
diff --git a/src/packing_list_detail.php b/packing_list_detail.php
similarity index 94%
rename from src/packing_list_detail.php
rename to packing_list_detail.php
index e94777c..d9f104e 100755
--- a/src/packing_list_detail.php
+++ b/packing_list_detail.php
@@ -236,7 +236,7 @@ function render_print_table_rows($items, $level = 0) {
Bearbeiten
Zur Übersicht
- Drucken
+ Drucken
@@ -336,26 +336,6 @@ function render_print_table_rows($items, $level = 0) {
-
-
-
-
- Artikel Anzahl Gewicht
-
- ' . htmlspecialchars($root['article_name']) . ' ' . $root['quantity'] . ' ' . $root['weight_grams'] . ' ';
- }
- }
- ?>
-
-
-
-
+
+
+
+