Merge branch 'lars' into 'master'
Lars See merge request !125
This commit was merged in pull request #129.
This commit is contained in:
16
website/public/API/loadFriends.php
Normal file
16
website/public/API/loadFriends.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
session_start();
|
||||
|
||||
require_once ("../../queries/connect.php");
|
||||
require_once ("../../queries/checkInput.php");
|
||||
require_once ("../../queries/friendship.php");
|
||||
|
||||
if (isset($_POST["limit"])) {
|
||||
echo selectLimitedFriends($_SESSION["userID"], (int) test_input($_POST["limit"]));
|
||||
} else if (isset($_GET["limit"])) {
|
||||
echo selectLimitedFriends($_SESSION["userID"], (int) test_input($_GET["limit"]));
|
||||
} else {
|
||||
echo selectFriends($_SESSION["userID"]);
|
||||
}
|
||||
|
||||
@@ -8,9 +8,9 @@ require_once("../../queries/checkInput.php");
|
||||
require_once("../../queries/friendship.php");
|
||||
|
||||
if (isset($_POST["lastID"]) && $_POST["lastID"] != "") {
|
||||
setLastVisited(test_input($_POST["destination"]));
|
||||
echo getNewChatMessages(test_input($_POST["lastID"]), test_input($_POST["destination"]));
|
||||
setLastVisited(test_input($_POST["destination"]));
|
||||
} else {
|
||||
echo getOldChatMessages(test_input($_POST["destination"]));
|
||||
setLastVisited(test_input($_POST["destination"]));
|
||||
echo getOldChatMessages(test_input($_POST["destination"]));
|
||||
}
|
||||
92
website/public/bits/friend-item.php
Normal file
92
website/public/bits/friend-item.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
session_start();
|
||||
|
||||
include_once ("../../queries/friendship.php");
|
||||
|
||||
if (isset($_POST["limit"])) {
|
||||
$limit = $_POST["limit"];
|
||||
} else {
|
||||
$limit = 5;
|
||||
}
|
||||
|
||||
if (isset($_POST["action"])) {
|
||||
$action = $_POST["action"];
|
||||
} else {
|
||||
$action = "profile.php";
|
||||
}
|
||||
|
||||
if (isset($_POST["actionType"])) {
|
||||
$actionType = $_POST["actionType"];
|
||||
} else {
|
||||
$actionType = "GET";
|
||||
}
|
||||
|
||||
$friends = json_decode($_POST["friends"]);
|
||||
|
||||
foreach($friends as $i => $friend) {
|
||||
$friendshipStatus = getFriendshipStatus($friend->userID);
|
||||
|
||||
if ($limit != 0 && $i >= $limit)
|
||||
$extra = "extra-friend-item";
|
||||
else
|
||||
$extra = "";
|
||||
?>
|
||||
<li class='friend-item <?= $extra ?>'>
|
||||
<form action='<?= $action ?>' method='<?= $actionType ?>'>
|
||||
<button type='submit'
|
||||
name='username'
|
||||
value='<?= $friend->username ?>'>
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
</button>
|
||||
</form>
|
||||
<?php
|
||||
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>
|
||||
<?php
|
||||
if ($friendshipStatus == 3) {
|
||||
?>
|
||||
<button type='submit'
|
||||
name='accept'
|
||||
class='accept-notification'
|
||||
value='1'>
|
||||
<i class='fa fa-check'></i>
|
||||
</button>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<form>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</li>
|
||||
<?php
|
||||
}
|
||||
|
||||
if (sizeof($friends) > $limit) {
|
||||
?>
|
||||
<li class='more-item'>
|
||||
Meer vrienden...
|
||||
</li>
|
||||
<?php
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ function switchUser(userID) {
|
||||
$("#chat-history").html("");
|
||||
$("#lastID").val("");
|
||||
$("#chat-recent-panel .friend-item").removeClass("active-friend-chat");
|
||||
$("#chat-left #friend-item-" + userID).addClass("active-friend-chat");
|
||||
$("#friend-item-" + userID).addClass("active-friend-chat");
|
||||
}
|
||||
|
||||
function sayEmpty() {
|
||||
|
||||
26
website/public/js/main.js
Normal file
26
website/public/js/main.js
Normal file
@@ -0,0 +1,26 @@
|
||||
function showFriends(friends, list) {
|
||||
if(friends && friends != "[]") {
|
||||
$(list).load("bits/friend-item.php", {
|
||||
"friends": friends
|
||||
});
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function showFriendsPlus(friends, list, limit, action, actionType) {
|
||||
if(friends && friends.length > 0) {
|
||||
$(list).load("bits/friend-item.php", {
|
||||
"friends": friends,
|
||||
"limit": limit,
|
||||
"action": action,
|
||||
"actionType": actionType
|
||||
});
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,39 +1,75 @@
|
||||
|
||||
$(document).ready(function() {
|
||||
$(".extra-menu-items").hide();
|
||||
$("#menu-back").hide();
|
||||
// Show more friends/users
|
||||
|
||||
// Show more friends
|
||||
$("#more-friends-click").click(function() {
|
||||
// Show only friends
|
||||
$("#groups-menu-section").slideUp();
|
||||
$("#friends-menu-section li").show();
|
||||
// $("#more-friends-click").click(function() {
|
||||
// // Show only friends
|
||||
// $("#groups-menu-section").slideUp();
|
||||
// $("#friends-menu-section li").show();
|
||||
//
|
||||
// // Change buttons
|
||||
// $("#more-friends-click").hide();
|
||||
// $("#menu-back").show();
|
||||
// });
|
||||
//
|
||||
// // Show more groups
|
||||
// $("#more-groups-click").click(function() {
|
||||
// // Show only groups
|
||||
// $("#friends-menu-section").slideUp();
|
||||
// $("#groups-menu-section li").show();
|
||||
//
|
||||
// // Change buttons
|
||||
// $("#more-groups-click").hide();
|
||||
// $("#menu-back").show();
|
||||
// });
|
||||
|
||||
// Change buttons
|
||||
$("#more-friends-click").hide();
|
||||
$("#menu-back").show();
|
||||
});
|
||||
// // Go back
|
||||
// $("#menu-back").click(function() {
|
||||
// // Show overview of friends and groups
|
||||
// $("#friends-menu-section").slideDown();
|
||||
// $("#groups-menu-section").slideDown();
|
||||
// $(".extra-menu-items").hide();
|
||||
//
|
||||
// // Change buttons
|
||||
// $("#menu-back").hide();
|
||||
// $("#more-groups-click").show();
|
||||
// $("#more-friends-click").show();
|
||||
// });
|
||||
|
||||
// Show more groups
|
||||
$("#more-groups-click").click(function() {
|
||||
// Show only groups
|
||||
$("#friends-menu-section").slideUp();
|
||||
$("#groups-menu-section li").show();
|
||||
|
||||
// Change buttons
|
||||
$("#more-groups-click").hide();
|
||||
$("#menu-back").show();
|
||||
});
|
||||
|
||||
// Go back
|
||||
$("#menu-back").click(function() {
|
||||
// Show overview of friends and groups
|
||||
$("#friends-menu-section").slideDown();
|
||||
$("#groups-menu-section").slideDown();
|
||||
$(".extra-menu-items").hide();
|
||||
|
||||
// Change buttons
|
||||
$("#menu-back").hide();
|
||||
$("#more-groups-click").show();
|
||||
$("#more-friends-click").show();
|
||||
});
|
||||
loadMenuFriends(5);
|
||||
loadNotificationFriends();
|
||||
});
|
||||
|
||||
|
||||
function loadMenuFriends(limit) {
|
||||
$.post(
|
||||
"API/loadFriends.php",
|
||||
{
|
||||
limit: 5
|
||||
}
|
||||
).done(function(data) {
|
||||
if (showFriends(data, "#menu-friends-list", 5, "profile.php", "GET", limit)) {
|
||||
$("#friends-menu-section").show();
|
||||
} else {
|
||||
$("#friends-menu-section").hide();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
setTimeout(loadMenuFriends, 3000, limit);
|
||||
}
|
||||
|
||||
function loadNotificationFriends() {
|
||||
$.post(
|
||||
"API/loadFriendRequest.php"
|
||||
).done(function(data) {
|
||||
if (showFriendsPlus(data, "#friend-requests-list", 5, "API/edit_friendship", "POST")) {
|
||||
$("#friend-request-section").show();
|
||||
} else {
|
||||
$("#friend-request-section").hide();
|
||||
}
|
||||
});
|
||||
|
||||
setTimeout(loadNotificationFriends, 30000);
|
||||
}
|
||||
@@ -1,45 +1,3 @@
|
||||
function showFriendNotifications(notifications) {
|
||||
$("#friendrequestslist").html("");
|
||||
for (i in notifications) {
|
||||
var outgoing = "";
|
||||
if (notifications[i].friend_state == "3") {
|
||||
outgoing = "<button\
|
||||
name='accept' \
|
||||
class='accept-notification' \
|
||||
value='"+ notifications[i].userID +"'> \
|
||||
<i class='fa fa-check'></i> \
|
||||
</button>";
|
||||
}
|
||||
|
||||
$("#friendrequestslist").append(" \
|
||||
<li class='friend-item'> \
|
||||
<form action='profile.php' method='get'> \
|
||||
<button type='submit' \
|
||||
name='username' \
|
||||
value='"+ notifications[i].username +"'> \
|
||||
<div class='friend'> \
|
||||
<img alt='PF' class='profile-picture' src='"+ notifications[i].profilepicture +"'/> \
|
||||
"+ notifications[i].username +" \
|
||||
</div> \
|
||||
</button> \
|
||||
</form> \
|
||||
<div class='notification-options'>\
|
||||
<form action='API/edit_friendship.php' method='post'> \
|
||||
<input type='hidden' name='userID' value='"+ notifications[i].userID +"' /> \
|
||||
"+ outgoing +" \
|
||||
<button type='submit' \
|
||||
name='delete' \
|
||||
class='deny-notification' \
|
||||
value='"+ notifications[i].userID +"'> \
|
||||
<i class='fa fa-times'></i> \
|
||||
</button>\
|
||||
<form>\
|
||||
</div> \
|
||||
</li> \
|
||||
");
|
||||
}
|
||||
}
|
||||
|
||||
function showChatNotifications(notifications) {
|
||||
$("#unreadChatlist").html("");
|
||||
for (i in notifications) {
|
||||
@@ -64,18 +22,14 @@ function showChatNotifications(notifications) {
|
||||
}
|
||||
|
||||
function loadNotifications() {
|
||||
$.post(
|
||||
"API/loadFriendRequestNotifications.php"
|
||||
).done(function(data) {
|
||||
if (data && data != "[]") {
|
||||
showFriendNotifications(JSON.parse(data));
|
||||
}
|
||||
});
|
||||
$.post(
|
||||
"API/loadChatNotifications.php"
|
||||
).done(function(data) {
|
||||
if (data && data != "[]") {
|
||||
$("#unread-messages-section").show();
|
||||
showChatNotifications(JSON.parse(data));
|
||||
} else {
|
||||
$("#unread-messages-section").hide();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user