Semi-stable version with old variable names
This commit is contained in:
@@ -0,0 +1,366 @@
|
||||
<?php
|
||||
|
||||
use TCPDF;
|
||||
|
||||
if (!isset($baseDir)) {
|
||||
$baseDir = $_SERVER['DOCUMENT_ROOT'];
|
||||
}
|
||||
|
||||
require_once $baseDir . '/../scripts/session_functions.php';
|
||||
|
||||
ini_wkvs_session();
|
||||
|
||||
check_user_permission('wk_leitung');
|
||||
|
||||
verify_csrf();
|
||||
|
||||
if (!isset($baseDir)) {
|
||||
$baseDir = $_SERVER['DOCUMENT_ROOT'];
|
||||
}
|
||||
|
||||
$type = 'kr';
|
||||
$data = require $baseDir . '/../scripts/db/db-verbindung-script.php';
|
||||
|
||||
if ($data['success'] === false) {
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(['success' => false, 'message' => $data['message']]);
|
||||
exit;
|
||||
}
|
||||
|
||||
require $baseDir . '/../scripts/db/db-tables.php';
|
||||
require $baseDir . '/../scripts/db/db-functions.php';
|
||||
|
||||
$wkName = db_get_var($mysqli, "SELECT `value` FROM $tableVar WHERE `name` = ?", ['wkName']);
|
||||
|
||||
$wkName = ($wkName === null) ? 'Keinen Wettkampfname angegeben. Setzen unter: /intern/wk-leitung/einstellungen' : $wkName;
|
||||
|
||||
$normalFontSize = 11;
|
||||
$marginSide = 10;
|
||||
$marginTop = 10;
|
||||
$minMarginBottomTable = 20;
|
||||
$format = 'A4';
|
||||
$orientation = 'L';
|
||||
|
||||
$svgs = [
|
||||
'1' => '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M6 2h12v2a6 6 0 0 1-6 6 6 6 0 0 1-6-6V2zm0 20h12v-2a6 6 0 0 0-6-6 6 6 0 0 0-6 6v2zm6-10c1.657 0 3-1.343 3-3H9c0 1.657 1.343 3 3 3z" fill="#0073aa"/></svg>',
|
||||
'2' => '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><circle cx="12" cy="12" r="10" fill="#28a745"/><path d="M7 12l3 3 7-7" stroke="white" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"/></svg>',
|
||||
'3' => '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><circle cx="12" cy="12" r="10" fill="#dc3545"/><path d="M8 8l8 8M16 8l-8 8" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>'
|
||||
];
|
||||
|
||||
$now = trim($_POST['date'] ?? date('Y-m-d H:i:s'));
|
||||
|
||||
$logEntries = db_select($mysqli, $tableOrdersLog, "*");
|
||||
|
||||
$personen = db_select($mysqli, $tableInternUsers, "`id`, `name_person`, `username`");
|
||||
|
||||
$indexedPersonen = array_column($personen, null, 'id');
|
||||
|
||||
$entriesArray = [];
|
||||
|
||||
foreach ($logEntries as $slE) {
|
||||
|
||||
// $value = ($slE['old_order_status'] !== null) ? ($svgs[$slE['old_order_status']] ?? $slE['old_order_status']) . ' ' . json_decode('"\u2192"') . ' ' . ($svgs[$slE['new_order_status'] ?? ''] ?? $slE['new_order_status'] ?? '') : ($svgs[$slE['new_order_status'] ?? ''] ?? $slE['new_order_status'] ?? '');
|
||||
|
||||
$valueArray = [
|
||||
1 => $svgs[$slE['old_order_status'] ?? ''] ?? '',
|
||||
2 => isset($svgs[$slE['old_order_status']]),
|
||||
3 => $svgs[$slE['new_order_status'] ?? ''] ?? '',
|
||||
4 => isset($svgs[$slE['new_order_status']])
|
||||
];
|
||||
|
||||
$entriesArray[] = [
|
||||
'order_id' => $slE['order_id'] ?? '',
|
||||
'value' => $valueArray,
|
||||
'edited_by' => $indexedPersonen[$slE['edited_by']]['name_person'] ?? 'Unbekannter User',
|
||||
'timestamp' => new DateTime($slE['edited_at'])->format('d.m.Y H:i:s') ?? '---'
|
||||
];
|
||||
}
|
||||
|
||||
// Load TCPDF
|
||||
require $baseDir . '/../composer/vendor/autoload.php';
|
||||
|
||||
class ProtokollPDF extends TCPDF
|
||||
{
|
||||
public $columns;
|
||||
public $wkName;
|
||||
public $marginSide;
|
||||
public $marginTop;
|
||||
public $pdfHeight;
|
||||
public $pdfWidth;
|
||||
public $headerType;
|
||||
public $now;
|
||||
// Page header
|
||||
|
||||
public $headerBottomY = 0;
|
||||
|
||||
|
||||
public function Header()
|
||||
{
|
||||
$this->SetFillColor(255, 255, 255);
|
||||
|
||||
$this->Rect(0, 0, $this->pdfWidth, $this->pdfHeight, 'F');
|
||||
|
||||
$arrayTitles = [];
|
||||
$image_file = $_SERVER['DOCUMENT_ROOT'] . '/intern/img/logo-normal.png';
|
||||
$this->SetY($this->marginTop);
|
||||
$this->SetX(($this->marginSide ?? 10));
|
||||
$this->SetFont('freesans', '', 20);
|
||||
|
||||
$this->Cell(0, 0, 'Protokoll Rechnungen ' . $this->wkName, 0, 1, 'L', 0, '', 0, false, 'T', 'M');
|
||||
$preimageX = $this->GetX();
|
||||
$preimageY = $this->GetY();
|
||||
$this->Image($image_file, $this->pdfWidth - 10 - $this->marginSide, $this->marginTop, '', 10, 'png', '', 'T');
|
||||
|
||||
$this->SetY($preimageY + 5);
|
||||
$this->SetX($this->marginSide ?? 10); // Force back to left margin
|
||||
$this->SetFont('freesans', '', 11);
|
||||
|
||||
$this->Ln(5);
|
||||
|
||||
$columns = $this->columns;
|
||||
$startY = $this->GetY();
|
||||
$this->SetFont('', 'B');
|
||||
|
||||
$this->SetX($this->marginSide ?? 10);
|
||||
|
||||
foreach ($columns as $col) {
|
||||
|
||||
$title = $col['header'];
|
||||
|
||||
if (($col['rotate'] ?? false)) {
|
||||
$x = $this->GetX();
|
||||
$y = $this->GetY() + 7;
|
||||
|
||||
$this->StartTransform();
|
||||
$this->Rotate(45, $x, $y);
|
||||
|
||||
$lineY = $startY + 7;
|
||||
if (($col['id'] ?? '') === 'gesamt') {
|
||||
$this->SetLineWidth(0.6);
|
||||
} else {
|
||||
$this->SetLineWidth(0.2);
|
||||
}
|
||||
|
||||
$this->Line($x, $lineY, $x + ($col['width_header'] ?? 0), $lineY);
|
||||
$this->SetLineWidth(0.2);
|
||||
|
||||
$this->Cell($col['width_header'] ?? 0, 7, $title ?? '', 0, 0, 'C');
|
||||
$this->StopTransform();
|
||||
$this->SetX($x + ($col['max_width'] ?? 0));
|
||||
} else {
|
||||
$this->Cell($col['max_width'] ?? 0, 7, $title ?? '', 0, 0, $col['align'] ?? 'L');
|
||||
}
|
||||
}
|
||||
|
||||
$this->Ln();
|
||||
$this->headerBottomY = $this->GetY();
|
||||
}
|
||||
|
||||
|
||||
// Page footer
|
||||
public function Footer()
|
||||
{
|
||||
$this->SetLineWidth(0.6);
|
||||
$this->Line($this->marginSide ?? 10, $this->headerBottomY, $this->pdfWidth - ($this->marginSide ?? 10), $this->headerBottomY);
|
||||
|
||||
$this->SetLineWidth(0.2);
|
||||
|
||||
$this->SetY(0);
|
||||
$this->SetX(0);
|
||||
|
||||
$this->SetFillColor(255, 255, 255); // white
|
||||
|
||||
$this->Cell(($this->marginSide ?? 10), $this->pdfHeight, '', 0, 0, 'L', true);
|
||||
|
||||
$this->SetY(0);
|
||||
$this->SetX($this->pdfWidth - ($this->marginSide ?? 10));
|
||||
|
||||
$this->Cell(($this->marginSide ?? 10), $this->pdfHeight, '', 0, 0, 'L', true);
|
||||
|
||||
$this->SetY(-15);
|
||||
$this->SetFont('freesans', 'I', 8);
|
||||
|
||||
// 1. Page Number - Centered
|
||||
$this->Cell(0, 10, 'Seite ' . $this->getAliasNumPage() . ' von ' . $this->getAliasNbPages(), 0, false, 'C');
|
||||
|
||||
// 2. Timestamp - Force to Left
|
||||
$this->SetX($this->getMargins()['left']); // Reset to left margin
|
||||
$this->Cell(0, 10, 'Zeitstempel: ' . $this->now, 0, false, 'L');
|
||||
|
||||
// 3. Host - Force to Right (Cell with width 0 and align 'R' handles this)
|
||||
$this->SetX($this->getMargins()['left']); // Reset again so 'R' alignment works from the start
|
||||
$this->Cell(0, 10, $_SERVER['HTTP_HOST'], 0, 0, 'R', false, 'https://'.$_SERVER['HTTP_HOST']);
|
||||
}
|
||||
}
|
||||
|
||||
$pdf = new ProtokollPDF($orientation, 'mm', $format, true, 'UTF-8', false);
|
||||
|
||||
$pdfHeight = $pdf->getPageHeight();
|
||||
$pdfWidth = $pdf->getPageWidth();
|
||||
|
||||
$pdf->wkName = $wkName;
|
||||
$pdf->marginSide = $marginSide;
|
||||
$pdf->marginTop = $marginTop;
|
||||
$pdf->pdfHeight = $pdfHeight;
|
||||
$pdf->pdfWidth = $pdfWidth;
|
||||
$pdf->now = $now;
|
||||
|
||||
$pdf->SetCreator(PDF_CREATOR);
|
||||
$pdf->SetAuthor($wkName);
|
||||
$pdf->SetTitle($wkName . "_Protokoll.pdf");
|
||||
|
||||
$pdf->SetAutoPageBreak(FALSE);
|
||||
|
||||
|
||||
$pdf->SetFont('freesans', '', 11);
|
||||
|
||||
// Define columns dynamically
|
||||
$columns = [
|
||||
['id' => 'order_id', 'header' => 'Rechnungsnummer', 'align' => 'L', 'flex' => true, 'type' => 'link', 'field' => 'order_id'],
|
||||
['id' => 'value', 'header' => 'Änderung', 'align' => 'L', 'flex' => true, 'type' => 'value', 'field' => 'value'],
|
||||
['id' => 'edited_by', 'header' => 'Geändert durch', 'align' => 'C', 'flex' => true, 'type' => 'field', 'field' => 'edited_by'],
|
||||
['id' => 'timestamp', 'header' => 'Zeitstempel', 'align' => 'C', 'flex' => true, 'type' => 'field', 'field' => 'timestamp'],
|
||||
];
|
||||
|
||||
|
||||
$padding = 4;
|
||||
|
||||
// 1. Calculate initial max widths based on headers
|
||||
foreach ($columns as &$col) {
|
||||
$col['width_header'] = $pdf->GetStringWidth($col['header']) + ($padding * 2);
|
||||
if ($col['type'] !== 'note') {
|
||||
$col['max_width'] = $col['width_header'];
|
||||
} else {
|
||||
$col['max_width'] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
unset($col);
|
||||
|
||||
foreach ($entriesArray as $row) {
|
||||
foreach ($columns as $col) {
|
||||
$text = '';
|
||||
if ($col['type'] !== 'value') {
|
||||
if (isset($row[$col['field']])) {
|
||||
$text = $row[$col['field']];
|
||||
}
|
||||
$width = $pdf->GetStringWidth($text) + ($padding * 2);
|
||||
if ($width > $col['max_width']) {
|
||||
$col['max_width'] = $width;
|
||||
}
|
||||
} else {
|
||||
if (40 > $col['max_width']) {
|
||||
$col['max_width'] = 40;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$fixedWidth = 0;
|
||||
|
||||
foreach ($columns as $col) {
|
||||
if ($col['flex'] ?? false) {
|
||||
$flexCols[] = $col['id'];
|
||||
$fixedWidth += $col['max_width'];
|
||||
} else {
|
||||
$fixedWidth += $col['max_width'];
|
||||
}
|
||||
}
|
||||
|
||||
$tablew = $pdfWidth - (2 * $marginSide);
|
||||
|
||||
$effTableWidth = $tablew - $fixedWidth;
|
||||
|
||||
if (!empty($flexCols) && $effTableWidth > 0) {
|
||||
$flexTotalInitial = 0;
|
||||
foreach ($columns as $col) {
|
||||
if ($col['flex'] ?? false) $flexTotalInitial += $col['max_width'];
|
||||
}
|
||||
|
||||
foreach ($columns as &$col) {
|
||||
if ($col['flex'] ?? false) {
|
||||
$col['max_width'] += ($col['max_width'] / $flexTotalInitial) * $effTableWidth;
|
||||
}
|
||||
}
|
||||
unset($col);
|
||||
}
|
||||
|
||||
$pdf->columns = $columns;
|
||||
|
||||
$pdf->AddPage();
|
||||
$margin_top = $pdf->headerBottomY;
|
||||
|
||||
$pdf->SetMargins($marginSide, $margin_top, $marginSide); // +5 mm padding below header
|
||||
$pdf->SetY($margin_top); // Move cursor below header manually
|
||||
|
||||
$pdf->SetFont('', '');
|
||||
|
||||
foreach ($entriesArray as $row) {
|
||||
|
||||
$rowHeight = 10;
|
||||
|
||||
foreach ($columns as $col) {
|
||||
|
||||
$pdf->setFillColor(255, 255, 255);
|
||||
|
||||
if ($pdf->getY() + $rowHeight > $pdfHeight - $minMarginBottomTable) {
|
||||
$pdf->addPage();
|
||||
$margin_top = $pdf->headerBottomY;
|
||||
$pdf->setY($margin_top);
|
||||
}
|
||||
|
||||
$customFontSize = (isset($col['font_size']) && $col['font_size'] != 0);
|
||||
|
||||
if ($customFontSize) {
|
||||
$pdf->SetFont('', '', $col['font_size']);
|
||||
}
|
||||
|
||||
$startX = $pdf->GetX();
|
||||
$startY = $pdf->GetY();
|
||||
|
||||
if ($col['type'] === 'field') {
|
||||
$text = $row[$col['field']] ?? '';
|
||||
|
||||
$pdf->MultiCell($col['max_width'], $rowHeight, $text, 'B', $col['align'], true, 0, $startX, $startY, true, 0, false, true, $rowHeight, 'M');
|
||||
} elseif ($col['type'] === 'value') {
|
||||
$pdf->MultiCell($col['max_width'], $rowHeight, '', 'B', $col['align'], true, 0, $startX, $startY, true, 0, false, true, $rowHeight, 'M');
|
||||
|
||||
$valuesArrary = $row[$col['field']];
|
||||
|
||||
if (isset($valuesArrary[1]) && isset($valuesArrary[2]) && $valuesArrary[2]) {
|
||||
$pdf->ImageSVG('@' . $valuesArrary[1], $startX, $startY + 2, $rowHeight - 4, $rowHeight - 4);
|
||||
$pdf->MultiCell(10, $rowHeight, json_decode('"\u2192"'), '', 'C', false, 0, $startX + $rowHeight - 4, $startY, true, 0, false, true, $rowHeight, 'M');
|
||||
}
|
||||
|
||||
if (isset($valuesArrary[3]) && isset($valuesArrary[3]) && $valuesArrary[4]) {
|
||||
$pdf->ImageSVG('@' . $valuesArrary[3], $startX + $rowHeight - 4 + 10, $startY + 2, $rowHeight - 4, $rowHeight - 4);
|
||||
}
|
||||
|
||||
$pdf->SetX($startX + $col['max_width']);
|
||||
|
||||
} elseif ($col['type'] === 'link') {
|
||||
$text = $row[$col['field']] ?? '';
|
||||
|
||||
$pdf->MultiCell($col['max_width'], $rowHeight, $text, 'B', $col['align'], true, 0, $startX, $startY, true, 0, false, true, $rowHeight, 'M');
|
||||
|
||||
$pdf->Link($startX, $startY, $col['max_width'], $rowHeight, 'https://'.$_SERVER['HTTP_HOST'].'/intern/wk-leitung/rechnungen-viewer?order_id='.$text);
|
||||
}
|
||||
|
||||
if ($customFontSize) {
|
||||
$pdf->SetFont('', '', $normalFontSize);
|
||||
}
|
||||
}
|
||||
|
||||
$pdf->SetY($startY + $rowHeight);
|
||||
}
|
||||
$textanzEintaege = (count($entriesArray) > 1) ? 'Einträge': 'Eintrag';
|
||||
|
||||
$pdf->SetFont('', '', 7);
|
||||
|
||||
$pdf->Cell(20, 6, count($entriesArray).' '.$textanzEintaege, 0, 0, 'L');
|
||||
|
||||
$pdf->SetFont('', '', $normalFontSize);
|
||||
|
||||
|
||||
$pdf->Output($wkName . "_Protokoll_Rechnungen.pdf", 'I');
|
||||
exit;
|
||||
@@ -1,74 +0,0 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
if (!isset($baseDir)) {
|
||||
$baseDir = $_SERVER['DOCUMENT_ROOT'];
|
||||
}
|
||||
|
||||
require_once $baseDir . '/../scripts/session_functions.php';
|
||||
|
||||
ini_wkvs_session();
|
||||
|
||||
check_user_permission('wk_leitung');
|
||||
|
||||
verify_csrf();
|
||||
|
||||
$type = 'wkl';
|
||||
|
||||
$data = include $baseDir . '/../scripts/db/db-verbindung-script.php';
|
||||
|
||||
if ($data['success'] === false){
|
||||
echo json_encode(['success' => false, 'message' => $data['message']]);
|
||||
http_response_code(500);
|
||||
exit;
|
||||
}
|
||||
|
||||
require $baseDir . '/../scripts/db/db-tables.php';
|
||||
|
||||
if (!isset($_POST['ids']) || !is_array($_POST['ids']) || count($_POST['ids']) < 1) {
|
||||
echo json_encode(['success' => false, 'message' => 'Keine Id angegeben']);
|
||||
http_response_code(422);
|
||||
exit;
|
||||
}
|
||||
|
||||
$ids = $_POST['ids'];
|
||||
|
||||
// Validate: all IDs must be integers
|
||||
$ids = array_filter($ids, fn($id) => ctype_digit(strval($id)));
|
||||
|
||||
if (count($ids) === 0) {
|
||||
echo json_encode(['success' => false, 'message' => 'Kein gültiger Input']);
|
||||
http_response_code(422);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Build placeholders for prepared statement
|
||||
$placeholders = implode(',', array_fill(0, count($ids), '?'));
|
||||
|
||||
// Prepare the SQL statement
|
||||
$sql = "DELETE FROM $tableOrders WHERE order_id IN ($placeholders)";
|
||||
$stmt = $mysqli->prepare($sql);
|
||||
|
||||
if (!$stmt) {
|
||||
echo json_encode(['success' => false, 'message' => 'Fehler beim Vorbereiten der Abfrage']);
|
||||
http_response_code(500);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Bind parameters dynamically
|
||||
$types = str_repeat('i', count($ids)); // all integers
|
||||
$stmt->bind_param($types, ...$ids);
|
||||
|
||||
// Execute
|
||||
if (!$stmt->execute()) {
|
||||
echo json_encode(['success' => false, 'message' => 'Fehler beim Löschen']);
|
||||
http_response_code(500);
|
||||
exit;
|
||||
}
|
||||
|
||||
$stmt->close();
|
||||
$mysqli->close();
|
||||
|
||||
echo json_encode(['success' => true, 'message' => 'Bestellungen erfolgreich gelöscht']);
|
||||
http_response_code(200);
|
||||
exit;
|
||||
@@ -1,6 +1,8 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
ini_set("display_errors", 1);
|
||||
|
||||
if (!isset($baseDir)) {
|
||||
$baseDir = $_SERVER['DOCUMENT_ROOT'];
|
||||
}
|
||||
@@ -13,6 +15,20 @@ check_user_permission('wk_leitung');
|
||||
|
||||
verify_csrf();
|
||||
|
||||
$allowedActions = ['payEntrys' => 2, 'deleteEntrys' => 3];
|
||||
|
||||
$requestedAction = trim($_POST['action'] ?? '');
|
||||
|
||||
if (!array_key_exists($requestedAction, $allowedActions)) {
|
||||
echo json_encode(['success' => false, 'message' => 'Invalid Action']);
|
||||
http_response_code(400);
|
||||
exit;
|
||||
}
|
||||
|
||||
$actionValue = $allowedActions[$requestedAction];
|
||||
|
||||
$user = $_SESSION['user_id_wk_leitung'] ?? 0;
|
||||
|
||||
$type = 'wkl';
|
||||
|
||||
$data = include $baseDir . '/../scripts/db/db-verbindung-script.php';
|
||||
@@ -24,47 +40,70 @@ if ($data['success'] === false){
|
||||
}
|
||||
|
||||
require $baseDir . '/../scripts/db/db-tables.php';
|
||||
require $baseDir . '/../scripts/db/db-functions.php';
|
||||
|
||||
if (!isset($_POST['scor']) || empty($_POST['scor']) || $_POST['scor'] === '') {
|
||||
echo json_encode(['success' => false, 'message' => 'Keine Referenz angegeben']);
|
||||
if (!isset($_POST['ids']) || !is_array($_POST['ids']) || count($_POST['ids']) < 1) {
|
||||
echo json_encode(['success' => false, 'message' => 'Keine Id angegeben']);
|
||||
http_response_code(422);
|
||||
exit;
|
||||
}
|
||||
|
||||
$scorFullStr = strval($_POST['scor']);
|
||||
$ids = $_POST['ids'];
|
||||
|
||||
$scor = intval(substr($scorFullStr, 2));
|
||||
// Validate: all IDs must be integers
|
||||
$ids = array_filter($ids, fn($id) => ctype_digit(strval($id)));
|
||||
|
||||
$stmt = $mysqli->prepare(
|
||||
"SELECT 1 FROM $tableOrders WHERE order_id = ? LIMIT 1"
|
||||
);
|
||||
$stmt->bind_param('i', $scor);
|
||||
$stmt->execute();
|
||||
$stmt->store_result();
|
||||
if (count($ids) === 0) {
|
||||
echo json_encode(['success' => false, 'message' => 'Kein gültiger Input']);
|
||||
http_response_code(422);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($stmt->num_rows !== 1) {
|
||||
echo json_encode(['success' => false, 'message' => 'Invalide Referenz']);
|
||||
http_response_code(403);
|
||||
exit;
|
||||
// Build placeholders for prepared statement
|
||||
$placeholders = implode(',', array_fill(0, count($ids), '?'));
|
||||
|
||||
$affectedRows = db_select($mysqli, $tableOrders, "order_status, order_id", "order_id IN ($placeholders)", $ids);
|
||||
|
||||
$mysqli->begin_transaction();
|
||||
|
||||
try {
|
||||
$stmt = $mysqli->prepare("INSERT INTO $tableOrdersLog (`old_order_status`, `new_order_status`, `order_id`, `edited_by`) VALUES (?, ?, ?, ?)");
|
||||
foreach ($affectedRows as $row) {
|
||||
$stmt->bind_param("ssss", $row['order_status'], $actionValue, $row['order_id'], $user);
|
||||
$stmt->execute();
|
||||
}
|
||||
$mysqli->commit();
|
||||
} catch (Exception $e) {
|
||||
$mysqli->rollback();
|
||||
throw $e;
|
||||
}
|
||||
|
||||
// Prepare the SQL statement
|
||||
$sql = "UPDATE $tableOrders SET order_status = ? WHERE order_id IN ($placeholders)";
|
||||
$stmt = $mysqli->prepare($sql);
|
||||
|
||||
if (!$stmt) {
|
||||
echo json_encode(['success' => false, 'message' => 'Fehler beim Vorbereiten der Abfrage']);
|
||||
http_response_code(500);
|
||||
exit;
|
||||
}
|
||||
|
||||
$params = array_merge([$actionValue], $ids);
|
||||
|
||||
// Bind parameters dynamically
|
||||
$types = 's' . str_repeat('i', count($ids)); // all integers
|
||||
$stmt->bind_param($types, ...$params);
|
||||
|
||||
// Execute
|
||||
if (!$stmt->execute()) {
|
||||
echo json_encode(['success' => false, 'message' => 'Fehler beim Löschen']);
|
||||
http_response_code(500);
|
||||
exit;
|
||||
}
|
||||
|
||||
$stmt->close();
|
||||
|
||||
$sql = "UPDATE $tableOrders SET order_status = 2 WHERE order_id = ?";
|
||||
|
||||
$nstmt = $mysqli->prepare($sql);
|
||||
|
||||
$nstmt->bind_param('i', $scor);
|
||||
|
||||
if (!$nstmt->execute()) {
|
||||
echo json_encode(['success' => false, 'message' => 'Fehler']);
|
||||
http_response_code(500);
|
||||
exit;
|
||||
}
|
||||
|
||||
$nstmt->close();
|
||||
$mysqli->close();
|
||||
|
||||
echo json_encode(['success' => true, 'message' => 'Rechnung wurde aktualisiert']);
|
||||
echo json_encode(['success' => true, 'message' => 'Bestellungen erfolgreich gelöscht']);
|
||||
http_response_code(200);
|
||||
exit;
|
||||
exit;
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
ini_set("display_errors", 1);
|
||||
|
||||
if (!isset($baseDir)) {
|
||||
$baseDir = $_SERVER['DOCUMENT_ROOT'];
|
||||
}
|
||||
|
||||
require_once $baseDir . '/../scripts/session_functions.php';
|
||||
|
||||
ini_wkvs_session();
|
||||
|
||||
check_user_permission('wk_leitung');
|
||||
|
||||
verify_csrf();
|
||||
|
||||
$type = 'wkl';
|
||||
|
||||
$data = include $baseDir . '/../scripts/db/db-verbindung-script.php';
|
||||
|
||||
if ($data['success'] === false){
|
||||
echo json_encode(['success' => false, 'message' => $data['message']]);
|
||||
http_response_code(500);
|
||||
exit;
|
||||
}
|
||||
|
||||
require $baseDir . '/../scripts/db/db-tables.php';
|
||||
require $baseDir . '/../scripts/db/db-functions.php';
|
||||
|
||||
if (!isset($_POST['scor']) || empty($_POST['scor']) || $_POST['scor'] === '') {
|
||||
echo json_encode(['success' => false, 'message' => 'Keine Referenz angegeben']);
|
||||
http_response_code(422);
|
||||
exit;
|
||||
}
|
||||
|
||||
$user = $_SESSION['user_id_wk_leitung'] ?? 0;
|
||||
|
||||
$scorFullStr = strval($_POST['scor'] ?? '');
|
||||
|
||||
$scor = intval(substr($scorFullStr, 2));
|
||||
|
||||
$stmt = $mysqli->prepare(
|
||||
"SELECT 1 FROM $tableOrders WHERE order_id = ? LIMIT 1"
|
||||
);
|
||||
|
||||
$stmt->bind_param('i', $scor);
|
||||
$stmt->execute();
|
||||
$stmt->store_result();
|
||||
|
||||
if ($stmt->num_rows !== 1) {
|
||||
echo json_encode(['success' => false, 'message' => 'Invalide Referenz']);
|
||||
http_response_code(403);
|
||||
exit;
|
||||
}
|
||||
|
||||
$stmt->close();
|
||||
|
||||
$affectedRow = db_select($mysqli, $tableOrders, "order_status, order_id", "order_id = ?", [$scor]);
|
||||
|
||||
$stmt = $mysqli->prepare("INSERT INTO $tableOrdersLog (`old_order_status`, `new_order_status`, `order_id`, `edited_by`) VALUES (?, 2, ?, ?)");
|
||||
|
||||
foreach ($affectedRow as $row) {
|
||||
$stmt->bind_param("sss", $row['order_status'], $row['order_id'], $user);
|
||||
$stmt->execute();
|
||||
}
|
||||
|
||||
$sql = "UPDATE $tableOrders SET order_status = 2 WHERE order_id = ?";
|
||||
|
||||
$nstmt = $mysqli->prepare($sql);
|
||||
|
||||
$nstmt->bind_param('i', $scor);
|
||||
|
||||
if (!$nstmt->execute()) {
|
||||
echo json_encode(['success' => false, 'message' => 'Fehler']);
|
||||
http_response_code(500);
|
||||
exit;
|
||||
}
|
||||
|
||||
$nstmt->close();
|
||||
$mysqli->close();
|
||||
|
||||
echo json_encode(['success' => true, 'message' => 'Rechnung wurde aktualisiert']);
|
||||
http_response_code(200);
|
||||
exit;
|
||||
Reference in New Issue
Block a user