From c987b0caba76cc380012518b96d4aaa0a00e0d35 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Sun, 15 Feb 2026 23:54:18 +0000 Subject: [PATCH] Autosave: 20260215-235418 --- api_v1_rules.php | 21 ++++++++++++++++++++ assets/css/discord.css | 6 +++++- assets/js/main.js | 45 +++++++++++++++++++++++++++++++++++++++--- debug_reorder.log | 4 ++++ index.php | 13 ++++++++++-- requests.log | 39 ++++++++++++++++++++++++++++++++++++ 6 files changed, 122 insertions(+), 6 deletions(-) diff --git a/api_v1_rules.php b/api_v1_rules.php index 9f07dd2..31f6e97 100644 --- a/api_v1_rules.php +++ b/api_v1_rules.php @@ -54,6 +54,27 @@ if ($_SERVER['REQUEST_METHOD'] === 'DELETE') { if ($_SERVER['REQUEST_METHOD'] === 'PATCH') { $data = json_decode(file_get_contents('php://input'), true); + + if (isset($data['order'])) { + // Bulk reorder + foreach ($data['order'] as $index => $id) { + // Basic permission check (optional but recommended: verify all rules belong to same server user can manage) + if ($index === 0) { + $stmt = db()->prepare("SELECT c.server_id FROM channels c JOIN channel_rules r ON c.id = r.channel_id WHERE r.id = ?"); + $stmt->execute([$id]); + $res = $stmt->fetch(); + if (!$res || !Permissions::hasPermission($user_id, $res['server_id'], Permissions::MANAGE_CHANNELS)) { + echo json_encode(['success' => false, 'error' => 'Unauthorized']); + exit; + } + } + $stmt = db()->prepare("UPDATE channel_rules SET position = ? WHERE id = ?"); + $stmt->execute([$index + 1, $id]); + } + echo json_encode(['success' => true]); + exit; + } + $id = $data['id'] ?? 0; $dir = $data['dir'] ?? 'up'; diff --git a/assets/css/discord.css b/assets/css/discord.css index ab4a68b..c2a1f1c 100644 --- a/assets/css/discord.css +++ b/assets/css/discord.css @@ -890,7 +890,11 @@ body { /* Rules Style */ .rule-item { transition: transform 0.2s; - cursor: default; + cursor: grab; +} + +.rule-item:active { + cursor: grabbing; } .rule-item:hover { diff --git a/assets/js/main.js b/assets/js/main.js index 73d98c3..25e3fb5 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -128,7 +128,7 @@ document.addEventListener('DOMContentLoaded', () => { // Scroll to bottom scrollToBottom(true); - const currentChannel = new URLSearchParams(window.location.search).get('channel_id') || 1; + const currentChannel = window.activeChannelId || new URLSearchParams(window.location.search).get('channel_id') || 1; const currentThread = new URLSearchParams(window.location.search).get('thread_id'); let typingTimeout; @@ -1868,8 +1868,25 @@ document.addEventListener('DOMContentLoaded', () => { // Rules: Add Rule const addRuleBtn = document.getElementById('add-rule-btn'); - addRuleBtn?.addEventListener('click', async () => { - const content = prompt('Rule Content:'); + const addRuleForm = document.getElementById('add-rule-form'); + const newRuleContent = document.getElementById('new-rule-content'); + const saveNewRuleBtn = document.getElementById('save-new-rule-btn'); + const cancelNewRuleBtn = document.getElementById('cancel-new-rule-btn'); + + addRuleBtn?.addEventListener('click', () => { + addRuleBtn.style.display = 'none'; + addRuleForm.style.display = 'block'; + newRuleContent.focus(); + }); + + cancelNewRuleBtn?.addEventListener('click', () => { + addRuleBtn.style.display = 'block'; + addRuleForm.style.display = 'none'; + newRuleContent.value = ''; + }); + + saveNewRuleBtn?.addEventListener('click', async () => { + const content = newRuleContent.value.trim(); if (!content) return; try { @@ -1886,6 +1903,28 @@ document.addEventListener('DOMContentLoaded', () => { } catch (e) { console.error(e); } }); + const rulesListSortable = document.getElementById('rules-list-sortable'); + if (typeof Sortable !== 'undefined' && rulesListSortable) { + new Sortable(rulesListSortable, { + animation: 150, + ghostClass: 'sortable-ghost', + onEnd: async () => { + const order = Array.from(rulesListSortable.querySelectorAll('.rule-item')).map(el => el.dataset.id); + // Update numbers in UI + rulesListSortable.querySelectorAll('.rule-item').forEach((item, index) => { + const numEl = item.querySelector('.rule-number'); + if (numEl) numEl.textContent = `${index + 1}.`; + }); + + await fetch('api_v1_rules.php', { + method: 'PATCH', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ order: order }) + }); + } + }); + } + // Rules: Delete/Edit document.addEventListener('click', async (e) => { if (e.target.classList.contains('delete-rule-btn')) { diff --git a/debug_reorder.log b/debug_reorder.log index 7038d2e..b86d5af 100644 --- a/debug_reorder.log +++ b/debug_reorder.log @@ -2,3 +2,7 @@ 2026-02-15 23:35:48 - Server: 1 - Orders: [{"id":"10","position":0,"category_id":null},{"id":"1","position":1,"category_id":null},{"id":"6","position":2,"category_id":null},{"id":"2","position":3,"category_id":null},{"id":"9","position":4,"category_id":null},{"id":"3","position":5,"category_id":null}] 2026-02-15 23:36:25 - Server: 1 - Orders: [{"id":"10","position":0,"category_id":null},{"id":"1","position":1,"category_id":"10"},{"id":"6","position":2,"category_id":"10"},{"id":"2","position":3,"category_id":null},{"id":"9","position":4,"category_id":null},{"id":"3","position":5,"category_id":null}] 2026-02-15 23:36:28 - Server: 1 - Orders: [{"id":"10","position":0,"category_id":null},{"id":"1","position":1,"category_id":"10"},{"id":"6","position":2,"category_id":"10"},{"id":"2","position":3,"category_id":"10"},{"id":"9","position":4,"category_id":null},{"id":"3","position":5,"category_id":null}] +2026-02-15 23:39:25 - Server: 1 - Orders: [{"id":"11","position":0,"category_id":null},{"id":"10","position":1,"category_id":null},{"id":"1","position":2,"category_id":"10"},{"id":"6","position":3,"category_id":"10"},{"id":"2","position":4,"category_id":"10"},{"id":"9","position":5,"category_id":null},{"id":"3","position":6,"category_id":null}] +2026-02-15 23:39:45 - Server: 1 - Orders: [{"id":"11","position":0,"category_id":null},{"id":"12","position":1,"category_id":null},{"id":"10","position":2,"category_id":null},{"id":"1","position":3,"category_id":"10"},{"id":"6","position":4,"category_id":"10"},{"id":"2","position":5,"category_id":"10"},{"id":"9","position":6,"category_id":null},{"id":"3","position":7,"category_id":null}] +2026-02-15 23:40:11 - Server: 1 - Orders: [{"id":"11","position":0,"category_id":null},{"id":"12","position":1,"category_id":null},{"id":"10","position":2,"category_id":null},{"id":"1","position":3,"category_id":"10"},{"id":"6","position":4,"category_id":"10"},{"id":"2","position":5,"category_id":"10"},{"id":"13","position":6,"category_id":null},{"id":"9","position":7,"category_id":null},{"id":"3","position":8,"category_id":null}] +2026-02-15 23:40:20 - Server: 1 - Orders: [{"id":"11","position":0,"category_id":null},{"id":"12","position":1,"category_id":null},{"id":"10","position":2,"category_id":null},{"id":"1","position":3,"category_id":"10"},{"id":"6","position":4,"category_id":"10"},{"id":"2","position":5,"category_id":"10"},{"id":"14","position":6,"category_id":null},{"id":"13","position":7,"category_id":null},{"id":"9","position":8,"category_id":null},{"id":"3","position":9,"category_id":null}] diff --git a/index.php b/index.php index b1fba61..e87abea 100644 --- a/index.php +++ b/index.php @@ -234,6 +234,7 @@ $projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? ''; window.isServerOwner = ; window.canManageServer = ; window.canManageChannels = ; + window.activeChannelId = ; window.currentChannelName = ""; window.isDndMode = ; window.soundNotifications = ; @@ -580,9 +581,10 @@ $projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';

📜

- +
+ .
@@ -597,7 +599,14 @@ $projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
- + +
diff --git a/requests.log b/requests.log index 044ac28..4f2a667 100644 --- a/requests.log +++ b/requests.log @@ -10,3 +10,42 @@ 2026-02-15 23:36:35 - GET /index.php?server_id=1&channel_id=2 - POST: [] 2026-02-15 23:38:20 - GET /index.php?server_id=1&channel_id=6 - POST: [] 2026-02-15 23:38:22 - GET /index.php?server_id=1&channel_id=1 - POST: [] +2026-02-15 23:39:19 - GET /index.php?server_id=1&channel_id=11 - POST: [] +2026-02-15 23:39:43 - GET /index.php?server_id=1&channel_id=12 - POST: [] +2026-02-15 23:39:49 - GET /index.php?server_id=1&channel_id=12 - POST: [] +2026-02-15 23:40:05 - GET /index.php?server_id=1&channel_id=13 - POST: [] +2026-02-15 23:40:17 - GET /index.php?server_id=1&channel_id=14 - POST: [] +2026-02-15 23:40:21 - GET /index.php?server_id=1&channel_id=13 - POST: [] +2026-02-15 23:40:49 - GET /index.php?server_id=1&channel_id=11 - POST: [] +2026-02-15 23:42:44 - GET /?fl_project=38443 - POST: [] +2026-02-15 23:42:55 - GET /index.php?server_id=1&channel_id=11 - POST: [] +2026-02-15 23:43:28 - GET /index.php - POST: [] +2026-02-15 23:44:37 - GET /index.php?server_id=1&channel_id=11 - POST: [] +2026-02-15 23:44:49 - GET /index.php?server_id=1&channel_id=12 - POST: [] +2026-02-15 23:44:52 - GET /index.php?server_id=1&channel_id=11 - POST: [] +2026-02-15 23:44:58 - GET /index.php?server_id=1&channel_id=1 - POST: [] +2026-02-15 23:45:04 - GET /index.php?server_id=1&channel_id=2 - POST: [] +2026-02-15 23:45:05 - GET /index.php?server_id=1&channel_id=6 - POST: [] +2026-02-15 23:45:11 - GET /index.php?server_id=1&channel_id=2 - POST: [] +2026-02-15 23:45:12 - GET /index.php?server_id=1&channel_id=2 - POST: [] +2026-02-15 23:45:13 - GET /index.php?server_id=1&channel_id=1 - POST: [] +2026-02-15 23:45:17 - GET /index.php?server_id=1&channel_id=6 - POST: [] +2026-02-15 23:45:41 - GET /index.php?server_id=1&channel_id=6 - POST: [] +2026-02-15 23:46:38 - GET /index.php?server_id=1&channel_id=1 - POST: [] +2026-02-15 23:46:40 - GET /index.php?server_id=1&channel_id=2 - POST: [] +2026-02-15 23:46:42 - GET /index.php?server_id=1&channel_id=6 - POST: [] +2026-02-15 23:46:50 - GET /index.php?server_id=1&channel_id=6 - POST: [] +2026-02-15 23:47:06 - GET /index.php?server_id=1&channel_id=2 - POST: [] +2026-02-15 23:47:16 - GET /index.php?server_id=1&channel_id=2 - POST: [] +2026-02-15 23:47:23 - GET /index.php?server_id=1&channel_id=2 - POST: [] +2026-02-15 23:47:45 - GET /index.php?server_id=1&channel_id=6 - POST: [] +2026-02-15 23:48:03 - GET /index.php?server_id=1&channel_id=2 - POST: [] +2026-02-15 23:49:16 - GET /index.php?server_id=1&channel_id=6 - POST: [] +2026-02-15 23:52:12 - GET /?fl_project=38443 - POST: [] +2026-02-15 23:52:32 - GET /index.php?server_id=1&channel_id=2 - POST: [] +2026-02-15 23:52:37 - GET /index.php?server_id=1&channel_id=2 - POST: [] +2026-02-15 23:52:45 - GET /index.php?server_id=1&channel_id=11 - POST: [] +2026-02-15 23:52:53 - GET /index.php?server_id=1&channel_id=11 - POST: [] +2026-02-15 23:52:56 - GET /index.php?server_id=1&channel_id=11 - POST: [] +2026-02-15 23:53:22 - GET /index.php?server_id=1&channel_id=11 - POST: [] +2026-02-15 23:54:12 - GET /index.php?server_id=1&channel_id=11 - POST: []