<?php

require dirname(__FILE__) . '/includes/bootstrap.php';
//Getting Current User ID
if (!($userID = buckys_is_logged_in())) {
    buckys_redirect('/index.php', MSG_NOT_LOGGED_IN_USER, MSG_TYPE_ERROR);
}
//Getting UserData from Id
$userData = BuckysUser::getUserData($userID);
if (isset($_REQUEST['action'])) {
    $action = $_REQUEST['action'];
    if ($action == 'set-profile-photo') {
        BuckysUser::updateUserProfilePhoto($userID, $_REQUEST['photoID']);
        buckys_redirect('/photo_manage.php');
    } else {
        if ($action == 'delete-photo') {
            if (!BuckysPost::deletePost($userID, $_REQUEST['photoID'])) {
                buckys_redirect('/photo_manage.php', MSG_INVALID_REQUEST, MSG_TYPE_ERROR);
            } else {
                buckys_redirect('/photo_manage.php', MSG_PHOTO_REMOVED, MSG_TYPE_SUCCESS);
            }
        } else {
            if ($action == 'remove-profile-photo') {
                BuckysUser::updateUserFields($userID, ['thumbnail' => '']);
                buckys_redirect('/photo_manage.php');
            }
        }
    }
}
//Getting Album ID
$albumID = isset($_REQUEST['albumID']) ? $_REQUEST['albumID'] : null;