summaryrefslogtreecommitdiff
path: root/public
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-04-21 16:18:49 +0500
committerilotterytea <iltsu@alright.party>2025-04-21 16:18:49 +0500
commitf496c838d202e16f65b6efa6207b877f0596ae1e (patch)
tree19a89ec575c658cb00abcef6f2b61862dad06fb3 /public
parent1f4877e3a8d59a4a4fb20d175b69d5e8f3349e5c (diff)
feat: emote removal
Diffstat (limited to 'public')
-rw-r--r--public/emotes/setmanip.php (renamed from public/emotes/add.php)38
1 files changed, 30 insertions, 8 deletions
diff --git a/public/emotes/add.php b/public/emotes/setmanip.php
index 33e8c06..2c5d577 100644
--- a/public/emotes/add.php
+++ b/public/emotes/setmanip.php
@@ -7,6 +7,11 @@ if (!authorize_user(true)) {
return;
}
+if (!isset($_POST["id"], $_POST["action"])) {
+ generate_alert("/emotes/$emote_id", "Not enough POST fields");
+ exit;
+}
+
$db = new PDO(DB_URL, DB_USER, DB_PASS);
// checking emote
@@ -54,14 +59,31 @@ $_SESSION["user_emote_set_id"] = $emote_set_id;
$stmt = $db->prepare("SELECT id FROM emote_set_contents WHERE emote_set_id = ? AND emote_id = ?");
$stmt->execute([$emote_set_id, $emote_id]);
-if ($stmt->rowCount() != 0) {
- generate_alert("/emotes/$emote_id", "This emote has been already added!");
- exit;
-}
+$action = $_POST["action"];
+
+if ($action == "add") {
+ if ($stmt->rowCount() != 0) {
+ generate_alert("/emotes/$emote_id", "This emote has been already added!");
+ exit;
+ }
+
+ $stmt = $db->prepare("INSERT INTO emote_set_contents(emote_set_id, emote_id, added_by) VALUES (?, ?, ?)");
+ $stmt->execute([$emote_set_id, $emote_id, $user_id]);
-$stmt = $db->prepare("INSERT INTO emote_set_contents(emote_set_id, emote_id, added_by) VALUES (?, ?, ?)");
-$stmt->execute([$emote_set_id, $emote_id, $user_id]);
+ $db = null;
+
+ generate_alert("/emotes/$emote_id", "This emote has been added to your set. Enjoy!", 200);
+} else {
+ if ($row = $stmt->fetch()) {
+ $stmt = $db->prepare("DELETE FROM emote_set_contents WHERE id = ?");
+ $stmt->execute([$row["id"]]);
+ } else {
+ generate_alert("/emotes/$emote_id", "This emote wasn't added!");
+ $db = null;
+ exit;
+ }
-$db = null;
+ $db = null;
-generate_alert("/emotes/$emote_id", "This emote has been added to your set. Enjoy!", 200); \ No newline at end of file
+ generate_alert("/emotes/$emote_id", "This emote has been removed from your set.", 200);
+} \ No newline at end of file