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-09 12:20:21 +00:00
|
|
|
$userDetails = $userObject->getUserDetails($user);
|
|
|
|
|
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-09 12:20:21 +00:00
|
|
|
$item = $_REQUEST['item'] ?? '';
|
|
|
|
|
|
|
|
// avatar editing
|
|
|
|
if ($item === 'avatar') {
|
|
|
|
switch ($action) {
|
|
|
|
case 'remove':
|
|
|
|
$result = $userObject->removeAvatar($user_id, $config['avatars_path'].$userDetails[0]['avatar']);
|
|
|
|
if ($result === true) {
|
|
|
|
$_SESSION['notice'] = "Avatar for user \"{$user}\" is removed.";
|
|
|
|
} else {
|
|
|
|
$_SESSION['error'] = "Removing the avatar failed. Error: $result";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'edit':
|
|
|
|
$result = $userObject->changeAvatar($user_id, $_FILES['avatar_file'], $config['avatars_path']);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$_SESSION['error'] = "Unspecified avatar editing action.";
|
|
|
|
}
|
|
|
|
|
|
|
|
header("Location: $app_root?page=profile");
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
2024-09-08 10:48:21 +00:00
|
|
|
// update the profile
|
|
|
|
$updatedUser = [
|
|
|
|
'name' => $_POST['name'] ?? '',
|
|
|
|
'email' => $_POST['email'] ?? '',
|
|
|
|
'bio' => $_POST['bio'] ?? '',
|
|
|
|
];
|
2024-09-09 12:20:21 +00:00
|
|
|
$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 {
|
2024-09-09 12:20:21 +00:00
|
|
|
$avatar = !empty($userDetails[0]['avatar']) ? $config['avatars_path'] . $userDetails[0]['avatar'] : $config['default_avatar'];
|
2024-09-08 10:48:21 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
?>
|