Files
gasemi_tier/admin/index.php
T

329 lines
18 KiB
PHP

<?php
// admin/index.php
require_once __DIR__ . '/../includes/db.php';
$message = '';
$error = '';
// Handle add / update tire
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$action = $_POST['admin_action'] ?? '';
if ($action === 'add_tire') {
$id = 'TR-' . (count(TireStore::getTires()) + 101);
$name = trim($_POST['name'] ?? '');
$brand = trim($_POST['brand'] ?? '');
$country = trim($_POST['country'] ?? '');
$category = trim($_POST['category'] ?? 'سواری');
$width = intval($_POST['width'] ?? 185);
$aspect = intval($_POST['aspect_ratio'] ?? 65);
$rim = intval($_POST['rim'] ?? 14);
$speed = trim($_POST['speed_index'] ?? 'H');
$load = trim($_POST['load_index'] ?? '86');
$price = intval($_POST['price'] ?? 0);
$stock = intval($_POST['stock'] ?? 10);
$warranty = intval($_POST['warranty_months'] ?? 36);
$vehicles = array_filter(array_map('trim', explode(',', $_POST['vehicles'] ?? '')));
$desc = trim($_POST['description'] ?? '');
if ($name && $brand && $price > 0) {
$newTire = [
"id" => $id,
"name" => $name,
"brand" => $brand,
"country" => $country,
"category" => $category,
"width" => $width,
"aspect_ratio" => $aspect,
"rim" => $rim,
"size_str" => "{$width}/{$aspect}R{$rim}",
"speed_index" => $speed,
"load_index" => $load,
"season" => "four_season",
"season_fa" => "چهار فصل",
"warranty_months" => $warranty,
"production_year" => "2026",
"fuel_efficiency" => "B",
"wet_grip" => "A",
"noise_level" => "69 dB",
"price" => $price,
"discount_percent" => 0,
"stock" => $stock,
"rating" => 5.0,
"reviews_count" => 1,
"vehicles" => $vehicles,
"description" => $desc,
"features" => ["تولید سال ۲۰۲۶ با گارانتی شرکتی", "ترکیب سیلیکایی با دوام بالا"],
"image" => "assets/images/tire_barez_p648.svg",
"is_featured" => false,
"is_best_seller" => false
];
TireStore::addTire($newTire);
$message = 'تایر جدید با موفقیت به انبار و کاتالوگ اضافه گردید.';
} else {
$error = 'لطفاً تمامی فیلدهای الزامی را پر کنید.';
}
}
if ($action === 'delete_tire') {
$delId = $_POST['tire_id'] ?? '';
if ($delId) {
TireStore::deleteTire($delId);
$message = "تایر با شناسه {$delId} حذف گردید.";
}
}
}
$tires = TireStore::getTires();
$consultations = TireStore::getConsultations();
?>
<!DOCTYPE html>
<html lang="fa" dir="rtl" class="dark">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>پنل مدیریت و انبارداری | تایر قاسمی</title>
<link href="https://fonts.googleapis.com/css2?family=Vazirmatn:wght@400;600;700;900&display=swap" rel="stylesheet">
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://unpkg.com/lucide@latest"></script>
<style>
* { font-family: 'Vazirmatn', sans-serif; }
</style>
</head>
<body class="bg-[#0b0f17] text-slate-100 min-h-screen">
<!-- Top Admin Bar -->
<header class="border-b border-slate-800 bg-slate-900/80 sticky top-0 z-40 backdrop-blur">
<div class="max-w-7xl mx-auto px-4 py-4 flex items-center justify-between">
<div class="flex items-center gap-3">
<div class="w-9 h-9 rounded-xl bg-brand-600 flex items-center justify-center text-white">
<i data-lucide="shield" class="w-5 h-5"></i>
</div>
<div>
<h1 class="text-base font-black text-white">داشبورد مدیریت تایر قاسمی</h1>
<p class="text-[10px] text-slate-400">انبارداری، استعلام‌ها و کاتالوگ محصولات</p>
</div>
</div>
<div class="flex items-center gap-3">
<a href="../index.php" class="px-3.5 py-1.5 rounded-xl bg-slate-800 hover:bg-slate-700 text-xs font-bold text-slate-300 flex items-center gap-1.5">
<i data-lucide="external-link" class="w-3.5 h-3.5"></i>
مشاهده سایت
</a>
</div>
</div>
</header>
<main class="max-w-7xl mx-auto px-4 py-8 space-y-8">
<?php if ($message): ?>
<div class="p-4 rounded-2xl bg-emerald-500/20 border border-emerald-500/30 text-emerald-300 text-xs font-bold flex items-center gap-2">
<i data-lucide="check-circle" class="w-4 h-4"></i> <?= htmlspecialchars($message) ?>
</div>
<?php endif; ?>
<?php if ($error): ?>
<div class="p-4 rounded-2xl bg-rose-500/20 border border-rose-500/30 text-rose-300 text-xs font-bold flex items-center gap-2">
<i data-lucide="alert-circle" class="w-4 h-4"></i> <?= htmlspecialchars($error) ?>
</div>
<?php endif; ?>
<!-- Stats Overview Cards -->
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4">
<div class="p-5 rounded-2xl bg-slate-900 border border-slate-800">
<span class="text-xs text-slate-400">تنوع کل تایرها در انبار</span>
<div class="text-2xl font-black text-white mt-1"><?= count($tires) ?> <span class="text-xs text-slate-500 font-normal">مدل</span></div>
</div>
<div class="p-5 rounded-2xl bg-slate-900 border border-slate-800">
<span class="text-xs text-slate-400">مجموع موجودی حلقه‌ها</span>
<div class="text-2xl font-black text-amber-400 mt-1"><?= array_sum(array_column($tires, 'stock')) ?> <span class="text-xs text-slate-500 font-normal">حلقه</span></div>
</div>
<div class="p-5 rounded-2xl bg-slate-900 border border-slate-800">
<span class="text-xs text-slate-400">درخواست‌های مشاوره و استعلام</span>
<div class="text-2xl font-black text-emerald-400 mt-1"><?= count($consultations) ?> <span class="text-xs text-slate-500 font-normal">مورد</span></div>
</div>
<div class="p-5 rounded-2xl bg-slate-900 border border-slate-800">
<span class="text-xs text-slate-400">وضعیت سرور و اتصال گیت</span>
<div class="text-sm font-bold text-cyan-400 mt-2 flex items-center gap-1.5">
<span class="w-2 h-2 rounded-full bg-emerald-400 animate-pulse"></span> آنلاین و فعال
</div>
</div>
</div>
<!-- Add New Tire Form Accordion -->
<div class="p-6 rounded-3xl bg-slate-900 border border-slate-800 space-y-4">
<h2 class="text-base font-black text-white flex items-center gap-2">
<i data-lucide="plus-circle" class="w-5 h-5 text-brand-400"></i>
افزودن تایر جدید به انبار و کاتالوگ
</h2>
<form method="POST" class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4 text-xs">
<input type="hidden" name="admin_action" value="add_tire">
<div>
<label class="block font-bold text-slate-300 mb-1">نام و مدل تایر *</label>
<input type="text" name="name" required placeholder="مثلاً: بارز پریمیوم P660" class="w-full bg-slate-950 border border-slate-800 rounded-xl px-3 py-2 text-white">
</div>
<div>
<label class="block font-bold text-slate-300 mb-1">برند سازنده *</label>
<input type="text" name="brand" required placeholder="بارز، کویر، هانکوک..." class="w-full bg-slate-950 border border-slate-800 rounded-xl px-3 py-2 text-white">
</div>
<div>
<label class="block font-bold text-slate-300 mb-1">کشور سازنده</label>
<input type="text" name="country" placeholder="ایران، کره جنوبی، فرانسه..." class="w-full bg-slate-950 border border-slate-800 rounded-xl px-3 py-2 text-white">
</div>
<div>
<label class="block font-bold text-slate-300 mb-1">دسته‌بندی</label>
<select name="category" class="w-full bg-slate-950 border border-slate-800 rounded-xl px-3 py-2 text-white">
<option value="سواری">سواری شهری</option>
<option value="اسپرت">اسپرت و ریسینگ</option>
<option value="شاسی بلند و آفرود (SUV/4x4)">شاسی بلند و آفرود (SUV/4x4)</option>
<option value="لوکس و پرمیوم">لوکس و پرمیوم</option>
</select>
</div>
<div>
<label class="block font-bold text-slate-300 mb-1">پهنا (Width - mm)</label>
<input type="number" name="width" value="205" class="w-full bg-slate-950 border border-slate-800 rounded-xl px-3 py-2 text-white">
</div>
<div>
<label class="block font-bold text-slate-300 mb-1">نسبت فاق (Aspect - %)</label>
<input type="number" name="aspect_ratio" value="55" class="w-full bg-slate-950 border border-slate-800 rounded-xl px-3 py-2 text-white">
</div>
<div>
<label class="block font-bold text-slate-300 mb-1">قطر رینگ (Rim - اینچ)</label>
<input type="number" name="rim" value="16" class="w-full bg-slate-950 border border-slate-800 rounded-xl px-3 py-2 text-white">
</div>
<div>
<label class="block font-bold text-slate-300 mb-1">قیمت هر حلقه (تومان) *</label>
<input type="number" name="price" required placeholder="5500000" class="w-full bg-slate-950 border border-slate-800 rounded-xl px-3 py-2 text-white">
</div>
<div>
<label class="block font-bold text-slate-300 mb-1">موجودی انبار (حلقه)</label>
<input type="number" name="stock" value="20" class="w-full bg-slate-950 border border-slate-800 rounded-xl px-3 py-2 text-white">
</div>
<div>
<label class="block font-bold text-slate-300 mb-1">گارانتی (ماه)</label>
<input type="number" name="warranty_months" value="36" class="w-full bg-slate-950 border border-slate-800 rounded-xl px-3 py-2 text-white">
</div>
<div class="sm:col-span-2">
<label class="block font-bold text-slate-300 mb-1">خودروهای سازگار (با کاما جدا کنید)</label>
<input type="text" name="vehicles" placeholder="دنا پلاس, تارا, شاهین, مگان" class="w-full bg-slate-950 border border-slate-800 rounded-xl px-3 py-2 text-white">
</div>
<div class="sm:col-span-4">
<label class="block font-bold text-slate-300 mb-1">توضیحات فنی و کاربرد</label>
<input type="text" name="description" placeholder="توضیح کوتاه درباره کارایی و چسبندگی تایر..." class="w-full bg-slate-950 border border-slate-800 rounded-xl px-3 py-2 text-white">
</div>
<div class="sm:col-span-4 pt-2">
<button type="submit" class="px-6 py-2.5 rounded-xl bg-emerald-600 hover:bg-emerald-500 text-white font-bold transition-all shadow">
افزودن و انتشار در کاتالوگ
</button>
</div>
</form>
</div>
<!-- Tire Inventory Table -->
<div class="p-6 rounded-3xl bg-slate-900 border border-slate-800 space-y-4">
<h2 class="text-base font-black text-white flex items-center gap-2">
<i data-lucide="database" class="w-5 h-5 text-amber-400"></i>
مدیریت موجودی و قیمت تایرها
</h2>
<div class="overflow-x-auto">
<table class="w-full text-right text-xs">
<thead>
<tr class="border-b border-slate-800 text-slate-400">
<th class="p-3">کد</th>
<th class="p-3">نام و مدل تایر</th>
<th class="p-3">برند</th>
<th class="p-3">سایز</th>
<th class="p-3">قیمت مصوب</th>
<th class="p-3">موجودی</th>
<th class="p-3">گارانتی</th>
<th class="p-3 text-center">عملیات</th>
</tr>
</thead>
<tbody class="divide-y divide-slate-800/60 text-slate-200">
<?php foreach ($tires as $t): ?>
<tr class="hover:bg-slate-800/30">
<td class="p-3 font-mono text-slate-400"><?= $t['id'] ?></td>
<td class="p-3 font-bold text-white"><?= htmlspecialchars($t['name']) ?></td>
<td class="p-3 text-brand-400 font-medium"><?= htmlspecialchars($t['brand']) ?></td>
<td class="p-3"><span class="px-2 py-0.5 rounded bg-slate-800"><?= $t['size_str'] ?></span></td>
<td class="p-3 font-bold"><?= number_format($t['price']) ?> تومان</td>
<td class="p-3"><span class="px-2 py-0.5 rounded <?= $t['stock'] > 10 ? 'bg-emerald-500/20 text-emerald-400' : 'bg-rose-500/20 text-rose-400' ?>"><?= $t['stock'] ?> حلقه</span></td>
<td class="p-3"><?= $t['warranty_months'] ?> ماه</td>
<td class="p-3 text-center">
<form method="POST" onsubmit="return confirm('آیا از حذف این تایر مطمئن هستید؟');" class="inline">
<input type="hidden" name="admin_action" value="delete_tire">
<input type="hidden" name="tire_id" value="<?= $t['id'] ?>">
<button type="submit" class="p-1.5 rounded-lg bg-rose-500/10 hover:bg-rose-500/30 text-rose-400 transition-colors" title="حذف تایر">
<i data-lucide="trash-2" class="w-4 h-4"></i>
</button>
</form>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
<!-- Inquiries / Consultations Table -->
<div class="p-6 rounded-3xl bg-slate-900 border border-slate-800 space-y-4">
<h2 class="text-base font-black text-white flex items-center gap-2">
<i data-lucide="headset" class="w-5 h-5 text-emerald-400"></i>
درخواست‌های استعلام قیمت و مشاوره کاربران
</h2>
<div class="overflow-x-auto">
<table class="w-full text-right text-xs">
<thead>
<tr class="border-b border-slate-800 text-slate-400">
<th class="p-3">کد</th>
<th class="p-3">نام مشتری</th>
<th class="p-3">شماره تماس</th>
<th class="p-3">خودرو</th>
<th class="p-3">متن پیام</th>
<th class="p-3">تاریخ ثبت</th>
<th class="p-3">وضعیت</th>
</tr>
</thead>
<tbody class="divide-y divide-slate-800/60 text-slate-200">
<?php foreach ($consultations as $c): ?>
<tr class="hover:bg-slate-800/30">
<td class="p-3 font-mono text-slate-400"><?= $c['id'] ?></td>
<td class="p-3 font-bold text-white"><?= htmlspecialchars($c['name']) ?></td>
<td class="p-3 font-mono text-brand-400"><?= htmlspecialchars($c['phone']) ?></td>
<td class="p-3 text-slate-300"><?= htmlspecialchars($c['car'] ?: '-') ?></td>
<td class="p-3 text-slate-400 max-w-xs truncate"><?= htmlspecialchars($c['message'] ?: '-') ?></td>
<td class="p-3 text-slate-500"><?= htmlspecialchars($c['created_at']) ?></td>
<td class="p-3"><span class="px-2 py-0.5 rounded bg-emerald-500/20 text-emerald-400 font-bold"><?= htmlspecialchars($c['status']) ?></span></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</main>
<script>
lucide.createIcons();
</script>
</body>
</html>