160 lines
6.7 KiB
PHP
160 lines
6.7 KiB
PHP
<?php
|
|
if (session_status() === PHP_SESSION_NONE) {
|
|
session_start();
|
|
}
|
|
require_once 'includes/auth.php';
|
|
require_login();
|
|
require_once 'includes/helpers.php';
|
|
|
|
function get_polish_status_translation(string $key): string {
|
|
$translations = [
|
|
'status_pending' => 'Oczekujące',
|
|
'status_pending_payment' => 'Oczekuje na płatność',
|
|
'status_paid' => 'Zapłacone',
|
|
'status_in_progress' => 'W realizacji',
|
|
'status_shipped' => 'Wysłane',
|
|
'status_partially_shipped' => 'Częściowo wysłane',
|
|
'status_completed' => 'Zrealizowane',
|
|
'status_cancelled' => 'Anulowane',
|
|
'payment_bank_transfer' => 'Przelew tradycyjny',
|
|
'payment_online' => 'Płatność online (Przelewy24)',
|
|
'payment_credit' => 'Kredyt kupiecki',
|
|
];
|
|
|
|
$payment_methods = ['bank_transfer', 'online', 'credit'];
|
|
if (in_array($key, $payment_methods)) {
|
|
$translation_key = 'payment_' . $key;
|
|
} else {
|
|
$translation_key = 'status_' . $key;
|
|
}
|
|
|
|
return $translations[$translation_key] ?? ucfirst(str_replace('_', ' ', $key));
|
|
}
|
|
|
|
|
|
$orders = [];
|
|
$error_message = '';
|
|
|
|
if (!isset($_SESSION['client_id'])) {
|
|
$error_message = 'Nie znaleziono identyfikatora klienta. Zaloguj się ponownie.';
|
|
} else {
|
|
$client_id = $_SESSION['client_id'];
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare('SELECT * FROM orders WHERE client_id = ? ORDER BY created_at DESC');
|
|
$stmt->execute([$client_id]);
|
|
$orders = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
} catch (PDOException $e) {
|
|
error_log("Database error in orders.php: " . $e->getMessage());
|
|
$error_message = 'Wystąpił błąd podczas pobierania zamówień. Prosimy spróbować ponownie później.';
|
|
}
|
|
}
|
|
|
|
$page_title = 'Twoje zamówienia';
|
|
$user_role = get_user_role();
|
|
$lang = 'pl';
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="pl">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title><?php echo htmlspecialchars($page_title); ?> - B2B Commerce</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
|
</head>
|
|
<body>
|
|
<nav class="navbar navbar-expand-lg navbar-light bg-white shadow-sm">
|
|
<div class="container-fluid">
|
|
<a class="navbar-brand" href="index.php">
|
|
<img src="assets/pasted-20251209-065617-6bf1b4e6.png" alt="Logo" style="height: 40px;">
|
|
</a>
|
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
|
<span class="navbar-toggler-icon"></span>
|
|
</button>
|
|
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
|
<ul class="navbar-nav ms-auto mb-2 mb-lg-0 align-items-center">
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="index.php">Katalog</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="cart.php">
|
|
<i class="bi bi-cart"></i> Koszyk
|
|
<span class="badge bg-primary rounded-pill"><?= count($_SESSION['cart'] ?? []) ?></span>
|
|
</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="orders.php">Zamówienia</a>
|
|
</li>
|
|
<?php if ($user_role === 'admin'): ?>
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="/admin/products.php">Admin</a>
|
|
</li>
|
|
<?php endif; ?>
|
|
<li class="nav-item dropdown">
|
|
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
|
|
<i class="bi bi-person-circle"></i> Witaj, <?= isset($_SESSION['username']) ? htmlspecialchars($_SESSION['username']) : '' ?>
|
|
</a>
|
|
<ul class="dropdown-menu dropdown-menu-end">
|
|
<li><a class="dropdown-item p-2" href="profile.php">Profil</a></li>
|
|
<li><hr class="dropdown-divider"></li>
|
|
<li><a class="dropdown-item p-2" href="logout.php">Wyloguj</a></li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<main class="container my-5">
|
|
<h1 class="mb-4">Historia zamówień</h1>
|
|
|
|
<?php if (!empty($error_message)): ?>
|
|
<div class="alert alert-danger" role="alert">
|
|
<?php echo htmlspecialchars($error_message); ?>
|
|
</div>
|
|
<?php elseif (empty($orders)): ?>
|
|
<div class="alert alert-info" role="alert">
|
|
Nie masz jeszcze żadnych zamówień.
|
|
</div>
|
|
<?php else: ?>
|
|
<table class="table table-hover">
|
|
<thead>
|
|
<tr>
|
|
<th>Numer zamówienia</th>
|
|
<th>Data zamówienia</th>
|
|
<th>Status</th>
|
|
<th>Suma (brutto)</th>
|
|
<th></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($orders as $order): ?>
|
|
<tr>
|
|
<td>#<?php echo $order['id']; ?></td>
|
|
<td><?php echo date('d.m.Y H:i', strtotime($order['created_at'])); ?></td>
|
|
<td><span class="badge bg-info"><?php echo htmlspecialchars(get_polish_status_translation($order['status'])); ?></span></td>
|
|
<td><?php echo number_format($order['total_amount'], 2, ',', ' '); ?> zł</td>
|
|
<td>
|
|
<a href="order_details.php?id=<?php echo $order['id']; ?>" class="btn btn-sm btn-outline-primary">
|
|
<i class="bi bi-eye"></i> Szczegóły
|
|
</a>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
<?php endif; ?>
|
|
</main>
|
|
|
|
<footer class="text-center py-4 mt-auto text-muted bg-light">
|
|
<div class="container">
|
|
<p class="mb-0">© <?php echo date("Y"); ?> powered by LEA24. All Rights Reserved.</p>
|
|
</div>
|
|
</footer>
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
|
</body>
|
|
</html>
|