summaryrefslogtreecommitdiffstats
path: root/includes/chats.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/chats.php')
-rw-r--r--includes/chats.php29
1 files changed, 16 insertions, 13 deletions
diff --git a/includes/chats.php b/includes/chats.php
index d9616fd..92bd90e 100644
--- a/includes/chats.php
+++ b/includes/chats.php
@@ -34,27 +34,27 @@ function muteUser($userID, $numMinutes) {
-function addChat($userID, $message) {
+function addChat($userID, $message, $channel = 1) {
global $mysqli;
if ($message == '') return;
$stmt = $mysqli->prepare("INSERT INTO `chat`
- (`userID`, `message`)
- VALUES (?, ?)");
- $stmt->bind_param('is', $userID, $message);
+ (`userID`, `message`, `channel`)
+ VALUES (?, ?, ?)");
+ $stmt->bind_param('isi', $userID, $message, $channel);
$stmt->execute();
$ID = $stmt->insert_id;
$stmt->close();
//Turnicate messages.
- $deleteFromID = $ID - CHAT_ROWS_TO_KEEP;
- $mysqli->query("DELETE FROM `chat` WHERE `ID` < $deleteFromID");
+ //$deleteFromID = $ID - CHAT_ROWS_TO_KEEP;
+ //$mysqli->query("DELETE FROM `chat` WHERE `ID` < $deleteFromID");
return $ID;
}
-function getChat($startID = 0) {
+function getChat($startID = 0, $channel = 1) {
global $mysqli;
if (!is_numeric($startID)) return false;
@@ -74,19 +74,22 @@ function getChat($startID = 0) {
LEFT JOIN `users`
ON chat.userID = users.ID
WHERE chat.ID > '$startID'
- ORDER BY chat.dateSent ASC, chat.ID ASC
- ")) {
- $array = array();
+ AND chat.channel = '$channel'
+ ORDER BY chat.dateSent DESC, chat.ID DESC
+ LIMIT " . CHAT_ROWS_TO_KEEP)
+ ) {
+ $chatData = array();
if ($res->num_rows == 0) {
$res->close();
return false;
}
while ($response = $res->fetch_assoc()) {
- $array[] = $response;
+ $chatData[] = $response;
}
$res->close();
- if (count($array) < 1) return false;
- return $array;
+ if (count($chatData) < 1) return false;
+ $chatData = array_reverse($chatData);
+ return $chatData;
} else {
printf("DError: %s\n", $mysqli->error);
return false;