| <?php |
| session_start(); |
| if (!isset($_SESSION['logged_in']) || $_SESSION['logged_in'] !== true || $_SESSION['user_type'] !== 'admin') { |
| header('Location: ../../index.php'); |
| exit; |
| } |
|
|
| require_once '../api/agent-functions.php'; |
|
|
| |
| if ($_SERVER['REQUEST_METHOD'] === 'POST') { |
| if (isset($_POST['action'])) { |
| if ($_POST['action'] === 'review_agent') { |
| $agentId = $_POST['agent_id']; |
| $status = $_POST['status']; |
| $notes = $_POST['notes'] ?? ''; |
| |
| if (reviewAgentApplication($agentId, $_SESSION['user_id'], $status, $notes)) { |
| $message = "Agent application " . ($status === 'approved' ? 'approved' : 'rejected') . " successfully!"; |
| } else { |
| $error = "Failed to update agent application."; |
| } |
| } elseif ($_POST['action'] === 'review_advertisement') { |
| $adId = $_POST['advertisement_id']; |
| $status = $_POST['status']; |
| $notes = $_POST['notes'] ?? ''; |
| |
| if (reviewAdvertisement($adId, $_SESSION['user_id'], $status, $notes)) { |
| $message = "Advertisement " . ($status === 'approved' ? 'approved' : 'rejected') . " successfully!"; |
| } else { |
| $error = "Failed to update advertisement."; |
| } |
| } |
| } |
| } |
|
|
| |
| $pendingAgents = getPendingAgents(0); |
| $pendingAds = getAdvertisementsForApproval('pending'); |
| $adStats = getAdvertisementStats(); |
| ?> |
|
|
| <!DOCTYPE html> |
| <html lang="en"> |
| <head> |
| <meta charset="UTF-8"> |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| <title>Admin - Approval System</title> |
| <script src="https://cdn.tailwindcss.com"></script> |
| <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600;700;800&display=swap" rel="stylesheet"> |
| <script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script> |
| </head> |
| <body class="bg-gray-100 font-sans"> |
| <div class="container mx-auto p-4"> |
| <h1 class="text-3xl font-bold mb-6">Admin Approval System</h1> |
| |
| <?php if (isset($message)): ?> |
| <div class="bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded mb-4"> |
| <?php echo $message; ?> |
| </div> |
| <?php endif; ?> |
| |
| <?php if (isset($error)): ?> |
| <div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded mb-4"> |
| <?php echo $error; ?> |
| </div> |
| <?php endif; ?> |
| |
| <!-- Statistics --> |
| <div class="grid grid-cols-1 md:grid-cols-4 gap-4 mb-6"> |
| <div class="bg-white p-4 rounded shadow"> |
| <h3 class="font-bold">Pending Agents</h3> |
| <p class="text-2xl"><?php echo count($pendingAgents); ?></p> |
| </div> |
| <div class="bg-white p-4 rounded shadow"> |
| <h3 class="font-bold">Pending Ads</h3> |
| <p class="text-2xl"><?php echo count($pendingAds); ?></p> |
| </div> |
| <div class="bg-white p-4 rounded shadow"> |
| <h3 class="font-bold">Total Revenue</h3> |
| <p class="text-2xl">KES <?php echo number_format($adStats['total_revenue'], 2); ?></p> |
| </div> |
| <div class="bg-white p-4 rounded shadow"> |
| <h3 class="font-bold">Pending Revenue</h3> |
| <p class="text-2xl">KES <?php echo number_format($adStats['pending_revenue'], 2); ?></p> |
| </div> |
| </div> |
| |
| <!-- Pending Advertisements --> |
| <div class="bg-white rounded shadow mb-6"> |
| <div class="p-4 border-b"> |
| <h2 class="text-xl font-bold">Pending Advertisements</h2> |
| </div> |
| <div class="p-4"> |
| <?php if (empty($pendingAds)): ?> |
| <p class="text-gray-500">No pending advertisements</p> |
| <?php else: ?> |
| <?php foreach ($pendingAds as $ad): ?> |
| <div class="border rounded p-4 mb-4"> |
| <div class="flex justify-between items-start"> |
| <div> |
| <h3 class="font-bold"><?php echo htmlspecialchars($ad['title']); ?></h3> |
| <p class="text-gray-600">By: <?php echo htmlspecialchars($ad['advertiser_name']); ?></p> |
| <p class="text-gray-600">Budget: KES <?php echo number_format($ad['budget'], 2); ?></p> |
| <p class="text-gray-600">Platform: <?php echo ucfirst($ad['target_platform']); ?></p> |
| <?php if ($ad['agent_name']): ?> |
| <p class="text-gray-600">Agent: <?php echo htmlspecialchars($ad['agent_name']); ?></p> |
| <?php endif; ?> |
| </div> |
| <div class="flex gap-2"> |
| <button onclick="reviewAd(<?php echo $ad['id']; ?>, 'approved')" |
| class="bg-green-500 text-white px-3 py-1 rounded">Approve</button> |
| <button onclick="reviewAd(<?php echo $ad['id']; ?>, 'rejected')" |
| class="bg-red-500 text-white px-3 py-1 rounded">Reject</button> |
| </div> |
| </div> |
| </div> |
| <?php endforeach; ?> |
| <?php endif; ?> |
| </div> |
| </div> |
| |
| <!-- Pending Agents --> |
| <div class="bg-white rounded shadow"> |
| <div class="p-4 border-b"> |
| <h2 class="text-xl font-bold">Pending Agent Applications</h2> |
| </div> |
| <div class="p-4"> |
| <?php if (empty($pendingAgents)): ?> |
| <p class="text-gray-500">No pending agent applications</p> |
| <?php else: ?> |
| <?php foreach ($pendingAgents as $agent): ?> |
| <div class="border rounded p-4 mb-4"> |
| <div class="flex justify-between items-start"> |
| <div> |
| <h3 class="font-bold"><?php echo htmlspecialchars($agent['full_name']); ?></h3> |
| <p class="text-gray-600">Phone: <?php echo htmlspecialchars($agent['phone']); ?></p> |
| <p class="text-gray-600">Location: <?php echo htmlspecialchars($agent['location']); ?></p> |
| <p class="text-gray-600">Sponsor: <?php echo htmlspecialchars($agent['username']); ?></p> |
| </div> |
| <div class="flex gap-2"> |
| <button onclick="reviewAgent(<?php echo $agent['id']; ?>, 'approved')" |
| class="bg-green-500 text-white px-3 py-1 rounded">Approve</button> |
| <button onclick="reviewAgent(<?php echo $agent['id']; ?>, 'rejected')" |
| class="bg-red-500 text-white px-3 py-1 rounded">Reject</button> |
| </div> |
| </div> |
| </div> |
| <?php endforeach; ?> |
| <?php endif; ?> |
| </div> |
| </div> |
| </div> |
| |
| <!-- Review Forms --> |
| <form id="agent-review-form" method="POST" class="hidden"> |
| <input type="hidden" name="action" value="review_agent"> |
| <input type="hidden" id="agent-id" name="agent_id"> |
| <input type="hidden" id="agent-status" name="status"> |
| <textarea id="agent-notes" name="notes" placeholder="Review notes..."></textarea> |
| </form> |
| |
| <form id="ad-review-form" method="POST" class="hidden"> |
| <input type="hidden" name="action" value="review_advertisement"> |
| <input type="hidden" id="ad-id" name="advertisement_id"> |
| <input type="hidden" id="ad-status" name="status"> |
| <textarea id="ad-notes" name="notes" placeholder="Review notes..."></textarea> |
| </form> |
| |
| <script> |
| function reviewAgent(agentId, status) { |
| if (confirm(`Are you sure you want to ${status} this agent application?`)) { |
| document.getElementById('agent-id').value = agentId; |
| document.getElementById('agent-status').value = status; |
| document.getElementById('agent-review-form').submit(); |
| } |
| } |
|
|
| function reviewAd(adId, status) { |
| if (confirm(`Are you sure you want to ${status} this advertisement?`)) { |
| document.getElementById('ad-id').value = adId; |
| document.getElementById('ad-status').value = status; |
| document.getElementById('ad-review-form').submit(); |
| } |
| } |
|
|
| feather.replace(); |
| </script> |
| </body> |
| </html> |