Hendrik testing #64
@@ -5,6 +5,7 @@
|
|||||||
<style>
|
<style>
|
||||||
@import url("styles/chat.css");
|
@import url("styles/chat.css");
|
||||||
</style>
|
</style>
|
||||||
|
<script src="js/sendMessage.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<?php
|
<?php
|
||||||
|
|||||||
14
website/public/js/sendMessage.js
Normal file
14
website/public/js/sendMessage.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
// $("#sendMessageForm").submit(function(e) {
|
||||||
|
function sendMessage() {
|
||||||
|
console.log($("#sendMessageForm").serialize());
|
||||||
|
$.post(
|
||||||
|
"sendMessage.php",
|
||||||
|
$("#sendMessageForm").serialize()
|
||||||
|
).done(function( data ) {
|
||||||
|
alert( "Data Loaded: " + data );
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadMessages() {
|
||||||
|
|
||||||
|
}
|
||||||
16
website/public/sendMessage.php
Normal file
16
website/public/sendMessage.php
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
include_once("../queries/private_message.php");
|
||||||
|
|
||||||
|
if (isset($_POST["destination"]) &&
|
||||||
|
isset($_POST["content"])) {
|
||||||
|
|
||||||
|
if (sendMessage($db, $_POST["destination"], $_POST["content"])) {
|
||||||
|
echo $_POST["content"] . " is naar " . $_POST["destination"] . " gestuurd";
|
||||||
|
} else {
|
||||||
|
echo "YOU FAILED!!!";
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
echo "maybe dont try to hax the system?";
|
||||||
|
}
|
||||||
51
website/queries/private_message.php
Normal file
51
website/queries/private_message.php
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
function get100ChatMessagesFromN($n, $user1ID, $user2ID) {
|
||||||
|
$db = $GLOBALS["db"];
|
||||||
|
$stmt = $db->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
|
||||||
|
));
|
||||||
|
}
|
||||||
@@ -37,16 +37,20 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="chat-field">
|
<div class="chat-field">
|
||||||
<form method="post">
|
<form id="sendMessageForm" action="javascript:sendMessage();">
|
||||||
|
<input type="hidden"
|
||||||
|
name="destination"
|
||||||
|
value="666"
|
||||||
|
/>
|
||||||
<input type="submit"
|
<input type="submit"
|
||||||
value="Verstuur"
|
value="Verstuur"
|
||||||
>
|
/>
|
||||||
<span>
|
<span>
|
||||||
<input type="text"
|
<input type="text"
|
||||||
name="message"
|
name="content"
|
||||||
placeholder="Reageer..."
|
placeholder="Reageer..."
|
||||||
required
|
required
|
||||||
>
|
/>
|
||||||
</span>
|
</span>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user