diff --git a/website/public/API/loadFriendRequestNotifications.php b/website/public/API/loadFriendRequest.php similarity index 100% rename from website/public/API/loadFriendRequestNotifications.php rename to website/public/API/loadFriendRequest.php diff --git a/website/public/API/loadFriends.php b/website/public/API/loadFriends.php new file mode 100644 index 0000000..38158c9 --- /dev/null +++ b/website/public/API/loadFriends.php @@ -0,0 +1,16 @@ + $friend) { + $friendshipStatus = getFriendshipStatus($friend->userID); + + if ($limit != 0 && $i >= $limit) + $extra = "extra-friend-item"; + else + $extra = ""; + ?> +
  • +
    + +
    + 1) { + ?> +
    +
    + + + + + + +
    + +
  • + $limit) { + ?> +
  • + Meer vrienden... +
  • + + + diff --git a/website/public/js/chat.js b/website/public/js/chat.js index 3c839e4..06f85df 100644 --- a/website/public/js/chat.js +++ b/website/public/js/chat.js @@ -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() { diff --git a/website/public/js/main.js b/website/public/js/main.js new file mode 100644 index 0000000..5873f26 --- /dev/null +++ b/website/public/js/main.js @@ -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; + } +} \ No newline at end of file diff --git a/website/public/js/menu.js b/website/public/js/menu.js index 32b048a..7bd6922 100644 --- a/website/public/js/menu.js +++ b/website/public/js/menu.js @@ -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); +} \ No newline at end of file diff --git a/website/public/js/notifications.js b/website/public/js/notifications.js index afcaca0..a875418 100644 --- a/website/public/js/notifications.js +++ b/website/public/js/notifications.js @@ -1,45 +1,3 @@ -function showFriendNotifications(notifications) { - $("#friendrequestslist").html(""); - for (i in notifications) { - var outgoing = ""; - if (notifications[i].friend_state == "3") { - outgoing = " \ - \ - "; - } - - $("#friendrequestslist").append(" \ -
  • \ - \ - \ - \ -
    \ -
    \ - \ - "+ outgoing +" \ - \ - \ -
    \ -
  • \ - "); - } -} - 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(); } }); diff --git a/website/queries/friendship.php b/website/queries/friendship.php index cb35640..1bfa6ea 100644 --- a/website/queries/friendship.php +++ b/website/queries/friendship.php @@ -1,13 +1,51 @@ prepare(" + SELECT + `userID`, + `username`, + LEFT(CONCAT(`user`.`fname`, ' ', `user`.`lname`), 15) as `fullname`, + IFNULL( + `profilepicture`, + '../img/avatar-standard.png' + ) AS profilepicture, + `onlinestatus`, + `role` + FROM + `user` + INNER JOIN + `friendship` + WHERE + (`friendship`.`user1ID` = :userID AND + `friendship`.`user2ID` = `user`.`userID` OR + `friendship`.`user2ID` = :userID AND + `friendship`.`user1ID` = `user`.`userID`) AND + `user`.`role` != 'banned' AND + `friendship`.`status` = 'confirmed' + LIMIT :limitCount + "); + + $stmt->bindParam(':userID', $userID, PDO::PARAM_INT); + $stmt->bindParam(':limitCount', $limit, PDO::PARAM_INT); + $stmt->execute(); + + return json_encode($stmt->fetchAll()); +} + function selectAllFriends($userID) { $stmt = $GLOBALS["db"]->prepare(" SELECT `userID`, `username`, - LEFT(CONCAT(`user`.`fname`, ' ', `user`.`lname`), 15) as `name`, + LEFT(CONCAT(`user`.`fname`, ' ', `user`.`lname`), 15) as `fullname`, IFNULL( `profilepicture`, '../img/avatar-standard.png' @@ -39,22 +77,7 @@ function selectAllFriendRequests() { SELECT `userID`, `username`, - CASE `status` IS NULL - WHEN TRUE THEN 0 - WHEN FALSE THEN - CASE `status` = 'confirmed' - WHEN TRUE THEN - 1 - WHEN FALSE THEN - CASE `user1ID` = :userID - WHEN TRUE THEN - 2 - WHEN FALSE THEN - 3 - END - END - END AS `friend_state`, - LEFT(CONCAT(`user`.`fname`, ' ', `user`.`lname`), 15) as `name`, + LEFT(CONCAT(`user`.`fname`, ' ', `user`.`lname`), 15) as `fullname`, IFNULL( `profilepicture`, '../img/avatar-standard.png' diff --git a/website/views/chat-view.php b/website/views/chat-view.php index 797e457..c3fdde4 100644 --- a/website/views/chat-view.php +++ b/website/views/chat-view.php @@ -37,9 +37,8 @@ "; } - - $chatID = $_GET["chatID"]; - if (isset($chatID) && $chatID != "") { + if (isset($_GET["chatID"]) && $_GET["chatID"] != "") { + $chatID = $_GET["chatID"]; echo ""; } ?> diff --git a/website/views/head.php b/website/views/head.php index 044ac83..b6c2f21 100644 --- a/website/views/head.php +++ b/website/views/head.php @@ -2,6 +2,7 @@ MyHyvesbook+ + diff --git a/website/views/menu.php b/website/views/menu.php index d360e77..6564366 100644 --- a/website/views/menu.php +++ b/website/views/menu.php @@ -1,75 +1,19 @@