dodanie csrf, oauth 2, dockerfile

This commit is contained in:
Marcin Cieślikowski
2026-03-16 10:43:19 +01:00
parent 56c7ecff6d
commit df448ea7c1
26 changed files with 916 additions and 318 deletions
+24 -25
View File
@@ -1,5 +1,5 @@
<?php
require 'vendor/autoload.php'; // Ładowanie biblioteki PhpSpreadsheet
require 'vendor/autoload.php';
require_once 'includes/db.php';
require_once 'includes/auth.php';
@@ -9,15 +9,14 @@ checkAuth();
$message = '';
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_FILES['excel_file'])) {
if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_FILES['excel_file'])) {
requireCsrfToken();
$file = $_FILES['excel_file']['tmp_name'];
try {
$spreadsheet = IOFactory::load($file);
$worksheet = $spreadsheet->getActiveSheet();
$rows = $worksheet->toArray();
// Pomijamy nagłówek (pierwszy wiersz w Excelu)
unset($rows[0]);
$pdo->beginTransaction();
@@ -28,30 +27,29 @@ if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_FILES['excel_file'])) {
$count = 0;
foreach ($rows as $row) {
// Zgodnie z wymaganiem: pomijamy 1. kolumnę ($row[0])
// Mapowanie kolumn Excela:
// $row[1] -> Produkt, $row[2] -> Ilość, $row[3] -> Miejsce,
// $row[4] -> Cena, $row[5] -> Data, $row[6] -> Notatki, $row[7] -> Status
if (empty($row[1])) continue; // Pomiń puste wiersze
if (empty($row[1])) {
continue;
}
$stmt->execute([
$row[1], // Produkt
(int)$row[2], // Ilość
$row[3], // Miejsce zakupu
(float)$row[4], // Cena
$row[5], // Data dostawy (format YYYY-MM-DD)
$row[6], // Notatki
$row[7] ?? 'nowe' // Status
$row[1],
(int)$row[2],
$row[3],
(float)$row[4],
$row[5],
$row[6],
$row[7] ?? 'nowe'
]);
$count++;
}
$pdo->commit();
$message = "<div class='alert alert-success'>Pomyślnie zaimportowano $count zamówień!</div>";
$message = "<div class='alert alert-success'>Pomyslnie zaimportowano $count zamowien.</div>";
} catch (Exception $e) {
if ($pdo->inTransaction()) $pdo->rollBack();
$message = "<div class='alert alert-danger'>Błąd importu: " . $e->getMessage() . "</div>";
if ($pdo->inTransaction()) {
$pdo->rollBack();
}
error_log($e->getMessage());
$message = "<div class='alert alert-danger'>Import nie powiodl sie.</div>";
}
}
?>
@@ -60,7 +58,7 @@ if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_FILES['excel_file'])) {
<html lang="pl">
<head>
<meta charset="UTF-8">
<title>Import Zamówień - <?php echo APP_NAME; ?></title>
<title>Import zamowien - <?php echo e(APP_NAME); ?></title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="bg-light">
@@ -74,17 +72,18 @@ if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_FILES['excel_file'])) {
<div class="alert alert-info">
<strong>Instrukcja:</strong><br>
1. System pomija pierwszą kolumnę (LP).<br>
2. Kolejne kolumny to: Produkt, Ilość, Miejsce, Cena, Data (RRRR-MM-DD), Notatki, Status.
1. System pomija pierwsza kolumne (LP).<br>
2. Kolejne kolumny to: Produkt, Ilosc, Miejsce, Cena, Data (RRRR-MM-DD), Notatki, Status.
</div>
<form method="POST" enctype="multipart/form-data">
<?php echo csrfInput(); ?>
<div class="mb-3">
<label class="form-label">Wybierz plik Excel</label>
<input type="file" name="excel_file" class="form-control" accept=".xlsx, .xls" required>
</div>
<div class="d-flex justify-content-between">
<a href="index.php" class="btn btn-secondary">Powrót</a>
<a href="index.php" class="btn btn-secondary">Powrot</a>
<button type="submit" class="btn btn-success">Rozpocznij import</button>
</div>
</form>