193 lines
10 KiB
PHP
193 lines
10 KiB
PHP
<?php
|
|
session_start();
|
|
if (!isset($_SESSION['user_id'])) {
|
|
header("Location: login.php");
|
|
exit;
|
|
}
|
|
|
|
require_once __DIR__ . '/db/config.php';
|
|
|
|
$stmt = db()->prepare("SELECT * FROM users WHERE id = ?");
|
|
$stmt->execute([$_SESSION['user_id']]);
|
|
$user = $stmt->fetch();
|
|
|
|
$platformName = defined('PLATFORM_NAME') ? PLATFORM_NAME : 'Gatsby';
|
|
|
|
$error = '';
|
|
$success = '';
|
|
|
|
// Check for active funding rounds
|
|
$stmt = db()->prepare("SELECT COUNT(*) FROM startups s JOIN funding_rounds fr ON s.id = fr.startup_id WHERE s.founder_id = ? AND fr.status = 'Active'");
|
|
$stmt->execute([$_SESSION['user_id']]);
|
|
$activeRoundsCount = $stmt->fetchColumn();
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
if (isset($_POST['action']) && $_POST['action'] === 'delete_account') {
|
|
if ($user['role'] === 'founder' && $activeRoundsCount > 0) {
|
|
$error = "You cannot delete your account with active funding rounds. Please finish or cancel them first.";
|
|
} else {
|
|
// Delete account
|
|
db()->beginTransaction();
|
|
try {
|
|
// Remove profile (cascades or sets null according to our migration)
|
|
$stmt = db()->prepare("DELETE FROM users WHERE id = ?");
|
|
$stmt->execute([$_SESSION['user_id']]);
|
|
db()->commit();
|
|
|
|
session_destroy();
|
|
header("Location: login.php?msg=account_deleted");
|
|
exit;
|
|
} catch (Exception $e) {
|
|
db()->rollBack();
|
|
$error = "Account deletion failed: " . $e->getMessage();
|
|
}
|
|
}
|
|
} else {
|
|
$full_name = trim($_POST['full_name'] ?? '');
|
|
$bio = trim($_POST['bio'] ?? '');
|
|
$interests = trim($_POST['interests'] ?? '');
|
|
$investment_appetite = trim($_POST['investment_appetite'] ?? '');
|
|
|
|
if (empty($full_name)) {
|
|
$error = "Name cannot be empty.";
|
|
} else {
|
|
$stmt = db()->prepare("UPDATE users SET full_name = ?, bio = ?, interests = ?, investment_appetite = ? WHERE id = ?");
|
|
try {
|
|
$stmt->execute([$full_name, $bio, $interests, $investment_appetite, $_SESSION['user_id']]);
|
|
$success = "Profile updated successfully!";
|
|
// Update session if name changed
|
|
$_SESSION['full_name'] = $full_name;
|
|
// Refresh user data
|
|
$stmt = db()->prepare("SELECT * FROM users WHERE id = ?");
|
|
$stmt->execute([$_SESSION['user_id']]);
|
|
$user = $stmt->fetch();
|
|
} catch (PDOException $e) {
|
|
$error = "Update failed: " . $e->getMessage();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>Edit Profile — <?= 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">
|
|
</head>
|
|
<body style="padding-bottom: 60px;">
|
|
|
|
<header>
|
|
<div class="container" style="display: flex; justify-content: space-between; align-items: center; width: 100%;">
|
|
<div class="logo"><?= htmlspecialchars($platformName) ?></div>
|
|
<nav class="nav-links">
|
|
<?php if ($user['role'] === 'founder'): ?>
|
|
<a href="startups.php">My Startups</a>
|
|
<a href="discover.php">Find Partners</a>
|
|
<?php else: ?>
|
|
<a href="discover.php">Discover</a>
|
|
<a href="portfolio.php">Portfolio</a>
|
|
<?php endif; ?>
|
|
<a href="messages.php">Messages</a>
|
|
<a href="notifications.php">Notifications</a>
|
|
</nav>
|
|
<div style="display: flex; align-items: center; gap: 15px;">
|
|
<a href="dashboard.php" class="btn btn-secondary" style="padding: 8px 16px;">Back to Dashboard</a>
|
|
</div>
|
|
</div>
|
|
</header>
|
|
|
|
<main class="container" style="padding-top: 50px;">
|
|
<div style="max-width: 600px; margin: 0 auto;">
|
|
<h1>Edit Profile</h1>
|
|
<p style="color: var(--text-secondary); margin-bottom: 40px;">Manage your public presence in the <?= htmlspecialchars($platformName) ?> community.</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;">
|
|
<?= htmlspecialchars($error) ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($success): ?>
|
|
<div style="background: rgba(0, 255, 0, 0.1); border: 1px solid rgba(0, 255, 0, 0.3); color: #55ff55; padding: 12px; border-radius: 8px; margin-bottom: 20px;">
|
|
<?= htmlspecialchars($success) ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="card" style="margin-bottom: 30px;">
|
|
<form method="POST">
|
|
<div style="margin-bottom: 20px;">
|
|
<label style="display: block; margin-bottom: 8px; font-size: 14px; font-weight: 500;">Full Name</label>
|
|
<input type="text" name="full_name" value="<?= htmlspecialchars($user['full_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: 20px;">
|
|
<label style="display: block; margin-bottom: 8px; font-size: 14px; font-weight: 500;">University</label>
|
|
<input type="text" value="<?= htmlspecialchars($user['university']) ?>" disabled style="width: 100%; padding: 12px; border-radius: 12px; background: rgba(255,255,255,0.05); border: 1px solid var(--border-color); color: var(--text-secondary);">
|
|
<span style="font-size: 12px; color: var(--text-secondary); margin-top: 4px; display: block;">University status is verified and cannot be changed.</span>
|
|
</div>
|
|
<div style="margin-bottom: 20px;">
|
|
<label style="display: block; margin-bottom: 8px; font-size: 14px; font-weight: 500;">Bio / Vision</label>
|
|
<textarea name="bio" placeholder="What are you building or looking for?" style="width: 100%; padding: 12px; border-radius: 12px; background: var(--surface-color); border: 1px solid var(--border-color); color: #fff; height: 120px; resize: none;"><?= htmlspecialchars($user['bio'] ?? '') ?></textarea>
|
|
</div>
|
|
<div style="margin-bottom: 20px;">
|
|
<label style="display: block; margin-bottom: 8px; font-size: 14px; font-weight: 500;">Interests / Skills (Comma separated)</label>
|
|
<input type="text" name="interests" value="<?= htmlspecialchars($user['interests'] ?? '') ?>" placeholder="Fintech, AI, Sustainable Fashion, Marketing" style="width: 100%; padding: 12px; border-radius: 12px; background: var(--surface-color); border: 1px solid var(--border-color); color: #fff;">
|
|
</div>
|
|
<?php if ($user['role'] === 'investor'): ?>
|
|
<div style="margin-bottom: 30px;">
|
|
<label style="display: block; margin-bottom: 8px; font-size: 14px; font-weight: 500;">Investment Appetite</label>
|
|
<select name="investment_appetite" style="width: 100%; padding: 12px; border-radius: 12px; background: var(--surface-color); border: 1px solid var(--border-color); color: #fff;">
|
|
<option value="Micro (£50 - £500)" <?= ($user['investment_appetite'] === 'Micro (£50 - £500)') ? 'selected' : '' ?>>Micro (£50 - £500)</option>
|
|
<option value="Standard (£500 - £5k)" <?= ($user['investment_appetite'] === 'Standard (£500 - £5k)') ? 'selected' : '' ?>>Standard (£500 - £5k)</option>
|
|
<option value="Angel (£5k+)" <?= ($user['investment_appetite'] === 'Angel (£5k+)') ? 'selected' : '' ?>>Angel (£5k+)</option>
|
|
</select>
|
|
</div>
|
|
<?php endif; ?>
|
|
<button type="submit" class="btn btn-primary" style="width: 100%; padding: 15px;">Save Changes</button>
|
|
</form>
|
|
</div>
|
|
|
|
<?php if ($user['role'] === 'founder'): ?>
|
|
<div class="card" style="border: 1px solid rgba(255, 85, 85, 0.3); background: rgba(255, 85, 85, 0.05);">
|
|
<h3 style="color: #ff5555; margin-bottom: 15px;">Danger Zone</h3>
|
|
<p style="color: var(--text-secondary); font-size: 14px; margin-bottom: 20px;">Deleting your account is permanent and cannot be undone. All your profile information will be removed, but your startup listings will remain.</p>
|
|
|
|
<button onclick="confirmDelete()" class="btn btn-secondary" style="border-color: #ff5555; color: #ff5555;">Delete My Account</button>
|
|
|
|
<form id="deleteForm" method="POST" style="display: none;">
|
|
<input type="hidden" name="action" value="delete_account">
|
|
</form>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</main>
|
|
|
|
<div id="deleteModal" style="display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.8); z-index: 2000; align-items: center; justify-content: center;">
|
|
<div class="card" style="max-width: 400px; text-align: center; padding: 40px;">
|
|
<i class="fas fa-exclamation-triangle" style="font-size: 48px; color: #ff5555; margin-bottom: 20px;"></i>
|
|
<h3>Permanent Deletion</h3>
|
|
<p style="color: var(--text-secondary); margin-bottom: 30px;">Are you sure you want to permanently delete your account? This action cannot be undone.</p>
|
|
<div style="display: flex; gap: 15px;">
|
|
<button onclick="closeModal()" class="btn btn-secondary" style="flex: 1;">Cancel</button>
|
|
<button onclick="submitDelete()" class="btn btn-primary" style="flex: 1; background: #ff5555; border-color: #ff5555;">Yes, Delete</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
function confirmDelete() {
|
|
document.getElementById('deleteModal').style.display = 'flex';
|
|
}
|
|
function closeModal() {
|
|
document.getElementById('deleteModal').style.display = 'none';
|
|
}
|
|
function submitDelete() {
|
|
document.getElementById('deleteForm').submit();
|
|
}
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|