From eb2a343d5fe5d4dc1ab44fbb3fb792579fbfca46 Mon Sep 17 00:00:00 2001 From: Lars van Hijfte Date: Wed, 18 Jan 2017 12:08:53 +0100 Subject: [PATCH] added live sending messages from user 2 to user 2 --- website/public/chat.php | 1 + website/public/js/sendMessage.js | 14 ++++++++ website/public/sendMessage.php | 16 +++++++++ website/queries/private_message.php | 51 +++++++++++++++++++++++++++++ website/views/chat-view.php | 12 ++++--- 5 files changed, 90 insertions(+), 4 deletions(-) create mode 100644 website/public/js/sendMessage.js create mode 100644 website/public/sendMessage.php create mode 100644 website/queries/private_message.php diff --git a/website/public/chat.php b/website/public/chat.php index f077a4d..150638d 100644 --- a/website/public/chat.php +++ b/website/public/chat.php @@ -5,6 +5,7 @@ + prepare(" + SELECT + * + FROM + `private_message` + WHERE + `origin` = :user1 AND + `destination` = :user2 OR + `origin` = :user2 AND + `destination` = :user1 + ORDER BY + `creationdate` DESC + LIMIT + :n, 100 + "); + + $stmt->bindParam(":user1", $user1ID); + $stmt->bindParam(":user2", $user2ID); + $stmt->bindParam(":n", $n); + + return $stmt->execute(); +} + +function sendMessage($destination, $content) { + $db = $GLOBALS["db"]; + $stmt = $db->prepare(" + INSERT INTO + `private_message` + ( + `origin`, + `destination`, + `content` + ) + VALUES + ( + :origin, + :destination, + :content + ) + "); + + return $stmt->execute(array( + "origin" => 2, + "destination" => $destination, + "content" => $content + )); +} \ No newline at end of file diff --git a/website/views/chat-view.php b/website/views/chat-view.php index a23a1c5..6b6aecd 100644 --- a/website/views/chat-view.php +++ b/website/views/chat-view.php @@ -37,16 +37,20 @@
-
+ + + /> + />