prepare("SELECT affiliate_code FROM affiliates WHERE id = ?"); $stmt->execute([$delete_id]); $affiliate_code = $stmt->fetchColumn(); // Delete affiliate (cascade will delete attachments and signups) $stmt = $pdo->prepare("DELETE FROM affiliates WHERE id = ?"); $stmt->execute([$delete_id]); logActivity($_SESSION['admin_id'], 'delete_affiliate', "Deleted affiliate: $affiliate_code", 'affiliate', $delete_id); $success = 'Affiliate deleted successfully!'; } catch (Exception $e) { $error = 'An error occurred while deleting. Please try again.'; error_log("Delete affiliate error: " . $e->getMessage()); } } } } // Fetch all affiliates try { $pdo = getDBConnection(); $stmt = $pdo->query("SELECT * FROM affiliates ORDER BY created_at DESC"); $affiliates = $stmt->fetchAll(); } catch (Exception $e) { $affiliates = []; error_log("Fetch affiliates error: " . $e->getMessage()); } // Calculate statistics $total_affiliates = count($affiliates); $active_affiliates = count(array_filter($affiliates, fn($a) => $a['status'] === 'active')); $total_signups = array_sum(array_column($affiliates, 'total_signups')); $verified_signups = array_sum(array_column($affiliates, 'total_verified_signups')); $company_affiliates = count(array_filter($affiliates, fn($a) => $a['type'] === 'company')); $individual_affiliates = count(array_filter($affiliates, fn($a) => $a['type'] === 'individual')); include 'includes/header.php'; ?>
Manage affiliate partners and track signups
| ID | Affiliate Code | Company/Name | Type | In-charge | Location | Contact | Signups | Verified | Status | Actions |
|---|---|---|---|---|---|---|---|---|---|---|
| No affiliates found. Click "Add New Affiliate" to create one. | ||||||||||
| # |
-
|
|||||||||