diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/accounts.php | 22 | ||||
| -rw-r--r-- | src/partials.php | 21 |
2 files changed, 37 insertions, 6 deletions
diff --git a/src/accounts.php b/src/accounts.php index 72c766f..51cb3f6 100644 --- a/src/accounts.php +++ b/src/accounts.php @@ -55,17 +55,27 @@ function authorize_user(bool $required = false): bool $_SESSION["user_role"] = $role_row; } - $stmt = $db->prepare("SELECT es.* FROM emote_sets es + $stmt = $db->prepare("SELECT es.*, aes.is_default FROM emote_sets es INNER JOIN acquired_emote_sets aes ON aes.emote_set_id = es.id - WHERE aes.user_id = ? AND aes.is_default = TRUE + WHERE aes.user_id = ? + ORDER BY + CASE WHEN es.id = ? THEN 0 ELSE 1 END, + es.id "); - $stmt->execute([$row["id"]]); + $stmt->execute([$row["id"], $_SESSION["user_active_emote_set_id"] ?? ""]); - $_SESSION["user_active_emote_set"] = null; + $emote_sets = $stmt->fetchAll(PDO::FETCH_ASSOC); - if ($emote_set_row = $stmt->fetch(PDO::FETCH_ASSOC)) { - $_SESSION["user_active_emote_set"] = $emote_set_row; + if (!isset($_SESSION["user_active_emote_set_id"])) { + foreach ($emote_sets as $es) { + if ($es["is_default"]) { + $_SESSION["user_active_emote_set"] = $es; + $_SESSION["user_active_emote_set_id"] = $es["id"]; + } + } } + + $_SESSION["user_emote_sets"] = $emote_sets; } else { session_regenerate_id(); session_unset(); diff --git a/src/partials.php b/src/partials.php index c9ee5cb..760923a 100644 --- a/src/partials.php +++ b/src/partials.php @@ -79,6 +79,27 @@ function html_navigation_bar() </div> <?php if (isset($_SESSION["user_id"])): ?> <div class="flex items-bottom small-gap" style="margin-left: auto;"> + <?php if (isset($_SESSION["user_emote_sets"])): ?> + <form action="/account/change_emoteset.php" method="POST" id="form-change-emoteset"> + <input type="text" name="redirect" value="<?php echo $_SERVER["REQUEST_URI"] ?>" style="display: none;"> + <div class="row small-gap"> + <label for="id">Current emote set: </label> + <select name="id" onchange="send_change_emoteset(event)"> + <?php + foreach ($_SESSION["user_emote_sets"] as $es) { + echo '<option value="' . $es["id"] . '">' . $es["name"] . '</option>'; + } + ?> + </select> + </div> + </form> + <script> + function send_change_emoteset(e) { + document.getElementById("form-change-emoteset").submit(); + } + </script> + <?php endif; ?> + <a href="/users.php?id=<?php echo $_SESSION["user_id"] ?>" class="flex items-bottom small-gap"> Signed in as <?php echo $_SESSION["user_name"] ?> <?php |
