File: /home/h278792/public_html/disc/customer.php
<?php
require 'config.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$phone = $_POST['phone'];
$stmt = $pdo->prepare("SELECT * FROM discounts WHERE phone = ?");
$stmt->execute([$phone]);
$customer = $stmt->fetch();
if (!$customer) {
$error = "مشتری با این شماره موبایل یافت نشد!";
} else {
$_SESSION['customer_id'] = $customer['id'];
header("Location: customer.php");
exit;
}
}
if (!isset($_SESSION['customer_id'])) {
// فرم ورود
?>
<!DOCTYPE html>
<html lang="fa" dir="rtl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ورود به پنل مشتری</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
</head>
<body class="bg-gradient-to-br from-gray-100 to-gray-200 min-h-screen flex items-center justify-center">
<div class="max-w-md mx-auto bg-white rounded-2xl shadow-2xl p-8">
<h2 class="text-2xl font-bold mb-6 text-center">ورود به پنل مشتری</h2>
<?php if (isset($error)): ?>
<div class="bg-red-100 border-r-4 border-red-500 text-red-700 p-4 mb-6 rounded-lg">
<?= $error ?>
</div>
<?php endif; ?>
<form method="POST" class="space-y-6">
<div>
<label for="phone" class="block text-sm font-medium text-gray-700 mb-2">شماره موبایل</label>
<div class="flex items-center">
<span class="inline-flex items-center px-3 bg-gradient-to-r from-purple-600 to-indigo-600 text-white rounded-r-lg">
<i class="bi bi-phone-fill"></i>
</span>
<input type="tel" id="phone" name="phone" class="w-full p-3 border border-gray-300 rounded-l-lg focus:ring-2 focus:ring-purple-600 focus:border-transparent" placeholder="مثال: 09123456789" required>
</div>
</div>
<button type="submit" class="w-full bg-gradient-to-r from-purple-600 to-indigo-600 text-white py-3 rounded-lg font-semibold hover:from-purple-700 hover:to-indigo-700 transition-all duration-300 shadow-lg">
<i class="bi bi-box-arrow-in-left ml-2"></i> ورود
</button>
</form>
</div>
</body>
</html>
<?php
exit;
}
// دریافت اطلاعات مشتری
$customer_id = $_SESSION['customer_id'];
$stmt = $pdo->prepare("SELECT * FROM discounts WHERE id = ?");
$stmt->execute([$customer_id]);
$customer = $stmt->fetch();
// دریافت امتیازات
$stmt = $pdo->prepare("SELECT SUM(points) as total_points FROM points WHERE customer_id = ?");
$stmt->execute([$customer_id]);
$points = $stmt->fetch()['total_points'];
// دریافت ارجاعات
$stmt = $pdo->prepare("SELECT * FROM referrals WHERE referrer_id = ?");
$stmt->execute([$customer_id]);
$referrals = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html lang="fa" dir="rtl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>پنل مشتری</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
</head>
<body class="bg-gradient-to-br from-gray-100 to-gray-200 min-h-screen">
<div class="container mx-auto px-4 py-8">
<div class="flex justify-between items-center mb-8">
<h2 class="text-3xl font-bold">پنل مشتری: <?= htmlspecialchars($customer['full_name']) ?></h2>
<a href="customer.php?logout=1" class="bg-red-600 text-white px-4 py-2 rounded-lg hover:bg-red-700">
<i class="bi bi-box-arrow-left ml-2"></i> خروج
</a>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
<div class="bg-white rounded-2xl shadow-xl p-6">
<h3 class="text-xl font-semibold mb-4">اطلاعات کد تخفیف</h3>
<div class="space-y-4">
<p><strong>کد تخفیف:</strong> <?= htmlspecialchars($customer['discount_code']) ?></p>
<p><strong>اعتبار تا:</strong> <?= gregorianToJalali($customer['expires_at']) ?></p>
<p><strong>کد ارجاع شما:</strong> <?= htmlspecialchars($customer['referral_code']) ?></p>
</div>
</div>
<div class="bg-white rounded-2xl shadow-xl p-6">
<h3 class="text-xl font-semibold mb-4">امتیازات شما</h3>
<p class="text-3xl font-bold text-purple-600"><?= $points ?> امتیاز</p>
<p class="text-sm text-gray-600 mt-2">هر 100 امتیاز = 5% تخفیف اضافی</p>
</div>
</div>
<div class="bg-white rounded-2xl shadow-xl p-6 mt-6">
<h3 class="text-xl font-semibold mb-4">ارجاعات شما</h3>
<div class="overflow-x-auto">
<table class="w-full table-auto">
<thead>
<tr class="bg-purple-600 text-white">
<th class="p-3">شماره موبایل</th>
<th class="p-3">کد ارجاع</th>
<th class="p-3">وضعیت</th>
</tr>
</thead>
<tbody>
<?php foreach ($referrals as $referral): ?>
<tr class="border-b">
<td class="p-3"><?= htmlspecialchars($referral['referred_phone']) ?></td>
<td class="p-3"><?= htmlspecialchars($referral['referral_code']) ?></td>
<td class="p-3">
<span class="px-2 py-1 roundedjohn rounded text-sm <?= $referral['status'] == 'completed' ? 'bg-green-100 text-green-800' : 'bg-yellow-100 text-yellow-800' ?>">
<?= $referral['status'] == 'completed' ? 'تکمیل شده' : 'در انتظار' ?>
</span>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>