197 lines
7.6 KiB
PHP
197 lines
7.6 KiB
PHP
<?php
|
|
include '../includes/database.php';
|
|
require_once('../vendor/tecnickcom/tcpdf/tcpdf.php');
|
|
require_once('../vendor/autoload.php');
|
|
|
|
$articleData = [];
|
|
$error = "";
|
|
|
|
function createPdfFolder($folder)
|
|
{
|
|
if (!file_exists($folder)) {
|
|
if (!mkdir($folder, 0755, true)) {
|
|
die('Fehler beim Erstellen des Verzeichnisses für PDFs.');
|
|
}
|
|
}
|
|
}
|
|
|
|
$pdfDirectory = dirname(__DIR__) . '/pdf';
|
|
createPdfFolder($pdfDirectory);
|
|
|
|
function generateEANBarcode($eanNumber, $pdf)
|
|
{
|
|
$style = array(
|
|
'border' => 0,
|
|
'padding' => 0,
|
|
'fgcolor' => array(0, 0, 0),
|
|
'bgcolor' => false,
|
|
'module_width' => 0.5,
|
|
'module_height' => 10
|
|
);
|
|
return $pdf->write1DBarcode($eanNumber, 'EAN13', '', '', '', 20, 1, $style, 'N');
|
|
}
|
|
|
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|
$articleNumber = $_POST['article_number'];
|
|
$setName = $_POST['set_name'];
|
|
$sql = "SELECT * FROM articles WHERE article_number = ? OR set_name LIKE ?";
|
|
$stmt = $conn->prepare($sql);
|
|
$stmt->bind_param("ss", $articleNumber, $setName);
|
|
$stmt->execute();
|
|
$result = $stmt->get_result();
|
|
|
|
if ($result) {
|
|
if ($result->num_rows > 0) {
|
|
$articleData = $result->fetch_assoc();
|
|
} else {
|
|
$error = "Artikel nicht gefunden.";
|
|
}
|
|
} else {
|
|
$error = "Fehler beim Ausführen der Abfrage: " . $conn->error;
|
|
}
|
|
}
|
|
|
|
if (isset($_POST['download_pdf'])) {
|
|
if (!empty($articleData)) {
|
|
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
|
|
$pdf->SetCreator(PDF_CREATOR);
|
|
$pdf->SetAuthor('M_Viper');
|
|
$pdf->SetTitle('Article Information');
|
|
$pdf->SetSubject('Article Details');
|
|
$pdf->SetKeywords('Article, Details, PDF');
|
|
$pdf->AddPage();
|
|
$pdf->SetFont('helvetica', '', 13);
|
|
|
|
$html = '
|
|
<h3> </h3>
|
|
<table style="border-collapse: collapse; width: 100%;">
|
|
<tbody>
|
|
<tr>
|
|
|
|
<td style="width: 35%;">
|
|
<h1 style="margin-left: 40px;"><strong>Hersteller: ' . $articleData['manufacturer'] . '</strong></h1>
|
|
<p style="margin-left: 40px;"><strong>Bezeichnung: ' . $articleData['set_name'] . '</strong></p>
|
|
<p style="margin-left: 40px;"><strong>Artikelnummer: ' . $articleData['article_number'] . '</strong></p>
|
|
<p style="margin-left: 40px;"><strong>EAN: ' . $articleData['ean_barcode'] . '</strong></p>
|
|
</td>
|
|
<td style="width: 35%;">
|
|
<h1 style="margin-left: 20px;"><img style="font-size: 14px; font-weight: 400; text-align: right;" src="https://m-viper.de/Logistik/img/ofen.png" alt="" width="120" height="120" /><strong><br /></strong></h1>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
';
|
|
|
|
// Adding additional tables for parts
|
|
$parts = array(
|
|
array("Bezeichnung" => "Backofen", "Teil" => $articleData['part1'], "EAN" => $articleData['part1_ean'], "Barcode" => $articleData['ean_barcode'], "Pakete" => $articleData['quantity']),
|
|
array("Bezeichnung" => "Kochfeld", "Teil" => $articleData['part2'], "EAN" => $articleData['part2_ean'], "Barcode" => '', "Pakete" => ''),
|
|
array("Bezeichnung" => "Auszug", "Teil" => $articleData['part3'], "EAN" => $articleData['part3_ean'], "Barcode" => '', "Pakete" => ''),
|
|
array("Bezeichnung" => "Backblech", "Teil" => $articleData['part4'], "EAN" => $articleData['part4_ean'], "Barcode" => '', "Pakete" => '')
|
|
);
|
|
|
|
foreach ($parts as $key => $part) {
|
|
$barcode = ($part["Barcode"] && $key === 0) ? generateEANBarcode($part["Barcode"], $pdf) : '';
|
|
$html .= '
|
|
<table style="border-collapse: collapse; width: 100%;">
|
|
<tr>
|
|
<td style="width: 70%; padding-left: 20px; border-bottom: 1px solid #000;">
|
|
<p><strong>' . $part["Bezeichnung"] . ': ' . $part["Teil"] . '</strong></p>
|
|
<p><strong>EAN: ' . $part["EAN"] . '</strong></p>
|
|
</td>
|
|
<td style="width: 30%; text-align: center; border-bottom: 1px solid #000;"><strong>' . ($barcode ? $barcode : '') . '</strong></td>
|
|
</tr>
|
|
</table>
|
|
<h3> </h3>';
|
|
}
|
|
|
|
$html .= '
|
|
<table style="border-collapse: collapse; width: 100%;">
|
|
<tr>
|
|
<td style="width: 100%; text-align: center; border: 1px solid #000; font-size: 18px;"><strong>Pakete: ' . $articleData['quantity'] . '</strong></td>
|
|
</tr>
|
|
</table>';
|
|
|
|
$pdf->writeHTML($html);
|
|
$pdf->Output($pdfDirectory . '/article_details.pdf', 'F');
|
|
header('Content-Type: application/pdf');
|
|
header('Content-Disposition: attachment; filename="article_details.pdf"');
|
|
readfile($pdfDirectory . '/article_details.pdf');
|
|
exit;
|
|
} else {
|
|
$error = "Keine Artikelinformationen gefunden.";
|
|
}
|
|
}
|
|
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<link rel="stylesheet" href="../css/search.css">
|
|
<link rel="icon" type="image/png" href="../img/logo.png">
|
|
<title>Einbauherdset Suche</title>
|
|
</head>
|
|
<body>
|
|
<div class="title-image">
|
|
<h1>Einbauherdset Suche</h1>
|
|
<img src="../img/ofen.png" alt="Title Image">
|
|
</div>
|
|
<div class="container">
|
|
<div class="search-box">
|
|
<h2>Artikel Suche </h2>
|
|
<form method="post">
|
|
<label>Artikelnummer:</label>
|
|
<input type="text" name="article_number" >
|
|
<label>Setbezeichnung:</label>
|
|
<input type="text" name="set_name">
|
|
<input type="submit" value="Search">
|
|
</form>
|
|
</div>
|
|
<div class="result-box">
|
|
<h2>Artikel Details</h2>
|
|
<?php if (!empty($articleData)) : ?>
|
|
<div class="box">
|
|
<h3>Hersteller: <?php echo $articleData['manufacturer']; ?></h3>
|
|
</div>
|
|
<div class="box">
|
|
<p>Artikelnummer: <?php echo $articleData['article_number']; ?></p>
|
|
<p>Bezeichnung: <?php echo $articleData['set_name']; ?></p>
|
|
<p>EAN Barcode: <?php echo $articleData['ean_barcode']; ?></p>
|
|
</div>
|
|
<?php $partNames = array('Backofen', 'Kochfeld', 'Auszug', 'Backblech'); ?>
|
|
<?php for ($i = 1; $i <= 4; $i++) : ?>
|
|
<?php $partKey = "part{$i}"; ?>
|
|
<?php $eanKey = "{$partKey}_ean"; ?>
|
|
<?php if (!empty($articleData[$partKey])) : ?>
|
|
<div class="box">
|
|
<h3><?php echo $partNames[$i-1]; ?>:</h3>
|
|
<p>Bezeichnung: <?php echo $articleData[$partKey]; ?></p>
|
|
<p>EAN Barcode: <?php echo $articleData[$eanKey]; ?></p>
|
|
</div>
|
|
<?php endif; ?>
|
|
<?php endfor; ?>
|
|
<div class="box">
|
|
<h3>Pakete:</h3>
|
|
<p><?php echo $articleData['quantity']; ?></p>
|
|
</div>
|
|
<form method="post">
|
|
<input type="hidden" name="article_number" value="<?php echo $articleData['article_number']; ?>">
|
|
<input type="submit" name="download_pdf" value="Download PDF">
|
|
</form>
|
|
<?php elseif ($error) : ?>
|
|
<p><?php echo $error; ?></p>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
<div class="footer">
|
|
<a href="admin.php" class="watermark">Copyright 2024 M_Viper</a>
|
|
</div>
|
|
</body>
|
|
</html>
|