diff --git a/website/public/API/loadGroups.php b/website/public/API/loadGroups.php new file mode 100644 index 0000000..546b9d7 --- /dev/null +++ b/website/public/API/loadGroups.php @@ -0,0 +1,14 @@ + $friend) {
@@ -50,27 +62,25 @@ foreach($friends as $i => $friend) { if ($friendshipStatus > 1) { ?>
- - - + + - + -
$group) { + ?> +
  • + + +
  • + + +
  • +
    + + + +
    +
  • diff --git a/website/public/index.php b/website/public/index.php index 914192b..7ad8b59 100644 --- a/website/public/index.php +++ b/website/public/index.php @@ -1,5 +1,9 @@ - - - - - \ No newline at end of file + 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; diff --git a/website/public/js/menu.js b/website/public/js/menu.js index 7bd6922..8329cde 100644 --- a/website/public/js/menu.js +++ b/website/public/js/menu.js @@ -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); } \ No newline at end of file diff --git a/website/public/js/notifications.js b/website/public/js/notifications.js index a875418..d78d167 100644 --- a/website/public/js/notifications.js +++ b/website/public/js/notifications.js @@ -1,43 +1,43 @@ -function showChatNotifications(notifications) { - $("#unreadChatlist").html(""); - for (i in notifications) { - $("#unreadChatlist").append(" \ -
  • \ -
    \ - \ -
    \ -
  • \ - "); - } -} - -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(" \ +//
  • \ +//
    \ +// \ +//
    \ +//
  • \ +// "); +// } +// } +// +// 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(); +// }); diff --git a/website/queries/group_member.php b/website/queries/group_member.php index 59d4dce..a188494 100644 --- a/website/queries/group_member.php +++ b/website/queries/group_member.php @@ -1,6 +1,10 @@ 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()); } + diff --git a/website/queries/private_message.php b/website/queries/private_message.php index d40ee88..e708541 100644 --- a/website/queries/private_message.php +++ b/website/queries/private_message.php @@ -79,11 +79,11 @@ 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`, - '../img/notbad.jpg' + `profilepicture`, + '../img/notbad.jpg' ) AS profilepicture, LEFT(`private_message`.`content`, 15) as `content` FROM @@ -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`.user2ID = `private_message`.`destination` 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"]); diff --git a/website/views/chat-view.php b/website/views/chat-view.php index c3fdde4..0d90149 100644 --- a/website/views/chat-view.php +++ b/website/views/chat-view.php @@ -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 @@ "; } - if (isset($_GET["chatID"]) && $_GET["chatID"] != "") { - $chatID = $_GET["chatID"]; + if (isset($_GET["username"]) && $_GET["username"] != "") { + $chatID = $_GET["username"]; echo ""; } ?> diff --git a/website/views/menu.php b/website/views/menu.php index 6564366..4d15d94 100644 --- a/website/views/menu.php +++ b/website/views/menu.php @@ -16,63 +16,10 @@
    - 0) { - echo " -

    - Groepen -

    -
    -
    -
    \ No newline at end of file