diff options
| -rw-r--r-- | public/emotes/setmanip.php (renamed from public/emotes/add.php) | 38 | ||||
| -rw-r--r-- | src/emotes/single_page.php | 26 |
2 files changed, 43 insertions, 21 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 diff --git a/src/emotes/single_page.php b/src/emotes/single_page.php index b76fda8..3fa0a30 100644 --- a/src/emotes/single_page.php +++ b/src/emotes/single_page.php @@ -50,21 +50,21 @@ include_once "../../src/config.php"; $db = null; ?> - <?php - if ($added) { ?> - <form action="/emotes/remove.php" method="POST"> - <input type="text" name="id" value="<?php echo $emote->get_id() ?>" - style="display: none;"> + <form action="/emotes/setmanip.php" method="POST"> + <input type="text" name="id" value="<?php echo $emote->get_id() ?>" + style="display: none;"> + <?php + if ($added) { ?> + <input type="text" name="action" value="remove" style="display: none;"> <button type="submit" class="red">Remove from my channel</button> - </form><?php - } else { ?> - <form action="/emotes/add.php" method="POST"> - <input type="text" name="id" value="<?php echo $emote->get_id() ?>" - style="display: none;"> + <?php + } else { ?> + <input type="text" name="action" value="add" style="display: none;"> <button type="submit" class="green">Add to my channel</button> - </form><?php - } - ?> + <?php + } + ?> + </form> </div> <div class="items row right full"> <form action="/emotes/rate.php" method="POST"> |
