35049-vm/analyst_dashboard.php
Flatlogic Bot 119d467b75 v2.0
2025-10-19 03:32:56 +00:00

192 lines
9.6 KiB
PHP

<?php
require_once __DIR__ . '/db/config.php';
// Fetch submissions
try {
$pdo = db();
$stmt = $pdo->query("SELECT * FROM submissions ORDER BY created_at DESC");
$submissions = $stmt->fetchAll();
} catch (PDOException $e) {
$submissions = [];
// In a real app, log this error to a file or service
// error_log($e->getMessage());
}
// Handle notifications from query parameters
$notification = null;
if (isset($_GET['success'])) {
$count = (int)$_GET['success'];
$notification = [
'type' => 'success',
'message' => "Successfully imported {$count} records from the CSV."
];
} elseif (isset($_GET['error'])) {
$notification = [
'type' => 'danger',
'message' => "An error occurred: " . htmlspecialchars($_GET['error'])
];
} elseif (isset($_GET['refreshed'])) {
$notification = [
'type' => 'info',
'message' => "Submission has been queued for refresh."
];
}
// Helper to determine badge color based on status
function get_status_badge_class($status) {
switch (strtolower($status)) {
case 'completed':
return 'bg-success-subtle text-success-emphasis';
case 'processing':
return 'bg-primary-subtle text-primary-emphasis';
case 'error':
return 'bg-danger-subtle text-danger-emphasis';
case 'pending':
default:
return 'bg-secondary-subtle text-secondary-emphasis';
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Analyst Dashboard</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-white shadow-sm">
<div class="container-fluid">
<a class="navbar-brand" href="index.php">
<i class="bi bi-person-bounding-box text-primary"></i>
Lead Enricher
</a>
<div class="collapse navbar-collapse">
<ul class="navbar-nav ms-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link" href="index.php">Home</a>
</li>
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="analyst_dashboard.php">Dashboard</a>
</li>
</ul>
</div>
</div>
</nav>
<main class="container mt-5">
<?php if ($notification): ?>
<div class="alert alert-<?= $notification['type'] ?> alert-dismissible fade show" role="alert">
<?= $notification['message'] ?>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<?php endif; ?>
<div class="d-flex justify-content-between align-items-center mb-4">
<h1 class="h2">Analyst Dashboard</h1>
<div class="d-flex gap-2">
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#uploadCsvModal">
<i class="bi bi-upload me-2"></i>Upload CSV
</button>
<a href="worker.php" class="btn btn-outline-secondary" onclick="this.innerHTML = '<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span> Refreshing...';">
<i class="bi bi-arrow-clockwise me-2"></i>Refresh All
</a>
</div>
</div>
<div class="card border-0 shadow-sm">
<div class="card-body">
<div class="table-responsive">
<table class="table table-hover align-middle">
<thead class="table-light">
<tr>
<th scope="col">Name</th>
<th scope="col">Company</th>
<th scope="col">Location</th>
<th scope="col">Social Profiles</th>
<th scope="col">Industry</th>
<th scope="col">Status</th>
<th scope="col" class="text-end">Actions</th>
</tr>
</thead>
<tbody>
<?php if (empty($submissions)): ?>
<tr>
<td colspan="7" class="text-center text-muted pt-4 pb-4">
<i class="bi bi-inbox fs-2 d-block mb-2"></i>
No data submitted yet.
</td>
</tr>
<?php else: ?>
<?php foreach ($submissions as $sub): ?>
<tr>
<td class="fw-medium"><?= htmlspecialchars($sub['name']) ?></td>
<td><?= htmlspecialchars($sub['company'] ?? 'N/A') ?></td>
<td><?= htmlspecialchars($sub['location'] ?? 'N/A') ?></td>
<td>
<?php if (!empty($sub['linkedin_url'])): ?><a href="<?= htmlspecialchars($sub['linkedin_url']) ?>" target="_blank" class="text-body me-2"><i class="bi bi-linkedin"></i></a><?php endif; ?>
<?php if (!empty($sub['twitter_url'])): ?><a href="<?= htmlspecialchars($sub['twitter_url']) ?>" target="_blank" class="text-body me-2"><i class="bi bi-twitter-x"></i></a><?php endif; ?>
<?php if (!empty($sub['facebook_url'])): ?><a href="<?= htmlspecialchars($sub['facebook_url']) ?>" target="_blank" class="text-body me-2"><i class="bi bi-facebook"></i></a><?php endif; ?>
<?php if (!empty($sub['instagram_url'])): ?><a href="<?= htmlspecialchars($sub['instagram_url']) ?>" target="_blank" class="text-body me-2"><i class="bi bi-instagram"></i></a><?php endif; ?>
<?php if (!empty($sub['youtube_url'])): ?><a href="<?= htmlspecialchars($sub['youtube_url']) ?>" target="_blank" class="text-body"><i class="bi bi-youtube"></i></a><?php endif; ?>
</td>
<td><?= htmlspecialchars($sub['industry'] ?? 'N/A') ?></td>
<td>
<span class="badge rounded-pill <?= get_status_badge_class($sub['status']) ?>">
<?= htmlspecialchars($sub['status']) ?>
</span>
</td>
<td class="text-end">
<a href="refresh_submission.php?id=<?= $sub['id'] ?>" class="btn btn-sm btn-outline-primary" data-bs-toggle="tooltip" title="Refresh Data">
<i class="bi bi-arrow-clockwise"></i>
</a>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
</main>
<!-- CSV Upload Modal -->
<div class="modal fade" id="uploadCsvModal" tabindex="-1" aria-labelledby="uploadCsvModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="uploadCsvModalLabel">Upload CSV File</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form action="upload_csv.php" method="post" enctype="multipart/form-data" id="csvUploadForm">
<div class="mb-3">
<label for="csvFile" class="form-label">Select a CSV file to upload. The file should contain one column with the header "Name".</label>
<input class="form-control" type="file" id="csvFile" name="csvFile" accept=".csv" required>
</div>
<p class="text-muted small">Maximum rows: 1000.</p>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="submit" form="csvUploadForm" class="btn btn-primary">Upload and Process</button>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
<script>
// Enable tooltips
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
return new bootstrap.Tooltip(tooltipTriggerEl)
})
</script>
</body>
</html>