jilo-web/app/pages/profile.php

46 lines
1.1 KiB
PHP
Raw Normal View History

2024-08-12 11:12:24 +00:00
<?php
2024-09-07 22:36:57 +00:00
$action = $_REQUEST['action'] ?? '';
2024-09-07 20:05:22 +00:00
require '../app/classes/user.php';
$userObject = new User($dbWeb);
2024-09-08 10:48:21 +00:00
// if a form is submitted, it's from the edit page
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
2024-09-07 20:05:22 +00:00
2024-09-08 10:48:21 +00:00
$user_id = $userObject->getUserId($user)[0]['id'];
2024-09-07 20:05:22 +00:00
2024-09-08 10:48:21 +00:00
// update the profile
$updatedUser = [
'name' => $_POST['name'] ?? '',
'email' => $_POST['email'] ?? '',
// 'avatar' => ,
'bio' => $_POST['bio'] ?? '',
];
$result = $userObject->editUser($user_id, $updatedUser);
if ($result === true) {
$_SESSION['notice'] = "User details for \"{$updatedUser['name']}\" are edited.";
} else {
$_SESSION['error'] = "Editing the user details failed. Error: $result";
}
2024-09-07 22:36:57 +00:00
2024-09-08 10:48:21 +00:00
header("Location: $app_root?page=profile");
exit();
// no form submitted, show the templates
} else {
$userDetails = $userObject->getUserDetails($user);
switch ($action) {
case 'edit':
include '../app/templates/profile-edit.php';
break;
default:
include '../app/templates/profile.php';
}
2024-09-07 22:36:57 +00:00
}
2024-08-12 11:12:24 +00:00
?>