Chat messages and groups are now live.

This commit is contained in:
Lars van Hijfte
2017-01-26 10:26:40 +01:00
parent 30d403ae7b
commit 95ee91748f
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 ?>'>
<button type='submit'
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'>
<img alt='PF' class='profile-picture' src='<?= $friend->profilepicture ?>'/>
<div class='friend-name'>
<?= $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>
</button>
@@ -50,27 +62,25 @@ foreach($friends as $i => $friend) {
if ($friendshipStatus > 1) {
?>
<div class='notification-options'>
<form action='API/edit_friendship.php' method='post'>
<input type='hidden' name='userID' value='<?= $friend->userID ?>' />
<button type='submit'
name='delete'
class='deny-notification'
value='1'>
<i class='fa fa-times'></i>
</button>
<input type='hidden' name='userID' value='' />
<button name='delete'
onclick="editFriendship('<?= $friend->userID ?>', 'delete')"
class='deny-notification'
value='1'>
<i class='fa fa-times'></i>
</button>
<?php
if ($friendshipStatus == 3) {
?>
<button type='submit'
name='accept'
class='accept-notification'
value='1'>
<i class='fa fa-check'></i>
</button>
<button name='accept'
onclick="editFriendship('<?= $friend->userID ?>', 'accept')"
class='accept-notification'
value='1'>
<i class='fa fa-check'></i>
</button>
<?php
}
?>
<form>
</div>
<?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>
<head>
<meta http-equiv="refresh" content="0; url=login.php" />
</head>
</html>
<?php
session_start();
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() {
$.post("API/editFriendship.php", { usr: userID, action: this.value })
.done(function() {
placeFriendButtons();
});
editFriendship(userID, this.value);
});
});
}

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) {
if(friends && friends != "[]") {
$(list).load("bits/friend-item.php", {
@@ -11,7 +18,7 @@ function showFriends(friends, list) {
}
function showFriendsPlus(friends, list, limit, action, actionType) {
if(friends && friends.length > 0) {
if(friends && friends != "[]") {
$(list).load("bits/friend-item.php", {
"friends": friends,
"limit": limit,
@@ -19,6 +26,18 @@ function showFriendsPlus(friends, list, limit, action, 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;
} else {
return false;

View File

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