From b80be97f187a4ed60e1bf0dc36e725ec3c122e43 Mon Sep 17 00:00:00 2001 From: Lncvrt Date: Sun, 24 Aug 2025 21:38:29 -0700 Subject: [PATCH] Add reporting --- database/reportChatroomMessage.php | 47 ++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 database/reportChatroomMessage.php diff --git a/database/reportChatroomMessage.php b/database/reportChatroomMessage.php new file mode 100644 index 0000000..c7fb442 --- /dev/null +++ b/database/reportChatroomMessage.php @@ -0,0 +1,47 @@ +prepare("SELECT * FROM users WHERE token = ? AND username = ?"); +$stmt->bind_param("ss", $token, $username); +$stmt->execute(); +$result = $stmt->get_result(); +$row = $result->fetch_assoc(); +if (!$row) exit; +$stmt->close(); + +$user_id = $row["id"]; + +$stmt = $conn->prepare("SELECT id FROM chats WHERE userId != ? AND deleted_at = 0 AND id = ? LIMIT 1"); +$stmt->bind_param("ii", $user_id, $id); +$stmt->execute(); +$res = $stmt->get_result(); +$stmt->close(); + +if ($res->num_rows < 0) exit; + +$stmt = $conn->prepare("SELECT id FROM chatroom_reports WHERE chatId = ? AND userId = ? LIMIT 1"); +$stmt->bind_param("ii", $id, $user_id); +$stmt->execute(); +$res = $stmt->get_result(); +$stmt->close(); + +if ($res->num_rows > 0) exit; + +$time = time(); +$reason = base64_encode($reason); + +$stmt = $conn->prepare("INSERT INTO chatroom_reports (chatid, userId, reason, timestamp) VALUES (?, ?, ?, ?)"); +$stmt->bind_param("iisi", $id, $user_id, $reason, $time); +$stmt->execute(); + +$conn->close(); \ No newline at end of file