This commit is contained in:
Flatlogic Bot 2026-02-28 18:39:14 +00:00
parent a67fbbdaf5
commit 306361e5fb
2 changed files with 142 additions and 39 deletions

View File

@ -9,6 +9,27 @@ require_once __DIR__ . '/db/config.php';
$error = '';
$success = '';
$existingStartup = null;
$startup_id = (int)($_GET['id'] ?? 0);
if ($startup_id > 0) {
$stmt = db()->prepare("SELECT * FROM startups WHERE id = ? AND founder_id = ?");
$stmt->execute([$startup_id, $_SESSION['user_id']]);
$existingStartup = $stmt->fetch();
if (!$existingStartup) {
header("Location: startups.php");
exit;
}
// Check if there is already an active round
$stmt = db()->prepare("SELECT id FROM funding_rounds WHERE startup_id = ? AND status = 'Active'");
$stmt->execute([$startup_id]);
if ($stmt->fetch()) {
header("Location: startup_details.php?id=" . $startup_id);
exit;
}
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$name = trim($_POST['name'] ?? '');
@ -16,23 +37,31 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$target = (float)($_POST['funding_target'] ?? 0);
$status = $_POST['status'] ?? 'public';
if (empty($name) || empty($description) || $target < 50) {
if ((!$existingStartup && empty($name)) || (!$existingStartup && empty($description)) || $target < 50) {
$error = "Please fill in all required fields. Minimum target is £50.";
} else {
db()->beginTransaction();
try {
// 1. Insert startup (keep target/raised for compatibility/legacy but we'll use funding_rounds)
$stmt = db()->prepare("INSERT INTO startups (name, description, founder_id, funding_target, status) VALUES (?, ?, ?, ?, ?)");
$stmt->execute([$name, $description, $_SESSION['user_id'], $target, $status]);
$startup_id = db()->lastInsertId();
// 2. Insert initial funding round
$stmt = db()->prepare("INSERT INTO funding_rounds (startup_id, funding_goal, status) VALUES (?, ?, 'Active')");
$stmt->execute([$startup_id, $target]);
if ($existingStartup) {
// Just create a new round for existing startup
$stmt = db()->prepare("INSERT INTO funding_rounds (startup_id, funding_goal, status) VALUES (?, ?, 'Active')");
$stmt->execute([$existingStartup['id'], $target]);
$final_id = $existingStartup['id'];
} else {
// 1. Insert startup
$stmt = db()->prepare("INSERT INTO startups (name, description, founder_id, funding_target, status) VALUES (?, ?, ?, ?, ?)");
$stmt->execute([$name, $description, $_SESSION['user_id'], $target, $status]);
$new_startup_id = db()->lastInsertId();
// 2. Insert initial funding round
$stmt = db()->prepare("INSERT INTO funding_rounds (startup_id, funding_goal, status) VALUES (?, ?, 'Active')");
$stmt->execute([$new_startup_id, $target]);
$final_id = $new_startup_id;
}
db()->commit();
$success = "Startup listed successfully! Your funding round is now active.";
header("refresh:2;url=dashboard.php");
$success = "Funding round is now active!";
header("refresh:2;url=startup_details.php?id=" . $final_id);
} catch (PDOException $e) {
db()->rollBack();
$error = "Database error: " . $e->getMessage();
@ -47,7 +76,7 @@ $platformName = defined('PLATFORM_NAME') ? PLATFORM_NAME : 'Gatsby';
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Start Funding Round <?= htmlspecialchars($platformName) ?></title>
<title><?= $existingStartup ? 'Start New Round' : 'Start Funding Round' ?> — <?= htmlspecialchars($platformName) ?></title>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&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">
@ -55,8 +84,10 @@ $platformName = defined('PLATFORM_NAME') ? PLATFORM_NAME : 'Gatsby';
<body style="display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 40px 20px;">
<div class="card" style="width: 100%; max-width: 600px;">
<h2 style="margin-bottom: 10px;">List Your Startup</h2>
<p style="color: var(--text-secondary); margin-bottom: 30px;">Kickstart your project with micro-investments from peers.</p>
<h2 style="margin-bottom: 10px;"><?= $existingStartup ? 'Start New Round for ' . htmlspecialchars($existingStartup['name']) : 'List Your Startup' ?></h2>
<p style="color: var(--text-secondary); margin-bottom: 30px;">
<?= $existingStartup ? 'Set a new funding goal for your existing venture.' : 'Kickstart your project with micro-investments from peers.' ?>
</p>
<?php if ($error): ?>
<div style="background: rgba(255, 0, 0, 0.1); border: 1px solid rgba(255, 0, 0, 0.3); color: #ff5555; padding: 12px; border-radius: 8px; margin-bottom: 20px;">
@ -70,27 +101,32 @@ $platformName = defined('PLATFORM_NAME') ? PLATFORM_NAME : 'Gatsby';
</div>
<?php else: ?>
<form method="POST">
<div style="margin-bottom: 15px;">
<label style="display: block; margin-bottom: 8px; font-size: 14px; font-weight: 500;">Startup Name</label>
<input type="text" name="name" required style="width: 100%; padding: 12px; border-radius: 12px; background: var(--surface-color); border: 1px solid var(--border-color); color: #fff;">
</div>
<div style="margin-bottom: 15px;">
<label style="display: block; margin-bottom: 8px; font-size: 14px; font-weight: 500;">Description</label>
<textarea name="description" required style="width: 100%; padding: 12px; border-radius: 12px; background: var(--surface-color); border: 1px solid var(--border-color); color: #fff; height: 120px; resize: none;"></textarea>
</div>
<?php if (!$existingStartup): ?>
<div style="margin-bottom: 15px;">
<label style="display: block; margin-bottom: 8px; font-size: 14px; font-weight: 500;">Startup Name</label>
<input type="text" name="name" required style="width: 100%; padding: 12px; border-radius: 12px; background: var(--surface-color); border: 1px solid var(--border-color); color: #fff;">
</div>
<div style="margin-bottom: 15px;">
<label style="display: block; margin-bottom: 8px; font-size: 14px; font-weight: 500;">Description</label>
<textarea name="description" required style="width: 100%; padding: 12px; border-radius: 12px; background: var(--surface-color); border: 1px solid var(--border-color); color: #fff; height: 120px; resize: none;"></textarea>
</div>
<div style="margin-bottom: 25px;">
<label style="display: block; margin-bottom: 8px; font-size: 14px; font-weight: 500;">Listing Type</label>
<select name="status" style="width: 100%; padding: 12px; border-radius: 12px; background: var(--surface-color); border: 1px solid var(--border-color); color: #fff;">
<option value="public">Public (Visible to all investors)</option>
<option value="private">Private (Invite-only)</option>
</select>
</div>
<?php endif; ?>
<div style="margin-bottom: 15px;">
<label style="display: block; margin-bottom: 8px; font-size: 14px; font-weight: 500;">Funding Target (£)</label>
<input type="number" name="funding_target" min="50" step="50" required style="width: 100%; padding: 12px; border-radius: 12px; background: var(--surface-color); border: 1px solid var(--border-color); color: #fff;">
<span style="font-size: 12px; color: var(--text-secondary); margin-top: 4px; display: block;">Min investment per user will be £50.</span>
</div>
<div style="margin-bottom: 25px;">
<label style="display: block; margin-bottom: 8px; font-size: 14px; font-weight: 500;">Listing Type</label>
<select name="status" style="width: 100%; padding: 12px; border-radius: 12px; background: var(--surface-color); border: 1px solid var(--border-color); color: #fff;">
<option value="public">Public (Visible to all investors)</option>
<option value="private">Private (Invite-only)</option>
</select>
</div>
<button type="submit" class="btn btn-primary" style="width: 100%; padding: 15px;">Launch Funding Round</button>
<button type="submit" class="btn btn-primary" style="width: 100%; padding: 15px;"><?= $existingStartup ? 'Launch New Round' : 'Launch Funding Round' ?></button>
<a href="<?= $existingStartup ? 'startup_details.php?id=' . $startup_id : 'dashboard.php' ?>" class="btn btn-secondary" style="width: 100%; padding: 15px; margin-top: 10px; display: block; text-align: center; text-decoration: none;">Cancel</a>
</form>
<?php endif; ?>
</div>

View File

@ -26,7 +26,7 @@ $stmt = db()->prepare("SELECT id FROM startup_followers WHERE user_id = ? AND st
$stmt->execute([$user_id, $startup_id]);
$isFollowing = $stmt->fetch();
// Actions: follow/unfollow, invest, post_update
// Actions: follow/unfollow, invest, post_update, finish_round, cancel_round
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 (?, ?)");
@ -43,8 +43,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
$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("INSERT INTO investments (investor_id, startup_id, funding_round_id, amount, status) VALUES (?, ?, ?, ?, 'approved')");
$stmt->execute([$user_id, $startup_id, $round['id'], $amount]);
$stmt = db()->prepare("UPDATE funding_rounds SET funding_raised = funding_raised + ? WHERE id = ?");
$stmt->execute([$amount, $round['id']]);
@ -83,6 +83,50 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
}
$success = "Update posted successfully!";
}
} elseif ($_POST['action'] === 'finish_round' && $user['role'] === 'founder' && $startup['founder_id'] == $user_id) {
$stmt = db()->prepare("UPDATE funding_rounds SET status = 'Closed' WHERE startup_id = ? AND status = 'Active'");
$stmt->execute([$startup_id]);
$success = "Funding round successfully closed!";
} elseif ($_POST['action'] === 'cancel_round' && $user['role'] === 'founder' && $startup['founder_id'] == $user_id) {
db()->beginTransaction();
try {
// Find active round
$stmt = db()->prepare("SELECT id FROM funding_rounds WHERE startup_id = ? AND status = 'Active'");
$stmt->execute([$startup_id]);
$round = $stmt->fetch();
if ($round) {
// Cancel round
$stmt = db()->prepare("UPDATE funding_rounds SET status = 'Cancelled' WHERE id = ?");
$stmt->execute([$round['id']]);
// Refund all investments in this round
$stmt = db()->prepare("UPDATE investments SET status = 'Refunded' WHERE funding_round_id = ?");
$stmt->execute([$round['id']]);
// Deduct from startup total raised
$stmt = db()->prepare("SELECT SUM(amount) as total FROM investments WHERE funding_round_id = ? AND status = 'Refunded'");
$stmt->execute([$round['id']]);
$totalRefunded = $stmt->fetch()['total'] ?? 0;
$stmt = db()->prepare("UPDATE startups SET funding_raised = GREATEST(0, funding_raised - ?) WHERE id = ?");
$stmt->execute([$totalRefunded, $startup_id]);
db()->commit();
$success = "Funding round cancelled and all investments marked for refund.";
// Refresh data
$stmt = db()->prepare("SELECT * FROM startups WHERE id = ?");
$stmt->execute([$startup_id]);
$startup = $stmt->fetch();
} else {
db()->rollBack();
$error = "No active round found to cancel.";
}
} catch (Exception $e) {
db()->rollBack();
$error = "Error: " . $e->getMessage();
}
}
}
@ -100,7 +144,7 @@ if ($canSeeHistory) {
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'
WHERE i.startup_id = ? AND i.status != 'rejected'
ORDER BY i.created_at DESC
");
$stmt->execute([$startup_id]);
@ -222,8 +266,12 @@ if ($canSeeHistory) {
</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 style="font-weight: 800; font-size: 18px; color: <?= $inv['status'] === 'Refunded' ? '#ff5555' : 'var(--accent-blue)' ?>;">
<?= $inv['status'] === 'Refunded' ? '-' : '' ?>£<?= number_format($inv['amount']) ?>
</div>
<div style="font-size: 11px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 1px;">
<?= $inv['status'] === 'Refunded' ? 'Refunded' : 'Investment' ?>
</div>
</div>
</div>
<?php endforeach; ?>
@ -290,7 +338,7 @@ if ($canSeeHistory) {
<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 style="font-size: 11px; color: var(--text-secondary);">Investments</div>
</div>
<div>
<div style="font-weight: 700;"><?= $startup['followers_count'] ?? 0 ?></div>
@ -327,11 +375,30 @@ if ($canSeeHistory) {
<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;">
<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; margin-bottom: 20px;">
<i class="fas fa-info-circle"></i> This is your active funding round. Share the link with potential investors to reach your goal.
</div>
<div style="display: flex; flex-direction: column; gap: 10px;">
<form method="POST" onsubmit="return confirm('Are you sure you want to finish this round early? Future investments will be disabled until you start a new round.')">
<input type="hidden" name="action" value="finish_round">
<button type="submit" class="btn btn-outline" style="width: 100%; border-color: var(--accent-blue); color: var(--accent-blue);"><i class="fas fa-check-circle"></i> Finish Round Early</button>
</form>
<form method="POST" onsubmit="return confirm('DANGER: This will cancel the current round and mark all investments as REFUNDED. This cannot be undone. Proceed?')">
<input type="hidden" name="action" value="cancel_round">
<button type="submit" class="btn btn-outline" style="width: 100%; border-color: #ff5555; color: #ff5555;"><i class="fas fa-times-circle"></i> Cancel & Refund All</button>
</form>
</div>
<?php endif; ?>
</section>
<?php else: ?>
<?php if ($user['role'] === 'founder' && $startup['founder_id'] == $user_id): ?>
<section class="card" style="margin-bottom: 30px; text-align: center; border: 2px dashed var(--border-color);">
<i class="fas fa-plus-circle" style="font-size: 32px; color: var(--accent-blue); margin-bottom: 15px; opacity: 0.5;"></i>
<h4 style="margin: 0 0 10px 0;">No Active Round</h4>
<p style="font-size: 13px; color: var(--text-secondary); margin-bottom: 20px;">Ready to raise more capital?</p>
<a href="start_funding.php?id=<?= $startup_id ?>" class="btn btn-primary" style="width: 100%;">Start New Round</a>
</section>
<?php endif; ?>
<?php endif; ?>
<section class="card">
@ -368,4 +435,4 @@ if ($canSeeHistory) {
<script src="assets/js/main.js"></script>
</body>
</html>
</html>