Merge branch 'lars' into 'master'

Chat messages and groups are now live.

See merge request !126
This commit was merged in pull request #130.
This commit is contained in:
Lars van Hijfte
2017-01-26 10:27:45 +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 ?>'>
<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,10 +62,9 @@ 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'
<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>
@@ -61,8 +72,8 @@ foreach($friends as $i => $friend) {
<?php
if ($friendshipStatus == 3) {
?>
<button type='submit'
name='accept'
<button name='accept'
onclick="editFriendship('<?= $friend->userID ?>', 'accept')"
class='accept-notification'
value='1'>
<i class='fa fa-check'></i>
@@ -70,7 +81,6 @@ foreach($friends as $i => $friend) {
<?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,
@@ -24,3 +31,15 @@ function showFriendsPlus(friends, list, limit, action, actionType) {
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();
// });

View File

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

View File

@@ -79,7 +79,7 @@ function getNewChatMessages($lastID, $destination) {
function selectAllUnreadChat() {
$stmt = $GLOBALS["db"]->prepare("
SELECT
LEFT(CONCAT(`user`.`fname`, ' ', `user`.`lname`), 15) as `name`,
LEFT(CONCAT(`user`.`fname`, ' ', `user`.`lname`), 15) as `fullname`,
`user`.`userID`,
IFNULL(
`profilepicture`,
@@ -93,15 +93,18 @@ function selectAllUnreadChat() {
WHERE
(`friendship`.user2ID = `private_message`.`origin` 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`.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`.`destination` = :userID AND
`user`.`role` != 'banned'
GROUP BY `user`.`userID`
");
$stmt->bindParam(':userID', $_SESSION["userID"]);

View File

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

View File

@@ -16,63 +16,10 @@
</form></h4>
</section>
<section id="groups-menu-section">
<?php
// Load file.
require_once("../queries/group_member.php");
// 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 id="menu-groups-list" class="nav-list">
</ul>
</section>
</nav>