Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5f8fcb0a33 | ||
|
|
02c2f115f9 | ||
|
|
119d467b75 | ||
|
|
d2b41a238e |
192
analyst_dashboard.php
Normal file
192
analyst_dashboard.php
Normal file
@ -0,0 +1,192 @@
|
||||
<?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>
|
||||
21
assets/css/custom.css
Normal file
21
assets/css/custom.css
Normal file
@ -0,0 +1,21 @@
|
||||
body {
|
||||
background-color: #F8F9FA;
|
||||
}
|
||||
|
||||
.navbar-brand {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.form-control:focus {
|
||||
border-color: #0D6EFD;
|
||||
box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background-color: #0D6EFD;
|
||||
border-color: #0D6EFD;
|
||||
}
|
||||
|
||||
.toast {
|
||||
border-radius: 0.5rem;
|
||||
}
|
||||
7
assets/js/main.js
Normal file
7
assets/js/main.js
Normal file
@ -0,0 +1,7 @@
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
var toastEl = document.getElementById('successToast');
|
||||
if (toastEl) {
|
||||
var toast = new bootstrap.Toast(toastEl);
|
||||
toast.show();
|
||||
}
|
||||
});
|
||||
56
db/migrate.php
Normal file
56
db/migrate.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/config.php';
|
||||
|
||||
try {
|
||||
// Connect without specifying a database to create it if it doesn't exist
|
||||
$pdo = new PDO('mysql:host='.DB_HOST, DB_USER, DB_PASS, [
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
]);
|
||||
$pdo->exec('CREATE DATABASE IF NOT EXISTS '.DB_NAME);
|
||||
echo "Database ".DB_NAME." created or already exists.\n";
|
||||
} catch (PDOException $e) {
|
||||
// Suppress error if DB exists but user lacks CREATE DB permissions
|
||||
}
|
||||
|
||||
// Now, connect to the specific database
|
||||
$pdo = db();
|
||||
|
||||
// 1. Create migrations table if it doesn't exist
|
||||
try {
|
||||
$pdo->exec("\n CREATE TABLE IF NOT EXISTS `migrations` (\n `id` INT AUTO_INCREMENT PRIMARY KEY,\n `migration` VARCHAR(255) NOT NULL,\n `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP\n )\n ");
|
||||
} catch (PDOException $e) {
|
||||
echo "Error creating migrations table: " . $e->getMessage() . "\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// 2. Get all migrations that have been run
|
||||
$stmt = $pdo->query("SELECT `migration` FROM `migrations`");
|
||||
$runMigrations = $stmt->fetchAll(PDO::FETCH_COLUMN);
|
||||
|
||||
// 3. Get all available migration files
|
||||
$migrationsDir = __DIR__ . '/migrations';
|
||||
$files = glob($migrationsDir . '/*.sql');
|
||||
sort($files);
|
||||
|
||||
// 4. Run migrations that have not been run yet
|
||||
foreach ($files as $file) {
|
||||
$migrationName = basename($file);
|
||||
if (!in_array($migrationName, $runMigrations)) {
|
||||
echo "Applying migration: " . $migrationName . "\n";
|
||||
$sql = file_get_contents($file);
|
||||
try {
|
||||
$pdo->exec($sql);
|
||||
|
||||
// Add the migration to the migrations table
|
||||
$insertStmt = $pdo->prepare("INSERT INTO `migrations` (`migration`) VALUES (?)");
|
||||
$insertStmt->execute([$migrationName]);
|
||||
|
||||
echo "Success\n";
|
||||
} catch (PDOException $e) {
|
||||
echo "Error applying migration: " . $e->getMessage() . "\n";
|
||||
// Don't exit, allow other migrations to run
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo "Migration check complete.\n";
|
||||
15
db/migrations/001_create_submissions_table.sql
Normal file
15
db/migrations/001_create_submissions_table.sql
Normal file
@ -0,0 +1,15 @@
|
||||
|
||||
CREATE TABLE IF NOT EXISTS submissions (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
status ENUM('new', 'processing', 'complete', 'error') NOT NULL DEFAULT 'new',
|
||||
profile_url VARCHAR(255) NULL,
|
||||
username VARCHAR(255) NULL,
|
||||
company VARCHAR(255) NULL,
|
||||
profile_image_url VARCHAR(255) NULL,
|
||||
location VARCHAR(255) NULL,
|
||||
industry VARCHAR(255) NULL,
|
||||
geo_location VARCHAR(255) NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||
);
|
||||
@ -0,0 +1,13 @@
|
||||
ALTER TABLE `submissions`
|
||||
ADD COLUMN `status` VARCHAR(255) NOT NULL DEFAULT 'Pending',
|
||||
ADD COLUMN `company` VARCHAR(255) NULL,
|
||||
ADD COLUMN `profile_image_url` VARCHAR(2048) NULL,
|
||||
ADD COLUMN `location` VARCHAR(255) NULL,
|
||||
ADD COLUMN `linkedin_url` VARCHAR(2048) NULL,
|
||||
ADD COLUMN `twitter_url` VARCHAR(2048) NULL,
|
||||
ADD COLUMN `facebook_url` VARCHAR(2048) NULL,
|
||||
ADD COLUMN `instagram_url` VARCHAR(2048) NULL,
|
||||
ADD COLUMN `youtube_url` VARCHAR(2048) NULL,
|
||||
ADD COLUMN `industry` VARCHAR(255) NULL,
|
||||
ADD COLUMN `geo_location` VARCHAR(255) NULL,
|
||||
ADD COLUMN `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;
|
||||
224
index.php
224
index.php
@ -1,150 +1,92 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
@ini_set('display_errors', '1');
|
||||
@error_reporting(E_ALL);
|
||||
@date_default_timezone_set('UTC');
|
||||
require_once __DIR__ . '/db/config.php';
|
||||
|
||||
$phpVersion = PHP_VERSION;
|
||||
$now = date('Y-m-d H:i:s');
|
||||
$success_toast = false;
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST['name'])) {
|
||||
$name = trim($_POST['name']);
|
||||
if (!empty($name)) {
|
||||
try {
|
||||
$pdo = db();
|
||||
$stmt = $pdo->prepare("INSERT INTO submissions (name) VALUES (?)");
|
||||
$stmt->execute([$name]);
|
||||
$success_toast = true;
|
||||
// Trigger the background worker
|
||||
shell_exec('php /home/ubuntu/executor/workspace/worker.php > /dev/null 2>&1 &');
|
||||
} catch (PDOException $e) {
|
||||
// For now, we'll just prevent the success toast on db error.
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
<!doctype html>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>New Style</title>
|
||||
<?php
|
||||
// Read project preview data from environment
|
||||
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? '';
|
||||
$projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
|
||||
?>
|
||||
<?php if ($projectDescription): ?>
|
||||
<!-- Meta description -->
|
||||
<meta name="description" content='<?= htmlspecialchars($projectDescription) ?>' />
|
||||
<!-- Open Graph meta tags -->
|
||||
<meta property="og:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
||||
<!-- Twitter meta tags -->
|
||||
<meta property="twitter:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
||||
<?php endif; ?>
|
||||
<?php if ($projectImageUrl): ?>
|
||||
<!-- Open Graph image -->
|
||||
<meta property="og:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
||||
<!-- Twitter image -->
|
||||
<meta property="twitter:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
||||
<?php endif; ?>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet">
|
||||
<style>
|
||||
:root {
|
||||
--bg-color-start: #6a11cb;
|
||||
--bg-color-end: #2575fc;
|
||||
--text-color: #ffffff;
|
||||
--card-bg-color: rgba(255, 255, 255, 0.01);
|
||||
--card-border-color: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: 'Inter', sans-serif;
|
||||
background: linear-gradient(45deg, var(--bg-color-start), var(--bg-color-end));
|
||||
color: var(--text-color);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-height: 100vh;
|
||||
text-align: center;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
}
|
||||
body::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><path d="M-10 10L110 10M10 -10L10 110" stroke-width="1" stroke="rgba(255,255,255,0.05)"/></svg>');
|
||||
animation: bg-pan 20s linear infinite;
|
||||
z-index: -1;
|
||||
}
|
||||
@keyframes bg-pan {
|
||||
0% { background-position: 0% 0%; }
|
||||
100% { background-position: 100% 100%; }
|
||||
}
|
||||
main {
|
||||
padding: 2rem;
|
||||
}
|
||||
.card {
|
||||
background: var(--card-bg-color);
|
||||
border: 1px solid var(--card-border-color);
|
||||
border-radius: 16px;
|
||||
padding: 2rem;
|
||||
backdrop-filter: blur(20px);
|
||||
-webkit-backdrop-filter: blur(20px);
|
||||
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
.loader {
|
||||
margin: 1.25rem auto 1.25rem;
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border: 3px solid rgba(255, 255, 255, 0.25);
|
||||
border-top-color: #fff;
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
@keyframes spin {
|
||||
from { transform: rotate(0deg); }
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
.hint {
|
||||
opacity: 0.9;
|
||||
}
|
||||
.sr-only {
|
||||
position: absolute;
|
||||
width: 1px; height: 1px;
|
||||
padding: 0; margin: -1px;
|
||||
overflow: hidden;
|
||||
clip: rect(0, 0, 0, 0);
|
||||
white-space: nowrap; border: 0;
|
||||
}
|
||||
h1 {
|
||||
font-size: 3rem;
|
||||
font-weight: 700;
|
||||
margin: 0 0 1rem;
|
||||
letter-spacing: -1px;
|
||||
}
|
||||
p {
|
||||
margin: 0.5rem 0;
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
code {
|
||||
background: rgba(0,0,0,0.2);
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
||||
}
|
||||
footer {
|
||||
position: absolute;
|
||||
bottom: 1rem;
|
||||
font-size: 0.8rem;
|
||||
opacity: 0.7;
|
||||
}
|
||||
</style>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Lead Enricher</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/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>
|
||||
<main>
|
||||
<div class="card">
|
||||
<h1>Analyzing your requirements and generating your website…</h1>
|
||||
<div class="loader" role="status" aria-live="polite" aria-label="Applying initial changes">
|
||||
<span class="sr-only">Loading…</span>
|
||||
</div>
|
||||
<p class="hint"><?= ($_SERVER['HTTP_HOST'] ?? '') === 'appwizzy.com' ? 'AppWizzy' : 'Flatlogic' ?> AI is collecting your requirements and applying the first changes.</p>
|
||||
<p class="hint">This page will update automatically as the plan is implemented.</p>
|
||||
<p>Runtime: PHP <code><?= htmlspecialchars($phpVersion) ?></code> — UTC <code><?= htmlspecialchars($now) ?></code></p>
|
||||
|
||||
<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 active" aria-current="page" href="index.php">Home</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="analyst_dashboard.php">Dashboard</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<!-- Hero Section -->
|
||||
<div class="container col-xl-10 col-xxl-8 px-4 py-5">
|
||||
<div class="row align-items-center g-lg-5 py-5">
|
||||
<div class="col-lg-7 text-center text-lg-start">
|
||||
<h1 class="display-4 fw-bold lh-1 mb-3">Enrich Leads, Effortlessly</h1>
|
||||
<p class="col-lg-10 fs-4">Submit a name, and our AI will find and classify their social profiles, industry, and location. Turn a simple name into a rich lead.</p>
|
||||
</div>
|
||||
<div class="col-md-10 mx-auto col-lg-5">
|
||||
<form class="p-4 p-md-5 border rounded-3 bg-white shadow-sm" method="POST" action="index.php">
|
||||
<div class="form-floating mb-3">
|
||||
<input type="text" class="form-control" id="name" name="name" placeholder="e.g., John Doe" required>
|
||||
<label for="name">Full Name</label>
|
||||
</div>
|
||||
<button class="w-100 btn btn-lg btn-primary" type="submit">Enrich Name</button>
|
||||
<hr class="my-4">
|
||||
<small class="text-muted">By clicking Enrich Name, you agree to the terms of use.</small>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
<footer>
|
||||
Page updated: <?= htmlspecialchars($now) ?> (UTC)
|
||||
</footer>
|
||||
|
||||
<!-- Toast Notification -->
|
||||
<?php if ($success_toast): ?>
|
||||
<div class="position-fixed bottom-0 end-0 p-3" style="z-index: 11">
|
||||
<div id="successToast" class="toast show align-items-center text-white bg-primary border-0" role="alert" aria-live="assertive" aria-atomic="true">
|
||||
<div class="d-flex">
|
||||
<div class="toast-body">
|
||||
<i class="bi bi-check-circle-fill me-2"></i>
|
||||
Name submitted successfully! We'll start the enrichment process.
|
||||
</div>
|
||||
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
28
refresh_submission.php
Normal file
28
refresh_submission.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/db/config.php';
|
||||
|
||||
// Check if ID is provided
|
||||
if (!isset($_GET['id']) || empty($_GET['id'])) {
|
||||
header('Location: analyst_dashboard.php?error=missing_id');
|
||||
exit;
|
||||
}
|
||||
|
||||
$submissionId = (int)$_GET['id'];
|
||||
|
||||
// Update the status to 'Pending'
|
||||
try {
|
||||
$pdo = db();
|
||||
$stmt = $pdo->prepare("UPDATE submissions SET status = 'Pending' WHERE id = ?");
|
||||
$stmt->execute([$submissionId]);
|
||||
|
||||
// Trigger the background worker
|
||||
shell_exec('php /home/ubuntu/executor/workspace/worker.php > /dev/null 2>&1 &');
|
||||
} catch (PDOException $e) {
|
||||
// In a real app, log this error
|
||||
header('Location: analyst_dashboard.php?error=' . urlencode($e->getMessage()));
|
||||
exit;
|
||||
}
|
||||
|
||||
// Redirect back with a success message
|
||||
header('Location: analyst_dashboard.php?refreshed=1');
|
||||
exit;
|
||||
76
upload_csv.php
Normal file
76
upload_csv.php
Normal file
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/db/config.php';
|
||||
|
||||
// Basic validation
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST' || !isset($_FILES['csvFile'])) {
|
||||
header('Location: analyst_dashboard.php?error=' . urlencode('Invalid request.'));
|
||||
exit;
|
||||
}
|
||||
|
||||
$file = $_FILES['csvFile'];
|
||||
|
||||
// Check for upload errors
|
||||
if ($file['error'] !== UPLOAD_ERR_OK) {
|
||||
header('Location: analyst_dashboard.php?error=' . urlencode('File upload error: ' . $file['error']));
|
||||
exit;
|
||||
}
|
||||
|
||||
// Check file type
|
||||
$mime_type = mime_content_type($file['tmp_name']);
|
||||
if ($mime_type !== 'text/csv' && $mime_type !== 'text/plain') {
|
||||
header('Location: analyst_dashboard.php?error=' . urlencode('Invalid file type. Please upload a CSV file.'));
|
||||
exit;
|
||||
}
|
||||
|
||||
$handle = fopen($file['tmp_name'], 'r');
|
||||
if ($handle === false) {
|
||||
header('Location: analyst_dashboard.php?error=' . urlencode('Could not open the uploaded file.'));
|
||||
exit;
|
||||
}
|
||||
|
||||
// Validate header
|
||||
$header = fgetcsv($handle);
|
||||
if ($header === false || count($header) !== 1 || strtolower(trim($header[0])) !== 'name') {
|
||||
fclose($handle);
|
||||
header('Location: analyst_dashboard.php?error=' . urlencode('Invalid CSV header. The first column must be "Name".'));
|
||||
exit;
|
||||
}
|
||||
|
||||
$pdo = db();
|
||||
$stmt = $pdo->prepare("INSERT INTO submissions (name) VALUES (:name)");
|
||||
|
||||
$importedCount = 0;
|
||||
$rowCount = 0;
|
||||
|
||||
while (($data = fgetcsv($handle)) !== false) {
|
||||
$rowCount++;
|
||||
if ($rowCount > 1000) {
|
||||
// Stop processing if the file exceeds the row limit
|
||||
break;
|
||||
}
|
||||
|
||||
if (isset($data[0]) && !empty(trim($data[0]))) {
|
||||
try {
|
||||
$stmt->execute(['name' => trim($data[0])]);
|
||||
$importedCount++;
|
||||
} catch (PDOException $e) {
|
||||
// You might want to log this error instead of ignoring it
|
||||
// error_log("CSV Import Error: " . $e->getMessage());
|
||||
continue; // Continue to the next row
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fclose($handle);
|
||||
|
||||
// Trigger the background worker now that new submissions are in
|
||||
if ($importedCount > 0) {
|
||||
shell_exec('php /home/ubuntu/executor/workspace/worker.php > /dev/null 2>&1 &');
|
||||
}
|
||||
|
||||
if ($rowCount > 1000) {
|
||||
header('Location: analyst_dashboard.php?error=' . urlencode('CSV file exceeds the 1000-row limit. Only the first 1000 rows were processed.') . '&success=' . $importedCount);
|
||||
} else {
|
||||
header('Location: analyst_dashboard.php?success=' . $importedCount);
|
||||
}
|
||||
exit;
|
||||
158
worker.php
Normal file
158
worker.php
Normal file
@ -0,0 +1,158 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/db/config.php';
|
||||
|
||||
// Set a longer execution time, as this can be a long-running script.
|
||||
ini_set('max_execution_time', 300); // 5 minutes
|
||||
|
||||
// --- Helper Functions ---
|
||||
|
||||
/**
|
||||
* Updates the status of a submission.
|
||||
*/
|
||||
function update_status($pdo, $id, $status, $message = null) {
|
||||
$sql = "UPDATE submissions SET status = ? WHERE id = ?";
|
||||
if ($message) {
|
||||
// For now, we don't have a column for error messages, but we could add one.
|
||||
// For this version, we'll just log it to the server's error log.
|
||||
error_log("Submission ID: $id, Status: $status, Message: $message");
|
||||
}
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([$status, $id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* A simple function to extract a domain from a URL.
|
||||
*/
|
||||
function get_domain($url) {
|
||||
$pieces = parse_url($url);
|
||||
if (isset($pieces['host'])) {
|
||||
return preg_replace('/^www\./', '', $pieces['host']);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// --- Main Worker Logic ---
|
||||
|
||||
$pdo = db();
|
||||
|
||||
// 1. Find submissions that are 'Pending' or those that have been 'Processing' for a while (e.g., > 15 mins)
|
||||
// This helps recover from script crashes.
|
||||
$stmt = $pdo->query("SELECT * FROM submissions WHERE status = 'Pending' OR (status = 'Processing' AND updated_at < NOW() - INTERVAL 15 MINUTE)");
|
||||
$pending_submissions = $stmt->fetchAll();
|
||||
|
||||
if (empty($pending_submissions)) {
|
||||
// No work to do, just redirect back.
|
||||
header('Location: analyst_dashboard.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
foreach ($pending_submissions as $sub) {
|
||||
$id = $sub['id'];
|
||||
$name = $sub['name'];
|
||||
|
||||
// 2. Mark as 'Processing'
|
||||
update_status($pdo, $id, 'Processing');
|
||||
|
||||
// 3. Simulate fetching data (This is where the Gemini API calls will go)
|
||||
// For now, we'll use a mock implementation that just populates some data.
|
||||
try {
|
||||
// --- REAL DATA IMPLEMENTATION ---
|
||||
$linkedin_query = "{$name}" site:linkedin.com/in/;
|
||||
$twitter_query = "{$name}" site:twitter.com;
|
||||
$company_query = "{$name}" company;
|
||||
|
||||
// For this example, we'll call the tool synchronously.
|
||||
// In a real-world high-volume application, you might use a job queue.
|
||||
$linkedin_results_json = shell_exec("gemini-tool google_web_search --query '{$linkedin_query}'");
|
||||
$twitter_results_json = shell_exec("gemini-tool google_web_search --query '{$twitter_query}'");
|
||||
$company_results_json = shell_exec("gemini-tool google_web_search --query '{$company_query}'");
|
||||
|
||||
$linkedin_url = null;
|
||||
if ($linkedin_results_json) {
|
||||
$results = json_decode($linkedin_results_json, true);
|
||||
if (!empty($results['web_search_result']['results'])) {
|
||||
// Find the first result that looks like a profile
|
||||
foreach ($results['web_search_result']['results'] as $res) {
|
||||
if (preg_match('/linkedin\.com\/in\//', $res['url'])) {
|
||||
$linkedin_url = $res['url'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$twitter_url = null;
|
||||
if ($twitter_results_json) {
|
||||
$results = json_decode($twitter_results_json, true);
|
||||
if (!empty($results['web_search_result']['results'])) {
|
||||
foreach ($results['web_search_result']['results'] as $res) {
|
||||
if (preg_match('/twitter\.com\/[^\/]+$/', $res['url'])) {
|
||||
$twitter_url = $res['url'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$company = null;
|
||||
if ($company_results_json) {
|
||||
$results = json_decode($company_results_json, true);
|
||||
if (!empty($results['web_search_result']['results'])) {
|
||||
// For simplicity, we'll take the title of the first result as the company name.
|
||||
// This is a very rough heuristic and could be improved.
|
||||
$company = $results['web_search_result']['results'][0]['title'];
|
||||
}
|
||||
}
|
||||
|
||||
$industry = null;
|
||||
if ($company) {
|
||||
$industry_query = ""{$company}" industry";
|
||||
$industry_results_json = shell_exec("gemini-tool google_web_search --query '{$industry_query}'");
|
||||
if ($industry_results_json) {
|
||||
$results = json_decode($industry_results_json, true);
|
||||
if (!empty($results['web_search_result']['results'])) {
|
||||
$industry = $results['web_search_result']['results'][0]['title'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$geo_location = null;
|
||||
if ($company) {
|
||||
$location_query = ""{$company}" headquarters location";
|
||||
$location_results_json = shell_exec("gemini-tool google_web_search --query '{$location_query}'");
|
||||
if ($location_results_json) {
|
||||
$results = json_decode($location_results_json, true);
|
||||
if (!empty($results['web_search_result']['results'])) {
|
||||
$geo_location = $results['web_search_result']['results'][0]['title'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$update_data = [
|
||||
'linkedin_url' => $linkedin_url,
|
||||
'twitter_url' => $twitter_url,
|
||||
'company' => $company,
|
||||
'industry' => $industry,
|
||||
'geo_location' => $geo_location,
|
||||
'status' => 'Completed'
|
||||
];
|
||||
|
||||
$sql_parts = [];
|
||||
foreach ($update_data as $key => $value) {
|
||||
$sql_parts[] = "`$key` = :$key";
|
||||
}
|
||||
$sql = "UPDATE submissions SET " . implode(', ', $sql_parts) . " WHERE id = :id";
|
||||
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$update_data['id'] = $id;
|
||||
$stmt->execute($update_data);
|
||||
|
||||
} catch (Exception $e) {
|
||||
// If something goes wrong, mark as 'Error'
|
||||
update_status($pdo, $id, 'Error', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// 4. Redirect back to the dashboard
|
||||
header('Location: analyst_dashboard.php?refreshed=all');
|
||||
exit;
|
||||
Loading…
x
Reference in New Issue
Block a user