dodanie csrf, oauth 2, dockerfile
This commit is contained in:
+20
-19
@@ -6,11 +6,11 @@ checkAuth();
|
||||
|
||||
$message = '';
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_FILES['csv_file'])) {
|
||||
if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_FILES['csv_file'])) {
|
||||
requireCsrfToken();
|
||||
$file = $_FILES['csv_file']['tmp_name'];
|
||||
|
||||
if (($handle = fopen($file, "r")) !== FALSE) {
|
||||
// Pomijamy pierwszy wiersz (nagłówki)
|
||||
if (($handle = fopen($file, "r")) !== false) {
|
||||
fgetcsv($handle, 1000, ";");
|
||||
|
||||
try {
|
||||
@@ -21,32 +21,32 @@ if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_FILES['csv_file'])) {
|
||||
$stmt = $pdo->prepare($sql);
|
||||
|
||||
$count = 0;
|
||||
while (($row = fgetcsv($handle, 1000, ";")) !== FALSE) {
|
||||
// $row[0] to LP - pomijamy zgodnie z wymaganiem
|
||||
|
||||
// Obsługa polskich znaków (jeśli plik jest w Windows-1250)
|
||||
foreach($row as $key => $value) {
|
||||
while (($row = fgetcsv($handle, 1000, ";")) !== false) {
|
||||
foreach ($row as $key => $value) {
|
||||
$row[$key] = mb_convert_encoding($value, "UTF-8", "auto");
|
||||
}
|
||||
|
||||
if (empty($row[1])) continue; // Pomiń jeśli brak nazwy produktu
|
||||
if (empty($row[1])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$stmt->execute([
|
||||
$row[1], // Produkt
|
||||
(int)$row[2], // Ilość
|
||||
$row[3], // Miejsce zakupu
|
||||
(float)str_replace(',', '.', $row[4]), // Cena (zamiana przecinka na kropkę)
|
||||
$row[5], // Data dostawy
|
||||
$row[6], // Notatki
|
||||
$row[7] ?? 'nowe' // Status
|
||||
$row[1],
|
||||
(int)$row[2],
|
||||
$row[3],
|
||||
(float)str_replace(',', '.', $row[4]),
|
||||
$row[5],
|
||||
$row[6],
|
||||
$row[7] ?? 'nowe'
|
||||
]);
|
||||
$count++;
|
||||
}
|
||||
$pdo->commit();
|
||||
$message = "<div class='alert alert-success'>Zaimportowano $count zamówień z pliku CSV!</div>";
|
||||
$message = "<div class='alert alert-success'>Zaimportowano $count zamówień z pliku CSV.</div>";
|
||||
} catch (Exception $e) {
|
||||
$pdo->rollBack();
|
||||
$message = "<div class='alert alert-danger'>Błąd: " . $e->getMessage() . "</div>";
|
||||
error_log($e->getMessage());
|
||||
$message = "<div class='alert alert-danger'>Import nie powiódł się.</div>";
|
||||
}
|
||||
fclose($handle);
|
||||
}
|
||||
@@ -57,7 +57,7 @@ if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_FILES['csv_file'])) {
|
||||
<html lang="pl">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Import CSV - <?php echo APP_NAME; ?></title>
|
||||
<title>Import CSV - <?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,6 +74,7 @@ if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_FILES['csv_file'])) {
|
||||
</div>
|
||||
|
||||
<form method="POST" enctype="multipart/form-data">
|
||||
<?php echo csrfInput(); ?>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Wybierz plik .csv</label>
|
||||
<input type="file" name="csv_file" class="form-control" accept=".csv" required>
|
||||
|
||||
Reference in New Issue
Block a user