131 lines
5.1 KiB
PHP
131 lines
5.1 KiB
PHP
<?php
|
||
require_once 'header.php';
|
||
|
||
// Oturumun başlatıldığından emin olalım (header.php içinde zaten olabilir, ama burada garantiye alalım)
|
||
if (session_status() === PHP_SESSION_NONE) {
|
||
session_start();
|
||
}
|
||
|
||
// 1. Erişim Kontrolü: Kullanıcı giriş yapmamışsa veya rolü 'admin' değilse, ana sayfaya yönlendir.
|
||
if (!isset($_SESSION['loggedin']) || $_SESSION['role'] !== 'admin') {
|
||
header('Location: /index.php');
|
||
exit;
|
||
}
|
||
|
||
require_once 'db/config.php';
|
||
|
||
$users = [];
|
||
$requests = [];
|
||
$error_message = '';
|
||
|
||
try {
|
||
$pdo = db();
|
||
// 2. Veritabanından tüm kullanıcıları çek
|
||
$stmt_users = $pdo->query('SELECT id, name, surname, email, role, created_at FROM users ORDER BY created_at DESC');
|
||
$users = $stmt_users->fetchAll(PDO::FETCH_ASSOC);
|
||
|
||
// 3. Veritabanından tüm influencer isteklerini çek
|
||
$stmt_requests = $pdo->query('
|
||
SELECT
|
||
ir.id, ir.client_name, ir.client_surname, ir.client_phone, ir.message, ir.status, ir.created_at,
|
||
u.name as influencer_name, u.surname as influencer_surname
|
||
FROM influencer_requests ir
|
||
JOIN users u ON ir.influencer_user_id = u.id
|
||
ORDER BY ir.created_at DESC
|
||
');
|
||
$requests = $stmt_requests->fetchAll(PDO::FETCH_ASSOC);
|
||
|
||
} catch (PDOException $e) {
|
||
// Geliştirme aşamasında hatayı görmek faydalı olabilir
|
||
$error_message = "Veritabanı hatası: " . $e->getMessage();
|
||
}
|
||
|
||
?>
|
||
|
||
<div class="container mt-5">
|
||
|
||
<?php if ($error_message): ?>
|
||
<div class="alert alert-danger">
|
||
<p><?php echo htmlspecialchars($error_message); ?></p>
|
||
</div>
|
||
<?php endif; ?>
|
||
|
||
<div class="mb-5">
|
||
<h2>Influencer Talepleri</h2>
|
||
<p>İşletmelerden gelen en son talepler.</p>
|
||
<div class="table-responsive">
|
||
<table class="table table-striped">
|
||
<thead>
|
||
<tr>
|
||
<th>ID</th>
|
||
<th>Talep Eden</th>
|
||
<th>Telefon</th>
|
||
<th>Influencer</th>
|
||
<th>Durum</th>
|
||
<th>Tarih</th>
|
||
<th>Mesaj</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<?php if (empty($requests)): ?>
|
||
<tr>
|
||
<td colspan="7">Henüz hiç talep gelmemiş.</td>
|
||
</tr>
|
||
<?php else: ?>
|
||
<?php foreach ($requests as $request): ?>
|
||
<tr>
|
||
<td><?php echo htmlspecialchars($request['id']); ?></td>
|
||
<td><?php echo htmlspecialchars($request['client_name'] . ' ' . $request['client_surname']); ?></td>
|
||
<td><?php echo htmlspecialchars($request['client_phone']); ?></td>
|
||
<td><?php echo htmlspecialchars($request['influencer_name'] . ' ' . $request['influencer_surname']); ?></td>
|
||
<td><span class="badge bg-primary"><?php echo htmlspecialchars($request['status']); ?></span></td>
|
||
<td><?php echo htmlspecialchars(date("d.m.Y H:i", strtotime($request['created_at']))); ?></td>
|
||
<td><?php echo htmlspecialchars($request['message']); ?></td>
|
||
</tr>
|
||
<?php endforeach; ?>
|
||
<?php endif; ?>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="mb-5">
|
||
<h2>Kullanıcı Yönetimi</h2>
|
||
<p>Sisteme kayıtlı tüm kullanıcıların listesi.</p>
|
||
<div class="table-responsive">
|
||
<table class="table table-striped">
|
||
<thead>
|
||
<tr>
|
||
<th>ID</th>
|
||
<th>Ad</th>
|
||
<th>Soyad</th>
|
||
<th>E-posta</th>
|
||
<th>Rol</th>
|
||
<th>Kayıt Tarihi</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<?php if (empty($users)): ?>
|
||
<tr>
|
||
<td colspan="6">Sistemde hiç kullanıcı bulunamadı.</td>
|
||
</tr>
|
||
<?php else: ?>
|
||
<?php foreach ($users as $user): ?>
|
||
<tr>
|
||
<td><?php echo htmlspecialchars($user['id']); ?></td>
|
||
<td><?php echo htmlspecialchars($user['name']); ?></td>
|
||
<td><?php echo htmlspecialchars($user['surname']); ?></td>
|
||
<td><?php echo htmlspecialchars($user['email']); ?></td>
|
||
<td><?php echo htmlspecialchars($user['role']); ?></td>
|
||
<td><?php echo htmlspecialchars(date("d.m.Y H:i", strtotime($user['created_at']))); ?></td>
|
||
</tr>
|
||
<?php endforeach; ?>
|
||
<?php endif; ?>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<?php require_once 'footer.php'; ?>
|