Initial import: Carteasy Shop (Dev-Stand)
This commit is contained in:
@@ -0,0 +1,252 @@
|
||||
<?php
|
||||
/**
|
||||
* ItemDatabase - Saubere DB-Abfragen für Items
|
||||
* Komplett neu geschrieben nach Auto-Refactoring-Chaos
|
||||
*/
|
||||
|
||||
class ItemDatabase {
|
||||
private $db;
|
||||
private $base_object;
|
||||
|
||||
public function __construct($base_object) {
|
||||
$this->base_object = $base_object;
|
||||
$this->db = $base_object->db;
|
||||
}
|
||||
|
||||
/**
|
||||
* Holt Basis-Item-Daten
|
||||
*/
|
||||
public function getItemData($item_id) {
|
||||
$sql = "SELECT * FROM items WHERE id = " . intval($item_id);
|
||||
$result = $this->db->query($sql);
|
||||
return $result ? $result->fetch_object() : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Holt Herstellerinformationen
|
||||
*/
|
||||
public function getManufacturerInfo($vendor_id) {
|
||||
if (!$vendor_id) return [];
|
||||
|
||||
$sql = "SELECT * FROM herstellerinformationen WHERE id = ?";
|
||||
$stmt = $this->db->prepare($sql);
|
||||
|
||||
if ($stmt) {
|
||||
$vendor_id_int = intval($vendor_id);
|
||||
$stmt->bind_param("i", $vendor_id_int);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
return $result->fetch_assoc() ?: [];
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Holt Admin User Daten
|
||||
*/
|
||||
public function getAdminUser($user_id) {
|
||||
if (!$user_id) return null;
|
||||
|
||||
$sql = "SELECT * FROM customers WHERE id = " . intval($user_id);
|
||||
$result = $this->db->query($sql);
|
||||
return $result ? $result->fetch_object() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Holt Sicherheitshinweise (REAKTIVIERT + FALLBACK)
|
||||
* Übertragen aus item.class.php Zeile 885-936
|
||||
* PRIORITÄT 1: attribute_5 (manuell)
|
||||
* PRIORITÄT 2: attribute_7 (Navision-Automatik)
|
||||
*/
|
||||
public function getSecurityWarnings($navision_id, $manual_warning_ids = null) {
|
||||
$warnings = [];
|
||||
$documents = [];
|
||||
|
||||
// PRIORITÄT 1: Manuelle Warning-IDs aus attribute_5 (für alte Artikel)
|
||||
if (!empty($manual_warning_ids) && preg_match('/^[\d,\s]+$/', $manual_warning_ids)) {
|
||||
// SPECIAL CASE: warning_id 199 = Allgemeine Sicherheitsdokumente
|
||||
if (trim($manual_warning_ids) == '199') {
|
||||
// Lade das PDF aus sicherheitshinweis.bild für warning_id 199
|
||||
$sql = "SELECT bild, name FROM sicherheitshinweis WHERE warning_id = 199";
|
||||
$result = $this->db->query($sql);
|
||||
|
||||
if ($result && $row = $result->fetch_assoc()) {
|
||||
if (!empty($row['bild'])) {
|
||||
$documents[] = [
|
||||
'file_name' => $row['bild'] . '.pdf',
|
||||
'label' => $row['name'] ?? 'Allgemeine Sicherheitshinweise'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'warnings' => [],
|
||||
'documents' => $documents,
|
||||
'source' => 'manual_attribute_5_document_199'
|
||||
];
|
||||
}
|
||||
|
||||
// Normale Warning-IDs (1-90): Nur Symbole, keine Dokumente
|
||||
$warnings = $this->loadWarnings($manual_warning_ids);
|
||||
return [
|
||||
'warnings' => $warnings,
|
||||
'documents' => [],
|
||||
'source' => 'manual_attribute_5'
|
||||
];
|
||||
}
|
||||
|
||||
// PRIORITÄT 2: Automatische Navision-Logik aus attribute_7
|
||||
if (!empty($navision_id)) {
|
||||
$sql = "SELECT * FROM sicherheitshinweis_item WHERE navision_id = ?";
|
||||
$stmt = $this->db->prepare($sql);
|
||||
|
||||
if ($stmt) {
|
||||
$stmt->bind_param("s", $navision_id);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
$warningDocsList = $result->fetch_assoc();
|
||||
|
||||
if ($warningDocsList) {
|
||||
// Sicherheitswarnungen laden
|
||||
$warningIdsList = $warningDocsList['warning_ids'] ?? null;
|
||||
$warnings = $this->loadWarnings($warningIdsList);
|
||||
|
||||
// Dokumente laden
|
||||
$documentColumns = [
|
||||
'Bedienungsanleitung' => 'Allg. Sicherheitshinweise',
|
||||
'EU_Datenblatt' => 'EU-Datenblatt',
|
||||
'Energielabel' => 'Energielabel',
|
||||
'Produktdatenblatt' => 'Produktdatenblatt',
|
||||
'Sicherheitsdatenblatt' => 'Sicherheitsdatenblatt',
|
||||
'Zertifikat' => 'Zertifikat',
|
||||
'null_feld' => 'Allg. Sicherheitshinweise'
|
||||
];
|
||||
|
||||
foreach ($documentColumns as $column => $label) {
|
||||
if (!empty($warningDocsList[$column])) {
|
||||
$pdfs = explode(',', $warningDocsList[$column]);
|
||||
$pdfs = array_map('trim', $pdfs);
|
||||
$pdfs = array_map(fn($pdf) => trim($pdf, '"'), $pdfs);
|
||||
foreach ($pdfs as $pdf) {
|
||||
if (!empty($pdf)) {
|
||||
$documents[] = [
|
||||
'file_name' => $pdf,
|
||||
'label' => $label
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'warnings' => $warnings,
|
||||
'documents' => $documents,
|
||||
'source' => !empty($navision_id) ? 'navision_attribute_7' : 'empty'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Lädt Sicherheitswarnungen basierend auf IDs
|
||||
* Übertragen aus item.class.php loadWarnings()
|
||||
*/
|
||||
private function loadWarnings($warningIdsList) {
|
||||
$articleWarnings = [];
|
||||
|
||||
if ($warningIdsList) {
|
||||
$ids = explode(',', $warningIdsList);
|
||||
$ids = array_map('trim', $ids);
|
||||
$ids = array_filter($ids, 'is_numeric');
|
||||
|
||||
if (!empty($ids)) {
|
||||
$placeholders = implode(',', array_fill(0, count($ids), '?'));
|
||||
|
||||
$sqlWarn = "
|
||||
SELECT warning_id, name, beschreibung, bild, bildnr, bilddateiname
|
||||
FROM sicherheitshinweis
|
||||
WHERE warning_id IN ($placeholders)
|
||||
ORDER BY warning_id
|
||||
";
|
||||
$stmtWarn = $this->db->prepare($sqlWarn);
|
||||
|
||||
if ($stmtWarn) {
|
||||
$types = str_repeat('i', count($ids));
|
||||
$stmtWarn->bind_param($types, ...$ids);
|
||||
$stmtWarn->execute();
|
||||
$resultWarn = $stmtWarn->get_result();
|
||||
$articleWarnings = $resultWarn->fetch_all(MYSQLI_ASSOC);
|
||||
|
||||
// Bild-Dateinamen generieren
|
||||
foreach ($articleWarnings as &$warning) {
|
||||
$warning['image_filename'] = $this->generateImageFileName($warning);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $articleWarnings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generiert Bild-Dateinamen für Sicherheitshinweise
|
||||
* Übertragen aus item.class.php generateImageFileName()
|
||||
*/
|
||||
private function generateImageFileName($warning) {
|
||||
// Verwende "bilddateiname", wenn vorhanden
|
||||
if (!empty($warning['bilddateiname'])) {
|
||||
return $warning['bilddateiname'];
|
||||
}
|
||||
|
||||
// Verwende "bildnr", wenn vorhanden
|
||||
if (!empty($warning['bildnr'])) {
|
||||
return $warning['bildnr'] . ".gif";
|
||||
}
|
||||
|
||||
// Generiere basierend auf der Bildnummer
|
||||
if (!empty($warning['bild'])) {
|
||||
$baseName = "ISO_7010_";
|
||||
$suffix = ".svg";
|
||||
|
||||
// Extrahiere die letzten 3 Ziffern der Bildnummer
|
||||
$imageFileId = substr($warning['bild'], -4);
|
||||
|
||||
return $baseName . $imageFileId . $suffix;
|
||||
}
|
||||
|
||||
// Kein Bild verfügbar
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performance-Debug - DIREKT AUF SEITE ausgeben
|
||||
*/
|
||||
public function debugItemPerformance($item_id) {
|
||||
echo "<div style='background:yellow;padding:10px;margin:10px;border:2px solid red;'>";
|
||||
echo "<h2>🔍 PERFORMANCE DEBUG für Item $item_id</h2>";
|
||||
|
||||
$this->benchmarkQuery("SELECT * FROM items WHERE id = $item_id", "1. Base Item Data");
|
||||
$this->benchmarkQuery("SELECT * FROM item_files WHERE item_id = $item_id", "2. Files");
|
||||
$this->benchmarkQuery("SELECT * FROM customers WHERE id = 1", "3. Test Admin User");
|
||||
|
||||
echo "<strong>✅ PERFORMANCE DEBUG ABGESCHLOSSEN</strong>";
|
||||
echo "</div>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Benchmark eine einzelne Abfrage - DIREKT AUF SEITE
|
||||
*/
|
||||
public function benchmarkQuery($sql, $description = '') {
|
||||
$start = microtime(true);
|
||||
$result = $this->db->query($sql);
|
||||
$end = microtime(true);
|
||||
$time = round(($end - $start) * 1000, 2);
|
||||
|
||||
echo "<p><strong>$description:</strong> {$time}ms<br>";
|
||||
echo "<code>$sql</code></p>";
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user