Chat messages and groups are now live. #130

Merged
11291680 merged 1 commits from lars into master 2017-01-26 10:27:46 +01:00
12 changed files with 209 additions and 137 deletions

View File

@@ -0,0 +1,14 @@
<?php
session_start();
require_once ("../../queries/connect.php");
require_once ("../../queries/checkInput.php");
require_once ("../../queries/group_member.php");
if (isset($_POST["limit"])) {
echo selectLimitedGroupsFromUser($_SESSION["userID"], (int) test_input($_POST["limit"]));
} else {
echo selectAllGroupsFromUser($_SESSION["userID"]);
}

View File

@@ -36,12 +36,24 @@ foreach($friends as $i => $friend) {
<form action='<?= $action ?>' method='<?= $actionType ?>'> <form action='<?= $action ?>' method='<?= $actionType ?>'>
<button type='submit' <button type='submit'
name='username' name='username'
value='<?= $friend->username ?>'> value='<?php
if (isset($friend->username)) {
echo $friend->username;
} else if (isset($friend->content)) {
echo $friend->userID;
}
?>'>
<div class='friend'> <div class='friend'>
<img alt='PF' class='profile-picture' src='<?= $friend->profilepicture ?>'/> <img alt='PF' class='profile-picture' src='<?= $friend->profilepicture ?>'/>
<div class='friend-name'> <div class='friend-name'>
<?= $friend->fullname ?><br/> <?= $friend->fullname ?><br/>
<span style='color: #666'><?= $friend->username ?></span> <span style='color: #666'><?php
if (isset($friend->username)) {
echo $friend->username;
} else if (isset($friend->content)) {
echo $friend->content;
}
?></span>
</div> </div>
</div> </div>
</button> </button>
@@ -50,27 +62,25 @@ foreach($friends as $i => $friend) {
if ($friendshipStatus > 1) { if ($friendshipStatus > 1) {
?> ?>
<div class='notification-options'> <div class='notification-options'>
<form action='API/edit_friendship.php' method='post'> <input type='hidden' name='userID' value='' />
<input type='hidden' name='userID' value='<?= $friend->userID ?>' /> <button name='delete'
<button type='submit' onclick="editFriendship('<?= $friend->userID ?>', 'delete')"
name='delete' class='deny-notification'
class='deny-notification' value='1'>
value='1'> <i class='fa fa-times'></i>
<i class='fa fa-times'></i> </button>
</button>
<?php <?php
if ($friendshipStatus == 3) { if ($friendshipStatus == 3) {
?> ?>
<button type='submit' <button name='accept'
name='accept' onclick="editFriendship('<?= $friend->userID ?>', 'accept')"
class='accept-notification' class='accept-notification'
value='1'> value='1'>
<i class='fa fa-check'></i> <i class='fa fa-check'></i>
</button> </button>
<?php <?php
} }
?> ?>
<form>
</div> </div>
<?php <?php
} }

View File

@@ -0,0 +1,38 @@
<?php
session_start();
include_once ("../../queries/group_member.php");
$groups = json_decode($_POST["groups"]);
foreach($groups as $i => $group) {
?>
<li class='group-item'>
<form action='group.php' method='get'>
<button type='submit'
name='groupname'
value='<?= $group->name ?>'>
<div class='group'>
<img alt='PF' class='group-picture' src='<?= $group->picture ?>'/>
<?= $group->name ?>
</div>
</button>
</form>
</li>
<?php
}
?>
<li>
<form action="search.php" method="get">
<input type="hidden"
name="search"
value="" />
<input type="hidden"
name="filter"
value="groups" />
<button type="submit">
Alle groepen...
</button>
</form>
</li>

View File

@@ -1,5 +1,9 @@
<html> <?php
<head>
<meta http-equiv="refresh" content="0; url=login.php" /> session_start();
</head>
</html> if (isset($_SESSION["userID"])) {
header("Location: profile.php");
} else {
header("Location: login.php");
}

View File

@@ -18,10 +18,7 @@ function placeFriendButtons() {
} }
$buttonContainer.children().click(function() { $buttonContainer.children().click(function() {
$.post("API/editFriendship.php", { usr: userID, action: this.value }) editFriendship(userID, this.value);
.done(function() {
placeFriendButtons();
});
}); });
}); });
} }

View File

@@ -1,3 +1,10 @@
function editFriendship(userID, value) {
$.post("API/editFriendship.php", { usr: userID, action: value })
.done(function() {
placeFriendButtons();
});
}
function showFriends(friends, list) { function showFriends(friends, list) {
if(friends && friends != "[]") { if(friends && friends != "[]") {
$(list).load("bits/friend-item.php", { $(list).load("bits/friend-item.php", {
@@ -11,7 +18,7 @@ function showFriends(friends, list) {
} }
function showFriendsPlus(friends, list, limit, action, actionType) { function showFriendsPlus(friends, list, limit, action, actionType) {
if(friends && friends.length > 0) { if(friends && friends != "[]") {
$(list).load("bits/friend-item.php", { $(list).load("bits/friend-item.php", {
"friends": friends, "friends": friends,
"limit": limit, "limit": limit,
@@ -19,6 +26,18 @@ function showFriendsPlus(friends, list, limit, action, actionType) {
"actionType": actionType "actionType": actionType
}); });
return true;
} else {
return false;
}
}
function showGroups(groups, list) {
if(groups && groups != "[]") {
$(list).load("bits/group-item.php", {
"groups": groups
});
return true; return true;
} else { } else {
return false; return false;

View File

@@ -39,6 +39,8 @@ $(document).ready(function() {
loadMenuFriends(5); loadMenuFriends(5);
loadNotificationFriends(); loadNotificationFriends();
loadUnreadMessages();
loadMenuGroups();
}); });
@@ -56,20 +58,51 @@ function loadMenuFriends(limit) {
} }
}); });
setTimeout(loadMenuFriends, 3000, limit); setTimeout(loadMenuFriends, 3000, limit);
} }
function loadMenuGroups() {
$.post(
"API/loadGroups.php",
{
limit: 5
}
).done(function(data) {
if (showGroups(data, "#menu-groups-list")) {
$("#groups-menu-section").show();
} else {
$("#groups-menu-section").hide();
}
});
setTimeout(loadMenuGroups, 3000);
}
function loadNotificationFriends() { function loadNotificationFriends() {
$.post( $.post(
"API/loadFriendRequest.php" "API/loadFriendRequest.php"
).done(function(data) { ).done(function(data) {
if (showFriendsPlus(data, "#friend-requests-list", 5, "API/edit_friendship", "POST")) { if (showFriendsPlus(data, "#friend-requests-list", 5, "profile.php", "GET")) {
$("#friend-request-section").show(); $("#friend-request-section").show();
} else { } else {
$("#friend-request-section").hide(); $("#friend-request-section").hide();
} }
}); });
setTimeout(loadNotificationFriends, 30000); setTimeout(loadNotificationFriends, 3000);
}
function loadUnreadMessages() {
$.post(
"API/loadChatNotifications.php"
).done(function(data) {
if (showFriendsPlus(data, "#unread-chat-list", 5, "chat.php", "GET")) {
console.log(data);
$("#unread-messages-section").show();
} else {
$("#unread-messages-section").hide();
}
});
setTimeout(loadUnreadMessages, 3000);
} }

View File

@@ -1,43 +1,43 @@
function showChatNotifications(notifications) { // function showChatNotifications(notifications) {
$("#unreadChatlist").html(""); // $("#unreadChatlist").html("");
for (i in notifications) { // for (i in notifications) {
$("#unreadChatlist").append(" \ // $("#unreadChatlist").append(" \
<li class='friend-item'> \ // <li class='friend-item'> \
<form action='chat.php' method='get'> \ // <form action='chat.php' method='get'> \
<button type='submit' \ // <button type='submit' \
name='chatID' \ // name='chatID' \
value='"+ notifications[i].userID +"'> \ // value='"+ notifications[i].userID +"'> \
<div class='friend'> \ // <div class='friend'> \
<img alt='PF' class='profile-picture' src='"+ notifications[i].profilepicture +"'/> \ // <img alt='PF' class='profile-picture' src='"+ notifications[i].profilepicture +"'/> \
<div class='friend-name'> \ // <div class='friend-name'> \
"+ notifications[i].name +"<br/> \ // "+ notifications[i].name +"<br/> \
<span style='color: #666'>"+ notifications[i].content +"</span> \ // <span style='color: #666'>"+ notifications[i].content +"</span> \
</div> \ // </div> \
</div> \ // </div> \
</button> \ // </button> \
</form> \ // </form> \
</li> \ // </li> \
"); // ");
} // }
} // }
//
function loadNotifications() { // function loadNotifications() {
$.post( // $.post(
"API/loadChatNotifications.php" // "API/loadChatNotifications.php"
).done(function(data) { // ).done(function(data) {
if (data && data != "[]") { // if (data && data != "[]") {
$("#unread-messages-section").show(); // $("#unread-messages-section").show();
showChatNotifications(JSON.parse(data)); // showChatNotifications(JSON.parse(data));
} else { // } else {
$("#unread-messages-section").hide(); // $("#unread-messages-section").hide();
} // }
}); // });
//
setTimeout(loadNotifications, 10000); // setTimeout(loadNotifications, 10000);
} // }
$(document).ready(function() { // $(document).ready(function() {
loadNotifications(); // loadNotifications();
}); // });

View File

@@ -1,6 +1,10 @@
<?php <?php
function selectAllGroupsFromUser($userID) { function selectAllGroupsFromUser($userID) {
selectLimitedGroupsFromUser($userID, 9999);
}
function selectLimitedGroupsFromUser($userID, $limit) {
$stmt = $GLOBALS["db"]->prepare(" $stmt = $GLOBALS["db"]->prepare("
SELECT SELECT
`group_page`.`name`, `group_page`.`name`,
@@ -13,10 +17,13 @@ function selectAllGroupsFromUser($userID) {
`group_member`.`userID` = :userID AND `group_member`.`userID` = :userID AND
`group_member`.`groupID` = `group_page`.`groupID` AND `group_member`.`groupID` = `group_page`.`groupID` AND
`group_page`.`status` != 'hidden' `group_page`.`status` != 'hidden'
LIMIT :limitCount
"); ");
$stmt->bindParam(':userID', $userID, PDO::PARAM_INT); $stmt->bindParam(':userID', $userID, PDO::PARAM_INT);
$stmt->bindParam(':limitCount', $limit, PDO::PARAM_INT);
$stmt->execute(); $stmt->execute();
return $stmt; return json_encode($stmt->fetchAll());
} }

View File

@@ -79,11 +79,11 @@ function getNewChatMessages($lastID, $destination) {
function selectAllUnreadChat() { function selectAllUnreadChat() {
$stmt = $GLOBALS["db"]->prepare(" $stmt = $GLOBALS["db"]->prepare("
SELECT SELECT
LEFT(CONCAT(`user`.`fname`, ' ', `user`.`lname`), 15) as `name`, LEFT(CONCAT(`user`.`fname`, ' ', `user`.`lname`), 15) as `fullname`,
`user`.`userID`, `user`.`userID`,
IFNULL( IFNULL(
`profilepicture`, `profilepicture`,
'../img/notbad.jpg' '../img/notbad.jpg'
) AS profilepicture, ) AS profilepicture,
LEFT(`private_message`.`content`, 15) as `content` LEFT(`private_message`.`content`, 15) as `content`
FROM FROM
@@ -93,15 +93,18 @@ function selectAllUnreadChat() {
WHERE WHERE
(`friendship`.user2ID = `private_message`.`origin` AND (`friendship`.user2ID = `private_message`.`origin` AND
`friendship`.user1ID = `private_message`.`destination` AND `friendship`.user1ID = `private_message`.`destination` AND
`friendship`.chatLastVisted1 < `private_message`.`creationdate` OR (`friendship`.chatLastVisted1 < `private_message`.`creationdate` OR
`friendship`.chatLastVisted1 IS NULL) OR
`friendship`.user1ID = `private_message`.`origin` AND `friendship`.user1ID = `private_message`.`origin` AND
`friendship`.user2ID = `private_message`.`destination` AND `friendship`.user2ID = `private_message`.`destination` AND
`friendship`.chatLastVisted2 < `private_message`.`creationdate`) AND (`friendship`.chatLastVisted2 < `private_message`.`creationdate` OR
`friendship`.chatLastVisted2 IS NULL)) AND
`private_message`.`origin` = `user`.`userID` AND `private_message`.`origin` = `user`.`userID` AND
`private_message`.`destination` = :userID AND `private_message`.`destination` = :userID AND
`user`.`role` != 'banned' `user`.`role` != 'banned'
GROUP BY `user`.`userID` GROUP BY `user`.`userID`
"); ");
$stmt->bindParam(':userID', $_SESSION["userID"]); $stmt->bindParam(':userID', $_SESSION["userID"]);

View File

@@ -16,7 +16,7 @@
// Set default values of a friend. // Set default values of a friend.
$username = $friend["username"]; $username = $friend["username"];
$name = $friend["name"]; $name = $friend["fullname"];
$userID = $friend["userID"]; $userID = $friend["userID"];
$pf = "img/avatar-standard.png"; $pf = "img/avatar-standard.png";
@@ -37,8 +37,8 @@
</li> </li>
"; ";
} }
if (isset($_GET["chatID"]) && $_GET["chatID"] != "") { if (isset($_GET["username"]) && $_GET["username"] != "") {
$chatID = $_GET["chatID"]; $chatID = $_GET["username"];
echo "<script>$(document).ready(function(){switchUser('$chatID')});</script>"; echo "<script>$(document).ready(function(){switchUser('$chatID')});</script>";
} }
?> ?>

View File

@@ -16,63 +16,10 @@
</form></h4> </form></h4>
</section> </section>
<section id="groups-menu-section"> <section id="groups-menu-section">
<?php <h4>
Groepen
// Load file. </h4>
require_once("../queries/group_member.php"); <ul id="menu-groups-list" class="nav-list">
// Get all the friends of a user.
$groups = selectAllGroupsFromUser($_SESSION["userID"]);
if (sizeof($groups) > 0) {
echo "
<h4>
Groepen
</h4>
<ul class=\"nav-list\">
";
foreach ($groups as $i => $group) {
// Set default values of a friend.
$name = $group["name"];
$extraItem = "";
$picture = $group["picture"];
// Change values if needed.
if ($i > 3)
$extraItem = "extra-menu-items";
echo "
<li class='group-item $extraItem'>
<form action='group.php' method='get'>
<button type='submit'
name='groupname'
value='$name'>
<div class='group'>
<img alt='PF' class='group-picture' src='$picture'/>
$name
</div>
</button>
</form>
</li>
";
}
if (sizeof($groups) > 3) {
echo "
<li class='more-item' id='more-groups-click'>
Meer groepen..
</li>
";
}
}
?>
</section>
<section>
<ul>
<li class="more-item" id="menu-back">
Terug naar het overzicht
</li>
</ul> </ul>
</section> </section>
</nav> </nav>