Everything previously under www/src now are under www/ Moved style.CSS under www/ressources, to allow blocking http requests to www/lib completly Moved <head> and <header> generation under lib/PHP/output/sections.php to reduce redundancy within files. Also implemented a system to allow them to generate relatif paht for href to ressources depending on their deepness within www/ hierarchy.
95 lines
No EOL
2.9 KiB
PHP
95 lines
No EOL
2.9 KiB
PHP
<?php
|
|
require_once '../lib/PHP/session/continue.php';
|
|
require_once '../lib/PHP/session/nosessiontest.php';
|
|
require_once '../lib/PHP/db_connection/human_ressources.php';
|
|
require_once '../lib/PHP/output/sections.php';
|
|
|
|
if (!is_logged_in()) {
|
|
header("Location: login.php");
|
|
exit;
|
|
}
|
|
|
|
$success = $error = '';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$displayname = trim($_POST['displayname'] ?? '');
|
|
$email = trim($_POST['email'] ?? '');
|
|
$password = trim($_POST['password'] ?? '');
|
|
|
|
if ($displayname === '' || $email === '') {
|
|
$error = "Display name and email cannot be empty.";
|
|
} else {
|
|
$params = [$displayname, $email, $user['ID']];
|
|
$sql = "UPDATE users SET displayname = ?, email = ?";
|
|
|
|
if ($password !== '') {
|
|
$hashed = password_hash($password, PASSWORD_DEFAULT);
|
|
$sql .= ", password = ?";
|
|
$params = [$displayname, $email, $hashed, $user['ID']];
|
|
}
|
|
|
|
$sql .= " WHERE ID = ?";
|
|
|
|
$statement = $db_connection->prepare($query);
|
|
$execsucces = $statement->execute($params);
|
|
$results = $statement->fetchAll();
|
|
|
|
// Update session
|
|
$_SESSION['user']['displayname'] = $displayname;
|
|
$_SESSION['user']['email'] = $email;
|
|
$success = "Profile updated successfully.";
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<?php print_website_meta(1, 'Profile - Project BDEE'); ?>
|
|
<body>
|
|
|
|
<?php print_website_header(1); ?>
|
|
|
|
|
|
<main class="info-page">
|
|
<h1>Your Profile</h1>
|
|
|
|
<?php if ($success): ?>
|
|
<p style="color: green; font-weight: bold;"><?= $success; ?></p>
|
|
<?php endif; ?>
|
|
<?php if ($error): ?>
|
|
<p style="color: red; font-weight: bold;"><?= $error; ?></p>
|
|
<?php endif; ?>
|
|
|
|
<form method="POST" class="profile-form" style="max-width: 600px; margin: 0 auto;">
|
|
<div style="margin-bottom: 15px;">
|
|
<label for="displayname"><strong>Display Name</strong></label><br>
|
|
<input type="text" id="displayname" name="displayname" required
|
|
value="<?= $user['displayname']; ?>"
|
|
style="width:100%; padding:10px; border-radius:6px; border:1px solid #ccc;">
|
|
</div>
|
|
|
|
<div style="margin-bottom: 15px;">
|
|
<label for="email"><strong>Email</strong></label><br>
|
|
<input type="email" id="email" name="email" required
|
|
value="<?= $user['email']; ?>"
|
|
style="width:100%; padding:10px; border-radius:6px; border:1px solid #ccc;">
|
|
</div>
|
|
|
|
<div style="margin-bottom: 20px;">
|
|
<label for="password"><strong>New Password (optional)</strong></label><br>
|
|
<input type="password" id="password" name="password"
|
|
placeholder="Leave empty to keep your current password"
|
|
style="width:100%; padding:10px; border-radius:6px; border:1px solid #ccc;">
|
|
</div>
|
|
|
|
<div style="text-align:center;">
|
|
<button type="submit" class="btn-primary">Save Changes</button>
|
|
</div>
|
|
</form>
|
|
</main>
|
|
|
|
<footer>
|
|
<p>© <?= date('Y'); ?> Project BDEE — All rights reserved.</p>
|
|
</footer>
|
|
|
|
</body>
|
|
</html>
|