Gggggggggggggggggggg

This commit is contained in:
Flatlogic Bot 2025-12-08 11:33:59 +00:00
parent 7da45b4e24
commit f7f8238fee
4 changed files with 595 additions and 714 deletions

View File

@ -1,4 +1,11 @@
/* Resetting styles for the new theme. */
:root {
--status-default: #444;
--status-default-dark: #6c757d;
--status-processing: #ffc107;
--status-shipped: #0d6efd;
--status-completed: #198754;
--status-cancelled: #dc3545;
}
.about-us-list {
width: 80vw;
@ -57,8 +64,6 @@
}
}
/* --- Order Tracking Modal Styles --- */
.tracking-modal-container {
position: fixed;
top: 0;
@ -181,7 +186,6 @@
margin-left: 8px;
}
/* --- Status Tracker --- */
.status-tracker {
position: relative;
display: flex;
@ -199,7 +203,7 @@
width: calc(100% - 40px);
margin: 0 20px;
height: 4px;
background-color: #444;
background-color: var(--status-default);
z-index: 1;
}
@ -209,9 +213,8 @@
transform: translateY(-50%);
right: 20px;
height: 4px;
background-color: var(--bs-primary);
z-index: 2;
transition: width 0.5s ease;
transition: width 0.5s ease, background-color 0.5s ease;
}
.status-step {
@ -225,11 +228,11 @@
width: 20px;
height: 20px;
border-radius: 50%;
background-color: #444;
background-color: var(--status-default);
border: 3px solid #2c2c2c;
margin: 0 auto;
transform: translateY(-8px);
transition: background-color 0.5s ease;
transition: background-color 0.5s ease, box-shadow 0.3s ease;
}
.status-step .label {
@ -240,34 +243,24 @@
transition: color 0.5s ease;
}
/* State Styling */
.status-step.completed .dot {
background-color: var(--bs-primary);
}
.status-step.active .dot {
background-color: #fff;
box-shadow: 0 0 10px var(--bs-primary);
}
.status-step.completed .label {
.status-step.completed .label,
.status-step.active .label {
color: #f0f0f0;
font-weight: 500;
}
.status-tracker.is-cancelled ~ .status-step:not([data-status="cancelled"]) {
opacity: 0.3;
}
.status-tracker.is-cancelled .status-step[data-status="cancelled"] .dot {
background-color: var(--bs-danger);
}
.status-tracker.is-cancelled .status-step[data-status="cancelled"] .label {
color: var(--bs-danger);
font-weight: bold;
.status-step.active .dot {
box-shadow: 0 0 12px rgba(255, 255, 255, 0.5);
}
.status-tracker.is-cancelled .status-step {
opacity: 0.5;
}
.status-tracker.is-cancelled .label {
color: var(--status-cancelled);
}
/* --- Products List --- */
#modal-products-list {
display: flex;
flex-direction: column;
@ -308,7 +301,6 @@
font-weight: bold;
}
/* --- Product Color Dot --- */
.product-meta {
display: flex;
align-items: center;
@ -331,3 +323,23 @@
border: 1px solid rgba(255, 255, 255, 0.2);
display: inline-block;
}
@media (max-width: 768px) {
footer {
text-align: center;
}
footer .row > * {
margin-bottom: 1.5rem;
}
footer .row {
justify-content: center;
}
/* Center social icons and contact list items on mobile */
footer .social-icons,
footer .list-unstyled .d-flex {
justify-content: center;
}
}

View File

@ -108,20 +108,18 @@ $page_title = $page_title ?? 'فروشگاه آتیمه'; // Default title
</a>
<?php if (isset($_SESSION['user_id'])): ?>
<div class="dropdown ms-3">
<a href="#" class="d-flex align-items-center text-decoration-none dropdown-toggle" id="dropdownUser" data-bs-toggle="dropdown" aria-expanded="false">
<i class="ri-user-line fs-5 me-1"></i>
<a href="profile.php" class="ms-4 d-flex align-items-center text-decoration-none" title="حساب کاربری">
<i class="ri-user-line fs-5 me-2"></i>
<span><?php echo htmlspecialchars($_SESSION['user_name']); ?></span>
</a>
<ul class="dropdown-menu dropdown-menu-end text-small shadow" aria-labelledby="dropdownUser">
<li><a class="dropdown-item" href="profile.php">حساب کاربری</a></li>
<?php if (!empty($_SESSION['is_admin'])): ?>
<li><a class="dropdown-item" href="/admin/index.php">پنل مدیریت</a></li>
<a href="/admin/index.php" class="ms-3" title="پنل مدیریت">
<i class="ri-shield-user-line fs-5"></i>
</a>
<?php endif; ?>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="logout.php">خروج</a></li>
</ul>
</div>
<a href="logout.php" class="ms-3" title="خروج">
<i class="ri-logout-box-r-line fs-5"></i>
</a>
<?php else: ?>
<a href="login.php" class="btn btn-primary btn-sm ms-3">ورود / ثبت‌نام</a>
<?php endif; ?>

View File

@ -1,10 +1,8 @@
<?php
session_start();
require_once 'db/config.php';
require_once 'includes/jdf.php'; // For Jalali date conversion
if (!isset($_SESSION['user_id'])) {
header('Location: login.php');
exit;
@ -15,68 +13,51 @@ $pdo = db();
// Handle form submissions for account page
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
if ($_POST['action'] === 'update_details') {
$action = $_POST['action'];
$redirect_page = $_GET['page'] ?? 'dashboard';
try {
if ($action === 'update_details') {
$first_name = trim($_POST['first_name'] ?? '');
$last_name = trim($_POST['last_name'] ?? '');
$email = trim($_POST['email'] ?? '');
if (empty($first_name) || empty($last_name) || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
$_SESSION['profile_message'] = 'لطفاً تمام فیلدها را به درستی پر کنید.';
$_SESSION['profile_message_type'] = 'danger';
} else {
try {
throw new Exception('لطفاً تمام فیلدها را به درستی پر کنید.');
}
$stmt = $pdo->prepare("UPDATE users SET first_name = ?, last_name = ?, email = ? WHERE id = ?");
$stmt->execute([$first_name, $last_name, $email, $user_id]);
$_SESSION['profile_message'] = 'اطلاعات شما با موفقیت به‌روزرسانی شد.';
$_SESSION['profile_message_type'] = 'success';
} catch (PDOException $e) {
// Check for duplicate email error
if ($e->errorInfo[1] == 1062) {
$_SESSION['profile_message'] = 'این ایمیل قبلاً ثبت شده است. لطفاً ایمیل دیگری را امتحان کنید.';
} else {
$_SESSION['profile_message'] = 'خطا در به‌روزرسانی اطلاعات.';
}
$_SESSION['profile_message_type'] = 'danger';
}
}
header('Location: profile.php?page=account');
exit;
} elseif ($_POST['action'] === 'update_password') {
$redirect_page = 'account';
} elseif ($action === 'update_password') {
$new_password = $_POST['new_password'] ?? '';
$confirm_password = $_POST['confirm_password'] ?? '';
if (strlen($new_password) < 8) {
$_SESSION['profile_message'] = 'رمز عبور جدید باید حداقل ۸ کاراکتر باشد.';
$_SESSION['profile_message_type'] = 'danger';
throw new Exception('رمز عبور جدید باید حداقل ۸ کاراکتر باشد.');
} elseif ($new_password !== $confirm_password) {
$_SESSION['profile_message'] = 'رمزهای عبور جدید با هم مطابقت ندارند.';
$_SESSION['profile_message_type'] = 'danger';
} elseif (!empty($new_password)) {
throw new Exception('رمزهای عبور جدید با هم مطابقت ندارند.');
}
$hashed_password = password_hash($new_password, PASSWORD_DEFAULT);
$stmt = $pdo->prepare("UPDATE users SET password = ? WHERE id = ?");
if ($stmt->execute([$hashed_password, $user_id])) {
$stmt->execute([$hashed_password, $user_id]);
$_SESSION['profile_message'] = 'رمز عبور شما با موفقیت تغییر کرد.';
$_SESSION['profile_message_type'] = 'success';
} else {
$_SESSION['profile_message'] = 'خطا در تغییر رمز عبور.';
$_SESSION['profile_message_type'] = 'danger';
}
}
header('Location: profile.php?page=account');
exit;
} elseif ($_POST['action'] === 'add_address') {
$redirect_page = 'account';
} elseif ($action === 'add_address') {
$province = trim($_POST['province'] ?? '');
$city = trim($_POST['city'] ?? '');
$address_line = trim($_POST['address_line'] ?? '');
$postal_code = trim($_POST['postal_code'] ?? '');
$is_default = isset($_POST['is_default']);
if (empty($province) || empty($city) || empty($address_line) || empty($postal_code)) {
$_SESSION['profile_message'] = 'لطفاً تمام فیلدهای آدرس را پر کنید.';
$_SESSION['profile_message_type'] = 'danger';
} else {
throw new Exception('لطفاً تمام فیلدهای آدرس را پر کنید.');
}
$pdo->beginTransaction();
try {
if ($is_default) {
$stmt = $pdo->prepare("UPDATE user_addresses SET is_default = 0 WHERE user_id = ?");
$stmt->execute([$user_id]);
@ -84,32 +65,21 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
$stmt = $pdo->prepare("INSERT INTO user_addresses (user_id, province, city, address_line, postal_code, is_default) VALUES (?, ?, ?, ?, ?, ?)");
$stmt->execute([$user_id, $province, $city, $address_line, $postal_code, $is_default ? 1 : 0]);
$pdo->commit();
$_SESSION['profile_message'] = 'آدرس جدید با موفقیت اضافه شد.';
$_SESSION['profile_message_type'] = 'success';
} catch (PDOException $e) {
$pdo->rollBack();
$_SESSION['profile_message'] = 'خطا در افزودن آدرس.';
$_SESSION['profile_message_type'] = 'danger';
}
}
header('Location: profile.php?page=addresses');
exit;
} elseif ($_POST['action'] === 'delete_address') {
$redirect_page = 'addresses';
} elseif ($action === 'delete_address') {
$address_id = $_POST['address_id'] ?? 0;
$stmt = $pdo->prepare("DELETE FROM user_addresses WHERE id = ? AND user_id = ?");
if ($stmt->execute([$address_id, $user_id])) {
if (!$stmt->execute([$address_id, $user_id])) throw new Exception('خطا در حذف آدرس.');
$_SESSION['profile_message'] = 'آدرس با موفقیت حذف شد.';
$_SESSION['profile_message_type'] = 'success';
} else {
$_SESSION['profile_message'] = 'خطا در حذف آدرس.';
$_SESSION['profile_message_type'] = 'danger';
}
header('Location: profile.php?page=addresses');
exit;
} elseif ($_POST['action'] === 'set_default_address') {
$redirect_page = 'addresses';
} elseif ($action === 'set_default_address') {
$address_id = $_POST['address_id'] ?? 0;
$pdo->beginTransaction();
try {
$stmt1 = $pdo->prepare("UPDATE user_addresses SET is_default = 0 WHERE user_id = ?");
$stmt1->execute([$user_id]);
$stmt2 = $pdo->prepare("UPDATE user_addresses SET is_default = 1 WHERE id = ? AND user_id = ?");
@ -117,16 +87,37 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
$pdo->commit();
$_SESSION['profile_message'] = 'آدرس پیش‌فرض با موفقیت تغییر کرد.';
$_SESSION['profile_message_type'] = 'success';
$redirect_page = 'addresses';
}
} catch (PDOException $e) {
if (isset($pdo) && $pdo->inTransaction()) {
$pdo->rollBack();
$_SESSION['profile_message'] = 'خطا در تغییر آدرس پیش‌فرض.';
}
if ($e->errorInfo[1] == 1062) { // Duplicate entry
$_SESSION['profile_message'] = 'این ایمیل قبلاً ثبت شده است.';
} else {
$_SESSION['profile_message'] = 'یک خطای پایگاه داده رخ داد: ' . $e->getMessage();
}
$_SESSION['profile_message_type'] = 'danger';
} catch (Exception $e) {
$_SESSION['profile_message'] = $e->getMessage();
$_SESSION['profile_message_type'] = 'danger';
}
header('Location: profile.php?page=addresses');
header('Location: profile.php?page=' . $redirect_page);
exit;
}
}
// Determine current page
$page = $_GET['page'] ?? 'dashboard';
$page_map = [
'dashboard' => 'داشبورد',
'orders' => 'سفارشات من',
'addresses' => 'آدرس‌های من',
'account' => 'جزئیات حساب',
];
$page_title = $page_map[$page] ?? 'حساب کاربری';
// Retrieve flash message
if (isset($_SESSION['profile_message'])) {
$flash_message = $_SESSION['profile_message'];
@ -135,185 +126,179 @@ if (isset($_SESSION['profile_message'])) {
unset($_SESSION['profile_message_type']);
}
// Fetch user data
$stmt = $pdo->prepare("SELECT * FROM users WHERE id = ?");
$stmt->execute([$user_id]);
$user = $stmt->fetch(PDO::FETCH_ASSOC);
// Fetch all necessary data
$stmt_user = $pdo->prepare("SELECT * FROM users WHERE id = ?");
$stmt_user->execute([$user_id]);
$user = $stmt_user->fetch(PDO::FETCH_ASSOC);
// Fetch user addresses
$stmt_addresses = $pdo->prepare("SELECT * FROM user_addresses WHERE user_id = ? ORDER BY is_default DESC, id DESC");
$stmt_addresses->execute([$user_id]);
$addresses = $stmt_addresses->fetchAll(PDO::FETCH_ASSOC);
// Fetch user orders with items
$stmt_orders = $pdo->prepare("SELECT * FROM orders WHERE user_id = ? ORDER BY created_at DESC");
$stmt_orders->execute([$user_id]);
$orders = $stmt_orders->fetchAll(PDO::FETCH_ASSOC);
// Calculate total purchase amount from COMPLETED orders
$total_purchase_amount = 0;
foreach ($orders as $order) {
if (strtolower($order['status']) === 'completed') {
$total_purchase_amount += $order['total_amount'];
$stmt_addresses = $pdo->prepare("SELECT * FROM user_addresses WHERE user_id = ? ORDER BY is_default DESC, id DESC");
$stmt_addresses->execute([$user_id]);
$addresses = $stmt_addresses->fetchAll(PDO::FETCH_ASSOC);
$total_purchase_amount = array_reduce($orders, function ($sum, $order) {
return strtolower($order['status']) === 'completed' ? $sum + $order['total_amount'] : $sum;
}, 0);
?>
<!DOCTYPE html>
<html lang="fa" dir="rtl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?= htmlspecialchars($page_title) ?> - پنل کاربری</title>
<meta name="robots" content="noindex, nofollow">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/rastikerdar/vazirmatn@v33.0.3/Vazirmatn-font-face.css">
<link rel="stylesheet" href="assets/css/theme.css?v=<?= time() ?>">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
<link rel="stylesheet" href="admin/assets/css/admin_style.css?v=<?= time() ?>">
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<style>
/* Minor adjustments for profile page to match admin styles */
.admin-main-content { background-color: var(--admin-bg); }
.table th, .table td { vertical-align: middle; }
.form-label { font-weight: 600; color: var(--admin-text-muted); }
.card-header h4 { margin: 0; font-size: 1.1rem; }
.order-status {
padding: 0.25em 0.6em;
font-size: 0.75em;
font-weight: 700;
border-radius: 50rem;
display: inline-block;
line-height: 1;
}
}
.order-status.status-completed { background: var(--admin-success); color: #111; }
.order-status.status-pending { background: var(--admin-warning); color: #111; }
.order-status.status-shipped { background: var(--admin-info); color: #111; }
.order-status.status-cancelled { background: var(--admin-danger); color: #fff; }
.stat-cards-grid-reports {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 1.5rem;
margin-bottom: 2rem;
}
.stat-card-report {
background-color: var(--admin-card-bg);
padding: 1.5rem;
border-radius: 12px;
border: 1px solid var(--admin-border);
}
.stat-card-report p { margin-bottom: 0.5rem; color: var(--admin-text-muted); }
.stat-card-report h3 { margin: 0; font-size: 2rem; color: var(--admin-text); }
</style>
</head>
<body class="admin-body">
$page_title = 'حساب کاربری';
require_once 'includes/header.php';
?>
<?php
// Simple router to determine the current page
$page = $_GET['page'] ?? 'dashboard';
?>
<main>
<section class="section-padding">
<div class="container">
<div class="text-center mb-5" data-aos="fade-down">
<h1 class="section-title">حساب کاربری من</h1>
<div class="admin-wrapper">
<!-- Sidebar -->
<aside class="admin-sidebar">
<div class="sidebar-header">
<h2><a href="index.php">آتیمه<span>.</span></a></h2>
</div>
<div class="row g-4">
<!-- Off-canvas Toggle Button (Visible on Mobile) -->
<div class="d-lg-none col-12">
<button class="btn btn-primary w-100" type="button" data-bs-toggle="offcanvas" data-bs-target="#profileOffcanvas" aria-controls="profileOffcanvas">
<i class="ri-menu-line me-2"></i>
منوی حساب کاربری
</button>
</div>
<!-- Profile Sidebar -->
<div class="col-lg-3">
<div class="offcanvas-lg offcanvas-end bg-dark" tabindex="-1" id="profileOffcanvas" aria-labelledby="profileOffcanvasLabel">
<div class="offcanvas-header border-bottom">
<h5 class="offcanvas-title" id="profileOffcanvasLabel">منوی کاربری</h5>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close" data-bs-target="#profileOffcanvas"></button>
</div>
<div class="offcanvas-body">
<div class="card card-body text-center mb-4" data-aos="fade-up">
<div class="user-avatar mb-3">
<i class="ri-user-fill display-4"></i>
</div>
<h5><?= htmlspecialchars(($user['first_name'] ?? '') . ' ' . ($user['last_name'] ?? '')); ?></h5>
<p class="text-muted mb-0"><?= htmlspecialchars($user['email'] ?? ''); ?></p>
</div>
<div class="card card-body p-2" data-aos="fade-up" data-aos-delay="100">
<ul class="nav flex-column profile-nav">
<li class="nav-item">
<a class="nav-link <?= ($page === 'dashboard') ? 'active' : '' ?>" href="profile.php?page=dashboard">
<i class="ri-dashboard-line me-2"></i>
داشبورد
<ul class="admin-nav">
<li>
<a class="admin-nav-link <?= ($page === 'dashboard') ? 'active' : '' ?>" href="profile.php?page=dashboard">
<i class="fas fa-tachometer-alt"></i><span>داشبورد</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link <?= ($page === 'orders') ? 'active' : '' ?>" href="profile.php?page=orders">
<i class="ri-shopping-bag-3-line me-2"></i>
سفارشات من
<li>
<a class="admin-nav-link <?= ($page === 'orders') ? 'active' : '' ?>" href="profile.php?page=orders">
<i class="fas fa-clipboard-list"></i><span>سفارشات من</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link <?= ($page === 'addresses') ? 'active' : '' ?>" href="profile.php?page=addresses">
<i class="ri-map-pin-line me-2"></i>
آدرس‌های من
<li>
<a class="admin-nav-link <?= ($page === 'addresses') ? 'active' : '' ?>" href="profile.php?page=addresses">
<i class="fas fa-map-marker-alt"></i><span>آدرس‌های من</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link <?= ($page === 'account') ? 'active' : '' ?>" href="profile.php?page=account">
<i class="ri-user-settings-line me-2"></i>
جزئیات حساب
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="logout.php">
<i class="ri-logout-box-r-line me-2"></i>
خروج از حساب
<li>
<a class="admin-nav-link <?= ($page === 'account') ? 'active' : '' ?>" href="profile.php?page=account">
<i class="fas fa-user-cog"></i><span>جزئیات حساب</span>
</a>
</li>
</ul>
<div class="sidebar-footer">
<a href="index.php"><i class="fas fa-home fa-fw"></i> <span>بازگشت به سایت</span></a>
<a href="logout.php"><i class="fas fa-sign-out-alt fa-fw"></i> <span>خروج از حساب</span></a>
</div>
</div>
</div>
</div>
</aside>
<!-- Profile Content -->
<div class="col-lg-9" data-aos="fade-left">
<?php if (isset($flash_message)): ?>
<div class="alert alert-<?= $flash_message_type; ?> alert-dismissible fade show" role="alert">
<?= htmlspecialchars($flash_message); ?>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
<!-- Main Content -->
<div class="admin-main-content">
<header class="admin-header-bar">
<button id="sidebar-toggle" class="btn d-lg-none">
<i class="fas fa-bars"></i>
</button>
<div class="admin-header-title">
<h1><?= htmlspecialchars($page_title) ?></h1>
</div>
</header>
<main>
<?php if (isset($flash_message)): ?>
<script>
Swal.fire({
title: '<?= ($flash_message_type === 'success') ? 'موفق' : 'خطا' ?>',
text: '<?= addslashes(htmlspecialchars($flash_message)) ?>',
icon: '<?= htmlspecialchars($flash_message_type) ?>',
confirmButtonText: 'باشه'
});
</script>
<?php endif; ?>
<?php if ($page === 'dashboard'): ?>
<div class="card card-body p-4 p-md-5 text-center text-md-start">
<h3 class="dashboard-title">سلام، <?= htmlspecialchars($user['first_name'] ?? 'کاربر'); ?> عزیز!</h3>
<p>به پنل کاربری خود خوش آمدید. از اینجا می‌توانید آخرین سفارشات خود را مشاهده کرده، اطلاعات حساب خود را مدیریت کنید و آدرس‌های خود را به‌روزرسانی نمایید.</p>
</div>
<div class="row g-4 mt-4">
<div class="col-md-6">
<div class="card card-body summary-card">
<i class="ri-shopping-cart-2-line"></i>
<div class="summary-card-info">
<span>تعداد کل سفارشات</span>
<strong><?= count($orders); ?></strong>
<div class="card mb-4" style="background-color: var(--admin-card-bg); border-color: var(--admin-border);">
<div class="card-body">
<h3 style="color: var(--admin-text);">سلام، <?= htmlspecialchars($user['first_name'] ?? 'کاربر'); ?> عزیز!</h3>
<p class="text-muted">به پنل کاربری خود خوش آمدید. از اینجا می‌توانید آخرین سفارشات خود را مشاهده کرده و حساب خود را مدیریت کنید.</p>
</div>
</div>
<div class="stat-cards-grid-reports">
<div class="stat-card-report">
<p>تعداد کل سفارشات</p>
<h3><?= count($orders); ?></h3>
</div>
<div class="col-md-6">
<div class="card card-body summary-card">
<i class="ri-wallet-3-line"></i>
<div class="summary-card-info">
<span>مجموع خرید شما</span>
<strong><?= number_format($total_purchase_amount); ?> تومان</strong>
</div>
</div>
<div class="stat-card-report">
<p>مجموع خرید (تکمیل شده)</p>
<h3><?= number_format($total_purchase_amount); ?> تومان</h3>
</div>
</div>
<?php elseif ($page === 'orders'): ?>
<div class="card">
<div class="card-header">
<h4 class="m-0">تاریخچه سفارشات</h4>
</div>
<div class="card-header"><h4>تاریخچه سفارشات</h4></div>
<div class="card-body">
<?php if (empty($orders)): ?>
<div class="alert alert-secondary text-center">شما هنوز هیچ سفارشی ثبت نکرده‌اید.</div>
<p class="text-center text-muted">شما هنوز هیچ سفارشی ثبت نکرده‌اید.</p>
<?php else: ?>
<div class="table-responsive">
<table class="table table-dark table-hover align-middle">
<table class="table table-hover">
<thead>
<tr>
<th>شماره سفارش</th>
<th>#</th>
<th>تاریخ</th>
<th>وضعیت</th>
<th>مبلغ کل</th>
<th class="text-end">عملیات</th>
<th class="text-end">رهگیری</th>
</tr>
</thead>
<tbody>
<?php foreach ($orders as $order): ?>
<?php
$status_map = [
'pending' => 'در انتظار پرداخت',
'processing' => 'در حال پردازش',
'shipped' => 'ارسال شده',
'completed' => 'تکمیل شده',
'cancelled' => 'لغو شده',
];
$order_status_lower = strtolower($order['status']);
$status_label = $status_map[$order_status_lower] ?? htmlspecialchars($order['status']);
$status_class = 'status-' . htmlspecialchars($order_status_lower);
?>
<tr>
<td><strong>#<?= $order['id']; ?></strong></td>
<td><?= htmlspecialchars($order['id']); ?></td>
<td><?= jdate('d F Y', strtotime($order['created_at'])); ?></td>
<td><span class="order-status <?= $status_class; ?>"><?= $status_label; ?></span></td>
<td>
<span class="order-status status-<?= strtolower(htmlspecialchars($order['status'])) ?>">
<?= htmlspecialchars($order['status']); ?>
</span>
</td>
<td><?= number_format($order['total_amount']); ?> تومان</td>
<td class="text-end">
<button type="button" class="btn btn-sm btn-outline-primary view-order-btn" data-tracking-id="<?= htmlspecialchars($order['tracking_id']); ?>">نمایش جزئیات</button>
<a href="track_order.php?tracking_id=<?= htmlspecialchars($order['tracking_id']); ?>" class="btn btn-sm btn-outline-primary">نمایش</a>
</td>
</tr>
<?php endforeach; ?>
@ -327,252 +312,117 @@ $page = $_GET['page'] ?? 'dashboard';
<?php elseif ($page === 'addresses'): ?>
<div class="card">
<div class="card-header d-flex justify-content-between align-items-center">
<h4 class="m-0">آدرس‌های من</h4>
<button class="btn btn-primary btn-sm" type="button" data-bs-toggle="collapse" data-bs-target="#add-address-form" aria-expanded="false" aria-controls="add-address-form">
<i class="ri-add-line me-1"></i> افزودن آدرس جدید
<h4>آدرس‌های من</h4>
<button class="btn btn-sm btn-primary" type="button" data-bs-toggle="collapse" data-bs-target="#add-address-form">
<i class="fas fa-plus"></i> افزودن آدرس
</button>
</div>
<div class="card-body">
<div class="collapse p-3 border rounded bg-dark mb-4" id="add-address-form">
<form method="POST">
<div class="collapse mb-4" id="add-address-form">
<form method="POST" action="profile.php?page=addresses">
<input type="hidden" name="action" value="add_address">
<div class="row">
<div class="col-md-4 mb-3">
<label for="add_province" class="form-label">استان</label>
<input type="text" class="form-control" id="add_province" name="province" required>
</div>
<div class="col-md-4 mb-3">
<label for="add_city" class="form-label">شهر</label>
<input type="text" class="form-control" id="add_city" name="city" required>
</div>
<div class="col-md-4 mb-3">
<label for="add_postal_code" class="form-label">کد پستی</label>
<input type="text" class="form-control" id="add_postal_code" name="postal_code" required>
</div>
</div>
<div class="mb-3">
<label for="new_address" class="form-label">آدرس کامل</label>
<textarea class="form-control" id="new_address" name="address_line" rows="2" required placeholder="خیابان، کوچه، پلاک، واحد"></textarea>
</div>
<div class="form-check mb-3">
<input class="form-check-input" type="checkbox" name="is_default" id="is_default">
<label class="form-check-label" for="is_default">
انتخاب به عنوان آدرس پیش‌فرض
</label>
<div class="col-md-4 mb-3"><label class="form-label">استان</label><input type="text" class="form-control" name="province" required></div>
<div class="col-md-4 mb-3"><label class="form-label">شهر</label><input type="text" class="form-control" name="city" required></div>
<div class="col-md-4 mb-3"><label class="form-label">کد پستی</label><input type="text" class="form-control" name="postal_code" required></div>
</div>
<div class="mb-3"><label class="form-label">آدرس کامل</label><textarea class="form-control" name="address_line" rows="2" required></textarea></div>
<div class="form-check mb-3"><input class="form-check-input" type="checkbox" name="is_default" id="is_default"><label class="form-check-label" for="is_default">انتخاب به عنوان آدرس پیش‌فرض</label></div>
<button type="submit" class="btn btn-success">ذخیره آدرس</button>
</form>
<hr>
</div>
<?php if (empty($addresses)): ?>
<div class="alert alert-secondary text-center">شما هنوز هیچ آدرسی ثبت نکرده‌اید.</div>
<p class="text-center text-muted">شما هنوز هیچ آدرسی ثبت نکرده‌اید.</p>
<?php else: ?>
<div class="address-list">
<?php foreach ($addresses as $address): ?>
<div class="card card-body mb-3 address-item">
<div class="address-content">
<p><?= htmlspecialchars(implode(', ', array_filter([$address['province'], $address['city'], $address['address_line'], $address['postal_code']]))) ?></p>
<?php if ($address['is_default']): ?>
<span class="badge bg-primary">پیش‌فرض</span>
<?php endif; ?>
<div class="d-flex justify-content-between align-items-center border-bottom py-2">
<div>
<p class="mb-0" style="color: var(--admin-text);"><?= htmlspecialchars(implode(', ', array_filter([$address['province'], $address['city'], $address['address_line'], "کدپستی: ".$address['postal_code']]))) ?></p>
<?php if ($address['is_default']): ?><span class="badge bg-primary">پیش‌فرض</span><?php endif; ?>
</div>
<div class="address-actions">
<form method="POST" class="d-inline">
<input type="hidden" name="action" value="delete_address">
<input type="hidden" name="address_id" value="<?= $address['id']; ?>">
<button type="submit" class="btn btn-sm btn-outline-danger" onclick="return confirm('آیا از حذف این آدرس مطمئن هستید؟');">حذف</button>
</form>
<div class="d-flex">
<?php if (!$address['is_default']): ?>
<form method="POST" class="d-inline">
<form method="POST" action="profile.php?page=addresses" class="ms-2">
<input type="hidden" name="action" value="set_default_address">
<input type="hidden" name="address_id" value="<?= $address['id']; ?>">
<button type="submit" class="btn btn-sm btn-outline-secondary">انتخاب به عنوان پیش‌فرض</button>
<button type="submit" class="btn btn-sm btn-outline-secondary">پیش‌فرض</button>
</form>
<?php endif; ?>
<form method="POST" action="profile.php?page=addresses" onsubmit="return confirm('آیا از حذف این آدرس مطمئن هستید؟');">
<input type="hidden" name="action" value="delete_address">
<input type="hidden" name="address_id" value="<?= $address['id']; ?>">
<button type="submit" class="btn btn-sm btn-outline-danger">حذف</button>
</form>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
</div>
<?php elseif ($page === 'account'): ?>
<div class="card">
<div class="card-header"><h4 class="m-0">جزئیات حساب</h4></div>
<div class="card-body">
<form id="account-details-form" method="POST">
<input type="hidden" name="action" value="update_details">
<p class="fs-6 text-muted">اطلاعات شخصی خود را اینجا ویرایش کنید.</p>
<div class="row">
<div class="col-md-6 mb-3">
<label for="first_name" class="form-label">نام</label>
<input type="text" class="form-control" id="first_name" name="first_name" value="<?= htmlspecialchars($user['first_name'] ?? ''); ?>" required>
</div>
<div class="col-md-6 mb-3">
<label for="last_name" class="form-label">نام خانوادگی</label>
<input type="text" class="form-control" id="last_name" name="last_name" value="<?= htmlspecialchars($user['last_name'] ?? ''); ?>" required>
</div>
</div>
<div class="mb-3">
<label for="email" class="form-label">آدرس ایمیل</label>
<input type="email" class="form-control" id="email" name="email" value="<?= htmlspecialchars($user['email'] ?? ''); ?>" required>
</div>
<div class="col-lg-6">
<div class="card">
<div class="card-header"><h4>جزئیات حساب</h4></div>
<div class="card-body">
<form method="POST" action="profile.php?page=account">
<input type="hidden" name="action" value="update_details">
<div class="mb-3"><label class="form-label">نام</label><input type="text" class="form-control" name="first_name" value="<?= htmlspecialchars($user['first_name'] ?? ''); ?>" required></div>
<div class="mb-3"><label class="form-label">نام خانوادگی</label><input type="text" class="form-control" name="last_name" value="<?= htmlspecialchars($user['last_name'] ?? ''); ?>" required></div>
<div class="mb-3"><label class="form-label">آدرس ایمیل</label><input type="email" class="form-control" name="email" value="<?= htmlspecialchars($user['email'] ?? ''); ?>" required></div>
<button type="submit" class="btn btn-primary">ذخیره تغییرات</button>
</form>
</div>
</div>
<div class="card mt-4">
<div class="card-header"><h4 class="m-0">تغییر رمز عبور</h4></div>
</div>
<div class="col-lg-6">
<div class="card">
<div class="card-header"><h4>تغییر رمز عبور</h4></div>
<div class="card-body">
<form id="password-form" method="POST">
<form method="POST" action="profile.php?page=account">
<input type="hidden" name="action" value="update_password">
<div class="mb-3">
<label for="new_password" class="form-label">رمز عبور جدید</label>
<input type="password" class="form-control" id="new_password" name="new_password" required>
</div>
<div class="mb-3">
<label for="confirm_password" class="form-label">تکرار رمز عبور جدید</label>
<input type="password" class="form-control" id="confirm_password" name="confirm_password" required>
</div>
<div class="mb-3"><label class="form-label">رمز عبور جدید</label><input type="password" class="form-control" name="new_password" required></div>
<div class="mb-3"><label class="form-label">تکرار رمز عبور جدید</label><input type="password" class="form-control" name="confirm_password" required></div>
<button type="submit" class="btn btn-primary">تغییر رمز عبور</button>
</form>
</div>
</div>
</div>
</div>
<?php else: ?>
<div class="alert alert-danger">صفحه مورد نظر یافت نشد.</div>
<?php endif; ?>
</div>
</div>
</div>
</section>
</main>
<!-- The Modal for Order Details -->
<div id="order-modal" class="order-modal">
<div class="order-modal-content">
<span class="order-modal-close-btn">&times;</span>
<div id="modal-body">
<!-- Order details will be injected here by JavaScript -->
</div>
</main>
</div>
</div>
<div class="sidebar-backdrop"></div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function () {
const modal = document.getElementById('order-modal');
const modalBody = document.getElementById('modal-body');
const closeBtn = document.querySelector('.order-modal-close-btn');
document.addEventListener('DOMContentLoaded', function() {
const sidebar = document.querySelector('.admin-sidebar');
const backdrop = document.querySelector('.sidebar-backdrop');
const sidebarToggle = document.getElementById('sidebar-toggle');
// Function to open modal and fetch order details
async function openOrderModal(trackingId) {
modalBody.innerHTML = `<div class="text-center p-5"><div class="spinner-border" role="status"><span class="visually-hidden">Loading...</span></div></div>`;
modal.style.display = 'block';
try {
const response = await fetch('api/get_order_details.php', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ tracking_id: trackingId }),
if (sidebarToggle) {
sidebarToggle.addEventListener('click', () => {
sidebar.classList.toggle('open');
backdrop.classList.toggle('show');
});
if (!response.ok) throw new Error(`Server error: ${response.status}`);
const data = await response.json();
if (data.success) {
displayOrderDetails(data.order, data.products);
} else {
modalBody.innerHTML = `<div class="alert alert-danger">${data.message}</div>`;
}
} catch (error) {
console.error('Fetch Error:', error);
modalBody.innerHTML = `<div class="alert alert-danger"><strong>خطا در ارتباط با سرور:</strong><br>${error.message}</div>`;
}
}
// Function to display fetched order details in the modal
function displayOrderDetails(order, products) {
let productsHtml = `
<div class="detail-box" style="grid-column: 1 / -1;">
<h3>محصولات سفارش</h3>
<div class="table-responsive">
<table class="products-table">
<thead>
<tr>
<th>محصول</th>
<th>تعداد</th>
<th>رنگ</th>
<th>قیمت واحد</th>
<th>قیمت کل</th>
</tr>
</thead>
<tbody>`;
products.forEach(p => {
productsHtml += `
<tr>
<td data-label="محصول"><img src="${p.image_url}" alt="${p.name}" class="me-2">${p.name}</td>
<td data-label="تعداد">${p.quantity}</td>
<td data-label="رنگ"><span class="cart-item-color-swatch" style="background-color: ${p.color || 'transparent'}"></span></td>
<td data-label="قیمت واحد">${parseInt(p.price).toLocaleString()} تومان</td>
<td data-label="قیمت کل">${(p.quantity * p.price).toLocaleString()} تومان</td>
</tr>`;
if (backdrop) {
backdrop.addEventListener('click', () => {
sidebar.classList.remove('open');
backdrop.classList.remove('show');
});
productsHtml += `</tbody></table></div></div>`;
const fullAddress = [order.billing_province, order.billing_city, order.billing_address, order.billing_postal_code].filter(Boolean).join(', ');
modalBody.innerHTML = `
<div class="order-modal-header">
<h2>جزئیات سفارش</h2>
<p class="text-muted">کد رهگیری: ${order.tracking_id}</p>
</div>
<div class="order-details-grid">
<div class="detail-box">
<h3>اطلاعات خریدار</h3>
<p><strong>نام:</strong> ${order.full_name}</p>
<p><strong>ایمیل:</strong> ${order.billing_email}</p>
<p><strong>تلفن:</strong> ${order.billing_phone}</p>
</div>
<div class="detail-box">
<h3>اطلاعات سفارش</h3>
<p><strong>وضعیت:</strong> <span class="order-status status-${order.status}">${order.status_jalali}</span></p>
<p><strong>تاریخ ثبت:</strong> ${order.created_at_jalali}</p>
<p><strong>آدرس:</strong> ${fullAddress}</p>
</div>
${productsHtml}
</div>
<div class="summary-totals mt-4 text-center">
<div class="grand-total">
<span class="label">جمع کل: </span>
<span class="value">${parseInt(order.total_amount).toLocaleString()} تومان</span>
</div>
</div>`;
}
// Add event listeners to all "View Details" buttons
const viewButtons = document.querySelectorAll('.view-order-btn');
viewButtons.forEach(button => {
button.addEventListener('click', function () {
const trackingId = this.getAttribute('data-tracking-id');
if (trackingId) {
openOrderModal(trackingId);
}
});
});
// Close modal logic
closeBtn.onclick = () => modal.style.display = 'none';
window.onclick = (event) => {
if (event.target == modal) {
modal.style.display = 'none';
}
};
});
</script>
<?php
require_once 'includes/footer.php';
?>
</body>
</html>

View File

@ -45,6 +45,9 @@ include 'includes/header.php';
<h4>وضعیت سفارش: <span id="modal-order-status-text" style="font-weight: bold;"></span></h4>
<div class="status-tracker" id="modal-status-tracker">
<div class="status-progress"></div>
<div class="status-step" data-status="placed">
<div class="dot"></div><span class="label">ثبت سفارش</span>
</div>
<div class="status-step" data-status="processing">
<div class="dot"></div><span class="label">در حال پردازش</span>
</div>
@ -52,10 +55,7 @@ include 'includes/header.php';
<div class="dot"></div><span class="label">ارسال شده</span>
</div>
<div class="status-step" data-status="completed">
<div class="dot"></div><span class="label">تکمیل شده</span>
</div>
<div class="status-step" data-status="cancelled">
<div class="dot"></div><span class="label">لغو شده</span>
<div class="dot"></div><span class="label">تحویل شده</span>
</div>
</div>
</div>
@ -71,10 +71,10 @@ include 'includes/header.php';
</div>
</div>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function () {
<script>
document.addEventListener('DOMContentLoaded', function () {
const form = document.getElementById('track-order-form');
const modal = document.getElementById('tracking-modal');
const overlay = document.querySelector('.modal-overlay');
@ -152,67 +152,88 @@ include 'includes/header.php';
}
function updateStatusTracker(status, statusPersian) {
console.log('--- Debugging Status Animation ---');
console.log('--- Debugging Status ---');
console.log('Received status:', status);
const statusTextEl = document.getElementById('modal-order-status-text');
const tracker = document.getElementById('modal-status-tracker');
const progress = tracker.querySelector('.status-progress');
const steps = Array.from(tracker.querySelectorAll('.status-step'));
const statusMap = {
'pending': 'processing',
// 1. Reset all dynamic styles and classes
steps.forEach(step => {
step.classList.remove('active', 'completed');
const dot = step.querySelector('.dot');
if (dot) dot.style.backgroundColor = ''; // Reset to default CSS color
});
tracker.classList.remove('is-cancelled');
progress.style.width = '0%';
progress.style.backgroundColor = ''; // Reset to default CSS color
// 2. Map API status to internal status keys
const statusKeyMap = {
'pending': 'placed',
'processing': 'processing',
'shipped': 'shipped',
'delivered': 'completed',
'completed': 'completed',
'cancelled': 'cancelled'
};
const mappedStatus = status ? statusMap[status.toLowerCase()] : 'processing';
const mappedStatus = status ? statusKeyMap[status.toLowerCase()] : 'placed';
// 3. Define display properties for each status, using CSS variables
const statusDisplayMap = {
'processing': { color: '#ffc107', text: 'در حال پردازش' },
'shipped': { color: '#0d6efd', text: 'ارسال شده' },
'completed': { color: '#198754', text: 'تکمیل شده' },
'cancelled': { color: '#dc3545', text: 'لغو شده' }
'placed': { text: 'ثبت شده', colorVar: '--status-default-dark', progress: '0%', stepIndex: 0 },
'processing': { text: 'در حال پردازش', colorVar: '--status-processing', progress: '33%', stepIndex: 1 },
'shipped': { text: 'ارسال شده', colorVar: '--status-shipped', progress: '66%', stepIndex: 2 },
'completed': { text: 'تحویل شده', colorVar: '--status-completed', progress: '100%', stepIndex: 3 },
'cancelled': { text: 'لغو شده', colorVar: '--status-cancelled', progress: '0%', stepIndex: -1 }
};
const displayInfo = statusDisplayMap[mappedStatus] || statusDisplayMap['processing'];
const displayInfo = statusDisplayMap[mappedStatus] || statusDisplayMap['placed'];
const currentStatusColor = `var(${displayInfo.colorVar})`;
const completedColor = `var(${statusDisplayMap['completed'].colorVar})`;
const cancelledColor = `var(${statusDisplayMap['cancelled'].colorVar})`;
console.log(`Mapped status: ${mappedStatus}, Index: ${displayInfo.stepIndex}`);
// 4. Update main status text color and content
statusTextEl.textContent = statusPersian || displayInfo.text;
statusTextEl.style.color = displayInfo.color;
const tracker = document.getElementById('modal-status-tracker');
tracker.className = 'status-tracker';
const progress = tracker.querySelector('.status-progress');
const steps = Array.from(tracker.querySelectorAll('.status-step'));
steps.forEach(step => step.classList.remove('active', 'completed'));
const statusOrder = ['processing', 'shipped', 'completed'];
let statusIndex = statusOrder.indexOf(mappedStatus);
console.log('Mapped status:', mappedStatus, '| Calculated status index:', statusIndex);
statusTextEl.style.color = currentStatusColor;
// 5. Handle the special 'cancelled' state
if (mappedStatus === 'cancelled') {
tracker.classList.add('is-cancelled');
const cancelledStep = tracker.querySelector('[data-status="cancelled"]');
if(cancelledStep) cancelledStep.classList.add('active');
progress.style.width = '0%';
progress.style.backgroundColor = cancelledColor;
progress.style.width = '100%';
steps.forEach(s => {
const dot = s.querySelector('.dot');
if (dot) dot.style.backgroundColor = cancelledColor;
});
} else {
tracker.classList.remove('is-cancelled');
if (statusIndex !== -1) {
for (let i = 0; i <= statusIndex; i++) {
const step = tracker.querySelector(`[data-status="${statusOrder[i]}"]`);
if(step) step.classList.add('completed');
// 6. Handle normal order progression
progress.style.backgroundColor = completedColor; // Progress bar is always green for consistency
setTimeout(() => {
progress.style.width = displayInfo.progress;
}, 100);
// Update step classes and dot colors
if (displayInfo.stepIndex >= 0) {
// Mark all past steps as completed (green)
for (let i = 0; i < displayInfo.stepIndex; i++) {
if (steps[i]) {
steps[i].classList.add('completed');
const dot = steps[i].querySelector('.dot');
if (dot) dot.style.backgroundColor = completedColor;
}
const activeStep = tracker.querySelector(`[data-status="${mappedStatus}"]`);
if(activeStep) {
activeStep.classList.remove('completed');
activeStep.classList.add('active');
}
const progressPercentage = statusIndex >= 0 ? (statusIndex / (statusOrder.length - 1)) * 100 : 0;
console.log('Progress percentage:', progressPercentage);
progress.style.width = `${progressPercentage}%`;
} else {
progress.style.width = '0%';
console.log('Unknown status. Resetting progress bar.');
// Mark current step as active (yellow, blue, or green)
if (steps[displayInfo.stepIndex]) {
steps[displayInfo.stepIndex].classList.add('active');
const dot = steps[displayInfo.stepIndex].querySelector('.dot');
if (dot) dot.style.backgroundColor = currentStatusColor;
}
}
}
}
@ -223,6 +244,6 @@ include 'includes/header.php';
closeBtn.addEventListener('click', closeModal);
overlay.addEventListener('click', closeModal);
});
</script>
});
</script>
<?php include 'includes/footer.php'; ?>