v8
This commit is contained in:
parent
9141a82a52
commit
eedf246822
11
db/migrations/06_startup_updates.sql
Normal file
11
db/migrations/06_startup_updates.sql
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
-- Migration: Add startup_updates table for founder progress reports
|
||||||
|
CREATE TABLE IF NOT EXISTS startup_updates (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
startup_id INT NOT NULL,
|
||||||
|
founder_id INT NOT NULL,
|
||||||
|
title VARCHAR(255) NOT NULL,
|
||||||
|
content TEXT NOT NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
FOREIGN KEY (startup_id) REFERENCES startups(id) ON DELETE CASCADE,
|
||||||
|
FOREIGN KEY (founder_id) REFERENCES users(id) ON DELETE CASCADE
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
@ -27,12 +27,15 @@ $stmt = db()->prepare("SELECT * FROM funding_rounds WHERE startup_id = ? AND sta
|
|||||||
$stmt->execute([$startup_id]);
|
$stmt->execute([$startup_id]);
|
||||||
$activeRound = $stmt->fetch();
|
$activeRound = $stmt->fetch();
|
||||||
|
|
||||||
// Handle Founder Actions
|
// Handle Actions
|
||||||
$error = '';
|
$error = '';
|
||||||
$success = '';
|
$success = '';
|
||||||
|
|
||||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $user['role'] === 'founder' && $startup['founder_id'] == $user_id) {
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
|
||||||
$action = $_POST['action'];
|
$action = $_POST['action'];
|
||||||
|
|
||||||
|
// Founder Actions
|
||||||
|
if ($user['role'] === 'founder' && $startup['founder_id'] == $user_id) {
|
||||||
$round_id = isset($_POST['round_id']) ? (int)$_POST['round_id'] : 0;
|
$round_id = isset($_POST['round_id']) ? (int)$_POST['round_id'] : 0;
|
||||||
|
|
||||||
if ($action === 'finish_round' && $activeRound && $activeRound['id'] == $round_id) {
|
if ($action === 'finish_round' && $activeRound && $activeRound['id'] == $round_id) {
|
||||||
@ -84,11 +87,49 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $user['r
|
|||||||
$stmt->execute([$startup_id]);
|
$stmt->execute([$startup_id]);
|
||||||
$activeRound = $stmt->fetch();
|
$activeRound = $stmt->fetch();
|
||||||
}
|
}
|
||||||
}
|
} elseif ($action === 'post_update') {
|
||||||
}
|
$title = trim($_POST['update_title'] ?? '');
|
||||||
|
$content = trim($_POST['update_content'] ?? '');
|
||||||
|
|
||||||
// Handle Investment (Investor Only)
|
if (empty($title) || empty($content)) {
|
||||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'invest') {
|
$error = "Update title and content are required.";
|
||||||
|
} else {
|
||||||
|
db()->beginTransaction();
|
||||||
|
try {
|
||||||
|
// 1. Insert Update
|
||||||
|
$stmt = db()->prepare("INSERT INTO startup_updates (startup_id, founder_id, title, content) VALUES (?, ?, ?, ?)");
|
||||||
|
$stmt->execute([$startup_id, $user_id, $title, $content]);
|
||||||
|
|
||||||
|
// 2. Identify All Unique Investors for this startup
|
||||||
|
$stmt = db()->prepare("SELECT DISTINCT u.id, u.email, u.full_name FROM investments i JOIN users u ON i.investor_id = u.id WHERE i.startup_id = ? AND i.status = 'approved'");
|
||||||
|
$stmt->execute([$startup_id]);
|
||||||
|
$investorsToNotify = $stmt->fetchAll();
|
||||||
|
|
||||||
|
// 3. Notify them
|
||||||
|
foreach ($investorsToNotify as $invUser) {
|
||||||
|
// DB Notification
|
||||||
|
$notif = db()->prepare("INSERT INTO notifications (user_id, content) VALUES (?, ?)");
|
||||||
|
$notif->execute([$invUser['id'], "New progress update from " . $startup['name'] . ": " . $title]);
|
||||||
|
|
||||||
|
// Email Notification
|
||||||
|
$subject = "New Update: " . $startup['name'];
|
||||||
|
$emailHtml = "<h1>New Update: " . htmlspecialchars($title) . "</h1><p>Hi " . htmlspecialchars($invUser['full_name']) . ", <strong>" . htmlspecialchars($startup['name']) . "</strong> has posted a new progress update:</p><hr><p>" . nl2br(htmlspecialchars($content)) . "</p>";
|
||||||
|
$emailText = "New Update: " . $title . "\n\nHi " . $invUser['full_name'] . ", " . $startup['name'] . " has posted a new progress update: " . $content;
|
||||||
|
MailService::sendMail($invUser['email'], $subject, $emailHtml, $emailText);
|
||||||
|
}
|
||||||
|
|
||||||
|
db()->commit();
|
||||||
|
$success = "Update posted and " . count($investorsToNotify) . " investors notified.";
|
||||||
|
} catch (Exception $e) {
|
||||||
|
db()->rollBack();
|
||||||
|
$error = "Failed to post update: " . $e->getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Investor Actions
|
||||||
|
if ($action === 'invest') {
|
||||||
if ($user['role'] !== 'investor') {
|
if ($user['role'] !== 'investor') {
|
||||||
$error = "Founders cannot make investments.";
|
$error = "Founders cannot make investments.";
|
||||||
} elseif (!$activeRound) {
|
} elseif (!$activeRound) {
|
||||||
@ -170,6 +211,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$platformName = defined('PLATFORM_NAME') ? PLATFORM_NAME : 'Gatsby';
|
$platformName = defined('PLATFORM_NAME') ? PLATFORM_NAME : 'Gatsby';
|
||||||
@ -235,6 +277,55 @@ $platformName = defined('PLATFORM_NAME') ? PLATFORM_NAME : 'Gatsby';
|
|||||||
<p style="font-size: 18px; line-height: 1.6; color: var(--text-secondary); white-space: pre-wrap;"><?= htmlspecialchars($startup['description']) ?></p>
|
<p style="font-size: 18px; line-height: 1.6; color: var(--text-secondary); white-space: pre-wrap;"><?= htmlspecialchars($startup['description']) ?></p>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<!-- Public Updates Section -->
|
||||||
|
<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: #f8fafc; padding: 25px; border-radius: 15px; margin-bottom: 30px;">
|
||||||
|
<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>
|
||||||
|
</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 investors..." required></textarea>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary">Post & Notify Investors</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 #eee; 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>
|
||||||
|
|
||||||
<?php if ($activeRound): ?>
|
<?php if ($activeRound): ?>
|
||||||
<section class="card" style="border-left: 5px solid var(--primary);">
|
<section class="card" style="border-left: 5px solid var(--primary);">
|
||||||
<h3 style="margin-top: 0;">Active Funding Round</h3>
|
<h3 style="margin-top: 0;">Active Funding Round</h3>
|
||||||
@ -345,7 +436,9 @@ $platformName = defined('PLATFORM_NAME') ? PLATFORM_NAME : 'Gatsby';
|
|||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<div style="font-weight: 600;"><?= htmlspecialchars($founder['full_name']) ?></div>
|
<div style="font-weight: 600;"><?= htmlspecialchars($founder['full_name']) ?></div>
|
||||||
<div style="font-size: 13px; color: var(--text-secondary);"><?= htmlspecialchars($founder['university']) ?></div>
|
<div style="font-size: 13px; color: var(--text-secondary);">
|
||||||
|
<?= htmlspecialchars($founder['university']) ?>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<a href="messages.php?user_id=<?= $founder['id'] ?>" class="btn btn-outline" style="width: 100%; text-align: center; display: block;">Send Message</a>
|
<a href="messages.php?user_id=<?= $founder['id'] ?>" class="btn btn-outline" style="width: 100%; text-align: center; display: block;">Send Message</a>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user