diff --git a/app/classes/user.php b/app/classes/user.php index 55dc137..4014990 100644 --- a/app/classes/user.php +++ b/app/classes/user.php @@ -137,19 +137,19 @@ class User { ':user_id' => $user_id ]); // all went OK - $_SESSION['notice'] = 'Avatar updated successfully!'; + $_SESSION['notice'] .= 'Avatar updated successfully. '; return true; } catch (Exception $e) { return $e->getMessage(); } } else { - $_SESSION['error'] = 'Error moving the uploaded file.'; + $_SESSION['error'] .= 'Error moving the uploaded file. '; } } else { - $_SESSION['error'] = 'Invalid avatar file type.'; + $_SESSION['error'] .= 'Invalid avatar file type. '; } } else { - $_SESSION['error'] = 'Error uploading the avatar file.'; + $_SESSION['error'] .= 'Error uploading the avatar file. '; } } catch (Exception $e) { diff --git a/app/pages/profile.php b/app/pages/profile.php index 417f968..f1639aa 100644 --- a/app/pages/profile.php +++ b/app/pages/profile.php @@ -14,22 +14,13 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { $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."; + // avatar removal + if ($item === 'avatar' && $action === '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 "; } header("Location: $app_root?page=profile"); @@ -44,9 +35,14 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { ]; $result = $userObject->editUser($user_id, $updatedUser); if ($result === true) { - $_SESSION['notice'] = "User details for \"{$updatedUser['name']}\" are edited."; + $_SESSION['notice'] .= "User details for \"{$updatedUser['name']}\" are edited. "; } else { - $_SESSION['error'] = "Editing the user details failed. Error: $result"; + $_SESSION['error'] .= "Editing the user details failed. Error: $result "; + } + + // update the avatar + if (!empty($_FILES['avatar_file']['tmp_name'])) { + $result = $userObject->changeAvatar($user_id, $_FILES['avatar_file'], $config['avatars_path']); } header("Location: $app_root?page=profile"); diff --git a/app/templates/profile-edit.php b/app/templates/profile-edit.php index 740ad88..68db8ce 100644 --- a/app/templates/profile-edit.php +++ b/app/templates/profile-edit.php @@ -5,55 +5,31 @@
Profile of = $userDetails[0]['username'] ?>
edit the profile fields
+