224 lines
12 KiB
PHP
224 lines
12 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; }
|
|
|
|
$platformName = defined('PLATFORM_NAME') ? PLATFORM_NAME : 'Gatsby';
|
|
$error = '';
|
|
$success = '';
|
|
|
|
// Centralized country list
|
|
$countries = require 'includes/countries.php';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
if (isset($_POST['action']) && $_POST['action'] === 'update_profile') {
|
|
$full_name = trim($_POST['full_name']);
|
|
$bio = trim($_POST['bio']);
|
|
$university = trim($_POST['university']);
|
|
$degree_program = trim($_POST['degree_program']);
|
|
$skills = trim($_POST['skills']);
|
|
$startup_industries = trim($_POST['startup_industries']);
|
|
$country = $_POST['country'] ?? '';
|
|
|
|
$cv_url = $user['cv_url'];
|
|
|
|
// Handle CV Upload
|
|
if (isset($_FILES['cv_file']) && $_FILES['cv_file']['error'] === UPLOAD_ERR_OK) {
|
|
$file_tmp = $_FILES['cv_file']['tmp_name'];
|
|
$file_name = $_FILES['cv_file']['name'];
|
|
$file_ext = strtolower(pathinfo($file_name, PATHINFO_EXTENSION));
|
|
$allowed_exts = ['pdf', 'doc', 'docx'];
|
|
|
|
if (in_array($file_ext, $allowed_exts)) {
|
|
$upload_dir = 'assets/docs/cvs/';
|
|
if (!is_dir($upload_dir)) {
|
|
mkdir($upload_dir, 0777, true);
|
|
}
|
|
$new_file_name = 'cv_' . $user_id . '_' . time() . '.' . $file_ext;
|
|
$target_path = $upload_dir . $new_file_name;
|
|
|
|
if (move_uploaded_file($file_tmp, $target_path)) {
|
|
$cv_url = $target_path;
|
|
} else {
|
|
$error = "Failed to upload CV.";
|
|
}
|
|
} else {
|
|
$error = "Invalid CV file type. Only PDF, DOC, and DOCX are allowed.";
|
|
}
|
|
}
|
|
|
|
if (!$error) {
|
|
if ($full_name) {
|
|
$stmt = db()->prepare("UPDATE users SET full_name = ?, bio = ?, university = ?, degree_program = ?, skills = ?, startup_industries = ?, country = ?, cv_url = ? WHERE id = ?");
|
|
$stmt->execute([$full_name, $bio, $university, $degree_program, $skills, $startup_industries, $country, $cv_url, $user_id]);
|
|
$success = "Profile updated successfully!";
|
|
// Refresh user data
|
|
$stmt = db()->prepare("SELECT * FROM users WHERE id = ?");
|
|
$stmt->execute([$user_id]);
|
|
$user = $stmt->fetch();
|
|
} else {
|
|
$error = "Full name is required.";
|
|
}
|
|
}
|
|
} elseif (isset($_POST['action']) && $_POST['action'] === 'delete_account') {
|
|
try {
|
|
db()->beginTransaction();
|
|
db()->prepare("DELETE FROM startup_followers WHERE user_id = ?")->execute([$user_id]);
|
|
db()->prepare("DELETE FROM matches WHERE user1_id = ? OR user2_id = ?")->execute([$user_id, $user_id]);
|
|
db()->prepare("DELETE FROM swipes WHERE swiper_id = ? OR swiped_id = ?")->execute([$user_id, $user_id]);
|
|
db()->prepare("DELETE FROM notifications WHERE user_id = ?")->execute([$user_id]);
|
|
db()->prepare("DELETE FROM users WHERE id = ?")->execute([$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();
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
<!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 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?v=<?php echo time(); ?>" 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="funding_rounds.php">Founding Rounds</a>
|
|
<a href="portfolio.php">Portfolio</a>
|
|
<a href="discover.php">Discovery Hub</a>
|
|
<?php endif; ?>
|
|
<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: 80px;">
|
|
<div style="max-width: 600px; margin: 0 auto;">
|
|
<h1>Edit Profile</h1>
|
|
<a href="dashboard.php" style="display: inline-block; margin-bottom: 20px; color: #aaa; text-decoration: none; font-size: 14px;"><i class="fas fa-arrow-left"></i> Back to Dashboard</a>
|
|
<p style="color: var(--text-secondary); margin-bottom: 40px;">Manage your public presence in the <?= htmlspecialchars($platformName) ?> community.</p>
|
|
|
|
<?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 class="card">
|
|
<form method="POST" enctype="multipart/form-data">
|
|
<input type="hidden" name="action" value="update_profile">
|
|
<div class="form-group" style="margin-bottom: 20px;">
|
|
<label>Full Name</label>
|
|
<input type="text" name="full_name" class="form-control" value="<?= htmlspecialchars($user['full_name']) ?>" required style="background: var(--surface-color); color: #fff; border: 1px solid var(--border-color);">
|
|
</div>
|
|
<div class="form-group" style="margin-bottom: 20px;">
|
|
<label>Bio</label>
|
|
<textarea name="bio" class="form-control" rows="4" style="background: var(--surface-color); color: #fff; border: 1px solid var(--border-color);"><?= htmlspecialchars($user['bio']) ?></textarea>
|
|
</div>
|
|
|
|
<div class="form-group" style="margin-bottom: 20px;">
|
|
<label>Country</label>
|
|
<select name="country" class="form-control" style="background: var(--surface-color); color: #fff; border: 1px solid var(--border-color);">
|
|
<option value="">Select a country...</option>
|
|
<?php foreach ($countries as $c): ?>
|
|
<option value="<?= htmlspecialchars($c) ?>" <?= ($user['country'] === $c) ? 'selected' : '' ?>>
|
|
<?= htmlspecialchars($c) ?>
|
|
</option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="form-group" style="margin-bottom: 20px;">
|
|
<label>University</label>
|
|
<input type="text" name="university" class="form-control" value="<?= htmlspecialchars($user['university']) ?>" style="background: var(--surface-color); color: #fff; border: 1px solid var(--border-color);">
|
|
</div>
|
|
<div class="form-group" style="margin-bottom: 20px;">
|
|
<label>Degree Program</label>
|
|
<input type="text" name="degree_program" class="form-control" value="<?= htmlspecialchars($user['degree_program']) ?>" style="background: var(--surface-color); color: #fff; border: 1px solid var(--border-color);">
|
|
</div>
|
|
<div class="form-group" style="margin-bottom: 20px;">
|
|
<label>Skills (comma separated)</label>
|
|
<input type="text" name="skills" class="form-control" value="<?= htmlspecialchars($user['skills']) ?>" style="background: var(--surface-color); color: #fff; border: 1px solid var(--border-color);">
|
|
</div>
|
|
<div class="form-group" style="margin-bottom: 20px;">
|
|
<label>Industries of Interest (comma separated)</label>
|
|
<input type="text" name="startup_industries" class="form-control" value="<?= htmlspecialchars($user['startup_industries']) ?>" style="background: var(--surface-color); color: #fff; border: 1px solid var(--border-color);">
|
|
</div>
|
|
|
|
<?php if ($user['role'] === 'founder'): ?>
|
|
<div class="form-group" style="margin-bottom: 30px;">
|
|
<label>Upload CV (PDF, DOC, DOCX)</label>
|
|
<?php if ($user['cv_url']): ?>
|
|
<div style="margin-bottom: 10px; font-size: 14px;">
|
|
<a href="<?= htmlspecialchars($user['cv_url']) ?>" target="_blank" style="color: var(--accent-color);"><i class="fas fa-file-alt"></i> Current CV</a>
|
|
</div>
|
|
<?php endif; ?>
|
|
<input type="file" name="cv_file" class="form-control" style="background: var(--surface-color); color: #fff; border: 1px solid var(--border-color); padding: 10px;">
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<button type="submit" class="btn btn-primary" style="width: 100%;">Save Changes</button>
|
|
</form>
|
|
</div>
|
|
|
|
<div class="card" style="margin-top: 40px; border-color: rgba(255, 77, 77, 0.2);">
|
|
<h3 style="color: #ff4d4d;">Danger Zone</h3>
|
|
<p style="color: var(--text-secondary); font-size: 14px; margin-bottom: 25px;">Deleting your account is permanent. All your data, startups, and matches will be removed.</p>
|
|
<form method="POST" onsubmit="return confirm('Are you absolutely sure you want to delete your account? This cannot be undone.');">
|
|
<input type="hidden" name="action" value="delete_account">
|
|
<button type="submit" class="btn btn-secondary" style="color: #ff4d4d; border-color: rgba(255, 77, 77, 0.2);">Delete My Account</button>
|
|
</form>
|
|
</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?v=<?php echo time(); ?>" 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;">© <?= date('Y') ?> <?= htmlspecialchars($platformName) ?>. All rights reserved.</p>
|
|
</div>
|
|
</footer>
|
|
|
|
<script src="assets/js/main.js"></script>
|
|
</body>
|
|
</html>
|