Add complete ScoutIQ system: Crawler (RSS+AI), CRUD Controllers (Organizations, Contacts, Opportunities, Sources), dynamic Views, API routes, CLI collector
This commit is contained in:
163
app/Controllers/Admin/ContactsController.php
Normal file
163
app/Controllers/Admin/ContactsController.php
Normal file
@@ -0,0 +1,163 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Admin;
|
||||
|
||||
use App\Controllers\Controller;
|
||||
use App\Core\Request;
|
||||
use App\Core\Response;
|
||||
use App\Services\Database\Connection;
|
||||
use PDO;
|
||||
use Throwable;
|
||||
|
||||
class ContactsController extends Controller
|
||||
{
|
||||
private PDO $pdo;
|
||||
|
||||
public function __construct(Connection $connection)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->pdo = $connection->getPdo();
|
||||
}
|
||||
|
||||
public function index(Request $request, Response $response): string
|
||||
{
|
||||
$search = $request->get('search', '');
|
||||
$page = max(1, (int)$request->get('page', 1));
|
||||
$perPage = 20;
|
||||
$offset = ($page - 1) * $perPage;
|
||||
|
||||
$where = ['c.deleted_at IS NULL'];
|
||||
$params = [];
|
||||
|
||||
if ($search) {
|
||||
$where[] = '(c.name LIKE ? OR c.email LIKE ? OR c.phone LIKE ?)';
|
||||
$params[] = "%{$search}%";
|
||||
$params[] = "%{$search}%";
|
||||
$params[] = "%{$search}%";
|
||||
}
|
||||
|
||||
$whereClause = implode(' AND ', $where);
|
||||
|
||||
$stmt = $this->pdo->prepare("SELECT COUNT(*) FROM contacts c WHERE {$whereClause}");
|
||||
$stmt->execute($params);
|
||||
$total = (int)$stmt->fetchColumn();
|
||||
|
||||
$stmt = $this->pdo->prepare(
|
||||
"SELECT c.*, org.name as org_name,
|
||||
(SELECT COUNT(*) FROM interactions WHERE contact_id = c.id) as interaction_count
|
||||
FROM contacts c
|
||||
LEFT JOIN organizations org ON org.id = c.organization_id
|
||||
WHERE {$whereClause}
|
||||
ORDER BY c.updated_at DESC
|
||||
LIMIT ? OFFSET ?"
|
||||
);
|
||||
$stmt->execute(array_merge($params, [$perPage, $offset]));
|
||||
$contacts = $stmt->fetchAll();
|
||||
|
||||
return $this->render('admin/contacts/index', [
|
||||
'contacts' => $contacts,
|
||||
'total' => $total,
|
||||
'page' => $page,
|
||||
'perPage' => $perPage,
|
||||
'search' => $search,
|
||||
], 'admin');
|
||||
}
|
||||
|
||||
public function show(Request $request, Response $response, int $id): string
|
||||
{
|
||||
$stmt = $this->pdo->prepare(
|
||||
"SELECT c.*, org.name as org_name, org.id as org_id
|
||||
FROM contacts c
|
||||
LEFT JOIN organizations org ON org.id = c.organization_id
|
||||
WHERE c.id = ? AND c.deleted_at IS NULL"
|
||||
);
|
||||
$stmt->execute([$id]);
|
||||
$contact = $stmt->fetch();
|
||||
|
||||
if (!$contact) { $response->redirect('/admin/contacts'); return ''; }
|
||||
|
||||
$stmt = $this->pdo->prepare("SELECT * FROM interactions WHERE contact_id = ? ORDER BY created_at DESC");
|
||||
$stmt->execute([$id]);
|
||||
$interactions = $stmt->fetchAll();
|
||||
|
||||
return $this->render('admin/contacts/show', [
|
||||
'contact' => $contact,
|
||||
'interactions' => $interactions,
|
||||
], 'admin');
|
||||
}
|
||||
|
||||
public function create(Request $request, Response $response): string
|
||||
{
|
||||
$orgId = $request->get('organization_id', '');
|
||||
$orgs = $this->pdo->query("SELECT id, name FROM organizations WHERE deleted_at IS NULL ORDER BY name")->fetchAll();
|
||||
return $this->render('admin/contacts/form', [
|
||||
'contact' => null,
|
||||
'organizations' => $orgs,
|
||||
'selectedOrgId' => $orgId,
|
||||
], 'admin');
|
||||
}
|
||||
|
||||
public function edit(Request $request, Response $response, int $id): string
|
||||
{
|
||||
$stmt = $this->pdo->prepare("SELECT * FROM contacts WHERE id = ? AND deleted_at IS NULL");
|
||||
$stmt->execute([$id]);
|
||||
$contact = $stmt->fetch();
|
||||
if (!$contact) { $response->redirect('/admin/contacts'); return ''; }
|
||||
|
||||
$orgs = $this->pdo->query("SELECT id, name FROM organizations WHERE deleted_at IS NULL ORDER BY name")->fetchAll();
|
||||
return $this->render('admin/contacts/form', [
|
||||
'contact' => $contact,
|
||||
'organizations' => $orgs,
|
||||
'selectedOrgId' => $contact['organization_id'],
|
||||
], 'admin');
|
||||
}
|
||||
|
||||
public function store(Request $request, Response $response): void
|
||||
{
|
||||
$id = $request->post('id', '');
|
||||
$name = $request->post('name', '');
|
||||
$email = $request->post('email', '');
|
||||
$phone = $request->post('phone', '');
|
||||
$position = $request->post('position', '');
|
||||
$organizationId = $request->post('organization_id', '');
|
||||
$notes = $request->post('notes', '');
|
||||
|
||||
try {
|
||||
if ($id) {
|
||||
$stmt = $this->pdo->prepare("UPDATE contacts SET name=?, email=?, phone=?, position=?, organization_id=?, notes=? WHERE id=?");
|
||||
$stmt->execute([$name, $email ?: null, $phone ?: null, $position ?: null, $organizationId ?: null, $notes, $id]);
|
||||
} else {
|
||||
$stmt = $this->pdo->prepare("INSERT INTO contacts (name, email, phone, position, organization_id, notes) VALUES (?, ?, ?, ?, ?, ?)");
|
||||
$stmt->execute([$name, $email ?: null, $phone ?: null, $position ?: null, $organizationId ?: null, $notes]);
|
||||
$id = $this->pdo->lastInsertId();
|
||||
}
|
||||
$this->session->setFlash('success', 'Contact saved.');
|
||||
$response->redirect('/admin/contacts/' . $id);
|
||||
} catch (Throwable $e) {
|
||||
$this->session->setFlash('error', 'Error: ' . $e->getMessage());
|
||||
$response->redirect('/admin/contacts');
|
||||
}
|
||||
}
|
||||
|
||||
public function delete(Request $request, Response $response, int $id): void
|
||||
{
|
||||
$this->pdo->prepare("UPDATE contacts SET deleted_at = NOW() WHERE id = ?")->execute([$id]);
|
||||
$this->session->setFlash('success', 'Contact deleted.');
|
||||
$response->redirect('/admin/contacts');
|
||||
}
|
||||
|
||||
public function addInteraction(Request $request, Response $response, int $contactId): void
|
||||
{
|
||||
$type = $request->post('type', 'note');
|
||||
$notes = $request->post('notes', '');
|
||||
|
||||
try {
|
||||
$stmt = $this->pdo->prepare("INSERT INTO interactions (contact_id, type, notes) VALUES (?, ?, ?)");
|
||||
$stmt->execute([$contactId, $type, $notes]);
|
||||
$this->session->setFlash('success', 'Interaction logged.');
|
||||
} catch (Throwable $e) {
|
||||
$this->session->setFlash('error', 'Error: ' . $e->getMessage());
|
||||
}
|
||||
$response->redirect('/admin/contacts/' . $contactId);
|
||||
}
|
||||
}
|
||||
112
app/Controllers/Admin/OpportunitiesController.php
Normal file
112
app/Controllers/Admin/OpportunitiesController.php
Normal file
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Admin;
|
||||
|
||||
use App\Controllers\Controller;
|
||||
use App\Core\Request;
|
||||
use App\Core\Response;
|
||||
use App\Services\Database\Connection;
|
||||
use PDO;
|
||||
use Throwable;
|
||||
|
||||
class OpportunitiesController extends Controller
|
||||
{
|
||||
private PDO $pdo;
|
||||
|
||||
public function __construct(Connection $connection)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->pdo = $connection->getPdo();
|
||||
}
|
||||
|
||||
public function index(Request $request, Response $response): string
|
||||
{
|
||||
$type = $request->get('type', '');
|
||||
$search = $request->get('search', '');
|
||||
$status = $request->get('status', '');
|
||||
$page = max(1, (int)$request->get('page', 1));
|
||||
$perPage = 20;
|
||||
$offset = ($page - 1) * $perPage;
|
||||
|
||||
$where = ['o.deleted_at IS NULL'];
|
||||
$params = [];
|
||||
|
||||
if ($type) { $where[] = 'o.type = ?'; $params[] = $type; }
|
||||
if ($status) { $where[] = 'o.status = ?'; $params[] = $status; }
|
||||
if ($search) {
|
||||
$where[] = '(o.title LIKE ? OR o.description LIKE ?)';
|
||||
$params[] = "%{$search}%";
|
||||
$params[] = "%{$search}%";
|
||||
}
|
||||
|
||||
$whereClause = implode(' AND ', $where);
|
||||
|
||||
$stmt = $this->pdo->prepare("SELECT COUNT(*) FROM opportunities o WHERE {$whereClause}");
|
||||
$stmt->execute($params);
|
||||
$total = (int)$stmt->fetchColumn();
|
||||
|
||||
$stmt = $this->pdo->prepare(
|
||||
"SELECT o.*, org.name as org_name,
|
||||
GROUP_CONCAT(DISTINCT t.name) as tag_names
|
||||
FROM opportunities o
|
||||
LEFT JOIN organizations org ON org.id = o.organization_id
|
||||
LEFT JOIN opportunity_tags ot ON ot.opportunity_id = o.id
|
||||
LEFT JOIN tags t ON t.id = ot.tag_id
|
||||
WHERE {$whereClause}
|
||||
GROUP BY o.id
|
||||
ORDER BY o.score DESC, o.created_at DESC
|
||||
LIMIT ? OFFSET ?"
|
||||
);
|
||||
$stmt->execute(array_merge($params, [$perPage, $offset]));
|
||||
$opportunities = $stmt->fetchAll();
|
||||
|
||||
// Get type counts for sidebar
|
||||
$typeCounts = $this->pdo->query(
|
||||
"SELECT type, COUNT(*) as count FROM opportunities WHERE deleted_at IS NULL GROUP BY type"
|
||||
)->fetchAll(PDO::FETCH_KEY_PAIR);
|
||||
|
||||
return $this->render('admin/opportunities/index', [
|
||||
'opportunities' => $opportunities,
|
||||
'total' => $total,
|
||||
'page' => $page,
|
||||
'perPage' => $perPage,
|
||||
'type' => $type,
|
||||
'status' => $status,
|
||||
'search' => $search,
|
||||
'typeCounts' => $typeCounts,
|
||||
'types' => ['grant', 'competition', 'demo_day', 'event', 'partnership', 'investment', 'other'],
|
||||
'statuses' => ['active', 'closed', 'expired'],
|
||||
], 'admin');
|
||||
}
|
||||
|
||||
public function show(Request $request, Response $response, int $id): string
|
||||
{
|
||||
$stmt = $this->pdo->prepare(
|
||||
"SELECT o.*, org.name as org_name, org.type as org_type, org.website_url as org_website,
|
||||
GROUP_CONCAT(DISTINCT t.name) as tag_names
|
||||
FROM opportunities o
|
||||
LEFT JOIN organizations org ON org.id = o.organization_id
|
||||
LEFT JOIN opportunity_tags ot ON ot.opportunity_id = o.id
|
||||
LEFT JOIN tags t ON t.id = ot.tag_id
|
||||
WHERE o.id = ? AND o.deleted_at IS NULL
|
||||
GROUP BY o.id"
|
||||
);
|
||||
$stmt->execute([$id]);
|
||||
$opportunity = $stmt->fetch();
|
||||
|
||||
if (!$opportunity) {
|
||||
$response->redirect('/admin/opportunities');
|
||||
return '';
|
||||
}
|
||||
|
||||
// Get applications
|
||||
$stmt = $this->pdo->prepare("SELECT * FROM applications WHERE opportunity_id = ? AND deleted_at IS NULL ORDER BY created_at DESC");
|
||||
$stmt->execute([$id]);
|
||||
$applications = $stmt->fetchAll();
|
||||
|
||||
return $this->render('admin/opportunities/show', [
|
||||
'opportunity' => $opportunity,
|
||||
'applications' => $applications,
|
||||
], 'admin');
|
||||
}
|
||||
}
|
||||
219
app/Controllers/Admin/OrganizationsController.php
Normal file
219
app/Controllers/Admin/OrganizationsController.php
Normal file
@@ -0,0 +1,219 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Admin;
|
||||
|
||||
use App\Controllers\Controller;
|
||||
use App\Core\Request;
|
||||
use App\Core\Response;
|
||||
use App\Services\Database\Connection;
|
||||
use PDO;
|
||||
use Throwable;
|
||||
|
||||
class OrganizationsController extends Controller
|
||||
{
|
||||
private PDO $pdo;
|
||||
|
||||
public function __construct(Connection $connection)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->pdo = $connection->getPdo();
|
||||
}
|
||||
|
||||
/**
|
||||
* List all organizations with filters.
|
||||
*/
|
||||
public function index(Request $request, Response $response): string
|
||||
{
|
||||
$type = $request->get('type', '');
|
||||
$search = $request->get('search', '');
|
||||
$page = max(1, (int)$request->get('page', 1));
|
||||
$perPage = 20;
|
||||
$offset = ($page - 1) * $perPage;
|
||||
|
||||
$where = ['o.deleted_at IS NULL'];
|
||||
$params = [];
|
||||
|
||||
if ($type) {
|
||||
$where[] = 'o.type = ?';
|
||||
$params[] = $type;
|
||||
}
|
||||
if ($search) {
|
||||
$where[] = '(o.name LIKE ? OR o.domain LIKE ? OR o.description LIKE ?)';
|
||||
$params[] = "%{$search}%";
|
||||
$params[] = "%{$search}%";
|
||||
$params[] = "%{$search}%";
|
||||
}
|
||||
|
||||
$whereClause = implode(' AND ', $where);
|
||||
|
||||
// Count total
|
||||
$stmt = $this->pdo->prepare("SELECT COUNT(*) FROM organizations o WHERE {$whereClause}");
|
||||
$stmt->execute($params);
|
||||
$total = (int)$stmt->fetchColumn();
|
||||
|
||||
// Fetch page
|
||||
$stmt = $this->pdo->prepare(
|
||||
"SELECT o.*,
|
||||
(SELECT COUNT(*) FROM opportunities WHERE organization_id = o.id AND deleted_at IS NULL) as opportunities_count
|
||||
FROM organizations o
|
||||
WHERE {$whereClause}
|
||||
ORDER BY o.updated_at DESC
|
||||
LIMIT ? OFFSET ?"
|
||||
);
|
||||
$stmt->execute(array_merge($params, [$perPage, $offset]));
|
||||
$organizations = $stmt->fetchAll();
|
||||
|
||||
return $this->render('admin/organizations/index', [
|
||||
'organizations' => $organizations,
|
||||
'total' => $total,
|
||||
'page' => $page,
|
||||
'perPage' => $perPage,
|
||||
'type' => $type,
|
||||
'search' => $search,
|
||||
'types' => ['vc', 'angel', 'accelerator', 'incubator', 'venture_studio', 'partner'],
|
||||
'statuses' => ['New', 'Researching', 'Contacted', 'Follow Up', 'Meeting Scheduled', 'Interested', 'Rejected', 'Invested'],
|
||||
], 'admin');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show single organization.
|
||||
*/
|
||||
public function show(Request $request, Response $response, int $id): string
|
||||
{
|
||||
$stmt = $this->pdo->prepare("SELECT * FROM organizations WHERE id = ? AND deleted_at IS NULL");
|
||||
$stmt->execute([$id]);
|
||||
$org = $stmt->fetch();
|
||||
|
||||
if (!$org) {
|
||||
$response->redirect('/admin/organizations');
|
||||
return '';
|
||||
}
|
||||
|
||||
// Get opportunities for this org
|
||||
$stmt = $this->pdo->prepare(
|
||||
"SELECT o.*, GROUP_CONCAT(t.name) as tag_names
|
||||
FROM opportunities o
|
||||
LEFT JOIN opportunity_tags ot ON ot.opportunity_id = o.id
|
||||
LEFT JOIN tags t ON t.id = ot.tag_id
|
||||
WHERE o.organization_id = ? AND o.deleted_at IS NULL
|
||||
GROUP BY o.id
|
||||
ORDER BY o.score DESC"
|
||||
);
|
||||
$stmt->execute([$id]);
|
||||
$opportunities = $stmt->fetchAll();
|
||||
|
||||
// Get contacts for this org
|
||||
$stmt = $this->pdo->prepare(
|
||||
"SELECT c.*,
|
||||
(SELECT COUNT(*) FROM interactions WHERE contact_id = c.id) as interaction_count
|
||||
FROM contacts c
|
||||
WHERE c.organization_id = ? AND c.deleted_at IS NULL
|
||||
ORDER BY c.created_at DESC"
|
||||
);
|
||||
$stmt->execute([$id]);
|
||||
$contacts = $stmt->fetchAll();
|
||||
|
||||
// Get activity logs
|
||||
$stmt = $this->pdo->prepare(
|
||||
"SELECT * FROM activity_logs WHERE description LIKE ? ORDER BY created_at DESC LIMIT 20"
|
||||
);
|
||||
$stmt->execute(['%' . $org['name'] . '%']);
|
||||
$activities = $stmt->fetchAll();
|
||||
|
||||
return $this->render('admin/organizations/show', [
|
||||
'org' => $org,
|
||||
'opportunities' => $opportunities,
|
||||
'contacts' => $contacts,
|
||||
'activities' => $activities,
|
||||
], 'admin');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show create/edit form.
|
||||
*/
|
||||
public function create(Request $request, Response $response): string
|
||||
{
|
||||
return $this->render('admin/organizations/form', [
|
||||
'org' => null,
|
||||
'types' => ['vc', 'angel', 'accelerator', 'incubator', 'venture_studio', 'partner'],
|
||||
'statuses' => ['New', 'Researching', 'Contacted', 'Follow Up', 'Meeting Scheduled', 'Interested', 'Rejected', 'Invested'],
|
||||
], 'admin');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show edit form.
|
||||
*/
|
||||
public function edit(Request $request, Response $response, int $id): string
|
||||
{
|
||||
$stmt = $this->pdo->prepare("SELECT * FROM organizations WHERE id = ? AND deleted_at IS NULL");
|
||||
$stmt->execute([$id]);
|
||||
$org = $stmt->fetch();
|
||||
|
||||
if (!$org) {
|
||||
$response->redirect('/admin/organizations');
|
||||
return '';
|
||||
}
|
||||
|
||||
return $this->render('admin/organizations/form', [
|
||||
'org' => $org,
|
||||
'types' => ['vc', 'angel', 'accelerator', 'incubator', 'venture_studio', 'partner'],
|
||||
'statuses' => ['New', 'Researching', 'Contacted', 'Follow Up', 'Meeting Scheduled', 'Interested', 'Rejected', 'Invested'],
|
||||
], 'admin');
|
||||
}
|
||||
|
||||
/**
|
||||
* Save organization (create or update).
|
||||
*/
|
||||
public function store(Request $request, Response $response): void
|
||||
{
|
||||
$id = $request->post('id', '');
|
||||
$name = $request->post('name', '');
|
||||
$domain = $request->post('domain', '');
|
||||
$type = $request->post('type', 'partner');
|
||||
$country = $request->post('country', '');
|
||||
$city = $request->post('city', '');
|
||||
$websiteUrl = $request->post('website_url', '');
|
||||
$description = $request->post('description', '');
|
||||
$crmStatus = $request->post('crm_status', 'New');
|
||||
$fundingStage = $request->post('funding_stage', '');
|
||||
|
||||
try {
|
||||
if ($id) {
|
||||
$stmt = $this->pdo->prepare(
|
||||
"UPDATE organizations SET name=?, domain=?, type=?, country=?, city=?, website_url=?,
|
||||
description=?, crm_status=?, funding_stage=? WHERE id=?"
|
||||
);
|
||||
$stmt->execute([$name, $domain ?: null, $type, $country ?: null, $city ?: null, $websiteUrl ?: null, $description, $crmStatus, $fundingStage ?: null, $id]);
|
||||
$this->session->setFlash('success', 'Organization updated successfully.');
|
||||
} else {
|
||||
$stmt = $this->pdo->prepare(
|
||||
"INSERT INTO organizations (name, domain, type, country, city, website_url, description, crm_status, funding_stage)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"
|
||||
);
|
||||
$stmt->execute([$name, $domain ?: null, $type, $country ?: null, $city ?: null, $websiteUrl ?: null, $description, $crmStatus, $fundingStage ?: null]);
|
||||
$id = $this->pdo->lastInsertId();
|
||||
$this->session->setFlash('success', 'Organization created successfully.');
|
||||
}
|
||||
|
||||
$response->redirect('/admin/organizations/' . $id);
|
||||
} catch (Throwable $e) {
|
||||
$this->session->setFlash('error', 'Error saving organization: ' . $e->getMessage());
|
||||
$response->redirect('/admin/organizations' . ($id ? '/' . $id : '/create'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete organization (soft delete).
|
||||
*/
|
||||
public function delete(Request $request, Response $response, int $id): void
|
||||
{
|
||||
try {
|
||||
$stmt = $this->pdo->prepare("UPDATE organizations SET deleted_at = NOW() WHERE id = ?");
|
||||
$stmt->execute([$id]);
|
||||
$this->session->setFlash('success', 'Organization deleted.');
|
||||
} catch (Throwable $e) {
|
||||
$this->session->setFlash('error', 'Error deleting organization.');
|
||||
}
|
||||
$response->redirect('/admin/organizations');
|
||||
}
|
||||
}
|
||||
93
app/Controllers/Admin/SourcesController.php
Normal file
93
app/Controllers/Admin/SourcesController.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Admin;
|
||||
|
||||
use App\Controllers\Controller;
|
||||
use App\Core\Request;
|
||||
use App\Core\Response;
|
||||
use App\Services\Database\Connection;
|
||||
use App\Services\Crawler\Collector;
|
||||
use PDO;
|
||||
use Throwable;
|
||||
|
||||
class SourcesController extends Controller
|
||||
{
|
||||
private PDO $pdo;
|
||||
private Collector $collector;
|
||||
|
||||
public function __construct(Connection $connection, Collector $collector)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->pdo = $connection->getPdo();
|
||||
$this->collector = $collector;
|
||||
}
|
||||
|
||||
public function index(Request $request, Response $response): string
|
||||
{
|
||||
$sources = $this->collector->getActiveSources();
|
||||
// Also get inactive ones
|
||||
$stmt = $this->pdo->query("SELECT * FROM sources ORDER BY status, name");
|
||||
$allSources = $stmt->fetchAll();
|
||||
return $this->render('admin/sources/index', ['sources' => $allSources], 'admin');
|
||||
}
|
||||
|
||||
public function create(Request $request, Response $response): string
|
||||
{
|
||||
return $this->render('admin/sources/form', ['source' => null], 'admin');
|
||||
}
|
||||
|
||||
public function edit(Request $request, Response $response, int $id): string
|
||||
{
|
||||
$stmt = $this->pdo->prepare("SELECT * FROM sources WHERE id = ?");
|
||||
$stmt->execute([$id]);
|
||||
$source = $stmt->fetch();
|
||||
if (!$source) { $response->redirect('/admin/sources'); return ''; }
|
||||
return $this->render('admin/sources/form', ['source' => $source], 'admin');
|
||||
}
|
||||
|
||||
public function store(Request $request, Response $response): void
|
||||
{
|
||||
$id = $request->post('id', '');
|
||||
$name = $request->post('name', '');
|
||||
$url = $request->post('url', '');
|
||||
$type = $request->post('type', 'rss');
|
||||
$status = $request->post('status', 'active');
|
||||
|
||||
try {
|
||||
if ($id) {
|
||||
$stmt = $this->pdo->prepare("UPDATE sources SET name=?, url=?, type=?, status=? WHERE id=?");
|
||||
$stmt->execute([$name, $url, $type, $status, $id]);
|
||||
} else {
|
||||
$stmt = $this->pdo->prepare("INSERT INTO sources (name, url, type, status) VALUES (?, ?, ?, ?)");
|
||||
$stmt->execute([$name, $url, $type, $status]);
|
||||
}
|
||||
$this->session->setFlash('success', 'Source saved.');
|
||||
} catch (Throwable $e) {
|
||||
$this->session->setFlash('error', 'Error: ' . $e->getMessage());
|
||||
}
|
||||
$response->redirect('/admin/sources');
|
||||
}
|
||||
|
||||
public function delete(Request $request, Response $response, int $id): void
|
||||
{
|
||||
$this->pdo->prepare("DELETE FROM sources WHERE id = ?")->execute([$id]);
|
||||
$this->session->setFlash('success', 'Source deleted.');
|
||||
$response->redirect('/admin/sources');
|
||||
}
|
||||
|
||||
public function run(Request $request, Response $response, int $id): void
|
||||
{
|
||||
$stmt = $this->pdo->prepare("SELECT * FROM sources WHERE id = ?");
|
||||
$stmt->execute([$id]);
|
||||
$source = $stmt->fetch();
|
||||
if (!$source) { $this->session->setFlash('error', 'Source not found.'); $response->redirect('/admin/sources'); return; }
|
||||
|
||||
try {
|
||||
$result = $this->collector->collectSource($source);
|
||||
$this->session->setFlash('success', "Collected {$result['entries_found']} entries, {$result['opportunities']} new opportunities.");
|
||||
} catch (Throwable $e) {
|
||||
$this->session->setFlash('error', 'Collection error: ' . $e->getMessage());
|
||||
}
|
||||
$response->redirect('/admin/sources');
|
||||
}
|
||||
}
|
||||
245
app/Services/Crawler/AiAnalyzer.php
Normal file
245
app/Services/Crawler/AiAnalyzer.php
Normal file
@@ -0,0 +1,245 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Crawler;
|
||||
|
||||
use Throwable;
|
||||
|
||||
class AiAnalyzer
|
||||
{
|
||||
private ?string $apiKey;
|
||||
private string $model;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$config = require __DIR__ . '/../../../config/ai.php';
|
||||
$this->apiKey = $config['gemini']['api_key'] ?? null;
|
||||
$this->model = $config['gemini']['model'] ?? 'gemini-1.5-flash-latest';
|
||||
}
|
||||
|
||||
/**
|
||||
* Analyze text using Google Gemini AI to classify and extract info.
|
||||
* Returns: type, score, tags, is_opportunity, summary
|
||||
*/
|
||||
public function analyze(string $title, string $description): array
|
||||
{
|
||||
if (!$this->apiKey) {
|
||||
return $this->fallbackAnalysis($title, $description);
|
||||
}
|
||||
|
||||
$prompt = <<<PROMPT
|
||||
You are ScoutIQ, an investor intelligence AI. Analyze the following startup/investment content and return a JSON object with:
|
||||
- "type": one of ["grant", "competition", "demo_day", "event", "partnership", "investment", "news", "other"]
|
||||
- "opportunity_type": one of ["vc_funding", "accelerator", "incubator", "grant", "competition", "demo_day", "event", "partnership", "other"]
|
||||
- "score": integer 0-100 (relevance to startups seeking funding)
|
||||
- "tags": array of relevant tags (max 5)
|
||||
- "is_opportunity": boolean (true if it's a funding/investment opportunity)
|
||||
- "summary": 1-2 sentence summary of what this is
|
||||
- "organization_name": extracted organization name if any, or null
|
||||
- "country": extracted country if any, or null
|
||||
|
||||
Title: {$title}
|
||||
Description: {$description}
|
||||
|
||||
Respond ONLY with valid JSON, no markdown, no code fences.
|
||||
PROMPT;
|
||||
|
||||
try {
|
||||
$response = $this->callGemini($prompt);
|
||||
$json = json_decode($response, true);
|
||||
if (json_last_error() === JSON_ERROR_NONE && isset($json['type'])) {
|
||||
return $json;
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
// Fallback
|
||||
}
|
||||
|
||||
return $this->fallbackAnalysis($title, $description);
|
||||
}
|
||||
|
||||
/**
|
||||
* Analyze content for organization/investor extraction.
|
||||
*/
|
||||
public function extractOrganization(string $text): array
|
||||
{
|
||||
if (!$this->apiKey) {
|
||||
return [
|
||||
'name' => null,
|
||||
'type' => null,
|
||||
'country' => null,
|
||||
'website' => null,
|
||||
'description' => substr($text, 0, 500),
|
||||
];
|
||||
}
|
||||
|
||||
$prompt = <<<PROMPT
|
||||
Extract organization/investor information from this text. Return JSON:
|
||||
- "name": organization name or null
|
||||
- "type": one of ["vc", "angel", "accelerator", "incubator", "venture_studio", "partner", "other"] or null
|
||||
- "country": country name or null
|
||||
- "website": website URL or null
|
||||
- "description": brief description max 200 chars
|
||||
|
||||
Text: {$text}
|
||||
|
||||
Respond ONLY with valid JSON.
|
||||
PROMPT;
|
||||
|
||||
try {
|
||||
$response = $this->callGemini($prompt);
|
||||
$json = json_decode($response, true);
|
||||
if (json_last_error() === JSON_ERROR_NONE) {
|
||||
return $json;
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
// Fallback
|
||||
}
|
||||
|
||||
return [
|
||||
'name' => null,
|
||||
'type' => null,
|
||||
'country' => null,
|
||||
'website' => null,
|
||||
'description' => substr($text, 0, 500),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Call Gemini API.
|
||||
*/
|
||||
private function callGemini(string $prompt): string
|
||||
{
|
||||
$url = "https://generativelanguage.googleapis.com/v1beta/models/{$this->model}:generateContent?key={$this->apiKey}";
|
||||
|
||||
$payload = json_encode([
|
||||
'contents' => [
|
||||
[
|
||||
'parts' => [
|
||||
['text' => $prompt]
|
||||
]
|
||||
]
|
||||
],
|
||||
'generationConfig' => [
|
||||
'temperature' => 0.2,
|
||||
'maxOutputTokens' => 500,
|
||||
]
|
||||
]);
|
||||
|
||||
$context = stream_context_create([
|
||||
'http' => [
|
||||
'method' => 'POST',
|
||||
'header' => "Content-Type: application/json\r\n",
|
||||
'content' => $payload,
|
||||
'timeout' => 30,
|
||||
],
|
||||
'ssl' => [
|
||||
'verify_peer' => false,
|
||||
'verify_peer_name' => false,
|
||||
],
|
||||
]);
|
||||
|
||||
$response = @file_get_contents($url, false, $context);
|
||||
if (!$response) {
|
||||
return '{}';
|
||||
}
|
||||
|
||||
$data = json_decode($response, true);
|
||||
return $data['candidates'][0]['content']['parts'][0]['text'] ?? '{}';
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple keyword-based fallback when AI is unavailable.
|
||||
*/
|
||||
private function fallbackAnalysis(string $title, string $description): array
|
||||
{
|
||||
$text = strtolower($title . ' ' . $description);
|
||||
|
||||
$type = 'news';
|
||||
$opportunityType = 'other';
|
||||
$score = 10;
|
||||
$tags = [];
|
||||
$isOpportunity = false;
|
||||
|
||||
// Keyword patterns
|
||||
if (preg_match('/\b(grant|funding|award|prize)\b/i', $text)) {
|
||||
$type = 'grant';
|
||||
$opportunityType = 'grant';
|
||||
$score = 75;
|
||||
$isOpportunity = true;
|
||||
$tags[] = 'grant';
|
||||
}
|
||||
if (preg_match('/\b(competition|contest|challenge|hackathon)\b/i', $text)) {
|
||||
$type = 'competition';
|
||||
$opportunityType = 'competition';
|
||||
$score = 65;
|
||||
$isOpportunity = true;
|
||||
$tags[] = 'competition';
|
||||
}
|
||||
if (preg_match('/\b(demo day|pitch day|investor day)\b/i', $text)) {
|
||||
$type = 'demo_day';
|
||||
$opportunityType = 'demo_day';
|
||||
$score = 60;
|
||||
$isOpportunity = true;
|
||||
$tags[] = 'demo_day';
|
||||
}
|
||||
if (preg_match('/\b(accelerator|incubator|venture studio)\b/i', $text)) {
|
||||
$opportunityType = 'accelerator';
|
||||
$score = 80;
|
||||
$isOpportunity = true;
|
||||
$tags[] = 'accelerator';
|
||||
$type = 'investment';
|
||||
}
|
||||
if (preg_match('/\b(vc|venture capital|seed fund|series [a-z])\b/i', $text)) {
|
||||
$opportunityType = 'vc_funding';
|
||||
$score = 85;
|
||||
$isOpportunity = true;
|
||||
$tags[] = 'vc_funding';
|
||||
$type = 'investment';
|
||||
}
|
||||
if (preg_match('/\b(partnership|collaboration|strategic alliance)\b/i', $text)) {
|
||||
$type = 'partnership';
|
||||
$opportunityType = 'partnership';
|
||||
$score = 50;
|
||||
$isOpportunity = true;
|
||||
$tags[] = 'partnership';
|
||||
}
|
||||
if (preg_match('/\b(conference|summit|meetup|webinar|workshop)\b/i', $text)) {
|
||||
$type = 'event';
|
||||
$opportunityType = 'event';
|
||||
$score = 40;
|
||||
$tags[] = 'event';
|
||||
}
|
||||
|
||||
// Industry tags
|
||||
if (preg_match('/\b(ai|artificial intelligence|machine learning|deep learning)\b/i', $text)) {
|
||||
$tags[] = 'ai';
|
||||
}
|
||||
if (preg_match('/\b(fintech|financial technology|blockchain|crypto)\b/i', $text)) {
|
||||
$tags[] = 'fintech';
|
||||
}
|
||||
if (preg_match('/\b(saas|software|cloud)\b/i', $text)) {
|
||||
$tags[] = 'saas';
|
||||
}
|
||||
if (preg_match('/\b(mobility|transportation|ev|electric vehicle|logistics)\b/i', $text)) {
|
||||
$tags[] = 'mobility';
|
||||
}
|
||||
if (preg_match('/\b(healthtech|healthcare|biotech|medtech)\b/i', $text)) {
|
||||
$tags[] = 'healthtech';
|
||||
}
|
||||
if (preg_match('/\b(climate|cleantech|sustainability|green energy|renewable)\b/i', $text)) {
|
||||
$tags[] = 'cleantech';
|
||||
}
|
||||
|
||||
$tags = array_unique($tags);
|
||||
|
||||
return [
|
||||
'type' => $type,
|
||||
'opportunity_type' => $opportunityType,
|
||||
'score' => $score,
|
||||
'tags' => $tags,
|
||||
'is_opportunity' => $isOpportunity,
|
||||
'summary' => substr($description, 0, 200),
|
||||
'organization_name' => null,
|
||||
'country' => null,
|
||||
];
|
||||
}
|
||||
}
|
||||
249
app/Services/Crawler/Collector.php
Normal file
249
app/Services/Crawler/Collector.php
Normal file
@@ -0,0 +1,249 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Crawler;
|
||||
|
||||
use App\Services\Database\Connection;
|
||||
use App\Services\Database\ActivityLogger;
|
||||
use PDO;
|
||||
use Throwable;
|
||||
|
||||
class Collector
|
||||
{
|
||||
private PDO $pdo;
|
||||
private RssParser $rssParser;
|
||||
private AiAnalyzer $aiAnalyzer;
|
||||
private ActivityLogger $logger;
|
||||
|
||||
public function __construct(
|
||||
Connection $connection,
|
||||
RssParser $rssParser,
|
||||
AiAnalyzer $aiAnalyzer,
|
||||
ActivityLogger $logger
|
||||
) {
|
||||
$this->pdo = $connection->getPdo();
|
||||
$this->rssParser = $rssParser;
|
||||
$this->aiAnalyzer = $aiAnalyzer;
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect from all active sources.
|
||||
*/
|
||||
public function collectAll(): array
|
||||
{
|
||||
$results = [
|
||||
'total_sources' => 0,
|
||||
'processed' => 0,
|
||||
'errors' => 0,
|
||||
'new_opportunities' => 0,
|
||||
'new_organizations' => 0,
|
||||
'details' => [],
|
||||
];
|
||||
|
||||
$sources = $this->getActiveSources();
|
||||
|
||||
foreach ($sources as $source) {
|
||||
$results['total_sources']++;
|
||||
try {
|
||||
$result = $this->collectSource($source);
|
||||
$results['processed']++;
|
||||
$results['new_opportunities'] += $result['opportunities'];
|
||||
$results['new_organizations'] += $result['organizations'];
|
||||
$results['details'][] = [
|
||||
'source' => $source['name'],
|
||||
'type' => $source['type'],
|
||||
'status' => 'success',
|
||||
'entries_found' => $result['entries_found'],
|
||||
'new_opportunities' => $result['opportunities'],
|
||||
'new_organizations' => $result['organizations'],
|
||||
];
|
||||
} catch (Throwable $e) {
|
||||
$results['errors']++;
|
||||
$results['details'][] = [
|
||||
'source' => $source['name'],
|
||||
'type' => $source['type'],
|
||||
'status' => 'error',
|
||||
'error' => $e->getMessage(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$this->logger->log(null, 'collector_run', 'Collector completed: ' . json_encode([
|
||||
'total_sources' => $results['total_sources'],
|
||||
'processed' => $results['processed'],
|
||||
'errors' => $results['errors'],
|
||||
'new_opportunities' => $results['new_opportunities'],
|
||||
'new_organizations' => $results['new_organizations'],
|
||||
]));
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect from a single source.
|
||||
*/
|
||||
public function collectSource(array $source): array
|
||||
{
|
||||
$result = [
|
||||
'entries_found' => 0,
|
||||
'opportunities' => 0,
|
||||
'organizations' => 0,
|
||||
];
|
||||
|
||||
if ($source['type'] === 'rss') {
|
||||
$entries = $this->rssParser->fetchEntries($source['url']);
|
||||
$result['entries_found'] = count($entries);
|
||||
|
||||
foreach ($entries as $entry) {
|
||||
$this->processEntry($entry, $source, $result);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process a single entry: analyze, save opportunity, save organization.
|
||||
*/
|
||||
private function processEntry(array $entry, array $source, array &$result): void
|
||||
{
|
||||
// Skip if already exists
|
||||
if ($this->rssParser->entryExists($entry['url'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
// AI Analysis
|
||||
$analysis = $this->aiAnalyzer->analyze($entry['title'], $entry['description']);
|
||||
|
||||
// Extract organization if any
|
||||
$orgId = null;
|
||||
if (!empty($analysis['organization_name'])) {
|
||||
$orgId = $this->rssParser->organizationExists($analysis['organization_name']);
|
||||
}
|
||||
|
||||
// If no org found and AI suggests one, try to extract more details
|
||||
if (!$orgId && !empty($analysis['organization_name'])) {
|
||||
$orgData = $this->aiAnalyzer->extractOrganization($entry['title'] . ' ' . $entry['description']);
|
||||
if (!empty($orgData['name'])) {
|
||||
$orgId = $this->createOrganization($orgData);
|
||||
if ($orgId) {
|
||||
$result['organizations']++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create opportunity
|
||||
$this->createOpportunity($entry, $analysis, $orgId, $source);
|
||||
$result['opportunities']++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an organization record.
|
||||
*/
|
||||
private function createOrganization(array $data): ?int
|
||||
{
|
||||
try {
|
||||
$stmt = $this->pdo->prepare(
|
||||
"INSERT INTO organizations (name, description, type, country, website_url, crm_status)
|
||||
VALUES (?, ?, ?, ?, ?, 'New')"
|
||||
);
|
||||
$stmt->execute([
|
||||
$data['name'],
|
||||
$data['description'] ?? '',
|
||||
$data['type'] ?? 'partner',
|
||||
$data['country'] ?? null,
|
||||
$data['website'] ?? null,
|
||||
]);
|
||||
return (int)$this->pdo->lastInsertId();
|
||||
} catch (Throwable $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an opportunity record.
|
||||
*/
|
||||
private function createOpportunity(array $entry, array $analysis, ?int $orgId, array $source): void
|
||||
{
|
||||
try {
|
||||
$score = min(100, max(0, $analysis['score'] ?? 10));
|
||||
|
||||
$stmt = $this->pdo->prepare(
|
||||
"INSERT INTO opportunities (title, description, type, organization_id, url, status, score, raw_data)
|
||||
VALUES (?, ?, ?, ?, ?, 'active', ?, ?)"
|
||||
);
|
||||
$stmt->execute([
|
||||
$entry['title'],
|
||||
$analysis['summary'] ?? $entry['description'],
|
||||
$analysis['opportunity_type'] ?? $analysis['type'] ?? 'other',
|
||||
$orgId,
|
||||
$entry['url'],
|
||||
$score,
|
||||
json_encode([
|
||||
'source_id' => $source['id'] ?? null,
|
||||
'source_name' => $source['name'] ?? '',
|
||||
'published_at' => $entry['published_at'],
|
||||
'categories' => $entry['categories'] ?? [],
|
||||
'analysis' => $analysis,
|
||||
]),
|
||||
]);
|
||||
|
||||
$opportunityId = (int)$this->pdo->lastInsertId();
|
||||
|
||||
// Save tags
|
||||
if (!empty($analysis['tags'])) {
|
||||
foreach ($analysis['tags'] as $tagName) {
|
||||
$tagId = $this->getOrCreateTag($tagName);
|
||||
if ($tagId) {
|
||||
$stmt = $this->pdo->prepare(
|
||||
"INSERT IGNORE INTO opportunity_tags (opportunity_id, tag_id) VALUES (?, ?)"
|
||||
);
|
||||
$stmt->execute([$opportunityId, $tagId]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Throwable $e) {
|
||||
// Log but don't fail
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get or create a tag.
|
||||
*/
|
||||
private function getOrCreateTag(string $name): ?int
|
||||
{
|
||||
$slug = strtolower(preg_replace('/[^a-z0-9]+/', '-', $name));
|
||||
$slug = trim($slug, '-');
|
||||
|
||||
$stmt = $this->pdo->prepare("SELECT id FROM tags WHERE slug = ?");
|
||||
$stmt->execute([$slug]);
|
||||
$id = $stmt->fetchColumn();
|
||||
if ($id) {
|
||||
return (int)$id;
|
||||
}
|
||||
|
||||
try {
|
||||
$stmt = $this->pdo->prepare("INSERT INTO tags (name, slug) VALUES (?, ?)");
|
||||
$stmt->execute([$name, $slug]);
|
||||
return (int)$this->pdo->lastInsertId();
|
||||
} catch (Throwable $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all active sources.
|
||||
*/
|
||||
public function getActiveSources(): array
|
||||
{
|
||||
$stmt = $this->pdo->query(
|
||||
"SELECT s.*, GROUP_CONCAT(sc.category) as categories
|
||||
FROM sources s
|
||||
LEFT JOIN source_categories sc ON sc.source_id = s.id
|
||||
WHERE s.status = 'active'
|
||||
GROUP BY s.id"
|
||||
);
|
||||
return $stmt->fetchAll() ?: [];
|
||||
}
|
||||
}
|
||||
105
app/Services/Crawler/RssParser.php
Normal file
105
app/Services/Crawler/RssParser.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Crawler;
|
||||
|
||||
use App\Services\Database\Connection;
|
||||
use PDO;
|
||||
use Throwable;
|
||||
|
||||
class RssParser
|
||||
{
|
||||
private PDO $pdo;
|
||||
|
||||
public function __construct(Connection $connection)
|
||||
{
|
||||
$this->pdo = $connection->getPdo();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse an RSS feed URL and return entries.
|
||||
*/
|
||||
public function fetchEntries(string $url): array
|
||||
{
|
||||
$context = stream_context_create([
|
||||
'http' => [
|
||||
'timeout' => 15,
|
||||
'user_agent' => 'ScoutIQ/1.0 (Crawler)',
|
||||
],
|
||||
'ssl' => [
|
||||
'verify_peer' => false,
|
||||
'verify_peer_name' => false,
|
||||
],
|
||||
]);
|
||||
|
||||
$xml = @file_get_contents($url, false, $context);
|
||||
if (!$xml) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$feed = @simplexml_load_string($xml);
|
||||
if (!$feed) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$entries = [];
|
||||
$items = $feed->channel->item ?? $feed->entry ?? [];
|
||||
|
||||
foreach ($items as $item) {
|
||||
$title = (string)($item->title ?? '');
|
||||
$description = (string)($item->description ?? $item->summary ?? '');
|
||||
$link = (string)($item->link ?? $item->guid ?? '');
|
||||
$pubDate = (string)($item->pubDate ?? $item->updated ?? '');
|
||||
$categories = [];
|
||||
|
||||
if (isset($item->category)) {
|
||||
foreach ($item->category as $cat) {
|
||||
$categories[] = (string)$cat;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($title)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$entries[] = [
|
||||
'title' => $title,
|
||||
'description' => strip_tags($description),
|
||||
'url' => $link,
|
||||
'published_at' => $pubDate ? date('Y-m-d H:i:s', strtotime($pubDate)) : date('Y-m-d H:i:s'),
|
||||
'categories' => $categories,
|
||||
'source_raw' => $xml,
|
||||
];
|
||||
}
|
||||
|
||||
return $entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if entry URL already exists in opportunities.
|
||||
*/
|
||||
public function entryExists(string $url): bool
|
||||
{
|
||||
$stmt = $this->pdo->prepare("SELECT id FROM opportunities WHERE url = ? AND deleted_at IS NULL");
|
||||
$stmt->execute([$url]);
|
||||
return (bool)$stmt->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if organization already exists by domain or name.
|
||||
*/
|
||||
public function organizationExists(string $name, ?string $domain = null): ?int
|
||||
{
|
||||
if ($domain) {
|
||||
$stmt = $this->pdo->prepare("SELECT id FROM organizations WHERE domain = ? AND deleted_at IS NULL");
|
||||
$stmt->execute([$domain]);
|
||||
$id = $stmt->fetchColumn();
|
||||
if ($id) return (int)$id;
|
||||
}
|
||||
|
||||
// Fuzzy match by name
|
||||
$stmt = $this->pdo->prepare("SELECT id FROM organizations WHERE name LIKE ? AND deleted_at IS NULL LIMIT 1");
|
||||
$stmt->execute(['%' . $name . '%']);
|
||||
$id = $stmt->fetchColumn();
|
||||
return $id ? (int)$id : null;
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,9 @@ use App\Services\Database\Connection;
|
||||
use App\Services\Auth\AuthService;
|
||||
use App\Services\Auth\RBAC;
|
||||
use App\Services\Database\ActivityLogger;
|
||||
use App\Services\Crawler\RssParser;
|
||||
use App\Services\Crawler\AiAnalyzer;
|
||||
use App\Services\Crawler\Collector;
|
||||
use App\Middleware\CsrfProtection;
|
||||
use App\Middleware\RateLimit;
|
||||
use App\Middleware\SecurityHeaders;
|
||||
@@ -35,6 +38,11 @@ $container->singleton(AuthService::class, AuthService::class);
|
||||
$container->singleton(RBAC::class, RBAC::class);
|
||||
$container->singleton(ActivityLogger::class, ActivityLogger::class);
|
||||
|
||||
// Crawler services
|
||||
$container->singleton(RssParser::class, RssParser::class);
|
||||
$container->singleton(AiAnalyzer::class, AiAnalyzer::class);
|
||||
$container->singleton(Collector::class, Collector::class);
|
||||
|
||||
// Middleware bindings
|
||||
$container->bind(CsrfProtection::class, CsrfProtection::class);
|
||||
$container->bind(RateLimit::class, RateLimit::class);
|
||||
|
||||
35
cli.php
35
cli.php
@@ -23,6 +23,9 @@ require_once __DIR__ . '/database/seeds/DatabaseSeeder.php';
|
||||
use App\Core\Container;
|
||||
use App\Services\Database\Connection;
|
||||
use App\Services\Database\MigrationRunner;
|
||||
use App\Services\Crawler\RssParser;
|
||||
use App\Services\Crawler\AiAnalyzer;
|
||||
use App\Services\Crawler\Collector;
|
||||
use Database\Seeds\DatabaseSeeder;
|
||||
|
||||
$container = new Container();
|
||||
@@ -32,6 +35,11 @@ $container->singleton(Connection::class, Connection::class);
|
||||
$container->singleton(MigrationRunner::class, MigrationRunner::class);
|
||||
$container->singleton(DatabaseSeeder::class, DatabaseSeeder::class);
|
||||
|
||||
// Crawler service (needed for CLI collect command)
|
||||
$container->singleton(RssParser::class, RssParser::class);
|
||||
$container->singleton(AiAnalyzer::class, AiAnalyzer::class);
|
||||
$container->singleton(Collector::class, Collector::class);
|
||||
|
||||
$args = $argv;
|
||||
$command = $args[1] ?? 'help';
|
||||
|
||||
@@ -58,6 +66,32 @@ switch ($command) {
|
||||
}
|
||||
break;
|
||||
|
||||
case 'collect':
|
||||
echo "=== Running Data Collector ===\n";
|
||||
try {
|
||||
$collector = $container->get(Collector::class);
|
||||
$results = $collector->collectAll();
|
||||
|
||||
echo "\n--- Results ---\n";
|
||||
echo "Sources processed: {$results['processed']}/{$results['total_sources']}\n";
|
||||
echo "Errors: {$results['errors']}\n";
|
||||
echo "New opportunities: {$results['new_opportunities']}\n";
|
||||
echo "New organizations: {$results['new_organizations']}\n\n";
|
||||
|
||||
foreach ($results['details'] as $detail) {
|
||||
echo "[{$detail['status']}] {$detail['source']} ({$detail['type']}): ";
|
||||
if ($detail['status'] === 'success') {
|
||||
echo "{$detail['entries_found']} entries, {$detail['new_opportunities']} opps, {$detail['new_organizations']} orgs\n";
|
||||
} else {
|
||||
echo "ERROR: {$detail['error']}\n";
|
||||
}
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
echo "Collection failed: " . $e->getMessage() . "\n";
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'help':
|
||||
default:
|
||||
echo "ScoutIQ CLI Utility\n";
|
||||
@@ -65,6 +99,7 @@ switch ($command) {
|
||||
echo "Commands:\n";
|
||||
echo " migrate Run SQL database migrations\n";
|
||||
echo " seed Seed the database with default data\n";
|
||||
echo " collect Run data collector (RSS feeds)\n";
|
||||
echo " help Show this help menu\n";
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,10 @@ $app = require_once __DIR__ . '/../bootstrap/app.php';
|
||||
use App\Controllers\HomeController;
|
||||
use App\Controllers\AuthController;
|
||||
use App\Controllers\Admin\DashboardController;
|
||||
use App\Controllers\Admin\OrganizationsController;
|
||||
use App\Controllers\Admin\OpportunitiesController;
|
||||
use App\Controllers\Admin\ContactsController;
|
||||
use App\Controllers\Admin\SourcesController;
|
||||
use App\Middleware\SecurityHeaders;
|
||||
use App\Middleware\RateLimit;
|
||||
use App\Middleware\CsrfProtection;
|
||||
@@ -34,11 +38,53 @@ $app->router->group([
|
||||
'prefix' => '/admin',
|
||||
'middleware' => [Authenticate::class, CsrfProtection::class]
|
||||
], function($r) {
|
||||
// Dashboard
|
||||
$r->get('/dashboard', [DashboardController::class, 'index']);
|
||||
|
||||
// Organizations CRUD
|
||||
$r->get('/organizations', [OrganizationsController::class, 'index']);
|
||||
$r->get('/organizations/create', [OrganizationsController::class, 'create']);
|
||||
$r->post('/organizations/store', [OrganizationsController::class, 'store']);
|
||||
$r->get('/organizations/{id}', [OrganizationsController::class, 'show']);
|
||||
$r->get('/organizations/{id}/edit', [OrganizationsController::class, 'edit']);
|
||||
$r->post('/organizations/{id}/update', [OrganizationsController::class, 'store']);
|
||||
$r->get('/organizations/{id}/delete', [OrganizationsController::class, 'delete']);
|
||||
|
||||
// Opportunities
|
||||
$r->get('/opportunities', [OpportunitiesController::class, 'index']);
|
||||
$r->get('/opportunities/{id}', [OpportunitiesController::class, 'show']);
|
||||
|
||||
// Contacts CRUD
|
||||
$r->get('/contacts', [ContactsController::class, 'index']);
|
||||
$r->get('/contacts/create', [ContactsController::class, 'create']);
|
||||
$r->post('/contacts/store', [ContactsController::class, 'store']);
|
||||
$r->get('/contacts/{id}', [ContactsController::class, 'show']);
|
||||
$r->get('/contacts/{id}/edit', [ContactsController::class, 'edit']);
|
||||
$r->post('/contacts/{id}/update', [ContactsController::class, 'store']);
|
||||
$r->get('/contacts/{id}/delete', [ContactsController::class, 'delete']);
|
||||
$r->post('/contacts/{id}/interaction', [ContactsController::class, 'addInteraction']);
|
||||
|
||||
// Sources
|
||||
$r->get('/sources', [SourcesController::class, 'index']);
|
||||
$r->get('/sources/create', [SourcesController::class, 'create']);
|
||||
$r->post('/sources/store', [SourcesController::class, 'store']);
|
||||
$r->get('/sources/{id}/edit', [SourcesController::class, 'edit']);
|
||||
$r->post('/sources/{id}/update', [SourcesController::class, 'store']);
|
||||
$r->get('/sources/{id}/delete', [SourcesController::class, 'delete']);
|
||||
$r->get('/sources/{id}/run', [SourcesController::class, 'run']);
|
||||
});
|
||||
|
||||
// Logout endpoint
|
||||
$router->get('/logout', [AuthController::class, 'logout']);
|
||||
});
|
||||
|
||||
// API Routes (no CSRF, uses JWT)
|
||||
$app->router->group([
|
||||
'prefix' => '/api',
|
||||
'middleware' => [RateLimit::class, Authenticate::class]
|
||||
], function($r) {
|
||||
$r->get('/organizations', [OrganizationsController::class, 'index']);
|
||||
$r->get('/opportunities', [OpportunitiesController::class, 'index']);
|
||||
});
|
||||
|
||||
$app->run();
|
||||
|
||||
59
resources/views/admin/contacts/form.php
Normal file
59
resources/views/admin/contacts/form.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<div class="page-header">
|
||||
<h1><?= $contact ? 'Edit' : 'Add' ?> Contact</h1>
|
||||
</div>
|
||||
|
||||
<div class="glass-panel" style="max-width: 600px;">
|
||||
<form action="/admin/contacts/store" method="POST" class="form-stacked">
|
||||
<?php if ($contact): ?>
|
||||
<input type="hidden" name="id" value="<?= $contact['id'] ?>">
|
||||
<?php endif; ?>
|
||||
<input type="hidden" name="_csrf" value="<?= $this->session->getCsrfToken() ?>">
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-label">Name *</label>
|
||||
<input type="text" name="name" class="form-control" required value="<?= $contact ? $this->escape($contact['name']) : '' ?>">
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label class="form-label">Email</label>
|
||||
<input type="email" name="email" class="form-control" value="<?= $contact ? $this->escape($contact['email'] ?? '') : '' ?>">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">Phone</label>
|
||||
<input type="text" name="phone" class="form-control" value="<?= $contact ? $this->escape($contact['phone'] ?? '') : '' ?>">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-label">Position / Title</label>
|
||||
<input type="text" name="position" class="form-control" placeholder="e.g. Partner, Director" value="<?= $contact ? $this->escape($contact['position'] ?? '') : '' ?>">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-label">Organization</label>
|
||||
<select name="organization_id" class="form-control">
|
||||
<option value="">No Organization</option>
|
||||
<?php foreach ($organizations as $org): ?>
|
||||
<option value="<?= $org['id'] ?>" <?= ($selectedOrgId == $org['id']) ? 'selected' : '' ?>><?= $this->escape($org['name']) ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-label">Notes</label>
|
||||
<textarea name="notes" class="form-control" rows="3"><?= $contact ? $this->escape($contact['notes'] ?? '') : '' ?></textarea>
|
||||
</div>
|
||||
|
||||
<div style="display: flex; gap: 12px; margin-top: 10px;">
|
||||
<button type="submit" class="btn btn-primary"><?= $contact ? 'Update' : 'Create' ?> Contact</button>
|
||||
<a href="/admin/contacts" class="btn btn-secondary">Cancel</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.form-stacked { display: flex; flex-direction: column; gap: 16px; }
|
||||
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
|
||||
@media (max-width: 600px) { .form-row { grid-template-columns: 1fr; } }
|
||||
</style>
|
||||
67
resources/views/admin/contacts/index.php
Normal file
67
resources/views/admin/contacts/index.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<div class="page-header">
|
||||
<div>
|
||||
<h1>Contacts</h1>
|
||||
<p>Manage your network of investor contacts and interactions</p>
|
||||
</div>
|
||||
<a href="/admin/contacts/create" class="btn btn-primary">+ Add Contact</a>
|
||||
</div>
|
||||
|
||||
<?php if ($flashSuccess = $this->session->getFlash('success')): ?>
|
||||
<div class="alert alert-success"><span><?= $this->escape($flashSuccess) ?></span></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="filters-bar">
|
||||
<form method="GET" class="filters-form">
|
||||
<input type="text" name="search" class="form-control" placeholder="Search contacts..." value="<?= $this->escape($search) ?>">
|
||||
<button type="submit" class="btn btn-secondary">Search</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="glass-panel" style="overflow-x: auto;">
|
||||
<table class="data-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Position</th>
|
||||
<th>Organization</th>
|
||||
<th>Email</th>
|
||||
<th>Interactions</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (empty($contacts)): ?>
|
||||
<tr><td colspan="6" style="text-align: center; padding: 40px; color: var(--text-muted);">No contacts yet.</td></tr>
|
||||
<?php else: ?>
|
||||
<?php foreach ($contacts as $contact): ?>
|
||||
<tr>
|
||||
<td><a href="/admin/contacts/<?= $contact['id'] ?>" style="font-weight: 600;"><?= $this->escape($contact['name']) ?></a></td>
|
||||
<td><?= $this->escape($contact['position'] ?? '-') ?></td>
|
||||
<td><?= $contact['org_name'] ? $this->escape($contact['org_name']) : '-' ?></td>
|
||||
<td><?= $contact['email'] ? $this->escape($contact['email']) : '-' ?></td>
|
||||
<td><?= $contact['interaction_count'] ?? 0 ?></td>
|
||||
<td>
|
||||
<a href="/admin/contacts/<?= $contact['id'] ?>" class="btn btn-sm btn-secondary">View</a>
|
||||
<a href="/admin/contacts/<?= $contact['id'] ?>/edit" class="btn btn-sm btn-secondary">Edit</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<?php if ($total > $perPage): ?>
|
||||
<div class="pagination">
|
||||
<?php for ($i = 1; $i <= ceil($total / $perPage); $i++): ?>
|
||||
<a href="?page=<?= $i ?>&search=<?= urlencode($search) ?>" class="btn btn-sm <?= $i === $page ? 'btn-primary' : 'btn-secondary' ?>"><?= $i ?></a>
|
||||
<?php endfor; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<style>
|
||||
.data-table { width: 100%; border-collapse: collapse; }
|
||||
.data-table th, .data-table td { padding: 12px 16px; text-align: left; border-bottom: 1px solid rgba(255,255,255,0.05); }
|
||||
.data-table th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); font-weight: 600; }
|
||||
.data-table tr:hover { background: rgba(255,255,255,0.02); }
|
||||
</style>
|
||||
82
resources/views/admin/contacts/show.php
Normal file
82
resources/views/admin/contacts/show.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<div class="page-header">
|
||||
<div>
|
||||
<h1><?= $this->escape($contact['name']) ?></h1>
|
||||
<p><?= $contact['position'] ? $this->escape($contact['position']) . ' • ' : '' ?><?= $contact['org_name'] ? $this->escape($contact['org_name']) : 'Independent' ?></p>
|
||||
</div>
|
||||
<div style="display: flex; gap: 10px;">
|
||||
<a href="/admin/contacts/<?= $contact['id'] ?>/edit" class="btn btn-secondary">Edit</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if ($flashSuccess = $this->session->getFlash('success')): ?>
|
||||
<div class="alert alert-success"><span><?= $this->escape($flashSuccess) ?></span></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="detail-grid">
|
||||
<div class="glass-panel">
|
||||
<h3 style="margin-bottom: 20px;">Contact Details</h3>
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">Email</span>
|
||||
<span><?= $contact['email'] ? $this->escape($contact['email']) : '-' ?></span>
|
||||
</div>
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">Phone</span>
|
||||
<span><?= $contact['phone'] ? $this->escape($contact['phone']) : '-' ?></span>
|
||||
</div>
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">Position</span>
|
||||
<span><?= $this->escape($contact['position'] ?? '-') ?></span>
|
||||
</div>
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">Organization</span>
|
||||
<span><?= $contact['org_id'] ? '<a href="/admin/organizations/' . $contact['org_id'] . '">' . $this->escape($contact['org_name']) . '</a>' : '-' ?></span>
|
||||
</div>
|
||||
<div class="detail-row" style="flex-direction: column; align-items: flex-start;">
|
||||
<span class="detail-label">Notes</span>
|
||||
<p style="margin-top: 8px; line-height: 1.6;"><?= $this->escape($contact['notes'] ?? 'No notes') ?></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<!-- Interactions -->
|
||||
<div class="glass-panel" style="margin-bottom: 20px;">
|
||||
<h3 style="margin-bottom: 16px;">Interactions (<?= count($interactions) ?>)</h3>
|
||||
|
||||
<form action="/admin/contacts/<?= $contact['id'] ?>/interaction" method="POST" style="display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px;">
|
||||
<input type="hidden" name="_csrf" value="<?= $this->session->getCsrfToken() ?>">
|
||||
<div class="form-row" style="display: flex; gap: 10px;">
|
||||
<select name="type" class="form-control" style="flex: 0 0 120px;">
|
||||
<option value="note">Note</option>
|
||||
<option value="email">Email</option>
|
||||
<option value="call">Call</option>
|
||||
<option value="meeting">Meeting</option>
|
||||
</select>
|
||||
<input type="text" name="notes" class="form-control" placeholder="Add interaction note..." required>
|
||||
<button type="submit" class="btn btn-primary">Log</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<?php if (empty($interactions)): ?>
|
||||
<p style="color: var(--text-muted);">No interactions logged yet.</p>
|
||||
<?php else: ?>
|
||||
<?php foreach ($interactions as $interaction): ?>
|
||||
<div class="list-item">
|
||||
<div style="display: flex; justify-content: space-between; align-items: center;">
|
||||
<span class="badge" style="background: rgba(56, 189, 248, 0.2); color: #38bdf8;"><?= $this->escape($interaction['type']) ?></span>
|
||||
<small style="color: var(--text-muted);"><?= date('M j, g:i a', strtotime($interaction['created_at'])) ?></small>
|
||||
</div>
|
||||
<p style="margin-top: 8px; line-height: 1.5;"><?= $this->escape($interaction['notes']) ?></p>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
|
||||
.detail-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid rgba(255,255,255,0.05); }
|
||||
.detail-label { font-size: 0.85rem; color: var(--text-muted); font-weight: 600; }
|
||||
.list-item { padding: 12px 0; border-bottom: 1px solid rgba(255,255,255,0.05); }
|
||||
@media (max-width: 768px) { .detail-grid { grid-template-columns: 1fr; } }
|
||||
</style>
|
||||
101
resources/views/admin/opportunities/index.php
Normal file
101
resources/views/admin/opportunities/index.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<div class="page-header">
|
||||
<div>
|
||||
<h1>Opportunities</h1>
|
||||
<p>Grants, competitions, events, partnerships and investment opportunities</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Filters -->
|
||||
<div class="filters-bar">
|
||||
<form method="GET" class="filters-form">
|
||||
<input type="text" name="search" class="form-control" placeholder="Search opportunities..." value="<?= $this->escape($search) ?>">
|
||||
<select name="type" class="form-control">
|
||||
<option value="">All Types</option>
|
||||
<?php foreach ($types as $t): ?>
|
||||
<option value="<?= $t ?>" <?= $type === $t ? 'selected' : '' ?>><?= ucfirst($t) ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<select name="status" class="form-control">
|
||||
<option value="">All Statuses</option>
|
||||
<?php foreach ($statuses as $s): ?>
|
||||
<option value="<?= $s ?>" <?= $status === $s ? 'selected' : '' ?>><?= ucfirst($s) ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<button type="submit" class="btn btn-secondary">Filter</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- Type Summary -->
|
||||
<div class="metrics-grid" style="margin-bottom: 20px;">
|
||||
<div class="glass-panel metric-card">
|
||||
<span class="metric-title">Total</span>
|
||||
<span class="metric-value"><?= $total ?></span>
|
||||
</div>
|
||||
<?php foreach ($typeCounts as $t => $c): ?>
|
||||
<div class="glass-panel metric-card">
|
||||
<span class="metric-title"><?= ucfirst($t) ?></span>
|
||||
<span class="metric-value"><?= $c ?></span>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
|
||||
<!-- Table -->
|
||||
<div class="glass-panel" style="overflow-x: auto;">
|
||||
<table class="data-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Title</th>
|
||||
<th>Type</th>
|
||||
<th>Source</th>
|
||||
<th>Score</th>
|
||||
<th>Status</th>
|
||||
<th>Created</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (empty($opportunities)): ?>
|
||||
<tr><td colspan="7" style="text-align: center; padding: 40px; color: var(--text-muted);">No opportunities yet. Run the collector first.</td></tr>
|
||||
<?php else: ?>
|
||||
<?php foreach ($opportunities as $opp): ?>
|
||||
<tr>
|
||||
<td>
|
||||
<a href="/admin/opportunities/<?= $opp['id'] ?>" style="font-weight: 600;"><?= $this->escape(mb_substr($opp['title'], 0, 60)) ?></a>
|
||||
<?php if ($opp['tag_names']): ?>
|
||||
<br><small style="color: var(--text-muted);"><?= $this->escape(implode(', ', explode(',', $opp['tag_names']))) ?></small>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td><span class="badge badge-type-<?= $opp['type'] ?>"><?= $this->escape($opp['type']) ?></span></td>
|
||||
<td><?= $opp['org_name'] ? $this->escape($opp['org_name']) : '-' ?></td>
|
||||
<td><span class="badge" style="background: rgba(251, 191, 36, 0.2); color: #fbbf24;"><?= $opp['score'] ?></span></td>
|
||||
<td><?= $this->escape($opp['status']) ?></td>
|
||||
<td><?= date('M j', strtotime($opp['created_at'])) ?></td>
|
||||
<td><a href="<?= $this->escape($opp['url']) ?>" target="_blank" class="btn btn-sm btn-secondary">Open</a></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- Pagination -->
|
||||
<?php if ($total > $perPage): ?>
|
||||
<div class="pagination">
|
||||
<?php for ($i = 1; $i <= ceil($total / $perPage); $i++): ?>
|
||||
<a href="?page=<?= $i ?>&type=<?= $type ?>&status=<?= $status ?>&search=<?= urlencode($search) ?>" class="btn btn-sm <?= $i === $page ? 'btn-primary' : 'btn-secondary' ?>"><?= $i ?></a>
|
||||
<?php endfor; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<style>
|
||||
.data-table { width: 100%; border-collapse: collapse; }
|
||||
.data-table th, .data-table td { padding: 12px 16px; text-align: left; border-bottom: 1px solid rgba(255,255,255,0.05); }
|
||||
.data-table th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); font-weight: 600; }
|
||||
.data-table tr:hover { background: rgba(255,255,255,0.02); }
|
||||
.badge-type-grant { background: rgba(52, 211, 153, 0.2); color: #34d399; }
|
||||
.badge-type-competition { background: rgba(251, 191, 36, 0.2); color: #fbbf24; }
|
||||
.badge-type-investment { background: rgba(139, 92, 246, 0.2); color: #a78bfa; }
|
||||
.badge-type-event { background: rgba(56, 189, 248, 0.2); color: #38bdf8; }
|
||||
.badge-type-demo_day { background: rgba(248, 113, 113, 0.2); color: #f87171; }
|
||||
.badge-type-partnership { background: rgba(167, 139, 250, 0.2); color: #c4b5fd; }
|
||||
</style>
|
||||
88
resources/views/admin/opportunities/show.php
Normal file
88
resources/views/admin/opportunities/show.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<div class="page-header">
|
||||
<div>
|
||||
<h1><?= $this->escape(mb_substr($opportunity['title'], 0, 80)) ?></h1>
|
||||
<p>
|
||||
<span class="badge badge-type-<?= $opportunity['type'] ?>"><?= $this->escape($opportunity['type']) ?></span>
|
||||
<span class="badge" style="background: rgba(251, 191, 36, 0.2); color: #fbbf24;">Score: <?= $opportunity['score'] ?></span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="detail-grid">
|
||||
<div class="glass-panel">
|
||||
<h3 style="margin-bottom: 20px;">Details</h3>
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">Status</span>
|
||||
<span><?= $this->escape($opportunity['status']) ?></span>
|
||||
</div>
|
||||
<?php if ($opportunity['org_name']): ?>
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">Organization</span>
|
||||
<span><a href="/admin/organizations/<?= $opportunity['organization_id'] ?>"><?= $this->escape($opportunity['org_name']) ?></a></span>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">URL</span>
|
||||
<span><a href="<?= $this->escape($opportunity['url']) ?>" target="_blank">Open Link →</a></span>
|
||||
</div>
|
||||
<?php if ($opportunity['deadline']): ?>
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">Deadline</span>
|
||||
<span><?= date('M j, Y', strtotime($opportunity['deadline'])) ?></span>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if ($opportunity['amount']): ?>
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">Amount</span>
|
||||
<span>$<?= number_format($opportunity['amount']) ?></span>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">Created</span>
|
||||
<span><?= date('M j, Y', strtotime($opportunity['created_at'])) ?></span>
|
||||
</div>
|
||||
<?php if ($opportunity['tag_names']): ?>
|
||||
<div class="detail-row" style="flex-direction: column; align-items: flex-start;">
|
||||
<span class="detail-label">Tags</span>
|
||||
<div style="display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px;">
|
||||
<?php foreach (explode(',', $opportunity['tag_names']) as $tag): ?>
|
||||
<span class="badge" style="background: rgba(139, 92, 246, 0.2); color: #c4b5fd;"><?= $this->escape(trim($tag)) ?></span>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<div class="detail-row" style="flex-direction: column; align-items: flex-start;">
|
||||
<span class="detail-label">Description</span>
|
||||
<p style="margin-top: 8px; line-height: 1.6;"><?= $this->escape($opportunity['description']) ?></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<div class="glass-panel">
|
||||
<h3 style="margin-bottom: 16px;">Applications (<?= count($applications) ?>)</h3>
|
||||
<?php if (empty($applications)): ?>
|
||||
<p style="color: var(--text-muted);">No applications tracked yet.</p>
|
||||
<?php else: ?>
|
||||
<?php foreach ($applications as $app): ?>
|
||||
<div class="list-item">
|
||||
<div style="display: flex; justify-content: space-between;">
|
||||
<span><?= date('M j', strtotime($app['created_at'])) ?></span>
|
||||
<span class="badge" style="background: rgba(56, 189, 248, 0.2); color: #38bdf8;"><?= $this->escape($app['status']) ?></span>
|
||||
</div>
|
||||
<?php if ($app['notes']): ?>
|
||||
<p style="margin-top: 4px; font-size: 0.9rem; color: var(--text-muted);"><?= $this->escape($app['notes']) ?></p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
|
||||
.detail-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid rgba(255,255,255,0.05); }
|
||||
.detail-label { font-size: 0.85rem; color: var(--text-muted); font-weight: 600; }
|
||||
.list-item { padding: 12px 0; border-bottom: 1px solid rgba(255,255,255,0.05); }
|
||||
@media (max-width: 768px) { .detail-grid { grid-template-columns: 1fr; } }
|
||||
</style>
|
||||
83
resources/views/admin/organizations/form.php
Normal file
83
resources/views/admin/organizations/form.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<div class="page-header">
|
||||
<h1><?= $org ? 'Edit' : 'Add' ?> Organization</h1>
|
||||
</div>
|
||||
|
||||
<?php if ($flashError = $this->session->getFlash('error')): ?>
|
||||
<div class="alert alert-error"><span><?= $this->escape($flashError) ?></span></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="glass-panel" style="max-width: 700px;">
|
||||
<form action="/admin/organizations/<?= $org ? 'store' : 'store' ?>" method="POST" class="form-stacked">
|
||||
<?php if ($org): ?>
|
||||
<input type="hidden" name="id" value="<?= $org['id'] ?>">
|
||||
<?php endif; ?>
|
||||
<input type="hidden" name="_csrf" value="<?= $this->session->getCsrfToken() ?>">
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label class="form-label">Name *</label>
|
||||
<input type="text" name="name" class="form-control" required value="<?= $org ? $this->escape($org['name']) : '' ?>">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">Domain</label>
|
||||
<input type="text" name="domain" class="form-control" placeholder="example.com" value="<?= $org ? $this->escape($org['domain'] ?? '') : '' ?>">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label class="form-label">Type</label>
|
||||
<select name="type" class="form-control">
|
||||
<?php foreach ($types as $t): ?>
|
||||
<option value="<?= $t ?>" <?= ($org && $org['type'] === $t) ? 'selected' : '' ?>><?= ucfirst($t) ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">CRM Status</label>
|
||||
<select name="crm_status" class="form-control">
|
||||
<?php foreach ($statuses as $s): ?>
|
||||
<option value="<?= $s ?>" <?= ($org && $org['crm_status'] === $s) ? 'selected' : '' ?>><?= $s ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label class="form-label">Country</label>
|
||||
<input type="text" name="country" class="form-control" placeholder="e.g. UAE" value="<?= $org ? $this->escape($org['country'] ?? '') : '' ?>">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">City</label>
|
||||
<input type="text" name="city" class="form-control" placeholder="e.g. Dubai" value="<?= $org ? $this->escape($org['city'] ?? '') : '' ?>">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-label">Website URL</label>
|
||||
<input type="url" name="website_url" class="form-control" placeholder="https://example.com" value="<?= $org ? $this->escape($org['website_url'] ?? '') : '' ?>">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-label">Funding Stage</label>
|
||||
<input type="text" name="funding_stage" class="form-control" placeholder="e.g. Seed, Series A" value="<?= $org ? $this->escape($org['funding_stage'] ?? '') : '' ?>">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-label">Description</label>
|
||||
<textarea name="description" class="form-control" rows="4"><?= $org ? $this->escape($org['description'] ?? '') : '' ?></textarea>
|
||||
</div>
|
||||
|
||||
<div style="display: flex; gap: 12px; margin-top: 20px;">
|
||||
<button type="submit" class="btn btn-primary"><?= $org ? 'Update' : 'Create' ?> Organization</button>
|
||||
<a href="/admin/organizations" class="btn btn-secondary">Cancel</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.form-stacked { display: flex; flex-direction: column; gap: 16px; }
|
||||
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
|
||||
@media (max-width: 600px) { .form-row { grid-template-columns: 1fr; } }
|
||||
</style>
|
||||
115
resources/views/admin/organizations/index.php
Normal file
115
resources/views/admin/organizations/index.php
Normal file
@@ -0,0 +1,115 @@
|
||||
<div class="page-header">
|
||||
<div>
|
||||
<h1>Organizations</h1>
|
||||
<p>Manage VCs, accelerators, incubators and investors</p>
|
||||
</div>
|
||||
<a href="/admin/organizations/create" class="btn btn-primary">+ Add Organization</a>
|
||||
</div>
|
||||
|
||||
<?php if ($flashSuccess = $this->session->getFlash('success')): ?>
|
||||
<div class="alert alert-success"><span><?= $this->escape($flashSuccess) ?></span></div>
|
||||
<?php endif; ?>
|
||||
<?php if ($flashError = $this->session->getFlash('error')): ?>
|
||||
<div class="alert alert-error"><span><?= $this->escape($flashError) ?></span></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- Filters -->
|
||||
<div class="filters-bar">
|
||||
<form method="GET" class="filters-form">
|
||||
<input type="text" name="search" class="form-control" placeholder="Search organizations..." value="<?= $this->escape($search) ?>">
|
||||
<select name="type" class="form-control">
|
||||
<option value="">All Types</option>
|
||||
<?php foreach ($types as $t): ?>
|
||||
<option value="<?= $t ?>" <?= $type === $t ? 'selected' : '' ?>><?= ucfirst($t) ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<button type="submit" class="btn btn-secondary">Filter</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- Stats Summary -->
|
||||
<div class="metrics-grid" style="margin-bottom: 20px;">
|
||||
<div class="glass-panel metric-card">
|
||||
<span class="metric-title">Total Organizations</span>
|
||||
<span class="metric-value"><?= $total ?></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Table -->
|
||||
<div class="glass-panel" style="overflow-x: auto;">
|
||||
<table class="data-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Type</th>
|
||||
<th>Country</th>
|
||||
<th>CRM Status</th>
|
||||
<th>Opportunities</th>
|
||||
<th>Updated</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (empty($organizations)): ?>
|
||||
<tr><td colspan="7" style="text-align: center; padding: 40px; color: var(--text-muted);">No organizations found. Run the collector or add one manually.</td></tr>
|
||||
<?php else: ?>
|
||||
<?php foreach ($organizations as $org): ?>
|
||||
<tr>
|
||||
<td>
|
||||
<a href="/admin/organizations/<?= $org['id'] ?>" style="font-weight: 600;">
|
||||
<?= $this->escape($org['name']) ?>
|
||||
</a>
|
||||
<?php if ($org['domain']): ?>
|
||||
<br><small style="color: var(--text-muted);"><?= $this->escape($org['domain']) ?></small>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td><span class="badge badge-<?= $org['type'] ?>"><?= $this->escape($org['type']) ?></span></td>
|
||||
<td><?= $this->escape($org['country'] ?? '-') ?></td>
|
||||
<td><span class="badge badge-status-<?= strtolower(str_replace(' ', '-', $org['crm_status'])) ?>"><?= $this->escape($org['crm_status']) ?></span></td>
|
||||
<td><?= $org['opportunities_count'] ?? 0 ?></td>
|
||||
<td><?= date('M j', strtotime($org['updated_at'])) ?></td>
|
||||
<td>
|
||||
<a href="/admin/organizations/<?= $org['id'] ?>" class="btn btn-sm btn-secondary">View</a>
|
||||
<a href="/admin/organizations/<?= $org['id'] ?>/edit" class="btn btn-sm btn-secondary">Edit</a>
|
||||
<a href="/admin/contacts/create?organization_id=<?= $org['id'] ?>" class="btn btn-sm btn-secondary">+ Contact</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- Pagination -->
|
||||
<?php if ($total > $perPage): ?>
|
||||
<div class="pagination">
|
||||
<?php for ($i = 1; $i <= ceil($total / $perPage); $i++): ?>
|
||||
<a href="?page=<?= $i ?>&type=<?= $type ?>&search=<?= urlencode($search) ?>" class="btn btn-sm <?= $i === $page ? 'btn-primary' : 'btn-secondary' ?>"><?= $i ?></a>
|
||||
<?php endfor; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<style>
|
||||
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
|
||||
.filters-bar { margin-bottom: 20px; }
|
||||
.filters-form { display: flex; gap: 12px; flex-wrap: wrap; }
|
||||
.filters-form .form-control { min-width: 200px; }
|
||||
.data-table { width: 100%; border-collapse: collapse; }
|
||||
.data-table th, .data-table td { padding: 12px 16px; text-align: left; border-bottom: 1px solid rgba(255,255,255,0.05); }
|
||||
.data-table th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); font-weight: 600; }
|
||||
.data-table tr:hover { background: rgba(255,255,255,0.02); }
|
||||
.badge { display: inline-block; padding: 4px 10px; border-radius: 12px; font-size: 0.78rem; font-weight: 600; }
|
||||
.badge-vc { background: rgba(139, 92, 246, 0.2); color: #a78bfa; }
|
||||
.badge-angel { background: rgba(251, 191, 36, 0.2); color: #fbbf24; }
|
||||
.badge-accelerator { background: rgba(52, 211, 153, 0.2); color: #34d399; }
|
||||
.badge-incubator { background: rgba(56, 189, 248, 0.2); color: #38bdf8; }
|
||||
.badge-venture_studio { background: rgba(248, 113, 113, 0.2); color: #f87171; }
|
||||
.badge-partner { background: rgba(167, 139, 250, 0.2); color: #a78bfa; }
|
||||
.badge-status-new { background: rgba(96, 165, 250, 0.2); color: #60a5fa; }
|
||||
.badge-status-researching { background: rgba(251, 191, 36, 0.2); color: #fbbf24; }
|
||||
.badge-status-contacted { background: rgba(52, 211, 153, 0.2); color: #34d399; }
|
||||
.badge-status-invested { background: rgba(34, 197, 94, 0.2); color: #22c55e; }
|
||||
.badge-status-rejected { background: rgba(239, 68, 68, 0.2); color: #ef4444; }
|
||||
.pagination { display: flex; gap: 8px; margin-top: 20px; justify-content: center; }
|
||||
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
|
||||
</style>
|
||||
108
resources/views/admin/organizations/show.php
Normal file
108
resources/views/admin/organizations/show.php
Normal file
@@ -0,0 +1,108 @@
|
||||
<div class="page-header">
|
||||
<div>
|
||||
<h1><?= $this->escape($org['name']) ?></h1>
|
||||
<p><?= $this->escape(ucfirst($org['type'])) ?> • <?= $this->escape($org['country'] ?? 'Unknown location') ?></p>
|
||||
</div>
|
||||
<div style="display: flex; gap: 10px;">
|
||||
<a href="/admin/organizations/<?= $org['id'] ?>/edit" class="btn btn-secondary">Edit</a>
|
||||
<a href="/admin/contacts/create?organization_id=<?= $org['id'] ?>" class="btn btn-primary">+ Add Contact</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if ($flashSuccess = $this->session->getFlash('success')): ?>
|
||||
<div class="alert alert-success"><span><?= $this->escape($flashSuccess) ?></span></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="detail-grid">
|
||||
<!-- Left: Details -->
|
||||
<div class="glass-panel">
|
||||
<h3 style="margin-bottom: 20px;">Details</h3>
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">Domain</span>
|
||||
<span><?= $org['domain'] ? $this->escape($org['domain']) : '-' ?></span>
|
||||
</div>
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">Website</span>
|
||||
<span><?= $org['website_url'] ? '<a href="' . $this->escape($org['website_url']) . '" target="_blank">' . $this->escape($org['website_url']) . '</a>' : '-' ?></span>
|
||||
</div>
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">Country</span>
|
||||
<span><?= $this->escape($org['country'] ?? '-') ?></span>
|
||||
</div>
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">City</span>
|
||||
<span><?= $this->escape($org['city'] ?? '-') ?></span>
|
||||
</div>
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">CRM Status</span>
|
||||
<span><span class="badge badge-status-<?= strtolower(str_replace(' ', '-', $org['crm_status'])) ?>"><?= $this->escape($org['crm_status']) ?></span></span>
|
||||
</div>
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">Funding Stage</span>
|
||||
<span><?= $this->escape($org['funding_stage'] ?? '-') ?></span>
|
||||
</div>
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">Created</span>
|
||||
<span><?= date('M j, Y', strtotime($org['created_at'])) ?></span>
|
||||
</div>
|
||||
<div class="detail-row" style="flex-direction: column; align-items: flex-start;">
|
||||
<span class="detail-label">Description</span>
|
||||
<p style="margin-top: 8px; line-height: 1.6;"><?= $this->escape($org['description'] ?? 'No description') ?></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Right: Opportunities & Contacts -->
|
||||
<div>
|
||||
<div class="glass-panel" style="margin-bottom: 20px;">
|
||||
<h3 style="margin-bottom: 16px;">Opportunities (<?= count($opportunities) ?>)</h3>
|
||||
<?php if (empty($opportunities)): ?>
|
||||
<p style="color: var(--text-muted);">No opportunities linked to this organization yet.</p>
|
||||
<?php else: ?>
|
||||
<?php foreach ($opportunities as $opp): ?>
|
||||
<div class="list-item">
|
||||
<div>
|
||||
<a href="/admin/opportunities/<?= $opp['id'] ?>" style="font-weight: 600;"><?= $this->escape($opp['title']) ?></a>
|
||||
<div style="display: flex; gap: 8px; margin-top: 6px;">
|
||||
<span class="badge badge-type-<?= $opp['type'] ?>"><?= $this->escape($opp['type']) ?></span>
|
||||
<span class="badge" style="background: rgba(251, 191, 36, 0.2); color: #fbbf24;">Score: <?= $opp['score'] ?></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<div class="glass-panel">
|
||||
<h3 style="margin-bottom: 16px;">Contacts (<?= count($contacts) ?>)</h3>
|
||||
<?php if (empty($contacts)): ?>
|
||||
<p style="color: var(--text-muted);">No contacts added yet.</p>
|
||||
<?php else: ?>
|
||||
<?php foreach ($contacts as $contact): ?>
|
||||
<div class="list-item">
|
||||
<div>
|
||||
<a href="/admin/contacts/<?= $contact['id'] ?>" style="font-weight: 600;"><?= $this->escape($contact['name']) ?></a>
|
||||
<div style="font-size: 0.85rem; color: var(--text-muted);">
|
||||
<?= $this->escape($contact['position'] ?? '') ?>
|
||||
<?= $contact['email'] ? ' • ' . $this->escape($contact['email']) : '' ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
|
||||
.detail-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid rgba(255,255,255,0.05); }
|
||||
.detail-label { font-size: 0.85rem; color: var(--text-muted); font-weight: 600; }
|
||||
.list-item { padding: 12px 0; border-bottom: 1px solid rgba(255,255,255,0.05); }
|
||||
.list-item:last-child { border-bottom: none; }
|
||||
.badge-type-grant { background: rgba(52, 211, 153, 0.2); color: #34d399; }
|
||||
.badge-type-competition { background: rgba(251, 191, 36, 0.2); color: #fbbf24; }
|
||||
.badge-type-investment { background: rgba(139, 92, 246, 0.2); color: #a78bfa; }
|
||||
.badge-type-event { background: rgba(56, 189, 248, 0.2); color: #38bdf8; }
|
||||
.badge-type-partnership { background: rgba(167, 139, 250, 0.2); color: #c4b5fd; }
|
||||
@media (max-width: 768px) { .detail-grid { grid-template-columns: 1fr; } }
|
||||
</style>
|
||||
46
resources/views/admin/sources/form.php
Normal file
46
resources/views/admin/sources/form.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<div class="page-header">
|
||||
<h1><?= $source ? 'Edit' : 'Add' ?> Source</h1>
|
||||
</div>
|
||||
|
||||
<div class="glass-panel" style="max-width: 600px;">
|
||||
<form action="/admin/sources/store" method="POST" class="form-stacked">
|
||||
<?php if ($source): ?>
|
||||
<input type="hidden" name="id" value="<?= $source['id'] ?>">
|
||||
<?php endif; ?>
|
||||
<input type="hidden" name="_csrf" value="<?= $this->session->getCsrfToken() ?>">
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-label">Name</label>
|
||||
<input type="text" name="name" class="form-control" required value="<?= $source ? $this->escape($source['name']) : '' ?>">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">URL</label>
|
||||
<input type="url" name="url" class="form-control" required value="<?= $source ? $this->escape($source['url']) : '' ?>" placeholder="https://example.com/rss">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label class="form-label">Type</label>
|
||||
<select name="type" class="form-control">
|
||||
<option value="rss" <?= $source && $source['type'] === 'rss' ? 'selected' : '' ?>>RSS Feed</option>
|
||||
<option value="api" <?= $source && $source['type'] === 'api' ? 'selected' : '' ?>>API</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">Status</label>
|
||||
<select name="status" class="form-control">
|
||||
<option value="active" <?= $source && $source['status'] === 'active' ? 'selected' : '' ?>>Active</option>
|
||||
<option value="inactive" <?= $source && $source['status'] === 'inactive' ? 'selected' : '' ?>>Inactive</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div style="display: flex; gap: 12px; margin-top: 10px;">
|
||||
<button type="submit" class="btn btn-primary">Save Source</button>
|
||||
<a href="/admin/sources" class="btn btn-secondary">Cancel</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.form-stacked { display: flex; flex-direction: column; gap: 16px; }
|
||||
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
|
||||
</style>
|
||||
60
resources/views/admin/sources/index.php
Normal file
60
resources/views/admin/sources/index.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<div class="page-header">
|
||||
<div>
|
||||
<h1>Data Sources</h1>
|
||||
<p>Manage RSS feeds and API sources for data collection</p>
|
||||
</div>
|
||||
<a href="/admin/sources/create" class="btn btn-primary">+ Add Source</a>
|
||||
</div>
|
||||
|
||||
<?php if ($flashSuccess = $this->session->getFlash('success')): ?>
|
||||
<div class="alert alert-success"><span><?= $this->escape($flashSuccess) ?></span></div>
|
||||
<?php endif; ?>
|
||||
<?php if ($flashError = $this->session->getFlash('error')): ?>
|
||||
<div class="alert alert-error"><span><?= $this->escape($flashError) ?></span></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="glass-panel" style="overflow-x: auto;">
|
||||
<table class="data-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>URL</th>
|
||||
<th>Type</th>
|
||||
<th>Status</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (empty($sources)): ?>
|
||||
<tr><td colspan="5" style="text-align: center; padding: 40px; color: var(--text-muted);">No data sources configured.</td></tr>
|
||||
<?php else: ?>
|
||||
<?php foreach ($sources as $source): ?>
|
||||
<tr>
|
||||
<td style="font-weight: 600;"><?= $this->escape($source['name']) ?></td>
|
||||
<td style="max-width: 300px; overflow: hidden; text-overflow: ellipsis;">
|
||||
<a href="<?= $this->escape($source['url']) ?>" target="_blank" style="font-size: 0.85rem;"><?= $this->escape($source['url']) ?></a>
|
||||
</td>
|
||||
<td><span class="badge badge-source-<?= $source['type'] ?>"><?= $this->escape($source['type']) ?></span></td>
|
||||
<td><span class="badge <?= $source['status'] === 'active' ? 'badge-active' : 'badge-inactive' ?>"><?= $this->escape($source['status']) ?></span></td>
|
||||
<td>
|
||||
<a href="/admin/sources/<?= $source['id'] ?>/run" class="btn btn-sm btn-primary" onclick="return confirm('Run collector on this source?')">Run</a>
|
||||
<a href="/admin/sources/<?= $source['id'] ?>/edit" class="btn btn-sm btn-secondary">Edit</a>
|
||||
<a href="/admin/sources/<?= $source['id'] ?>/delete" class="btn btn-sm btn-secondary" onclick="return confirm('Delete this source?')">Delete</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.data-table { width: 100%; border-collapse: collapse; }
|
||||
.data-table th, .data-table td { padding: 12px 16px; text-align: left; border-bottom: 1px solid rgba(255,255,255,0.05); }
|
||||
.data-table th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); font-weight: 600; }
|
||||
.data-table tr:hover { background: rgba(255,255,255,0.02); }
|
||||
.badge-source-rss { background: rgba(251, 191, 36, 0.2); color: #fbbf24; }
|
||||
.badge-source-api { background: rgba(52, 211, 153, 0.2); color: #34d399; }
|
||||
.badge-active { background: rgba(34, 197, 94, 0.2); color: #22c55e; }
|
||||
.badge-inactive { background: rgba(239, 68, 68, 0.2); color: #ef4444; }
|
||||
</style>
|
||||
Reference in New Issue
Block a user