38873-vm/startup_details.php
Flatlogic Bot ffcaed889a s21
2026-02-28 18:28:06 +00:00

371 lines
23 KiB
PHP

<?php
require_once 'db/config.php';
session_start();
$user_id = $_SESSION['user_id'] ?? null;
if (!$user_id) { header('Location: login.php'); exit; }
$stmt = db()->prepare("SELECT * FROM users WHERE id = ?");
$stmt->execute([$user_id]);
$user = $stmt->fetch();
if (!$user) { header('Location: login.php'); exit; }
$startup_id = (int)($_GET['id'] ?? 0);
$stmt = db()->prepare("SELECT * FROM startups WHERE id = ?");
$stmt->execute([$startup_id]);
$startup = $stmt->fetch();
if (!$startup) { header('Location: startups.php'); exit; }
$platformName = defined('PLATFORM_NAME') ? PLATFORM_NAME : 'Gatsby';
$error = '';
$success = '';
// Check if user is following
$stmt = db()->prepare("SELECT id FROM startup_followers WHERE user_id = ? AND startup_id = ?");
$stmt->execute([$user_id, $startup_id]);
$isFollowing = $stmt->fetch();
// Actions: follow/unfollow, invest, post_update
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
if ($_POST['action'] === 'follow') {
$stmt = db()->prepare("INSERT IGNORE INTO startup_followers (user_id, startup_id) VALUES (?, ?)");
$stmt->execute([$user_id, $startup_id]);
$success = "You are now following " . $startup['name'] . "!";
} elseif ($_POST['action'] === 'unfollow') {
$stmt = db()->prepare("DELETE FROM startup_followers WHERE user_id = ? AND startup_id = ?");
$stmt->execute([$user_id, $startup_id]);
$success = "You have unfollowed " . $startup['name'] . ".";
} elseif ($_POST['action'] === 'invest' && $user['role'] === 'investor') {
$amount = (float)($_POST['amount'] ?? 0);
if ($amount > 0) {
$stmt = db()->prepare("SELECT * FROM funding_rounds WHERE startup_id = ? AND status = 'Active'");
$stmt->execute([$startup_id]);
$round = $stmt->fetch();
if ($round) {
$stmt = db()->prepare("INSERT INTO investments (investor_id, startup_id, amount, status) VALUES (?, ?, ?, 'approved')");
$stmt->execute([$user_id, $startup_id, $amount]);
$stmt = db()->prepare("UPDATE funding_rounds SET funding_raised = funding_raised + ? WHERE id = ?");
$stmt->execute([$amount, $round['id']]);
$stmt = db()->prepare("UPDATE startups SET funding_raised = funding_raised + ? WHERE id = ?");
$stmt->execute([$amount, $startup_id]);
// Create notification for founder
$notif = db()->prepare("INSERT INTO notifications (user_id, content) VALUES (?, ?)");
$notif->execute([$startup['founder_id'], $user['full_name'] . " just invested £" . number_format($amount) . " in " . $startup['name'] . "!"]);
$success = "Investment of £" . number_format($amount) . " successfully processed!";
// Refresh data
$stmt = db()->prepare("SELECT * FROM startups WHERE id = ?");
$stmt->execute([$startup_id]);
$startup = $stmt->fetch();
}
}
} elseif ($_POST['action'] === 'post_update' && $user['role'] === 'founder' && $startup['founder_id'] == $user_id) {
$title = $_POST['update_title'] ?? '';
$content = $_POST['update_content'] ?? '';
if ($title && $content) {
$stmt = db()->prepare("INSERT INTO startup_updates (startup_id, title, content) VALUES (?, ?, ?)");
$stmt->execute([$startup_id, $title, $content]);
// Notify followers
$stmt = db()->prepare("SELECT user_id FROM startup_followers WHERE startup_id = ?");
$stmt->execute([$startup_id]);
$followers = $stmt->fetchAll(PDO::FETCH_COLUMN);
if (!empty($followers)) {
$notif = db()->prepare("INSERT INTO notifications (user_id, content) VALUES (?, ?)");
foreach ($followers as $f_id) {
$notif->execute([$f_id, "New update from " . $startup['name'] . ": " . $title]);
}
}
$success = "Update posted successfully!";
}
}
}
$stmt = db()->prepare("SELECT * FROM funding_rounds WHERE startup_id = ? AND status = 'Active'");
$stmt->execute([$startup_id]);
$activeRound = $stmt->fetch();
// Permission check for Funding History: Founders see their own, Investors see all.
$canSeeHistory = ($user['role'] === 'investor' || ($user['role'] === 'founder' && $startup['founder_id'] == $user_id));
// Fetch Funding History
$fundingHistory = [];
if ($canSeeHistory) {
$stmt = db()->prepare("
SELECT i.*, u.full_name as investor_name, u.profile_photo as investor_photo
FROM investments i
JOIN users u ON i.investor_id = u.id
WHERE i.startup_id = ? AND i.status = 'approved'
ORDER BY i.created_at DESC
");
$stmt->execute([$startup_id]);
$fundingHistory = $stmt->fetchAll();
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?= htmlspecialchars($startup['name']) ?> — <?= htmlspecialchars($platformName) ?></title>
<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;500;600;700;800;900&display=swap" rel="stylesheet">
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
</head>
<body>
<header>
<div class="container" style="display: flex; justify-content: space-between; align-items: center; width: 100%;">
<a href="dashboard.php" class="logo-container">
<img src="assets/images/logo.svg" alt="<?= htmlspecialchars($platformName) ?> Logo" class="logo-img">
<span class="logo-text"><?= htmlspecialchars($platformName) ?></span>
</a>
<nav class="nav-links">
<?php if ($user['role'] === 'founder'): ?>
<a href="startups.php">My Startups</a>
<a href="partners.php">Find Partners</a>
<?php else: ?>
<a href="startups.php">Browse Startups</a>
<a href="portfolio.php">Portfolio</a>
<?php endif; ?>
<a href="discover.php">Discovery Hub</a>
<a href="messages.php">Messages</a>
</nav>
<div style="display: flex; align-items: center; gap: 15px;">
<a href="notifications.php" style="color: var(--text-secondary); position: relative; font-size: 18px;">
<i class="fas fa-bell"></i>
</a>
<div style="display: flex; align-items: center; gap: 10px; padding: 5px 12px; background: rgba(255,255,255,0.05); border-radius: 50px; border: 1px solid var(--border-color);">
<div style="width: 24px; height: 24px; background: var(--gradient-primary); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 10px; color: #fff; font-weight: 800;">
<?= substr($user['full_name'], 0, 1) ?>
</div>
<span style="font-size: 13px; font-weight: 600;"><?= htmlspecialchars(explode(' ', $user['full_name'])[0]) ?></span>
</div>
<a href="logout.php" class="btn btn-secondary" style="padding: 8px 16px; font-size: 12px; border-radius: 10px;">Log Out</a>
</div>
</div>
</header>
<main class="container" style="padding-top: 50px; padding-bottom: 50px;">
<?php if ($error): ?>
<div class="alert alert-danger" style="margin-bottom: 30px;"><?= htmlspecialchars($error) ?></div>
<?php endif; ?>
<?php if ($success): ?>
<div class="alert alert-success" style="margin-bottom: 30px;"><?= htmlspecialchars($success) ?></div>
<?php endif; ?>
<div style="display: grid; grid-template-columns: 2fr 1.2fr; gap: 40px;">
<div>
<div style="display: flex; align-items: center; gap: 20px; margin-bottom: 30px;">
<div style="width: 80px; height: 80px; background: var(--gradient-primary); border-radius: 20px; display: flex; align-items: center; justify-content: center; color: white; font-size: 32px; font-weight: 700;">
<?= substr($startup['name'], 0, 1) ?>
</div>
<div style="flex: 1;">
<h1 style="margin: 0; font-size: 36px;"><?= htmlspecialchars($startup['name']) ?></h1>
<div style="color: var(--text-secondary); display: flex; align-items: center; gap: 10px;">
<span><i class="fas fa-calendar-alt"></i> Founded <?= date('M Y', strtotime($startup['created_at'])) ?></span>
<span class="badge"><?= ucfirst($startup['status']) ?></span>
</div>
</div>
<?php if ($startup['founder_id'] != $user_id): ?>
<form method="POST">
<?php if ($isFollowing): ?>
<input type="hidden" name="action" value="unfollow">
<button type="submit" class="btn btn-outline" style="border-radius: 50px; padding: 10px 25px;"><i class="fas fa-check"></i> Following</button>
<?php else: ?>
<input type="hidden" name="action" value="follow">
<button type="submit" class="btn btn-primary" style="border-radius: 50px; padding: 10px 25px;"><i class="fas fa-plus"></i> Follow</button>
<?php endif; ?>
</form>
<?php endif; ?>
</div>
<section class="card" style="margin-bottom: 40px;">
<h2 style="margin-top: 0; margin-bottom: 20px;">About the Venture</h2>
<p style="font-size: 18px; line-height: 1.6; color: var(--text-secondary); white-space: pre-wrap;"><?= htmlspecialchars($startup['description']) ?></p>
</section>
<!-- Funding History Section -->
<?php if ($canSeeHistory): ?>
<section class="card" style="margin-bottom: 40px;">
<h2 style="margin-top: 0; margin-bottom: 25px; display: flex; align-items: center; gap: 12px;">
<i class="fas fa-history" style="color: var(--accent-blue);"></i> Funding History
</h2>
<?php if (empty($fundingHistory)): ?>
<div style="padding: 40px; text-align: center; background: rgba(255,255,255,0.02); border-radius: 20px; border: 1px dashed var(--border-color);">
<i class="fas fa-coins" style="font-size: 32px; color: var(--text-secondary); opacity: 0.3; margin-bottom: 15px;"></i>
<p style="color: var(--text-secondary); margin: 0; font-style: italic;">No investment history available yet.</p>
</div>
<?php else: ?>
<div style="display: flex; flex-direction: column; gap: 15px;">
<?php foreach ($fundingHistory as $inv): ?>
<div style="display: flex; align-items: center; justify-content: space-between; padding: 20px; background: rgba(255,255,255,0.03); border-radius: 18px; border: 1px solid var(--border-color);">
<div style="display: flex; align-items: center; gap: 15px;">
<div style="width: 45px; height: 45px; border-radius: 12px; background: var(--surface-color); border: 1px solid var(--border-color); display: flex; align-items: center; justify-content: center; overflow: hidden;">
<?php if ($inv['investor_photo']): ?>
<img src="<?= htmlspecialchars($inv['investor_photo']) ?>" style="width: 100%; height: 100%; object-fit: cover;">
<?php else: ?>
<span style="font-weight: 800; color: var(--accent-blue);"><?= substr($inv['investor_name'], 0, 1) ?></span>
<?php endif; ?>
</div>
<div>
<div style="font-weight: 700; font-size: 16px;"><?= htmlspecialchars($inv['investor_name']) ?></div>
<div style="font-size: 12px; color: var(--text-secondary);"><?= date('M d, Y', strtotime($inv['created_at'])) ?></div>
</div>
</div>
<div style="text-align: right;">
<div style="font-weight: 800; font-size: 18px; color: var(--accent-blue);">£<?= number_format($inv['amount']) ?></div>
<div style="font-size: 11px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 1px;">Investment</div>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</section>
<?php endif; ?>
<section class="card" style="margin-bottom: 40px;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
<h2 style="margin: 0;">Public Updates</h2>
<?php if ($user['role'] === 'founder' && $startup['founder_id'] == $user_id): ?>
<button class="btn btn-outline" onclick="document.getElementById('postUpdateForm').style.display='block'">Post Update</button>
<?php endif; ?>
</div>
<?php if ($user['role'] === 'founder' && $startup['founder_id'] == $user_id): ?>
<div id="postUpdateForm" style="display: none; background: rgba(255,255,255,0.02); padding: 25px; border-radius: 15px; margin-bottom: 30px; border: 1px solid var(--border-color);">
<h4 style="margin-top: 0;">New Progress Report</h4>
<form method="POST">
<input type="hidden" name="action" value="post_update">
<div class="form-group" style="margin-bottom: 15px;">
<label>Title</label>
<input type="text" name="update_title" class="form-control" placeholder="e.g. Prototype Finished!" required style="background: var(--surface-color); color: #fff; border: 1px solid var(--border-color);">
</div>
<div class="form-group" style="margin-bottom: 15px;">
<label>What's happening?</label>
<textarea name="update_content" class="form-control" rows="5" placeholder="Share your progress with backers and followers..." required style="background: var(--surface-color); color: #fff; border: 1px solid var(--border-color);"></textarea>
</div>
<button type="submit" class="btn btn-primary">Post & Notify Everyone</button>
<button type="button" class="btn btn-secondary" onclick="document.getElementById('postUpdateForm').style.display='none'">Cancel</button>
</form>
</div>
<?php endif; ?>
<?php
$stmt = db()->prepare("SELECT * FROM startup_updates WHERE startup_id = ? ORDER BY created_at DESC");
$stmt->execute([$startup_id]);
$updates = $stmt->fetchAll();
?>
<?php if (empty($updates)): ?>
<p style="color: var(--text-secondary); font-style: italic;">No updates have been posted yet.</p>
<?php else: ?>
<?php foreach ($updates as $upd): ?>
<div style="border-bottom: 1px solid var(--border-color); padding-bottom: 25px; margin-bottom: 25px;">
<h4 style="margin: 0 0 10px 0;"><?= htmlspecialchars($upd['title']) ?></h4>
<div style="font-size: 13px; color: var(--text-secondary); margin-bottom: 15px;">
<i class="fas fa-clock"></i> Posted on <?= date('M d, Y', strtotime($upd['created_at'])) ?>
</div>
<p style="color: var(--text-secondary); line-height: 1.6; white-space: pre-wrap;"><?= htmlspecialchars($upd['content']) ?></p>
</div>
<?php endforeach; ?>
<?php endif; ?>
</section>
</div>
<div>
<!-- Sidebar with Financial Stats -->
<section class="card" style="margin-bottom: 30px; border-left: 4px solid var(--accent-blue);">
<h4 style="margin-top: 0; color: var(--text-secondary); text-transform: uppercase; font-size: 12px; letter-spacing: 1px;">Venture Financials</h4>
<div style="margin: 20px 0;">
<div style="font-size: 32px; font-weight: 900; color: var(--text-primary);">£<?= number_format($startup['funding_raised']) ?></div>
<div style="font-size: 13px; color: var(--text-secondary);">Total Raised All-Time</div>
</div>
<div style="height: 1px; background: var(--border-color); margin: 20px 0;"></div>
<div style="display: flex; justify-content: space-between; align-items: center;">
<div>
<div style="font-weight: 700;"><?= count($fundingHistory) ?></div>
<div style="font-size: 11px; color: var(--text-secondary);">Investors</div>
</div>
<div>
<div style="font-weight: 700;"><?= $startup['followers_count'] ?? 0 ?></div>
<div style="font-size: 11px; color: var(--text-secondary);">Followers</div>
</div>
<div>
<div style="font-weight: 700;">Seed</div>
<div style="font-size: 11px; color: var(--text-secondary);">Stage</div>
</div>
</div>
</section>
<?php if ($activeRound): ?>
<section class="card" style="margin-bottom: 30px; background: linear-gradient(135deg, rgba(0, 122, 255, 0.05) 0%, rgba(0, 242, 255, 0.05) 100%);">
<h3 style="margin-top: 0;">Active Round</h3>
<div style="margin: 20px 0;">
<?php $percent = ($activeRound['funding_goal'] > 0) ? min(100, ($activeRound['funding_raised'] / $activeRound['funding_goal']) * 100) : 0; ?>
<div style="width: 100%; height: 10px; background: var(--border-color); border-radius: 5px; overflow: hidden; margin-bottom: 10px;">
<div style="width: <?= $percent ?>%; height: 100%; background: var(--gradient-primary);"></div>
</div>
<div style="display: flex; justify-content: space-between; font-size: 14px; font-weight: 600;">
<span>£<?= number_format($activeRound['funding_raised']) ?></span>
<span style="color: var(--text-secondary);">£<?= number_format($activeRound['funding_goal']) ?> target</span>
</div>
</div>
<?php if ($user['role'] === 'investor'): ?>
<form method="POST" style="margin-top: 25px;">
<input type="hidden" name="action" value="invest">
<div class="form-group" style="margin-bottom: 15px;">
<label style="font-size: 13px; font-weight: 600;">Investment Amount (£)</label>
<input type="number" name="amount" class="form-control" min="100" step="100" value="1000" style="background: var(--surface-color); color: #fff; border: 1px solid var(--border-color); font-size: 18px; font-weight: 700;">
</div>
<button type="submit" class="btn btn-primary" style="width: 100%; padding: 15px; font-weight: 700; font-size: 16px;">Back this Venture</button>
</form>
<?php elseif ($user['role'] === 'founder' && $startup['founder_id'] == $user_id): ?>
<div style="background: rgba(0,0,0,0.2); padding: 15px; border-radius: 12px; font-size: 13px; color: var(--text-secondary); line-height: 1.5;">
<i class="fas fa-info-circle"></i> This is your active funding round. Share the link with potential investors to reach your goal.
</div>
<?php endif; ?>
</section>
<?php endif; ?>
<section class="card">
<h3 style="margin-top: 0;">Founder</h3>
<?php
$stmt = db()->prepare("SELECT * FROM users WHERE id = ?");
$stmt->execute([$startup['founder_id']]);
$founder = $stmt->fetch();
?>
<div style="display: flex; align-items: center; gap: 15px; margin-top: 20px;">
<div style="width: 50px; height: 50px; background: var(--surface-color); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 20px; font-weight: 800; color: #fff; border: 2px solid var(--accent-blue);">
<?= substr($founder['full_name'], 0, 1) ?>
</div>
<div>
<div style="font-weight: 700;"><?= htmlspecialchars($founder['full_name'] ?? 'Founder') ?></div>
<div style="font-size: 13px; color: var(--text-secondary);"><?= htmlspecialchars($founder['university'] ?? 'Founder') ?></div>
</div>
</div>
<a href="messages.php?chat_with=<?= $founder['id'] ?>" class="btn btn-secondary" style="width: 100%; margin-top: 20px; padding: 12px; border-radius: 12px;">Send Message</a>
</section>
</div>
</div>
</main>
<footer style="margin-top: 80px; padding: 60px 0; border-top: 1px solid var(--border-color); background: rgba(0,0,0,0.2);">
<div class="container" style="text-align: center;">
<div class="logo-container" style="justify-content: center; margin-bottom: 25px;">
<img src="assets/images/logo.svg" alt="<?= htmlspecialchars($platformName) ?> Logo" class="logo-img" style="width: 30px; height: 30px;">
<span class="logo-text" style="font-size: 20px;"><?= htmlspecialchars($platformName) ?></span>
</div>
<p style="color: var(--text-secondary); font-size: 14px;">&copy; <?= date('Y') ?> <?= htmlspecialchars($platformName) ?>. All rights reserved.</p>
</div>
</footer>
<script src="assets/js/main.js"></script>
</body>
</html>